diff options
author | Glease <4586901+Glease@users.noreply.github.com> | 2022-03-07 14:06:27 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-07 07:06:27 +0100 |
commit | 6ebee72bbe887ea2c7d753347200ba8a38d16ea8 (patch) | |
tree | 42bd86cf203b4d56dd1f7a162797dae47f04d628 | |
parent | 0fe957014c4725b048c43eaf196c23a181286427 (diff) | |
download | GT5-Unofficial-6ebee72bbe887ea2c7d753347200ba8a38d16ea8.tar.gz GT5-Unofficial-6ebee72bbe887ea2c7d753347200ba8a38d16ea8.tar.bz2 GT5-Unofficial-6ebee72bbe887ea2c7d753347200ba8a38d16ea8.zip |
fix balky nei handlers (#102)
* fix balky nei handlers
also cleaned up NEI plugin a bit. ore handler still looks dumb though.
* add some comment to explain the magic numbers
Former-commit-id: 8b96e8847c20e74a601f8fd06d68d79a4852952b
5 files changed, 73 insertions, 127 deletions
diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/neiHandler/BW_NEI_BioLabHandler.java b/src/main/java/com/github/bartimaeusnek/bartworks/neiHandler/BW_NEI_BioLabHandler.java index 0e17f16506..d1dac08766 100644 --- a/src/main/java/com/github/bartimaeusnek/bartworks/neiHandler/BW_NEI_BioLabHandler.java +++ b/src/main/java/com/github/bartimaeusnek/bartworks/neiHandler/BW_NEI_BioLabHandler.java @@ -32,12 +32,9 @@ import gregtech.api.util.GT_Recipe; import gregtech.nei.GT_NEI_DefaultHandler; import net.minecraft.item.ItemStack; -import java.awt.*; - public class BW_NEI_BioLabHandler extends GT_NEI_DefaultHandler { public BW_NEI_BioLabHandler(GT_Recipe.GT_Recipe_Map aRecipeMap) { super(aRecipeMap); - this.transferRects.add(new TemplateRecipeHandler.RecipeTransferRect(new Rectangle(65, 13, 36, 18), this.getOverlayIdentifier())); if (!NEI_BW_Config.sIsAdded) { FMLInterModComms.sendRuntimeMessage(GT_Values.GT, "NEIPlugins", "register-crafting-handler", "gregtech@" + this.getRecipeName() + "@" + this.getOverlayIdentifier()); GuiCraftingRecipe.craftinghandlers.add(this); @@ -50,37 +47,23 @@ public class BW_NEI_BioLabHandler extends GT_NEI_DefaultHandler { } public void loadCraftingRecipes(ItemStack aResult) { - if (aResult != null && aResult.getItem() instanceof LabParts && aResult.getItemDamage() < 3) { - for (GT_Recipe recipe : this.getSortedRecipes()) { - if (aResult.getTagCompound() != null && recipe != null) - for (int i = 0; i < recipe.mOutputs.length; i++) { - if (recipe.mOutputs[i] != null) - if (aResult.getTagCompound().equals(recipe.mOutputs[i].getTagCompound())) { - this.arecipes.add(new CachedDefaultRecipe(recipe)); - break; - } - - } - } - } else + if (aResult != null && aResult.getItem() instanceof LabParts && aResult.getItemDamage() < 3 && aResult.getTagCompound() != null) { + for (CachedDefaultRecipe recipe : getCache()) + if (NEI_BW_Config.checkRecipe(aResult, recipe.mOutputs)) + arecipes.add(recipe); + } else { super.loadCraftingRecipes(aResult); + } } @Override public void loadUsageRecipes(ItemStack aResult) { - if (aResult != null && aResult.getItem() instanceof LabParts && aResult.getItemDamage() < 3) { - for (GT_Recipe recipe : this.getSortedRecipes()) { - if (aResult.getTagCompound() != null && recipe != null) - for (int i = 0; i < recipe.mInputs.length; i++) { - if (recipe.mInputs[i] != null) - if (aResult.getTagCompound().equals(recipe.mInputs[i].getTagCompound())) { - this.arecipes.add(new CachedDefaultRecipe(recipe)); - break; - } - - } - } - } else - super.loadCraftingRecipes(aResult); + if (aResult != null && aResult.getItem() instanceof LabParts && aResult.getItemDamage() < 3 && aResult.getTagCompound() != null) { + for (CachedDefaultRecipe recipe : getCache()) + if (NEI_BW_Config.checkRecipe(aResult, recipe.mInputs)) + arecipes.add(recipe); + } else { + super.loadUsageRecipes(aResult); + } } } diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/neiHandler/BW_NEI_BioVatHandler.java b/src/main/java/com/github/bartimaeusnek/bartworks/neiHandler/BW_NEI_BioVatHandler.java index 33ba6e874a..7890af3d54 100644 --- a/src/main/java/com/github/bartimaeusnek/bartworks/neiHandler/BW_NEI_BioVatHandler.java +++ b/src/main/java/com/github/bartimaeusnek/bartworks/neiHandler/BW_NEI_BioVatHandler.java @@ -22,6 +22,7 @@ package com.github.bartimaeusnek.bartworks.neiHandler; +import codechicken.nei.PositionedStack; import codechicken.nei.recipe.GuiCraftingRecipe; import codechicken.nei.recipe.GuiUsageRecipe; import codechicken.nei.recipe.TemplateRecipeHandler; @@ -37,6 +38,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.StatCollector; import java.awt.*; +import java.util.Collections; public class BW_NEI_BioVatHandler extends GT_NEI_DefaultHandler { @@ -107,23 +109,33 @@ public class BW_NEI_BioVatHandler extends GT_NEI_DefaultHandler { } + private void loadLabPartRecipes(ItemStack aResult) { + for (CachedDefaultRecipe recipe : getCache()) { + // dirty way of finding the special slot item + // see constructor of CachedDefaultRecipe on why relx==120 and rely==52 means special slot + for (PositionedStack stack : recipe.mInputs) { + if (stack.relx == 120 && stack.rely == 52) { + if (NEI_BW_Config.checkRecipe(aResult, Collections.singletonList(stack))) + arecipes.add(recipe); + } + } + } + } + @Override public void loadUsageRecipes(ItemStack aResult) { - if (aResult != null && aResult.getItem() instanceof LabParts && aResult.getItemDamage() < 3) - for (GT_Recipe recipe : this.getSortedRecipes()) { - if (aResult.getTagCompound() != null && recipe != null) - if (recipe.mSpecialItems instanceof ItemStack && ((ItemStack) recipe.mSpecialItems).getItem() instanceof LabParts) - if (aResult.getTagCompound().equals(((ItemStack) recipe.mSpecialItems).getTagCompound())) { - this.arecipes.add(new CachedDefaultRecipe(recipe)); - } - } - else - super.loadCraftingRecipes(aResult); + if (aResult != null && aResult.getItem() instanceof LabParts && aResult.getItemDamage() < 3 && aResult.getTagCompound() != null) { + loadLabPartRecipes(aResult); + } else { + super.loadUsageRecipes(aResult); + } } @Override public void loadCraftingRecipes(ItemStack aResult) { - if (aResult == null || !(aResult.getItem() instanceof LabParts && aResult.getItemDamage() < 3)) { + if (aResult != null && aResult.getItem() instanceof LabParts && aResult.getItemDamage() < 3 && aResult.getTagCompound() != null) { + loadLabPartRecipes(aResult); + } else { super.loadCraftingRecipes(aResult); } } diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/neiHandler/BW_NEI_OreHandler.java b/src/main/java/com/github/bartimaeusnek/bartworks/neiHandler/BW_NEI_OreHandler.java index c54667c431..8bb59713ae 100644 --- a/src/main/java/com/github/bartimaeusnek/bartworks/neiHandler/BW_NEI_OreHandler.java +++ b/src/main/java/com/github/bartimaeusnek/bartworks/neiHandler/BW_NEI_OreHandler.java @@ -51,7 +51,6 @@ public class BW_NEI_OreHandler extends TemplateRecipeHandler { if (!NEI_BW_Config.sIsAdded) { FMLInterModComms.sendRuntimeMessage(MainMod.MOD_ID, "NEIPlugins", "register-crafting-handler", MainMod.MOD_ID + "@" + this.getRecipeName() + "@" + this.getOverlayIdentifier()); GuiCraftingRecipe.craftinghandlers.add(this); -// GuiUsageRecipe.usagehandlers.add(this); } } diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/neiHandler/NEI_BW_Config.java b/src/main/java/com/github/bartimaeusnek/bartworks/neiHandler/NEI_BW_Config.java index c0f6ba3340..92779481bb 100644 --- a/src/main/java/com/github/bartimaeusnek/bartworks/neiHandler/NEI_BW_Config.java +++ b/src/main/java/com/github/bartimaeusnek/bartworks/neiHandler/NEI_BW_Config.java @@ -22,24 +22,55 @@ package com.github.bartimaeusnek.bartworks.neiHandler; +import codechicken.nei.PositionedStack; import codechicken.nei.api.API; import codechicken.nei.api.IConfigureNEI; import com.github.bartimaeusnek.bartworks.MainMod; import com.github.bartimaeusnek.bartworks.common.loaders.FluidLoader; import com.github.bartimaeusnek.bartworks.common.loaders.ItemRegistry; +import com.github.bartimaeusnek.bartworks.system.material.WerkstoffLoader; import com.github.bartimaeusnek.bartworks.util.BWRecipes; -import cpw.mods.fml.common.Optional; +import gregtech.api.enums.OrePrefixes; import net.minecraft.item.ItemStack; -@Optional.Interface(iface = "codechicken.nei.api.API", modid = "NotEnoughItems") public class NEI_BW_Config implements IConfigureNEI { - public static boolean sIsAdded = true; + static boolean sIsAdded = true; + static boolean checkRecipe(ItemStack labPart, Iterable<? extends PositionedStack> stacks) { + for (PositionedStack stack : stacks) { + for (ItemStack item : stack.items) { + if (labPart.getTagCompound().equals(item.getTagCompound())) { + return true; + } + } + } + return false; + } + + @Override public void loadConfig() { API.hideItem(new ItemStack(ItemRegistry.TAB)); API.hideItem(new ItemStack(FluidLoader.bioFluidBlock)); API.hideItem(new ItemStack(ItemRegistry.bw_fake_glasses)); + ItemStack[] prefixesToHide = { + WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.dustTiny, WerkstoffLoader.Bismutite).copy(), + WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.dustSmall, WerkstoffLoader.Bismutite).copy(), + WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.crushed, WerkstoffLoader.Bismutite).copy(), + WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.crushedPurified, WerkstoffLoader.Bismutite).copy(), + WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.crushedCentrifuged, WerkstoffLoader.Bismutite).copy(), + WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.nugget, WerkstoffLoader.Bismutite).copy(), + WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.gemChipped, WerkstoffLoader.Bismutite).copy(), + WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.gemFlawed, WerkstoffLoader.Bismutite).copy(), + WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.gemFlawless, WerkstoffLoader.Bismutite).copy(), + WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.gemExquisite, WerkstoffLoader.Bismutite).copy(), + WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.dustImpure, WerkstoffLoader.Bismutite).copy(), + WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.dustPure, WerkstoffLoader.Bismutite).copy(), + }; + for (ItemStack stack : prefixesToHide) { + stack.setItemDamage(Short.MAX_VALUE); + API.hideItem(stack); + } NEI_BW_Config.sIsAdded = false; new BW_NEI_OreHandler(); new BW_NEI_BioVatHandler(BWRecipes.instance.getMappingsFor(BWRecipes.BACTERIALVATBYTE)); @@ -47,13 +78,13 @@ public class NEI_BW_Config implements IConfigureNEI { NEI_BW_Config.sIsAdded = true; } - @Optional.Method(modid = "NotEnoughItems") + @Override public String getName() { return "BartWorks NEI Plugin"; } - @Optional.Method(modid = "NotEnoughItems") + @Override public String getVersion() { return MainMod.APIVERSION; } -}
\ No newline at end of file +} diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/neiHandler/NEIbartworksConfig.java b/src/main/java/com/github/bartimaeusnek/bartworks/neiHandler/NEIbartworksConfig.java deleted file mode 100644 index f05a35cdb9..0000000000 --- a/src/main/java/com/github/bartimaeusnek/bartworks/neiHandler/NEIbartworksConfig.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2018-2020 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.neiHandler; - -import codechicken.nei.api.API; -import codechicken.nei.api.IConfigureNEI; -import com.github.bartimaeusnek.bartworks.MainMod; -import com.github.bartimaeusnek.bartworks.common.loaders.FluidLoader; -import com.github.bartimaeusnek.bartworks.common.loaders.ItemRegistry; -import com.github.bartimaeusnek.bartworks.system.material.WerkstoffLoader; -import cpw.mods.fml.common.Optional; -import gregtech.api.enums.OrePrefixes; -import net.minecraft.item.ItemStack; - - -@Optional.Interface(iface = "codechicken.nei.api.API", modid = "NotEnoughItems") -public class NEIbartworksConfig implements IConfigureNEI { - - @Optional.Method(modid = "NotEnoughItems") - @Override - public String getName() { - return MainMod.NAME; - } - - @Optional.Method(modid = "NotEnoughItems") - @Override - public String getVersion() { - return MainMod.VERSION; - } - - @Optional.Method(modid = "NotEnoughItems") - @Override - public void loadConfig() { - API.hideItem(new ItemStack(ItemRegistry.TAB)); - API.hideItem(new ItemStack(FluidLoader.bioFluidBlock)); - API.hideItem(new ItemStack(ItemRegistry.bw_fake_glasses)); - ItemStack[] prefixesToHide = { - WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.dustTiny, WerkstoffLoader.Bismutite).copy(), - WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.dustSmall, WerkstoffLoader.Bismutite).copy(), - WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.crushed, WerkstoffLoader.Bismutite).copy(), - WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.crushedPurified, WerkstoffLoader.Bismutite).copy(), - WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.crushedCentrifuged, WerkstoffLoader.Bismutite).copy(), - WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.nugget, WerkstoffLoader.Bismutite).copy(), - WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.gemChipped, WerkstoffLoader.Bismutite).copy(), - WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.gemFlawed, WerkstoffLoader.Bismutite).copy(), - WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.gemFlawless, WerkstoffLoader.Bismutite).copy(), - WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.gemExquisite, WerkstoffLoader.Bismutite).copy(), - WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.dustImpure, WerkstoffLoader.Bismutite).copy(), - WerkstoffLoader.getCorrespondingItemStack(OrePrefixes.dustPure, WerkstoffLoader.Bismutite).copy(), - }; - for (ItemStack stack : prefixesToHide) { - stack.setItemDamage(Short.MAX_VALUE); - API.hideItem(stack); - } -// for (int i = 0; i < Short.MAX_VALUE; i++) { -// API.addItemListEntry(new ItemStack(WerkstoffLoader.BWOres,1,i)); -// } - } -}
\ No newline at end of file |