Skip to content

Commit

Permalink
Fixed hoppers extracting the frypan
Browse files Browse the repository at this point in the history
Fixed hoppers being able to extract the frying pan making it (hopefully)
impossible to extract/place items into the invisible frying pan slot of
the placed frying pan.
  • Loading branch information
fuj1n committed Sep 8, 2013
1 parent 6ed986c commit c3ebcf4
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 9 deletions.
55 changes: 55 additions & 0 deletions src/tconstruct/blocks/EquipBlock.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
package tconstruct.blocks;

import tconstruct.blocks.logic.EquipLogic;

import net.minecraft.entity.item.EntityItem;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import tconstruct.library.blocks.InventoryLogic;

import java.util.*;

import cpw.mods.fml.relauncher.*;
Expand Down Expand Up @@ -115,6 +122,54 @@ public void onBlockPlacedBy (World par1World, int par2, int par3, int par4, Enti
par1World.setBlockMetadataWithNotify(par2, par3, par4, newMeta, 2);
}

@Override
public void breakBlock (World par1World, int x, int y, int z, int par5, int meta){
TileEntity te = par1World.getBlockTileEntity(x, y, z);

if (te != null && te instanceof EquipLogic)
{
EquipLogic logic = (EquipLogic) te;
for (int iter = 0; iter < logic.getSizeInventory(); ++iter)
{
ItemStack stack = iter == 0 ? logic.getEquipmentItem() : logic.getStackInSlot(iter);

if (stack != null && logic.canDropInventorySlot(iter))
{
float jumpX = rand.nextFloat() * 0.8F + 0.1F;
float jumpY = rand.nextFloat() * 0.8F + 0.1F;
float jumpZ = rand.nextFloat() * 0.8F + 0.1F;

while (stack.stackSize > 0)
{
int itemSize = rand.nextInt(21) + 10;

if (itemSize > stack.stackSize)
{
itemSize = stack.stackSize;
}

stack.stackSize -= itemSize;
EntityItem entityitem = new EntityItem(par1World, (double) ((float) x + jumpX), (double) ((float) y + jumpY), (double) ((float) z + jumpZ), new ItemStack(stack.itemID,
itemSize, stack.getItemDamage()));

if (stack.hasTagCompound())
{
entityitem.getEntityItem().setTagCompound((NBTTagCompound) stack.getTagCompound().copy());
}

float offset = 0.05F;
entityitem.motionX = (double) ((float) rand.nextGaussian() * offset);
entityitem.motionY = (double) ((float) rand.nextGaussian() * offset + 0.2F);
entityitem.motionZ = (double) ((float) rand.nextGaussian() * offset);
par1World.spawnEntityInWorld(entityitem);
}
}
}
}

super.breakBlock(par1World, x, y, z, par5, meta);
}

public int getLightValue (IBlockAccess world, int x, int y, int z)
{
return !isActive(world, x, y, z) ? 0 : 9;
Expand Down
21 changes: 12 additions & 9 deletions src/tconstruct/blocks/logic/EquipLogic.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,23 @@ public ItemStack getEquipmentItem ()
return inventory[0];
}

/*@Override
@Override
public void setInventorySlotContents(int slot, ItemStack stack){
if(slot == 0){
return;
}else{
super.setInventorySlotContents(slot, stack);
}
}

@Override
public ItemStack getStackInSlot(int slot)
{
return inventory[slot +1];
return slot != 0 ? inventory[slot] : null;
}

public boolean isStackInSlot(int slot)
{
return inventory[slot +1] != null;
return slot != 0 ? inventory[slot] != null : false;
}
@Override
public int getSizeInventory()
{
return inventory.length - 1;
}*/
}

0 comments on commit c3ebcf4

Please sign in to comment.