mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-26 08:48:34 +01:00
Improved Item Dropping from TileEntities just because it was bugging me
This commit is contained in:
parent
5092c1dab7
commit
4f0ed425a3
3 changed files with 29 additions and 46 deletions
|
@ -31,31 +31,34 @@ public abstract class BlockContainerBase extends BlockContainer{
|
|||
|
||||
public void dropInventory(World world, int x, int y, int z){
|
||||
if(!world.isRemote){
|
||||
TileEntity tile = world.getTileEntity(x, y, z);
|
||||
if(tile instanceof TileEntityInventoryBase){
|
||||
TileEntityInventoryBase tileEntity = (TileEntityInventoryBase)tile;
|
||||
if(tileEntity.getSizeInventory() > 0){
|
||||
TileEntity aTile = world.getTileEntity(x, y, z);
|
||||
if(aTile instanceof TileEntityInventoryBase){
|
||||
TileEntityInventoryBase tile = (TileEntityInventoryBase)aTile;
|
||||
if(tile.getSizeInventory() > 0){
|
||||
for(int i = 0; i < tile.getSizeInventory(); i++){
|
||||
this.dropSlotFromInventory(i, tile, world, x, y, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void dropSlotFromInventory(int i, TileEntityInventoryBase tile, World world, int x, int y, int z){
|
||||
Random rand = new Random();
|
||||
for(int i = 0; i < tileEntity.getSizeInventory(); i++){
|
||||
ItemStack itemStack = tileEntity.getStackInSlot(i);
|
||||
if(itemStack != null && itemStack.stackSize > 0){
|
||||
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, itemStack.copy());
|
||||
if(itemStack.hasTagCompound()) entityItem.getEntityItem().setTagCompound((NBTTagCompound)itemStack.getTagCompound().copy());
|
||||
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);
|
||||
itemStack.stackSize = 0;
|
||||
}
|
||||
tileEntity.setInventorySlotContents(i, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
tile.setInventorySlotContents(i, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -22,12 +22,10 @@ import ellpeck.actuallyadditions.util.StringUtil;
|
|||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.EnumRarity;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
|
@ -79,26 +77,10 @@ public class BlockInputter extends BlockContainerBase implements INameableItem{
|
|||
@Override
|
||||
public void breakBlock(World world, int x, int y, int z, Block block, int par6){
|
||||
if(!world.isRemote){
|
||||
TileEntity tile = world.getTileEntity(x, y, z);
|
||||
if(tile instanceof TileEntityInventoryBase){
|
||||
TileEntityInventoryBase tileEntity = (TileEntityInventoryBase)tile;
|
||||
Random rand = new Random();
|
||||
|
||||
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);
|
||||
TileEntity aTile = world.getTileEntity(x, y, z);
|
||||
if(aTile instanceof TileEntityInventoryBase){
|
||||
TileEntityInventoryBase tile = (TileEntityInventoryBase)aTile;
|
||||
this.dropSlotFromInventory(0, tile, world, x, y, z);
|
||||
}
|
||||
}
|
||||
super.breakBlock(world, x, y, z, block, par6);
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
package ellpeck.actuallyadditions.blocks.render;
|
||||
|
||||
import ellpeck.actuallyadditions.config.values.ConfigIntValues;
|
||||
import ellpeck.actuallyadditions.tile.TileEntityCompost;
|
||||
import net.minecraft.client.model.ModelRenderer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
|
@ -57,7 +56,6 @@ public class ModelCompost extends ModelBaseAA{
|
|||
|
||||
@Override
|
||||
public void renderExtra(float f, TileEntity tile){
|
||||
TileEntityCompost tileCompost = (TileEntityCompost)tile;
|
||||
int meta = tile.getWorldObj().getBlockMetadata(tile.xCoord, tile.yCoord, tile.zCoord);
|
||||
if(meta > 0 && meta <= 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);
|
||||
}
|
||||
if(meta == ConfigIntValues.COMPOST_AMOUNT.getValue()+1){
|
||||
else if(meta == ConfigIntValues.COMPOST_AMOUNT.getValue()+1){
|
||||
this.innerDone.render(f);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue