From c25ab8227a2f8f6e1ba0464186c9932c98e67f76 Mon Sep 17 00:00:00 2001 From: Stuart Pomeroy Date: Mon, 28 Mar 2016 11:45:21 +0100 Subject: [PATCH] Update the Tiles for Storage. Also work on Drops. Not Finished. --- .../blocks/storage/BlockBatBox.java | 9 +- .../blocks/storage/BlockEnergyStorage.java | 17 +-- .../techreborn/blocks/storage/BlockMFE.java | 11 +- .../techreborn/blocks/storage/BlockMFSU.java | 12 ++ .../transformers/BlockHVTransformer.java | 34 +++++ .../transformers/BlockLVTransformer.java | 33 ++++ .../transformers/BlockMVTransformer.java | 35 +++++ .../techreborn/tiles/storage/TileBatBox.java | 127 +--------------- .../tiles/storage/TileEnergyStorage.java | 141 ++++++++++++++++++ .../techreborn/tiles/storage/TileMFE.java | 35 +---- .../techreborn/tiles/storage/TileMFSU.java | 35 +---- 11 files changed, 290 insertions(+), 199 deletions(-) create mode 100644 src/main/java/techreborn/tiles/storage/TileEnergyStorage.java diff --git a/src/main/java/techreborn/blocks/storage/BlockBatBox.java b/src/main/java/techreborn/blocks/storage/BlockBatBox.java index 6fd6e4f5e..bc60f399f 100644 --- a/src/main/java/techreborn/blocks/storage/BlockBatBox.java +++ b/src/main/java/techreborn/blocks/storage/BlockBatBox.java @@ -1,6 +1,9 @@ package techreborn.blocks.storage; +import net.minecraft.block.state.IBlockState; +import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import techreborn.client.GuiHandler; import techreborn.tiles.storage.TileBatBox; @@ -20,5 +23,9 @@ public class BlockBatBox extends BlockEnergyStorage { return new TileBatBox(); } - + @Override + public void breakBlock(World worldIn, BlockPos pos, IBlockState state) + { + dropInventory(worldIn, pos, new ItemStack(this)); + } } diff --git a/src/main/java/techreborn/blocks/storage/BlockEnergyStorage.java b/src/main/java/techreborn/blocks/storage/BlockEnergyStorage.java index dbf66e2d3..b015e9d05 100644 --- a/src/main/java/techreborn/blocks/storage/BlockEnergyStorage.java +++ b/src/main/java/techreborn/blocks/storage/BlockEnergyStorage.java @@ -28,7 +28,6 @@ import reborncore.common.BaseTileBlock; import reborncore.common.blocks.IRotationTexture; import techreborn.Core; import techreborn.client.TechRebornCreativeTab; -import techreborn.init.ModBlocks; import java.util.ArrayList; import java.util.Iterator; @@ -48,6 +47,7 @@ public abstract class BlockEnergyStorage extends BaseTileBlock implements IRotat public BlockEnergyStorage(String name, int guiID) { super(Material.rock); + setHardness(2f); setUnlocalizedName("techreborn." + name.toLowerCase()); setCreativeTab(TechRebornCreativeTab.instance); this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH)); @@ -125,23 +125,20 @@ public abstract class BlockEnergyStorage extends BaseTileBlock implements IRotat setFacing(facing, worldIn, pos); } - @Override - public void breakBlock(World worldIn, BlockPos pos, IBlockState state) - { - dropInventory(worldIn, pos); - super.breakBlock(worldIn, pos, state); - } - protected void dropInventory(World world, BlockPos pos) + + protected void dropInventory(World world, BlockPos pos, ItemStack itemToDrop) { TileEntity tileEntity = world.getTileEntity(pos); if (tileEntity == null) { + System.out.print("Null"); return; } if (!(tileEntity instanceof IInventory)) { + return; } @@ -171,7 +168,7 @@ public abstract class BlockEnergyStorage extends BaseTileBlock implements IRotat } items.add(itemStack.copy()); } - + items.add(itemToDrop); for (ItemStack itemStack : items) { Random rand = new Random(); @@ -195,6 +192,7 @@ public abstract class BlockEnergyStorage extends BaseTileBlock implements IRotat world.spawnEntityInWorld(entityItem); itemStack.stackSize = 0; } + } @@ -270,7 +268,6 @@ public abstract class BlockEnergyStorage extends BaseTileBlock implements IRotat public List getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) { List items = new ArrayList(); - items.add(new ItemStack(ModBlocks.machineframe)); return items; } diff --git a/src/main/java/techreborn/blocks/storage/BlockMFE.java b/src/main/java/techreborn/blocks/storage/BlockMFE.java index a9f51cd2b..7ff015e35 100644 --- a/src/main/java/techreborn/blocks/storage/BlockMFE.java +++ b/src/main/java/techreborn/blocks/storage/BlockMFE.java @@ -1,8 +1,12 @@ package techreborn.blocks.storage; +import net.minecraft.block.state.IBlockState; +import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import techreborn.client.GuiHandler; +import techreborn.init.ModBlocks; import techreborn.tiles.storage.TileMFE; /** @@ -20,5 +24,10 @@ public class BlockMFE extends BlockEnergyStorage { return new TileMFE(); } - + @Override + public void breakBlock(World worldIn, BlockPos pos, IBlockState state) + { + dropInventory(worldIn, pos, new ItemStack(ModBlocks.machineframe)); + super.breakBlock(worldIn, pos, state); + } } diff --git a/src/main/java/techreborn/blocks/storage/BlockMFSU.java b/src/main/java/techreborn/blocks/storage/BlockMFSU.java index c73e0c00d..9ee9d14c1 100644 --- a/src/main/java/techreborn/blocks/storage/BlockMFSU.java +++ b/src/main/java/techreborn/blocks/storage/BlockMFSU.java @@ -1,8 +1,12 @@ package techreborn.blocks.storage; +import net.minecraft.block.state.IBlockState; +import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import techreborn.client.GuiHandler; +import techreborn.init.ModBlocks; import techreborn.tiles.storage.TileMFSU; /** @@ -13,6 +17,7 @@ public class BlockMFSU extends BlockEnergyStorage public BlockMFSU() { super("MFSU", GuiHandler.mfsuID); + setHardness(2f); } @Override @@ -21,4 +26,11 @@ public class BlockMFSU extends BlockEnergyStorage return new TileMFSU(); } + @Override + public void breakBlock(World worldIn, BlockPos pos, IBlockState state) + { + dropInventory(worldIn, pos, new ItemStack(ModBlocks.machineframe, 1 ,7)); + super.breakBlock(worldIn, pos, state); + } + } diff --git a/src/main/java/techreborn/blocks/transformers/BlockHVTransformer.java b/src/main/java/techreborn/blocks/transformers/BlockHVTransformer.java index e15a3b38c..5041e8dbc 100644 --- a/src/main/java/techreborn/blocks/transformers/BlockHVTransformer.java +++ b/src/main/java/techreborn/blocks/transformers/BlockHVTransformer.java @@ -1,10 +1,18 @@ package techreborn.blocks.transformers; +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import techreborn.client.TechRebornCreativeTab; +import techreborn.init.ModBlocks; import techreborn.tiles.transformers.TileHVTransformer; +import java.util.Random; + /** * Created by modmuss50 on 16/03/2016. */ @@ -53,5 +61,31 @@ public class BlockHVTransformer extends BlockLVTransformer { return prefix + "hv_transformer_bottom"; } + @Override + public void breakBlock(World world, BlockPos pos, IBlockState state) + { + ItemStack itemStack = new ItemStack(ModBlocks.machineframe, 1 ,7); + Random rand = new Random(); + + float dX = rand.nextFloat() * 0.8F + 0.1F; + float dY = rand.nextFloat() * 0.8F + 0.1F; + float dZ = rand.nextFloat() * 0.8F + 0.1F; + + EntityItem entityItem = new EntityItem(world, pos.getX() + dX, pos.getY() + dY, pos.getZ() + dZ, + itemStack.copy()); + + if (itemStack.hasTagCompound()) + { + entityItem.getEntityItem().setTagCompound((NBTTagCompound) itemStack.getTagCompound().copy()); + } + + float factor = 0.05F; + entityItem.motionX = rand.nextGaussian() * factor; + entityItem.motionY = rand.nextGaussian() * factor + 0.2F; + entityItem.motionZ = rand.nextGaussian() * factor; + world.spawnEntityInWorld(entityItem); + itemStack.stackSize = 0; + } + } diff --git a/src/main/java/techreborn/blocks/transformers/BlockLVTransformer.java b/src/main/java/techreborn/blocks/transformers/BlockLVTransformer.java index 0e76b27d8..aab14b4a8 100644 --- a/src/main/java/techreborn/blocks/transformers/BlockLVTransformer.java +++ b/src/main/java/techreborn/blocks/transformers/BlockLVTransformer.java @@ -1,11 +1,18 @@ package techreborn.blocks.transformers; +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import techreborn.blocks.storage.BlockBatBox; import techreborn.client.TechRebornCreativeTab; import techreborn.tiles.transformers.TileLVTransformer; +import java.util.Random; + /** * Created by modmuss50 on 16/03/2016. */ @@ -54,4 +61,30 @@ public class BlockLVTransformer extends BlockBatBox { return prefix + "lv_transformer_side"; } + @Override + public void breakBlock(World world, BlockPos pos, IBlockState state) + { + ItemStack itemStack = new ItemStack(this); + + Random rand = new Random(); + + float dX = rand.nextFloat() * 0.8F + 0.1F; + float dY = rand.nextFloat() * 0.8F + 0.1F; + float dZ = rand.nextFloat() * 0.8F + 0.1F; + + EntityItem entityItem = new EntityItem(world, pos.getX() + dX, pos.getY() + dY, pos.getZ() + dZ, + itemStack.copy()); + + if (itemStack.hasTagCompound()) + { + entityItem.getEntityItem().setTagCompound((NBTTagCompound) itemStack.getTagCompound().copy()); + } + + float factor = 0.05F; + entityItem.motionX = rand.nextGaussian() * factor; + entityItem.motionY = rand.nextGaussian() * factor + 0.2F; + entityItem.motionZ = rand.nextGaussian() * factor; + world.spawnEntityInWorld(entityItem); + itemStack.stackSize = 0; + } } diff --git a/src/main/java/techreborn/blocks/transformers/BlockMVTransformer.java b/src/main/java/techreborn/blocks/transformers/BlockMVTransformer.java index 58b1b9037..f04a12330 100644 --- a/src/main/java/techreborn/blocks/transformers/BlockMVTransformer.java +++ b/src/main/java/techreborn/blocks/transformers/BlockMVTransformer.java @@ -1,10 +1,18 @@ package techreborn.blocks.transformers; +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import techreborn.client.TechRebornCreativeTab; +import techreborn.init.ModBlocks; import techreborn.tiles.transformers.TileMVTransformer; +import java.util.Random; + /** * Created by modmuss50 on 16/03/2016. */ @@ -53,4 +61,31 @@ public class BlockMVTransformer extends BlockLVTransformer { return prefix + "mv_transformer_side"; } + @Override + public void breakBlock(World world, BlockPos pos, IBlockState state) + { + ItemStack itemStack = new ItemStack(ModBlocks.machineframe); + itemStack.setItemDamage(6); + Random rand = new Random(); + + float dX = rand.nextFloat() * 0.8F + 0.1F; + float dY = rand.nextFloat() * 0.8F + 0.1F; + float dZ = rand.nextFloat() * 0.8F + 0.1F; + + EntityItem entityItem = new EntityItem(world, pos.getX() + dX, pos.getY() + dY, pos.getZ() + dZ, + itemStack.copy()); + + if (itemStack.hasTagCompound()) + { + entityItem.getEntityItem().setTagCompound((NBTTagCompound) itemStack.getTagCompound().copy()); + } + + float factor = 0.05F; + entityItem.motionX = rand.nextGaussian() * factor; + entityItem.motionY = rand.nextGaussian() * factor + 0.2F; + entityItem.motionZ = rand.nextGaussian() * factor; + world.spawnEntityInWorld(entityItem); + itemStack.stackSize = 0; + super.breakBlock(world, pos, state); + } } diff --git a/src/main/java/techreborn/tiles/storage/TileBatBox.java b/src/main/java/techreborn/tiles/storage/TileBatBox.java index c35851356..39f5e4736 100644 --- a/src/main/java/techreborn/tiles/storage/TileBatBox.java +++ b/src/main/java/techreborn/tiles/storage/TileBatBox.java @@ -1,139 +1,16 @@ package techreborn.tiles.storage; -import ic2.api.tile.IWrenchable; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.ITickable; import reborncore.api.power.EnumPowerTier; -import reborncore.api.power.IEnergyItemInfo; -import reborncore.common.powerSystem.PoweredItem; -import reborncore.common.powerSystem.TilePowerAcceptor; -import reborncore.common.util.Inventory; import techreborn.init.ModBlocks; /** * Created by modmuss50 on 14/03/2016. */ -public class TileBatBox extends TilePowerAcceptor implements IWrenchable, ITickable +public class TileBatBox extends TileEnergyStorage { - public Inventory inventory = new Inventory(2, "TileBatBox", 64, this); public TileBatBox() { - super(1); - } - - @Override - public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, EnumFacing side) - { - return true; - } - - @Override - public EnumFacing getFacing() - { - return getFacingEnum(); - } - - @Override - public boolean wrenchCanRemove(EntityPlayer entityPlayer) - { - if (entityPlayer.isSneaking()) - { - return true; - } - return false; - } - - @Override public void updateEntity() - { - if(inventory.getStackInSlot(0) != null){ - ItemStack stack = inventory.getStackInSlot(0); - IEnergyItemInfo item = (IEnergyItemInfo) inventory.getStackInSlot(0).getItem(); - if(PoweredItem.getEnergy(stack) != PoweredItem.getMaxPower(stack)){ - if(canUseEnergy(item.getMaxTransfer(stack))) - { - useEnergy(item.getMaxTransfer(stack)); - PoweredItem.setEnergy(PoweredItem.getEnergy(stack) + item.getMaxTransfer(stack), stack); - } - } - }if(inventory.getStackInSlot(1) != null){ - ItemStack stack = inventory.getStackInSlot(1); - IEnergyItemInfo item = (IEnergyItemInfo) stack.getItem(); - if(item.canProvideEnergy(stack)){ - if(getEnergy() != getMaxPower()) - { - addEnergy(item.getMaxTransfer(stack)); - PoweredItem.setEnergy(PoweredItem.getEnergy(stack) - item.getMaxTransfer(stack), stack); - } - } - } - } - - @Override - public float getWrenchDropRate() - { - return 1.0F; - } - - @Override - public ItemStack getWrenchDrop(EntityPlayer entityPlayer) - { - return new ItemStack(ModBlocks.batBox); - } - - public boolean isComplete() - { - return false; - } - - @Override - public double getMaxPower() - { - return 40000; - } - - @Override - public boolean canAcceptEnergy(EnumFacing direction) - { - return getFacingEnum() != direction; - } - - @Override - public boolean canProvideEnergy(EnumFacing direction) - { - return getFacingEnum() == direction; - } - - @Override - public double getMaxOutput() - { - return 32; - } - - @Override - public double getMaxInput() - { - return 32; - } - - @Override - public EnumPowerTier getTier() - { - return EnumPowerTier.LOW; - } - @Override - public void writeToNBT(NBTTagCompound tagCompound) - { - super.writeToNBT(tagCompound); - inventory.writeToNBT(tagCompound); - } - @Override - public void readFromNBT(NBTTagCompound nbttagcompound) - { - super.readFromNBT(nbttagcompound); - inventory.readFromNBT(nbttagcompound); + super("BatBox", 2, ModBlocks.batBox, EnumPowerTier.LOW, 32, 32, 4000); } } \ No newline at end of file diff --git a/src/main/java/techreborn/tiles/storage/TileEnergyStorage.java b/src/main/java/techreborn/tiles/storage/TileEnergyStorage.java new file mode 100644 index 000000000..ee99d4a32 --- /dev/null +++ b/src/main/java/techreborn/tiles/storage/TileEnergyStorage.java @@ -0,0 +1,141 @@ +package techreborn.tiles.storage; + +import ic2.api.tile.IWrenchable; +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.ITickable; +import reborncore.api.power.EnumPowerTier; +import reborncore.api.power.IEnergyItemInfo; +import reborncore.common.powerSystem.PoweredItem; +import reborncore.common.powerSystem.TilePowerAcceptor; +import reborncore.common.util.Inventory; + +/** + * Created by Rushmead + */ +public class TileEnergyStorage extends TilePowerAcceptor implements IWrenchable, ITickable +{ + + public Inventory inventory; + public String name; + public Block wrenchDrop; + public EnumPowerTier tier; + public int maxInput; + public int maxOutput; + public int maxStorage; + public TileEnergyStorage(String name, int invSize, Block wrenchDrop, EnumPowerTier tier, int maxInput, int maxOuput, int maxStorage) + { + super(1); + inventory = new Inventory(invSize, "Tile" + name, 64, this); + this.wrenchDrop = wrenchDrop; + this.tier = tier; + this.name = name; + this.maxInput = maxInput; + this.maxOutput = maxOuput; + this.maxStorage = maxStorage; + } + + @Override public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, EnumFacing side) + { + return true; + } + + @Override public EnumFacing getFacing() + { + return getFacingEnum(); + } + + @Override public boolean wrenchCanRemove(EntityPlayer entityPlayer) + { + if (entityPlayer.isSneaking()) + { + return true; + } + return false; + } + + @Override public void updateEntity() + { + if (inventory.getStackInSlot(0) != null) + { + ItemStack stack = inventory.getStackInSlot(0); + IEnergyItemInfo item = (IEnergyItemInfo) inventory.getStackInSlot(0).getItem(); + if (PoweredItem.getEnergy(stack) != PoweredItem.getMaxPower(stack)) + { + if (canUseEnergy(item.getMaxTransfer(stack))) + { + useEnergy(item.getMaxTransfer(stack)); + PoweredItem.setEnergy(PoweredItem.getEnergy(stack) + item.getMaxTransfer(stack), stack); + } + } + } + if (inventory.getStackInSlot(1) != null) + { + ItemStack stack = inventory.getStackInSlot(1); + IEnergyItemInfo item = (IEnergyItemInfo) stack.getItem(); + if (item.canProvideEnergy(stack)) + { + if (getEnergy() != getMaxPower()) + { + addEnergy(item.getMaxTransfer(stack)); + PoweredItem.setEnergy(PoweredItem.getEnergy(stack) - item.getMaxTransfer(stack), stack); + } + } + } + } + + @Override public float getWrenchDropRate() + { + return 1.0F; + } + + @Override public ItemStack getWrenchDrop(EntityPlayer entityPlayer) + { + return new ItemStack(wrenchDrop); + } + + @Override public double getMaxPower() + { + return maxStorage; + } + + @Override public boolean canAcceptEnergy(EnumFacing direction) + { + return getFacingEnum() != direction; + } + + @Override public boolean canProvideEnergy(EnumFacing direction) + { + return getFacingEnum() == direction; + } + + @Override public double getMaxOutput() + { + return maxOutput; + } + + @Override public double getMaxInput() + { + return maxInput; + } + + @Override public EnumPowerTier getTier() + { + return tier; + } + + @Override public void writeToNBT(NBTTagCompound tagCompound) + { + super.writeToNBT(tagCompound); + inventory.writeToNBT(tagCompound); + } + + @Override public void readFromNBT(NBTTagCompound nbttagcompound) + { + super.readFromNBT(nbttagcompound); + inventory.readFromNBT(nbttagcompound); + } +} \ No newline at end of file diff --git a/src/main/java/techreborn/tiles/storage/TileMFE.java b/src/main/java/techreborn/tiles/storage/TileMFE.java index cf9496f21..c5144f6ae 100644 --- a/src/main/java/techreborn/tiles/storage/TileMFE.java +++ b/src/main/java/techreborn/tiles/storage/TileMFE.java @@ -1,43 +1,16 @@ package techreborn.tiles.storage; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; import reborncore.api.power.EnumPowerTier; import techreborn.init.ModBlocks; /** * Created by modmuss50 on 14/03/2016. */ -public class TileMFE extends TileBatBox +public class TileMFE extends TileEnergyStorage { - @Override - public ItemStack getWrenchDrop(EntityPlayer entityPlayer) + public TileMFE() { - return new ItemStack(ModBlocks.mfe); + super("MFE", 2, ModBlocks.mfe, EnumPowerTier.MEDIUM, 512, 512, 4000000); } - - @Override - public double getMaxPower() - { - return 4000000; - } - - @Override - public double getMaxOutput() - { - return 512; - } - - @Override - public double getMaxInput() - { - return 512; - } - - @Override - public EnumPowerTier getTier() - { - return EnumPowerTier.MEDIUM; - } -} +} \ No newline at end of file diff --git a/src/main/java/techreborn/tiles/storage/TileMFSU.java b/src/main/java/techreborn/tiles/storage/TileMFSU.java index c2e50e463..4bfe9d10c 100644 --- a/src/main/java/techreborn/tiles/storage/TileMFSU.java +++ b/src/main/java/techreborn/tiles/storage/TileMFSU.java @@ -1,43 +1,16 @@ package techreborn.tiles.storage; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; import reborncore.api.power.EnumPowerTier; import techreborn.init.ModBlocks; /** * Created by modmuss50 on 14/03/2016. */ -public class TileMFSU extends TileBatBox +public class TileMFSU extends TileEnergyStorage { - @Override - public ItemStack getWrenchDrop(EntityPlayer entityPlayer) + public TileMFSU() { - return new ItemStack(ModBlocks.mfsu); + super("MFSU", 2, ModBlocks.mfsu, EnumPowerTier.HIGH, 2048, 2048, 40000000); } - - @Override - public double getMaxPower() - { - return 40000000; - } - - @Override - public double getMaxOutput() - { - return 2048; - } - - @Override - public double getMaxInput() - { - return 2048; - } - - @Override - public EnumPowerTier getTier() - { - return EnumPowerTier.HIGH; - } -} +} \ No newline at end of file