From c7b38c23c5b34a324256966f0a9335694fe8d63b Mon Sep 17 00:00:00 2001 From: Raven Szewczyk Date: Sat, 27 Jul 2024 07:12:04 +0100 Subject: Optimize load time (#2774) * Load time optimization: replace recipe reflection with mixin accessor * Save an inner loop allocation in StaticRecipeChangeLoaders * Move Bauble event handler from individual items to GT++ proxy * Update mobs info with more optimizations --- .../gregtech/api/interfaces/IRecipeMutableAccess.java | 18 ++++++++++++++++++ src/main/java/gregtech/api/util/GT_ModHandler.java | 4 ++-- src/main/java/gregtech/mixin/Mixin.java | 10 ++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 src/main/java/gregtech/api/interfaces/IRecipeMutableAccess.java (limited to 'src/main/java/gregtech') diff --git a/src/main/java/gregtech/api/interfaces/IRecipeMutableAccess.java b/src/main/java/gregtech/api/interfaces/IRecipeMutableAccess.java new file mode 100644 index 0000000000..5c6d931d5a --- /dev/null +++ b/src/main/java/gregtech/api/interfaces/IRecipeMutableAccess.java @@ -0,0 +1,18 @@ +package gregtech.api.interfaces; + +import net.minecraft.item.ItemStack; + +/** + * Mixed-in interface for recipe classes in Forge and Vanilla that allows mutating the input and output items. + */ +public interface IRecipeMutableAccess { + + /** @return Gets the current output item of the recipe */ + ItemStack gt5u$getRecipeOutputItem(); + + /** Sets a new output item on the recipe */ + void gt5u$setRecipeOutputItem(ItemStack newItem); + + /** @return The raw list or array of recipe inputs, the exact type depends on the underlying recipe type. */ + Object gt5u$getRecipeInputs(); +} diff --git a/src/main/java/gregtech/api/util/GT_ModHandler.java b/src/main/java/gregtech/api/util/GT_ModHandler.java index 8c43a5334b..45df4ffeea 100644 --- a/src/main/java/gregtech/api/util/GT_ModHandler.java +++ b/src/main/java/gregtech/api/util/GT_ModHandler.java @@ -93,8 +93,8 @@ public class GT_ModHandler { public static final List sSingleNonBlockDamagableRecipeList = new ArrayList<>(1000); private static final Map sIC2ItemMap = new HashMap<>(); - private static final List sAllRecipeList = new ArrayList<>(5000), - sBufferRecipeList = new ArrayList<>(1000); + // public for bartworks + public static final List sAllRecipeList = new ArrayList<>(5000), sBufferRecipeList = new ArrayList<>(1000); private static final List delayedRemovalByOutput = new ArrayList<>(); private static final List delayedRemovalByRecipe = new ArrayList<>(); diff --git a/src/main/java/gregtech/mixin/Mixin.java b/src/main/java/gregtech/mixin/Mixin.java index 8ead56bf44..340868e015 100644 --- a/src/main/java/gregtech/mixin/Mixin.java +++ b/src/main/java/gregtech/mixin/Mixin.java @@ -41,6 +41,16 @@ public enum Mixin { .setApplyIf(() -> ConfigHandler.enabledPatches[3]) .setPhase(Phase.EARLY) .setSide(Side.BOTH)), + CraftingRecipeAccessorMixin(new Builder("Add accessors to crafting recipe types") + .addMixinClasses( + "minecraft.VanillaShapedRecipeMixin", + "minecraft.VanillaShapelessRecipeMixin", + "minecraft.ForgeShapedRecipeMixin", + "minecraft.ForgeShapelessRecipeMixin") + .addTargetedMod(VANILLA) + .setApplyIf(() -> true) + .setPhase(Phase.EARLY) + .setSide(Side.BOTH)), BlockStemMixin(new Builder("Stem Crop Block Accessor").addMixinClasses("minecraft.BlockStemMixin") .addTargetedMod(VANILLA) .setApplyIf(() -> true) -- cgit