Added a mixin for custom model data synchronisation

This commit is contained in:
Goodbird committed 2024-01-24 22:55:45 +03:00
1 parent 7c9ee59c1d
commit 24484701ad
1 file changed
+32
@@ -0,0 +1,32 @@
package com.goodbird.cnpcgeckoaddon.mixin.impl;
import com.goodbird.cnpcgeckoaddon.entity.EntityCustomModel;
import com.goodbird.cnpcgeckoaddon.mixin.IDataDisplay;
import com.goodbird.cnpcgeckoaddon.utils.NpcTextureUtils;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.ResourceLocation;
import noppes.npcs.client.EntityUtil;
import noppes.npcs.entity.EntityNPCInterface;
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;
@Mixin(EntityUtil.class)
public class MixinEntityUtil {
@Inject(method = "Copy", at = @At("TAIL"), remap = false)
private static void copy(EntityLivingBase copied, EntityLivingBase entity, CallbackInfo ci) {
if (entity instanceof EntityCustomModel modelEntity && copied instanceof EntityNPCInterface npc) {
IDataDisplay display = (IDataDisplay) npc.display;
modelEntity.textureResLoc = NpcTextureUtils.getNpcTexture((EntityNPCInterface) copied);
modelEntity.modelResLoc = new ResourceLocation(display.getCustomModelData().getModel());
modelEntity.animResLoc = new ResourceLocation(display.getCustomModelData().getAnimFile());
modelEntity.idleAnim = display.getCustomModelData().getIdleAnim();
modelEntity.walkAnim = display.getCustomModelData().getWalkAnim();
modelEntity.attackAnim = display.getCustomModelData().getAttackAnim();
modelEntity.hurtAnim = display.getCustomModelData().getHurtAnim();
modelEntity.leftHeldItem = npc.inventory.getOffHand();
}
}
}