Add a constructor that sets an elementName for ElementSlider, and set up a cached copy of the OreDictionary (since we should be doing that rather than constantly rebuilding it with queries all the time)

This commit is contained in:
pahimar 2015-04-05 22:07:31 -04:00
parent 5dd7f5a835
commit ad83088933
5 changed files with 122 additions and 3 deletions

View file

@ -2,6 +2,7 @@ package com.pahimar.ee3;
import com.pahimar.ee3.array.AlchemyArrayRegistry;
import com.pahimar.ee3.command.CommandEE;
import com.pahimar.ee3.exchange.CachedOreDictionary;
import com.pahimar.ee3.exchange.EnergyValueRegistry;
import com.pahimar.ee3.handler.*;
import com.pahimar.ee3.init.*;
@ -110,6 +111,7 @@ public class EquivalentExchange3
@EventHandler
public void postInit(FMLPostInitializationEvent event)
{
CachedOreDictionary.getInstance();
RecipeRegistry.getInstance().registerVanillaRecipes();
AludelRecipeManager.registerRecipes();
}

View file

@ -88,7 +88,7 @@ public class GuiTransmutationTablet extends GuiBase
};
setTooltipByState();
slider = new ElementSlider(this, 239, 36, 12, 201, 187, 0)
slider = new ElementSlider(this, "scrollBar", 239, 36, 12, 201, 187, 0)
{
@Override
protected void dragSlider(int x, int y)
@ -123,7 +123,6 @@ public class GuiTransmutationTablet extends GuiBase
return _value;
}
};
slider.setName("scrollBar");
slider.backgroundColor = new GuiColor(0, 0, 0, 0).getColor();
slider.borderColor = new GuiColor(0, 0, 0, 0).getColor();
slider.setSliderSize(12, 15);
@ -137,7 +136,7 @@ public class GuiTransmutationTablet extends GuiBase
protected void drawGuiContainerForegroundLayer(int x, int y)
{
super.drawGuiContainerForegroundLayer(x, y);
fontRendererObj.drawString(String.format("%s:", StatCollector.translateToLocal(Messages.ENERGY_VALUE)), 8, 140, Integer.parseInt(Colors.PURE_WHITE, 16)); // TODO Localize
fontRendererObj.drawString(String.format("%s:", StatCollector.translateToLocal(Messages.ENERGY_VALUE)), 8, 140, Integer.parseInt(Colors.PURE_WHITE, 16));
fontRendererObj.drawString(String.format("%s", energyValueDecimalFormat.format(tileEntityTransmutationTablet.getStoredEnergyValue().getEnergyValue())), 8, 150, Integer.parseInt(Colors.PURE_WHITE, 16));
}

View file

@ -0,0 +1,79 @@
package com.pahimar.ee3.exchange;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Multimap;
import com.google.common.collect.TreeMultimap;
import com.pahimar.ee3.reference.Comparators;
import com.pahimar.ee3.util.ItemHelper;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import java.util.*;
public class CachedOreDictionary
{
private static CachedOreDictionary cachedOreDictionary = null;
private ImmutableMap<String, List<ItemStack>> oreNameToItemStackMap;
private ImmutableMultimap<ItemStack, String> itemStackToOreNameMap;
private CachedOreDictionary()
{
Map<String, List<ItemStack>> nameToStackMap = new TreeMap<String, List<ItemStack>>(Comparators.stringComparator);
Multimap<ItemStack, String> stackToNameMultiMap = TreeMultimap.create(ItemHelper.idComparator, Comparators.stringComparator);
for (String oreName : OreDictionary.getOreNames())
{
List<ItemStack> oreNameItemStacks = OreDictionary.getOres(oreName);
nameToStackMap.put(oreName, oreNameItemStacks);
for (ItemStack itemStack : oreNameItemStacks)
{
stackToNameMultiMap.put(itemStack, oreName);
}
}
oreNameToItemStackMap = ImmutableMap.copyOf(nameToStackMap);
itemStackToOreNameMap = ImmutableMultimap.copyOf(stackToNameMultiMap);
}
public static CachedOreDictionary getInstance()
{
if (cachedOreDictionary == null)
{
cachedOreDictionary = new CachedOreDictionary();
}
return cachedOreDictionary;
}
public Set<String> getOreNames()
{
return oreNameToItemStackMap.keySet();
}
public List<ItemStack> getItemStacksForOreName(String oreName)
{
if (oreNameToItemStackMap.containsKey(oreName))
{
return oreNameToItemStackMap.get(oreName);
}
return new ArrayList<ItemStack>();
}
public List<String> getOreNamesForItemStack(ItemStack itemStack)
{
List<String> oreNameList = new ArrayList<String>();
if (itemStackToOreNameMap.containsKey(itemStack))
{
for (String oreName : itemStackToOreNameMap.get(itemStack))
{
oreNameList.add(oreName);
}
}
return oreNameList;
}
}

View file

@ -7,4 +7,13 @@ import java.util.Comparator;
public class Comparators
{
public static final Comparator[] itemComparators = {ItemHelper.displayNameComparator, ItemHelper.energyValueComparator, ItemHelper.idComparator};
public static Comparator<String> stringComparator = new Comparator<String>()
{
@Override
public int compare(String string1, String string2)
{
return string1.compareToIgnoreCase(string2);
}
};
}

View file

@ -35,6 +35,14 @@ public abstract class ElementSlider extends ElementBase
_valueMin = minValue;
}
protected ElementSlider(GuiBase containerScreen, String elementName, int x, int y, int width, int height, int maxValue, int minValue)
{
super(containerScreen, x, y, width, height);
this.name = elementName;
_valueMax = maxValue;
_valueMin = minValue;
}
public ElementSlider setColor(int backgroundColor, int borderColor)
{
this.borderColor = borderColor;
@ -54,6 +62,16 @@ public abstract class ElementSlider extends ElementBase
return this._value;
}
public int getValueMin()
{
return this._valueMin;
}
public int getValueMax()
{
return this._valueMax;
}
public ElementSlider setValue(int value)
{
value = Math.max(_valueMin, Math.min(_valueMax, value));
@ -65,6 +83,18 @@ public abstract class ElementSlider extends ElementBase
return this;
}
public ElementSlider setMinValue(int minValue)
{
_valueMin = minValue;
return this;
}
public ElementSlider setMaxValue(int maxValue)
{
_valueMax = maxValue;
return this;
}
@Override
public void drawBackground(int mouseX, int mouseY, float gameTicks)
{