Skip to content

Commit

Permalink
Add 2d items color (WIP ⚠️ ) and old skull position (1.8) + Remove ol…
Browse files Browse the repository at this point in the history
…d projectile position (also WIP)
  • Loading branch information
Mixces committed Dec 29, 2024
1 parent 7c5791f commit ac7c5eb
Show file tree
Hide file tree
Showing 8 changed files with 156 additions and 119 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.llamalad7.mixinextras.sugar.Local;
import me.mixces.animatium.config.AnimatiumConfig;
import me.mixces.animatium.util.EntityUtils;
import me.mixces.animatium.util.ItemUtils;
import me.mixces.animatium.util.MathUtils;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.Camera;
Expand All @@ -15,6 +16,7 @@
import net.minecraft.entity.ItemEntity;
import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ShieldItem;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

Expand All @@ -26,7 +28,7 @@ public abstract class MixinItemEntityRenderer {
Entity entity = EntityUtils.getEntityByState(itemEntityRenderState);
if (entity instanceof ItemEntity itemEntity) {
ItemStack itemStack = itemEntity.getStack();
if (!(itemStack.getItem() instanceof BlockItem) || !itemEntityRenderState.itemRenderState.hasDepth()) {
if (!ItemUtils.isBlock3d(itemStack, itemEntityRenderState.itemRenderState) && !(itemStack.getItem() instanceof ShieldItem)) {
Camera camera = MinecraftClient.getInstance().gameRenderer.getCamera();
return MathUtils.toRadians(180F - camera.getYaw());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.llamalad7.mixinextras.sugar.Local;
import com.mojang.blaze3d.platform.GlStateManager;
import me.mixces.animatium.config.AnimatiumConfig;
import me.mixces.animatium.util.ItemUtils;
import me.mixces.animatium.util.MathUtils;
import me.mixces.animatium.util.PlayerUtils;
import net.minecraft.block.Block;
import net.minecraft.block.SkullBlock;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.AbstractClientPlayerEntity;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.item.HeldItemRenderer;
import net.minecraft.client.render.item.ItemRenderState;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.item.*;
import net.minecraft.util.Arm;
Expand All @@ -23,6 +27,7 @@
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.ModifyArg;
import org.spongepowered.asm.mixin.injection.Slice;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

Expand Down Expand Up @@ -79,8 +84,8 @@ public abstract class MixinHeldItemRenderer {

@Inject(method = "renderFirstPersonItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/item/HeldItemRenderer;renderItem(Lnet/minecraft/entity/LivingEntity;Lnet/minecraft/item/ItemStack;Lnet/minecraft/item/ModelTransformationMode;ZLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V", ordinal = 1))
private void animatium$tiltItemPositions(AbstractClientPlayerEntity player, float tickDelta, float pitch, Hand hand, float swingProgress, ItemStack stack, float equipProgress, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo ci) {
if (AnimatiumConfig.getInstance().getTiltItemPositions() && !(stack.getItem() instanceof BlockItem) && !(stack.getItem() instanceof ShieldItem)) {
int direction = PlayerUtils.getHandMultiplier(player, hand);
int direction = PlayerUtils.getHandMultiplier(player, hand);
if (AnimatiumConfig.getInstance().getTiltItemPositions() && !ItemUtils.isBlock3d(stack, new ItemRenderState()) && !ItemUtils.isItemBlacklisted(stack)) {
float angle = MathUtils.toRadians(25);
if (ItemUtils.isFishingRodItem(stack)) {
matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(direction * 180.0F));
Expand All @@ -96,6 +101,16 @@ public abstract class MixinHeldItemRenderer {
matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(direction * 90.0F));
matrices.translate(direction * -1.13 * 0.0625F, -3.2 * 0.0625F, -1.13 * 0.0625F);
}

if (AnimatiumConfig.getInstance().getOldSkullPosition() && ItemUtils.isSkullBlock(stack)) {
matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(45.0F));
matrices.scale(0.4F, 0.4F, 0.4F);

// TODO: This is not quite right...
matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(-180.0F));
matrices.translate(0.0F, 0.25F, 0.0F);
matrices.scale(1.125F, 1.125F, 1.125F);
}
}

@Inject(method = "resetEquipProgress", at = @At("HEAD"), cancellable = true)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package me.mixces.animatium.mixins.renderer.item;

import me.mixces.animatium.config.AnimatiumConfig;
import me.mixces.animatium.util.ItemUtils;
import net.minecraft.client.render.VertexConsumer;
import net.minecraft.item.ModelTransformationMode;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArgs;
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;

@Mixin(VertexConsumer.class)
public interface MixinVertexConsumer {

// TODO: this is only half of the battle
@ModifyArgs(method = "quad(Lnet/minecraft/client/util/math/MatrixStack$Entry;Lnet/minecraft/client/render/model/BakedQuad;[FFFFF[IIZ)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/math/MatrixStack$Entry;transformNormal(FFFLorg/joml/Vector3f;)Lorg/joml/Vector3f;"))
default void animatium$item2DColors(Args args) {
if (AnimatiumConfig.getInstance().getItem2DColors()) {
ModelTransformationMode transformationMode = ItemUtils.getTransformMode();
if (transformationMode == ModelTransformationMode.GROUND || transformationMode == ModelTransformationMode.FIXED) {
args.set(1, (float) args.get(2));
args.set(2, (float) args.get(1));
}
}
}
}
36 changes: 24 additions & 12 deletions src/main/kotlin/me/mixces/animatium/config/AnimatiumConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,17 @@ class AnimatiumConfig {
.controller(TickBoxControllerBuilder::create)
.build()
)
otherGroup.option(
Option.createBuilder<Boolean>()
.name(Text.translatable("animatium.oldSkullPosition"))
.description(OptionDescription.of(Text.translatable("animatium.oldSkullPosition.description")))
.binding(
defaults.oldSkullPosition,
{ config.oldSkullPosition },
{ newVal -> config.oldSkullPosition = newVal })
.controller(TickBoxControllerBuilder::create)
.build()
)
otherGroup.option(
Option.createBuilder<Boolean>()
.name(Text.translatable("animatium.applyItemSwingUsage"))
Expand Down Expand Up @@ -736,6 +747,17 @@ class AnimatiumConfig {
.controller(TickBoxControllerBuilder::create)
.build()
)
otherGroup.option(
Option.createBuilder<Boolean>()
.name(Text.translatable("animatium.item2DColors"))
.description(OptionDescription.of(Text.translatable("animatium.item2DColors.description")))
.binding(
defaults.item2DColors,
{ config.item2DColors },
{ newVal -> config.item2DColors = newVal })
.controller(TickBoxControllerBuilder::create)
.build()
)
otherGroup.option(
Option.createBuilder<Boolean>()
.name(Text.translatable("animatium.oldDurabilityBarColors"))
Expand Down Expand Up @@ -842,17 +864,6 @@ class AnimatiumConfig {
.controller(TickBoxControllerBuilder::create)
.build()
)
category.option(
Option.createBuilder<Boolean>()
.name(Text.translatable("animatium.oldProjectilePosition"))
.description(OptionDescription.of(Text.translatable("animatium.oldProjectilePosition.description")))
.binding(
defaults.oldProjectilePosition,
{ config.oldProjectilePosition },
{ newVal -> config.oldProjectilePosition = newVal })
.controller(TickBoxControllerBuilder::create)
.build()
)
category.option(
Option.createBuilder<Boolean>()
.name(Text.translatable("animatium.disableProjectileAgeCheck"))
Expand Down Expand Up @@ -988,13 +999,15 @@ class AnimatiumConfig {
// Items
@SerialEntry var tiltItemPositions = true
@SerialEntry var tiltItemPositionsInThirdperson = true
@SerialEntry var oldSkullPosition = true
@SerialEntry var applyItemSwingUsage = true
@SerialEntry var removeEquipAnimationOnItemUse = true
@SerialEntry var doNotSkipHandAnimationOnSwap = true
@SerialEntry var disableItemUsingTextureInGui = true
@SerialEntry var itemDropsFaceCamera = true
@SerialEntry var itemDrops2D = true
@SerialEntry var itemFramed2D = true
@SerialEntry var item2DColors = true
@SerialEntry var oldDurabilityBarColors = true
@SerialEntry var oldItemRarities = true
@SerialEntry var removeClientsideBlockingDelay = true
Expand All @@ -1013,7 +1026,6 @@ class AnimatiumConfig {
@SerialEntry var oldCloudHeight = true
@SerialEntry var legacyThirdpersonSwordBlockingPosition = true
@SerialEntry var lockBlockingArmRotation = true
@SerialEntry var oldProjectilePosition = true
@SerialEntry var disableProjectileAgeCheck = true
@SerialEntry var oldBlockMiningProgress = true
@SerialEntry var disableInventoryEntityScissor = true
Expand Down
45 changes: 28 additions & 17 deletions src/main/kotlin/me/mixces/animatium/util/ItemUtils.kt
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
package me.mixces.animatium.util

import me.mixces.animatium.config.AnimatiumConfig
import net.minecraft.block.BannerBlock
import net.minecraft.block.Block
import net.minecraft.block.SkullBlock
import net.minecraft.client.render.entity.state.EntityRenderState
import net.minecraft.client.render.item.ItemRenderState
import net.minecraft.client.util.math.MatrixStack
import net.minecraft.entity.LivingEntity
import net.minecraft.item.BlockItem
import net.minecraft.item.CrossbowItem
import net.minecraft.item.FishingRodItem
import net.minecraft.item.ItemStack
import net.minecraft.item.Items
import net.minecraft.item.MaceItem
import net.minecraft.item.MiningToolItem
import net.minecraft.item.ModelTransformationMode
import net.minecraft.item.OnAStickItem
import net.minecraft.item.RangedWeaponItem
import net.minecraft.item.ShieldItem
import net.minecraft.item.SwordItem
import net.minecraft.item.TridentItem
import net.minecraft.item.*
import net.minecraft.util.Rarity
import net.minecraft.util.math.RotationAxis
import kotlin.math.roundToInt
Expand Down Expand Up @@ -65,11 +56,30 @@ object ItemUtils {
@JvmStatic
fun isHandheldItem(stack: ItemStack): Boolean {
return if (!stack.isEmpty) {
val item = stack.item
// TODO: is this the best way? probably not
stack.item is MiningToolItem || stack.item is SwordItem
|| stack.item is MaceItem || stack.item is TridentItem
item is MiningToolItem || item is SwordItem
|| item is MaceItem || item is TridentItem
|| isFishingRodItem(stack)
|| setOf(Items.STICK, Items.BREEZE_ROD, Items.BLAZE_ROD).contains(stack.item)
|| setOf(Items.STICK, Items.BREEZE_ROD, Items.BLAZE_ROD).contains(item)
} else {
false
}
}

@JvmStatic
fun isSkullBlock(stack: ItemStack): Boolean {
return if (!stack.isEmpty) {
Block.getBlockFromItem(stack.item) is SkullBlock
} else {
false
}
}

@JvmStatic
fun isBlockItemBlacklisted(stack: ItemStack): Boolean {
return if (!stack.isEmpty) {
Block.getBlockFromItem(stack.item) is BannerBlock || isSkullBlock(stack)
} else {
false
}
Expand All @@ -78,7 +88,8 @@ object ItemUtils {
@JvmStatic
fun isItemBlacklisted(stack: ItemStack): Boolean {
return if (!stack.isEmpty) {
stack.item is ShieldItem || stack.item is CrossbowItem
val item = stack.item
item is ShieldItem || item is CrossbowItem || isBlockItemBlacklisted(stack)
} else {
false
}
Expand Down
Loading

0 comments on commit ac7c5eb

Please sign in to comment.