diff options
author | bartimaeusnek <33183715+bartimaeusnek@users.noreply.github.com> | 2019-12-13 00:07:12 +0100 |
---|---|---|
committer | bartimaeusnek <33183715+bartimaeusnek@users.noreply.github.com> | 2019-12-13 00:07:12 +0100 |
commit | 8c35bce9a6b7f1d917778243047a16eba791c5d9 (patch) | |
tree | 0a46364cdebc4c7857ea61c6b8e0dfae140fb7a1 /src/main | |
parent | 1a184abb892c4b9a83c7b89d59fcd3206ca7378e (diff) | |
download | GT5-Unofficial-8c35bce9a6b7f1d917778243047a16eba791c5d9.tar.gz GT5-Unofficial-8c35bce9a6b7f1d917778243047a16eba791c5d9.tar.bz2 GT5-Unofficial-8c35bce9a6b7f1d917778243047a16eba791c5d9.zip |
added ASM to buffer recipe
+added a command to print the recipe list to a file
Signed-off-by: bartimaeusnek <33183715+bartimaeusnek@users.noreply.github.com>
Former-commit-id: 2d9d7406dc7377641cfcf6d38e744e89c7518a47
Diffstat (limited to 'src/main')
5 files changed, 170 insertions, 5 deletions
diff --git a/src/main/java/com/github/bartimaeusnek/ASM/BWCoreStaticReplacementMethodes.java b/src/main/java/com/github/bartimaeusnek/ASM/BWCoreStaticReplacementMethodes.java index b239563656..9552528acf 100644 --- a/src/main/java/com/github/bartimaeusnek/ASM/BWCoreStaticReplacementMethodes.java +++ b/src/main/java/com/github/bartimaeusnek/ASM/BWCoreStaticReplacementMethodes.java @@ -22,7 +22,82 @@ package com.github.bartimaeusnek.ASM; +import net.minecraft.inventory.InventoryCrafting; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.CraftingManager; +import net.minecraft.item.crafting.IRecipe; +import net.minecraft.world.World; + +import java.util.LinkedList; +import java.util.Optional; + public class BWCoreStaticReplacementMethodes { + + public static final LinkedList<IRecipe> RECENTLYUSEDRECIPES = new LinkedList<>(); + + @SuppressWarnings("ALL") + public static ItemStack findCachedMatchingRecipe(InventoryCrafting inventoryCrafting, World world) { + int i = 0; + ItemStack itemstack = null; + ItemStack itemstack1 = null; + int j; + + for (j = 0; j < inventoryCrafting.getSizeInventory(); ++j) + { + ItemStack itemstack2 = inventoryCrafting.getStackInSlot(j); + + if (itemstack2 != null) + { + if (i == 0) + { + itemstack = itemstack2; + } + + if (i == 1) + { + itemstack1 = itemstack2; + } + + ++i; + } + } + + if (i == 2 && itemstack.getItem() == itemstack1.getItem() && itemstack.stackSize == 1 && itemstack1.stackSize == 1 && itemstack.getItem().isRepairable()) + { + Item item = itemstack.getItem(); + int j1 = item.getMaxDamage() - itemstack.getItemDamageForDisplay(); + int k = item.getMaxDamage() - itemstack1.getItemDamageForDisplay(); + int l = j1 + k + item.getMaxDamage() * 5 / 100; + int i1 = item.getMaxDamage() - l; + + if (i1 < 0) + { + i1 = 0; + } + + return new ItemStack(itemstack.getItem(), 1, i1); + } else { + Optional<IRecipe> iPossibleRecipe = RECENTLYUSEDRECIPES.stream().filter(r -> r.matches(inventoryCrafting, world)).findFirst(); + + if (iPossibleRecipe.isPresent()) { + int index = RECENTLYUSEDRECIPES.indexOf(iPossibleRecipe.get()); + if (index != 0) { + --index; + RECENTLYUSEDRECIPES.remove(iPossibleRecipe.get()); + RECENTLYUSEDRECIPES.add(index, iPossibleRecipe.get()); + } + return iPossibleRecipe.get().getCraftingResult(inventoryCrafting); + } + + iPossibleRecipe = CraftingManager.getInstance().getRecipeList().stream().filter(r -> ((IRecipe)r).matches(inventoryCrafting, world)).findFirst(); + ItemStack stack = iPossibleRecipe.map(iRecipe -> iRecipe.getCraftingResult(inventoryCrafting)).orElse(null); + if (stack != null) + RECENTLYUSEDRECIPES.addLast(iPossibleRecipe.get()); + return stack; + } + } + private BWCoreStaticReplacementMethodes() { } diff --git a/src/main/java/com/github/bartimaeusnek/ASM/BWCoreTransformer.java b/src/main/java/com/github/bartimaeusnek/ASM/BWCoreTransformer.java index 4ec2f70142..99a748fbd7 100644 --- a/src/main/java/com/github/bartimaeusnek/ASM/BWCoreTransformer.java +++ b/src/main/java/com/github/bartimaeusnek/ASM/BWCoreTransformer.java @@ -40,6 +40,7 @@ public class BWCoreTransformer implements IClassTransformer { "PATCHING THAUMCRAFT WAND PEDESTAL TO PREVENT VIS DUPLICATION", "PLACING MY GLASS-BLOCK RUNNABLE INTO THE GT_API", "DUCTTAPING RWG WORLDEN FAILS", + "PATCHING CRAFTING MANAGER FOR CACHING RECIPES" // "REMOVING 12% BONUS OUTPUTS FROM GT++ SIFTER" }; public static final String[] CLASSESBEEINGTRANSFORMED = { @@ -49,6 +50,7 @@ public class BWCoreTransformer implements IClassTransformer { "thaumcraft.common.tiles.TileWandPedestal", "gregtech.GT_Mod", "rwg.world.ChunkGeneratorRealistic", + "net.minecraft.item.crafting.CraftingManager" // "gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing.GregtechMetaTileEntity_IndustrialSifter" }; static boolean obfs; @@ -282,6 +284,23 @@ public class BWCoreTransformer implements IClassTransformer { } } } + case 6: { + BWCore.BWCORE_LOG.info("Could find: " + BWCoreTransformer.CLASSESBEEINGTRANSFORMED[id]); + String name_deObfs = "findMatchingRecipe"; + String name_Obfs = "a"; + String name_src = "func_82787_a"; + for (MethodNode toPatch : methods) { + if (ASMUtils.isCorrectMethod(toPatch,name_deObfs,name_Obfs,name_src)){ + toPatch.instructions = new InsnList(); + toPatch.instructions.add(new VarInsnNode(ALOAD,1)); + toPatch.instructions.add(new VarInsnNode(ALOAD,2)); + toPatch.instructions.add(new MethodInsnNode(INVOKESTATIC,"com/github/bartimaeusnek/ASM/BWCoreStaticReplacementMethodes","findCachedMatchingRecipe","(Lnet/minecraft/inventory/InventoryCrafting;Lnet/minecraft/world/World;)Lnet/minecraft/item/ItemStack;",false)); + toPatch.instructions.add(new InsnNode(ARETURN)); + break scase; + } + } + } + // case 6: { // BWCore.BWCORE_LOG.info("Could find: " + BWCoreTransformer.CLASSESBEEINGTRANSFORMED[id]); // ((IntInsnNode) methods.get(11).instructions.get(10)).operand = 10000; diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/MainMod.java b/src/main/java/com/github/bartimaeusnek/bartworks/MainMod.java index d725129087..88aa7b547c 100644 --- a/src/main/java/com/github/bartimaeusnek/bartworks/MainMod.java +++ b/src/main/java/com/github/bartimaeusnek/bartworks/MainMod.java @@ -31,6 +31,9 @@ import com.github.bartimaeusnek.bartworks.client.creativetabs.BioTab; import com.github.bartimaeusnek.bartworks.client.creativetabs.GT2Tab; import com.github.bartimaeusnek.bartworks.client.creativetabs.bartworksTab; import com.github.bartimaeusnek.bartworks.client.textures.PrefixTextureLinker; +import com.github.bartimaeusnek.bartworks.common.commands.ChangeConfig; +import com.github.bartimaeusnek.bartworks.common.commands.PrintRecipeListToFile; +import com.github.bartimaeusnek.bartworks.common.commands.SummonRuin; import com.github.bartimaeusnek.bartworks.common.configs.ConfigHandler; import com.github.bartimaeusnek.bartworks.common.loaders.BioCultureLoader; import com.github.bartimaeusnek.bartworks.common.loaders.BioLabLoader; @@ -198,7 +201,12 @@ public final class MainMod { } } - private static boolean recipesAdded; + @Mod.EventHandler + public void onServerStarting(FMLServerStartingEvent event){ + event.registerServerCommand(new SummonRuin()); + event.registerServerCommand(new ChangeConfig()); + event.registerServerCommand(new PrintRecipeListToFile()); + } @Mod.EventHandler public void onServerStarted(FMLServerStartedEvent event) { @@ -215,6 +223,8 @@ public final class MainMod { MainMod.unificationRecipeEnforcer(); } + private static boolean recipesAdded; + public static void runOnPlayerJoined(boolean classicMode, boolean extraGasRecipes){ OreDictHandler.adaptCacheForWorld(); if (!recipesAdded) { diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/common/commands/PrintRecipeListToFile.java b/src/main/java/com/github/bartimaeusnek/bartworks/common/commands/PrintRecipeListToFile.java new file mode 100644 index 0000000000..b7d6e7f82d --- /dev/null +++ b/src/main/java/com/github/bartimaeusnek/bartworks/common/commands/PrintRecipeListToFile.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2018-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.commands; + +import net.minecraft.command.CommandBase; +import net.minecraft.command.ICommandSender; +import net.minecraft.item.crafting.CraftingManager; +import net.minecraft.item.crafting.IRecipe; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; + +public class PrintRecipeListToFile extends CommandBase { + @Override + public String getCommandName() { + return "prltf"; + } + + @Override + public String getCommandUsage(ICommandSender p_71518_1_) { + return "prltf <FilePath>"; + } + + @Override + public void processCommand(ICommandSender p_71515_1_, String[] p_71515_2_) { + File file = new File(p_71515_2_[0]); + try { + + BufferedWriter fw = new BufferedWriter(new FileWriter(file)); + CraftingManager.getInstance().getRecipeList().forEach( e -> { + try { + fw.write(e.toString() + " = " +((IRecipe)e).getRecipeOutput().getDisplayName() +"\n"); + } catch (IOException ex) { + ex.printStackTrace(); + } + }); + fw.flush(); + fw.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/com/github/bartimaeusnek/crossmod/BartWorksCrossmod.java b/src/main/java/com/github/bartimaeusnek/crossmod/BartWorksCrossmod.java index 67deac1066..953cfa62ad 100644 --- a/src/main/java/com/github/bartimaeusnek/crossmod/BartWorksCrossmod.java +++ b/src/main/java/com/github/bartimaeusnek/crossmod/BartWorksCrossmod.java @@ -23,8 +23,6 @@ package com.github.bartimaeusnek.crossmod; import com.github.bartimaeusnek.bartworks.MainMod; -import com.github.bartimaeusnek.bartworks.common.commands.ChangeConfig; -import com.github.bartimaeusnek.bartworks.common.commands.SummonRuin; import com.github.bartimaeusnek.crossmod.GTpp.loader.RadioHatchCompat; import com.github.bartimaeusnek.crossmod.galacticraft.GalacticraftProxy; import com.github.bartimaeusnek.crossmod.tectech.TecTechResearchLoader; @@ -110,8 +108,6 @@ public class BartWorksCrossmod { @Mod.EventHandler public void onFMLServerStart(FMLServerStartingEvent event) { - event.registerServerCommand(new SummonRuin()); - event.registerServerCommand(new ChangeConfig()); if (Loader.isModLoaded("miscutils")) for (Object s : RadioHatchCompat.TranslateSet){ StringTranslate.inject(new ReaderInputStream(new StringReader((String) s))); |