diff --git a/src/main/java/com/cleanroommc/fugue/mixin/extrautils2/XUBlockStatic$3Mixin.java b/src/main/java/com/cleanroommc/fugue/mixin/extrautils2/XUBlockStatic$3Mixin.java new file mode 100644 index 0000000..c7752aa --- /dev/null +++ b/src/main/java/com/cleanroommc/fugue/mixin/extrautils2/XUBlockStatic$3Mixin.java @@ -0,0 +1,61 @@ +package com.cleanroommc.fugue.mixin.extrautils2; + +import com.rwtema.extrautils2.backend.XUBlock; +import com.rwtema.extrautils2.backend.XUBlockStatic; +import com.rwtema.extrautils2.backend.model.MutableModel; +import com.rwtema.extrautils2.backend.model.PassthruModelBlock; +import com.rwtema.extrautils2.backend.model.Transforms; +import net.minecraft.block.state.IBlockState; +import net.minecraft.client.renderer.block.model.BakedQuad; +import net.minecraft.client.renderer.block.model.ModelResourceLocation; +import net.minecraft.util.BlockRenderLayer; +import net.minecraft.util.EnumFacing; +import net.minecraftforge.client.MinecraftForgeClient; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; +import org.spongepowered.asm.mixin.*; + +import javax.annotation.Nonnull; +import java.util.HashMap; +import java.util.List; + +/** + * @author ZZZank + */ +@Mixin(targets = "com.rwtema.extrautils2.backend.XUBlockStatic$3", remap = false) +public abstract class XUBlockStatic$3Mixin extends PassthruModelBlock { + @Shadow + @Final + XUBlockStatic this$0; + + @Shadow + HashMap>>> cachedLists; + + @Unique + private final Object fugue$lock = new Object(); + + private XUBlockStatic$3Mixin(XUBlock block, IBlockState key, ModelResourceLocation modelResourceLocation) { + super(block, key, modelResourceLocation); + } + + /** + * @author ZZZank + * @reason original implementation forces the usage of {@link HashMap}, which is NOT concurrency-safe + */ + @Overwrite + @Nonnull + @SideOnly(Side.CLIENT) + @Override + public List getQuads(IBlockState state, EnumFacing side, long rand) { + synchronized (fugue$lock) { + return cachedLists + .computeIfAbsent(state, XUBlockStatic::dummyCreateHash) + .computeIfAbsent(side, XUBlockStatic::dummyCreateHash) + .computeIfAbsent(MinecraftForgeClient.getRenderLayer(), (layer) -> { + MutableModel model = new MutableModel(Transforms.blockTransforms); + this$0.cachedModels.get(state).loadIntoMutable(model, layer); + return model.getQuads(state, side, rand); + }); + } + } +} diff --git a/src/main/java/com/cleanroommc/fugue/mixin/extrautils2/XUBlockStaticMixin.java b/src/main/java/com/cleanroommc/fugue/mixin/extrautils2/XUBlockStaticMixin.java deleted file mode 100644 index ff7df17..0000000 --- a/src/main/java/com/cleanroommc/fugue/mixin/extrautils2/XUBlockStaticMixin.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.cleanroommc.fugue.mixin.extrautils2; - - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -import java.util.HashMap; -import java.util.function.Function; - -@Mixin(targets = "com.rwtema.extrautils2.backend.XUBlockStatic$3", remap = false) -public class XUBlockStaticMixin { - @Redirect(method = "getQuads", at = @At(value = "INVOKE", target = "Ljava/util/HashMap;computeIfAbsent(Ljava/lang/Object;Ljava/util/function/Function;)Ljava/lang/Object;")) - private Object hackCIA(HashMap instance, Object n, Function k) { - if (instance.containsKey(n)) { - return instance.get(n); - } else { - Object v = k.apply(n); - instance.put(n, v); - return v; - } - } - -} diff --git a/src/main/resources/fugue.mixin.mod.json b/src/main/resources/fugue.mixin.mod.json index 0eb2101..af760d5 100644 --- a/src/main/resources/fugue.mixin.mod.json +++ b/src/main/resources/fugue.mixin.mod.json @@ -16,7 +16,6 @@ "extrautils2.FieldSetterMixin", "extrautils2.TileIndexerMixin", "extrautils2.TransferNodeEnergyMixin", - "extrautils2.XUBlockStaticMixin", "gregtech.GTRecipeInputCacheMixin", "hammercore.ReflectionUtilMixin", "howlingmoon.WerewolfCapabilityMixin", @@ -35,6 +34,7 @@ ], "client": [ "custommainmenu.SlideshowMixin", + "extrautils2.XUBlockStatic$3Mixin", "jei.RecipesGuiMixin", "mcjty.AbstractContainerWidgetMixin", "mcjty.SliderMixin"