2015-03-07 12:51:28 +01:00
|
|
|
package ellpeck.actuallyadditions.blocks;
|
2014-12-20 21:34:07 +01:00
|
|
|
|
2015-03-07 12:51:28 +01:00
|
|
|
import ellpeck.actuallyadditions.tile.TileEntityInventoryBase;
|
2014-12-20 21:34:07 +01:00
|
|
|
import net.minecraft.block.BlockContainer;
|
|
|
|
import net.minecraft.block.material.Material;
|
|
|
|
import net.minecraft.entity.item.EntityItem;
|
2015-05-25 17:00:54 +02:00
|
|
|
import net.minecraft.inventory.Container;
|
|
|
|
import net.minecraft.inventory.IInventory;
|
2014-12-20 21:34:07 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2015-05-25 17:00:54 +02:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2014-12-20 21:34:07 +01:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
|
|
|
import java.util.Random;
|
|
|
|
|
|
|
|
public abstract class BlockContainerBase extends BlockContainer{
|
|
|
|
|
2015-02-09 17:25:05 +01:00
|
|
|
public BlockContainerBase(Material mat){
|
2014-12-20 21:34:07 +01:00
|
|
|
super(mat);
|
|
|
|
}
|
|
|
|
|
2015-06-18 13:14:57 +02:00
|
|
|
public void dropInventory(World world, int x, int y, int z){
|
2015-06-28 03:12:32 +02:00
|
|
|
if(!world.isRemote){
|
|
|
|
TileEntity tile = world.getTileEntity(x, y, z);
|
|
|
|
if(tile instanceof TileEntityInventoryBase){
|
|
|
|
TileEntityInventoryBase tileEntity = (TileEntityInventoryBase)tile;
|
|
|
|
if(tileEntity.getSizeInventory() > 0){
|
2015-07-10 13:08:20 +02:00
|
|
|
Random rand = new Random();
|
2015-06-28 03:12:32 +02:00
|
|
|
for(int i = 0; i < tileEntity.getSizeInventory(); i++){
|
|
|
|
ItemStack itemStack = tileEntity.getStackInSlot(i);
|
|
|
|
if(itemStack != null && itemStack.stackSize > 0){
|
|
|
|
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;
|
|
|
|
}
|
2015-06-18 13:14:57 +02:00
|
|
|
}
|
|
|
|
}
|
2014-12-20 21:34:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-05-25 17:00:54 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasComparatorInputOverride(){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getComparatorInputOverride(World world, int x, int y, int z, int meta){
|
|
|
|
TileEntity tile = world.getTileEntity(x, y, z);
|
|
|
|
if(tile instanceof IInventory) return Container.calcRedstoneFromInventory((IInventory)tile);
|
|
|
|
return 0;
|
|
|
|
}
|
2014-12-20 21:34:07 +01:00
|
|
|
}
|