Fixes and drop items on break

This commit is contained in:
Justin Aquadro committed 2014-08-25 01:54:08 -04:00
1 parent caeb17d4ac
commit 5b33673956
4 files changed
+83 -6

No files matched your search

@@ -12,6 +12,7 @@ import net.minecraft.block.BlockContainer;
import net.minecraft.block.BlockWood;
import net.minecraft.block.material.Material;
import net.minecraft.client.Minecraft;
import net.minecraft.client.particle.EffectRenderer;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
@@ -20,6 +21,7 @@ import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.IIcon;
@@ -29,6 +31,7 @@ import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import java.util.List;
import java.util.Random;
public class BlockDrawers extends BlockContainer implements IExtendedBlockClickHandler
{
@@ -57,7 +60,7 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH
this.halfDepth = halfDepth;
setCreativeTab(ModCreativeTabs.tabStorageDrawers);
setHardness(2.5f);
setHardness(5f);
setStepSound(Block.soundTypeWood);
setBlockName(blockName);
}
@@ -244,6 +247,52 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH
return super.removedByPlayer(world, player, x, y, z);
}
@Override
public void breakBlock (World world, int x, int y, int z, Block block, int meta) {
TileEntityDrawers tile = getTileEntity(world, x, y, z);
if (tile != null) {
for (int i = 0; i < tile.getDrawerCount(); i++) {
while (tile.getItemCount(i) > 0) {
ItemStack stack = tile.takeItemsFromSlot(i, tile.getStackSize(i));
if (stack == null || stack.stackSize == 0)
break;
dropStackInBatches(world, x, y, z, stack);
}
}
world.func_147453_f(x, y, z, block);
}
super.breakBlock(world, x, y, z, block, meta);
}
private void dropStackInBatches (World world, int x, int y, int z, ItemStack stack) {
Random rand = world.rand;
float ex = rand.nextFloat() * .8f + .1f;
float ey = rand.nextFloat() * .8f + .1f;
float ez = rand.nextFloat() * .8f + .1f;
EntityItem entity;
for (; stack.stackSize > 0; world.spawnEntityInWorld(entity)) {
int stackPartSize = rand.nextInt(21) + 10;
if (stackPartSize > stack.stackSize)
stackPartSize = stack.stackSize;
stack.stackSize -= stackPartSize;
entity = new EntityItem(world, x + ex, y + ey, z + ez, new ItemStack(stack.getItem(), stackPartSize, stack.getItemDamage()));
float motionUnit = .05f;
entity.motionX = rand.nextGaussian() * motionUnit;
entity.motionY = rand.nextGaussian() * motionUnit + .2f;
entity.motionZ = rand.nextGaussian() * motionUnit;
if (stack.hasTagCompound())
entity.getEntityItem().setTagCompound((NBTTagCompound)stack.getTagCompound().copy());
}
}
@Override
public TileEntityDrawers createNewTileEntity (World world, int meta) {
return new TileEntityDrawers();
@@ -264,6 +313,26 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH
return tile;
}
@Override
@SideOnly(Side.CLIENT)
public boolean addHitEffects (World worldObj, MovingObjectPosition target, EffectRenderer effectRenderer) {
TileEntity tile = worldObj.getTileEntity(target.blockX, target.blockY, target.blockZ);
if (tile instanceof TileEntityDrawers) {
if (((TileEntityDrawers) tile).getDirection() == target.sideHit)
return true;
}
return super.addHitEffects(worldObj, target, effectRenderer);
}
/*@Override
@SideOnly(Side.CLIENT)
public boolean addDestroyEffects (World world, int x, int y, int z, int meta, EffectRenderer effectRenderer) {
TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof TileEntityDrawers)
return super.addDestroyEffects(world, x, y, z, meta, effectRenderer);
}*/
@Override
public void getSubBlocks (Item item, CreativeTabs creativeTabs, List list) {
for (int i = 0; i < BlockWood.field_150096_a.length; i++)
@@ -89,6 +89,10 @@ public class TileEntityDrawers extends TileEntity
this.direction = direction % 6;
}
public int getDrawerCount () {
return drawerCount;
}
public void setDrawerCount (int count) {
drawerCount = count;
@@ -113,6 +117,10 @@ public class TileEntityDrawers extends TileEntity
return data[slot].meta;
}
public int getItemCount (int slot) {
return data[slot].count;
}
public int getStackSize (int slot) {
if (data[slot].item == null)
return 0;
@@ -51,15 +51,15 @@ public class TileEntityDrawersRenderer extends TileEntitySpecialRenderer
GL11.glEnable(GL11.GL_LIGHTING);
int drawerCount = 2;
int drawerCount = tileDrawers.getDrawerCount();
double depth = 1;
double unit = .0625;
Block block = tile.getWorldObj().getBlock(tile.xCoord, tile.yCoord, tile.zCoord);
if (block instanceof BlockDrawers) {
if (block instanceof BlockDrawers)
depth = ((BlockDrawers) block).halfDepth ? .5 : 1;
drawerCount = ((BlockDrawers) block).drawerCount;
}
else
return;
itemRenderer.setRenderManager(RenderManager.instance);
@@ -9,7 +9,7 @@ public class ForgeEventHandler
{
@SubscribeEvent
public void playerInteracts (PlayerInteractEvent event) {
if (event.action == PlayerInteractEvent.Action.LEFT_CLICK_BLOCK) {
if (event.action == PlayerInteractEvent.Action.LEFT_CLICK_BLOCK && event.entityPlayer.capabilities.isCreativeMode) {
TileEntity tile = event.world.getTileEntity(event.x, event.y, event.z);
if (tile instanceof TileEntityDrawers) {
int dir = ((TileEntityDrawers) tile).getDirection();