From 2be853c78c6b9f3dd4f61a996a951e6e10aabfd8 Mon Sep 17 00:00:00 2001 From: Robert S Date: Fri, 18 Apr 2014 01:01:22 -0400 Subject: [PATCH] Moved hammer code to engineering table, changed hammer change, reduce energy loss --- .../archaic/engineering/ItemHammer.java | 77 ++----------------- .../engineering/TileEngineeringTable.java | 44 ++++++++++- 2 files changed, 50 insertions(+), 71 deletions(-) diff --git a/archaic/src/main/scala/resonantinduction/archaic/engineering/ItemHammer.java b/archaic/src/main/scala/resonantinduction/archaic/engineering/ItemHammer.java index 42e76d2fa..59c59fc22 100644 --- a/archaic/src/main/scala/resonantinduction/archaic/engineering/ItemHammer.java +++ b/archaic/src/main/scala/resonantinduction/archaic/engineering/ItemHammer.java @@ -1,77 +1,14 @@ package resonantinduction.archaic.engineering; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.World; -import net.minecraftforge.oredict.OreDictionary; -import resonantinduction.core.Reference; -import resonantinduction.core.ResonantInduction; -import resonantinduction.core.ResonantInduction.RecipeType; -import universalelectricity.api.vector.Vector3; -import calclavia.api.recipe.MachineRecipes; -import calclavia.api.recipe.RecipeResource; -import calclavia.lib.utility.inventory.InventoryUtility; +/** Item used to interact with engineering table to crush ore */ public class ItemHammer extends Item { - public ItemHammer(int id) - { - super(id); - setMaxStackSize(1); - setMaxDamage(400); - } - - @Override - public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) - { - TileEntity tileEntity = world.getBlockTileEntity(x, y, z); - - if (tileEntity instanceof TileEngineeringTable) - { - TileEngineeringTable tile = (TileEngineeringTable) tileEntity; - - // We don't want to bash the output slots - for (int i = 0; i < TileEngineeringTable.CRAFTING_OUTPUT_END; i++) - { - ItemStack inputStack = tile.getStackInSlot(i); - - if (inputStack != null) - { - String oreName = OreDictionary.getOreName(OreDictionary.getOreID(inputStack)); - - if (oreName != null && !oreName.equals("Unknown")) - { - RecipeResource[] outputs = MachineRecipes.INSTANCE.getOutput(RecipeType.CRUSHER.name(), oreName); - - if (outputs.length > 0) - { - if (!world.isRemote && world.rand.nextFloat() < 0.04) - { - for (RecipeResource resource : outputs) - { - ItemStack outputStack = resource.getItemStack().copy(); - - if (outputStack != null) - { - InventoryUtility.dropItemStack(world, new Vector3(player), outputStack, 0); - tile.setInventorySlotContents(i, --inputStack.stackSize <= 0 ? null : inputStack); - } - } - } - - ResonantInduction.proxy.renderBlockParticle(world, new Vector3(x + 0.5, y + 0.5, z + 0.5), new Vector3((Math.random() - 0.5f) * 3, (Math.random() - 0.5f) * 3, (Math.random() - 0.5f) * 3), inputStack.itemID, 1); - 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; - } + public ItemHammer(int id) + { + super(id); + setMaxStackSize(1); + setMaxDamage(400); + } } diff --git a/archaic/src/main/scala/resonantinduction/archaic/engineering/TileEngineeringTable.java b/archaic/src/main/scala/resonantinduction/archaic/engineering/TileEngineeringTable.java index c0c034e9f..8aec881fd 100644 --- a/archaic/src/main/scala/resonantinduction/archaic/engineering/TileEngineeringTable.java +++ b/archaic/src/main/scala/resonantinduction/archaic/engineering/TileEngineeringTable.java @@ -19,14 +19,19 @@ import net.minecraft.network.packet.Packet; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Icon; import net.minecraftforge.common.ForgeDirection; +import net.minecraftforge.oredict.OreDictionary; import org.apache.commons.lang3.ArrayUtils; import org.lwjgl.opengl.GL11; +import resonantinduction.core.Reference; import resonantinduction.core.ResonantInduction; +import resonantinduction.core.ResonantInduction.RecipeType; import resonantinduction.core.prefab.imprint.ItemImprint; import universalelectricity.api.vector.Vector2; import universalelectricity.api.vector.Vector3; +import calclavia.api.recipe.MachineRecipes; +import calclavia.api.recipe.RecipeResource; import calclavia.lib.content.module.TileRender; import calclavia.lib.content.module.prefab.TileInventory; import calclavia.lib.gui.ContainerDummy; @@ -131,7 +136,44 @@ public class TileEngineeringTable extends TileInventory implements IPacketReceiv { if (player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() instanceof ItemHammer) { - return false; + for (int slot = 0; slot < TileEngineeringTable.CRAFTING_OUTPUT_END; slot++) + { + ItemStack inputStack = getStackInSlot(slot); + + if (inputStack != null) + { + String oreName = OreDictionary.getOreName(OreDictionary.getOreID(inputStack)); + + if (oreName != null && !oreName.equals("Unknown")) + { + RecipeResource[] outputs = MachineRecipes.INSTANCE.getOutput(RecipeType.CRUSHER.name(), oreName); + + if (outputs != null && outputs.length > 0) + { + if (!world().isRemote && world().rand.nextFloat() < 0.2) + { + for (RecipeResource resource : outputs) + { + ItemStack outputStack = resource.getItemStack().copy(); + + if (outputStack != null) + { + InventoryUtility.dropItemStack(world(), new Vector3(player), outputStack, 0); + setInventorySlotContents(slot, --inputStack.stackSize <= 0 ? null : inputStack); + } + } + } + + ResonantInduction.proxy.renderBlockParticle(world(), new Vector3(x() + 0.5, y() + 0.5, z() + 0.5), new Vector3((Math.random() - 0.5f) * 3, (Math.random() - 0.5f) * 3, (Math.random() - 0.5f) * 3), inputStack.itemID, 1); + 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.1f); + player.getCurrentEquippedItem().damageItem(1, player); + return true; + } + } + } + } + return true; } if (hitSide == 1)