diff --git a/src/main/java/de/teamlapen/vampirism/client/model/armor/CloakModel.java b/src/main/java/de/teamlapen/vampirism/client/model/armor/CloakModel.java index 0960c2308f..63f6dee29e 100644 --- a/src/main/java/de/teamlapen/vampirism/client/model/armor/CloakModel.java +++ b/src/main/java/de/teamlapen/vampirism/client/model/armor/CloakModel.java @@ -2,6 +2,7 @@ import com.google.common.collect.ImmutableList; import de.teamlapen.vampirism.client.core.ModEntitiesRender; +import de.teamlapen.vampirism.util.MixinHooks; import net.minecraft.client.Minecraft; import net.minecraft.client.model.HumanoidModel; import net.minecraft.client.model.geom.ModelPart; @@ -10,10 +11,14 @@ import net.minecraft.client.model.geom.builders.LayerDefinition; import net.minecraft.client.model.geom.builders.MeshDefinition; import net.minecraft.client.model.geom.builders.PartDefinition; +import net.minecraft.util.Mth; +import net.minecraft.world.entity.LivingEntity; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import org.jetbrains.annotations.NotNull; +import static net.minecraft.client.renderer.entity.LivingEntityRenderer.isEntityUpsideDown; + @OnlyIn(Dist.CLIENT) public class CloakModel extends VampirismArmorModel { @@ -29,11 +34,12 @@ public class CloakModel extends VampirismArmorModel { private static CloakModel cloakItemModel; - public static CloakModel getAdjustedCloak(HumanoidModel wearerModel) { + public static CloakModel getAdjustedCloak(HumanoidModel wearerModel, LivingEntity entity) { if (cloakItemModel == null) { cloakItemModel = new CloakModel(Minecraft.getInstance().getEntityModels().bakeLayer(ModEntitiesRender.CLOAK)); } cloakItemModel.copyFromHumanoid(wearerModel); + cloakItemModel.setupAnimation(entity); return cloakItemModel; } @@ -74,47 +80,91 @@ public CloakModel(@NotNull ModelPart part) { shoulderright = part.getChild(SHOULDER_RIGHT); } -// @Override -// public void setupAnim(@NotNull LivingEntity entity, float f, float f1, float ageInTicks, float netHeadYaw, float headPitch) { -// super.setupAnim(entity, f, f1, ageInTicks, netHeadYaw, headPitch); -// //Isn't use afaik -// -// -// boolean flag = entity != null && entity.getFallFlyingTicks() > 4; -// -// float f6 = 1.0F; -// if (flag) { -// f6 = (float) (entity.getDeltaMovement().x * entity.getDeltaMovement().x + entity.getDeltaMovement().y * entity.getDeltaMovement().y -// + entity.getDeltaMovement().z * entity.getDeltaMovement().z); -// f6 = f6 / 0.2F; -// f6 = f6 * f6 * f6; -// } -// -// if (f6 < 1.0F) { -// f6 = 1.0F; -// } -// -// float rotation = Mth.cos(f * 0.6662F) * 1.4F * f1 / f6; -// if (rotation < 0.0F) -// rotation *= -1; -// this.cloakback.xRot = 0.0872665F + (rotation / 3); -// this.leftlong.xRot = 0.0872665F + (rotation / 3); -// this.rightlong.xRot = 0.0872665F + (rotation / 3); -// this.leftmedium.xRot = 0.0872665F + (rotation / 3); -// this.rightmedium.xRot = 0.0872665F + (rotation / 3); -// this.rightshort.xRot = 0.0872665F + (rotation / 3); -// this.leftshort.xRot = 0.0872665F + (rotation / 3); -// -// if (this.crouching) { -// this.cloakback.xRot += 0.5F; -// this.leftlong.xRot += 0.5F; -// this.rightlong.xRot += 0.5F; -// this.leftmedium.xRot += 0.5F; -// this.rightmedium.xRot += 0.5F; -// this.leftshort.xRot += 0.5F; -// this.rightshort.xRot += 0.5F; -// } -// } + private void setupAnimation(LivingEntity entity) { + boolean shouldSit = entity.isPassenger() && (entity.getVehicle() != null && entity.getVehicle().shouldRiderSit()); + + float f = Mth.rotLerp(MixinHooks.armorLayerPartialTicks, entity.yBodyRotO, entity.yBodyRot); + float f1 = Mth.rotLerp(MixinHooks.armorLayerPartialTicks, entity.yHeadRotO, entity.yHeadRot); + float f2 = f1 - f; + + float f6 = Mth.lerp(MixinHooks.armorLayerPartialTicks, entity.xRotO, entity.getXRot()); + + if (shouldSit && entity.getVehicle() instanceof LivingEntity livingentity) { + f = Mth.rotLerp(MixinHooks.armorLayerPartialTicks, livingentity.yBodyRotO, livingentity.yBodyRot); + f2 = f1 - f; + float f3 = Mth.wrapDegrees(f2); + if (f3 < -85.0F) { + f3 = -85.0F; + } + + if (f3 >= 85.0F) { + f3 = 85.0F; + } + + f = f1 - f3; + if (f3 * f3 > 2500.0F) { + f += f3 * 0.2F; + } + + f2 = f1 - f; + } + + if (isEntityUpsideDown(entity)) { + f6 *= -1.0F; + f2 *= -1.0F; + } + + float f8 = 0.0F; + float f5 = 0.0F; + if (!shouldSit && entity.isAlive()) { + f8 = entity.walkAnimation.speed(MixinHooks.armorLayerPartialTicks); + f5 = entity.walkAnimation.position(MixinHooks.armorLayerPartialTicks); + if (entity.isBaby()) { + f5 *= 3.0F; + } + + if (f8 > 1.0F) { + f8 = 1.0F; + } + } + cloakItemModel.setupAnim(entity, f5, f8,entity.tickCount + MixinHooks.armorLayerPartialTicks, f2, f6); + } + + public void setupAnim(@NotNull LivingEntity entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) { + boolean flag = entity != null && entity.getFallFlyingTicks() > 4; + + float f6 = 1.0F; + if (flag) { + f6 = (float) (entity.getDeltaMovement().x * entity.getDeltaMovement().x + entity.getDeltaMovement().y * entity.getDeltaMovement().y + entity.getDeltaMovement().z * entity.getDeltaMovement().z); + f6 = f6 / 0.2F; + f6 = f6 * f6 * f6; + } + + if (f6 < 1.0F) { + f6 = 1.0F; + } + + float rotation = Mth.cos(limbSwing * 0.6662F) * 1.4F * (limbSwingAmount / 1.8f) / f6; + if (rotation < 0.0F) + rotation *= -1; + this.cloakback.xRot = 0.0872665F + (rotation / 3); + this.leftlong.xRot = 0.0872665F + (rotation / 3); + this.rightlong.xRot = 0.0872665F + (rotation / 3); + this.leftmedium.xRot = 0.0872665F + (rotation / 3); + this.rightmedium.xRot = 0.0872665F + (rotation / 3); + this.rightshort.xRot = 0.0872665F + (rotation / 3); + this.leftshort.xRot = 0.0872665F + (rotation / 3); + + if (entity.isCrouching()) { + this.cloakback.xRot += 0.5F; + this.leftlong.xRot += 0.5F; + this.rightlong.xRot += 0.5F; + this.leftmedium.xRot += 0.5F; + this.rightmedium.xRot += 0.5F; + this.leftshort.xRot += 0.5F; + this.rightshort.xRot += 0.5F; + } + } @Override protected @NotNull Iterable getBodyModels() { diff --git a/src/main/java/de/teamlapen/vampirism/items/ColoredVampireClothingItem.java b/src/main/java/de/teamlapen/vampirism/items/ColoredVampireClothingItem.java index f6907ac603..b469178d0d 100644 --- a/src/main/java/de/teamlapen/vampirism/items/ColoredVampireClothingItem.java +++ b/src/main/java/de/teamlapen/vampirism/items/ColoredVampireClothingItem.java @@ -34,12 +34,8 @@ public ColoredVampireClothingItem(@NotNull ArmorItem.Type type, EnumModel model, @Override public void initializeClient(@NotNull Consumer consumer) { consumer.accept(new IClientItemExtensions() { - @SuppressWarnings({"UnnecessaryDefault", "DuplicateBranchesInSwitch", "SwitchStatementWithTooFewBranches"}) public @NotNull Model getGenericArmorModel(LivingEntity livingEntity, ItemStack itemStack, EquipmentSlot equipmentSlot, HumanoidModel original) { - return switch (model) { - case CLOAK -> CloakModel.getAdjustedCloak(original); - default -> CloakModel.getAdjustedCloak(original); - }; + return CloakModel.getAdjustedCloak(original, livingEntity); } } ); diff --git a/src/main/java/de/teamlapen/vampirism/mixin/client/HumanoidArmorLayerMixin.java b/src/main/java/de/teamlapen/vampirism/mixin/client/HumanoidArmorLayerMixin.java new file mode 100644 index 0000000000..34be3e3010 --- /dev/null +++ b/src/main/java/de/teamlapen/vampirism/mixin/client/HumanoidArmorLayerMixin.java @@ -0,0 +1,28 @@ +package de.teamlapen.vampirism.mixin.client; + +import com.mojang.blaze3d.vertex.PoseStack; +import de.teamlapen.vampirism.util.MixinHooks; +import net.minecraft.client.model.HumanoidModel; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.entity.RenderLayerParent; +import net.minecraft.client.renderer.entity.layers.HumanoidArmorLayer; +import net.minecraft.client.renderer.entity.layers.RenderLayer; +import net.minecraft.world.entity.LivingEntity; +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(HumanoidArmorLayer.class) +public abstract class HumanoidArmorLayerMixin, A extends HumanoidModel> extends RenderLayer { + + @Deprecated + private HumanoidArmorLayerMixin(RenderLayerParent pRenderer) { + super(pRenderer); + } + + @Inject(method = "render(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;ILnet/minecraft/world/entity/LivingEntity;FFFFFF)V", at = @At("HEAD")) + public void render(PoseStack pMatrixStack, MultiBufferSource pBuffer, int pPackedLight, T pLivingEntity, float pLimbSwing, float pLimbSwingAmount, float pPartialTicks, float pAgeInTicks, float pNetHeadYaw, float pHeadPitch, CallbackInfo ci) { + MixinHooks.armorLayerPartialTicks = pPartialTicks; + } +} diff --git a/src/main/java/de/teamlapen/vampirism/util/MixinHooks.java b/src/main/java/de/teamlapen/vampirism/util/MixinHooks.java index 9ebac123d2..8215036c6d 100644 --- a/src/main/java/de/teamlapen/vampirism/util/MixinHooks.java +++ b/src/main/java/de/teamlapen/vampirism/util/MixinHooks.java @@ -28,6 +28,8 @@ public class MixinHooks { */ public static boolean enforcingGlowing_bloodVision = false; + public static float armorLayerPartialTicks; + public static void addSingleInstanceStructure(@NotNull List structures) { onlyOneStructure.addAll(structures.stream().map(MixinHooks::singleJigsawString).toList()); } diff --git a/src/main/resources/vampirism.mixins.json b/src/main/resources/vampirism.mixins.json index d255a4e60a..1e7229c388 100644 --- a/src/main/resources/vampirism.mixins.json +++ b/src/main/resources/vampirism.mixins.json @@ -43,6 +43,7 @@ "client": [ "client.AgeableModelAccessor", "client.BossOverlayGuiAccessor", + "client.HumanoidArmorLayerMixin", "client.LevelRendererMixin", "client.LivingEntityRendererAccessor", "client.ResourceLoadStateTrackerMixin",