aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author‭huajijam <strhuaji@gmail.com>2019-04-30 22:59:13 +0800
committer‭huajijam <strhuaji@gmail.com>2019-04-30 22:59:13 +0800
commit63c33c98c3fca4d89adc4fa61fa5de5ae77a11eb (patch)
treea88c946551474aed5642c99ba857fc036af7e206
parentf203f18effabfbb52e269e3bdd889bd39f5b8509 (diff)
parentcbe6cb131f9d2a346adf9b89130fe348f74a7231 (diff)
downloadGT5-Unofficial-63c33c98c3fca4d89adc4fa61fa5de5ae77a11eb.tar.gz
GT5-Unofficial-63c33c98c3fca4d89adc4fa61fa5de5ae77a11eb.tar.bz2
GT5-Unofficial-63c33c98c3fca4d89adc4fa61fa5de5ae77a11eb.zip
Automatic synchronization
Former-commit-id: d1f9f1cb51a43c48243c4e805073f12ec958f6b2
-rw-r--r--src/main/java/com/github/bartimaeusnek/bartworks/MainMod.java68
-rw-r--r--src/main/java/com/github/bartimaeusnek/bartworks/client/ClientEventHandler/ClientEventHandler.java57
-rw-r--r--src/main/java/com/github/bartimaeusnek/bartworks/client/ClientEventHandler/TooltipCache.java67
-rw-r--r--src/main/java/com/github/bartimaeusnek/bartworks/common/net/BW_Network.java2
-rw-r--r--src/main/java/com/github/bartimaeusnek/bartworks/common/net/OreDictCachePacket.java76
-rw-r--r--src/main/java/com/github/bartimaeusnek/bartworks/server/EventHandler/ServerEventHandler.java41
-rw-r--r--src/main/java/com/github/bartimaeusnek/bartworks/system/oredict/OreDictHandler.java43
7 files changed, 289 insertions, 65 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..da330424ee 100644
--- a/src/main/java/com/github/bartimaeusnek/bartworks/MainMod.java
+++ b/src/main/java/com/github/bartimaeusnek/bartworks/MainMod.java
@@ -35,10 +35,12 @@ import com.github.bartimaeusnek.bartworks.common.loaders.BioLabLoader;
import com.github.bartimaeusnek.bartworks.common.loaders.GTNHBlocks;
import com.github.bartimaeusnek.bartworks.common.loaders.LoaderRegistry;
import com.github.bartimaeusnek.bartworks.common.net.BW_Network;
+import com.github.bartimaeusnek.bartworks.server.EventHandler.ServerEventHandler;
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;
@@ -49,8 +51,6 @@ import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerStartedEvent;
import cpw.mods.fml.common.network.IGuiHandler;
import cpw.mods.fml.common.network.NetworkRegistry;
-import cpw.mods.fml.common.registry.GameData;
-import cpw.mods.fml.common.registry.GameRegistry;
import gregtech.api.enums.ItemList;
import gregtech.api.enums.Materials;
import gregtech.api.enums.SubTag;
@@ -59,7 +59,6 @@ import gregtech.api.util.GT_Recipe;
import gregtech.api.util.GT_Utility;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
-import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.MinecraftForge;
import org.apache.logging.log4j.LogManager;
@@ -67,7 +66,6 @@ import org.apache.logging.log4j.Logger;
import java.io.IOException;
import java.util.HashSet;
-import java.util.Iterator;
import static com.github.bartimaeusnek.bartworks.common.tileentities.multis.GT_TileEntity_ElectricImplosionCompressor.eicMap;
@@ -132,6 +130,8 @@ public final class MainMod {
public void init(FMLInitializationEvent init) {
if (FMLCommonHandler.instance().getSide().isClient() && ConfigHandler.BioLab)
MinecraftForge.EVENT_BUS.register(new ClientEventHandler());
+ if (FMLCommonHandler.instance().getSide().isServer())
+ MinecraftForge.EVENT_BUS.register(new ServerEventHandler());
new LoaderRegistry().run();
if (ConfigHandler.BioLab)
new BioLabLoader().run();
@@ -157,37 +157,39 @@ public final class MainMod {
WerkstoffLoader.INSTANCE.run();
}
}
-
@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 d2277817c5..f4c155d246 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,9 +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;
@@ -51,38 +53,41 @@ import java.util.List;
@SideOnly(Side.CLIENT)
public class ClientEventHandler {
- HashMap<ItemStack, List<String>> cache = new HashMap<>();
-
@SideOnly(Side.CLIENT)
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void getTooltip(ItemTooltipEvent event) {
- if (event.itemStack == null || event.itemStack.getItem() == null || Block.getBlockFromItem(event.itemStack.getItem()) == null)
+
+ 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<>();
-
- for (ItemStack stack : OreDictHandler.getCache().values()) {
- if (GT_Utility.areStacksEqual(event.itemStack, stack)) {
- GameRegistry.UniqueIdentifier UI = GameRegistry.findUniqueIdentifierFor(stack.getItem());
- if (UI == null)
- UI = GameRegistry.findUniqueIdentifierFor(Block.getBlockFromItem(stack.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"))
- break;
- if (UI.modId.equals(modContainer.getModId())) {
- tooAdd.add("Shared ItemStack between " + ChatColorHelper.DARKGREEN + "BartWorks" + ChatColorHelper.GRAY + " and " + ChatColorHelper.RED + modContainer.getName());
+ if (OreDictHandler.getNonBWCache().contains(abstractedStack)) {
+ for (Pair<Integer,Short> pair : OreDictHandler.getNonBWCache()) {
+ if (pair.equals(abstractedStack)) {
+ GameRegistry.UniqueIdentifier UI = GameRegistry.findUniqueIdentifierFor(tmp.getItem());
+ if (UI == null)
+ 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"))
+ break;
+ if (UI.modId.equals(modContainer.getModId())) {
+ tooAdd.add("Shared ItemStack between " + ChatColorHelper.DARKGREEN + "BartWorks" + ChatColorHelper.GRAY + " and " + ChatColorHelper.RED + modContainer.getName());
+ }
}
- }
- } else
- tooAdd.add("Shared ItemStack between " + ChatColorHelper.DARKGREEN + "BartWorks" + ChatColorHelper.GRAY + " and another Mod, that doesn't use the ModContainer propperly!");
+ } else
+ tooAdd.add("Shared ItemStack between " + ChatColorHelper.DARKGREEN + "BartWorks" + ChatColorHelper.GRAY + " and another Mod, that doesn't use the ModContainer propperly!");
+ }
}
}
- final Block BLOCK = Block.getBlockFromItem(event.itemStack.getItem());
+ 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());
@@ -98,10 +103,12 @@ public class ClientEventHandler {
" "
+ BW_ColorUtil.getColorForTier(3) + GT_Values.VN[3] + ChatColorHelper.RESET);
}
- cache.put(event.itemStack, tooAdd);
- event.toolTip.addAll(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/common/net/BW_Network.java b/src/main/java/com/github/bartimaeusnek/bartworks/common/net/BW_Network.java
index cca0c39712..277823b5f4 100644
--- a/src/main/java/com/github/bartimaeusnek/bartworks/common/net/BW_Network.java
+++ b/src/main/java/com/github/bartimaeusnek/bartworks/common/net/BW_Network.java
@@ -59,7 +59,7 @@ public class BW_Network extends MessageToMessageCodec<FMLProxyPacket, GT_Packet>
public BW_Network() {
this.mChannel = NetworkRegistry.INSTANCE.newChannel("BartWorks", new ChannelHandler[]{this, new HandlerShared()});
- this.mSubChannels = new GT_Packet[]{new RendererPacket(), new CircuitProgrammerPacket(), new OrePacket()};
+ this.mSubChannels = new GT_Packet[]{new RendererPacket(), new CircuitProgrammerPacket(), new OrePacket(), new OreDictCachePacket()};
}
protected void encode(ChannelHandlerContext aContext, GT_Packet aPacket, List<Object> aOutput) throws Exception {
diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/common/net/OreDictCachePacket.java b/src/main/java/com/github/bartimaeusnek/bartworks/common/net/OreDictCachePacket.java
new file mode 100644
index 0000000000..d44fc42cce
--- /dev/null
+++ b/src/main/java/com/github/bartimaeusnek/bartworks/common/net/OreDictCachePacket.java
@@ -0,0 +1,76 @@
+/*
+ * 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.common.net;
+
+import com.github.bartimaeusnek.bartworks.system.oredict.OreDictHandler;
+import com.github.bartimaeusnek.bartworks.util.Pair;
+import com.google.common.io.ByteArrayDataInput;
+import gregtech.api.net.GT_Packet;
+import net.minecraft.world.IBlockAccess;
+
+import java.nio.ByteBuffer;
+import java.util.HashSet;
+
+public class OreDictCachePacket extends GT_Packet {
+
+
+ private HashSet<Pair<Integer,Short>> hashSet = new HashSet<>();
+
+ public OreDictCachePacket() {
+ super(true);
+ }
+
+ public OreDictCachePacket(HashSet<Pair<Integer,Short>> set) {
+ super(false);
+ hashSet = set;
+ }
+
+ @Override
+ public byte getPacketID() {
+ return 3;
+ }
+
+ @Override
+ public byte[] encode() {
+ int size = this.hashSet.size();
+ ByteBuffer buff = ByteBuffer.allocate(4+size*4+size*2).putInt(size);
+ for(Pair<Integer,Short> p : this.hashSet)
+ buff.putInt(p.getKey()).putShort(p.getValue());
+ return buff.array();
+ }
+
+ @Override
+ public GT_Packet decode(ByteArrayDataInput byteArrayDataInput) {
+ int size = byteArrayDataInput.readInt();
+ for (int i = 0; i < size; i++) {
+ this.hashSet.add(new Pair<Integer,Short>(byteArrayDataInput.readInt(),byteArrayDataInput.readShort()));
+ }
+ return new OreDictCachePacket(this.hashSet);
+ }
+
+ @Override
+ public void process(IBlockAccess iBlockAccess) {
+ OreDictHandler.getNonBWCache().clear();
+ OreDictHandler.getNonBWCache().addAll(this.hashSet);
+ }
+} \ No newline at end of file
diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/server/EventHandler/ServerEventHandler.java b/src/main/java/com/github/bartimaeusnek/bartworks/server/EventHandler/ServerEventHandler.java
new file mode 100644
index 0000000000..9fc72b31cd
--- /dev/null
+++ b/src/main/java/com/github/bartimaeusnek/bartworks/server/EventHandler/ServerEventHandler.java
@@ -0,0 +1,41 @@
+/*
+ * 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.server.EventHandler;
+
+import com.github.bartimaeusnek.bartworks.MainMod;
+import com.github.bartimaeusnek.bartworks.common.net.OreDictCachePacket;
+import com.github.bartimaeusnek.bartworks.system.oredict.OreDictHandler;
+import cpw.mods.fml.common.FMLCommonHandler;
+import cpw.mods.fml.common.eventhandler.EventPriority;
+import cpw.mods.fml.common.eventhandler.SubscribeEvent;
+import net.minecraft.entity.player.EntityPlayerMP;
+import net.minecraftforge.event.entity.EntityJoinWorldEvent;
+
+public class ServerEventHandler {
+ @SubscribeEvent(priority = EventPriority.LOWEST)
+ public void getTooltip(EntityJoinWorldEvent event) {
+ if (event == null || !(event.entity instanceof EntityPlayerMP) || !FMLCommonHandler.instance().getSide().isServer())
+ return;
+ MainMod.BW_Network_instance.sendToPlayer(new OreDictCachePacket(OreDictHandler.getNonBWCache()), (EntityPlayerMP) event.entity);
+ }
+}
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..fb13cc7c85 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,60 @@
package com.github.bartimaeusnek.bartworks.system.oredict;
+import com.github.bartimaeusnek.bartworks.MainMod;
+import com.github.bartimaeusnek.bartworks.util.Pair;
+import com.github.bartimaeusnek.crossmod.BartWorksCrossmod;
+import cpw.mods.fml.common.registry.GameRegistry;
import gregtech.api.enums.OrePrefixes;
+import net.minecraft.block.Block;
+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<>();
+ private static final HashSet<Pair<Integer,Short>> cacheNonBW = new HashSet<>();
- public static HashMap<String, ItemStack> getCache() {
+ public static HashMap<String, Pair<Integer,Short>> getCache() {
return OreDictHandler.cache;
}
+ public static HashSet<Pair<Integer,Short>> getNonBWCache(){
+ return OreDictHandler.cacheNonBW;
+ }
+
+ public static void adaptCacheForWorld(){
+ Set<String> used = new HashSet<>(cache.keySet());
+ OreDictHandler.cache.clear();
+ OreDictHandler.cacheNonBW.clear();
+ for (String s : used) {
+ if (!OreDictionary.getOres(s).isEmpty()) {
+ ItemStack tmp = OreDictionary.getOres(s).get(0).copy();
+ Pair<Integer,Short> p = new Pair<>(Item.getIdFromItem(tmp.getItem()), (short) tmp.getItemDamage());
+ cache.put(s, p);
+ GameRegistry.UniqueIdentifier UI = GameRegistry.findUniqueIdentifierFor(tmp.getItem());
+ if (UI == null)
+ UI = GameRegistry.findUniqueIdentifierFor(Block.getBlockFromItem(tmp.getItem()));
+ if (!UI.modId.equals(MainMod.MOD_ID) && !UI.modId.equals(BartWorksCrossmod.MOD_ID) && !UI.modId.equals("BWCore")){
+ OreDictHandler.cacheNonBW.add(p);
+ }
+ }
+ }
+ }
+
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;