Make arcane workbench drop items correctly when broken, fixes #20
This commit is contained in:
@@ -1,17 +1,13 @@
|
|||||||
package electroblob.wizardry.block;
|
package electroblob.wizardry.block;
|
||||||
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import electroblob.wizardry.Wizardry;
|
import electroblob.wizardry.Wizardry;
|
||||||
import electroblob.wizardry.WizardryGuiHandler;
|
import electroblob.wizardry.WizardryGuiHandler;
|
||||||
import electroblob.wizardry.tileentity.TileEntityArcaneWorkbench;
|
import electroblob.wizardry.tileentity.TileEntityArcaneWorkbench;
|
||||||
import net.minecraft.block.BlockContainer;
|
import net.minecraft.block.BlockContainer;
|
||||||
import net.minecraft.block.material.Material;
|
import net.minecraft.block.material.Material;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.entity.item.EntityItem;
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.inventory.InventoryHelper;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.EnumBlockRenderType;
|
import net.minecraft.util.EnumBlockRenderType;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
@@ -65,59 +61,20 @@ public class BlockArcaneWorkbench extends BlockContainer {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
player.openGui(Wizardry.instance, WizardryGuiHandler.ARCANE_WORKBENCH, world, pos.getX(), pos.getY(),
|
player.openGui(Wizardry.instance, WizardryGuiHandler.ARCANE_WORKBENCH, world, pos.getX(), pos.getY(), pos.getZ());
|
||||||
pos.getZ());
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void breakBlock(World world, BlockPos pos, IBlockState block){
|
public void breakBlock(World world, BlockPos pos, IBlockState block){
|
||||||
|
|
||||||
Random random = new Random();
|
TileEntity tileentity = world.getTileEntity(pos);
|
||||||
TileEntityArcaneWorkbench tileentityarcaneworkbench = (TileEntityArcaneWorkbench)world.getTileEntity(pos);
|
|
||||||
|
|
||||||
if(tileentityarcaneworkbench != null){
|
if(tileentity instanceof TileEntityArcaneWorkbench){
|
||||||
|
InventoryHelper.dropInventoryItems(world, pos, (TileEntityArcaneWorkbench)tileentity);
|
||||||
|
}
|
||||||
|
|
||||||
for(int j1 = 0; j1 < tileentityarcaneworkbench.getSizeInventory(); ++j1){
|
super.breakBlock(world, pos, block);
|
||||||
|
|
||||||
ItemStack itemstack = tileentityarcaneworkbench.getStackInSlot(j1);
|
|
||||||
|
|
||||||
if(!itemstack.isEmpty()){
|
|
||||||
|
|
||||||
float f = random.nextFloat() * 0.8F + 0.1F;
|
|
||||||
float f1 = random.nextFloat() * 0.8F + 0.1F;
|
|
||||||
EntityItem entityitem;
|
|
||||||
|
|
||||||
for(float f2 = random.nextFloat() * 0.8F + 0.1F; itemstack.getCount() > 0; world
|
|
||||||
.spawnEntity(entityitem)){
|
|
||||||
|
|
||||||
int k1 = random.nextInt(21) + 10;
|
|
||||||
|
|
||||||
if(k1 > itemstack.getCount()){
|
|
||||||
k1 = itemstack.getCount();
|
|
||||||
}
|
|
||||||
|
|
||||||
itemstack.shrink(k1);
|
|
||||||
|
|
||||||
entityitem = new EntityItem(world, (double)((float)pos.getX() + f),
|
|
||||||
(double)((float)pos.getY() + f1), (double)((float)pos.getZ() + f2),
|
|
||||||
new ItemStack(itemstack.getItem(), k1, itemstack.getItemDamage()));
|
|
||||||
float f3 = 0.05F;
|
|
||||||
entityitem.motionX = (double)((float)random.nextGaussian() * f3);
|
|
||||||
entityitem.motionY = (double)((float)random.nextGaussian() * f3 + 0.2F);
|
|
||||||
entityitem.motionZ = (double)((float)random.nextGaussian() * f3);
|
|
||||||
|
|
||||||
if(itemstack.hasTagCompound()){
|
|
||||||
entityitem.getItem().setTagCompound(((NBTTagCompound)itemstack.getTagCompound().copy()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// par1World.func_96440_m(par2, par3, par4, block);
|
|
||||||
}
|
|
||||||
|
|
||||||
super.breakBlock(world, pos, block);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user