From 14edb8c466164d45fed407de7f8217b62306cc3b Mon Sep 17 00:00:00 2001 From: asiekierka Date: Sun, 28 Jun 2015 20:20:38 +0200 Subject: [PATCH] make AdvancedSlots highlight, move more zone planner code to Robotics, initial implementation of new Lists (some GUI parts missing) --- .../buildcraftcore/textures/gui/list_new.png | Bin 0 -> 3567 bytes common/buildcraft/BuildCraftCore.java | 15 + .../buildcraft/builders/gui/GuiBuilder.java | 2 +- common/buildcraft/builders/gui/GuiFiller.java | 2 +- .../builders/urbanism/GuiUrbanist.java | 2 +- common/buildcraft/core/CoreGuiHandler.java | 18 +- common/buildcraft/core/GuiIds.java | 3 +- common/buildcraft/core/ItemList.java | 256 ++---------------- common/buildcraft/core/ItemMapLocation.java | 1 + common/buildcraft/core/StackAtPosition.java | 16 +- .../buildcraft/core/lib/gui/AdvancedSlot.java | 4 + .../core/lib/gui/GuiAdvancedInterface.java | 22 +- .../core/lib/gui/StatementSlot.java | 5 + .../core/lib/utils/OreDictionaryCache.java | 81 ++++++ .../core/list/ContainerListNew.java | 104 +++++++ .../ContainerListOld.java} | 15 +- common/buildcraft/core/list/GuiListNew.java | 127 +++++++++ .../GuiList.java => list/GuiListOld.java} | 38 +-- .../buildcraft/core/list/ListHandlerNew.java | 166 ++++++++++++ .../buildcraft/core/list/ListHandlerOld.java | 245 +++++++++++++++++ .../core/list/ListMatchHandler.java | 17 ++ .../core/list/ListMatchHandlerClass.java | 26 ++ .../list/ListMatchHandlerOreDictionary.java | 72 +++++ common/buildcraft/core/list/ListRegistry.java | 19 ++ .../buildcraft/factory/gui/GuiRefinery.java | 2 +- common/buildcraft/robotics/TileZonePlan.java | 1 - .../{core => robotics}/ZoneChunk.java | 2 +- .../{core => robotics}/ZonePlan.java | 3 +- .../robotics/gui/ContainerZonePlan.java | 2 +- .../buildcraft/robotics/gui/GuiRequester.java | 2 +- .../buildcraft/robotics/gui/GuiZonePlan.java | 4 +- .../silicon/gui/GuiAssemblyTable.java | 2 +- .../silicon/gui/GuiProgrammingTable.java | 2 +- .../transport/gui/GuiGateInterface.java | 2 +- 34 files changed, 992 insertions(+), 286 deletions(-) create mode 100644 buildcraft_resources/assets/buildcraftcore/textures/gui/list_new.png create mode 100644 common/buildcraft/core/lib/utils/OreDictionaryCache.java create mode 100755 common/buildcraft/core/list/ContainerListNew.java rename common/buildcraft/core/{gui/ContainerList.java => list/ContainerListOld.java} (86%) create mode 100755 common/buildcraft/core/list/GuiListNew.java rename common/buildcraft/core/{gui/GuiList.java => list/GuiListOld.java} (83%) create mode 100644 common/buildcraft/core/list/ListHandlerNew.java create mode 100644 common/buildcraft/core/list/ListHandlerOld.java create mode 100644 common/buildcraft/core/list/ListMatchHandler.java create mode 100644 common/buildcraft/core/list/ListMatchHandlerClass.java create mode 100644 common/buildcraft/core/list/ListMatchHandlerOreDictionary.java create mode 100644 common/buildcraft/core/list/ListRegistry.java rename common/buildcraft/{core => robotics}/ZoneChunk.java (99%) rename common/buildcraft/{core => robotics}/ZonePlan.java (98%) diff --git a/buildcraft_resources/assets/buildcraftcore/textures/gui/list_new.png b/buildcraft_resources/assets/buildcraftcore/textures/gui/list_new.png new file mode 100644 index 0000000000000000000000000000000000000000..fd2fbd6ea7842269665d953750fd3777d9771b84 GIT binary patch literal 3567 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 LINE_CACHE = new WeakHashMap(); - - public static class StackLine { - public boolean oreWildcard = false; - public boolean subitemsWildcard = false; - public boolean isOre; - - private ItemStack[] stacks = new ItemStack[7]; - private ArrayList ores = new ArrayList(); - private ArrayList relatedItems = new ArrayList(); - - public ItemStack getStack(int index) { - if (index == 0 || (!oreWildcard && !subitemsWildcard)) { - if (index < 7) { - return stacks[index]; - } else { - return null; - } - } else if (oreWildcard) { - if (ores.size() >= index) { - return ores.get(index - 1); - } else { - return null; - } - } else { - if (relatedItems.size() >= index) { - return relatedItems.get(index - 1); - } else { - return null; - } - } - } - - public void setStack(int slot, ItemStack stack) { - stacks[slot] = stack; - - if (stack != null) { - stacks[slot] = stacks[slot].copy(); - stacks[slot].stackSize = 1; - } - - if (slot == 0) { - relatedItems.clear(); - ores.clear(); - - if (stack == null) { - isOre = false; - } else { - if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) { - setClientPreviewLists(); - } else { - isOre = OreDictionary.getOreIDs(stacks[0]).length > 0; - } - } - } - } - - public void writeToNBT(NBTTagCompound nbt) { - nbt.setBoolean("ore", oreWildcard); - nbt.setBoolean("sub", subitemsWildcard); - - for (int i = 0; i < 7; ++i) { - if (stacks[i] != null) { - NBTTagCompound stackNBT = new NBTTagCompound(); - stacks[i].writeToNBT(stackNBT); - nbt.setTag("stacks[" + i + "]", stackNBT); - } - } - } - - public void readFromNBT(NBTTagCompound nbt) { - oreWildcard = nbt.getBoolean("ore"); - subitemsWildcard = nbt.getBoolean("sub"); - - for (int i = 0; i < 7; ++i) { - if (nbt.hasKey("stacks[" + i + "]")) { - setStack(i, ItemStack.loadItemStackFromNBT(nbt.getCompoundTag("stacks[" + i + "]"))); - } - } - } - - private boolean classMatch(Item base, Item matched) { - if (base.getClass() == Item.class) { - return base == matched; - } else if (base.getClass() == matched.getClass()) { - if (base instanceof ItemBlock) { - Block baseBlock = ((ItemBlock) base).field_150939_a; - Block matchedBlock = ((ItemBlock) matched).field_150939_a; - - if (baseBlock.getClass() == Block.class) { - return baseBlock == matchedBlock; - } else { - return baseBlock.equals(matchedBlock); - } - } else { - return true; - } - } else { - return false; - } - } - - private boolean oreMatch(ItemStack base, ItemStack matched) { - int[] oreIds = OreDictionary.getOreIDs(base); - int[] matchesIds = OreDictionary.getOreIDs(matched); - - - for (int stackId : oreIds) { - for (int matchId : matchesIds) { - if (stackId == matchId) { - return true; - } - } - } - - return false; - } - - private void setClientPreviewLists() { - Item baseItem = stacks [0].getItem(); - - int[] oreIds = OreDictionary.getOreIDs(stacks[0]); - - isOre = oreIds.length > 0; - - for (Object o : Item.itemRegistry) { - Item item = (Item) o; - boolean classMatch = classMatch(baseItem, item); - - List list = new LinkedList(); - - for (CreativeTabs tab : item.getCreativeTabs()) { - item.getSubItems(item, tab, list); - } - - if (list.size() > 0) { - for (Object ol : list) { - ItemStack stack = (ItemStack) ol; - - if (classMatch && relatedItems.size() <= 7 && !StackHelper.isMatchingItemOrList(stacks[0], stack)) { - relatedItems.add(stack); - } - - if (isOre && ores.size() <= 7 && !StackHelper.isMatchingItemOrList(stacks[0], stack) - && oreMatch(stacks[0], stack)) { - ores.add(stack); - } - } - } - } - } - - public boolean matches(ItemStack item) { - if (subitemsWildcard) { - if (stacks[0] == null) { - return false; - } - - return classMatch(stacks[0].getItem(), item.getItem()); - } else if (oreWildcard) { - if (stacks[0] == null) { - return false; - } - - return oreMatch(stacks[0], item); - } else { - for (ItemStack stack : stacks) { - if (stack != null && StackHelper.isMatchingItem(stack, item, true, false)) { - return true; - } - } - - return false; - } - } - } - public ItemList() { super(); + setHasSubtypes(true); setMaxStackSize(1); } @Override public IIcon getIconIndex(ItemStack stack) { - return icons[NBTUtils.getItemData(stack).hasKey("written") ? 1 : 0]; + itemIcon = icons[NBTUtils.getItemData(stack).hasKey("written") ? 1 : 0]; + return itemIcon; } @Override @@ -228,7 +50,7 @@ public class ItemList extends ItemBuildCraft implements IList { @Override public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) { if (!world.isRemote) { - player.openGui(BuildCraftCore.instance, GuiIds.LIST, world, 0, 0, 0); + player.openGui(BuildCraftCore.instance, stack.getItemDamage() == 1 ? GuiIds.LIST_NEW : GuiIds.LIST_OLD, world, 0, 0, 0); } return stack; @@ -236,53 +58,22 @@ public class ItemList extends ItemBuildCraft implements IList { @Override public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean advanced) { - NBTTagCompound nbt = NBTUtils.getItemData(stack); + if (stack.getItemDamage() == 0) { + list.add(EnumChatFormatting.DARK_RED + StatCollector.translateToLocal("tip.deprecated")); + } + NBTTagCompound nbt = NBTUtils.getItemData(stack); if (nbt.hasKey("label")) { list.add(nbt.getString("label")); } } - public static void saveLine(ItemStack stack, StackLine line, int index) { - NBTTagCompound nbt = NBTUtils.getItemData(stack); - - nbt.setBoolean("written", true); - - NBTTagCompound lineNBT = new NBTTagCompound(); - line.writeToNBT(lineNBT); - nbt.setTag("line[" + index + "]", lineNBT); - } - public static void saveLabel(ItemStack stack, String text) { NBTTagCompound nbt = NBTUtils.getItemData(stack); nbt.setString("label", text); } - public static StackLine[] getLines(ItemStack stack) { - if (LINE_CACHE.containsKey(stack)) { - return LINE_CACHE.get(stack); - } - - StackLine[] result = new StackLine[6]; - - for (int i = 0; i < 6; ++i) { - result[i] = new StackLine(); - } - - NBTTagCompound nbt = NBTUtils.getItemData(stack); - - if (nbt.hasKey("written")) { - for (int i = 0; i < 6; ++i) { - result[i].readFromNBT(nbt.getCompoundTag("line[" + i + "]")); - } - } - - LINE_CACHE.put(stack, result); - - return result; - } - @Override public boolean setName(ItemStack stack, String name) { saveLabel(stack, name); @@ -301,16 +92,17 @@ public class ItemList extends ItemBuildCraft implements IList { @Override public boolean matches(ItemStack stackList, ItemStack item) { - StackLine[] lines = getLines(stackList); - - if (lines != null) { - for (int i = 0; i < lines.length; i++) { - if (lines[i] != null && lines[i].matches(item)) { - return true; - } - } + if (stackList.getItemDamage() == 1) { + return ListHandlerNew.matches(stackList, item); + } else { + return ListHandlerOld.matches(stackList, item); } + } - return false; + @Override + @SideOnly(Side.CLIENT) + public void getSubItems(Item item, CreativeTabs tab, List itemList) { + itemList.add(new ItemStack(this, 1, 0)); // TODO: remove + itemList.add(new ItemStack(this, 1, 1)); } } diff --git a/common/buildcraft/core/ItemMapLocation.java b/common/buildcraft/core/ItemMapLocation.java index 9a9769c9..562c35fa 100755 --- a/common/buildcraft/core/ItemMapLocation.java +++ b/common/buildcraft/core/ItemMapLocation.java @@ -33,6 +33,7 @@ import buildcraft.api.items.IMapLocation; import buildcraft.core.lib.items.ItemBuildCraft; import buildcraft.core.lib.utils.NBTUtils; import buildcraft.core.lib.utils.StringUtils; +import buildcraft.robotics.ZonePlan; public class ItemMapLocation extends ItemBuildCraft implements IMapLocation { public ItemMapLocation() { diff --git a/common/buildcraft/core/StackAtPosition.java b/common/buildcraft/core/StackAtPosition.java index 61b3f5eb..1b213e0d 100755 --- a/common/buildcraft/core/StackAtPosition.java +++ b/common/buildcraft/core/StackAtPosition.java @@ -21,7 +21,7 @@ public class StackAtPosition implements ISerializable { public Position pos; public boolean display; - // Rendering + // Rendering only! public boolean generatedListId; public int glListId; @@ -34,4 +34,18 @@ public class StackAtPosition implements ISerializable { public void writeData(ByteBuf stream) { NetworkUtils.writeStack(stream, stack); } + + @Override + public boolean equals(Object o) { + if (o == null || !(o instanceof StackAtPosition)) { + return false; + } + StackAtPosition other = (StackAtPosition) o; + return other.stack.equals(stack) && other.pos.equals(pos) && other.display == display; + } + + @Override + public int hashCode() { + return stack.hashCode() * 17 + pos.hashCode(); + } } \ No newline at end of file diff --git a/common/buildcraft/core/lib/gui/AdvancedSlot.java b/common/buildcraft/core/lib/gui/AdvancedSlot.java index f833547d..df659ce4 100755 --- a/common/buildcraft/core/lib/gui/AdvancedSlot.java +++ b/common/buildcraft/core/lib/gui/AdvancedSlot.java @@ -113,4 +113,8 @@ public abstract class AdvancedSlot { public void selected () { } + + public boolean shouldDrawHighlight() { + return true; + } } \ No newline at end of file diff --git a/common/buildcraft/core/lib/gui/GuiAdvancedInterface.java b/common/buildcraft/core/lib/gui/GuiAdvancedInterface.java index ee1a0e89..ab90b078 100644 --- a/common/buildcraft/core/lib/gui/GuiAdvancedInterface.java +++ b/common/buildcraft/core/lib/gui/GuiAdvancedInterface.java @@ -17,6 +17,7 @@ import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.RenderHelper; import net.minecraft.client.renderer.entity.RenderItem; import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; @@ -52,7 +53,25 @@ public abstract class GuiAdvancedInterface extends GuiBuildCraft { } } - protected void drawBackgroundSlots() { + private boolean isMouseOverSlot(AdvancedSlot slot, int mouseX, int mouseY) { + int realMouseX = mouseX - this.guiLeft; + int realMouseY = mouseY - this.guiTop; + return realMouseX >= slot.x - 1 && realMouseX < slot.x + 16 + 1 && realMouseY >= slot.y - 1 && realMouseY < slot.y + 16 + 1; + } + + protected void drawSlotHighlight(AdvancedSlot slot, int mouseX, int mouseY) { + if (this.isMouseOverSlot(slot, mouseX, mouseY) && slot.shouldDrawHighlight()) { + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glDisable(GL11.GL_DEPTH_TEST); + GL11.glColorMask(true, true, true, false); + this.drawGradientRect(guiLeft + slot.x, guiTop + slot.y, guiLeft + slot.x + 16, guiTop + slot.y + 16, -2130706433, -2130706433); + GL11.glColorMask(true, true, true, true); + GL11.glEnable(GL11.GL_LIGHTING); + GL11.glEnable(GL11.GL_DEPTH_TEST); + } + } + + protected void drawBackgroundSlots(int mouseX, int mouseY) { RenderHelper.enableGUIStandardItemLighting(); GL11.glPushMatrix(); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); @@ -66,6 +85,7 @@ public abstract class GuiAdvancedInterface extends GuiBuildCraft { for (AdvancedSlot slot : slots) { if (slot != null) { slot.drawSprite(guiLeft, guiTop); + drawSlotHighlight(slot, mouseX, mouseY); } } } diff --git a/common/buildcraft/core/lib/gui/StatementSlot.java b/common/buildcraft/core/lib/gui/StatementSlot.java index 5a98c454..1624f65f 100644 --- a/common/buildcraft/core/lib/gui/StatementSlot.java +++ b/common/buildcraft/core/lib/gui/StatementSlot.java @@ -50,4 +50,9 @@ public abstract class StatementSlot extends AdvancedSlot { } public abstract IStatement getStatement(); + + @Override + public boolean shouldDrawHighlight() { + return false; + } } diff --git a/common/buildcraft/core/lib/utils/OreDictionaryCache.java b/common/buildcraft/core/lib/utils/OreDictionaryCache.java new file mode 100644 index 00000000..10d1c7bd --- /dev/null +++ b/common/buildcraft/core/lib/utils/OreDictionaryCache.java @@ -0,0 +1,81 @@ +package buildcraft.core.lib.utils; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.oredict.OreDictionary; + +public final class OreDictionaryCache { + public static final OreDictionaryCache INSTANCE = new OreDictionaryCache(); + + private final Map> namingCache = new HashMap>(); + private final Set registeredNames = new HashSet(); + + private OreDictionaryCache() { + + } + + public Set getListOfPartialMatches(String part) { + return namingCache.get(part); + } + + private void addToNamingCache(String s, int id) { + if (s == null) { + return; + } + + Set ll = namingCache.get(s); + + if (ll == null) { + ll = new HashSet(); + ll.add(id); + namingCache.put(s, ll); + } else { + ll.add(id); + } + } + + private static int getSplitLocation(String name) { + int splitLocation = 0; + while (splitLocation < name.length()) { + if (!Character.isUpperCase(name.codePointAt(splitLocation))) { + splitLocation++; + } else { + break; + } + } + + return splitLocation; + } + + public static String getFirstHalf(String name) { + int splitLocation = getSplitLocation(name); + return splitLocation < name.length() ? name.substring(0, splitLocation) : name; // No null - this handles things like "record". + } + + public static String getSecondHalf(String name) { + int splitLocation = getSplitLocation(name); + return splitLocation < name.length() ? name.substring(splitLocation) : null; + } + + @SubscribeEvent + public void oreRegister(OreDictionary.OreRegisterEvent event) { + registerName(event.Name); + } + + public void registerName(String name) { + if (registeredNames.contains(name)) { + return; + } + + int oreID = OreDictionary.getOreID(name); + + addToNamingCache(getFirstHalf(name), oreID); + addToNamingCache(getSecondHalf(name), oreID); + + registeredNames.add(name); + } +} diff --git a/common/buildcraft/core/list/ContainerListNew.java b/common/buildcraft/core/list/ContainerListNew.java new file mode 100755 index 00000000..9877b1e1 --- /dev/null +++ b/common/buildcraft/core/list/ContainerListNew.java @@ -0,0 +1,104 @@ +/** + * Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team + * http://www.mod-buildcraft.com + * + * BuildCraft is distributed under the terms of the Minecraft Mod Public + * License 1.0, or MMPL. Please check the contents of the license located in + * http://www.mod-buildcraft.com/MMPL-1.0.txt + */ +package buildcraft.core.list; + +import io.netty.buffer.ByteBuf; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; +import cpw.mods.fml.relauncher.Side; +import buildcraft.BuildCraftCore; +import buildcraft.core.ItemList; +import buildcraft.core.lib.gui.BuildCraftContainer; +import buildcraft.core.lib.network.command.CommandWriter; +import buildcraft.core.lib.network.command.ICommandReceiver; +import buildcraft.core.lib.network.command.PacketCommand; +import buildcraft.core.lib.utils.NetworkUtils; + +public class ContainerListNew extends BuildCraftContainer implements ICommandReceiver { + public ListHandlerNew.Line[] lines; + private EntityPlayer player; + + public ContainerListNew(EntityPlayer iPlayer) { + super(iPlayer.inventory.getSizeInventory()); + + player = iPlayer; + + lines = ListHandlerNew.getLines(player.getCurrentEquippedItem()); + + for (int sy = 0; sy < 3; sy++) { + for (int sx = 0; sx < 9; sx++) { + addSlotToContainer(new Slot(player.inventory, sx + sy * 9 + 9, 8 + sx * 18, 118 + sy * 18)); + } + } + + for (int sx = 0; sx < 9; sx++) { + addSlotToContainer(new Slot(player.inventory, sx, 8 + sx * 18, 176)); + } + } + + @Override + public boolean canInteractWith(EntityPlayer player) { + return true; + } + + public void setStack(final int lineIndex, final int slotIndex, final ItemStack stack) { + lines[lineIndex].setStack(slotIndex, stack); + ListHandlerNew.saveLines(player.getCurrentEquippedItem(), lines); + + if (player.worldObj.isRemote) { + BuildCraftCore.instance.sendToServer(new PacketCommand(this, "setStack", new CommandWriter() { + public void write(ByteBuf data) { + data.writeByte(lineIndex); + data.writeByte(slotIndex); + NetworkUtils.writeStack(data, stack); + } + })); + } + } + + public void switchButton(final int lineIndex, final int button) { + lines[lineIndex].toggleOption(lineIndex); + ListHandlerNew.saveLines(player.getCurrentEquippedItem(), lines); + + if (player.worldObj.isRemote) { + BuildCraftCore.instance.sendToServer(new PacketCommand(this, "switchButton", new CommandWriter() { + public void write(ByteBuf data) { + data.writeByte(lineIndex); + data.writeByte(button); + } + })); + } + } + + public void setLabel(final String text) { + ItemList.saveLabel(player.getCurrentEquippedItem(), text); + + if (player.worldObj.isRemote) { + BuildCraftCore.instance.sendToServer(new PacketCommand(this, "setLabel", new CommandWriter() { + public void write(ByteBuf data) { + NetworkUtils.writeUTF(data, text); + } + })); + } + } + + @Override + public void receiveCommand(String command, Side side, Object sender, ByteBuf stream) { + if (side.isServer()) { + if ("setLabel".equals(command)) { + setLabel(NetworkUtils.readUTF(stream)); + } else if ("switchButton".equals(command)) { + switchButton(stream.readUnsignedByte(), stream.readUnsignedByte()); + } else if ("setStack".equals(command)) { + setStack(stream.readUnsignedByte(), stream.readUnsignedByte(), NetworkUtils.readStack(stream)); + } + } + } +} diff --git a/common/buildcraft/core/gui/ContainerList.java b/common/buildcraft/core/list/ContainerListOld.java similarity index 86% rename from common/buildcraft/core/gui/ContainerList.java rename to common/buildcraft/core/list/ContainerListOld.java index 47187754..7dbb654c 100755 --- a/common/buildcraft/core/gui/ContainerList.java +++ b/common/buildcraft/core/list/ContainerListOld.java @@ -6,7 +6,7 @@ * License 1.0, or MMPL. Please check the contents of the license located in * http://www.mod-buildcraft.com/MMPL-1.0.txt */ -package buildcraft.core.gui; +package buildcraft.core.list; import io.netty.buffer.ByteBuf; @@ -17,23 +17,24 @@ import cpw.mods.fml.relauncher.Side; import buildcraft.BuildCraftCore; import buildcraft.core.ItemList; +import buildcraft.core.list.ListHandlerOld; import buildcraft.core.lib.gui.BuildCraftContainer; import buildcraft.core.lib.network.command.CommandWriter; import buildcraft.core.lib.network.command.ICommandReceiver; import buildcraft.core.lib.network.command.PacketCommand; import buildcraft.core.lib.utils.NetworkUtils; -public class ContainerList extends BuildCraftContainer implements ICommandReceiver { +public class ContainerListOld extends BuildCraftContainer implements ICommandReceiver { - public ItemList.StackLine[] lines; + public ListHandlerOld.StackLine[] lines; private EntityPlayer player; - public ContainerList(EntityPlayer iPlayer) { + public ContainerListOld(EntityPlayer iPlayer) { super(iPlayer.inventory.getSizeInventory()); player = iPlayer; - lines = ItemList.getLines(player.getCurrentEquippedItem()); + lines = ListHandlerOld.getLines(player.getCurrentEquippedItem()); for (int sy = 0; sy < 3; sy++) { for (int sx = 0; sx < 9; sx++) { @@ -53,7 +54,7 @@ public class ContainerList extends BuildCraftContainer implements ICommandReceiv public void setStack(final int lineIndex, final int slotIndex, final ItemStack stack) { lines[lineIndex].setStack(slotIndex, stack); - ItemList.saveLine(player.getCurrentEquippedItem(), lines[lineIndex], lineIndex); + ListHandlerOld.saveLine(player.getCurrentEquippedItem(), lines[lineIndex], lineIndex); if (player.worldObj.isRemote) { BuildCraftCore.instance.sendToServer(new PacketCommand(this, "setStack", new CommandWriter() { @@ -75,7 +76,7 @@ public class ContainerList extends BuildCraftContainer implements ICommandReceiv lines[lineIndex].oreWildcard = !lines[lineIndex].oreWildcard; } - ItemList.saveLine(player.getCurrentEquippedItem(), lines[lineIndex], lineIndex); + ListHandlerOld.saveLine(player.getCurrentEquippedItem(), lines[lineIndex], lineIndex); if (player.worldObj.isRemote) { BuildCraftCore.instance.sendToServer(new PacketCommand(this, "switchButton", new CommandWriter() { diff --git a/common/buildcraft/core/list/GuiListNew.java b/common/buildcraft/core/list/GuiListNew.java new file mode 100755 index 00000000..eaf6742b --- /dev/null +++ b/common/buildcraft/core/list/GuiListNew.java @@ -0,0 +1,127 @@ +/** + * Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team + * http://www.mod-buildcraft.com + * + * BuildCraft is distributed under the terms of the Minecraft Mod Public + * License 1.0, or MMPL. Please check the contents of the license located in + * http://www.mod-buildcraft.com/MMPL-1.0.txt + */ +package buildcraft.core.list; + +import net.minecraft.client.gui.GuiTextField; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; +import buildcraft.BuildCraftCore; +import buildcraft.core.ItemList; +import buildcraft.core.lib.gui.AdvancedSlot; +import buildcraft.core.lib.gui.GuiAdvancedInterface; + +public class GuiListNew extends GuiAdvancedInterface { + + private static final ResourceLocation TEXTURE_BASE = new ResourceLocation( + "buildcraftcore:textures/gui/list_new.png"); + + private GuiTextField textField; + private EntityPlayer player; + + private static class ListSlot extends AdvancedSlot { + public int lineIndex; + public int slotIndex; + + public ListSlot(GuiAdvancedInterface gui, int x, int y, int iLineIndex, int iSlotIndex) { + super(gui, x, y); + + lineIndex = iLineIndex; + slotIndex = iSlotIndex; + } + + @Override + public ItemStack getItemStack() { + ContainerListNew container = (ContainerListNew) gui.getContainer(); + return container.lines[lineIndex].getStack(slotIndex); + } + } + + public GuiListNew(EntityPlayer iPlayer) { + super(new ContainerListNew(iPlayer), iPlayer.inventory, TEXTURE_BASE); + + xSize = 176; + ySize = 206; + + for (int sy = 0; sy < ListHandlerNew.HEIGHT; sy++) { + for (int sx = 0; sx < ListHandlerNew.WIDTH; sx++) { + slots.add(new ListSlot(this, 8 + sx * 18, 46 + sy * 33, sy, sx)); + } + } + + player = iPlayer; + } + + @Override + public void initGui() { + super.initGui(); + + textField = new GuiTextField(this.fontRendererObj, 10, 10, 156, 12); + textField.setMaxStringLength(32); + textField.setText(BuildCraftCore.listItem.getLabel(player.getCurrentEquippedItem())); + textField.setFocused(false); + } + + @Override + protected void drawGuiContainerBackgroundLayer(float f, int x, int y) { + super.drawGuiContainerBackgroundLayer(f, x, y); + + ContainerListNew container = (ContainerListNew) getContainer(); + drawBackgroundSlots(x, y); + } + + @Override + protected void drawGuiContainerForegroundLayer(int par1, int par2) { + super.drawGuiContainerForegroundLayer(par1, par2); + + textField.drawTextBox(); + drawTooltipForSlotAt(par1, par2); + } + + private boolean isCarryingList() { + ItemStack stack = mc.thePlayer.inventory.getItemStack(); + return stack != null && stack.getItem() instanceof ItemList; + } + + private boolean hasListEquipped() { + return mc.thePlayer.getCurrentEquippedItem() != null && mc.thePlayer.getCurrentEquippedItem().getItem() instanceof ItemList; + } + + @Override + protected void mouseClicked(int x, int y, int b) { + super.mouseClicked(x, y, b); + + if (isCarryingList() || !hasListEquipped()) { + return; + } + + AdvancedSlot slot = getSlotAtLocation(x, y); + ContainerListNew container = (ContainerListNew) getContainer(); + + if (slot instanceof ListSlot) { + container.setStack(((ListSlot) slot).lineIndex, ((ListSlot) slot).slotIndex, mc.thePlayer.inventory.getItemStack()); + } + + textField.mouseClicked(x - guiLeft, y - guiTop, b); + } + + @Override + protected void keyTyped(char c, int i) { + if (textField.isFocused()) { + if (c == 13 || c == 27) { + textField.setFocused(false); + } else { + textField.textboxKeyTyped(c, i); + ((ContainerListNew) container).setLabel(textField.getText()); + } + } else { + super.keyTyped(c, i); + } + } +} \ No newline at end of file diff --git a/common/buildcraft/core/gui/GuiList.java b/common/buildcraft/core/list/GuiListOld.java similarity index 83% rename from common/buildcraft/core/gui/GuiList.java rename to common/buildcraft/core/list/GuiListOld.java index a95b97c2..3f46da8a 100755 --- a/common/buildcraft/core/gui/GuiList.java +++ b/common/buildcraft/core/list/GuiListOld.java @@ -6,7 +6,7 @@ * License 1.0, or MMPL. Please check the contents of the license located in * http://www.mod-buildcraft.com/MMPL-1.0.txt */ -package buildcraft.core.gui; +package buildcraft.core.list; import net.minecraft.client.gui.GuiTextField; import net.minecraft.entity.player.EntityPlayer; @@ -18,7 +18,7 @@ import buildcraft.core.ItemList; import buildcraft.core.lib.gui.AdvancedSlot; import buildcraft.core.lib.gui.GuiAdvancedInterface; -public class GuiList extends GuiAdvancedInterface { +public class GuiListOld extends GuiAdvancedInterface { private static final ResourceLocation TEXTURE_BASE = new ResourceLocation( "buildcraftcore:textures/gui/list.png"); @@ -37,13 +37,9 @@ public class GuiList extends GuiAdvancedInterface { @Override public ItemStack getItemStack() { - ContainerList container = (ContainerList) gui.getContainer(); + ContainerListOld container = (ContainerListOld) gui.getContainer(); - if (container.lines[lineIndex].getStack(0) != null) { - return container.lines[lineIndex].getStack(0); - } else { - return null; - } + return container.lines[lineIndex].getStack(0); } } @@ -60,17 +56,13 @@ public class GuiList extends GuiAdvancedInterface { @Override public ItemStack getItemStack() { - ContainerList container = (ContainerList) gui.getContainer(); + ContainerListOld container = (ContainerListOld) gui.getContainer(); if (slotIndex == 6 && container.lines[lineIndex].getStack(7) != null) { return null; } - if (container.lines[lineIndex].getStack(slotIndex) != null) { - return container.lines[lineIndex].getStack(slotIndex); - } else { - return null; - } + return container.lines[lineIndex].getStack(slotIndex); } } @@ -94,16 +86,16 @@ public class GuiList extends GuiAdvancedInterface { } } - public GuiList(EntityPlayer iPlayer) { - super(new ContainerList(iPlayer), iPlayer.inventory, TEXTURE_BASE); + public GuiListOld(EntityPlayer iPlayer) { + super(new ContainerListOld(iPlayer), iPlayer.inventory, TEXTURE_BASE); xSize = 176; ySize = 241; - for (int sy = 0; sy < 6; ++sy) { + for (int sy = 0; sy < 6; sy++) { slots.add(new MainSlot(this, 44, 31 + sy * 18, sy)); - for (int sx = 1; sx < 7; ++sx) { + for (int sx = 1; sx < 7; sx++) { slots.add(new SecondarySlot(this, 44 + sx * 18, 31 + sy * 18, sy, sx)); } @@ -128,7 +120,7 @@ public class GuiList extends GuiAdvancedInterface { protected void drawGuiContainerBackgroundLayer(float f, int x, int y) { super.drawGuiContainerBackgroundLayer(f, x, y); - ContainerList container = (ContainerList) getContainer(); + ContainerListOld container = (ContainerListOld) getContainer(); bindTexture(TEXTURE_BASE); @@ -154,7 +146,7 @@ public class GuiList extends GuiAdvancedInterface { } } - drawBackgroundSlots(); + drawBackgroundSlots(x, y); bindTexture(TEXTURE_BASE); @@ -192,7 +184,7 @@ public class GuiList extends GuiAdvancedInterface { } AdvancedSlot slot = getSlotAtLocation(x, y); - ContainerList container = (ContainerList) getContainer(); + ContainerListOld container = (ContainerListOld) getContainer(); if (slot instanceof MainSlot) { container.setStack(((MainSlot) slot).lineIndex, 0, mc.thePlayer.inventory.getItemStack()); @@ -215,9 +207,7 @@ public class GuiList extends GuiAdvancedInterface { textField.setFocused(false); } else { textField.textboxKeyTyped(c, i); - ((ContainerList) container).setLabel(textField.getText()); - // RPCHandler.rpcServer(architect, "handleClientSetName", - // textField.getText()); + ((ContainerListOld) container).setLabel(textField.getText()); } } else { super.keyTyped(c, i); diff --git a/common/buildcraft/core/list/ListHandlerNew.java b/common/buildcraft/core/list/ListHandlerNew.java new file mode 100644 index 00000000..d00b8559 --- /dev/null +++ b/common/buildcraft/core/list/ListHandlerNew.java @@ -0,0 +1,166 @@ +package buildcraft.core.list; + +import java.util.List; + +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; + +import buildcraft.core.lib.inventory.StackHelper; +import buildcraft.core.lib.utils.NBTUtils; + +public class ListHandlerNew { + public static final int WIDTH = 9; + public static final int HEIGHT = 2; + + public static class Line { + public final ItemStack[] stacks; + public boolean precise, byType, byMaterial; + + public Line() { + stacks = new ItemStack[WIDTH]; + } + + public boolean isOneStackMode() { + return byType || byMaterial; + } + + public boolean getOption(int id) { + return (id == 0 ? precise : (id == 1 ? byType : byMaterial)); + } + + public void toggleOption(int id) { + if (byType == false && byMaterial == false && (id == 1 || id == 2)) { + for (int i = 1; i < stacks.length; i++) { + stacks[i] = null; + } + } + switch (id) { + case 0: + precise = !precise; + break; + case 1: + byType = !byType; + break; + case 2: + byMaterial = !byMaterial; + break; + } + } + + public boolean matches(ItemStack target) { + if (byType || byMaterial) { + if (stacks[0] == null) { + return false; + } + + List handlers = ListRegistry.getHandlers(); + ListMatchHandler.Type type = byType ? (byMaterial ? ListMatchHandler.Type.CLASS : ListMatchHandler.Type.TYPE) : ListMatchHandler.Type.MATERIAL; + for (ListMatchHandler h : handlers) { + if (h.matches(type, stacks[0], target, precise)) { + return true; + } + } + } else { + for (ItemStack s : stacks) { + if (s != null && StackHelper.isMatchingItem(s, target, precise || target.getItem().getHasSubtypes(), precise)) { + return true; + } + } + } + return false; + } + + public static Line fromNBT(NBTTagCompound data) { + Line line = new Line(); + + if (data != null && data.hasKey("st")) { + NBTTagList l = data.getTagList("st", 10); + for (int i = 0; i < l.tagCount(); i++) { + line.stacks[i] = ItemStack.loadItemStackFromNBT(l.getCompoundTagAt(i)); + } + + line.precise = data.getBoolean("Fp"); + line.byType = data.getBoolean("Ft"); + line.byMaterial = data.getBoolean("Fm"); + } + + return line; + } + + public NBTTagCompound toNBT() { + NBTTagCompound data = new NBTTagCompound(); + NBTTagList stackList = new NBTTagList(); + for (int i = 0; i < stacks.length; i++) { + NBTTagCompound stack = new NBTTagCompound(); + if (stacks[i] != null) { + stacks[i].writeToNBT(stack); + } + stackList.appendTag(stack); + } + data.setTag("st", stackList); + data.setBoolean("Fp", precise); + data.setBoolean("Ft", byType); + data.setBoolean("Fm", byMaterial); + return data; + } + + public void setStack(int slotIndex, ItemStack stack) { + if (slotIndex == 0 || (!byType && !byMaterial)) { + if (stack != null && stack.getItem() != null) { + stacks[slotIndex] = stack.copy(); + stacks[slotIndex].stackSize = 1; + } else { + stacks[slotIndex] = null; + } + } + } + + public ItemStack getStack(int i) { + return i >= 0 && i < stacks.length ? stacks[i] : null; + } + } + + public static Line[] getLines(ItemStack item) { + NBTTagCompound data = NBTUtils.getItemData(item); + if (data.hasKey("written") && data.hasKey("lines")) { + NBTTagList list = data.getTagList("lines", 10); + Line[] lines = new Line[list.tagCount()]; + for (int i = 0; i < lines.length; i++) { + lines[i] = Line.fromNBT(list.getCompoundTagAt(i)); + } + return lines; + } else { + Line[] lines = new Line[HEIGHT]; + for (int i = 0; i < lines.length; i++) { + lines[i] = new Line(); + } + return lines; + } + } + + public static void saveLines(ItemStack stackList, Line[] lines) { + NBTTagCompound data = NBTUtils.getItemData(stackList); + data.setBoolean("written", true); + NBTTagList lineList = new NBTTagList(); + for (Line l : lines) { + lineList.appendTag(l.toNBT()); + } + data.setTag("lines", lineList); + } + + public static boolean matches(ItemStack stackList, ItemStack item) { + NBTTagCompound data = NBTUtils.getItemData(stackList); + if (data.hasKey("written") && data.hasKey("lines")) { + NBTTagList list = data.getTagList("lines", 10); + for (int i = 0; i < list.tagCount(); i++) { + Line line = Line.fromNBT(list.getCompoundTagAt(i)); + if (line.matches(item)) { + return true; + } + } + } + + return false; + } +} diff --git a/common/buildcraft/core/list/ListHandlerOld.java b/common/buildcraft/core/list/ListHandlerOld.java new file mode 100644 index 00000000..c28a5ec8 --- /dev/null +++ b/common/buildcraft/core/list/ListHandlerOld.java @@ -0,0 +1,245 @@ +package buildcraft.core.list; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.WeakHashMap; + +import net.minecraft.block.Block; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.item.Item; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.relauncher.Side; +import net.minecraftforge.oredict.OreDictionary; + +import buildcraft.core.lib.inventory.StackHelper; +import buildcraft.core.lib.utils.NBTUtils; + +public class ListHandlerOld { + private static final WeakHashMap LINE_CACHE = new WeakHashMap(); + + public static class StackLine { + public boolean oreWildcard = false; + public boolean subitemsWildcard = false; + public boolean isOre; + + private ItemStack[] stacks = new ItemStack[7]; + private ArrayList ores = new ArrayList(); + private ArrayList relatedItems = new ArrayList(); + + public ItemStack getStack(int index) { + if (index == 0 || (!oreWildcard && !subitemsWildcard)) { + if (index < 7) { + return stacks[index]; + } else { + return null; + } + } else if (oreWildcard) { + if (ores.size() >= index) { + return ores.get(index - 1); + } else { + return null; + } + } else { + if (relatedItems.size() >= index) { + return relatedItems.get(index - 1); + } else { + return null; + } + } + } + + public void setStack(int slot, ItemStack stack) { + stacks[slot] = stack; + + if (stack != null) { + stacks[slot] = stacks[slot].copy(); + stacks[slot].stackSize = 1; + } + + if (slot == 0) { + relatedItems.clear(); + ores.clear(); + + if (stack == null) { + isOre = false; + } else { + if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) { + setClientPreviewLists(); + } else { + isOre = OreDictionary.getOreIDs(stacks[0]).length > 0; + } + } + } + } + + public void writeToNBT(NBTTagCompound nbt) { + nbt.setBoolean("ore", oreWildcard); + nbt.setBoolean("sub", subitemsWildcard); + + for (int i = 0; i < 7; ++i) { + if (stacks[i] != null) { + NBTTagCompound stackNBT = new NBTTagCompound(); + stacks[i].writeToNBT(stackNBT); + nbt.setTag("stacks[" + i + "]", stackNBT); + } + } + } + + public void readFromNBT(NBTTagCompound nbt) { + oreWildcard = nbt.getBoolean("ore"); + subitemsWildcard = nbt.getBoolean("sub"); + + for (int i = 0; i < 7; ++i) { + if (nbt.hasKey("stacks[" + i + "]")) { + setStack(i, ItemStack.loadItemStackFromNBT(nbt.getCompoundTag("stacks[" + i + "]"))); + } + } + } + + private boolean classMatch(Item base, Item matched) { + if (base.getClass() == Item.class) { + return base == matched; + } else if (base.getClass() == matched.getClass()) { + if (base instanceof ItemBlock) { + Block baseBlock = ((ItemBlock) base).field_150939_a; + Block matchedBlock = ((ItemBlock) matched).field_150939_a; + + if (baseBlock.getClass() == Block.class) { + return baseBlock == matchedBlock; + } else { + return baseBlock.equals(matchedBlock); + } + } else { + return true; + } + } else { + return false; + } + } + + private boolean oreMatch(ItemStack base, ItemStack matched) { + int[] oreIds = OreDictionary.getOreIDs(base); + int[] matchesIds = OreDictionary.getOreIDs(matched); + + for (int stackId : oreIds) { + for (int matchId : matchesIds) { + if (stackId == matchId) { + return true; + } + } + } + + return false; + } + + private void setClientPreviewLists() { + Item baseItem = stacks [0].getItem(); + + int[] oreIds = OreDictionary.getOreIDs(stacks[0]); + + isOre = oreIds.length > 0; + + for (Object o : Item.itemRegistry) { + Item item = (Item) o; + boolean classMatch = classMatch(baseItem, item); + + List list = new LinkedList(); + + for (CreativeTabs tab : item.getCreativeTabs()) { + item.getSubItems(item, tab, list); + } + + if (list.size() > 0) { + for (Object ol : list) { + ItemStack stack = (ItemStack) ol; + + if (classMatch && relatedItems.size() <= 7 && !StackHelper.isMatchingItemOrList(stacks[0], stack)) { + relatedItems.add(stack); + } + + if (isOre && ores.size() <= 7 && !StackHelper.isMatchingItemOrList(stacks[0], stack) + && oreMatch(stacks[0], stack)) { + ores.add(stack); + } + } + } + } + } + + public boolean matches(ItemStack item) { + if (subitemsWildcard) { + if (stacks[0] == null) { + return false; + } + + return classMatch(stacks[0].getItem(), item.getItem()); + } else if (oreWildcard) { + if (stacks[0] == null) { + return false; + } + + return oreMatch(stacks[0], item); + } else { + for (ItemStack stack : stacks) { + if (stack != null && StackHelper.isMatchingItem(stack, item, true, false)) { + return true; + } + } + + return false; + } + } + } + + public static void saveLine(ItemStack stack, StackLine line, int index) { + NBTTagCompound nbt = NBTUtils.getItemData(stack); + + nbt.setBoolean("written", true); + + NBTTagCompound lineNBT = new NBTTagCompound(); + line.writeToNBT(lineNBT); + nbt.setTag("line[" + index + "]", lineNBT); + } + + public static StackLine[] getLines(ItemStack stack) { + if (LINE_CACHE.containsKey(stack)) { + return LINE_CACHE.get(stack); + } + + StackLine[] result = new StackLine[6]; + + for (int i = 0; i < 6; ++i) { + result[i] = new StackLine(); + } + + NBTTagCompound nbt = NBTUtils.getItemData(stack); + + if (nbt.hasKey("written")) { + for (int i = 0; i < 6; ++i) { + result[i].readFromNBT(nbt.getCompoundTag("line[" + i + "]")); + } + } + + LINE_CACHE.put(stack, result); + + return result; + } + + public static boolean matches(ItemStack stackList, ItemStack item) { + StackLine[] lines = getLines(stackList); + + if (lines != null) { + for (int i = 0; i < lines.length; i++) { + if (lines[i] != null && lines[i].matches(item)) { + return true; + } + } + } + + return false; + } +} diff --git a/common/buildcraft/core/list/ListMatchHandler.java b/common/buildcraft/core/list/ListMatchHandler.java new file mode 100644 index 00000000..f6d4366d --- /dev/null +++ b/common/buildcraft/core/list/ListMatchHandler.java @@ -0,0 +1,17 @@ +package buildcraft.core.list; + +import java.util.List; +import net.minecraft.item.ItemStack; + +/** + * Internal interface for now - it will become public once its shape is set + * in stone better. + */ +public abstract class ListMatchHandler { + public enum Type { + TYPE, MATERIAL, CLASS + } + + public abstract boolean matches(Type type, ItemStack stack, ItemStack target, boolean precise); + public abstract List getClientExamples(Type type, ItemStack stack); +} diff --git a/common/buildcraft/core/list/ListMatchHandlerClass.java b/common/buildcraft/core/list/ListMatchHandlerClass.java new file mode 100644 index 00000000..3d3d8541 --- /dev/null +++ b/common/buildcraft/core/list/ListMatchHandlerClass.java @@ -0,0 +1,26 @@ +package buildcraft.core.list; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; + +public class ListMatchHandlerClass extends ListMatchHandler { + public static final Set> itemClasses = new HashSet>(); + + @Override + public boolean matches(Type type, ItemStack stack, ItemStack target, boolean precise) { + if (type == Type.TYPE) { + Class kl = stack.getItem().getClass(); + return itemClasses.contains(kl) && kl.equals(target.getClass()); + } + return false; + } + + @Override + public List getClientExamples(Type type, ItemStack stack) { + return null; + } +} diff --git a/common/buildcraft/core/list/ListMatchHandlerOreDictionary.java b/common/buildcraft/core/list/ListMatchHandlerOreDictionary.java new file mode 100644 index 00000000..9d502ef3 --- /dev/null +++ b/common/buildcraft/core/list/ListMatchHandlerOreDictionary.java @@ -0,0 +1,72 @@ +package buildcraft.core.list; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import net.minecraft.item.ItemStack; +import net.minecraftforge.oredict.OreDictionary; + +import buildcraft.core.lib.utils.OreDictionaryCache; + +public class ListMatchHandlerOreDictionary extends ListMatchHandler { + @Override + public boolean matches(Type type, ItemStack stack, ItemStack target, boolean precise) { + int[] oreIds = OreDictionary.getOreIDs(stack); + int[] matchesIds = OreDictionary.getOreIDs(target); + + if (type == Type.CLASS) { + for (int i : oreIds) { + for (int j : matchesIds) { + if (i == j) { + return true; + } + } + } + } else { + for (int i : oreIds) { + String s = OreDictionary.getOreName(i); + Set stackIds = OreDictionaryCache.INSTANCE.getListOfPartialMatches( + type == Type.MATERIAL ? OreDictionaryCache.getSecondHalf(s) : OreDictionaryCache.getFirstHalf(s) + ); + if (stackIds != null) { + for (int j : stackIds) { + for (int k : matchesIds) { + if (j == k) { + return true; + } + } + } + } + } + } + + return false; + } + + @Override + public List getClientExamples(Type type, ItemStack stack) { + int[] oreIds = OreDictionary.getOreIDs(stack); + List stacks = new ArrayList(); + + if (type == Type.CLASS) { + for (int i : oreIds) { + stacks.addAll(OreDictionary.getOres(i)); + } + } else { + for (int i : oreIds) { + String s = OreDictionary.getOreName(i); + Set stackIds = OreDictionaryCache.INSTANCE.getListOfPartialMatches( + type == Type.MATERIAL ? OreDictionaryCache.getSecondHalf(s) : OreDictionaryCache.getFirstHalf(s) + ); + if (stackIds != null) { + for (int j : stackIds) { + stacks.addAll(OreDictionary.getOres(j)); + } + } + } + } + + return stacks; + } +} diff --git a/common/buildcraft/core/list/ListRegistry.java b/common/buildcraft/core/list/ListRegistry.java new file mode 100644 index 00000000..d15b36e8 --- /dev/null +++ b/common/buildcraft/core/list/ListRegistry.java @@ -0,0 +1,19 @@ +package buildcraft.core.list; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class ListRegistry { + private static final List handlers = new ArrayList(); + + public static void registerHandler(ListMatchHandler h) { + if (h != null) { + handlers.add(h); + } + } + + public static List getHandlers() { + return Collections.unmodifiableList(handlers); + } +} diff --git a/common/buildcraft/factory/gui/GuiRefinery.java b/common/buildcraft/factory/gui/GuiRefinery.java index 58039b01..b0be7d83 100644 --- a/common/buildcraft/factory/gui/GuiRefinery.java +++ b/common/buildcraft/factory/gui/GuiRefinery.java @@ -58,7 +58,7 @@ public class GuiRefinery extends GuiAdvancedInterface { drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize); updateSlots(); - drawBackgroundSlots(); + drawBackgroundSlots(x, y); } @Override diff --git a/common/buildcraft/robotics/TileZonePlan.java b/common/buildcraft/robotics/TileZonePlan.java index 8e3ff192..4cedaabe 100644 --- a/common/buildcraft/robotics/TileZonePlan.java +++ b/common/buildcraft/robotics/TileZonePlan.java @@ -23,7 +23,6 @@ import buildcraft.api.core.IZone; import buildcraft.api.items.IMapLocation; import buildcraft.api.items.INamedItem; import buildcraft.core.ItemMapLocation; -import buildcraft.core.ZonePlan; import buildcraft.core.lib.block.TileBuildCraft; import buildcraft.core.lib.inventory.SimpleInventory; import buildcraft.core.lib.network.Packet; diff --git a/common/buildcraft/core/ZoneChunk.java b/common/buildcraft/robotics/ZoneChunk.java similarity index 99% rename from common/buildcraft/core/ZoneChunk.java rename to common/buildcraft/robotics/ZoneChunk.java index d0504b6f..0355eb50 100755 --- a/common/buildcraft/core/ZoneChunk.java +++ b/common/buildcraft/robotics/ZoneChunk.java @@ -6,7 +6,7 @@ * License 1.0, or MMPL. Please check the contents of the license located in * http://www.mod-buildcraft.com/MMPL-1.0.txt */ -package buildcraft.core; +package buildcraft.robotics; import java.util.BitSet; import java.util.Random; diff --git a/common/buildcraft/core/ZonePlan.java b/common/buildcraft/robotics/ZonePlan.java similarity index 98% rename from common/buildcraft/core/ZonePlan.java rename to common/buildcraft/robotics/ZonePlan.java index 665743ed..315daa82 100755 --- a/common/buildcraft/core/ZonePlan.java +++ b/common/buildcraft/robotics/ZonePlan.java @@ -6,7 +6,7 @@ * License 1.0, or MMPL. Please check the contents of the license located in * http://www.mod-buildcraft.com/MMPL-1.0.txt */ -package buildcraft.core; +package buildcraft.robotics; import java.util.HashMap; import java.util.Map; @@ -21,6 +21,7 @@ import net.minecraftforge.common.util.Constants; import buildcraft.api.core.BlockIndex; import buildcraft.api.core.ISerializable; import buildcraft.api.core.IZone; +import buildcraft.core.ChunkIndex; public class ZonePlan implements IZone, ISerializable { private HashMap chunkMapping = new HashMap(); diff --git a/common/buildcraft/robotics/gui/ContainerZonePlan.java b/common/buildcraft/robotics/gui/ContainerZonePlan.java index f62afb2f..87424693 100755 --- a/common/buildcraft/robotics/gui/ContainerZonePlan.java +++ b/common/buildcraft/robotics/gui/ContainerZonePlan.java @@ -18,7 +18,7 @@ import cpw.mods.fml.relauncher.Side; import buildcraft.BuildCraftCore; import buildcraft.BuildCraftRobotics; -import buildcraft.core.ZonePlan; +import buildcraft.robotics.ZonePlan; import buildcraft.core.lib.gui.BuildCraftContainer; import buildcraft.core.lib.gui.slots.SlotOutput; import buildcraft.core.lib.network.command.CommandWriter; diff --git a/common/buildcraft/robotics/gui/GuiRequester.java b/common/buildcraft/robotics/gui/GuiRequester.java index 2eb807b0..dd6de927 100755 --- a/common/buildcraft/robotics/gui/GuiRequester.java +++ b/common/buildcraft/robotics/gui/GuiRequester.java @@ -80,7 +80,7 @@ public class GuiRequester extends GuiAdvancedInterface { protected void drawGuiContainerBackgroundLayer(float f, int x, int y) { super.drawGuiContainerBackgroundLayer(f, x, y); - drawBackgroundSlots(); + drawBackgroundSlots(x, y); } @Override diff --git a/common/buildcraft/robotics/gui/GuiZonePlan.java b/common/buildcraft/robotics/gui/GuiZonePlan.java index c6ae18a0..23b9619f 100755 --- a/common/buildcraft/robotics/gui/GuiZonePlan.java +++ b/common/buildcraft/robotics/gui/GuiZonePlan.java @@ -25,7 +25,7 @@ import net.minecraft.util.ResourceLocation; import buildcraft.BuildCraftCore; import buildcraft.api.core.EnumColor; import buildcraft.core.DefaultProps; -import buildcraft.core.ZonePlan; +import buildcraft.robotics.ZonePlan; import buildcraft.core.lib.gui.AdvancedSlot; import buildcraft.core.lib.gui.GuiAdvancedInterface; import buildcraft.core.lib.gui.buttons.GuiBetterButton; @@ -213,7 +213,7 @@ public class GuiZonePlan extends GuiAdvancedInterface { } if (!isFullscreen()) { - drawBackgroundSlots(); + drawBackgroundSlots(x, y); bindTexture(texture); diff --git a/common/buildcraft/silicon/gui/GuiAssemblyTable.java b/common/buildcraft/silicon/gui/GuiAssemblyTable.java index 820a7cba..06bc695f 100644 --- a/common/buildcraft/silicon/gui/GuiAssemblyTable.java +++ b/common/buildcraft/silicon/gui/GuiAssemblyTable.java @@ -172,7 +172,7 @@ public class GuiAssemblyTable extends GuiAdvancedInterface { drawTexturedModalRect(guiLeft + 86, guiTop + 36 + 70 - h, 176, 18, 4, h); - drawBackgroundSlots(); + drawBackgroundSlots(x, y); } @Override diff --git a/common/buildcraft/silicon/gui/GuiProgrammingTable.java b/common/buildcraft/silicon/gui/GuiProgrammingTable.java index abd218e9..d278c144 100644 --- a/common/buildcraft/silicon/gui/GuiProgrammingTable.java +++ b/common/buildcraft/silicon/gui/GuiProgrammingTable.java @@ -154,7 +154,7 @@ public class GuiProgrammingTable extends GuiAdvancedInterface { drawTexturedModalRect(guiLeft + 164, guiTop + 36 + 70 - h, 176, 18, 4, h); - drawBackgroundSlots(); + drawBackgroundSlots(x, y); } @Override diff --git a/common/buildcraft/transport/gui/GuiGateInterface.java b/common/buildcraft/transport/gui/GuiGateInterface.java index 3e1c6437..2fb23a12 100644 --- a/common/buildcraft/transport/gui/GuiGateInterface.java +++ b/common/buildcraft/transport/gui/GuiGateInterface.java @@ -265,7 +265,7 @@ public class GuiGateInterface extends GuiAdvancedInterface { } } - drawBackgroundSlots(); + drawBackgroundSlots(x, y); } private void doSlotClick(AdvancedSlot slot, int k) {