From e916b06862e8e0df1ad1b28da91feb034f1e7843 Mon Sep 17 00:00:00 2001 From: reidbhuntley Date: Tue, 18 May 2021 21:52:35 -0400 Subject: [PATCH] Added model data refresh mixin --- .../mixin/ModelDataRefreshMixin.java | 37 +++++++++++++++++++ src/main/resources/create.mixins.json | 3 +- 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/simibubi/create/foundation/mixin/ModelDataRefreshMixin.java diff --git a/src/main/java/com/simibubi/create/foundation/mixin/ModelDataRefreshMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/ModelDataRefreshMixin.java new file mode 100644 index 000000000..151a0a7c6 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/mixin/ModelDataRefreshMixin.java @@ -0,0 +1,37 @@ +package com.simibubi.create.foundation.mixin; + +import com.simibubi.create.content.schematics.SchematicWorld; + +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import net.minecraftforge.client.model.ModelDataManager; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.minecraft.client.Minecraft; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; + +@OnlyIn(Dist.CLIENT) +@Mixin(ModelDataManager.class) +public class ModelDataRefreshMixin { + + /** + * Normally ModelDataManager will throw an exception if a tile entity tries + * to refresh its model data from a world the client isn't currently in, + * but we need that to not happen for tile entities in fake schematic + * worlds, so in those cases just do nothing instead. + */ + @Inject(at = @At("HEAD"), method = "requestModelDataRefresh", cancellable = true, remap = false) + private static void requestModelDataRefresh(TileEntity te, CallbackInfo ci) { + if (te != null) { + World world = te.getWorld(); + if (world != Minecraft.getInstance().world && world instanceof SchematicWorld) + ci.cancel(); + } + } + +} diff --git a/src/main/resources/create.mixins.json b/src/main/resources/create.mixins.json index 0938f8534..fbd4a5c91 100644 --- a/src/main/resources/create.mixins.json +++ b/src/main/resources/create.mixins.json @@ -18,7 +18,8 @@ "StoreProjectionMatrixMixin", "TileRemoveMixin", "TileWorldHookMixin", - "WindowResizeMixin" + "WindowResizeMixin", + "ModelDataRefreshMixin" ], "injectors": { "defaultRequire": 1