Add necessary GUI implementation for new mod ID filters

This commit is contained in:
Aidan C. Brady 2014-06-14 10:26:12 +02:00
parent 1a0821c727
commit 31dd643259
7 changed files with 296 additions and 410 deletions

View file

@ -12,9 +12,11 @@ import mekanism.api.EnumColor;
import mekanism.client.render.MekanismRenderer;
import mekanism.client.sound.SoundHandler;
import mekanism.common.Mekanism;
import mekanism.common.OreDictCache;
import mekanism.common.inventory.container.ContainerNull;
import mekanism.common.miner.MItemStackFilter;
import mekanism.common.miner.MMaterialFilter;
import mekanism.common.miner.MModIDFilter;
import mekanism.common.miner.MOreDictFilter;
import mekanism.common.miner.MinerFilter;
import mekanism.common.network.PacketDigitalMinerGui.DigitalMinerGuiMessage;
@ -26,9 +28,7 @@ import mekanism.common.util.MekanismUtils.ResourceType;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11;
@ -48,6 +48,7 @@ public class GuiDigitalMinerConfig extends GuiMekanism
public int stackSwitch = 0;
public Map<MOreDictFilter, StackData> oreDictStacks = new HashMap<MOreDictFilter, StackData>();
public Map<MModIDFilter, StackData> modIDStacks = new HashMap<MModIDFilter, StackData>();
public float scroll;
@ -109,6 +110,23 @@ public class GuiDigitalMinerConfig extends GuiMekanism
}
}
for(Map.Entry<MModIDFilter, StackData> entry : modIDStacks.entrySet())
{
if(entry.getValue().iterStacks != null && entry.getValue().iterStacks.size() > 0)
{
if(entry.getValue().stackIndex == -1 || entry.getValue().stackIndex == entry.getValue().iterStacks.size()-1)
{
entry.getValue().stackIndex = 0;
}
else if(entry.getValue().stackIndex < entry.getValue().iterStacks.size()-1)
{
entry.getValue().stackIndex++;
}
entry.getValue().renderStack = entry.getValue().iterStacks.get(entry.getValue().stackIndex);
}
}
stackSwitch = 20;
}
else {
@ -119,27 +137,47 @@ public class GuiDigitalMinerConfig extends GuiMekanism
entry.getValue().renderStack = null;
}
}
for(Map.Entry<MModIDFilter, StackData> entry : modIDStacks.entrySet())
{
if(entry.getValue().iterStacks != null && entry.getValue().iterStacks.size() == 0)
{
entry.getValue().renderStack = null;
}
}
}
Set<MOreDictFilter> filtersVisible = new HashSet<MOreDictFilter>();
Set<MOreDictFilter> oreDictFilters = new HashSet<MOreDictFilter>();
Set<MModIDFilter> modIDFilters = new HashSet<MModIDFilter>();
for(int i = 0; i < 4; i++)
{
if(tileEntity.filters.get(getFilterIndex()+i) instanceof MOreDictFilter)
{
filtersVisible.add((MOreDictFilter)tileEntity.filters.get(getFilterIndex()+i));
oreDictFilters.add((MOreDictFilter)tileEntity.filters.get(getFilterIndex()+i));
}
else if(tileEntity.filters.get(getFilterIndex()+i) instanceof MModIDFilter)
{
modIDFilters.add((MModIDFilter)tileEntity.filters.get(getFilterIndex()+i));
}
}
for(MinerFilter filter : tileEntity.filters)
{
if(filter instanceof MOreDictFilter && !filtersVisible.contains(filter))
if(filter instanceof MOreDictFilter && !oreDictFilters.contains(filter))
{
if(oreDictStacks.containsKey(filter))
{
oreDictStacks.remove(filter);
}
}
else if(filter instanceof MModIDFilter && !modIDFilters.contains(filter))
{
if(modIDStacks.containsKey(filter))
{
modIDStacks.remove(filter);
}
}
}
}
@ -301,9 +339,8 @@ public class GuiDigitalMinerConfig extends GuiMekanism
fontRendererObj.drawString(MekanismUtils.localize("gui.digitalMinerConfig"), 43, 6, 0x404040);
fontRendererObj.drawString(MekanismUtils.localize("gui.filters") + ":", 11, 19, 0x00CD00);
fontRendererObj.drawString("IS: " + getItemStackFilters().size(), 11, 28, 0x00CD00);
fontRendererObj.drawString("OD: " + getOreDictFilters().size(), 11, 37, 0x00CD00);
fontRendererObj.drawString("M: " + getMaterialFilters().size(), 11, 46, 0x00CD00);
fontRendererObj.drawString("T: " + tileEntity.filters.size(), 11, 28, 0x00CD00);
fontRendererObj.drawString("I: " + (tileEntity.inverse ? MekanismUtils.localize("gui.on") : MekanismUtils.localize("gui.off")), 11, 131, 0x00CD00);
fontRendererObj.drawString("Radi: " + tileEntity.radius, 11, 58, 0x00CD00);
@ -371,6 +408,28 @@ public class GuiDigitalMinerConfig extends GuiMekanism
fontRendererObj.drawString(MekanismUtils.localize("gui.materialFilter"), 78, yStart + 2, 0x404040);
}
else if(filter instanceof MModIDFilter)
{
MModIDFilter modFilter = (MModIDFilter)filter;
if(!modIDStacks.containsKey(modFilter))
{
updateStackList(modFilter);
}
if(modIDStacks.get(filter).renderStack != null)
{
try {
GL11.glPushMatrix();
GL11.glEnable(GL11.GL_LIGHTING);
itemRender.renderItemAndEffectIntoGUI(fontRendererObj, mc.getTextureManager(), modIDStacks.get(filter).renderStack, 59, yStart + 3);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glPopMatrix();
} catch(Exception e) {}
}
fontRendererObj.drawString(MekanismUtils.localize("gui.modIDFilter"), 78, yStart + 2, 0x404040);
}
}
}
@ -419,6 +478,10 @@ public class GuiDigitalMinerConfig extends GuiMekanism
{
MekanismRenderer.color(EnumColor.PURPLE, 1.0F, 4F);
}
else if(filter instanceof MModIDFilter)
{
MekanismRenderer.color(EnumColor.PINK, 1.0F, 2.5F);
}
drawTexturedModalRect(guiWidth + 56, guiHeight + yStart, mouseOver ? 0 : 96, 166, 96, 29);
MekanismRenderer.resetColor();
@ -550,51 +613,6 @@ public class GuiDigitalMinerConfig extends GuiMekanism
}
}
public ArrayList getItemStackFilters()
{
ArrayList list = new ArrayList();
for(MinerFilter filter : tileEntity.filters)
{
if(filter instanceof MItemStackFilter)
{
list.add(filter);
}
}
return list;
}
public ArrayList getOreDictFilters()
{
ArrayList list = new ArrayList();
for(MinerFilter filter : tileEntity.filters)
{
if(filter instanceof MOreDictFilter)
{
list.add(filter);
}
}
return list;
}
public ArrayList getMaterialFilters()
{
ArrayList list = new ArrayList();
for(MinerFilter filter : tileEntity.filters)
{
if(filter instanceof MMaterialFilter)
{
list.add(filter);
}
}
return list;
}
private void updateStackList(MOreDictFilter filter)
{
if(!oreDictStacks.containsKey(filter))
@ -602,63 +620,27 @@ public class GuiDigitalMinerConfig extends GuiMekanism
oreDictStacks.put(filter, new StackData());
}
if(oreDictStacks.get(filter).iterStacks == null)
{
oreDictStacks.get(filter).iterStacks = new ArrayList<ItemStack>();
}
else {
oreDictStacks.get(filter).iterStacks.clear();
}
List<String> keys = new ArrayList<String>();
for(String s : OreDictionary.getOreNames())
{
if(filter.oreDictName.equals(s) || filter.oreDictName.equals("*"))
{
keys.add(s);
}
else if(filter.oreDictName.endsWith("*") && !filter.oreDictName.startsWith("*"))
{
if(s.startsWith(filter.oreDictName.substring(0, filter.oreDictName.length()-1)))
{
keys.add(s);
}
}
else if(filter.oreDictName.startsWith("*") && !filter.oreDictName.endsWith("*"))
{
if(s.endsWith(filter.oreDictName.substring(1)))
{
keys.add(s);
}
}
else if(filter.oreDictName.startsWith("*") && filter.oreDictName.endsWith("*"))
{
if(s.contains(filter.oreDictName.substring(1, filter.oreDictName.length()-1)))
{
keys.add(s);
}
}
}
for(String key : keys)
{
for(ItemStack stack : OreDictionary.getOres(key))
{
ItemStack toAdd = stack.copy();
if(!oreDictStacks.get(filter).iterStacks.contains(stack) && toAdd.getItem() instanceof ItemBlock)
{
oreDictStacks.get(filter).iterStacks.add(stack.copy());
}
}
}
oreDictStacks.get(filter).iterStacks = OreDictCache.getOreDictStacks(filter.oreDictName, true);
stackSwitch = 0;
updateScreen();
oreDictStacks.get(filter).stackIndex = -1;
}
private void updateStackList(MModIDFilter filter)
{
if(!modIDStacks.containsKey(filter))
{
modIDStacks.put(filter, new StackData());
}
modIDStacks.get(filter).iterStacks = OreDictCache.getModIDStacks(filter.modID, true);
stackSwitch = 0;
updateScreen();
modIDStacks.get(filter).stackIndex = -1;
}
public static class StackData
{
public List<ItemStack> iterStacks;

View file

@ -12,6 +12,7 @@ import mekanism.api.EnumColor;
import mekanism.client.render.MekanismRenderer;
import mekanism.client.sound.SoundHandler;
import mekanism.common.Mekanism;
import mekanism.common.OreDictCache;
import mekanism.common.inventory.container.ContainerNull;
import mekanism.common.network.PacketLogisticalSorterGui.LogisticalSorterGuiMessage;
import mekanism.common.network.PacketLogisticalSorterGui.SorterGuiPacket;
@ -19,6 +20,7 @@ import mekanism.common.network.PacketTileEntity.TileEntityMessage;
import mekanism.common.tile.TileEntityLogisticalSorter;
import mekanism.common.transporter.TItemStackFilter;
import mekanism.common.transporter.TMaterialFilter;
import mekanism.common.transporter.TModIDFilter;
import mekanism.common.transporter.TOreDictFilter;
import mekanism.common.transporter.TransporterFilter;
import mekanism.common.util.MekanismUtils;
@ -26,7 +28,6 @@ import mekanism.common.util.MekanismUtils.ResourceType;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11;
@ -47,6 +48,7 @@ public class GuiLogisticalSorter extends GuiMekanism
public int stackSwitch = 0;
public Map<TOreDictFilter, StackData> oreDictStacks = new HashMap<TOreDictFilter, StackData>();
public Map<TModIDFilter, StackData> modIDStacks = new HashMap<TModIDFilter, StackData>();
public float scroll;
@ -101,6 +103,23 @@ public class GuiLogisticalSorter extends GuiMekanism
}
}
for(Map.Entry<TModIDFilter, StackData> entry : modIDStacks.entrySet())
{
if(entry.getValue().iterStacks != null && entry.getValue().iterStacks.size() > 0)
{
if(entry.getValue().stackIndex == -1 || entry.getValue().stackIndex == entry.getValue().iterStacks.size()-1)
{
entry.getValue().stackIndex = 0;
}
else if(entry.getValue().stackIndex < entry.getValue().iterStacks.size()-1)
{
entry.getValue().stackIndex++;
}
entry.getValue().renderStack = entry.getValue().iterStacks.get(entry.getValue().stackIndex);
}
}
stackSwitch = 20;
}
else {
@ -111,27 +130,47 @@ public class GuiLogisticalSorter extends GuiMekanism
entry.getValue().renderStack = null;
}
}
for(Map.Entry<TModIDFilter, StackData> entry : modIDStacks.entrySet())
{
if(entry.getValue().iterStacks != null && entry.getValue().iterStacks.size() == 0)
{
entry.getValue().renderStack = null;
}
}
}
Set<TOreDictFilter> filtersVisible = new HashSet<TOreDictFilter>();
Set<TOreDictFilter> oreDictFilters = new HashSet<TOreDictFilter>();
Set<TModIDFilter> modIDFilters = new HashSet<TModIDFilter>();
for(int i = 0; i < 4; i++)
{
if(tileEntity.filters.get(getFilterIndex()+i) instanceof TOreDictFilter)
{
filtersVisible.add((TOreDictFilter)tileEntity.filters.get(getFilterIndex()+i));
oreDictFilters.add((TOreDictFilter)tileEntity.filters.get(getFilterIndex()+i));
}
else if(tileEntity.filters.get(getFilterIndex()+i) instanceof TModIDFilter)
{
modIDFilters.add((TModIDFilter)tileEntity.filters.get(getFilterIndex()+i));
}
}
for(TransporterFilter filter : tileEntity.filters)
{
if(filter instanceof TOreDictFilter && !filtersVisible.contains(filter))
if(filter instanceof TOreDictFilter && !oreDictFilters.contains(filter))
{
if(oreDictStacks.containsKey(filter))
{
oreDictStacks.remove(filter);
}
}
else if(filter instanceof TModIDFilter && !modIDFilters.contains(filter))
{
if(modIDStacks.containsKey(filter))
{
modIDStacks.remove(filter);
}
}
}
}
@ -273,9 +312,7 @@ public class GuiLogisticalSorter extends GuiMekanism
fontRendererObj.drawString(tileEntity.getInventoryName(), 43, 6, 0x404040);
fontRendererObj.drawString(MekanismUtils.localize("gui.filters") + ":", 11, 19, 0x00CD00);
fontRendererObj.drawString("IS: " + getItemStackFilters().size(), 11, 28, 0x00CD00);
fontRendererObj.drawString("OD: " + getOreDictFilters().size(), 11, 37, 0x00CD00);
fontRendererObj.drawString("M: " + getMaterialFilters().size(), 11, 46, 0x00CD00);
fontRendererObj.drawString("T: " + tileEntity.filters.size(), 11, 28, 0x00CD00);
fontRendererObj.drawString("RR:", 12, 74, 0x00CD00);
fontRendererObj.drawString(MekanismUtils.localize("gui." + (tileEntity.roundRobin ? "on" : "off")), 27, 86, 0x00CD00);
@ -347,6 +384,29 @@ public class GuiLogisticalSorter extends GuiMekanism
fontRendererObj.drawString(MekanismUtils.localize("gui.materialFilter"), 78, yStart + 2, 0x404040);
fontRendererObj.drawString(filter.color != null ? filter.color.getName() : MekanismUtils.localize("gui.none"), 78, yStart + 11, 0x404040);
}
else if(filter instanceof TModIDFilter)
{
TModIDFilter modFilter = (TModIDFilter)filter;
if(!modIDStacks.containsKey(modFilter))
{
updateStackList(modFilter);
}
if(modIDStacks.get(filter).renderStack != null)
{
try {
GL11.glPushMatrix();
GL11.glEnable(GL11.GL_LIGHTING);
itemRender.renderItemAndEffectIntoGUI(fontRendererObj, mc.getTextureManager(), modIDStacks.get(filter).renderStack, 59, yStart + 3);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glPopMatrix();
} catch(Exception e) {}
}
fontRendererObj.drawString(MekanismUtils.localize("gui.modIDFilter"), 78, yStart + 2, 0x404040);
fontRendererObj.drawString(filter.color != null ? filter.color.getName() : MekanismUtils.localize("gui.none"), 78, yStart + 11, 0x404040);
}
}
}
@ -425,6 +485,10 @@ public class GuiLogisticalSorter extends GuiMekanism
{
MekanismRenderer.color(EnumColor.PURPLE, 1.0F, 4F);
}
else if(filter instanceof TModIDFilter)
{
MekanismRenderer.color(EnumColor.PINK, 1.0F, 2.5F);
}
drawTexturedModalRect(guiWidth + 56, guiHeight + yStart, mouseOver ? 0 : 96, 166, 96, 29);
MekanismRenderer.resetColor();
@ -448,51 +512,6 @@ public class GuiLogisticalSorter extends GuiMekanism
}
}
public ArrayList getItemStackFilters()
{
ArrayList list = new ArrayList();
for(TransporterFilter filter : tileEntity.filters)
{
if(filter instanceof TItemStackFilter)
{
list.add(filter);
}
}
return list;
}
public ArrayList getOreDictFilters()
{
ArrayList list = new ArrayList();
for(TransporterFilter filter : tileEntity.filters)
{
if(filter instanceof TOreDictFilter)
{
list.add(filter);
}
}
return list;
}
public ArrayList getMaterialFilters()
{
ArrayList list = new ArrayList();
for(TransporterFilter filter : tileEntity.filters)
{
if(filter instanceof TMaterialFilter)
{
list.add(filter);
}
}
return list;
}
private void updateStackList(TOreDictFilter filter)
{
if(!oreDictStacks.containsKey(filter))
@ -500,63 +519,27 @@ public class GuiLogisticalSorter extends GuiMekanism
oreDictStacks.put(filter, new StackData());
}
if(oreDictStacks.get(filter).iterStacks == null)
{
oreDictStacks.get(filter).iterStacks = new ArrayList<ItemStack>();
}
else {
oreDictStacks.get(filter).iterStacks.clear();
}
List<String> keys = new ArrayList<String>();
for(String s : OreDictionary.getOreNames())
{
if(filter.oreDictName.equals(s) || filter.oreDictName.equals("*"))
{
keys.add(s);
}
else if(filter.oreDictName.endsWith("*") && !filter.oreDictName.startsWith("*"))
{
if(s.startsWith(filter.oreDictName.substring(0, filter.oreDictName.length()-1)))
{
keys.add(s);
}
}
else if(filter.oreDictName.startsWith("*") && !filter.oreDictName.endsWith("*"))
{
if(s.endsWith(filter.oreDictName.substring(1)))
{
keys.add(s);
}
}
else if(filter.oreDictName.startsWith("*") && filter.oreDictName.endsWith("*"))
{
if(s.contains(filter.oreDictName.substring(1, filter.oreDictName.length()-1)))
{
keys.add(s);
}
}
}
for(String key : keys)
{
for(ItemStack stack : OreDictionary.getOres(key))
{
ItemStack toAdd = stack.copy();
if(!oreDictStacks.get(filter).iterStacks.contains(stack))
{
oreDictStacks.get(filter).iterStacks.add(stack.copy());
}
}
}
oreDictStacks.get(filter).iterStacks = OreDictCache.getOreDictStacks(filter.oreDictName, false);
stackSwitch = 0;
updateScreen();
oreDictStacks.get(filter).stackIndex = -1;
}
private void updateStackList(TModIDFilter filter)
{
if(!modIDStacks.containsKey(filter))
{
modIDStacks.put(filter, new StackData());
}
modIDStacks.get(filter).iterStacks = OreDictCache.getModIDStacks(filter.modID, false);
stackSwitch = 0;
updateScreen();
modIDStacks.get(filter).stackIndex = -1;
}
public static class StackData
{
public List<ItemStack> iterStacks;

View file

@ -1,12 +1,12 @@
package mekanism.client.gui;
import java.util.ArrayList;
import java.util.List;
import mekanism.api.Coord4D;
import mekanism.api.EnumColor;
import mekanism.client.sound.SoundHandler;
import mekanism.common.Mekanism;
import mekanism.common.OreDictCache;
import mekanism.common.inventory.container.ContainerFilter;
import mekanism.common.miner.MModIDFilter;
import mekanism.common.network.PacketDigitalMinerGui.DigitalMinerGuiMessage;
@ -19,9 +19,7 @@ import mekanism.common.util.MekanismUtils.ResourceType;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11;
@ -277,51 +275,7 @@ public class GuiMModIDFilter extends GuiMekanism
private void updateStackList(String modName)
{
if(iterStacks == null)
{
iterStacks = new ArrayList<ItemStack>();
}
else {
iterStacks.clear();
}
for(String key : OreDictionary.getOreNames())
{
for(ItemStack stack : OreDictionary.getOres(key))
{
ItemStack toAdd = stack.copy();
String s = MekanismUtils.getMod(toAdd);
if(!iterStacks.contains(stack) && toAdd.getItem() instanceof ItemBlock)
{
if(modName.equals(s) || modName.equals("*"))
{
iterStacks.add(stack.copy());
}
else if(modName.endsWith("*") && !modName.startsWith("*"))
{
if(s.startsWith(modName.substring(0, modName.length()-1)))
{
iterStacks.add(stack.copy());
}
}
else if(modName.startsWith("*") && !modName.endsWith("*"))
{
if(s.endsWith(modName.substring(1)))
{
iterStacks.add(stack.copy());
}
}
else if(modName.startsWith("*") && modName.endsWith("*"))
{
if(s.contains(modName.substring(1, modName.length()-1)))
{
iterStacks.add(stack.copy());
}
}
}
}
}
iterStacks = OreDictCache.getModIDStacks(modName, true);
stackSwitch = 0;
stackIndex = -1;

View file

@ -7,6 +7,7 @@ import mekanism.api.Coord4D;
import mekanism.api.EnumColor;
import mekanism.client.sound.SoundHandler;
import mekanism.common.Mekanism;
import mekanism.common.OreDictCache;
import mekanism.common.inventory.container.ContainerFilter;
import mekanism.common.miner.MOreDictFilter;
import mekanism.common.network.PacketDigitalMinerGui.DigitalMinerGuiMessage;
@ -277,57 +278,7 @@ public class GuiMOreDictFilter extends GuiMekanism
private void updateStackList(String oreName)
{
if(iterStacks == null)
{
iterStacks = new ArrayList<ItemStack>();
}
else {
iterStacks.clear();
}
List<String> keys = new ArrayList<String>();
for(String s : OreDictionary.getOreNames())
{
if(oreName.equals(s) || oreName.equals("*"))
{
keys.add(s);
}
else if(oreName.endsWith("*") && !oreName.startsWith("*"))
{
if(s.startsWith(oreName.substring(0, oreName.length()-1)))
{
keys.add(s);
}
}
else if(oreName.startsWith("*") && !oreName.endsWith("*"))
{
if(s.endsWith(oreName.substring(1)))
{
keys.add(s);
}
}
else if(oreName.startsWith("*") && oreName.endsWith("*"))
{
if(s.contains(oreName.substring(1, oreName.length()-1)))
{
keys.add(s);
}
}
}
for(String key : keys)
{
for(ItemStack stack : OreDictionary.getOres(key))
{
ItemStack toAdd = stack.copy();
if(!iterStacks.contains(stack) && toAdd.getItem() instanceof ItemBlock)
{
iterStacks.add(stack.copy());
}
}
}
iterStacks = OreDictCache.getOreDictStacks(oreName, true);
stackSwitch = 0;
stackIndex = -1;

View file

@ -1,6 +1,5 @@
package mekanism.client.gui;
import java.util.ArrayList;
import java.util.List;
import mekanism.api.Coord4D;
@ -8,6 +7,7 @@ import mekanism.api.EnumColor;
import mekanism.client.render.MekanismRenderer;
import mekanism.client.sound.SoundHandler;
import mekanism.common.Mekanism;
import mekanism.common.OreDictCache;
import mekanism.common.inventory.container.ContainerFilter;
import mekanism.common.network.PacketEditFilter.EditFilterMessage;
import mekanism.common.network.PacketLogisticalSorterGui.LogisticalSorterGuiMessage;
@ -21,9 +21,7 @@ import mekanism.common.util.TransporterUtils;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11;
@ -328,51 +326,7 @@ public class GuiTModIDFilter extends GuiMekanism
private void updateStackList(String modName)
{
if(iterStacks == null)
{
iterStacks = new ArrayList<ItemStack>();
}
else {
iterStacks.clear();
}
for(String key : OreDictionary.getOreNames())
{
for(ItemStack stack : OreDictionary.getOres(key))
{
ItemStack toAdd = stack.copy();
String s = MekanismUtils.getMod(toAdd);
if(!iterStacks.contains(stack) && toAdd.getItem() instanceof ItemBlock)
{
if(modName.equals(s) || modName.equals("*"))
{
iterStacks.add(stack.copy());
}
else if(modName.endsWith("*") && !modName.startsWith("*"))
{
if(s.startsWith(modName.substring(0, modName.length()-1)))
{
iterStacks.add(stack.copy());
}
}
else if(modName.startsWith("*") && !modName.endsWith("*"))
{
if(s.endsWith(modName.substring(1)))
{
iterStacks.add(stack.copy());
}
}
else if(modName.startsWith("*") && modName.endsWith("*"))
{
if(s.contains(modName.substring(1, modName.length()-1)))
{
iterStacks.add(stack.copy());
}
}
}
}
}
iterStacks = OreDictCache.getModIDStacks(modName, false);
stackSwitch = 0;
stackIndex = -1;

View file

@ -1,6 +1,5 @@
package mekanism.client.gui;
import java.util.ArrayList;
import java.util.List;
import mekanism.api.Coord4D;
@ -8,6 +7,7 @@ import mekanism.api.EnumColor;
import mekanism.client.render.MekanismRenderer;
import mekanism.client.sound.SoundHandler;
import mekanism.common.Mekanism;
import mekanism.common.OreDictCache;
import mekanism.common.inventory.container.ContainerFilter;
import mekanism.common.network.PacketEditFilter.EditFilterMessage;
import mekanism.common.network.PacketLogisticalSorterGui.LogisticalSorterGuiMessage;
@ -22,7 +22,6 @@ import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11;
@ -327,57 +326,7 @@ public class GuiTOreDictFilter extends GuiMekanism
private void updateStackList(String oreName)
{
if(iterStacks == null)
{
iterStacks = new ArrayList<ItemStack>();
}
else {
iterStacks.clear();
}
List<String> keys = new ArrayList<String>();
for(String s : OreDictionary.getOreNames())
{
if(oreName.equals(s) || oreName.equals("*"))
{
keys.add(s);
}
else if(oreName.endsWith("*") && !oreName.startsWith("*"))
{
if(s.startsWith(oreName.substring(0, oreName.length()-1)))
{
keys.add(s);
}
}
else if(oreName.startsWith("*") && !oreName.endsWith("*"))
{
if(s.endsWith(oreName.substring(1)))
{
keys.add(s);
}
}
else if(oreName.startsWith("*") && oreName.endsWith("*"))
{
if(s.contains(oreName.substring(1, oreName.length()-1)))
{
keys.add(s);
}
}
}
for(String key : keys)
{
for(ItemStack stack : OreDictionary.getOres(key))
{
ItemStack toAdd = stack.copy();
if(!iterStacks.contains(stack))
{
iterStacks.add(stack.copy());
}
}
}
iterStacks = OreDictCache.getOreDictStacks(oreName, false);
stackSwitch = 0;
stackIndex = -1;

View file

@ -8,12 +8,15 @@ import java.util.Map;
import mekanism.api.ItemInfo;
import mekanism.common.util.MekanismUtils;
import mekanism.common.util.StackUtils;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
public class OreDictCache
public final class OreDictCache
{
public static HashMap<ItemInfo, List<String>> cachedKeys = new HashMap<ItemInfo, List<String>>();
public static HashMap<String, List<ItemStack>> oreDictStacks = new HashMap<String, List<ItemStack>>();
public static HashMap<String, List<ItemStack>> modIDStacks = new HashMap<String, List<ItemStack>>();
public static List<String> getOreDictName(ItemStack check)
{
@ -51,4 +54,114 @@ public class OreDictCache
return ret;
}
public static List<ItemStack> getOreDictStacks(String oreName, boolean forceBlock)
{
if(oreDictStacks.get(oreName) != null)
{
return oreDictStacks.get(oreName);
}
List<String> keys = new ArrayList<String>();
for(String s : OreDictionary.getOreNames())
{
if(oreName.equals(s) || oreName.equals("*"))
{
keys.add(s);
}
else if(oreName.endsWith("*") && !oreName.startsWith("*"))
{
if(s.startsWith(oreName.substring(0, oreName.length()-1)))
{
keys.add(s);
}
}
else if(oreName.startsWith("*") && !oreName.endsWith("*"))
{
if(s.endsWith(oreName.substring(1)))
{
keys.add(s);
}
}
else if(oreName.startsWith("*") && oreName.endsWith("*"))
{
if(s.contains(oreName.substring(1, oreName.length()-1)))
{
keys.add(s);
}
}
}
List<ItemStack> stacks = new ArrayList<ItemStack>();
for(String key : keys)
{
for(ItemStack stack : OreDictionary.getOres(key))
{
ItemStack toAdd = stack.copy();
if(!stacks.contains(stack) && (!forceBlock || toAdd.getItem() instanceof ItemBlock))
{
stacks.add(stack.copy());
}
}
}
oreDictStacks.put(oreName, stacks);
return stacks;
}
public static List<ItemStack> getModIDStacks(String modName, boolean forceBlock)
{
if(modIDStacks.get(modName) != null)
{
return modIDStacks.get(modName);
}
List<ItemStack> stacks = new ArrayList<ItemStack>();
for(String key : OreDictionary.getOreNames())
{
for(ItemStack stack : OreDictionary.getOres(key))
{
ItemStack toAdd = stack.copy();
String s = MekanismUtils.getMod(toAdd);
if(!stacks.contains(stack) && toAdd.getItem() instanceof ItemBlock)
{
if(modName.equals(s) || modName.equals("*"))
{
stacks.add(stack.copy());
}
else if(modName.endsWith("*") && !modName.startsWith("*"))
{
if(s.startsWith(modName.substring(0, modName.length()-1)))
{
stacks.add(stack.copy());
}
}
else if(modName.startsWith("*") && !modName.endsWith("*"))
{
if(s.endsWith(modName.substring(1)))
{
stacks.add(stack.copy());
}
}
else if(modName.startsWith("*") && modName.endsWith("*"))
{
if(s.contains(modName.substring(1, modName.length()-1)))
{
stacks.add(stack.copy());
}
}
}
}
}
modIDStacks.put(modName, stacks);
return stacks;
}
}