Energy Storage migrated

This commit is contained in:
drcrazy 2019-02-21 16:00:12 +03:00
parent 46fb0ede7a
commit 3201ac878b
8 changed files with 38 additions and 93 deletions

View file

@ -39,7 +39,7 @@ import techreborn.tiles.storage.TileAdjustableSU;
public class BlockAdjustableSU extends BlockEnergyStorage {
public BlockAdjustableSU() {
super("AESU", EGui.AESU.ordinal());
super("AESU", EGui.AESU);
}
@Override

View file

@ -27,19 +27,20 @@ package techreborn.blocks.storage;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterators;
import net.minecraft.block.Block;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.state.DirectionProperty;
import net.minecraft.state.StateContainer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import reborncore.api.ToolManager;
import reborncore.api.tile.IMachineGuiHandler;
import reborncore.client.models.ModelCompound;
import reborncore.client.models.RebornModelRegistry;
import reborncore.common.BaseTileBlock;
@ -55,13 +56,13 @@ import java.util.Random;
public abstract class BlockEnergyStorage extends BaseTileBlock {
public static DirectionProperty FACING = DirectionProperty.create("facing", Facings.ALL);
public String name;
public int guiID;
public IMachineGuiHandler gui;
public BlockEnergyStorage(String name, int guiID) {
public BlockEnergyStorage(String name, IMachineGuiHandler gui) {
super(Block.Properties.create(Material.IRON).hardnessAndResistance(2f));
this.setDefaultState(this.blockState.getBaseState().with(FACING, EnumFacing.NORTH));
this.setDefaultState(this.stateContainer.getBaseState().with(FACING, EnumFacing.NORTH));
this.name = name;
this.guiID = guiID;
this.gui = gui;
RebornModelRegistry.registerModel(new ModelCompound(TechReborn.MOD_ID, this, "machines/energy"));
BlockWrenchEventHandler.wrenableBlocks.add(this);
}
@ -70,42 +71,8 @@ public abstract class BlockEnergyStorage extends BaseTileBlock {
world.setBlockState(pos, world.getBlockState(pos).with(FACING, facing));
}
public EnumFacing getSideFromint(int i) {
if (i == 0) {
return EnumFacing.NORTH;
} else if (i == 1) {
return EnumFacing.SOUTH;
} else if (i == 2) {
return EnumFacing.EAST;
} else if (i == 3) {
return EnumFacing.WEST;
} else if (i == 4) {
return EnumFacing.UP;
} else if (i == 5) {
return EnumFacing.DOWN;
}
return EnumFacing.NORTH;
}
public int getSideFromEnum(EnumFacing facing) {
if (facing == EnumFacing.NORTH) {
return 0;
} else if (facing == EnumFacing.SOUTH) {
return 1;
} else if (facing == EnumFacing.EAST) {
return 2;
} else if (facing == EnumFacing.WEST) {
return 3;
} else if (facing == EnumFacing.UP) {
return 4;
} else if (facing == EnumFacing.DOWN) {
return 5;
}
return 0;
}
public EnumFacing getFacing(IBlockState state) {
return state.getValue(FACING);
return state.get(FACING);
}
public String getSimpleName(String fullName) {
@ -132,23 +99,12 @@ public abstract class BlockEnergyStorage extends BaseTileBlock {
// Block
@Override
public boolean rotateBlock(World world, BlockPos pos, EnumFacing side) {
IBlockState state = world.getBlockState(pos);
Block block = state.getBlock();
if (block instanceof BlockEnergyStorage) {
EnumFacing facing = state.getValue(BlockEnergyStorage.FACING);
if (facing.getOpposite() == side) {
facing = side;
} else {
facing = side.getOpposite();
}
world.setBlockState(pos, state.with(BlockEnergyStorage.FACING, facing));
return true;
}
return false;
protected void fillStateContainer(StateContainer.Builder<Block, IBlockState> builder) {
FACING = DirectionProperty.create("facing", Facings.ALL);
builder.add(FACING);
}
@SuppressWarnings("deprecation")
@Override
public boolean onBlockActivated(IBlockState state, World worldIn, BlockPos pos, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
ItemStack stack = playerIn.getHeldItem(EnumHand.MAIN_HAND);
@ -165,23 +121,17 @@ public abstract class BlockEnergyStorage extends BaseTileBlock {
}
}
if (!playerIn.isSneaking()) {
playerIn.openGui(TechReborn.INSTANCE, guiID, worldIn, pos.getX(), pos.getY(), pos.getZ());
if (!playerIn.isSneaking() && gui != null) {
gui.open(playerIn, pos, worldIn);
return true;
}
return super.onBlockActivated(worldIn, pos, state, playerIn, hand, side, hitX, hitY, hitZ);
}
@Override
protected BlockStateContainer createBlockState() {
FACING = DirectionProperty.create("facing", Facings.ALL);
return new BlockStateContainer(this, FACING);
return super.onBlockActivated(state, worldIn, pos, playerIn, hand, side, hitX, hitY, hitZ);
}
@Override
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer,
ItemStack stack) {
ItemStack stack) {
super.onBlockPlacedBy(worldIn, pos, state, placer, stack);
EnumFacing facing = placer.getHorizontalFacing().getOpposite();
if (placer.rotationPitch < -50) {

View file

@ -42,7 +42,7 @@ import techreborn.tiles.storage.TileHighVoltageSU;
public class BlockHighVoltageSU extends BlockEnergyStorage {
public BlockHighVoltageSU() {
super("high_voltage_su", EGui.HIGH_VOLTAGE_SU.ordinal());
super("high_voltage_su", EGui.HIGH_VOLTAGE_SU);
}
@Override

View file

@ -26,12 +26,11 @@ package techreborn.blocks.storage;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.BlockItemUseContext;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.World;
import reborncore.common.RebornCoreConfig;
@ -42,7 +41,7 @@ import techreborn.tiles.storage.idsu.TileInterdimensionalSU;
public class BlockInterdimensionalSU extends BlockEnergyStorage {
public BlockInterdimensionalSU() {
super("IDSU", EGui.IDSU.ordinal());
super("IDSU", EGui.IDSU);
}
@Override
@ -51,11 +50,10 @@ public class BlockInterdimensionalSU extends BlockEnergyStorage {
}
@Override
public IBlockState getStateForPlacement(final World world, final BlockPos pos, final EnumFacing facing, final float hitX, final float hitY,
final float hitZ, final int meta, final EntityLivingBase placer) {
final TileEntity tile = world.getTileEntity(pos);
public IBlockState getStateForPlacement(BlockItemUseContext context) {
final TileEntity tile = context.getWorld().getTileEntity(context.getPos());
if (tile instanceof TileInterdimensionalSU) {
((TileInterdimensionalSU) tile).ownerUdid = placer.getUniqueID().toString();
((TileInterdimensionalSU) tile).ownerUdid = context.getPlayer().getUniqueID().toString();
}
return this.getDefaultState();
}

View file

@ -54,29 +54,31 @@ import techreborn.tiles.storage.lesu.TileLSUStorage;
public class BlockLSUStorage extends BaseTileBlock {
public BlockLSUStorage() {
super(Material.IRON);
super(Block.Properties.create(Material.IRON).hardnessAndResistance(2f));
RebornModelRegistry.registerModel(new ModelCompound(TechReborn.MOD_ID, this, "machines/energy"));
BlockWrenchEventHandler.wrenableBlocks.add(this);
}
// BaseTileBlock
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state) {
if (world.getTileEntity(pos) instanceof TileLSUStorage) {
TileLSUStorage tile = (TileLSUStorage) world.getTileEntity(pos);
public void onReplaced(IBlockState state, World worldIn, BlockPos pos, IBlockState newState, boolean isMoving) {
if (state.getBlock() == newState.getBlock()) {
return;
}
if (worldIn.getTileEntity(pos) instanceof TileLSUStorage) {
TileLSUStorage tile = (TileLSUStorage) worldIn.getTileEntity(pos);
if (tile != null) {
tile.removeFromNetwork();
}
}
super.breakBlock(world, pos, state);
super.onReplaced(state, worldIn, pos, newState, isMoving);
}
@Override
public TileEntity createNewTileEntity(IBlockReader worldIn) {
return new TileLSUStorage();
}
// Block
@Override
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase player, ItemStack itemstack) {
super.onBlockPlacedBy(world, pos, state, player, itemstack);
@ -88,6 +90,8 @@ public class BlockLSUStorage extends BaseTileBlock {
}
}
// Block
@SuppressWarnings("deprecation")
@Override
public boolean onBlockActivated(IBlockState state, World worldIn, BlockPos pos, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
ItemStack stack = playerIn.getHeldItem(EnumHand.MAIN_HAND);
@ -115,10 +119,4 @@ public class BlockLSUStorage extends BaseTileBlock {
super.getDrops(state, drops, world, pos, fortune);
}
}
@Override
public boolean canBeConnectedTo(IBlockAccess world, BlockPos pos, EnumFacing facing) {
Block block = world.getBlockState(pos).getBlock();
return this == block;
}
}

View file

@ -39,7 +39,7 @@ import techreborn.tiles.storage.lesu.TileLapotronicSU;
public class BlockLapotronicSU extends BlockEnergyStorage {
public BlockLapotronicSU() {
super("LESU", EGui.LESU.ordinal());
super("LESU", EGui.LESU);
}
@Override

View file

@ -35,7 +35,7 @@ import techreborn.tiles.storage.TileLowVoltageSU;
public class BlockLowVoltageSU extends BlockEnergyStorage {
public BlockLowVoltageSU() {
super("low_voltage_su", EGui.LOW_VOLTAGE_SU.ordinal());
super("low_voltage_su", EGui.LOW_VOLTAGE_SU);
}
@Override

View file

@ -29,7 +29,6 @@ import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.World;
import reborncore.common.RebornCoreConfig;
@ -43,7 +42,7 @@ import techreborn.tiles.storage.TileMediumVoltageSU;
public class BlockMediumVoltageSU extends BlockEnergyStorage {
public BlockMediumVoltageSU() {
super("medium_voltage_su", EGui.MEDIUM_VOLTAGE_SU.ordinal());
super("medium_voltage_su", EGui.MEDIUM_VOLTAGE_SU);
}
@Override