From 053db047a053cfa4b510d872802434a922275326 Mon Sep 17 00:00:00 2001 From: inglettronald Date: Tue, 18 Jul 2023 12:27:13 -0500 Subject: More Entity/Animation fixes --- .../mixin/render/HeldItemRendererMixin.java | 21 +++++++++++- .../mixin/render/LivingEntityMixin.java | 38 +++++++++++++++++++--- .../mixin/render/WorldRendererMixin.java | 2 ++ .../kotlin/com/dulkirfabric/config/DulkirConfig.kt | 6 ++++ .../kotlin/com/dulkirfabric/features/RenderTest.kt | 6 ++-- .../dulkirfabric/util/GlowingEntityInterface.kt | 2 +- 6 files changed, 64 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/main/java/com/dulkirfabric/mixin/render/HeldItemRendererMixin.java b/src/main/java/com/dulkirfabric/mixin/render/HeldItemRendererMixin.java index 664af0d..f0e6422 100644 --- a/src/main/java/com/dulkirfabric/mixin/render/HeldItemRendererMixin.java +++ b/src/main/java/com/dulkirfabric/mixin/render/HeldItemRendererMixin.java @@ -1,6 +1,8 @@ package com.dulkirfabric.mixin.render; import com.dulkirfabric.config.DulkirConfig; +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; +import com.llamalad7.mixinextras.injector.ModifyReturnValue; import net.minecraft.client.network.AbstractClientPlayerEntity; import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.render.item.HeldItemRenderer; @@ -9,6 +11,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.Hand; import net.minecraft.util.math.RotationAxis; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @@ -16,7 +19,13 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; // SOURCE FOR A LOT OF THIS: https://github.com/cosrnic/smallviewmodel/blob/main/src/main/java/uk/cosrnic/smallviewmodel/mixin/MixinHeldItemRenderer.java @Mixin(HeldItemRenderer.class) -public class HeldItemRendererMixin { +public abstract class HeldItemRendererMixin { + @Shadow public abstract void resetEquipProgress(Hand hand); + + @Shadow private float equipProgressMainHand; + + @Shadow private float equipProgressOffHand; + @Inject(method = "renderFirstPersonItem(Lnet/minecraft/client/network/AbstractClientPlayerEntity;FFLnet/minecraft/util/Hand;FLnet/minecraft/item/ItemStack;FLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/item/HeldItemRenderer;renderItem(Lnet/minecraft/entity/LivingEntity;Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/render/model/json/ModelTransformationMode;ZLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V")) public void onRenderHeldItem(AbstractClientPlayerEntity player, float tickDelta, float pitch, Hand hand, float swingProgress, ItemStack item, float equipProgress, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo ci) { @@ -38,4 +47,14 @@ public class HeldItemRendererMixin { matrices.translate(posX, posY, posZ); } } + + /** + * Stop the weird mid-swing bobbing animation from happening + * @param original + * @return 1f if enabled, else original + */ + @ModifyExpressionValue(method = "updateHeldItems", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;getAttackCooldownProgress(F)F")) + public float attackCooldown(float original) { + return 1f; + } } diff --git a/src/main/java/com/dulkirfabric/mixin/render/LivingEntityMixin.java b/src/main/java/com/dulkirfabric/mixin/render/LivingEntityMixin.java index badac4c..c0f9a03 100644 --- a/src/main/java/com/dulkirfabric/mixin/render/LivingEntityMixin.java +++ b/src/main/java/com/dulkirfabric/mixin/render/LivingEntityMixin.java @@ -1,20 +1,31 @@ package com.dulkirfabric.mixin.render; +import com.dulkirfabric.config.DulkirConfig; import com.dulkirfabric.util.GlowingEntityInterface; +import net.minecraft.client.MinecraftClient; import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.text.Text; +import net.minecraft.util.Hand; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import java.awt.*; @Mixin(LivingEntity.class) public class LivingEntityMixin implements GlowingEntityInterface { + @Shadow + public float handSwingProgress; + @Unique + private int animationTicks; + @Unique private boolean shouldGlow_DulkirMod; @Unique @@ -45,8 +56,25 @@ public class LivingEntityMixin implements GlowingEntityInterface { return shouldESP_DulkirMod; } - @Inject(method = "getHandSwingDuration()I", at = @At("HEAD"), cancellable = true) - public void getHandSwingDuration(CallbackInfoReturnable cir) { - cir.setReturnValue(50); + @Inject(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;tickNewAi()V", + shift = At.Shift.AFTER)) + public void onWhatever(CallbackInfo ci) { + if (DulkirConfig.ConfigVars.getConfigOptions().getHandSwingDuration() == 6) return; + if (animationTicks > DulkirConfig.ConfigVars.getConfigOptions().getHandSwingDuration()) { + animationTicks = 0; + } + if (animationTicks == 0) { + handSwingProgress = 1F; + } else { + handSwingProgress = (animationTicks - 1F) / DulkirConfig.ConfigVars.getConfigOptions().getHandSwingDuration(); + animationTicks++; + } + } + + @Inject(method = "swingHand(Lnet/minecraft/util/Hand;Z)V", at = @At("HEAD")) + public void onSwing(Hand hand, boolean fromServerPlayer, CallbackInfo ci) { + if (animationTicks == 0) { + animationTicks = 1; + } } -} +} \ No newline at end of file diff --git a/src/main/java/com/dulkirfabric/mixin/render/WorldRendererMixin.java b/src/main/java/com/dulkirfabric/mixin/render/WorldRendererMixin.java index db235df..03ffbd0 100644 --- a/src/main/java/com/dulkirfabric/mixin/render/WorldRendererMixin.java +++ b/src/main/java/com/dulkirfabric/mixin/render/WorldRendererMixin.java @@ -69,6 +69,7 @@ public class WorldRendererMixin { @Inject(method = "render(Lnet/minecraft/client/util/math/MatrixStack;FJZLnet/minecraft/client/render/Camera;Lnet/minecraft/client/render/GameRenderer;Lnet/minecraft/client/render/LightmapTextureManager;Lorg/joml/Matrix4f;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/entity/EntityRenderDispatcher;shouldRender(Lnet/minecraft/entity/Entity;Lnet/minecraft/client/render/Frustum;DDD)Z")) public void setOutlineESP(MatrixStack matrices, float tickDelta, long limitTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightmapTextureManager lightmapTextureManager, Matrix4f positionMatrix, CallbackInfo ci, @Local Entity entity) { + this.bufferBuilders.getEntityVertexConsumers().drawCurrentLayer(); if (entity instanceof GlowingEntityInterface dEntity && dEntity.shouldDulkirEntityGlow() && !dEntity.shouldDulkirEntityESP()) { if (this.entityOutlinesFramebuffer != null) this.entityOutlinesFramebuffer.copyDepthFrom(mc.getFramebuffer()); @@ -77,5 +78,6 @@ public class WorldRendererMixin { if (this.entityOutlinesFramebuffer != null) this.entityOutlinesFramebuffer.copyDepthFrom(defaultEntityOutlineBuffer); } + this.client.getFramebuffer().beginWrite(false); } } diff --git a/src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt b/src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt index b612156..0b04c0f 100644 --- a/src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt +++ b/src/main/kotlin/com/dulkirfabric/config/DulkirConfig.kt @@ -189,6 +189,11 @@ class DulkirConfig { } .build() ) + animations.addEntry( + entryBuilder.startIntSlider(Text.literal("rotationZ"), configOptions.handSwingDuration, 2, 15) + .setSaveConsumer { newValue -> configOptions.handSwingDuration = newValue } + .build() + ) builder.transparentBackground() @@ -222,6 +227,7 @@ class DulkirConfig { var heldItemScale: Float = 0f, var duraCooldown: Boolean = false, var alarmTimeout: Int = 300, + var handSwingDuration: Int = 6 ) @Serializable diff --git a/src/main/kotlin/com/dulkirfabric/features/RenderTest.kt b/src/main/kotlin/com/dulkirfabric/features/RenderTest.kt index 7b6c5e6..8d941d1 100644 --- a/src/main/kotlin/com/dulkirfabric/features/RenderTest.kt +++ b/src/main/kotlin/com/dulkirfabric/features/RenderTest.kt @@ -2,14 +2,12 @@ package com.dulkirfabric.features import com.dulkirfabric.events.EntityLoadEvent import com.dulkirfabric.events.WorldRenderLastEvent -import com.dulkirfabric.util.GlowingEntityInterface import com.dulkirfabric.util.WorldRenderUtils import meteordevelopment.orbit.EventHandler import net.minecraft.text.Style import net.minecraft.text.Text import net.minecraft.util.math.Vec3d import java.awt.Color -import kotlin.random.Random object RenderTest { @@ -28,7 +26,7 @@ object RenderTest { @EventHandler fun onLoadEnt(event: EntityLoadEvent) { - if (event.entity !is GlowingEntityInterface) return - event.entity.setDulkirEntityGlow(true, Color(255, 255, 255, 255), Random(event.entity.id).nextBoolean()) +// if (event.entity !is GlowingEntityInterface) return +// event.entity.setDulkirEntityGlow(true, Color(255, 255, 255, 255),false) } } \ No newline at end of file diff --git a/src/main/kotlin/com/dulkirfabric/util/GlowingEntityInterface.kt b/src/main/kotlin/com/dulkirfabric/util/GlowingEntityInterface.kt index 5a76890..9b129fd 100644 --- a/src/main/kotlin/com/dulkirfabric/util/GlowingEntityInterface.kt +++ b/src/main/kotlin/com/dulkirfabric/util/GlowingEntityInterface.kt @@ -3,7 +3,7 @@ package com.dulkirfabric.util import java.awt.Color interface GlowingEntityInterface { - fun setDulkirEntityGlow(shouldGlow: Boolean, glowColor: Color, shouldESP: Boolean = false) + fun setDulkirEntityGlow(shouldGlow: Boolean = false, glowColor: Color, shouldESP: Boolean = false) fun shouldDulkirEntityGlow() : Boolean -- cgit