Energy Storage migrated
This commit is contained in:
parent
46fb0ede7a
commit
3201ac878b
8 changed files with 38 additions and 93 deletions
|
@ -39,7 +39,7 @@ import techreborn.tiles.storage.TileAdjustableSU;
|
||||||
public class BlockAdjustableSU extends BlockEnergyStorage {
|
public class BlockAdjustableSU extends BlockEnergyStorage {
|
||||||
|
|
||||||
public BlockAdjustableSU() {
|
public BlockAdjustableSU() {
|
||||||
super("AESU", EGui.AESU.ordinal());
|
super("AESU", EGui.AESU);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -27,19 +27,20 @@ package techreborn.blocks.storage;
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.collect.Iterators;
|
import com.google.common.collect.Iterators;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.SoundType;
|
|
||||||
import net.minecraft.block.material.Material;
|
import net.minecraft.block.material.Material;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.entity.EntityLivingBase;
|
import net.minecraft.entity.EntityLivingBase;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.state.DirectionProperty;
|
import net.minecraft.state.DirectionProperty;
|
||||||
|
import net.minecraft.state.StateContainer;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.EnumHand;
|
import net.minecraft.util.EnumHand;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import reborncore.api.ToolManager;
|
import reborncore.api.ToolManager;
|
||||||
|
import reborncore.api.tile.IMachineGuiHandler;
|
||||||
import reborncore.client.models.ModelCompound;
|
import reborncore.client.models.ModelCompound;
|
||||||
import reborncore.client.models.RebornModelRegistry;
|
import reborncore.client.models.RebornModelRegistry;
|
||||||
import reborncore.common.BaseTileBlock;
|
import reborncore.common.BaseTileBlock;
|
||||||
|
@ -55,13 +56,13 @@ import java.util.Random;
|
||||||
public abstract class BlockEnergyStorage extends BaseTileBlock {
|
public abstract class BlockEnergyStorage extends BaseTileBlock {
|
||||||
public static DirectionProperty FACING = DirectionProperty.create("facing", Facings.ALL);
|
public static DirectionProperty FACING = DirectionProperty.create("facing", Facings.ALL);
|
||||||
public String name;
|
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));
|
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.name = name;
|
||||||
this.guiID = guiID;
|
this.gui = gui;
|
||||||
RebornModelRegistry.registerModel(new ModelCompound(TechReborn.MOD_ID, this, "machines/energy"));
|
RebornModelRegistry.registerModel(new ModelCompound(TechReborn.MOD_ID, this, "machines/energy"));
|
||||||
BlockWrenchEventHandler.wrenableBlocks.add(this);
|
BlockWrenchEventHandler.wrenableBlocks.add(this);
|
||||||
}
|
}
|
||||||
|
@ -70,42 +71,8 @@ public abstract class BlockEnergyStorage extends BaseTileBlock {
|
||||||
world.setBlockState(pos, world.getBlockState(pos).with(FACING, facing));
|
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) {
|
public EnumFacing getFacing(IBlockState state) {
|
||||||
return state.getValue(FACING);
|
return state.get(FACING);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSimpleName(String fullName) {
|
public String getSimpleName(String fullName) {
|
||||||
|
@ -132,23 +99,12 @@ public abstract class BlockEnergyStorage extends BaseTileBlock {
|
||||||
|
|
||||||
// Block
|
// Block
|
||||||
@Override
|
@Override
|
||||||
public boolean rotateBlock(World world, BlockPos pos, EnumFacing side) {
|
protected void fillStateContainer(StateContainer.Builder<Block, IBlockState> builder) {
|
||||||
IBlockState state = world.getBlockState(pos);
|
FACING = DirectionProperty.create("facing", Facings.ALL);
|
||||||
Block block = state.getBlock();
|
builder.add(FACING);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
@Override
|
@Override
|
||||||
public boolean onBlockActivated(IBlockState state, World worldIn, BlockPos pos, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
|
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);
|
ItemStack stack = playerIn.getHeldItem(EnumHand.MAIN_HAND);
|
||||||
|
@ -165,23 +121,17 @@ public abstract class BlockEnergyStorage extends BaseTileBlock {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!playerIn.isSneaking()) {
|
if (!playerIn.isSneaking() && gui != null) {
|
||||||
playerIn.openGui(TechReborn.INSTANCE, guiID, worldIn, pos.getX(), pos.getY(), pos.getZ());
|
gui.open(playerIn, pos, worldIn);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.onBlockActivated(worldIn, pos, state, playerIn, hand, side, hitX, hitY, hitZ);
|
return super.onBlockActivated(state, worldIn, pos, playerIn, hand, side, hitX, hitY, hitZ);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected BlockStateContainer createBlockState() {
|
|
||||||
FACING = DirectionProperty.create("facing", Facings.ALL);
|
|
||||||
return new BlockStateContainer(this, FACING);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer,
|
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer,
|
||||||
ItemStack stack) {
|
ItemStack stack) {
|
||||||
super.onBlockPlacedBy(worldIn, pos, state, placer, stack);
|
super.onBlockPlacedBy(worldIn, pos, state, placer, stack);
|
||||||
EnumFacing facing = placer.getHorizontalFacing().getOpposite();
|
EnumFacing facing = placer.getHorizontalFacing().getOpposite();
|
||||||
if (placer.rotationPitch < -50) {
|
if (placer.rotationPitch < -50) {
|
||||||
|
|
|
@ -42,7 +42,7 @@ import techreborn.tiles.storage.TileHighVoltageSU;
|
||||||
public class BlockHighVoltageSU extends BlockEnergyStorage {
|
public class BlockHighVoltageSU extends BlockEnergyStorage {
|
||||||
|
|
||||||
public BlockHighVoltageSU() {
|
public BlockHighVoltageSU() {
|
||||||
super("high_voltage_su", EGui.HIGH_VOLTAGE_SU.ordinal());
|
super("high_voltage_su", EGui.HIGH_VOLTAGE_SU);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -26,12 +26,11 @@ package techreborn.blocks.storage;
|
||||||
|
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.entity.EntityLivingBase;
|
import net.minecraft.entity.EntityLivingBase;
|
||||||
|
import net.minecraft.item.BlockItemUseContext;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.EnumFacing;
|
|
||||||
import net.minecraft.util.NonNullList;
|
import net.minecraft.util.NonNullList;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.IBlockAccess;
|
|
||||||
import net.minecraft.world.IBlockReader;
|
import net.minecraft.world.IBlockReader;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import reborncore.common.RebornCoreConfig;
|
import reborncore.common.RebornCoreConfig;
|
||||||
|
@ -42,7 +41,7 @@ import techreborn.tiles.storage.idsu.TileInterdimensionalSU;
|
||||||
public class BlockInterdimensionalSU extends BlockEnergyStorage {
|
public class BlockInterdimensionalSU extends BlockEnergyStorage {
|
||||||
|
|
||||||
public BlockInterdimensionalSU() {
|
public BlockInterdimensionalSU() {
|
||||||
super("IDSU", EGui.IDSU.ordinal());
|
super("IDSU", EGui.IDSU);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -51,11 +50,10 @@ public class BlockInterdimensionalSU extends BlockEnergyStorage {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IBlockState getStateForPlacement(final World world, final BlockPos pos, final EnumFacing facing, final float hitX, final float hitY,
|
public IBlockState getStateForPlacement(BlockItemUseContext context) {
|
||||||
final float hitZ, final int meta, final EntityLivingBase placer) {
|
final TileEntity tile = context.getWorld().getTileEntity(context.getPos());
|
||||||
final TileEntity tile = world.getTileEntity(pos);
|
|
||||||
if (tile instanceof TileInterdimensionalSU) {
|
if (tile instanceof TileInterdimensionalSU) {
|
||||||
((TileInterdimensionalSU) tile).ownerUdid = placer.getUniqueID().toString();
|
((TileInterdimensionalSU) tile).ownerUdid = context.getPlayer().getUniqueID().toString();
|
||||||
}
|
}
|
||||||
return this.getDefaultState();
|
return this.getDefaultState();
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,29 +54,31 @@ import techreborn.tiles.storage.lesu.TileLSUStorage;
|
||||||
public class BlockLSUStorage extends BaseTileBlock {
|
public class BlockLSUStorage extends BaseTileBlock {
|
||||||
|
|
||||||
public BlockLSUStorage() {
|
public BlockLSUStorage() {
|
||||||
super(Material.IRON);
|
super(Block.Properties.create(Material.IRON).hardnessAndResistance(2f));
|
||||||
RebornModelRegistry.registerModel(new ModelCompound(TechReborn.MOD_ID, this, "machines/energy"));
|
RebornModelRegistry.registerModel(new ModelCompound(TechReborn.MOD_ID, this, "machines/energy"));
|
||||||
BlockWrenchEventHandler.wrenableBlocks.add(this);
|
BlockWrenchEventHandler.wrenableBlocks.add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// BaseTileBlock
|
// BaseTileBlock
|
||||||
@Override
|
@Override
|
||||||
public void breakBlock(World world, BlockPos pos, IBlockState state) {
|
public void onReplaced(IBlockState state, World worldIn, BlockPos pos, IBlockState newState, boolean isMoving) {
|
||||||
if (world.getTileEntity(pos) instanceof TileLSUStorage) {
|
if (state.getBlock() == newState.getBlock()) {
|
||||||
TileLSUStorage tile = (TileLSUStorage) world.getTileEntity(pos);
|
return;
|
||||||
|
}
|
||||||
|
if (worldIn.getTileEntity(pos) instanceof TileLSUStorage) {
|
||||||
|
TileLSUStorage tile = (TileLSUStorage) worldIn.getTileEntity(pos);
|
||||||
if (tile != null) {
|
if (tile != null) {
|
||||||
tile.removeFromNetwork();
|
tile.removeFromNetwork();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
super.breakBlock(world, pos, state);
|
super.onReplaced(state, worldIn, pos, newState, isMoving);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TileEntity createNewTileEntity(IBlockReader worldIn) {
|
public TileEntity createNewTileEntity(IBlockReader worldIn) {
|
||||||
return new TileLSUStorage();
|
return new TileLSUStorage();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Block
|
|
||||||
@Override
|
@Override
|
||||||
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase player, ItemStack itemstack) {
|
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase player, ItemStack itemstack) {
|
||||||
super.onBlockPlacedBy(world, pos, state, player, itemstack);
|
super.onBlockPlacedBy(world, pos, state, player, itemstack);
|
||||||
|
@ -88,6 +90,8 @@ public class BlockLSUStorage extends BaseTileBlock {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Block
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
@Override
|
@Override
|
||||||
public boolean onBlockActivated(IBlockState state, World worldIn, BlockPos pos, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
|
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);
|
ItemStack stack = playerIn.getHeldItem(EnumHand.MAIN_HAND);
|
||||||
|
@ -115,10 +119,4 @@ public class BlockLSUStorage extends BaseTileBlock {
|
||||||
super.getDrops(state, drops, world, pos, fortune);
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ import techreborn.tiles.storage.lesu.TileLapotronicSU;
|
||||||
public class BlockLapotronicSU extends BlockEnergyStorage {
|
public class BlockLapotronicSU extends BlockEnergyStorage {
|
||||||
|
|
||||||
public BlockLapotronicSU() {
|
public BlockLapotronicSU() {
|
||||||
super("LESU", EGui.LESU.ordinal());
|
super("LESU", EGui.LESU);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -35,7 +35,7 @@ import techreborn.tiles.storage.TileLowVoltageSU;
|
||||||
public class BlockLowVoltageSU extends BlockEnergyStorage {
|
public class BlockLowVoltageSU extends BlockEnergyStorage {
|
||||||
|
|
||||||
public BlockLowVoltageSU() {
|
public BlockLowVoltageSU() {
|
||||||
super("low_voltage_su", EGui.LOW_VOLTAGE_SU.ordinal());
|
super("low_voltage_su", EGui.LOW_VOLTAGE_SU);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -29,7 +29,6 @@ import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.NonNullList;
|
import net.minecraft.util.NonNullList;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.IBlockAccess;
|
|
||||||
import net.minecraft.world.IBlockReader;
|
import net.minecraft.world.IBlockReader;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import reborncore.common.RebornCoreConfig;
|
import reborncore.common.RebornCoreConfig;
|
||||||
|
@ -43,7 +42,7 @@ import techreborn.tiles.storage.TileMediumVoltageSU;
|
||||||
public class BlockMediumVoltageSU extends BlockEnergyStorage {
|
public class BlockMediumVoltageSU extends BlockEnergyStorage {
|
||||||
|
|
||||||
public BlockMediumVoltageSU() {
|
public BlockMediumVoltageSU() {
|
||||||
super("medium_voltage_su", EGui.MEDIUM_VOLTAGE_SU.ordinal());
|
super("medium_voltage_su", EGui.MEDIUM_VOLTAGE_SU);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue