Improved Item Dropping from TileEntities just because it was bugging me

This commit is contained in:
Ellpeck 2015-09-13 19:39:02 +02:00
parent 5092c1dab7
commit 4f0ed425a3
3 changed files with 29 additions and 46 deletions

View file

@ -31,33 +31,36 @@ public abstract class BlockContainerBase extends BlockContainer{
public void dropInventory(World world, int x, int y, int z){ public void dropInventory(World world, int x, int y, int z){
if(!world.isRemote){ if(!world.isRemote){
TileEntity tile = world.getTileEntity(x, y, z); TileEntity aTile = world.getTileEntity(x, y, z);
if(tile instanceof TileEntityInventoryBase){ if(aTile instanceof TileEntityInventoryBase){
TileEntityInventoryBase tileEntity = (TileEntityInventoryBase)tile; TileEntityInventoryBase tile = (TileEntityInventoryBase)aTile;
if(tileEntity.getSizeInventory() > 0){ if(tile.getSizeInventory() > 0){
Random rand = new Random(); for(int i = 0; i < tile.getSizeInventory(); i++){
for(int i = 0; i < tileEntity.getSizeInventory(); i++){ this.dropSlotFromInventory(i, tile, world, x, y, z);
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;
}
tileEntity.setInventorySlotContents(i, null);
} }
} }
} }
} }
} }
public void dropSlotFromInventory(int i, TileEntityInventoryBase tile, World world, int x, int y, int z){
Random rand = new Random();
ItemStack stack = tile.getStackInSlot(i);
if(stack != null && stack.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, stack.copy());
if(stack.hasTagCompound()) entityItem.getEntityItem().setTagCompound((NBTTagCompound)stack.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);
}
tile.setInventorySlotContents(i, null);
}
@Override @Override
public boolean hasComparatorInputOverride(){ public boolean hasComparatorInputOverride(){
return true; return true;

View file

@ -22,12 +22,10 @@ import ellpeck.actuallyadditions.util.StringUtil;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumRarity; import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon; import net.minecraft.util.IIcon;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -79,26 +77,10 @@ public class BlockInputter extends BlockContainerBase implements INameableItem{
@Override @Override
public void breakBlock(World world, int x, int y, int z, Block block, int par6){ public void breakBlock(World world, int x, int y, int z, Block block, int par6){
if(!world.isRemote){ if(!world.isRemote){
TileEntity tile = world.getTileEntity(x, y, z); TileEntity aTile = world.getTileEntity(x, y, z);
if(tile instanceof TileEntityInventoryBase){ if(aTile instanceof TileEntityInventoryBase){
TileEntityInventoryBase tileEntity = (TileEntityInventoryBase)tile; TileEntityInventoryBase tile = (TileEntityInventoryBase)aTile;
Random rand = new Random(); this.dropSlotFromInventory(0, tile, world, x, y, z);
ItemStack itemStack = tileEntity.getStackInSlot(0);
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;
}
tileEntity.setInventorySlotContents(0, null);
} }
} }
super.breakBlock(world, x, y, z, block, par6); super.breakBlock(world, x, y, z, block, par6);

View file

@ -11,7 +11,6 @@
package ellpeck.actuallyadditions.blocks.render; package ellpeck.actuallyadditions.blocks.render;
import ellpeck.actuallyadditions.config.values.ConfigIntValues; import ellpeck.actuallyadditions.config.values.ConfigIntValues;
import ellpeck.actuallyadditions.tile.TileEntityCompost;
import net.minecraft.client.model.ModelRenderer; import net.minecraft.client.model.ModelRenderer;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
@ -57,7 +56,6 @@ public class ModelCompost extends ModelBaseAA{
@Override @Override
public void renderExtra(float f, TileEntity tile){ public void renderExtra(float f, TileEntity tile){
TileEntityCompost tileCompost = (TileEntityCompost)tile;
int meta = tile.getWorldObj().getBlockMetadata(tile.xCoord, tile.yCoord, tile.zCoord); int meta = tile.getWorldObj().getBlockMetadata(tile.xCoord, tile.yCoord, tile.zCoord);
if(meta > 0 && meta <= ConfigIntValues.COMPOST_AMOUNT.getValue()){ if(meta > 0 && meta <= ConfigIntValues.COMPOST_AMOUNT.getValue()){
int heightToDisplay = meta*13/ConfigIntValues.COMPOST_AMOUNT.getValue(); int heightToDisplay = meta*13/ConfigIntValues.COMPOST_AMOUNT.getValue();
@ -65,7 +63,7 @@ public class ModelCompost extends ModelBaseAA{
this.innerRawList[heightToDisplay-1].render(f); this.innerRawList[heightToDisplay-1].render(f);
} }
if(meta == ConfigIntValues.COMPOST_AMOUNT.getValue()+1){ else if(meta == ConfigIntValues.COMPOST_AMOUNT.getValue()+1){
this.innerDone.render(f); this.innerDone.render(f);
} }
} }