From aaa4c29f55ec261fb784941ca17435ba06e58467 Mon Sep 17 00:00:00 2001 From: bartimaeusnek <33183715+bartimaeusnek@users.noreply.github.com> Date: Sun, 28 Apr 2019 02:22:39 +0200 Subject: reworked clienteventhandler Signed-off-by: bartimaeusnek <33183715+bartimaeusnek@users.noreply.github.com> Former-commit-id: be5ebbabc9ed6e24d8394f4f38242c431b9f694e --- .../ClientEventHandler/ClientEventHandler.java | 54 +++++++++++++--------- 1 file changed, 31 insertions(+), 23 deletions(-) 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..2d37b61242 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 @@ -40,6 +40,7 @@ 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.ItemStack; import net.minecraft.util.StatCollector; import net.minecraftforge.event.entity.player.ItemTooltipEvent; @@ -51,38 +52,43 @@ import java.util.List; @SideOnly(Side.CLIENT) public class ClientEventHandler { - HashMap> cache = new HashMap<>(); + private static final HashMap> 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 (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)) return; - if (!cache.containsKey(event.itemStack)) { + if (!CACHE.containsKey(event.itemStack)) { List 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.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 (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()); + } } - } - } 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); + CACHE.put(event.itemStack, tooAdd); return; } final BioVatLogicAdder.BlockMetaPair PAIR = new BioVatLogicAdder.BlockMetaPair(BLOCK, (byte) event.itemStack.getItemDamage()); @@ -98,10 +104,12 @@ public class ClientEventHandler { " " + BW_ColorUtil.getColorForTier(3) + GT_Values.VN[3] + ChatColorHelper.RESET); } - cache.put(event.itemStack, tooAdd); - event.toolTip.addAll(tooAdd); + } + + CACHE.put(event.itemStack, tooAdd); + event.toolTip.addAll(tooAdd); } else { - event.toolTip.addAll(cache.get(event.itemStack)); + event.toolTip.addAll(CACHE.get(event.itemStack)); } } } \ No newline at end of file -- cgit From 7f895c5e164e8b73d953756a3c02b2aea2d405b6 Mon Sep 17 00:00:00 2001 From: bartimaeusnek <33183715+bartimaeusnek@users.noreply.github.com> Date: Sun, 28 Apr 2019 06:34:48 +0200 Subject: re-enabled the tooltip handler Signed-off-by: bartimaeusnek <33183715+bartimaeusnek@users.noreply.github.com> Former-commit-id: 949b0d20ef0323d6308beac55e46a933b32bcf79 --- .../github/bartimaeusnek/bartworks/MainMod.java | 60 ++++++++++--------- .../ClientEventHandler/ClientEventHandler.java | 29 +++++----- .../client/ClientEventHandler/TooltipCache.java | 67 ++++++++++++++++++++++ .../bartworks/system/oredict/OreDictHandler.java | 26 +++++++-- 4 files changed, 133 insertions(+), 49 deletions(-) create mode 100644 src/main/java/com/github/bartimaeusnek/bartworks/client/ClientEventHandler/TooltipCache.java 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> 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 abstractedStack = new Pair<>(Item.getIdFromItem(tmp.getItem()), (short) tmp.getItemDamage()); List 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 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, char[]> cache = new HashMap<>(); + + static boolean put(ItemStack itemStack, List tooltip){ + Pair 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 getTooltip(ItemStack itemStack) { + Pair 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 cache = new HashMap<>(); + private static final HashMap> cache = new HashMap<>(); - public static HashMap getCache() { + public static HashMap> getCache() { return OreDictHandler.cache; } + public static void adaptCacheForWorld(){ + Set 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 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; -- cgit From 3a88412bab88b2338ad76ebb78d8b1ea35b5eeea Mon Sep 17 00:00:00 2001 From: huajijam Date: Sun, 28 Apr 2019 12:35:43 +0800 Subject: update chinses translation and fix more bugssssss (#29) * fix a simple bug that i have never mind * update translation Former-commit-id: fc0087dc6a6794d611782199d6e5c50f3d1ffdeb --- src/main/resources/assets/bartworks/lang/zh_CN.lang | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/resources/assets/bartworks/lang/zh_CN.lang b/src/main/resources/assets/bartworks/lang/zh_CN.lang index bd6200e2bb..29b66c2ebd 100644 --- a/src/main/resources/assets/bartworks/lang/zh_CN.lang +++ b/src/main/resources/assets/bartworks/lang/zh_CN.lang @@ -144,7 +144,7 @@ tile.radiohatch.name=放射仓 tile.bw.windmill.name=风车 tile.manutrafo.name=手动变压器 -tooltip.tile.htr.0.name=高温钍反应堆的控制器方块;大小(宽x高x长): 9x12x9 (中空);角落和两个相邻的方块是空气;一旦搭建,需要在输入仓中输入氦气,直到它不再接受;1+输出仓(任意底部机械方块);1+输入仓(任意顶部机械方块);1+输入总线(任意顶部机械方块);1x维护仓(任意机械方块);其余的为辐射防护机械方块;需要持续供应冷却液或将关机;需要至少100k燃料卵石才能开始工作(最多可使用675k个卵石);每次操作消耗1个燃料颗粒;TRISO卵石将提供30%的额外能量;每个卵石都会增加转换冷却剂的需求数量;一次工作耗时27个游戏天数 +tooltip.tile.htr.0.name=高温钍反应堆的控制器方块;大小(宽x高x长):11x12x11 (中空);控制器:正面中心,最低一层;角落和两个相邻的方块是空气;:一旦搭建完成,需要在输入仓中输入氦气直到不再接受;1+输出仓(任意底部机械方块);1+输入仓(任意顶部机械方块);1+输入总线(任意顶部机械方块);1x维护仓(任意机械方块);其余的为辐射防护机械方块;在运行时需要持续供应冷却液,完成工作后输出;需要至少100k卵石燃料才能开始工作(最多可使用675k个卵石);每次操作消耗1个燃料颗粒;TRISO卵石将提供30%的额外能量;每个卵石都会增加转换冷却剂的需求数量;一次工作耗时27个游戏日 item.TRISOPellet.name=TRISO卵石 item.TRISOPelletBall.name=TRISO卵石球 item.BISOPelletBall.name=BISO卵石球 @@ -153,8 +153,11 @@ item.TRISOPelletCompound.name=TRISO卵石复合材料 item.BISOPelletCompound.name=BISO卵石复合材料 itemGroup.bartworksMetaMaterials=BartWorks-meta材料 +tooltip.tile.eic.0.name=电气聚爆压缩机的控制器方块;大小(宽x高x长):3x9x3;使用电而不是爆炸物工作;控制器在第三层正面中心;第一到第九层为坚硬钢机械方块,每层中间为能量仓;第2,3,7,8层:中心为镍锌铁氧体方块,其余的为变压器线圈块;第4,5,6层为中子块;1+输入总线,1+输出总线,1个维护仓于坚硬钢机械方块;在操作过程中,请勿遮挡或挖掘移动方块,这会上演爆炸的艺术!! + + planet.Ross128b=罗斯128b moon.Ross128ba=罗斯128ba star.Ross128=罗斯128 solarsystem.Ross128System=罗斯128-行星系 -//This zh_CN.lang is translation by huajijam for bartworks (15/4/19) \ No newline at end of file +//This zh_CN.lang is translated by huajijam for bartworks (24/4/19) \ No newline at end of file -- cgit From 5f41aa8bd449c8c63fd899c6640468fe9d86dc9f Mon Sep 17 00:00:00 2001 From: bartimaeusnek <33183715+bartimaeusnek@users.noreply.github.com> Date: Sun, 28 Apr 2019 22:13:13 +0200 Subject: Tooltip Server Synchronisation Signed-off-by: bartimaeusnek <33183715+bartimaeusnek@users.noreply.github.com> Former-commit-id: 1ce6237155c71ee8329f6302c82b357cc6432214 --- .../github/bartimaeusnek/bartworks/MainMod.java | 8 +-- .../ClientEventHandler/ClientEventHandler.java | 4 +- .../bartworks/common/net/BW_Network.java | 2 +- .../bartworks/common/net/OreDictCachePacket.java | 76 ++++++++++++++++++++++ .../server/EventHandler/ServerEventHandler.java | 41 ++++++++++++ .../bartworks/system/oredict/OreDictHandler.java | 19 +++++- 6 files changed, 141 insertions(+), 9 deletions(-) create mode 100644 src/main/java/com/github/bartimaeusnek/bartworks/common/net/OreDictCachePacket.java create mode 100644 src/main/java/com/github/bartimaeusnek/bartworks/server/EventHandler/ServerEventHandler.java diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/MainMod.java b/src/main/java/com/github/bartimaeusnek/bartworks/MainMod.java index 43b76254d2..da330424ee 100644 --- a/src/main/java/com/github/bartimaeusnek/bartworks/MainMod.java +++ b/src/main/java/com/github/bartimaeusnek/bartworks/MainMod.java @@ -35,6 +35,7 @@ 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; @@ -50,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; @@ -60,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; @@ -68,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; @@ -133,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(); @@ -158,7 +157,6 @@ public final class MainMod { WerkstoffLoader.INSTANCE.run(); } } - @Mod.EventHandler public void onServerStarted(FMLServerStartedEvent event) { OreDictHandler.adaptCacheForWorld(); 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 861b456fd9..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 @@ -64,8 +64,8 @@ public class ClientEventHandler { ItemStack tmp = event.itemStack.copy(); Pair abstractedStack = new Pair<>(Item.getIdFromItem(tmp.getItem()), (short) tmp.getItemDamage()); List tooAdd = new ArrayList<>(); - if (OreDictHandler.getCache().containsValue(abstractedStack)) { - for (Pair pair : OreDictHandler.getCache().values()) { + if (OreDictHandler.getNonBWCache().contains(abstractedStack)) { + for (Pair pair : OreDictHandler.getNonBWCache()) { if (pair.equals(abstractedStack)) { GameRegistry.UniqueIdentifier UI = GameRegistry.findUniqueIdentifierFor(tmp.getItem()); if (UI == null) 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 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 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> hashSet = new HashSet<>(); + + public OreDictCachePacket() { + super(true); + } + + public OreDictCachePacket(HashSet> 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 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(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 d70bf884d2..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,8 +22,12 @@ 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; @@ -35,18 +39,31 @@ import java.util.Set; public class OreDictHandler { private static final HashMap> cache = new HashMap<>(); + private static final HashSet> cacheNonBW = new HashSet<>(); public static HashMap> getCache() { return OreDictHandler.cache; } + public static HashSet> getNonBWCache(){ + return OreDictHandler.cacheNonBW; + } + public static void adaptCacheForWorld(){ Set 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(); - cache.put(s, new Pair<>(Item.getIdFromItem(tmp.getItem()), (short) tmp.getItemDamage())); + Pair 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); + } } } } -- cgit