Added model data refresh mixin

This commit is contained in:
reidbhuntley 2021-05-18 21:52:35 -04:00
parent 6c3bec250f
commit e916b06862
2 changed files with 39 additions and 1 deletions

View file

@ -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();
}
}
}

View file

@ -18,7 +18,8 @@
"StoreProjectionMatrixMixin",
"TileRemoveMixin",
"TileWorldHookMixin",
"WindowResizeMixin"
"WindowResizeMixin",
"ModelDataRefreshMixin"
],
"injectors": {
"defaultRequire": 1