diff options
-rw-r--r-- | src/main/java/dulkirmod/mixins/ItemRendererMixin.java | 9 | ||||
-rw-r--r-- | src/main/kotlin/dulkirmod/DulkirMod.kt | 4 | ||||
-rw-r--r-- | src/main/kotlin/dulkirmod/config/Config.kt | 16 | ||||
-rw-r--r-- | src/main/kotlin/dulkirmod/features/ItemAnimations.kt | 41 |
4 files changed, 62 insertions, 8 deletions
diff --git a/src/main/java/dulkirmod/mixins/ItemRendererMixin.java b/src/main/java/dulkirmod/mixins/ItemRendererMixin.java index 54b4d45..18fd72a 100644 --- a/src/main/java/dulkirmod/mixins/ItemRendererMixin.java +++ b/src/main/java/dulkirmod/mixins/ItemRendererMixin.java @@ -3,7 +3,11 @@ package dulkirmod.mixins; import dulkirmod.features.ItemAnimations; import net.minecraft.client.entity.AbstractClientPlayer; import net.minecraft.client.renderer.ItemRenderer; +import net.minecraft.client.renderer.entity.RenderItem; +import net.minecraft.item.ItemStack; +import org.spongepowered.asm.mixin.Final; 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; @@ -11,6 +15,10 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(value = {ItemRenderer.class}) public class ItemRendererMixin { + @Shadow @Final private RenderItem itemRenderer; + + @Shadow private ItemStack itemToRender; + @Inject(method = {"transformFirstPersonItem(FF)V"}, at = @At("HEAD"), cancellable = true) public void itemTransform(float equipProgress, float swingProgress, CallbackInfo ci) { if (ItemAnimations.INSTANCE.itemTransforHook(equipProgress, swingProgress)) ci.cancel(); @@ -24,5 +32,6 @@ public class ItemRendererMixin { @Inject(method ={"performDrinking"}, at = @At("HEAD"), cancellable = true) public void drinkTransform(AbstractClientPlayer clientPlayer, float partialTicks, CallbackInfo ci) { if (ItemAnimations.INSTANCE.rotationlessDrink(clientPlayer, partialTicks)) ci.cancel(); + if (ItemAnimations.INSTANCE.scaledDrinking(clientPlayer, partialTicks, itemToRender)) ci.cancel(); } } diff --git a/src/main/kotlin/dulkirmod/DulkirMod.kt b/src/main/kotlin/dulkirmod/DulkirMod.kt index 4817b20..c6e765b 100644 --- a/src/main/kotlin/dulkirmod/DulkirMod.kt +++ b/src/main/kotlin/dulkirmod/DulkirMod.kt @@ -83,8 +83,8 @@ class DulkirMod { companion object { const val MOD_ID = "dulkirmod" const val MOD_NAME = "Dulkir Mod" - const val MOD_VERSION = "1.0.2" - const val CHAT_PREFIX = "§b§l<§fDulkirMod§b§l>§r" + const val MOD_VERSION = "1.0.3" + const val CHAT_PREFIX = "<DulkirMod>" val mc: Minecraft = Minecraft.getMinecraft() var config = Config diff --git a/src/main/kotlin/dulkirmod/config/Config.kt b/src/main/kotlin/dulkirmod/config/Config.kt index 71f7fe0..a409d91 100644 --- a/src/main/kotlin/dulkirmod/config/Config.kt +++ b/src/main/kotlin/dulkirmod/config/Config.kt @@ -176,12 +176,13 @@ object Config : Vigilant(File("./config/dulkirmod/config.toml"), "DulkirMod") { var ignoreHaste = true @Property( - type = PropertyType.CHECKBOX, - name = "Rotationless Drink", - description = "Stops you from breaking your arm every time you get thirsty", - category = "Animations" + type = PropertyType.SELECTOR, + name = "Drinking Fix", + description = "Pick how to handle drinking animations.", + category = "Animations", + options = ["No fix", "Rotationless", "Fixed"] ) - var rotationlessdrink = true + var drinkingSelector = 2 @Property( type = PropertyType.BUTTON, @@ -206,6 +207,11 @@ object Config : Vigilant(File("./config/dulkirmod/config.toml"), "DulkirMod") { fun init() { initialize() addDependency("customMessage", "throttleNotifier") + + setCategoryDescription( + "Custom Animations", + "All settings that are related to custom animations. Mostly help from Aton." + ) } } diff --git a/src/main/kotlin/dulkirmod/features/ItemAnimations.kt b/src/main/kotlin/dulkirmod/features/ItemAnimations.kt index f143289..a86e947 100644 --- a/src/main/kotlin/dulkirmod/features/ItemAnimations.kt +++ b/src/main/kotlin/dulkirmod/features/ItemAnimations.kt @@ -4,6 +4,7 @@ import dulkirmod.DulkirMod.Companion.config import dulkirmod.DulkirMod.Companion.mc import net.minecraft.client.entity.AbstractClientPlayer import net.minecraft.client.renderer.GlStateManager +import net.minecraft.item.ItemStack import net.minecraft.util.MathHelper import kotlin.math.exp import kotlin.math.pow @@ -61,8 +62,12 @@ object ItemAnimations { return true } + /** + * Directly referenced by the ItemRendereMixin. If enabled will scale the potion drink animation. + * Returns whether custom animation was performed. + */ fun rotationlessDrink(clientPlayer : AbstractClientPlayer, partialTicks : Float): Boolean { - if (!config.rotationlessdrink) return false + if (!config.customAnimations || config.drinkingSelector != 1) return false val f: Float = clientPlayer.itemInUseCount.toFloat() - partialTicks + 1.0f val f1: Float = f / mc.thePlayer.heldItem.maxItemUseDuration.toFloat() var f2 = MathHelper.abs(MathHelper.cos(f / 4.0f * 3.1415927f) * 0.1f) @@ -72,4 +77,38 @@ object ItemAnimations { GlStateManager.translate(0.0f, f2, 0.0f) return true } + + /** + * Directly referenced by the ItemRendereMixin. If enabled will scale the potion drink animation. + * Returns whether custom animation was performed. + */ + fun scaledDrinking(clientPlayer: AbstractClientPlayer, partialTicks: Float, itemToRender: ItemStack): Boolean { + if (!config.customAnimations || config.drinkingSelector != 2) return false + val f: Float = clientPlayer.itemInUseCount.toFloat() - partialTicks + 1.0f + val f1: Float = f / itemToRender.maxItemUseDuration.toFloat() + var f2 = MathHelper.abs(MathHelper.cos(f / 4.0f * Math.PI.toFloat()) * 0.1f) + + if (f1 >= 0.8f) { + f2 = 0.0f + } + + // Transform to correct rotation center + val newX = (0.56f * (1 + config.customX)).toFloat() + val newY = (-0.52f * (1 - config.customY)).toFloat() + val newZ = (-0.71999997f * (1 + config.customZ)).toFloat() + GlStateManager.translate(-0.56f, 0.52f, 0.71999997f) + GlStateManager.translate(newX, newY, newZ) + + GlStateManager.translate(0.0f, f2, 0.0f) + val f3 = 1.0f - f1.toDouble().pow(27.0).toFloat() + GlStateManager.translate(f3 * 0.6f, f3 * -0.5f, f3 * 0.0f) + GlStateManager.rotate(f3 * 90.0f, 0.0f, 1.0f, 0.0f) + GlStateManager.rotate(f3 * 10.0f, 1.0f, 0.0f, 0.0f) + GlStateManager.rotate(f3 * 30.0f, 0.0f, 0.0f, 1.0f) + + // Transform back + GlStateManager.translate(0.56f, -0.52f, -0.71999997f) + GlStateManager.translate(-newX, -newY, -newZ) + return true + } }
\ No newline at end of file |