Skip to content

Commit

Permalink
Kotlin <3
Browse files Browse the repository at this point in the history
  • Loading branch information
lowercasebtw committed Dec 20, 2024
1 parent 513c5a0 commit f0f6f8e
Show file tree
Hide file tree
Showing 33 changed files with 331 additions and 307 deletions.
8 changes: 8 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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}")
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
37 changes: 0 additions & 37 deletions src/main/java/me/mixces/animatium/Animatium.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ protected MixinBipedEntityModel(ModelPart modelPart, Function<Identifier, Render
private void animatium$oldSwordBlockArm(BipedEntityModel<?> instance, ModelPart arm, boolean rightArm, Operation<Void> original, @Local(argsOnly = true) T state) {
original.call(instance, arm, rightArm);
if (AnimatiumConfig.getInstance().legacySwordBlockingPosition) {
Optional<Entity> optionalLivingEntity = EntityUtils.getEntityByState(state);
Optional<Entity> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<ItemStack> stackOptional = ItemUtils.getStack();
if (stackOptional.isPresent() && ItemUtils.isFishingRodItem(stackOptional.get())) {
Optional<ModelTransformationMode> modeOptional = ItemUtils.getTransformMode();
Optional<ItemStack> stackOptional = ItemUtils.Companion.getStack();
if (stackOptional.isPresent() && ItemUtils.Companion.isFishingRodItem(stackOptional.get())) {
Optional<ModelTransformationMode> modeOptional = ItemUtils.Companion.getTransformMode();
if (modeOptional.isEmpty()) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
public abstract class MixinEntityRenderer {
@Inject(method = "updateRenderState", at = @At("TAIL"))
private <T extends Entity, S extends EntityRenderState> 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"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Float> original, @Local(argsOnly = true) ItemEntityRenderState itemEntityRenderState, @Local(argsOnly = true) MatrixStack matrixStack) {
if (AnimatiumConfig.getInstance().itemDropsFaceCamera) {
Optional<Entity> optionalEntity = EntityUtils.getEntityByState(itemEntityRenderState);
Optional<Entity> 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());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public MixinHeldItemFeatureRenderer(FeatureRendererContext<S, M> 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<ItemStack> stackRef) {
if (AnimatiumConfig.getInstance().tiltItemPositionsInThirdperson && !itemState.isEmpty()) {
Optional<Entity> optionalLivingEntity = EntityUtils.getEntityByState(entityState);
Optional<Entity> optionalLivingEntity = EntityUtils.Companion.getEntityByState(entityState);
if (optionalLivingEntity.isPresent() && entityState instanceof ArmedEntityRenderState) {
LivingEntity livingEntity = (LivingEntity) optionalLivingEntity.get();
stackRef.set(livingEntity.getStackInArm(arm));
Expand All @@ -53,28 +53,28 @@ public MixinHeldItemFeatureRenderer(FeatureRendererContext<S, M> 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<ItemStack> 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<ItemStack> 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<Entity> optionalLivingEntity = EntityUtils.getEntityByState(entityState);
Optional<Entity> 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));
Expand All @@ -89,9 +89,9 @@ public MixinHeldItemFeatureRenderer(FeatureRendererContext<S, M> 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);
}
Expand All @@ -117,7 +117,7 @@ public MixinHeldItemFeatureRenderer(FeatureRendererContext<S, M> 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));
Expand All @@ -128,7 +128,7 @@ public MixinHeldItemFeatureRenderer(FeatureRendererContext<S, M> 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));
Expand All @@ -139,8 +139,8 @@ public MixinHeldItemFeatureRenderer(FeatureRendererContext<S, M> 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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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));
}

Expand Down
Loading

0 comments on commit f0f6f8e

Please sign in to comment.