Skip to content

Commit

Permalink
More adjustments to drinking animations
Browse files Browse the repository at this point in the history
  • Loading branch information
inglettronald committed Sep 26, 2022
1 parent b8bcc4a commit e60fbdd
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 8 deletions.
9 changes: 9 additions & 0 deletions src/main/java/dulkirmod/mixins/ItemRendererMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,22 @@
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;

@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();
Expand All @@ -24,5 +32,6 @@ public void useTransform(float swingProgress, CallbackInfo ci){
@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();
}
}
4 changes: 2 additions & 2 deletions src/main/kotlin/dulkirmod/DulkirMod.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 11 additions & 5 deletions src/main/kotlin/dulkirmod/config/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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."
)
}

}
41 changes: 40 additions & 1 deletion src/main/kotlin/dulkirmod/features/ItemAnimations.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
}
}

0 comments on commit e60fbdd

Please sign in to comment.