diff --git a/src/main/java/com/viaversion/viafabricplus/injection/mixin/features/block/mining_calculation/MixinPlayerEntity.java b/src/main/java/com/viaversion/viafabricplus/injection/mixin/features/block/mining_calculation/MixinPlayerEntity.java new file mode 100644 index 00000000..a2b71258 --- /dev/null +++ b/src/main/java/com/viaversion/viafabricplus/injection/mixin/features/block/mining_calculation/MixinPlayerEntity.java @@ -0,0 +1,94 @@ +/* + * This file is part of ViaFabricPlus - https://github.com/ViaVersion/ViaFabricPlus + * Copyright (C) 2021-2025 the original authors + * - FlorianMichael/EnZaXD + * - RK_01/RaphiMC + * Copyright (C) 2023-2025 ViaVersion and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.viaversion.viafabricplus.injection.mixin.features.block.mining_calculation; + +import com.llamalad7.mixinextras.sugar.Local; +import com.llamalad7.mixinextras.sugar.ref.LocalFloatRef; +import com.viaversion.viafabricplus.protocoltranslator.ProtocolTranslator; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; +import net.minecraft.block.BlockState; +import net.minecraft.entity.EntityType; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.attribute.EntityAttributes; +import net.minecraft.entity.effect.StatusEffect; +import net.minecraft.entity.effect.StatusEffects; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.registry.entry.RegistryEntry; +import net.minecraft.world.World; +import net.raphimc.vialegacy.api.LegacyProtocolVersion; +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.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(PlayerEntity.class) +public abstract class MixinPlayerEntity extends LivingEntity { + + @Shadow @Final private PlayerInventory inventory; + + @Shadow public abstract boolean canHarvest(BlockState state); + + protected MixinPlayerEntity(EntityType entityType, World world) { + super(entityType, world); + } + + @Redirect(method = "getBlockBreakingSpeed", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;hasStatusEffect(Lnet/minecraft/registry/entry/RegistryEntry;)Z")) + private boolean changeSpeedCalculation(PlayerEntity instance, RegistryEntry statusEffect, @Local LocalFloatRef f) { + final boolean hasMiningFatigue = instance.hasStatusEffect(statusEffect); + if (hasMiningFatigue && ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_7_6)) { + f.set(f.get() * (1.0F - (this.getStatusEffect(StatusEffects.MINING_FATIGUE).getAmplifier() + 1) * 0.2F)); + if (f.get() < 0) { + f.set(0); + } + return false; // disable original code + } + return hasMiningFatigue; + } + + @Inject(method = "getBlockBreakingSpeed", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/effect/StatusEffectUtil;hasHaste(Lnet/minecraft/entity/LivingEntity;)Z", shift = At.Shift.BEFORE)) + private void changeSpeedCalculation(BlockState block, CallbackInfoReturnable cir, @Local LocalFloatRef f) { + final float efficiency = (float) this.getAttributeValue(EntityAttributes.MINING_EFFICIENCY); + if (efficiency <= 0) { + return; + } + + final float speed = this.inventory.getBlockBreakingSpeed(block); + if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(LegacyProtocolVersion.r1_4_4tor1_4_5) && this.canHarvest(block)) { + f.set(speed + efficiency); + } else if (speed > 1F || ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(LegacyProtocolVersion.r1_4_6tor1_4_7)) { + if (!this.getMainHandStack().isEmpty()) { + if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_7_6)) { + if (speed <= 1.0 && !this.canHarvest(block)) { + f.set(speed + efficiency * 0.08F); + } else { + f.set(speed + efficiency); + } + } + } + } + } + +} \ No newline at end of file diff --git a/src/main/java/com/viaversion/viafabricplus/injection/mixin/features/interaction/attack_cooldown/MixinPlayerEntity.java b/src/main/java/com/viaversion/viafabricplus/injection/mixin/features/interaction/attack_cooldown/MixinPlayerEntity.java new file mode 100644 index 00000000..86cf3c34 --- /dev/null +++ b/src/main/java/com/viaversion/viafabricplus/injection/mixin/features/interaction/attack_cooldown/MixinPlayerEntity.java @@ -0,0 +1,42 @@ +/* + * This file is part of ViaFabricPlus - https://github.com/ViaVersion/ViaFabricPlus + * Copyright (C) 2021-2025 the original authors + * - FlorianMichael/EnZaXD + * - RK_01/RaphiMC + * Copyright (C) 2023-2025 ViaVersion and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.viaversion.viafabricplus.injection.mixin.features.interaction.attack_cooldown; + +import com.viaversion.viafabricplus.protocoltranslator.ProtocolTranslator; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; +import net.minecraft.entity.player.PlayerEntity; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(PlayerEntity.class) +public abstract class MixinPlayerEntity { + + @Inject(method = "getAttackCooldownProgress", at = @At("HEAD"), cancellable = true) + private void removeAttackCooldown(CallbackInfoReturnable ci) { + if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_8)) { + ci.setReturnValue(1F); + } + } + +} \ No newline at end of file diff --git a/src/main/java/com/viaversion/viafabricplus/injection/mixin/features/movement/constants/MixinLivingEntity.java b/src/main/java/com/viaversion/viafabricplus/injection/mixin/features/movement/constants/MixinLivingEntity.java new file mode 100644 index 00000000..58fd951d --- /dev/null +++ b/src/main/java/com/viaversion/viafabricplus/injection/mixin/features/movement/constants/MixinLivingEntity.java @@ -0,0 +1,63 @@ +/* + * This file is part of ViaFabricPlus - https://github.com/ViaVersion/ViaFabricPlus + * Copyright (C) 2021-2025 the original authors + * - FlorianMichael/EnZaXD + * - RK_01/RaphiMC + * Copyright (C) 2023-2025 ViaVersion and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.viaversion.viafabricplus.injection.mixin.features.movement.constants; + +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; +import com.viaversion.viafabricplus.protocoltranslator.ProtocolTranslator; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; +import net.minecraft.entity.LivingEntity; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Constant; +import org.spongepowered.asm.mixin.injection.ModifyConstant; + +@Mixin(LivingEntity.class) +public abstract class MixinLivingEntity { + + @ModifyExpressionValue(method = "tickStatusEffects", at = @At(value = "CONSTANT", args = "intValue=4")) + private int changeParticleDensity(int original) { + if (ProtocolTranslator.getTargetVersion().olderThan(ProtocolVersion.v1_20_5)) { + return 2; + } else { + return original; + } + } + + @ModifyConstant(method = "getBlockingItem", constant = @Constant(intValue = 5)) + private int removeBlockActionUseDelay(int constant) { + if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_8)) { + return 0; + } else { + return constant; + } + } + + @ModifyConstant(method = "tickMovement", constant = @Constant(doubleValue = 0.003D)) + private double modifyVelocityZero(double constant) { + if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_8)) { + return 0.005D; + } else { + return constant; + } + } + +} \ No newline at end of file diff --git a/src/main/java/com/viaversion/viafabricplus/injection/mixin/features/movement/constants/MixinPlayerEntity.java b/src/main/java/com/viaversion/viafabricplus/injection/mixin/features/movement/constants/MixinPlayerEntity.java index 12ff0e80..4d86e1c4 100644 --- a/src/main/java/com/viaversion/viafabricplus/injection/mixin/features/movement/constants/MixinPlayerEntity.java +++ b/src/main/java/com/viaversion/viafabricplus/injection/mixin/features/movement/constants/MixinPlayerEntity.java @@ -23,14 +23,27 @@ package com.viaversion.viafabricplus.injection.mixin.features.movement.constants import com.viaversion.viafabricplus.protocoltranslator.ProtocolTranslator; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; +import net.minecraft.entity.EntityAttachmentType; +import net.minecraft.entity.EntityAttachments; +import net.minecraft.entity.EntityDimensions; +import net.minecraft.entity.EntityPose; import net.minecraft.entity.player.PlayerEntity; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.Constant; -import org.spongepowered.asm.mixin.injection.ModifyConstant; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.*; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(PlayerEntity.class) public abstract class MixinPlayerEntity { + @Unique + private static final EntityDimensions viaFabricPlus$sneaking_dimensions_v1_13_2 = EntityDimensions.changing(0.6F, 1.65F).withEyeHeight(1.54F). + withAttachments(EntityAttachments.builder().add(EntityAttachmentType.VEHICLE, PlayerEntity.VEHICLE_ATTACHMENT_POS)); + + @Unique + private static final EntityDimensions viaFabricPlus$sneaking_dimensions_v1_8 = EntityDimensions.changing(0.6F, 1.8F).withEyeHeight(1.54F). + withAttachments(EntityAttachments.builder().add(EntityAttachmentType.VEHICLE, PlayerEntity.VEHICLE_ATTACHMENT_POS)); + @ModifyConstant(method = "isSpaceAroundPlayerEmpty", constant = @Constant(doubleValue = 9.999999747378752E-6 /* 1.0E-5F */)) private double removeOffsetWhenCheckingSneakingCollision(double constant) { if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_20_3)) { @@ -40,4 +53,24 @@ public abstract class MixinPlayerEntity { } } + @Inject(method = "getBaseDimensions", at = @At("HEAD"), cancellable = true) + private void modifyDimensions(EntityPose pose, CallbackInfoReturnable cir) { + if (pose == EntityPose.CROUCHING) { + if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_8)) { + cir.setReturnValue(viaFabricPlus$sneaking_dimensions_v1_8); + } else if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_13_2)) { + cir.setReturnValue(viaFabricPlus$sneaking_dimensions_v1_13_2); + } + } + } + + @Redirect(method = "adjustMovementForSneaking", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;getStepHeight()F")) + private float modifyStepHeight(PlayerEntity instance) { + if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_10)) { + return 1.0F; + } else { + return instance.getStepHeight(); + } + } + } \ No newline at end of file diff --git a/src/main/java/com/viaversion/viafabricplus/injection/mixin/features/movement/entity/MixinPlayerEntityRenderer.java b/src/main/java/com/viaversion/viafabricplus/injection/mixin/features/movement/constants/MixinPlayerEntityRenderer.java similarity index 99% rename from src/main/java/com/viaversion/viafabricplus/injection/mixin/features/movement/entity/MixinPlayerEntityRenderer.java rename to src/main/java/com/viaversion/viafabricplus/injection/mixin/features/movement/constants/MixinPlayerEntityRenderer.java index bad1205b..071a77cc 100644 --- a/src/main/java/com/viaversion/viafabricplus/injection/mixin/features/movement/entity/MixinPlayerEntityRenderer.java +++ b/src/main/java/com/viaversion/viafabricplus/injection/mixin/features/movement/constants/MixinPlayerEntityRenderer.java @@ -19,7 +19,7 @@ * along with this program. If not, see . */ -package com.viaversion.viafabricplus.injection.mixin.features.movement.entity; +package com.viaversion.viafabricplus.injection.mixin.features.movement.constants; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import com.viaversion.viafabricplus.protocoltranslator.ProtocolTranslator; diff --git a/src/main/java/com/viaversion/viafabricplus/injection/mixin/features/movement/entity/MixinLivingEntity.java b/src/main/java/com/viaversion/viafabricplus/injection/mixin/features/movement/entity/MixinLivingEntity.java index 996a9562..681915c1 100644 --- a/src/main/java/com/viaversion/viafabricplus/injection/mixin/features/movement/entity/MixinLivingEntity.java +++ b/src/main/java/com/viaversion/viafabricplus/injection/mixin/features/movement/entity/MixinLivingEntity.java @@ -66,15 +66,6 @@ public abstract class MixinLivingEntity extends Entity { super(type, world); } - @ModifyExpressionValue(method = "tickStatusEffects", at = @At(value = "CONSTANT", args = "intValue=4")) - private int changeParticleDensity(int original) { - if (ProtocolTranslator.getTargetVersion().olderThan(ProtocolVersion.v1_20_5)) { - return 2; - } else { - return original; - } - } - @Inject(method = "tickCramming", at = @At("HEAD"), cancellable = true) private void preventEntityPush(CallbackInfo ci) { if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_8)) { @@ -119,24 +110,6 @@ public abstract class MixinLivingEntity extends Entity { } } - @ModifyConstant(method = "getBlockingItem", constant = @Constant(intValue = 5)) - private int removeBlockActionUseDelay(int constant) { - if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_8)) { - return 0; - } else { - return constant; - } - } - - @ModifyConstant(method = "tickMovement", constant = @Constant(doubleValue = 0.003D)) - private double modifyVelocityZero(double constant) { - if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_8)) { - return 0.005D; - } else { - return constant; - } - } - @Inject(method = "canEnterTrapdoor", at = @At("HEAD"), cancellable = true) private void disableCrawling(CallbackInfoReturnable ci) { if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_8)) { diff --git a/src/main/java/com/viaversion/viafabricplus/injection/mixin/features/movement/entity/MixinPlayerEntity.java b/src/main/java/com/viaversion/viafabricplus/injection/mixin/features/movement/entity/MixinPlayerEntity.java index 7baf1885..0ed43496 100644 --- a/src/main/java/com/viaversion/viafabricplus/injection/mixin/features/movement/entity/MixinPlayerEntity.java +++ b/src/main/java/com/viaversion/viafabricplus/injection/mixin/features/movement/entity/MixinPlayerEntity.java @@ -55,21 +55,6 @@ public abstract class MixinPlayerEntity extends LivingEntity { @Final private PlayerAbilities abilities; - @Shadow - public abstract boolean canHarvest(BlockState state); - - @Shadow - @Final - PlayerInventory inventory; - - @Unique - private static final EntityDimensions viaFabricPlus$sneaking_dimensions_v1_13_2 = EntityDimensions.changing(0.6F, 1.65F).withEyeHeight(1.54F). - withAttachments(EntityAttachments.builder().add(EntityAttachmentType.VEHICLE, PlayerEntity.VEHICLE_ATTACHMENT_POS)); - - @Unique - private static final EntityDimensions viaFabricPlus$sneaking_dimensions_v1_8 = EntityDimensions.changing(0.6F, 1.8F).withEyeHeight(1.54F). - withAttachments(EntityAttachments.builder().add(EntityAttachmentType.VEHICLE, PlayerEntity.VEHICLE_ATTACHMENT_POS)); - @Unique public boolean viaFabricPlus$isSprinting; @@ -91,11 +76,6 @@ public abstract class MixinPlayerEntity extends LivingEntity { } } - @Redirect(method = "getMaxRelativeHeadRotation", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;isBlocking()Z")) - private boolean dontModifyHeadRotationWhenBlocking(PlayerEntity instance) { - return ProtocolTranslator.getTargetVersion().newerThan(ProtocolVersion.v1_20_2) && instance.isBlocking(); - } - @Inject(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;setMovementSpeed(F)V")) private void storeSprintingState(CallbackInfo ci) { viaFabricPlus$isSprinting = this.isSprinting(); @@ -110,11 +90,6 @@ public abstract class MixinPlayerEntity extends LivingEntity { } } - @WrapWithCondition(method = "dropItem(Lnet/minecraft/item/ItemStack;ZZ)Lnet/minecraft/entity/ItemEntity;", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;swingHand(Lnet/minecraft/util/Hand;)V")) - private boolean dontSwingHand(PlayerEntity instance, Hand hand) { - return ProtocolTranslator.getTargetVersion().newerThan(ProtocolVersion.v1_15_2); - } - @Inject(method = "canConsume", at = @At("HEAD"), cancellable = true) private void preventEatingFoodInCreative(boolean ignoreHunger, CallbackInfoReturnable cir) { if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_14_4) && this.abilities.invulnerable) { @@ -122,67 +97,4 @@ public abstract class MixinPlayerEntity extends LivingEntity { } } - @Inject(method = "getBaseDimensions", at = @At("HEAD"), cancellable = true) - private void modifyDimensions(EntityPose pose, CallbackInfoReturnable cir) { - if (pose == EntityPose.CROUCHING) { - if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_8)) { - cir.setReturnValue(viaFabricPlus$sneaking_dimensions_v1_8); - } else if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_13_2)) { - cir.setReturnValue(viaFabricPlus$sneaking_dimensions_v1_13_2); - } - } - } - - @Redirect(method = "adjustMovementForSneaking", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;getStepHeight()F")) - private float modifyStepHeight(PlayerEntity instance) { - if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_10)) { - return 1.0F; - } else { - return instance.getStepHeight(); - } - } - - @Inject(method = "getAttackCooldownProgress", at = @At("HEAD"), cancellable = true) - private void removeAttackCooldown(CallbackInfoReturnable ci) { - if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_8)) { - ci.setReturnValue(1F); - } - } - - @Redirect(method = "getBlockBreakingSpeed", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;hasStatusEffect(Lnet/minecraft/registry/entry/RegistryEntry;)Z")) - private boolean changeSpeedCalculation(PlayerEntity instance, RegistryEntry statusEffect, @Local LocalFloatRef f) { - final boolean hasMiningFatigue = instance.hasStatusEffect(statusEffect); - if (hasMiningFatigue && ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_7_6)) { - f.set(f.get() * (1.0F - (this.getStatusEffect(StatusEffects.MINING_FATIGUE).getAmplifier() + 1) * 0.2F)); - if (f.get() < 0) { - f.set(0); - } - return false; // disable original code - } - return hasMiningFatigue; - } - - @Inject(method = "getBlockBreakingSpeed", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/effect/StatusEffectUtil;hasHaste(Lnet/minecraft/entity/LivingEntity;)Z", shift = At.Shift.BEFORE)) - private void changeSpeedCalculation(BlockState block, CallbackInfoReturnable cir, @Local LocalFloatRef f) { - final float efficiency = (float) this.getAttributeValue(EntityAttributes.MINING_EFFICIENCY); - if (efficiency <= 0) { - return; - } - - final float speed = this.inventory.getBlockBreakingSpeed(block); - if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(LegacyProtocolVersion.r1_4_4tor1_4_5) && this.canHarvest(block)) { - f.set(speed + efficiency); - } else if (speed > 1F || ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(LegacyProtocolVersion.r1_4_6tor1_4_7)) { - if (!this.getMainHandStack().isEmpty()) { - if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_7_6)) { - if (speed <= 1.0 && !this.canHarvest(block)) { - f.set(speed + efficiency * 0.08F); - } else { - f.set(speed + efficiency); - } - } - } - } - } - } diff --git a/src/main/java/com/viaversion/viafabricplus/injection/mixin/features/movement/limitation/rotation/MixinPlayerEntity.java b/src/main/java/com/viaversion/viafabricplus/injection/mixin/features/movement/limitation/rotation/MixinPlayerEntity.java new file mode 100644 index 00000000..0566d6ce --- /dev/null +++ b/src/main/java/com/viaversion/viafabricplus/injection/mixin/features/movement/limitation/rotation/MixinPlayerEntity.java @@ -0,0 +1,39 @@ +/* + * This file is part of ViaFabricPlus - https://github.com/ViaVersion/ViaFabricPlus + * Copyright (C) 2021-2025 the original authors + * - FlorianMichael/EnZaXD + * - RK_01/RaphiMC + * Copyright (C) 2023-2025 ViaVersion and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.viaversion.viafabricplus.injection.mixin.features.movement.limitation.rotation; + +import com.viaversion.viafabricplus.protocoltranslator.ProtocolTranslator; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; +import net.minecraft.entity.player.PlayerEntity; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(PlayerEntity.class) +public abstract class MixinPlayerEntity { + + @Redirect(method = "getMaxRelativeHeadRotation", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;isBlocking()Z")) + private boolean dontModifyHeadRotationWhenBlocking(PlayerEntity instance) { + return ProtocolTranslator.getTargetVersion().newerThan(ProtocolVersion.v1_20_2) && instance.isBlocking(); + } + +} \ No newline at end of file diff --git a/src/main/java/com/viaversion/viafabricplus/injection/mixin/features/swinging/MixinPlayerEntity.java b/src/main/java/com/viaversion/viafabricplus/injection/mixin/features/swinging/MixinPlayerEntity.java new file mode 100644 index 00000000..a9b8e5d5 --- /dev/null +++ b/src/main/java/com/viaversion/viafabricplus/injection/mixin/features/swinging/MixinPlayerEntity.java @@ -0,0 +1,40 @@ +/* + * This file is part of ViaFabricPlus - https://github.com/ViaVersion/ViaFabricPlus + * Copyright (C) 2021-2025 the original authors + * - FlorianMichael/EnZaXD + * - RK_01/RaphiMC + * Copyright (C) 2023-2025 ViaVersion and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.viaversion.viafabricplus.injection.mixin.features.swinging; + +import com.llamalad7.mixinextras.injector.v2.WrapWithCondition; +import com.viaversion.viafabricplus.protocoltranslator.ProtocolTranslator; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.util.Hand; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +@Mixin(PlayerEntity.class) +public abstract class MixinPlayerEntity { + + @WrapWithCondition(method = "dropItem(Lnet/minecraft/item/ItemStack;ZZ)Lnet/minecraft/entity/ItemEntity;", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;swingHand(Lnet/minecraft/util/Hand;)V")) + private boolean dontSwingHand(PlayerEntity instance, Hand hand) { + return ProtocolTranslator.getTargetVersion().newerThan(ProtocolVersion.v1_15_2); + } + +} diff --git a/src/main/resources/viafabricplus.mixins.json b/src/main/resources/viafabricplus.mixins.json index 364c3124..dcc48fd3 100644 --- a/src/main/resources/viafabricplus.mixins.json +++ b/src/main/resources/viafabricplus.mixins.json @@ -182,13 +182,13 @@ "features.movement.collision.MixinEntity", "features.movement.collision.MixinHoneyBlock", "features.movement.collision.MixinSoulSandBlock", + "features.movement.constants.MixinPlayerEntityRenderer", "features.movement.elytra.MixinClientPlayerEntity", "features.movement.elytra.MixinFireworkRocketItem", "features.movement.elytra.MixinLivingEntity", "features.movement.elytra.MixinPlayerEntity", "features.movement.entity.MixinLivingEntity", "features.movement.entity.MixinPlayerEntity", - "features.movement.entity.MixinPlayerEntityRenderer", "features.movement.jump.MixinClientPlayerEntity", "features.movement.remove_bed_bounce.MixinBedBlock", "features.movement.slowdown_calculation.MixinClientPlayerEntity", @@ -247,17 +247,20 @@ "features.world.disable_sequencing.MixinClientWorld", "features.world.item_picking.MixinClientPlayerInteractionManager", "features.world.item_picking.MixinMinecraftClient", - "features.world.remove_server_view_distance.MixinGameOptions" + "features.world.remove_server_view_distance.MixinGameOptions", + "features.block.mining_calculation.MixinPlayerEntity", + "features.interaction.attack_cooldown.MixinPlayerEntity", + "features.movement.constants.MixinEntity", + "features.movement.constants.MixinLivingEntity", + "features.movement.constants.MixinPlayerEntity", + "features.movement.limitation.rotation.MixinEntity", + "features.movement.limitation.rotation.MixinPlayerEntity", + "features.swinging.MixinPlayerEntity" ], "injectors": { "defaultRequire": 1 }, "overwrites": { "requireAnnotations": true - }, - "mixins": [ - "features.movement.constants.MixinEntity", - "features.movement.constants.MixinPlayerEntity", - "features.movement.limitation.rotation.MixinEntity" - ] + } }