diff options
Diffstat (limited to 'src/main/java/gregtech')
12 files changed, 159 insertions, 48 deletions
diff --git a/src/main/java/gregtech/api/util/GTRecipeRegistrator.java b/src/main/java/gregtech/api/util/GTRecipeRegistrator.java index 919b37e7d9..745a544a52 100644 --- a/src/main/java/gregtech/api/util/GTRecipeRegistrator.java +++ b/src/main/java/gregtech/api/util/GTRecipeRegistrator.java @@ -31,7 +31,6 @@ import static gregtech.api.util.GTRecipeConstants.UniversalArcFurnace; import static gregtech.api.util.GTUtility.calculateRecipeEU; import static gregtech.api.util.GTUtility.getTier; -import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Arrays; import java.util.IdentityHashMap; @@ -53,7 +52,6 @@ import com.google.common.collect.HashMultimap; import com.google.common.collect.ImmutableList; import com.google.common.collect.SetMultimap; -import cpw.mods.fml.relauncher.ReflectionHelper; import gregtech.api.GregTechAPI; import gregtech.api.enums.GTValues; import gregtech.api.enums.Materials; @@ -63,6 +61,7 @@ import gregtech.api.enums.TierEU; import gregtech.api.objects.ItemData; import gregtech.api.objects.MaterialStack; import gregtech.api.recipe.RecipeCategories; +import gregtech.mixin.interfaces.accessors.ShapedOreRecipeAccessor; import ic2.api.reactor.IReactorComponent; /** @@ -123,8 +122,6 @@ public class GTRecipeRegistrator { new RecipeShape(null, sMt1, null, sMt1, null, null, null, null, null), new RecipeShape(sMt1, sMt1, null, sMt2, null, sMt1, sMt2, null, null), new RecipeShape(null, sMt1, sMt1, sMt1, null, sMt2, null, null, sMt2) }; - public static final Field SHAPED_ORE_RECIPE_WIDTH = ReflectionHelper.findField(ShapedOreRecipe.class, "width"); - public static final Field SHAPED_ORE_RECIPE_HEIGHT = ReflectionHelper.findField(ShapedOreRecipe.class, "height"); private static volatile Map<RecipeShape, List<IRecipe>> indexedRecipeListCache; private static final String[][] sShapesA = new String[][] { null, null, null, { "Helmet", s_P + s_P + s_P, s_P + s_H + s_P }, @@ -791,19 +788,11 @@ public class GTRecipeRegistrator { } private static int getRecipeWidth(ShapedOreRecipe r) { - try { - return (int) SHAPED_ORE_RECIPE_WIDTH.get(r); - } catch (ReflectiveOperationException e) { - throw new RuntimeException(e); - } + return ((ShapedOreRecipeAccessor) r).gt5u$getWidth(); } private static int getRecipeHeight(ShapedOreRecipe r) { - try { - return (int) SHAPED_ORE_RECIPE_HEIGHT.get(r); - } catch (ReflectiveOperationException e) { - throw new RuntimeException(e); - } + return ((ShapedOreRecipeAccessor) r).gt5u$getHeight(); } private static int getRecipeHeight(ShapedRecipes r) { diff --git a/src/main/java/gregtech/loaders/preload/GTPreLoad.java b/src/main/java/gregtech/loaders/preload/GTPreLoad.java index 6216f752dc..b3c4c48095 100644 --- a/src/main/java/gregtech/loaders/preload/GTPreLoad.java +++ b/src/main/java/gregtech/loaders/preload/GTPreLoad.java @@ -339,12 +339,9 @@ public class GTPreLoad { try { Objects.requireNonNull(GTUtility.getField("ic2.core.item.ItemScrapbox$Drop", "topChance", true, true)) .set(null, 0); - ((List<?>) Objects.requireNonNull( - GTUtility.getFieldContent( - GTUtility.getFieldContent("ic2.api.recipe.Recipes", "scrapboxDrops", true, true), - "drops", - true, - true))).clear(); + ((List<?>) Objects + .requireNonNull(GTUtility.getFieldContent(ic2.api.recipe.Recipes.scrapboxDrops, "drops", true, true))) + .clear(); } catch (Throwable e) { if (GTValues.D1) { e.printStackTrace(GTLog.err); @@ -539,7 +536,7 @@ public class GTPreLoad { /** * Clamp value between 0 and 255 - * + * * @param value the value to clamp * @return the clamped value */ diff --git a/src/main/java/gregtech/mixin/Mixin.java b/src/main/java/gregtech/mixin/Mixin.java index 224c7b5f1c..b9ba1db098 100644 --- a/src/main/java/gregtech/mixin/Mixin.java +++ b/src/main/java/gregtech/mixin/Mixin.java @@ -48,16 +48,13 @@ public enum Mixin { .setSide(Side.BOTH)), VanillaAccessors(new Builder("Adds various accessors") .addMixinClasses( - "minecraft.VanillaShapedRecipeMixin", - "minecraft.VanillaShapelessRecipeMixin", - "minecraft.ForgeShapedRecipeMixin", - "minecraft.ForgeShapelessRecipeMixin", - "minecraft.PotionMixin") - .addTargetedMod(VANILLA) - .setApplyIf(() -> true) - .setPhase(Phase.EARLY) - .setSide(Side.BOTH)), - BlockStemMixin(new Builder("Stem Crop Block Accessor").addMixinClasses("minecraft.BlockStemMixin") + "minecraft.accessors.BlockStemMixin", + "minecraft.accessors.VanillaShapedRecipeMixin", + "minecraft.accessors.VanillaShapelessRecipeMixin", + "minecraft.accessors.ForgeShapedRecipeMixin", + "minecraft.accessors.ForgeShapelessRecipeMixin", + "minecraft.accessors.PotionMixin", + "minecraft.accessors.EntityPlayerMPMixin") .addTargetedMod(VANILLA) .setApplyIf(() -> true) .setPhase(Phase.EARLY) diff --git a/src/main/java/gregtech/mixin/hooks/BWCoreStaticReplacementMethodes.java b/src/main/java/gregtech/mixin/hooks/BWCoreStaticReplacementMethodes.java new file mode 100644 index 0000000000..9f8f5fb8b4 --- /dev/null +++ b/src/main/java/gregtech/mixin/hooks/BWCoreStaticReplacementMethodes.java @@ -0,0 +1,112 @@ +/* + * 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 gregtech.mixin.hooks; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; + +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 bartworks.util.NonNullWrappedHashSet; +import bartworks.util.accessprioritylist.AccessPriorityList; +import bartworks.util.accessprioritylist.AccessPriorityListNode; + +public class BWCoreStaticReplacementMethodes { + + private static ThreadLocal<AccessPriorityList<IRecipe>> RECENTLYUSEDRECIPES = ThreadLocal + .withInitial(AccessPriorityList::new); + + public static void clearRecentlyUsedRecipes() { + // the easiest way to ensure the cache is flushed without causing synchronization overhead + // is to just replace the whole ThreadLocal instance. + RECENTLYUSEDRECIPES = ThreadLocal.withInitial(AccessPriorityList::new); + } + + 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); + + } + IRecipe iPossibleRecipe = null; + AccessPriorityList<IRecipe> cache = RECENTLYUSEDRECIPES.get(); + Iterator<AccessPriorityListNode<IRecipe>> it = cache.nodeIterator(); + + while (it.hasNext()) { + AccessPriorityListNode<IRecipe> recipeNode = it.next(); + iPossibleRecipe = recipeNode.getELEMENT(); + + if (!iPossibleRecipe.matches(inventoryCrafting, world)) continue; + + cache.addPrioToNode(recipeNode); + return iPossibleRecipe.getCraftingResult(inventoryCrafting); + } + + HashSet<IRecipe> recipeSet = new NonNullWrappedHashSet<>(); + List<IRecipe> recipeList = CraftingManager.getInstance() + .getRecipeList(); + + for (IRecipe r : recipeList) { + if (r.matches(inventoryCrafting, world)) recipeSet.add(r); + } + + Object[] arr = recipeSet.toArray(); + + if (arr.length == 0) return null; + + IRecipe recipe = (IRecipe) arr[0]; + ItemStack stack = recipe.getCraftingResult(inventoryCrafting); + + if (arr.length != 1) return stack; + + if (stack != null) cache.addLast(recipe); + + return stack; + } + +} diff --git a/src/main/java/gregtech/mixin/MixinsVariablesHelper.java b/src/main/java/gregtech/mixin/hooks/MixinsVariablesHelper.java index 96cc2ee115..7925573f2d 100644 --- a/src/main/java/gregtech/mixin/MixinsVariablesHelper.java +++ b/src/main/java/gregtech/mixin/hooks/MixinsVariablesHelper.java @@ -1,4 +1,4 @@ -package gregtech.mixin; +package gregtech.mixin.hooks; public class MixinsVariablesHelper { diff --git a/src/main/java/gregtech/mixin/interfaces/IBlockStemAccesor.java b/src/main/java/gregtech/mixin/interfaces/IBlockStemAccesor.java deleted file mode 100644 index 089479f8ad..0000000000 --- a/src/main/java/gregtech/mixin/interfaces/IBlockStemAccesor.java +++ /dev/null @@ -1,8 +0,0 @@ -package gregtech.mixin.interfaces; - -import net.minecraft.block.Block; - -public interface IBlockStemAccesor { - - Block getCropBlock(); -} diff --git a/src/main/java/gregtech/mixin/interfaces/PotionExt.java b/src/main/java/gregtech/mixin/interfaces/PotionExt.java deleted file mode 100644 index 11ae365e5a..0000000000 --- a/src/main/java/gregtech/mixin/interfaces/PotionExt.java +++ /dev/null @@ -1,7 +0,0 @@ -package gregtech.mixin.interfaces; - -public interface PotionExt { - - boolean gt5u$isBadEffect(); - -} diff --git a/src/main/java/gregtech/mixin/interfaces/accessors/EntityPlayerMPAccessor.java b/src/main/java/gregtech/mixin/interfaces/accessors/EntityPlayerMPAccessor.java new file mode 100644 index 0000000000..826c5d1474 --- /dev/null +++ b/src/main/java/gregtech/mixin/interfaces/accessors/EntityPlayerMPAccessor.java @@ -0,0 +1,7 @@ +package gregtech.mixin.interfaces.accessors; + +public interface EntityPlayerMPAccessor { + + String gt5u$getTranslator(); + +} diff --git a/src/main/java/gregtech/mixin/interfaces/accessors/IBlockStemAccessor.java b/src/main/java/gregtech/mixin/interfaces/accessors/IBlockStemAccessor.java new file mode 100644 index 0000000000..da3efa582d --- /dev/null +++ b/src/main/java/gregtech/mixin/interfaces/accessors/IBlockStemAccessor.java @@ -0,0 +1,8 @@ +package gregtech.mixin.interfaces.accessors; + +import net.minecraft.block.Block; + +public interface IBlockStemAccessor { + + Block gt5u$getCropBlock(); +} diff --git a/src/main/java/gregtech/api/interfaces/IRecipeMutableAccess.java b/src/main/java/gregtech/mixin/interfaces/accessors/IRecipeMutableAccess.java index 5c6d931d5a..778e021205 100644 --- a/src/main/java/gregtech/api/interfaces/IRecipeMutableAccess.java +++ b/src/main/java/gregtech/mixin/interfaces/accessors/IRecipeMutableAccess.java @@ -1,4 +1,4 @@ -package gregtech.api.interfaces; +package gregtech.mixin.interfaces.accessors; import net.minecraft.item.ItemStack; diff --git a/src/main/java/gregtech/mixin/interfaces/accessors/PotionAccessor.java b/src/main/java/gregtech/mixin/interfaces/accessors/PotionAccessor.java new file mode 100644 index 0000000000..48794c256a --- /dev/null +++ b/src/main/java/gregtech/mixin/interfaces/accessors/PotionAccessor.java @@ -0,0 +1,7 @@ +package gregtech.mixin.interfaces.accessors; + +public interface PotionAccessor { + + boolean gt5u$isBadEffect(); + +} diff --git a/src/main/java/gregtech/mixin/interfaces/accessors/ShapedOreRecipeAccessor.java b/src/main/java/gregtech/mixin/interfaces/accessors/ShapedOreRecipeAccessor.java new file mode 100644 index 0000000000..9d2980e434 --- /dev/null +++ b/src/main/java/gregtech/mixin/interfaces/accessors/ShapedOreRecipeAccessor.java @@ -0,0 +1,9 @@ +package gregtech.mixin.interfaces.accessors; + +public interface ShapedOreRecipeAccessor { + + int gt5u$getWidth(); + + int gt5u$getHeight(); + +} |