2015-01-30 20:16:32 +01:00
|
|
|
package ellpeck.someprettyrandomstuff.blocks;
|
2014-12-20 21:34:07 +01:00
|
|
|
|
2015-01-30 20:16:32 +01:00
|
|
|
import ellpeck.someprettyrandomstuff.tile.TileEntityInventoryBase;
|
2014-12-20 21:34:07 +01:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.block.BlockContainer;
|
|
|
|
import net.minecraft.block.material.Material;
|
|
|
|
import net.minecraft.entity.item.EntityItem;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
|
|
|
import java.util.Random;
|
|
|
|
|
|
|
|
public abstract class BlockContainerBase extends BlockContainer{
|
|
|
|
|
|
|
|
public BlockContainerBase(Material mat) {
|
|
|
|
super(mat);
|
|
|
|
}
|
|
|
|
|
|
|
|
public TileEntityInventoryBase dropInventory(World world, int x, int y, int z) {
|
|
|
|
TileEntityInventoryBase tileEntity = (TileEntityInventoryBase) world.getTileEntity(x, y, z);
|
2015-01-29 20:23:19 +01:00
|
|
|
for (int i = 0; i < tileEntity.getSizeInventory(); i++){
|
2014-12-20 21:34:07 +01:00
|
|
|
ItemStack itemStack = tileEntity.getStackInSlot(i);
|
|
|
|
if (itemStack != null && itemStack.stackSize > 0) {
|
|
|
|
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, x + dX, y + dY, z + 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return tileEntity;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void breakBlock(World world, int x, int y, int z, Block block, int meta){
|
2015-01-29 20:23:19 +01:00
|
|
|
if(world.getTileEntity(x, y, z) instanceof TileEntityInventoryBase) this.dropInventory(world, x, y, z);
|
2014-12-20 21:34:07 +01:00
|
|
|
super.breakBlock(world, x, y, z, block, meta);
|
|
|
|
}
|
|
|
|
}
|