From 553487bf63fcbfa11ac2e329319ffe94ec52d2fe Mon Sep 17 00:00:00 2001 From: screret <68943070+screret@users.noreply.github.com> Date: Mon, 23 Oct 2023 08:33:56 +0300 Subject: [PATCH] "fix" #480 (#482) * "fix" #480 * memoize this cuz why not, should? speed it up. --- .../renderer/block/OreBlockRenderer.java | 3 ++- .../core/mixins/GregTechMixinPlugin.java | 2 +- .../core/mixins/rhino/InterpreterMixin.java | 23 +++++++++++++++++++ .../main/resources/gtceu-common.mixins.json | 3 ++- 4 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 common/src/main/java/com/gregtechceu/gtceu/core/mixins/rhino/InterpreterMixin.java diff --git a/common/src/main/java/com/gregtechceu/gtceu/client/renderer/block/OreBlockRenderer.java b/common/src/main/java/com/gregtechceu/gtceu/client/renderer/block/OreBlockRenderer.java index 146c168666..7c7601ab1c 100644 --- a/common/src/main/java/com/gregtechceu/gtceu/client/renderer/block/OreBlockRenderer.java +++ b/common/src/main/java/com/gregtechceu/gtceu/client/renderer/block/OreBlockRenderer.java @@ -1,5 +1,6 @@ package com.gregtechceu.gtceu.client.renderer.block; +import com.google.common.base.Suppliers; import com.gregtechceu.gtceu.client.model.ItemBakedModel; import com.lowdragmc.lowdraglib.LDLib; import com.lowdragmc.lowdraglib.client.bakedpipeline.FaceQuad; @@ -43,7 +44,7 @@ public class OreBlockRenderer extends BlockStateRenderer { private final boolean emissive; public OreBlockRenderer(Supplier stone, Supplier overlaySupplier, boolean emissive) { - this.stone = stone; + this.stone = Suppliers.memoize(stone::get); this.overlaySupplier = overlaySupplier; this.emissive = emissive; if (LDLib.isClient()) { diff --git a/common/src/main/java/com/gregtechceu/gtceu/core/mixins/GregTechMixinPlugin.java b/common/src/main/java/com/gregtechceu/gtceu/core/mixins/GregTechMixinPlugin.java index f03c8ee672..5e6ff54cdf 100644 --- a/common/src/main/java/com/gregtechceu/gtceu/core/mixins/GregTechMixinPlugin.java +++ b/common/src/main/java/com/gregtechceu/gtceu/core/mixins/GregTechMixinPlugin.java @@ -21,7 +21,7 @@ public String getRefMapperConfig() { @Override public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { - if (mixinClassName.contains("com.gregtechceu.gtceu.core.mixins.kjs")) { + if (mixinClassName.contains("com.gregtechceu.gtceu.core.mixins.kjs") || mixinClassName.contains("com.gregtechceu.gtceu.core.mixins.rhino")) { return MixinPluginShared.isClassFound("dev.latvian.mods.kubejs.KubeJSPlugin"); } else if (mixinClassName.contains("com.gregtechceu.gtceu.core.mixins.create")) { return MixinPluginShared.isClassFound("com.simibubi.create.compat.Mods"); diff --git a/common/src/main/java/com/gregtechceu/gtceu/core/mixins/rhino/InterpreterMixin.java b/common/src/main/java/com/gregtechceu/gtceu/core/mixins/rhino/InterpreterMixin.java new file mode 100644 index 0000000000..bd42db121c --- /dev/null +++ b/common/src/main/java/com/gregtechceu/gtceu/core/mixins/rhino/InterpreterMixin.java @@ -0,0 +1,23 @@ +package com.gregtechceu.gtceu.core.mixins.rhino; + +import dev.latvian.mods.rhino.*; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Coerce; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(value = Interpreter.class, remap = false) +public class InterpreterMixin { + + /** + * {@code @Coerce}'d because the InterpretedFunction class is package-private. It "works". + * What a bodge for an issue that should never even happen, looking at the code. + * God I hate Rhino. + */ + @SuppressWarnings("InvalidInjectorMethodSignature") + @Inject(method = "interpret", at = @At(value = "INVOKE", target = "Ldev/latvian/mods/rhino/Kit;codeBug()Ljava/lang/RuntimeException;"), remap = false, cancellable = true) + private static void gtceu$doNotCrashPls(@Coerce NativeFunction ifun, Context cx, Scriptable scope, Scriptable thisObj, Object[] args, CallbackInfoReturnable cir) { + cir.setReturnValue(ScriptRuntime.doTopCall(cx, scope, ifun, thisObj, args, cx.isStrictMode())); + } +} diff --git a/common/src/main/resources/gtceu-common.mixins.json b/common/src/main/resources/gtceu-common.mixins.json index 7715e149de..755229c53a 100644 --- a/common/src/main/resources/gtceu-common.mixins.json +++ b/common/src/main/resources/gtceu-common.mixins.json @@ -37,7 +37,8 @@ "WorldLoaderPackConfigMixin", "create.RotationPropagatorMixin", "kjs.RecipeEventJSMixin", - "top.ConfigMixin" + "top.ConfigMixin", + "rhino.InterpreterMixin" ], "injectors": { "defaultRequire": 1,