diff --git a/archaic/src/main/java/resonantinduction/archaic/crate/BlockCrate.java b/archaic/src/main/java/resonantinduction/archaic/crate/BlockCrate.java index 3e782e3ef..38fe02c6a 100644 --- a/archaic/src/main/java/resonantinduction/archaic/crate/BlockCrate.java +++ b/archaic/src/main/java/resonantinduction/archaic/crate/BlockCrate.java @@ -1,5 +1,6 @@ package resonantinduction.archaic.crate; +import java.util.ArrayList; import java.util.List; import net.minecraft.client.renderer.texture.IconRegister; @@ -11,9 +12,11 @@ import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Icon; import net.minecraft.world.World; +import net.minecraftforge.oredict.OreDictionary; import resonantinduction.core.Reference; import universalelectricity.api.UniversalElectricity; import calclavia.lib.prefab.block.BlockTile; +import calclavia.lib.utility.WrenchUtility; import codechicken.multipart.ControlKeyModifer; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -87,39 +90,62 @@ public class BlockCrate extends BlockTile { if (world.getBlockTileEntity(x, y, z) instanceof TileCrate) { - TileCrate tileEntity = (TileCrate) world.getBlockTileEntity(x, y, z); + TileCrate tile = (TileCrate) world.getBlockTileEntity(x, y, z); + + if (player.getCurrentEquippedItem() != null && WrenchUtility.isWrench(player.getCurrentEquippedItem())) + { + /** + * Swap oredict nodes if the player is wrenching the crate. + */ + ItemStack sampleStack = tile.getSampleStack(); + + int oreID = OreDictionary.getOreID(sampleStack); + + if (oreID != -1) + { + ArrayList ores = OreDictionary.getOres(oreID); + + for (int i = 0; i < ores.size(); i++) + { + if (ores.get(i).isItemEqual(sampleStack)) + { + int nextIndex = (i + 1) % ores.size(); + ItemStack desiredStack = ores.get(nextIndex).copy(); + desiredStack.stackSize = sampleStack.stackSize; + + for (int index = 0; index < tile.getSizeInventory(); index++) + tile.setInventorySlotContents(index, null); + + tile.addStackToStorage(desiredStack); + break; + } + } + } + } /** Make double clicking input all stacks. */ - boolean allMode = (world.getWorldTime() - tileEntity.prevClickTime < 10); + boolean allMode = (world.getWorldTime() - tile.prevClickTime < 10); - tileEntity.prevClickTime = world.getWorldTime(); + tile.prevClickTime = world.getWorldTime(); if (ControlKeyModifer.isControlDown(player)) { - this.tryEject(tileEntity, player, allMode); + tryEject(tile, player, allMode); } else { ItemStack current = player.inventory.getCurrentItem(); if (side == 1 && player.capabilities.isCreativeMode) { - if (current != null && tileEntity.getSampleStack() == null) + if (current != null && tile.getSampleStack() == null) { ItemStack cStack = current.copy(); cStack.stackSize = TileCrate.getSlotCount(world.getBlockMetadata(x, y, z)) * 64; - BlockCrate.addStackToCrate(tileEntity, cStack); + addStackToCrate(tile, cStack); } } - // Add items - if (side == 1 || (side > 1 && hitY > 0.5) || !player.capabilities.isCreativeMode) - { - this.tryInsert(tileEntity, player, allMode); - } - // Remove items - else if (side == 0 || (side > 1 && hitY <= 0.5)) - { - this.tryEject(tileEntity, player, allMode); - } + + tryInsert(tile, player, allMode); } } } @@ -160,7 +186,7 @@ public class BlockCrate extends BlockTile public void tryInsert(TileCrate tileEntity, EntityPlayer player, boolean allMode) { - this.tryInsert(tileEntity, player, allMode, true); + tryInsert(tileEntity, player, allMode, true); } public void tryEject(TileCrate tileEntity, EntityPlayer player, boolean allMode) @@ -209,7 +235,7 @@ public class BlockCrate extends BlockTile { if (tileEntity.getSampleStack() != null) { - if (!tileEntity.getSampleStack().isItemEqual(currentStack)) + if (!(tileEntity.getSampleStack().isItemEqual(currentStack) || OreDictionary.getOreID(tileEntity.getSampleStack()) == OreDictionary.getOreID(currentStack))) { return false; } @@ -339,7 +365,7 @@ public class BlockCrate extends BlockTile ItemStack containingStack = tileEntity.getSampleStack(); - if (containingStack == null || containingStack != null && containingStack.isItemEqual(itemStack)) + if (containingStack == null || (containingStack.isItemEqual(itemStack) || OreDictionary.getOreID(containingStack) == OreDictionary.getOreID(itemStack))) { int room = Math.max((tileEntity.getInventory().getSizeInventory() * 64) - (containingStack != null ? containingStack.stackSize : 0), 0); if (itemStack.stackSize <= room) diff --git a/archaic/src/main/java/resonantinduction/archaic/crate/TileCrate.java b/archaic/src/main/java/resonantinduction/archaic/crate/TileCrate.java index 9bcb5e763..b4fbbf607 100644 --- a/archaic/src/main/java/resonantinduction/archaic/crate/TileCrate.java +++ b/archaic/src/main/java/resonantinduction/archaic/crate/TileCrate.java @@ -5,6 +5,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.packet.Packet; import net.minecraftforge.common.ForgeDirection; +import net.minecraftforge.oredict.OreDictionary; import resonantinduction.core.ResonantInduction; import calclavia.lib.network.IPacketReceiver; import calclavia.lib.network.PacketHandler; @@ -130,16 +131,18 @@ public class TileCrate extends TileExternalInventory implements IPacketReceiver, { this.buildSampleStack(); boolean flag = false; + if (this.sampleStack == null) { this.sampleStack = stack; flag = true; } - else if (this.sampleStack.isItemEqual(stack)) + else if (this.sampleStack.isItemEqual(stack) || OreDictionary.getOreID(sampleStack) == OreDictionary.getOreID(stack)) { this.sampleStack.stackSize += stack.stackSize; flag = true; } + if (flag) { this.getInventory().buildInventory(this.sampleStack); @@ -165,7 +168,7 @@ public class TileCrate extends TileExternalInventory implements IPacketReceiver, @Override public boolean canStore(ItemStack stack, int slot, ForgeDirection side) { - return this.sampleStack == null || stack != null && stack.isItemEqual(sampleStack); + return sampleStack == null || stack != null && (stack.isItemEqual(sampleStack) || OreDictionary.getOreID(sampleStack) == OreDictionary.getOreID(stack)); } /** Gets the current slot count for the crate */