From 75d384ec289d468d38bb7a72d6c96c54a4a475f8 Mon Sep 17 00:00:00 2001 From: tterrag1098 Date: Mon, 27 Oct 2014 01:49:32 -0400 Subject: [PATCH] Remove AT and fix hardcoded check for vanilla anvil --- resources/EnderIO_at.cfg | 3 -- .../block/ContainerDarkSteelAnvil.java | 50 +++++++++++++------ 2 files changed, 34 insertions(+), 19 deletions(-) delete mode 100644 resources/EnderIO_at.cfg diff --git a/resources/EnderIO_at.cfg b/resources/EnderIO_at.cfg deleted file mode 100644 index 615e52c0..00000000 --- a/resources/EnderIO_at.cfg +++ /dev/null @@ -1,3 +0,0 @@ -protected net.minecraft.inventory.ContainerRepair field_82852_f # outputSlot -protected net.minecraft.inventory.ContainerRepair field_82853_g # inputSlots -protected net.minecraft.inventory.ContainerRepair field_82856_l # materialCost (stackSizeToBeUsedInRepair) \ No newline at end of file diff --git a/src/main/java/crazypants/enderio/block/ContainerDarkSteelAnvil.java b/src/main/java/crazypants/enderio/block/ContainerDarkSteelAnvil.java index 535846fa..bdd351b9 100644 --- a/src/main/java/crazypants/enderio/block/ContainerDarkSteelAnvil.java +++ b/src/main/java/crazypants/enderio/block/ContainerDarkSteelAnvil.java @@ -1,28 +1,46 @@ package crazypants.enderio.block; -import crazypants.enderio.EnderIO; -import crazypants.enderio.config.Config; +import java.lang.reflect.Field; + import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.init.Blocks; import net.minecraft.inventory.ContainerRepair; +import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; import net.minecraft.world.World; +import cpw.mods.fml.relauncher.ReflectionHelper; +import crazypants.enderio.EnderIO; +import crazypants.enderio.config.Config; public class ContainerDarkSteelAnvil extends ContainerRepair { private int x, y, z; - + + private final Field _outputSlot = ReflectionHelper.findField(ContainerRepair.class, "outputSlot", "field_82852_f"); + private final Field _inputSlots = ReflectionHelper.findField(ContainerRepair.class, "inputSlots", "field_82853_g"); + private final Field _materialCost = ReflectionHelper.findField(ContainerRepair.class, "materialCost", "stackSizeToBeUsedInRepair", "field_82856_l"); + @SuppressWarnings("unchecked") public ContainerDarkSteelAnvil(InventoryPlayer playerInv, final World world, final int x, final int y, final int z, EntityPlayer player) { super(playerInv, world, x, y, z, player); + final IInventory outputSlot, inputSlots; + final int materialCost; + + try { + outputSlot = (IInventory) _outputSlot.get(this); + inputSlots = (IInventory) _inputSlots.get(this); + materialCost = _materialCost.getInt(this); + } catch (Exception e) { + throw new RuntimeException(e); + } + this.x = x; this.y = y; this.z = z; - - this.inventorySlots.set(2, new Slot(this.outputSlot, 2, 134, 47) { + + this.inventorySlots.set(2, new Slot(outputSlot, 2, 134, 47) { public boolean isItemValid(ItemStack stack) { return false; @@ -38,24 +56,24 @@ public class ContainerDarkSteelAnvil extends ContainerRepair { player.addExperienceLevel(-ContainerDarkSteelAnvil.this.maximumCost); } - ContainerDarkSteelAnvil.this.inputSlots.setInventorySlotContents(0, (ItemStack) null); + inputSlots.setInventorySlotContents(0, (ItemStack) null); - if(ContainerDarkSteelAnvil.this.stackSizeToBeUsedInRepair > 0) { - ItemStack itemstack1 = ContainerDarkSteelAnvil.this.inputSlots.getStackInSlot(1); + if(materialCost > 0) { + ItemStack itemstack1 = inputSlots.getStackInSlot(1); - if(itemstack1 != null && itemstack1.stackSize > ContainerDarkSteelAnvil.this.stackSizeToBeUsedInRepair) { - itemstack1.stackSize -= ContainerDarkSteelAnvil.this.stackSizeToBeUsedInRepair; - ContainerDarkSteelAnvil.this.inputSlots.setInventorySlotContents(1, itemstack1); + if(itemstack1 != null && itemstack1.stackSize > materialCost) { + itemstack1.stackSize -= materialCost; + inputSlots.setInventorySlotContents(1, itemstack1); } else { - ContainerDarkSteelAnvil.this.inputSlots.setInventorySlotContents(1, (ItemStack) null); + inputSlots.setInventorySlotContents(1, (ItemStack) null); } } else { - ContainerDarkSteelAnvil.this.inputSlots.setInventorySlotContents(1, (ItemStack) null); + inputSlots.setInventorySlotContents(1, (ItemStack) null); } ContainerDarkSteelAnvil.this.maximumCost = 0; - if(!player.capabilities.isCreativeMode && !world.isRemote && world.getBlock(x, y, z) == Blocks.anvil + if(!player.capabilities.isCreativeMode && !world.isRemote && world.getBlock(x, y, z) == EnderIO.blockDarkSteelAnvil && player.getRNG().nextFloat() < Config.darkSteelAnvilDamageChance) { int i1 = world.getBlockMetadata(x, y, z); int k = i1 & 3; @@ -75,7 +93,7 @@ public class ContainerDarkSteelAnvil extends ContainerRepair { } }); } - + @Override public boolean canInteractWith(EntityPlayer player) { return player.worldObj.getBlock(this.x, this.y, this.z) == EnderIO.blockDarkSteelAnvil;