diff --git a/src/main/java/techreborn/blocks/storage/BlockBatBox.java b/src/main/java/techreborn/blocks/storage/BlockBatBox.java index bc60f399f..9ac63c696 100644 --- a/src/main/java/techreborn/blocks/storage/BlockBatBox.java +++ b/src/main/java/techreborn/blocks/storage/BlockBatBox.java @@ -1,13 +1,20 @@ package techreborn.blocks.storage; 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.IBlockAccess; import net.minecraft.world.World; import techreborn.client.GuiHandler; import techreborn.tiles.storage.TileBatBox; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + /** * Created by modmuss50 on 14/03/2016. */ @@ -26,6 +33,34 @@ public class BlockBatBox extends BlockEnergyStorage @Override public void breakBlock(World worldIn, BlockPos pos, IBlockState state) { - dropInventory(worldIn, pos, new ItemStack(this)); + ArrayList items = (ArrayList) dropInventory(worldIn, pos, new ItemStack(this)); + for(ItemStack itemStack : items){ + 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(worldIn, 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; + worldIn.spawnEntityInWorld(entityItem); + itemStack.stackSize = 0; + } + } + + @Override public List getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) + { + + return new ArrayList(); } } diff --git a/src/main/java/techreborn/blocks/storage/BlockEnergyStorage.java b/src/main/java/techreborn/blocks/storage/BlockEnergyStorage.java index b015e9d05..01815518c 100644 --- a/src/main/java/techreborn/blocks/storage/BlockEnergyStorage.java +++ b/src/main/java/techreborn/blocks/storage/BlockEnergyStorage.java @@ -11,12 +11,10 @@ import net.minecraft.block.properties.PropertyDirection; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; @@ -127,19 +125,20 @@ public abstract class BlockEnergyStorage extends BaseTileBlock implements IRotat - protected void dropInventory(World world, BlockPos pos, ItemStack itemToDrop) + protected List dropInventory(IBlockAccess world, BlockPos pos, ItemStack itemToDrop) { TileEntity tileEntity = world.getTileEntity(pos); if (tileEntity == null) { System.out.print("Null"); - return; + return null; } if (!(tileEntity instanceof IInventory)) { - return; + System.out.print("Not INstance"); + return null; } IInventory inventory = (IInventory) tileEntity; @@ -168,30 +167,8 @@ public abstract class BlockEnergyStorage extends BaseTileBlock implements IRotat } items.add(itemStack.copy()); } - items.add(itemToDrop); - for (ItemStack itemStack : items) - { - 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; - } + items.add(itemToDrop.copy()); + return items; } @@ -264,12 +241,6 @@ public abstract class BlockEnergyStorage extends BaseTileBlock implements IRotat return 0; } - @Override - public List getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) - { - List items = new ArrayList(); - return items; - } @Override public String getFrontOff() diff --git a/src/main/java/techreborn/blocks/storage/BlockMFE.java b/src/main/java/techreborn/blocks/storage/BlockMFE.java index 7ff015e35..1ee75d563 100644 --- a/src/main/java/techreborn/blocks/storage/BlockMFE.java +++ b/src/main/java/techreborn/blocks/storage/BlockMFE.java @@ -1,14 +1,21 @@ package techreborn.blocks.storage; 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.IBlockAccess; import net.minecraft.world.World; import techreborn.client.GuiHandler; import techreborn.init.ModBlocks; import techreborn.tiles.storage.TileMFE; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + /** * Created by modmuss50 on 14/03/2016. */ @@ -27,7 +34,34 @@ public class BlockMFE extends BlockEnergyStorage @Override public void breakBlock(World worldIn, BlockPos pos, IBlockState state) { - dropInventory(worldIn, pos, new ItemStack(ModBlocks.machineframe)); - super.breakBlock(worldIn, pos, state); + ArrayList items = (ArrayList) dropInventory(worldIn, pos, new ItemStack(ModBlocks.machineframe, 1 , 6)); + for(ItemStack itemStack : items){ + 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(worldIn, 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; + worldIn.spawnEntityInWorld(entityItem); + itemStack.stackSize = 0; + } + } + + @Override public List getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) + { + + return new ArrayList(); } } diff --git a/src/main/java/techreborn/blocks/storage/BlockMFSU.java b/src/main/java/techreborn/blocks/storage/BlockMFSU.java index 9ee9d14c1..a50ed75db 100644 --- a/src/main/java/techreborn/blocks/storage/BlockMFSU.java +++ b/src/main/java/techreborn/blocks/storage/BlockMFSU.java @@ -1,14 +1,21 @@ package techreborn.blocks.storage; 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.IBlockAccess; import net.minecraft.world.World; import techreborn.client.GuiHandler; import techreborn.init.ModBlocks; import techreborn.tiles.storage.TileMFSU; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + /** * Created by modmuss50 on 14/03/2016. */ @@ -29,8 +36,34 @@ public class BlockMFSU extends BlockEnergyStorage @Override public void breakBlock(World worldIn, BlockPos pos, IBlockState state) { - dropInventory(worldIn, pos, new ItemStack(ModBlocks.machineframe, 1 ,7)); - super.breakBlock(worldIn, pos, state); + ArrayList items = (ArrayList) dropInventory(worldIn, pos, new ItemStack(ModBlocks.machineframe, 1 , 7)); + for(ItemStack itemStack : items){ + 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(worldIn, 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; + worldIn.spawnEntityInWorld(entityItem); + itemStack.stackSize = 0; + } } + @Override public List getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) + { + + return new ArrayList(); + } } diff --git a/src/main/java/techreborn/tiles/storage/TileEnergyStorage.java b/src/main/java/techreborn/tiles/storage/TileEnergyStorage.java index ee99d4a32..132cb10ab 100644 --- a/src/main/java/techreborn/tiles/storage/TileEnergyStorage.java +++ b/src/main/java/techreborn/tiles/storage/TileEnergyStorage.java @@ -3,10 +3,12 @@ package techreborn.tiles.storage; import ic2.api.tile.IWrenchable; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumFacing; import net.minecraft.util.ITickable; +import net.minecraft.util.text.ITextComponent; import reborncore.api.power.EnumPowerTier; import reborncore.api.power.IEnergyItemInfo; import reborncore.common.powerSystem.PoweredItem; @@ -16,7 +18,7 @@ import reborncore.common.util.Inventory; /** * Created by Rushmead */ -public class TileEnergyStorage extends TilePowerAcceptor implements IWrenchable, ITickable +public class TileEnergyStorage extends TilePowerAcceptor implements IWrenchable, ITickable, IInventory { public Inventory inventory; @@ -138,4 +140,89 @@ public class TileEnergyStorage extends TilePowerAcceptor implements IWrenchable, super.readFromNBT(nbttagcompound); inventory.readFromNBT(nbttagcompound); } + + @Override public int getSizeInventory() + { + return 2; + } + + @Override public ItemStack getStackInSlot(int index) + { + return inventory.getStackInSlot(index); + } + + @Override public ItemStack decrStackSize(int index, int count) + { + return inventory.decrStackSize(index, count); + } + + @Override public ItemStack removeStackFromSlot(int index) + { + return inventory.removeStackFromSlot(index); + } + + @Override public void setInventorySlotContents(int index, ItemStack stack) + { + inventory.setInventorySlotContents(index, stack); + } + + @Override public int getInventoryStackLimit() + { + return inventory.getInventoryStackLimit(); + } + + @Override public boolean isUseableByPlayer(EntityPlayer player) + { + return inventory.isUseableByPlayer(player); + } + + @Override public void openInventory(EntityPlayer player) + { + inventory.openInventory(player); + } + + @Override public void closeInventory(EntityPlayer player) + { + inventory.closeInventory(player); + } + + @Override public boolean isItemValidForSlot(int index, ItemStack stack) + { + return inventory.isItemValidForSlot(index, stack); + } + + @Override public int getField(int id) + { + return inventory.getField(id); + } + + @Override public void setField(int id, int value) + { + inventory.setField(id, value); + } + + @Override public int getFieldCount() + { + return inventory.getFieldCount(); + } + + @Override public void clear() + { + inventory.clear(); + } + + @Override public String getName() + { + return inventory.getName(); + } + + @Override public boolean hasCustomName() + { + return inventory.hasCustomName(); + } + + @Override public ITextComponent getDisplayName() + { + return inventory.getDisplayName(); + } } \ 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 c5144f6ae..4f89d950c 100644 --- a/src/main/java/techreborn/tiles/storage/TileMFE.java +++ b/src/main/java/techreborn/tiles/storage/TileMFE.java @@ -13,4 +13,5 @@ public class TileMFE extends TileEnergyStorage { super("MFE", 2, ModBlocks.mfe, EnumPowerTier.MEDIUM, 512, 512, 4000000); } + } \ No newline at end of file