Moved hammer code to engineering table, changed hammer change, reduce energy loss

This commit is contained in:
Robert S 2014-04-18 01:01:22 -04:00
parent 696be02a8d
commit 2be853c78c
2 changed files with 50 additions and 71 deletions

View file

@ -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);
}
}

View file

@ -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)