make AdvancedSlots highlight, move more zone planner code to Robotics, initial implementation of new Lists (some GUI parts missing)
This commit is contained in:
parent
24dbaa4369
commit
14edb8c466
34 changed files with 992 additions and 286 deletions
Binary file not shown.
After Width: | Height: | Size: 3.5 KiB |
|
@ -26,6 +26,7 @@ import net.minecraft.entity.EntityList;
|
|||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemFood;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.stats.Achievement;
|
||||
import net.minecraft.util.IIcon;
|
||||
|
@ -121,8 +122,12 @@ import buildcraft.core.lib.engines.TileEngineBase;
|
|||
import buildcraft.core.lib.network.ChannelHandler;
|
||||
import buildcraft.core.lib.utils.ColorUtils;
|
||||
import buildcraft.core.lib.utils.NBTUtils;
|
||||
import buildcraft.core.lib.utils.OreDictionaryCache;
|
||||
import buildcraft.core.lib.utils.Utils;
|
||||
import buildcraft.core.lib.utils.XorShift128Random;
|
||||
import buildcraft.core.list.ListMatchHandlerClass;
|
||||
import buildcraft.core.list.ListMatchHandlerOreDictionary;
|
||||
import buildcraft.core.list.ListRegistry;
|
||||
import buildcraft.core.network.PacketHandlerCore;
|
||||
import buildcraft.core.properties.WorldPropertyIsDirt;
|
||||
import buildcraft.core.properties.WorldPropertyIsFarmland;
|
||||
|
@ -453,6 +458,9 @@ public class BuildCraftCore extends BuildCraftMod {
|
|||
StatementManager.registerParameterClass(PatternParameterXZDir.class);
|
||||
StatementManager.registerParameterClass(PatternParameterCenter.class);
|
||||
StatementManager.registerParameterClass(PatternParameterHollow.class);
|
||||
|
||||
ListRegistry.registerHandler(new ListMatchHandlerClass());
|
||||
ListMatchHandlerClass.itemClasses.add(ItemFood.class);
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
|
@ -497,6 +505,13 @@ public class BuildCraftCore extends BuildCraftMod {
|
|||
actionControl[mode.ordinal()] = new ActionMachineControl(mode);
|
||||
}
|
||||
}
|
||||
|
||||
MinecraftForge.EVENT_BUS.register(OreDictionaryCache.INSTANCE);
|
||||
for (String s : OreDictionary.getOreNames()) {
|
||||
OreDictionaryCache.INSTANCE.registerName(s);
|
||||
}
|
||||
|
||||
ListRegistry.registerHandler(new ListMatchHandlerOreDictionary());
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
|
|
|
@ -122,7 +122,7 @@ public class GuiBuilder extends GuiAdvancedInterface {
|
|||
}
|
||||
|
||||
if (isBlueprint) {
|
||||
drawBackgroundSlots();
|
||||
drawBackgroundSlots(x, y);
|
||||
|
||||
for (int i = 0; i < builder.fluidTanks.length; i++) {
|
||||
Tank tank = builder.fluidTanks[i];
|
||||
|
|
|
@ -155,7 +155,7 @@ public class GuiFiller extends GuiAdvancedInterface {
|
|||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float f, int mx, int my) {
|
||||
super.drawGuiContainerBackgroundLayer(f, mx, my);
|
||||
drawBackgroundSlots();
|
||||
drawBackgroundSlots(mx, my);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -129,7 +129,7 @@ public class GuiUrbanist extends GuiAdvancedInterface {
|
|||
tools [selectedTool].drawGuiContainerBackgroundLayer(this, f, x, y);
|
||||
}
|
||||
|
||||
drawBackgroundSlots();
|
||||
drawBackgroundSlots(x, y);
|
||||
|
||||
if (selectedTool != -1) {
|
||||
tools [selectedTool].drawSelection(this, f, x, y);
|
||||
|
|
|
@ -12,23 +12,29 @@ import net.minecraft.entity.player.EntityPlayer;
|
|||
import net.minecraft.world.World;
|
||||
import cpw.mods.fml.common.network.IGuiHandler;
|
||||
|
||||
import buildcraft.core.gui.ContainerList;
|
||||
import buildcraft.core.gui.GuiList;
|
||||
import buildcraft.core.list.ContainerListNew;
|
||||
import buildcraft.core.list.ContainerListOld;
|
||||
import buildcraft.core.list.GuiListNew;
|
||||
import buildcraft.core.list.GuiListOld;
|
||||
|
||||
public class CoreGuiHandler implements IGuiHandler {
|
||||
|
||||
@Override
|
||||
public Object getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) {
|
||||
if (id == GuiIds.LIST) {
|
||||
return new GuiList(player);
|
||||
if (id == GuiIds.LIST_OLD) {
|
||||
return new GuiListOld(player);
|
||||
} else if (id == GuiIds.LIST_NEW) {
|
||||
return new GuiListNew(player);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) {
|
||||
if (id == GuiIds.LIST) {
|
||||
return new ContainerList(player);
|
||||
if (id == GuiIds.LIST_OLD) {
|
||||
return new ContainerListOld(player);
|
||||
} else if (id == GuiIds.LIST_NEW) {
|
||||
return new ContainerListNew(player);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -17,8 +17,9 @@ public final class GuiIds {
|
|||
public static final int URBANIST = 14;
|
||||
public static final int MAP = 15;
|
||||
public static final int REQUESTER = 16;
|
||||
public static final int LIST = 17;
|
||||
public static final int LIST_OLD = 17;
|
||||
public static final int TABLET = 18;
|
||||
public static final int LIST_NEW = 19;
|
||||
|
||||
public static final int ENGINE_IRON = 20;
|
||||
public static final int ENGINE_STONE = 21;
|
||||
|
|
|
@ -8,216 +8,38 @@
|
|||
*/
|
||||
package buildcraft.core;
|
||||
|
||||
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.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import net.minecraft.world.World;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import buildcraft.BuildCraftCore;
|
||||
import buildcraft.api.items.IList;
|
||||
import buildcraft.core.lib.inventory.StackHelper;
|
||||
import buildcraft.core.lib.items.ItemBuildCraft;
|
||||
import buildcraft.core.lib.utils.NBTUtils;
|
||||
import buildcraft.core.list.ListHandlerNew;
|
||||
import buildcraft.core.list.ListHandlerOld;
|
||||
|
||||
public class ItemList extends ItemBuildCraft implements IList {
|
||||
private static final WeakHashMap<ItemStack, StackLine[]> LINE_CACHE = new WeakHashMap<ItemStack, StackLine[]>();
|
||||
|
||||
public static class StackLine {
|
||||
public boolean oreWildcard = false;
|
||||
public boolean subitemsWildcard = false;
|
||||
public boolean isOre;
|
||||
|
||||
private ItemStack[] stacks = new ItemStack[7];
|
||||
private ArrayList<ItemStack> ores = new ArrayList<ItemStack>();
|
||||
private ArrayList<ItemStack> relatedItems = new ArrayList<ItemStack>();
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -113,4 +113,8 @@ public abstract class AdvancedSlot {
|
|||
public void selected () {
|
||||
|
||||
}
|
||||
|
||||
public boolean shouldDrawHighlight() {
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,4 +50,9 @@ public abstract class StatementSlot extends AdvancedSlot {
|
|||
}
|
||||
|
||||
public abstract IStatement getStatement();
|
||||
|
||||
@Override
|
||||
public boolean shouldDrawHighlight() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
81
common/buildcraft/core/lib/utils/OreDictionaryCache.java
Normal file
81
common/buildcraft/core/lib/utils/OreDictionaryCache.java
Normal file
|
@ -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<String, Set<Integer>> namingCache = new HashMap<String, Set<Integer>>();
|
||||
private final Set<String> registeredNames = new HashSet<String>();
|
||||
|
||||
private OreDictionaryCache() {
|
||||
|
||||
}
|
||||
|
||||
public Set<Integer> getListOfPartialMatches(String part) {
|
||||
return namingCache.get(part);
|
||||
}
|
||||
|
||||
private void addToNamingCache(String s, int id) {
|
||||
if (s == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Set<Integer> ll = namingCache.get(s);
|
||||
|
||||
if (ll == null) {
|
||||
ll = new HashSet<Integer>();
|
||||
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);
|
||||
}
|
||||
}
|
104
common/buildcraft/core/list/ContainerListNew.java
Executable file
104
common/buildcraft/core/list/ContainerListNew.java
Executable file
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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() {
|
127
common/buildcraft/core/list/GuiListNew.java
Executable file
127
common/buildcraft/core/list/GuiListNew.java
Executable file
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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);
|
166
common/buildcraft/core/list/ListHandlerNew.java
Normal file
166
common/buildcraft/core/list/ListHandlerNew.java
Normal file
|
@ -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<ListMatchHandler> 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;
|
||||
}
|
||||
}
|
245
common/buildcraft/core/list/ListHandlerOld.java
Normal file
245
common/buildcraft/core/list/ListHandlerOld.java
Normal file
|
@ -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<ItemStack, StackLine[]> LINE_CACHE = new WeakHashMap<ItemStack, StackLine[]>();
|
||||
|
||||
public static class StackLine {
|
||||
public boolean oreWildcard = false;
|
||||
public boolean subitemsWildcard = false;
|
||||
public boolean isOre;
|
||||
|
||||
private ItemStack[] stacks = new ItemStack[7];
|
||||
private ArrayList<ItemStack> ores = new ArrayList<ItemStack>();
|
||||
private ArrayList<ItemStack> relatedItems = new ArrayList<ItemStack>();
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
17
common/buildcraft/core/list/ListMatchHandler.java
Normal file
17
common/buildcraft/core/list/ListMatchHandler.java
Normal file
|
@ -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<ItemStack> getClientExamples(Type type, ItemStack stack);
|
||||
}
|
26
common/buildcraft/core/list/ListMatchHandlerClass.java
Normal file
26
common/buildcraft/core/list/ListMatchHandlerClass.java
Normal file
|
@ -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<Class<? extends Item>> itemClasses = new HashSet<Class<? extends Item>>();
|
||||
|
||||
@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<ItemStack> getClientExamples(Type type, ItemStack stack) {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -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<Integer> 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<ItemStack> getClientExamples(Type type, ItemStack stack) {
|
||||
int[] oreIds = OreDictionary.getOreIDs(stack);
|
||||
List<ItemStack> stacks = new ArrayList<ItemStack>();
|
||||
|
||||
if (type == Type.CLASS) {
|
||||
for (int i : oreIds) {
|
||||
stacks.addAll(OreDictionary.getOres(i));
|
||||
}
|
||||
} else {
|
||||
for (int i : oreIds) {
|
||||
String s = OreDictionary.getOreName(i);
|
||||
Set<Integer> 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;
|
||||
}
|
||||
}
|
19
common/buildcraft/core/list/ListRegistry.java
Normal file
19
common/buildcraft/core/list/ListRegistry.java
Normal file
|
@ -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<ListMatchHandler> handlers = new ArrayList<ListMatchHandler>();
|
||||
|
||||
public static void registerHandler(ListMatchHandler h) {
|
||||
if (h != null) {
|
||||
handlers.add(h);
|
||||
}
|
||||
}
|
||||
|
||||
public static List getHandlers() {
|
||||
return Collections.unmodifiableList(handlers);
|
||||
}
|
||||
}
|
|
@ -58,7 +58,7 @@ public class GuiRefinery extends GuiAdvancedInterface {
|
|||
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
|
||||
|
||||
updateSlots();
|
||||
drawBackgroundSlots();
|
||||
drawBackgroundSlots(x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
|
@ -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<ChunkIndex, ZoneChunk> chunkMapping = new HashMap<ChunkIndex, ZoneChunk>();
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -265,7 +265,7 @@ public class GuiGateInterface extends GuiAdvancedInterface {
|
|||
}
|
||||
}
|
||||
|
||||
drawBackgroundSlots();
|
||||
drawBackgroundSlots(x, y);
|
||||
}
|
||||
|
||||
private void doSlotClick(AdvancedSlot slot, int k) {
|
||||
|
|
Loading…
Reference in a new issue