diff --git a/build.gradle b/build.gradle index af5000c..9a23bb7 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,7 @@ plugins { id 'fabric-loom' version '1.9-SNAPSHOT' id 'maven-publish' + id "org.jetbrains.kotlin.jvm" version "2.1.0" } version = project.mod_version @@ -31,6 +32,7 @@ dependencies { // Fabric API. This is technically optional, but you probably want it anyway. modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" + modImplementation "net.fabricmc:fabric-language-kotlin:${project.fabric_kotlin_version}" // Mod Menu modImplementation("com.terraformersmc:modmenu:${project.modmenu_version}") @@ -50,6 +52,12 @@ tasks.withType(JavaCompile).configureEach { it.options.release = 21 } +tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all { + kotlinOptions { + jvmTarget = 21 + } +} + java { withSourcesJar() sourceCompatibility = JavaVersion.VERSION_21 diff --git a/gradle.properties b/gradle.properties index 3e4dc80..717948d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,6 +10,7 @@ loader_version=0.16.9 # Dependencies fabric_version=0.111.0+1.21.4 +fabric_kotlin_version=1.13.0+kotlin.2.1.0 modmenu_version=13.0.0-beta.1 yacl_version=3.6.2+1.21.4-fabric diff --git a/src/main/java/me/mixces/animatium/Animatium.java b/src/main/java/me/mixces/animatium/Animatium.java deleted file mode 100644 index f879d22..0000000 --- a/src/main/java/me/mixces/animatium/Animatium.java +++ /dev/null @@ -1,37 +0,0 @@ -package me.mixces.animatium; - -import me.mixces.animatium.config.AnimatiumConfig; -import net.fabricmc.api.ClientModInitializer; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.network.ClientPlayNetworkHandler; -import net.minecraft.client.network.ServerInfo; - -public class Animatium implements ClientModInitializer { - @Override - public void onInitializeClient() { - AnimatiumConfig.load(); - } - - public static boolean isLegacySupportedVersion() { - MinecraftClient client = MinecraftClient.getInstance(); - ClientPlayNetworkHandler networkHandler = client.getNetworkHandler(); - if (networkHandler == null) { - return false; - } - - String brand = networkHandler.getBrand(); - if (brand == null) { - return false; - } - - if (brand.toLowerCase().contains("hypixel") || brand.toLowerCase().contains("hygot") || brand.contains("1.8")) { - return true; - } else { - ServerInfo serverInfo = networkHandler.getServerInfo(); - return serverInfo != null && - (serverInfo.address.contains("loyisa") || - serverInfo.address.contains("bedwarspractice") || - serverInfo.address.contains("bridger.land")); - } - } -} \ No newline at end of file diff --git a/src/main/java/me/mixces/animatium/mixins/MixinMinecraftClient.java b/src/main/java/me/mixces/animatium/mixins/MixinMinecraftClient.java index 64b0a6b..434568f 100644 --- a/src/main/java/me/mixces/animatium/mixins/MixinMinecraftClient.java +++ b/src/main/java/me/mixces/animatium/mixins/MixinMinecraftClient.java @@ -38,7 +38,7 @@ public abstract class MixinMinecraftClient { // TODO: Possible setting to allow swinging without having to look at a block? if (AnimatiumConfig.getInstance().alwaysAllowUsageSwinging || (this.crosshairTarget != null && this.crosshairTarget.getType() == HitResult.Type.BLOCK)) { - PlayerUtils.fakeHandSwing(player, player.getActiveHand()); + PlayerUtils.Companion.fakeHandSwing(player, player.getActiveHand()); } } } diff --git a/src/main/java/me/mixces/animatium/mixins/model/entity/MixinBipedEntityModel.java b/src/main/java/me/mixces/animatium/mixins/model/entity/MixinBipedEntityModel.java index 9dc0ead..e60fe23 100644 --- a/src/main/java/me/mixces/animatium/mixins/model/entity/MixinBipedEntityModel.java +++ b/src/main/java/me/mixces/animatium/mixins/model/entity/MixinBipedEntityModel.java @@ -133,7 +133,7 @@ protected MixinBipedEntityModel(ModelPart modelPart, Function instance, ModelPart arm, boolean rightArm, Operation original, @Local(argsOnly = true) T state) { original.call(instance, arm, rightArm); if (AnimatiumConfig.getInstance().legacySwordBlockingPosition) { - Optional optionalLivingEntity = EntityUtils.getEntityByState(state); + Optional optionalLivingEntity = EntityUtils.Companion.getEntityByState(state); if (optionalLivingEntity.isPresent() && state instanceof BipedEntityRenderState) { LivingEntity livingEntity = (LivingEntity) optionalLivingEntity.get(); ItemStack stack = rightArm ? livingEntity.getStackInArm(Arm.RIGHT) : livingEntity.getStackInArm(Arm.LEFT); diff --git a/src/main/java/me/mixces/animatium/mixins/model/item/MixinItemModelManager.java b/src/main/java/me/mixces/animatium/mixins/model/item/MixinItemModelManager.java index 40eaf7f..a39870f 100644 --- a/src/main/java/me/mixces/animatium/mixins/model/item/MixinItemModelManager.java +++ b/src/main/java/me/mixces/animatium/mixins/model/item/MixinItemModelManager.java @@ -16,6 +16,6 @@ public abstract class MixinItemModelManager { @Inject(method = "update(Lnet/minecraft/client/render/item/ItemRenderState;Lnet/minecraft/item/ItemStack;Lnet/minecraft/item/ModelTransformationMode;ZLnet/minecraft/world/World;Lnet/minecraft/entity/LivingEntity;I)V", at = @At("HEAD")) private void animatium$setItemUtils(ItemRenderState renderState, ItemStack stack, ModelTransformationMode transformationMode, boolean leftHand, World world, LivingEntity entity, int seed, CallbackInfo ci) { - ItemUtils.set(stack, transformationMode); + ItemUtils.Companion.set(stack, transformationMode); } } diff --git a/src/main/java/me/mixces/animatium/mixins/model/item/MixinItemRenderLayerState.java b/src/main/java/me/mixces/animatium/mixins/model/item/MixinItemRenderLayerState.java index bd9b3c7..2c17ecf 100644 --- a/src/main/java/me/mixces/animatium/mixins/model/item/MixinItemRenderLayerState.java +++ b/src/main/java/me/mixces/animatium/mixins/model/item/MixinItemRenderLayerState.java @@ -25,9 +25,9 @@ public abstract class MixinItemRenderLayerState { @Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/model/json/Transformation;apply(ZLnet/minecraft/client/util/math/MatrixStack;)V")) private void animatium$tiltItemPositionsRod(MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay, CallbackInfo ci) { if (AnimatiumConfig.getInstance().tiltItemPositions) { - Optional stackOptional = ItemUtils.getStack(); - if (stackOptional.isPresent() && ItemUtils.isFishingRodItem(stackOptional.get())) { - Optional modeOptional = ItemUtils.getTransformMode(); + Optional stackOptional = ItemUtils.Companion.getStack(); + if (stackOptional.isPresent() && ItemUtils.Companion.isFishingRodItem(stackOptional.get())) { + Optional modeOptional = ItemUtils.Companion.getTransformMode(); if (modeOptional.isEmpty()) { return; } diff --git a/src/main/java/me/mixces/animatium/mixins/model/item/MixinUsingItemProperty.java b/src/main/java/me/mixces/animatium/mixins/model/item/MixinUsingItemProperty.java index 4c48706..2b5d915 100644 --- a/src/main/java/me/mixces/animatium/mixins/model/item/MixinUsingItemProperty.java +++ b/src/main/java/me/mixces/animatium/mixins/model/item/MixinUsingItemProperty.java @@ -14,7 +14,7 @@ public abstract class MixinUsingItemProperty { @ModifyReturnValue(method = "getValue", at = @At(value = "RETURN")) private boolean animatium$getValue(boolean original, @Local(argsOnly = true) ItemStack stack, @Local(argsOnly = true) ModelTransformationMode modelTransformationMode) { - if (AnimatiumConfig.getInstance().disableItemUsingTextureInGui && ItemUtils.isRangedWeaponItem(stack) && modelTransformationMode == ModelTransformationMode.GUI) { + if (AnimatiumConfig.getInstance().disableItemUsingTextureInGui && ItemUtils.Companion.isRangedWeaponItem(stack) && modelTransformationMode == ModelTransformationMode.GUI) { return false; } else { return original; diff --git a/src/main/java/me/mixces/animatium/mixins/renderer/MixinDrawContext.java b/src/main/java/me/mixces/animatium/mixins/renderer/MixinDrawContext.java index 05aaccb..6d59cd7 100644 --- a/src/main/java/me/mixces/animatium/mixins/renderer/MixinDrawContext.java +++ b/src/main/java/me/mixces/animatium/mixins/renderer/MixinDrawContext.java @@ -22,7 +22,7 @@ public abstract class MixinDrawContext { if (AnimatiumConfig.getInstance().oldDurabilityBarColors) { int i = x + 2; int j = y + 13; - int color = ColorHelper.getArgb((255 - ItemUtils.getLegacyDurabilityColorValue(stack)) / 4, 64, 0); + int color = ColorHelper.getArgb((255 - ItemUtils.Companion.getLegacyDurabilityColorValue(stack)) / 4, 64, 0); this.fill(RenderLayer.getGui(), i, j, i + 12, j + 1, 200, ColorHelper.fullAlpha(color)); } } diff --git a/src/main/java/me/mixces/animatium/mixins/renderer/entity/MixinEntityRenderer.java b/src/main/java/me/mixces/animatium/mixins/renderer/entity/MixinEntityRenderer.java index 8f74565..300fe97 100644 --- a/src/main/java/me/mixces/animatium/mixins/renderer/entity/MixinEntityRenderer.java +++ b/src/main/java/me/mixces/animatium/mixins/renderer/entity/MixinEntityRenderer.java @@ -20,7 +20,7 @@ public abstract class MixinEntityRenderer { @Inject(method = "updateRenderState", at = @At("TAIL")) private void animatium$saveEntityByState(T entity, S state, float tickDelta, CallbackInfo ci) { - EntityUtils.setEntityByState(state, entity); + EntityUtils.Companion.setEntityByState(state, entity); } @WrapOperation(method = "renderLabelIfPresent", at = @At(value = "FIELD", target = "Lnet/minecraft/client/render/entity/state/EntityRenderState;sneaking:Z")) diff --git a/src/main/java/me/mixces/animatium/mixins/renderer/entity/MixinFishingBobberEntityRenderer.java b/src/main/java/me/mixces/animatium/mixins/renderer/entity/MixinFishingBobberEntityRenderer.java index 2228a0d..3c2e6ea 100644 --- a/src/main/java/me/mixces/animatium/mixins/renderer/entity/MixinFishingBobberEntityRenderer.java +++ b/src/main/java/me/mixces/animatium/mixins/renderer/entity/MixinFishingBobberEntityRenderer.java @@ -34,7 +34,7 @@ protected MixinFishingBobberEntityRenderer(EntityRendererFactory.Context ctx) { if (AnimatiumConfig.getInstance().fishingRodLineInterpolation) { CameraAccessor cameraAccessor = (CameraAccessor) dispatcher.camera; float eyeHeight = MathHelper.lerp(v, cameraAccessor.getLastCameraY(), cameraAccessor.getCameraY()); - return PlayerUtils.lerpPlayerWithEyeHeight(instance, v, eyeHeight); + return PlayerUtils.Companion.lerpPlayerWithEyeHeight(instance, v, eyeHeight); } else { return original.call(instance, v); } @@ -63,7 +63,7 @@ protected MixinFishingBobberEntityRenderer(EntityRendererFactory.Context ctx) { @ModifyArg(method = "updateRenderState(Lnet/minecraft/entity/projectile/FishingBobberEntity;Lnet/minecraft/client/render/entity/state/FishingBobberEntityState;F)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/entity/FishingBobberEntityRenderer;getHandPos(Lnet/minecraft/entity/player/PlayerEntity;FF)Lnet/minecraft/util/math/Vec3d;"), index = 1) private float animatium$fixCastLineSwing(float f) { if (AnimatiumConfig.getInstance().fixCastLineSwing) { - int multiplier = PlayerUtils.getHandMultiplier(Objects.requireNonNull(MinecraftClient.getInstance().player)); + int multiplier = PlayerUtils.Companion.getHandMultiplier(Objects.requireNonNull(MinecraftClient.getInstance().player)); return f * multiplier; } else { return f; diff --git a/src/main/java/me/mixces/animatium/mixins/renderer/entity/MixinFlyingItemEntityRenderer.java b/src/main/java/me/mixces/animatium/mixins/renderer/entity/MixinFlyingItemEntityRenderer.java index 15a55b8..63fe428 100644 --- a/src/main/java/me/mixces/animatium/mixins/renderer/entity/MixinFlyingItemEntityRenderer.java +++ b/src/main/java/me/mixces/animatium/mixins/renderer/entity/MixinFlyingItemEntityRenderer.java @@ -26,7 +26,7 @@ protected MixinFlyingItemEntityRenderer(EntityRendererFactory.Context ctx) { private void animatium$oldProjectilePosition(FlyingItemEntityRenderState flyingItemEntityRenderState, MatrixStack matrices, VertexConsumerProvider vertexConsumerProvider, int i, CallbackInfo ci) { if (AnimatiumConfig.getInstance().oldProjectilePosition) { assert MinecraftClient.getInstance().player != null; - int direction = PlayerUtils.getHandMultiplier(MinecraftClient.getInstance().player); + int direction = PlayerUtils.Companion.getHandMultiplier(MinecraftClient.getInstance().player); matrices.translate(direction * 0.25F, 0.0F, 0.25F); } } diff --git a/src/main/java/me/mixces/animatium/mixins/renderer/entity/MixinItemEntityRenderer.java b/src/main/java/me/mixces/animatium/mixins/renderer/entity/MixinItemEntityRenderer.java index 7a6c88a..5d007b8 100644 --- a/src/main/java/me/mixces/animatium/mixins/renderer/entity/MixinItemEntityRenderer.java +++ b/src/main/java/me/mixces/animatium/mixins/renderer/entity/MixinItemEntityRenderer.java @@ -25,13 +25,13 @@ public abstract class MixinItemEntityRenderer { @WrapOperation(method = "render(Lnet/minecraft/client/render/entity/state/ItemEntityRenderState;Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/ItemEntity;getRotation(FF)F")) private float animatium$itemDropsFaceCamera(float age, float uniqueOffset, Operation original, @Local(argsOnly = true) ItemEntityRenderState itemEntityRenderState, @Local(argsOnly = true) MatrixStack matrixStack) { if (AnimatiumConfig.getInstance().itemDropsFaceCamera) { - Optional optionalEntity = EntityUtils.getEntityByState(itemEntityRenderState); + Optional optionalEntity = EntityUtils.Companion.getEntityByState(itemEntityRenderState); if (optionalEntity.isPresent()) { ItemEntity entity = (ItemEntity) optionalEntity.get(); ItemStack itemStack = entity.getStack(); if (!(itemStack.getItem() instanceof BlockItem) && !itemEntityRenderState.itemRenderState.hasDepth()) { Camera camera = MinecraftClient.getInstance().gameRenderer.getCamera(); - return MathUtils.toRadians(180F - camera.getYaw()); + return MathUtils.Companion.toRadians(180F - camera.getYaw()); } } } diff --git a/src/main/java/me/mixces/animatium/mixins/renderer/item/MixinHeldItemFeatureRenderer.java b/src/main/java/me/mixces/animatium/mixins/renderer/item/MixinHeldItemFeatureRenderer.java index e0c36d7..174b3d5 100644 --- a/src/main/java/me/mixces/animatium/mixins/renderer/item/MixinHeldItemFeatureRenderer.java +++ b/src/main/java/me/mixces/animatium/mixins/renderer/item/MixinHeldItemFeatureRenderer.java @@ -42,7 +42,7 @@ public MixinHeldItemFeatureRenderer(FeatureRendererContext context) { @Inject(method = "renderItem", at = @At("HEAD")) private void animatium$setRef(S entityState, ItemRenderState itemState, Arm arm, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo ci, @Share("stack") LocalRef stackRef) { if (AnimatiumConfig.getInstance().tiltItemPositionsInThirdperson && !itemState.isEmpty()) { - Optional optionalLivingEntity = EntityUtils.getEntityByState(entityState); + Optional optionalLivingEntity = EntityUtils.Companion.getEntityByState(entityState); if (optionalLivingEntity.isPresent() && entityState instanceof ArmedEntityRenderState) { LivingEntity livingEntity = (LivingEntity) optionalLivingEntity.get(); stackRef.set(livingEntity.getStackInArm(arm)); @@ -53,28 +53,28 @@ public MixinHeldItemFeatureRenderer(FeatureRendererContext context) { @ModifyArgs(method = "renderItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/math/MatrixStack;translate(FFF)V")) private void animatium$oldTransformTranslation(Args args, @Share("stack") LocalRef stackRef) { - if (AnimatiumConfig.getInstance().tiltItemPositionsInThirdperson && !ItemUtils.isItemBlacklisted(stackRef.get())) { + if (AnimatiumConfig.getInstance().tiltItemPositionsInThirdperson && !ItemUtils.Companion.isItemBlacklisted(stackRef.get())) { args.setAll((float) args.get(0) * -1.0F, 0.4375F, (float) args.get(2) / 10 * -1.0F); } } @WrapWithCondition(method = "renderItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/math/MatrixStack;multiply(Lorg/joml/Quaternionf;)V")) private boolean animatium$removeTransformMultiply(MatrixStack instance, Quaternionf quaternion, @Share("stack") LocalRef stackRef) { - return !AnimatiumConfig.getInstance().tiltItemPositionsInThirdperson || ItemUtils.isItemBlacklisted(stackRef.get()); + return !AnimatiumConfig.getInstance().tiltItemPositionsInThirdperson || ItemUtils.Companion.isItemBlacklisted(stackRef.get()); } @Inject(method = "renderItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/item/ItemRenderState;render(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;II)V")) - private void animatium$tiltItemPositionsThird(S entityState, ItemRenderState itemState, Arm arm, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo ci) { + private void animatium$tiltItemPositionsThird(S entityState, ItemRenderState itemRenderState, Arm arm, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo ci) { if (AnimatiumConfig.getInstance().tiltItemPositionsInThirdperson) { - Optional optionalLivingEntity = EntityUtils.getEntityByState(entityState); + Optional optionalLivingEntity = EntityUtils.Companion.getEntityByState(entityState); if (optionalLivingEntity.isPresent() && entityState instanceof ArmedEntityRenderState) { int direction = arm == Arm.RIGHT ? 1 : -1; LivingEntity livingEntity = (LivingEntity) optionalLivingEntity.get(); ItemStack stack = livingEntity.getStackInArm(arm); Item item = stack.getItem(); - if (!stack.isEmpty() && !ItemUtils.isItemBlacklisted(stack)) { + if (!stack.isEmpty() && !ItemUtils.Companion.isItemBlacklisted(stack)) { float scale; - if (ItemUtils.isBlock3d(stack)) { + if (ItemUtils.Companion.isBlock3d(stack, itemRenderState)) { scale = 0.375F; matrices.translate(0.0F, 0.1875F, -0.3125F); matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(20.0F)); @@ -89,9 +89,9 @@ public MixinHeldItemFeatureRenderer(FeatureRendererContext context) { matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(180)); matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(100.0F)); matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(direction * -145.0F)); - } else if (ItemUtils.isHandheldItem(stack)) { + } else if (ItemUtils.Companion.isHandheldItem(stack)) { scale = 0.625F; - if (ItemUtils.isFishingRodItem(stack)) { + if (ItemUtils.Companion.isFishingRodItem(stack)) { matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(direction * 180.0F)); matrices.translate(0.0F, -0.125F, 0.0F); } @@ -117,7 +117,7 @@ public MixinHeldItemFeatureRenderer(FeatureRendererContext context) { matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(direction * 20.0F)); } - if (!ItemUtils.isBlock3d(stack)) { + if (!ItemUtils.Companion.isBlock3d(stack, itemRenderState)) { matrices.translate(0.0F, -0.3F, 0.0F); matrices.scale(1.5F, 1.5F, 1.5F); matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(direction * 50.0F)); @@ -128,7 +128,7 @@ public MixinHeldItemFeatureRenderer(FeatureRendererContext context) { matrices.translate(direction * -0.5F, 0.5F, 0.03125F); } - if (ItemUtils.isBlock3d(stack)) { + if (ItemUtils.Companion.isBlock3d(stack, itemRenderState)) { matrices.scale(1 / 0.375F, 1 / 0.375F, 1 / 0.375F); matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(direction * -45.0F)); matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(-75.0F)); @@ -139,8 +139,8 @@ public MixinHeldItemFeatureRenderer(FeatureRendererContext context) { matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(direction * -260.0F)); matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(80.0F)); matrices.translate(direction * 0.0625F, 2.0F * 0.0625F, -2.5F * 0.0625F); - } else if (ItemUtils.isHandheldItem(stack)) { - boolean isRod = ItemUtils.isFishingRodItem(stack); + } else if (ItemUtils.Companion.isHandheldItem(stack)) { + boolean isRod = ItemUtils.Companion.isFishingRodItem(stack); matrices.scale(1 / 0.85F, 1 / 0.85F, 1 / 0.85F); matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(direction * -55.0F)); matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(direction * 90.0F)); diff --git a/src/main/java/me/mixces/animatium/mixins/renderer/item/MixinHeldItemRenderer.java b/src/main/java/me/mixces/animatium/mixins/renderer/item/MixinHeldItemRenderer.java index 4a1c668..a26adb4 100644 --- a/src/main/java/me/mixces/animatium/mixins/renderer/item/MixinHeldItemRenderer.java +++ b/src/main/java/me/mixces/animatium/mixins/renderer/item/MixinHeldItemRenderer.java @@ -54,7 +54,7 @@ public abstract class MixinHeldItemRenderer { if (AnimatiumConfig.getInstance().tiltItemPositions && !(instance.getItem() instanceof ShieldItem)) { Arm arm = hand == Hand.MAIN_HAND ? player.getMainArm() : player.getMainArm().getOpposite(); int direction = arm == Arm.RIGHT ? 1 : -1; - ItemUtils.applyLegacyFirstpersonTransforms(matrices, direction, () -> { + ItemUtils.Companion.applyLegacyFirstpersonTransforms(matrices, direction, () -> { matrices.translate(direction * -0.5F, 0.2F, 0.0F); matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(direction * 30.0F)); matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(-80.0F)); @@ -71,8 +71,8 @@ public abstract class MixinHeldItemRenderer { if (AnimatiumConfig.getInstance().tiltItemPositions && !(stack.getItem() instanceof BlockItem) && !(stack.getItem() instanceof ShieldItem)) { Arm arm = hand == Hand.MAIN_HAND ? player.getMainArm() : player.getMainArm().getOpposite(); int direction = arm == Arm.RIGHT ? 1 : -1; - float angle = MathUtils.toRadians(25); - if (ItemUtils.isFishingRodItem(stack)) { + float angle = MathUtils.Companion.toRadians(25); + if (ItemUtils.Companion.isFishingRodItem(stack)) { matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(direction * 180.0F)); } diff --git a/src/main/java/me/mixces/animatium/mixins/renderer/item/MixinItemRenderer.java b/src/main/java/me/mixces/animatium/mixins/renderer/item/MixinItemRenderer.java index 5fd1786..99190fe 100644 --- a/src/main/java/me/mixces/animatium/mixins/renderer/item/MixinItemRenderer.java +++ b/src/main/java/me/mixces/animatium/mixins/renderer/item/MixinItemRenderer.java @@ -23,7 +23,7 @@ public abstract class MixinItemRenderer { @WrapOperation(method = "renderBakedItemModel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/model/BakedModel;getQuads(Lnet/minecraft/block/BlockState;Lnet/minecraft/util/math/Direction;Lnet/minecraft/util/math/random/Random;)Ljava/util/List;", ordinal = 1)) private static List animatium$itemDrops2D(BakedModel instance, BlockState state, Direction direction, Random random, Operation> original) { List quads = original.call(instance, state, direction, random); - Optional optionalModelTransformationMode = ItemUtils.getTransformMode(); + Optional optionalModelTransformationMode = ItemUtils.Companion.getTransformMode(); if (AnimatiumConfig.getInstance().itemDrops2D && !instance.hasDepth() && optionalModelTransformationMode.isPresent() && optionalModelTransformationMode.get() == ModelTransformationMode.GROUND) { return quads.stream().filter(baked -> baked.getFace() == Direction.SOUTH).collect(Collectors.toList()); } else { diff --git a/src/main/java/me/mixces/animatium/mixins/world/MixinItem.java b/src/main/java/me/mixces/animatium/mixins/world/MixinItem.java index 6eb4238..5cc4864 100644 --- a/src/main/java/me/mixces/animatium/mixins/world/MixinItem.java +++ b/src/main/java/me/mixces/animatium/mixins/world/MixinItem.java @@ -15,7 +15,7 @@ public abstract class MixinItem { @Inject(method = "getItemBarColor", at = @At("HEAD"), cancellable = true) private void animatium$oldDurabilityBarColors(ItemStack stack, CallbackInfoReturnable cir) { if (AnimatiumConfig.getInstance().oldDurabilityBarColors) { - int value = ItemUtils.getLegacyDurabilityColorValue(stack); + int value = ItemUtils.Companion.getLegacyDurabilityColorValue(stack); cir.setReturnValue(ColorHelper.getArgb(255 - value, value, 0)); } } diff --git a/src/main/java/me/mixces/animatium/mixins/world/MixinItemStack.java b/src/main/java/me/mixces/animatium/mixins/world/MixinItemStack.java index eebb1a6..24f80ad 100644 --- a/src/main/java/me/mixces/animatium/mixins/world/MixinItemStack.java +++ b/src/main/java/me/mixces/animatium/mixins/world/MixinItemStack.java @@ -14,7 +14,7 @@ public abstract class MixinItemStack { @WrapOperation(method = "getFormattedName", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;getRarity()Lnet/minecraft/util/Rarity;")) private Rarity animatium$oldItemRarities$getFormattedName(ItemStack instance, Operation original) { if (AnimatiumConfig.getInstance().oldItemRarities) { - return ItemUtils.getOldItemRarity((ItemStack) (Object) this); + return ItemUtils.Companion.getOldItemRarity((ItemStack) (Object) this); } else { return original.call(instance); } @@ -23,7 +23,7 @@ public abstract class MixinItemStack { @WrapOperation(method = "toHoverableText", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;getRarity()Lnet/minecraft/util/Rarity;")) private Rarity animatium$oldItemRarities$toHoverableText(ItemStack instance, Operation original) { if (AnimatiumConfig.getInstance().oldItemRarities) { - return ItemUtils.getOldItemRarity((ItemStack) (Object) this); + return ItemUtils.Companion.getOldItemRarity((ItemStack) (Object) this); } else { return original.call(instance); } diff --git a/src/main/java/me/mixces/animatium/mixins/world/entity/MixinPlayerEntity.java b/src/main/java/me/mixces/animatium/mixins/world/entity/MixinPlayerEntity.java index 876acd3..ace725e 100644 --- a/src/main/java/me/mixces/animatium/mixins/world/entity/MixinPlayerEntity.java +++ b/src/main/java/me/mixces/animatium/mixins/world/entity/MixinPlayerEntity.java @@ -62,7 +62,7 @@ protected MixinPlayerEntity(EntityType entityType, World @Inject(method = "getBaseDimensions", at = @At("RETURN"), cancellable = true) private void animatium$oldSneakEyeHeight(EntityPose pose, CallbackInfoReturnable cir) { if (AnimatiumConfig.getInstance().oldSneakEyeHeight && pose.equals(EntityPose.CROUCHING)) { - cir.setReturnValue(PlayerUtils.getLegacySneakingDimensions((PlayerEntity) (Object) this, pose)); + cir.setReturnValue(PlayerUtils.Companion.getLegacySneakingDimensions((PlayerEntity) (Object) this, pose)); } } } diff --git a/src/main/java/me/mixces/animatium/util/CameraVersion.java b/src/main/java/me/mixces/animatium/util/CameraVersion.java deleted file mode 100644 index c17ae7f..0000000 --- a/src/main/java/me/mixces/animatium/util/CameraVersion.java +++ /dev/null @@ -1,8 +0,0 @@ -package me.mixces.animatium.util; - -public enum CameraVersion { - v1_8, - v1_9_v1_13_2, - v1_14_v1_14_3, - LATEST -} diff --git a/src/main/java/me/mixces/animatium/util/EntityUtils.java b/src/main/java/me/mixces/animatium/util/EntityUtils.java deleted file mode 100644 index aaa76ea..0000000 --- a/src/main/java/me/mixces/animatium/util/EntityUtils.java +++ /dev/null @@ -1,20 +0,0 @@ -package me.mixces.animatium.util; - -import net.minecraft.client.render.entity.state.EntityRenderState; -import net.minecraft.entity.Entity; - -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; - -public abstract class EntityUtils { - private static final Map STATE_TO_ENTITY = new HashMap<>(); - - public static void setEntityByState(EntityRenderState state, Entity entity) { - STATE_TO_ENTITY.put(state, entity); - } - - public static Optional getEntityByState(EntityRenderState state) { - return Optional.ofNullable(STATE_TO_ENTITY.getOrDefault(state, null)); - } -} diff --git a/src/main/java/me/mixces/animatium/util/ItemUtils.java b/src/main/java/me/mixces/animatium/util/ItemUtils.java deleted file mode 100644 index 3a89d4f..0000000 --- a/src/main/java/me/mixces/animatium/util/ItemUtils.java +++ /dev/null @@ -1,122 +0,0 @@ -package me.mixces.animatium.util; - -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.render.model.BakedModel; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.item.*; -import net.minecraft.registry.Registries; -import net.minecraft.util.Rarity; -import net.minecraft.util.math.RotationAxis; - -import java.util.List; -import java.util.Optional; -import java.util.Set; - -public abstract class ItemUtils { - private static final ThreadLocal STACK = ThreadLocal.withInitial(() -> null); - private static final ThreadLocal TRANSFORMATION_MODE = ThreadLocal.withInitial(() -> null); - - public static void set(ItemStack stack, ModelTransformationMode transformationMode) { - ItemUtils.STACK.remove(); - ItemUtils.TRANSFORMATION_MODE.remove(); - ItemUtils.STACK.set(stack); - ItemUtils.TRANSFORMATION_MODE.set(transformationMode); - } - - public static Optional getStack() { - return Optional.ofNullable(STACK.get()); - } - - public static Optional getTransformMode() { - return Optional.ofNullable(TRANSFORMATION_MODE.get()); - } - - public static boolean isFishingRodItem(ItemStack stack) { - if (!stack.isEmpty()) { - Item item = stack.getItem(); - return item instanceof FishingRodItem || item instanceof OnAStickItem; - } else { - return false; - } - } - - public static boolean isRangedWeaponItem(ItemStack stack) { - if (!stack.isEmpty()) { - Item item = stack.getItem(); - return item instanceof RangedWeaponItem; - } else { - return false; - } - } - - public static boolean isHandheldItem(ItemStack stack) { - if (!stack.isEmpty()) { - Item item = stack.getItem(); - // TODO: is this the best way? probably not - return item instanceof MiningToolItem - || item instanceof SwordItem - || item instanceof MaceItem - || item instanceof TridentItem - || isFishingRodItem(stack) - || Set.of(Items.STICK, Items.BREEZE_ROD, Items.BLAZE_ROD).contains(item); - } else { - return false; - } - } - - public static boolean isItemBlacklisted(ItemStack stack) { - if (!stack.isEmpty()) { - Item item = stack.getItem(); - return item instanceof ShieldItem || item instanceof CrossbowItem; - } else { - return false; - } - } - - public static boolean isBlock3d(ItemStack stack) { - if (!stack.isEmpty()) { - Item item = stack.getItem(); - BakedModel model = MinecraftClient.getInstance().getBakedModelManager().getModel(Registries.ITEM.getId(item)); - return item instanceof BlockItem && model.hasDepth(); - } else { - return false; - } - } - - public static void applyLegacyFirstpersonTransforms(MatrixStack matrices, int direction, Runnable runnable) { - matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(direction * 45.0F)); - matrices.scale(0.4F, 0.4F, 0.4F); - runnable.run(); - matrices.scale(1 / 0.4F, 1 / 0.4F, 1 / 0.4F); - matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(direction * -45.0F)); - } - - public static void applyLegacyThirdpersonTransforms(MatrixStack matrices, int direction, Runnable runnable) { - // TODO - runnable.run(); - // TODO - } - - public static int getLegacyDurabilityColorValue(ItemStack stack) { - return (int) Math.round(255.0 - (double) stack.getDamage() * 255.0 / (double) stack.getMaxDamage()); - } - - public static Rarity getOldItemRarity(ItemStack stack) { - Rarity original = stack.getRarity(); - if (!stack.isEmpty()) { - Item item = stack.getItem(); - // TODO?: Trims? eh, if someone requests it ig - if (List.of(Items.GOLDEN_APPLE, Items.END_CRYSTAL).contains(item)) { - return Rarity.RARE; - } else if (List.of(Items.NETHER_STAR, Items.ELYTRA, Items.DRAGON_HEAD).contains(item)) { - return Rarity.UNCOMMON; - } else if (item == Items.ENCHANTED_GOLDEN_APPLE) { - return Rarity.EPIC; - } else if (item == Items.TRIDENT) { - return Rarity.COMMON; - } - } - - return original; - } -} diff --git a/src/main/java/me/mixces/animatium/util/MathUtils.java b/src/main/java/me/mixces/animatium/util/MathUtils.java deleted file mode 100644 index be0f342..0000000 --- a/src/main/java/me/mixces/animatium/util/MathUtils.java +++ /dev/null @@ -1,11 +0,0 @@ -package me.mixces.animatium.util; - -public abstract class MathUtils { - public static float toRadians(float angle) { - return angle * (float) Math.PI / 180F; - } - - public static float toAngle(float radians) { - return radians / (float) Math.PI * 180F; - } -} diff --git a/src/main/java/me/mixces/animatium/util/PlayerUtils.java b/src/main/java/me/mixces/animatium/util/PlayerUtils.java deleted file mode 100644 index 9c452a0..0000000 --- a/src/main/java/me/mixces/animatium/util/PlayerUtils.java +++ /dev/null @@ -1,61 +0,0 @@ -package me.mixces.animatium.util; - -import com.google.common.base.MoreObjects; -import me.mixces.animatium.mixins.accessor.PlayerEntityAccessor; -import net.minecraft.client.MinecraftClient; -import net.minecraft.entity.EntityDimensions; -import net.minecraft.entity.EntityPose; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.effect.StatusEffectUtil; -import net.minecraft.entity.effect.StatusEffects; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.Arm; -import net.minecraft.util.Hand; -import net.minecraft.util.math.Vec3d; - -import java.util.Objects; - -import static me.mixces.animatium.Animatium.isLegacySupportedVersion; - -public abstract class PlayerUtils { - public static int getHandMultiplier(PlayerEntity player) { - Hand hand = MoreObjects.firstNonNull(player.preferredHand, Hand.MAIN_HAND); - Arm arm = hand == Hand.MAIN_HAND ? player.getMainArm() : player.getMainArm().getOpposite(); - MinecraftClient client = MinecraftClient.getInstance(); - assert client != null; - int i = client.options.getPerspective().isFirstPerson() ? 1 : -1; - return arm == Arm.RIGHT ? i : -i; - } - - public static EntityDimensions getLegacySneakingDimensions(PlayerEntity player, EntityPose defaultPose) { - // Changes the sneak height to the one from <=1.13.2 on Hypixel & Loyisa & Bedwars Practice & Bridger Land - EntityDimensions dimensions = Objects.requireNonNull(PlayerEntityAccessor.getPoseDimensions()).getOrDefault(isLegacySupportedVersion() ? null : defaultPose, PlayerEntity.STANDING_DIMENSIONS); - if (((PlayerEntityAccessor) player).canChangeIntoPose$(EntityPose.STANDING)) { - return dimensions.withEyeHeight(1.54F); - } else { - return dimensions; - } - } - - public static Vec3d lerpPlayerWithEyeHeight(PlayerEntity entity, float tickDelta, float eyeHeight) { - return entity.getLerpedPos(tickDelta).add(0, eyeHeight, 0); - } - - public static void fakeHandSwing(PlayerEntity player, Hand hand) { - // NOTE: Clientside fake swinging, doesn't send a packet - if (!player.handSwinging || player.handSwingTicks >= getHandSwingDuration(player) / 2 || player.handSwingTicks < 0) { - player.handSwingTicks = -1; - player.handSwinging = true; - player.preferredHand = hand; - } - } - - // Fixes crash & doesn't require accesswidener - private static int getHandSwingDuration(LivingEntity entity) { - if (StatusEffectUtil.hasHaste(entity)) { - return 6 - (1 + StatusEffectUtil.getHasteAmplifier(entity)); - } else { - return entity.hasStatusEffect(StatusEffects.MINING_FATIGUE) ? 6 + (1 + Objects.requireNonNull(entity.getStatusEffect(StatusEffects.MINING_FATIGUE)).getAmplifier()) * 2 : 6; - } - } -} diff --git a/src/main/java/me/mixces/animatium/util/ViewBobbingStorage.java b/src/main/java/me/mixces/animatium/util/ViewBobbingStorage.java deleted file mode 100644 index 4baf0a9..0000000 --- a/src/main/java/me/mixces/animatium/util/ViewBobbingStorage.java +++ /dev/null @@ -1,11 +0,0 @@ -package me.mixces.animatium.util; - -public interface ViewBobbingStorage { - void animatium$setBobbingTilt(float bobbingTilt); - - void animatium$setPreviousBobbingTilt(float previousBobbingTilt); - - float animatium$getBobbingTilt(); - - float animatium$getPreviousBobbingTilt(); -} diff --git a/src/main/kotlin/me/mixces/animatium/AnimatiumClient.kt b/src/main/kotlin/me/mixces/animatium/AnimatiumClient.kt new file mode 100644 index 0000000..304671c --- /dev/null +++ b/src/main/kotlin/me/mixces/animatium/AnimatiumClient.kt @@ -0,0 +1,28 @@ +package me.mixces.animatium + +import me.mixces.animatium.config.AnimatiumConfig +import net.fabricmc.api.ClientModInitializer +import net.minecraft.client.MinecraftClient + +class AnimatiumClient : ClientModInitializer { + companion object { + fun isLegacySupportedVersion(): Boolean { + val client = MinecraftClient.getInstance() + val networkHandler = client.getNetworkHandler() ?: return false + val brand = networkHandler.getBrand()?.lowercase() ?: return false + if (brand.contains("hypixel") || brand.contains("hygot") || brand.contains("1.8")) { + return true + } else { + val serverInfo = networkHandler.getServerInfo() + return serverInfo != null && + (serverInfo.address.contains("loyisa") || + serverInfo.address.contains("bedwarspractice") || + serverInfo.address.contains("bridger.land")) + } + } + } + + override fun onInitializeClient() { + AnimatiumConfig.load() + } +} \ No newline at end of file diff --git a/src/main/kotlin/me/mixces/animatium/util/CameraVersion.kt b/src/main/kotlin/me/mixces/animatium/util/CameraVersion.kt new file mode 100644 index 0000000..e8309f9 --- /dev/null +++ b/src/main/kotlin/me/mixces/animatium/util/CameraVersion.kt @@ -0,0 +1,8 @@ +package me.mixces.animatium.util + +enum class CameraVersion { + v1_8, + v1_9_v1_13_2, + v1_14_v1_14_3, + LATEST +} \ No newline at end of file diff --git a/src/main/kotlin/me/mixces/animatium/util/EntityUtils.kt b/src/main/kotlin/me/mixces/animatium/util/EntityUtils.kt new file mode 100644 index 0000000..9d70ead --- /dev/null +++ b/src/main/kotlin/me/mixces/animatium/util/EntityUtils.kt @@ -0,0 +1,19 @@ +package me.mixces.animatium.util + +import net.minecraft.client.render.entity.state.EntityRenderState +import net.minecraft.entity.Entity +import java.util.Optional + +abstract class EntityUtils { + companion object { + val STATE_TO_ENTITY = hashMapOf() + + fun setEntityByState(state: EntityRenderState, entity: Entity) { + STATE_TO_ENTITY.put(state, entity) + } + + fun getEntityByState(state: EntityRenderState): Optional { + return Optional.ofNullable(STATE_TO_ENTITY.getOrDefault(state, null)) + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/me/mixces/animatium/util/ItemUtils.kt b/src/main/kotlin/me/mixces/animatium/util/ItemUtils.kt new file mode 100644 index 0000000..471ccb4 --- /dev/null +++ b/src/main/kotlin/me/mixces/animatium/util/ItemUtils.kt @@ -0,0 +1,125 @@ +package me.mixces.animatium.util + +import net.minecraft.client.render.item.ItemRenderState +import net.minecraft.client.util.math.MatrixStack +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.util.Rarity +import net.minecraft.util.math.RotationAxis +import java.util.Optional +import kotlin.math.roundToInt + +abstract class ItemUtils { + companion object { + val STACK: ThreadLocal = ThreadLocal.withInitial({ null }) + val TRANSFORMATION_MODE: ThreadLocal = ThreadLocal.withInitial({ null }) + + fun set(stack: ItemStack, transformationMode: ModelTransformationMode) { + STACK.remove() + TRANSFORMATION_MODE.remove() + STACK.set(stack) + TRANSFORMATION_MODE.set(transformationMode) + } + + fun getStack(): Optional { + return Optional.ofNullable(STACK.get()) + } + + fun getTransformMode(): Optional { + return Optional.ofNullable(TRANSFORMATION_MODE.get()) + } + + fun isFishingRodItem(stack: ItemStack): Boolean { + return if (!stack.isEmpty) { + stack.item is FishingRodItem || stack.item is OnAStickItem<*> + } else { + false + } + } + + fun isRangedWeaponItem(stack: ItemStack): Boolean { + return if (!stack.isEmpty) { + stack.item is RangedWeaponItem + } else { + false + } + } + + fun isHandheldItem(stack: ItemStack): Boolean { + return if (!stack.isEmpty) { + // TODO: is this the best way? probably not + (stack.item is MiningToolItem + || stack.item is SwordItem + || stack.item is MaceItem + || stack.item is TridentItem + || isFishingRodItem(stack) + || setOf(Items.STICK, Items.BREEZE_ROD, Items.BLAZE_ROD).contains(stack.item)) + } else { + false + } + } + + fun isItemBlacklisted(stack: ItemStack): Boolean { + return if (!stack.isEmpty) { + stack.item is ShieldItem || stack.item is CrossbowItem + } else { + false + } + } + + fun isBlock3d(stack: ItemStack, itemRenderState: ItemRenderState): Boolean { + return if (!stack.isEmpty) { + stack.item is BlockItem && itemRenderState.hasDepth() + } else { + false + } + } + + fun applyLegacyFirstpersonTransforms(matrices: MatrixStack, direction: Int, runnable: Runnable) { + matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(direction * 45.0F)) + matrices.scale(0.4F, 0.4F, 0.4F) + runnable.run() + matrices.scale(1 / 0.4F, 1 / 0.4F, 1 / 0.4F) + matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(direction * -45.0F)) + } + + fun applyLegacyThirdpersonTransforms(matrices: MatrixStack, direction: Int, runnable: Runnable) { + // TODO + runnable.run() + // TODO + } + + fun getLegacyDurabilityColorValue(stack: ItemStack): Int { + return (255.0 - stack.damage.toDouble() * 255.0 / stack.maxDamage.toDouble()).roundToInt() + } + + fun getOldItemRarity(stack: ItemStack): Rarity { + var original = stack.rarity + if (!stack.isEmpty) { + // TODO?: Trims? eh, if someone requests it ig + if (listOf(Items.GOLDEN_APPLE, Items.END_CRYSTAL).contains(stack.item)) { + return Rarity.RARE + } else if (listOf(Items.NETHER_STAR, Items.ELYTRA, Items.DRAGON_HEAD).contains(stack.item)) { + return Rarity.UNCOMMON + } else if (stack.item == Items.ENCHANTED_GOLDEN_APPLE) { + return Rarity.EPIC + } else if (stack.item == Items.TRIDENT) { + return Rarity.COMMON + } + } + + return original + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/me/mixces/animatium/util/MathUtils.kt b/src/main/kotlin/me/mixces/animatium/util/MathUtils.kt new file mode 100644 index 0000000..63ced1f --- /dev/null +++ b/src/main/kotlin/me/mixces/animatium/util/MathUtils.kt @@ -0,0 +1,13 @@ +package me.mixces.animatium.util + +abstract class MathUtils { + companion object { + fun toRadians(angle: Float): Float { + return angle * Math.PI.toFloat() / 180F + } + + fun toAngle(radians: Float): Float { + return radians / Math.PI.toFloat() * 180F + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/me/mixces/animatium/util/PlayerUtils.kt b/src/main/kotlin/me/mixces/animatium/util/PlayerUtils.kt new file mode 100644 index 0000000..e75adeb --- /dev/null +++ b/src/main/kotlin/me/mixces/animatium/util/PlayerUtils.kt @@ -0,0 +1,67 @@ +package me.mixces.animatium.util + +import com.google.common.base.MoreObjects +import me.mixces.animatium.AnimatiumClient +import me.mixces.animatium.mixins.accessor.PlayerEntityAccessor +import net.minecraft.client.MinecraftClient +import net.minecraft.entity.EntityDimensions +import net.minecraft.entity.EntityPose +import net.minecraft.entity.LivingEntity +import net.minecraft.entity.effect.StatusEffectUtil +import net.minecraft.entity.effect.StatusEffects +import net.minecraft.entity.player.PlayerEntity +import net.minecraft.util.Arm +import net.minecraft.util.Hand +import net.minecraft.util.math.Vec3d +import java.util.Objects + +abstract class PlayerUtils { + companion object { + fun getHandMultiplier(player: PlayerEntity): Int { + val hand = MoreObjects.firstNonNull(player.preferredHand, Hand.MAIN_HAND) + val arm = if (hand == Hand.MAIN_HAND) player.getMainArm() else player.getMainArm().getOpposite() + val client = MinecraftClient.getInstance() + val i = if (client.options.perspective.isFirstPerson) 1 else -1 + return if (arm == Arm.RIGHT) i else -i + } + + fun getLegacySneakingDimensions(player: PlayerEntity, defaultPose: EntityPose): EntityDimensions { + // Changes the sneak height to the one from <=1.13.2 on Hypixel & Loyisa & Bedwars Practice & Bridger Land + val dimensions = Objects.requireNonNull(PlayerEntityAccessor.getPoseDimensions()).getOrDefault( + if (AnimatiumClient.isLegacySupportedVersion()) null else defaultPose, + PlayerEntity.STANDING_DIMENSIONS + ) + return if ((player as PlayerEntityAccessor).`canChangeIntoPose$`(EntityPose.STANDING)) { + dimensions.withEyeHeight(1.54F) + } else { + dimensions + } + } + + fun lerpPlayerWithEyeHeight(entity: PlayerEntity, tickDelta: Float, eyeHeight: Double): Vec3d { + return entity.getLerpedPos(tickDelta).add(0.0, eyeHeight, 0.0) + } + + fun fakeHandSwing(player: PlayerEntity, hand: Hand) { + // NOTE: Clientside fake swinging, doesn't send a packet + if (!player.handSwinging || player.handSwingTicks >= getHandSwingDuration(player) / 2 || player.handSwingTicks < 0) { + player.handSwingTicks = -1 + player.handSwinging = true + player.preferredHand = hand + } + } + + // Fixes crash & doesn't require accesswidener + fun getHandSwingDuration(entity: LivingEntity): Int { + if (StatusEffectUtil.hasHaste(entity)) { + return 6 - (1 + StatusEffectUtil.getHasteAmplifier(entity)) + } else { + if (entity.hasStatusEffect(StatusEffects.MINING_FATIGUE)) { + return 6 + (1 + Objects.requireNonNull(entity.getStatusEffect(StatusEffects.MINING_FATIGUE))!!.amplifier) * 2 + } else { + return 6; + } + } + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/me/mixces/animatium/util/ViewBobbingStorage.kt b/src/main/kotlin/me/mixces/animatium/util/ViewBobbingStorage.kt new file mode 100644 index 0000000..5420039 --- /dev/null +++ b/src/main/kotlin/me/mixces/animatium/util/ViewBobbingStorage.kt @@ -0,0 +1,11 @@ +package me.mixces.animatium.util + +interface ViewBobbingStorage { + fun `animatium$setBobbingTilt`(bobbingTilt: Float) + + fun `animatium$setPreviousBobbingTilt`(previousBobbingTilt: Float) + + fun `animatium$getBobbingTilt`(): Float + + fun `animatium$getPreviousBobbingTilt`(): Float +} \ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 18d494a..92a6193 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -8,22 +8,36 @@ "mixcesta", "lowercasebtw" ], + "contact": { + "sources": "https://github.com/Legacy-Visuals-Project/Animatium/", + "issues": "https://github.com/Legacy-Visuals-Project/Animatium/issues" + }, "license": "LGPL-2.1", "icon": "assets/animatium/icon.png", "environment": "client", "entrypoints": { "client": [ - "me.mixces.animatium.Animatium" + { + "value": "me.mixces.animatium.AnimatiumClient", + "adapter": "kotlin" + } ], "modmenu": [ "me.mixces.animatium.config.ModMenuIntegration" ] }, + "custom": { + "modmenu": {} + }, "mixins": [ - "animatium.mixins.json" + { + "config": "animatium.mixins.json", + "environment": "client" + } ], "depends": { "fabricloader": ">=0.16.7", + "fabric-language-kotlin": ">=1.13.0+kotlin.2.1.0", "minecraft": ">=1.21.4 <1.21.5", "yet_another_config_lib_v3": ">=3.6.2" }