aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbartimaeusnek <33183715+bartimaeusnek@users.noreply.github.com>2019-04-28 06:34:48 +0200
committerbartimaeusnek <33183715+bartimaeusnek@users.noreply.github.com>2019-04-28 06:34:48 +0200
commit7f895c5e164e8b73d953756a3c02b2aea2d405b6 (patch)
treeaf093fa43ac7007ea77d6f966b974d0d37bffb7a
parentaaa4c29f55ec261fb784941ca17435ba06e58467 (diff)
downloadGT5-Unofficial-7f895c5e164e8b73d953756a3c02b2aea2d405b6.tar.gz
GT5-Unofficial-7f895c5e164e8b73d953756a3c02b2aea2d405b6.tar.bz2
GT5-Unofficial-7f895c5e164e8b73d953756a3c02b2aea2d405b6.zip
re-enabled the tooltip handler
Signed-off-by: bartimaeusnek <33183715+bartimaeusnek@users.noreply.github.com> Former-commit-id: 949b0d20ef0323d6308beac55e46a933b32bcf79
-rw-r--r--src/main/java/com/github/bartimaeusnek/bartworks/MainMod.java60
-rw-r--r--src/main/java/com/github/bartimaeusnek/bartworks/client/ClientEventHandler/ClientEventHandler.java29
-rw-r--r--src/main/java/com/github/bartimaeusnek/bartworks/client/ClientEventHandler/TooltipCache.java67
-rw-r--r--src/main/java/com/github/bartimaeusnek/bartworks/system/oredict/OreDictHandler.java26
4 files changed, 133 insertions, 49 deletions
diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/MainMod.java b/src/main/java/com/github/bartimaeusnek/bartworks/MainMod.java
index e5ee488b2f..43b76254d2 100644
--- a/src/main/java/com/github/bartimaeusnek/bartworks/MainMod.java
+++ b/src/main/java/com/github/bartimaeusnek/bartworks/MainMod.java
@@ -39,6 +39,7 @@ import com.github.bartimaeusnek.bartworks.system.log.DebugLog;
import com.github.bartimaeusnek.bartworks.system.material.ThreadedLoader;
import com.github.bartimaeusnek.bartworks.system.material.Werkstoff;
import com.github.bartimaeusnek.bartworks.system.material.WerkstoffLoader;
+import com.github.bartimaeusnek.bartworks.system.oredict.OreDictHandler;
import com.github.bartimaeusnek.bartworks.util.BW_Util;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Loader;
@@ -160,34 +161,37 @@ public final class MainMod {
@Mod.EventHandler
public void onServerStarted(FMLServerStartedEvent event) {
- eicMap = new GT_Recipe.GT_Recipe_Map(new HashSet(GT_Recipe.GT_Recipe_Map.sImplosionRecipes.mRecipeList.size()), "gt.recipe.electricimplosioncompressor", "Electric Implosion Compressor", (String) null, "gregtech:textures/gui/basicmachines/Default", 1, 2, 1, 0, 1, "", 1, "", true, true);
- recipeLoop:
- for (GT_Recipe recipe : GT_Recipe.GT_Recipe_Map.sImplosionRecipes.mRecipeList) {
- if (recipe == null || recipe.mInputs == null)
- continue;
- try {
- ItemStack input = recipe.mInputs[0];
- int i = 0;
- float durMod = 0;
- if (checkForExplosives(recipe.mInputs[1])) {
- if (GT_Utility.areStacksEqual(recipe.mInputs[1], GT_ModHandler.getIC2Item("industrialTnt", 1L)))
- durMod += ((float) input.stackSize * 2f);
- else
- continue recipeLoop;
- }
- while (checkForExplosives(input)) {
- if (GT_Utility.areStacksEqual(input, GT_ModHandler.getIC2Item("industrialTnt", 1L)))
- durMod += ((float) input.stackSize * 2f);
- else
- continue recipeLoop;
- i++;
- input = recipe.mInputs[i];
- }
-
- eicMap.addRecipe(true, new ItemStack[]{input}, recipe.mOutputs, null, null, null, (int)Math.floor(Math.max((float)recipe.mDuration*durMod,20f)), BW_Util.getMachineVoltageFromTier(10), 0);
- } catch (ArrayIndexOutOfBoundsException e) {
- LOGGER.error("CAUGHT DEFECTIVE IMPLOSION COMPRESSOR RECIPE!");
- e.printStackTrace();
+ OreDictHandler.adaptCacheForWorld();
+ if (eicMap == null) {
+ eicMap = new GT_Recipe.GT_Recipe_Map(new HashSet(GT_Recipe.GT_Recipe_Map.sImplosionRecipes.mRecipeList.size()), "gt.recipe.electricimplosioncompressor", "Electric Implosion Compressor", (String) null, "gregtech:textures/gui/basicmachines/Default", 1, 2, 1, 0, 1, "", 1, "", true, true);
+ recipeLoop:
+ for (GT_Recipe recipe : GT_Recipe.GT_Recipe_Map.sImplosionRecipes.mRecipeList) {
+ if (recipe == null || recipe.mInputs == null)
+ continue;
+ try {
+ ItemStack input = recipe.mInputs[0];
+ int i = 0;
+ float durMod = 0;
+ if (this.checkForExplosives(recipe.mInputs[1])) {
+ if (GT_Utility.areStacksEqual(recipe.mInputs[1], GT_ModHandler.getIC2Item("industrialTnt", 1L)))
+ durMod += ((float) input.stackSize * 2f);
+ else
+ continue;
+ }
+ while (this.checkForExplosives(input)) {
+ if (GT_Utility.areStacksEqual(input, GT_ModHandler.getIC2Item("industrialTnt", 1L)))
+ durMod += ((float) input.stackSize * 2f);
+ else
+ continue recipeLoop;
+ i++;
+ input = recipe.mInputs[i];
+ }
+
+ eicMap.addRecipe(true, new ItemStack[]{input}, recipe.mOutputs, null, null, null, (int) Math.floor(Math.max((float) recipe.mDuration * durMod, 20f)), BW_Util.getMachineVoltageFromTier(10), 0);
+ } catch (ArrayIndexOutOfBoundsException e) {
+ MainMod.LOGGER.error("CAUGHT DEFECTIVE IMPLOSION COMPRESSOR RECIPE!");
+ e.printStackTrace();
+ }
}
}
}
diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/client/ClientEventHandler/ClientEventHandler.java b/src/main/java/com/github/bartimaeusnek/bartworks/client/ClientEventHandler/ClientEventHandler.java
index 2d37b61242..861b456fd9 100644
--- a/src/main/java/com/github/bartimaeusnek/bartworks/client/ClientEventHandler/ClientEventHandler.java
+++ b/src/main/java/com/github/bartimaeusnek/bartworks/client/ClientEventHandler/ClientEventHandler.java
@@ -28,6 +28,7 @@ import com.github.bartimaeusnek.bartworks.common.blocks.BW_Blocks;
import com.github.bartimaeusnek.bartworks.system.oredict.OreDictHandler;
import com.github.bartimaeusnek.bartworks.util.BW_ColorUtil;
import com.github.bartimaeusnek.bartworks.util.ChatColorHelper;
+import com.github.bartimaeusnek.bartworks.util.Pair;
import com.github.bartimaeusnek.crossmod.BartWorksCrossmod;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.ModContainer;
@@ -37,10 +38,10 @@ import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import gregtech.api.enums.GT_Values;
-import gregtech.api.util.GT_Utility;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.init.Blocks;
+import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.StatCollector;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
@@ -52,25 +53,23 @@ import java.util.List;
@SideOnly(Side.CLIENT)
public class ClientEventHandler {
- private static final HashMap<ItemStack, List<String>> CACHE = new HashMap<>();
-
@SideOnly(Side.CLIENT)
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void getTooltip(ItemTooltipEvent event) {
- if (CACHE.size() > 500)
- CACHE.clear();
- if (event.itemStack == null || event.itemStack.getItem() == null || !(OreDictHandler.getCache().containsValue(event.itemStack) || Block.getBlockFromItem(event.itemStack.getItem()) != Blocks.air))
+ if (event.itemStack == null || event.itemStack.getItem() == null)
return;
- if (!CACHE.containsKey(event.itemStack)) {
+ if (TooltipCache.getTooltip(event.itemStack).isEmpty()) {
+ ItemStack tmp = event.itemStack.copy();
+ Pair<Integer,Short> abstractedStack = new Pair<>(Item.getIdFromItem(tmp.getItem()), (short) tmp.getItemDamage());
List<String> tooAdd = new ArrayList<>();
- if (OreDictHandler.getCache().containsValue(event.itemStack) ) {
- for (ItemStack stack : OreDictHandler.getCache().values()) {
- if (GT_Utility.areStacksEqual(event.itemStack, stack)) {
- GameRegistry.UniqueIdentifier UI = GameRegistry.findUniqueIdentifierFor(stack.getItem());
+ if (OreDictHandler.getCache().containsValue(abstractedStack)) {
+ for (Pair<Integer,Short> pair : OreDictHandler.getCache().values()) {
+ if (pair.equals(abstractedStack)) {
+ GameRegistry.UniqueIdentifier UI = GameRegistry.findUniqueIdentifierFor(tmp.getItem());
if (UI == null)
- UI = GameRegistry.findUniqueIdentifierFor(Block.getBlockFromItem(stack.getItem()));
+ UI = GameRegistry.findUniqueIdentifierFor(Block.getBlockFromItem(tmp.getItem()));
if (UI != null) {
for (ModContainer modContainer : Loader.instance().getModList()) {
if (UI.modId.equals(MainMod.MOD_ID) || UI.modId.equals(BartWorksCrossmod.MOD_ID) || UI.modId.equals("BWCore"))
@@ -88,7 +87,7 @@ public class ClientEventHandler {
final Block BLOCK = Block.getBlockFromItem(event.itemStack.getItem());
if (BLOCK != null && BLOCK != Blocks.air) {
if (BLOCK instanceof BW_Blocks) {
- CACHE.put(event.itemStack, tooAdd);
+ TooltipCache.put(event.itemStack, tooAdd);
return;
}
final BioVatLogicAdder.BlockMetaPair PAIR = new BioVatLogicAdder.BlockMetaPair(BLOCK, (byte) event.itemStack.getItemDamage());
@@ -106,10 +105,10 @@ public class ClientEventHandler {
}
}
- CACHE.put(event.itemStack, tooAdd);
+ TooltipCache.put(event.itemStack, tooAdd);
event.toolTip.addAll(tooAdd);
} else {
- event.toolTip.addAll(CACHE.get(event.itemStack));
+ event.toolTip.addAll(TooltipCache.getTooltip(event.itemStack));
}
}
} \ No newline at end of file
diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/client/ClientEventHandler/TooltipCache.java b/src/main/java/com/github/bartimaeusnek/bartworks/client/ClientEventHandler/TooltipCache.java
new file mode 100644
index 0000000000..5702c32252
--- /dev/null
+++ b/src/main/java/com/github/bartimaeusnek/bartworks/client/ClientEventHandler/TooltipCache.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2019 bartimaeusnek
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package com.github.bartimaeusnek.bartworks.client.ClientEventHandler;
+
+import com.github.bartimaeusnek.bartworks.util.Pair;
+import net.minecraft.item.Item;
+import net.minecraft.item.ItemStack;
+
+import java.util.*;
+
+class TooltipCache {
+ private static final HashMap<Pair<Integer, Short>, char[]> cache = new HashMap<>();
+
+ static boolean put(ItemStack itemStack, List<String> tooltip){
+ Pair<Integer, Short> p = new Pair<>(Item.getIdFromItem(itemStack.getItem()), (short) itemStack.getItemDamage());
+ if (TooltipCache.cache.containsKey(p))
+ return false;
+
+ if (!tooltip.isEmpty()) {
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < tooltip.size(); i++) {
+ sb.append(tooltip.get(i));
+ sb.append(System.lineSeparator());
+ }
+ char[] rettype = sb.toString().toCharArray();
+ return TooltipCache.cache.put(p,rettype) == rettype;
+ } else {
+ return false;
+ }
+ }
+
+ static List<String> getTooltip(ItemStack itemStack) {
+ Pair<Integer, Short> p = new Pair<>(Item.getIdFromItem(itemStack.getItem()), (short) itemStack.getItemDamage());
+ char[] toTest= TooltipCache.cache.get(p);
+ if (toTest == null){
+ return new ArrayList<>();
+ }
+ return Arrays.asList(new String(toTest).split(System.lineSeparator()));
+ }
+
+ private static void checkSize(){
+ if (TooltipCache.cache.size()> Short.MAX_VALUE*2 ){
+ TooltipCache.cache.clear();
+ }
+ }
+
+}
diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/system/oredict/OreDictHandler.java b/src/main/java/com/github/bartimaeusnek/bartworks/system/oredict/OreDictHandler.java
index e86d55acce..d70bf884d2 100644
--- a/src/main/java/com/github/bartimaeusnek/bartworks/system/oredict/OreDictHandler.java
+++ b/src/main/java/com/github/bartimaeusnek/bartworks/system/oredict/OreDictHandler.java
@@ -22,29 +22,43 @@
package com.github.bartimaeusnek.bartworks.system.oredict;
+import com.github.bartimaeusnek.bartworks.util.Pair;
import gregtech.api.enums.OrePrefixes;
+import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Set;
public class OreDictHandler {
- private static final HashMap<String,ItemStack> cache = new HashMap<>();
+ private static final HashMap<String, Pair<Integer,Short>> cache = new HashMap<>();
- public static HashMap<String, ItemStack> getCache() {
+ public static HashMap<String, Pair<Integer,Short>> getCache() {
return OreDictHandler.cache;
}
+ public static void adaptCacheForWorld(){
+ Set<String> used = new HashSet<>(cache.keySet());
+ OreDictHandler.cache.clear();
+ for (String s : used) {
+ if (!OreDictionary.getOres(s).isEmpty()) {
+ ItemStack tmp = OreDictionary.getOres(s).get(0).copy();
+ cache.put(s, new Pair<>(Item.getIdFromItem(tmp.getItem()), (short) tmp.getItemDamage()));
+ }
+ }
+ }
+
public static ItemStack getItemStack(String elementName, OrePrefixes prefixes, int amount){
if (cache.get(prefixes+elementName.replaceAll(" ","")) != null){
- ItemStack tmp = cache.get(prefixes+elementName.replaceAll(" ","")).copy();
- tmp.stackSize=amount;
- return tmp;
+ Pair<Integer,Short> p = cache.get(prefixes+elementName.replaceAll(" ",""));
+ return new ItemStack(Item.getItemById(p.getKey()),amount,p.getValue());
} else if (!OreDictionary.getOres(prefixes+elementName.replaceAll(" ","")).isEmpty()){
ItemStack tmp = OreDictionary.getOres(prefixes+elementName.replaceAll(" ","")).get(0).copy();
+ cache.put(prefixes+elementName.replaceAll(" ",""),new Pair<>(Item.getIdFromItem(tmp.getItem()), (short) tmp.getItemDamage()));
tmp.stackSize=amount;
- cache.put(prefixes+elementName.replaceAll(" ",""),tmp);
return tmp;
}
return null;