Fixed #361 - Engineering table can be hammered at all slots

This commit is contained in:
Calclavia 2014-03-03 22:41:22 +08:00
parent a7a5743c4b
commit b8734c86f9
2 changed files with 28 additions and 19 deletions

View file

@ -30,38 +30,46 @@ public class ItemHammer extends Item
if (tileEntity instanceof TileEngineeringTable)
{
TileEngineeringTable tile = (TileEngineeringTable) tileEntity;
ItemStack inputStack = tile.getStackInSlot(TileEngineeringTable.CENTER_SLOT);
if (inputStack != null)
// We don't want to bash the output slots
for (int i = 0; i < TileEngineeringTable.CRAFTING_OUTPUT_END; i++)
{
String oreName = OreDictionary.getOreName(OreDictionary.getOreID(inputStack));
ItemStack inputStack = tile.getStackInSlot(i);
if (oreName != null && !oreName.equals("Unknown"))
if (inputStack != null)
{
if (!world.isRemote && world.rand.nextFloat() < 0.04)
String oreName = OreDictionary.getOreName(OreDictionary.getOreID(inputStack));
if (oreName != null && !oreName.equals("Unknown"))
{
RecipeResource[] outputs = MachineRecipes.INSTANCE.getOutput(RecipeType.CRUSHER, oreName);
for (RecipeResource resource : outputs)
if (outputs.length > 0)
{
ItemStack outputStack = resource.getItemStack().copy();
if (outputStack != null)
if (!world.isRemote && world.rand.nextFloat() < 0.04)
{
InventoryUtility.dropItemStack(world, new Vector3(player), outputStack, 0);
tile.setInventorySlotContents(TileEngineeringTable.CENTER_SLOT, --inputStack.stackSize <= 0 ? null : inputStack);
for (RecipeResource resource : outputs)
{
ItemStack outputStack = resource.getItemStack().copy();
if (outputStack != null)
{
InventoryUtility.dropItemStack(world, new Vector3(player), outputStack, 0);
tile.setInventorySlotContents(TileEngineeringTable.CENTER_SLOT, --inputStack.stackSize <= 0 ? null : inputStack);
}
}
}
world.playSoundEffect(x + 0.5, y + 0.5, z + 0.5, Reference.PREFIX + "hammer", 0.5f, 0.8f + (0.2f * world.rand.nextFloat()));
player.addExhaustion(0.3f);
stack.damageItem(1, player);
return true;
}
}
world.playSoundEffect(x + 0.5, y + 0.5, z + 0.5, Reference.PREFIX + "hammer", 0.5f, 0.8f + (0.2f * world.rand.nextFloat()));
player.addExhaustion(0.3f);
stack.damageItem(1, player);
}
}
return true;
}
return false;
}
}

View file

@ -47,10 +47,11 @@ public class TileEngineeringTable extends TileAdvanced implements IPacketReceive
private AutoCraftingManager craftManager;
/** 9 slots for crafting, 1 slot for a output. */
public ItemStack[] craftingMatrix = new ItemStack[9];
public static final int CRAFTING_MATRIX_SIZE=9;
public ItemStack[] craftingMatrix = new ItemStack[CRAFTING_MATRIX_SIZE];
public static final int[] craftingSlots = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
/** The output inventory containing slots. */
/** The output inventory containing slots.*/
public ItemStack[] outputInventory = new ItemStack[1];
/** The ability for the engineering table to search nearby inventories. */