From cf56d9c9140a5f53f679f6ca5e665714ee39c52a Mon Sep 17 00:00:00 2001 From: FlorianMichael Date: Fri, 25 Oct 2024 01:20:03 +0200 Subject: [PATCH] More fixes to font rendering, item interactions, entity movement --- .../fixes/minecraft/MixinActionResult.java | 44 -------------- .../fixes/minecraft/MixinFontStorage.java | 34 +++++------ .../fixes/minecraft/MixinMinecraftClient.java | 23 +++++--- .../fixes/minecraft/MixinTextRenderer.java | 15 ++--- .../minecraft/MixinTextRenderer_Drawer.java | 4 +- .../minecraft/block/MixinFenceBlock.java | 19 ++++-- .../entity/MixinBipedEntityModel.java | 19 +++--- .../minecraft/entity/MixinLivingEntity.java | 5 ++ .../minecraft/entity/MixinPlayerEntity.java | 20 +++---- .../entity/MixinPlayerEntityRenderer.java | 17 +++--- .../fixes/minecraft/item/MixinArmorItem.java | 58 ------------------- .../minecraft/item/MixinDrawContext.java | 4 +- ...ent.java => MixinEquippableComponent.java} | 36 +++++++----- .../minecraft/item/MixinMilkBucketItem.java | 52 ++++++++--------- src/main/resources/viafabricplus.mixins.json | 5 +- 15 files changed, 135 insertions(+), 220 deletions(-) delete mode 100644 src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/MixinActionResult.java delete mode 100644 src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinArmorItem.java rename src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/{MixinEquipment.java => MixinEquippableComponent.java} (63%) diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/MixinActionResult.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/MixinActionResult.java deleted file mode 100644 index cffc19d46..000000000 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/MixinActionResult.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus - * Copyright (C) 2021-2024 FlorianMichael/EnZaXD and RK_01/RaphiMC - * Copyright (C) 2023-2024 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 de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft; - -import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; -import de.florianmichael.viafabricplus.protocoltranslator.ProtocolTranslator; -import net.minecraft.util.ActionResult; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(ActionResult.class) -public abstract class MixinActionResult { - - @Shadow - public abstract boolean isAccepted(); - - @Inject(method = "shouldSwingHand", at = @At("HEAD"), cancellable = true) - private void swingWhenConsume(CallbackInfoReturnable cir) { - if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_14_4)) { - cir.setReturnValue(this.isAccepted()); - } - } - -} diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/MixinFontStorage.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/MixinFontStorage.java index d969a9876..581e54005 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/MixinFontStorage.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/MixinFontStorage.java @@ -38,22 +38,20 @@ @Mixin(FontStorage.class) public abstract class MixinFontStorage { - @Shadow - private GlyphRenderer blankGlyphRenderer; - - @Shadow - protected abstract GlyphRenderer getGlyphRenderer(RenderableGlyph c); - @Shadow @Final private Identifier id; + @Shadow private BakedGlyph blankBakedGlyph; + + @Shadow protected abstract BakedGlyph bake(RenderableGlyph c); + @Unique - private GlyphRenderer viaFabricPlus$blankGlyphRenderer1_12_2; + private BakedGlyph viaFabricPlus$blankBakedGlyph1_12_2; - @Inject(method = "clear", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/font/BuiltinEmptyGlyph;bake(Ljava/util/function/Function;)Lnet/minecraft/client/font/GlyphRenderer;", ordinal = 0)) + @Inject(method = "clear", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/font/BuiltinEmptyGlyph;bake(Ljava/util/function/Function;)Lnet/minecraft/client/font/BakedGlyph;", ordinal = 0)) private void bakeBlankGlyph1_12_2(CallbackInfo ci) { - this.viaFabricPlus$blankGlyphRenderer1_12_2 = BuiltinEmptyGlyph1_12_2.INSTANCE.bake(this::getGlyphRenderer); + this.viaFabricPlus$blankBakedGlyph1_12_2 = BuiltinEmptyGlyph1_12_2.INSTANCE.bake(this::bake); } @Inject(method = "findGlyph", at = @At("RETURN"), cancellable = true) @@ -63,10 +61,10 @@ private void filterGlyphs(int codePoint, CallbackInfoReturnable cir) { + @Inject(method = "bake(I)Lnet/minecraft/client/font/BakedGlyph;", at = @At("RETURN"), cancellable = true) + private void filterBakedGlyph(int codePoint, CallbackInfoReturnable cir) { if (this.viaFabricPlus$shouldBeInvisible(codePoint)) { - cir.setReturnValue(this.viaFabricPlus$getBlankGlyphRenderer()); + cir.setReturnValue(this.viaFabricPlus$getBlankBakedGlyph()); } } @@ -80,9 +78,9 @@ private void fixBlankGlyph1_12_2(int codePoint, CallbackInfoReturnable cir) { + @Shadow public abstract boolean isRightToLeft(); + + @Shadow protected abstract int drawInternal(OrderedText text, float x, float y, int color, boolean shadow, Matrix4f matrix, VertexConsumerProvider vertexConsumerProvider, TextRenderer.TextLayerType layerType, int backgroundColor, int light, boolean swapZIndex); + + @Inject(method = "draw(Ljava/lang/String;FFIZLorg/joml/Matrix4f;Lnet/minecraft/client/render/VertexConsumerProvider;Lnet/minecraft/client/font/TextRenderer$TextLayerType;II)I", at = @At("HEAD"), cancellable = true) + private void allowNewLines_String(String text, float x, float y, int color, boolean shadow, Matrix4f matrix, VertexConsumerProvider vertexConsumers, TextRenderer.TextLayerType layerType, int backgroundColor, int light, CallbackInfoReturnable cir) { if (ProtocolTranslator.getTargetVersion() == BedrockProtocolVersion.bedrockLatest) { - final List lines = wrapLines(StringVisitable.plain(rightToLeft ? this.mirror(text) : text), Integer.MAX_VALUE); + final List lines = wrapLines(StringVisitable.plain(isRightToLeft() ? this.mirror(text) : text), Integer.MAX_VALUE); if (lines.size() > 1) { int offsetX = 0; for (int i = 0; i < lines.size(); i++) { - offsetX = this.drawInternal(lines.get(i), x, y - (lines.size() * (fontHeight + 2)) + (i * (fontHeight + 2)), color, shadow, new Matrix4f(matrix), vertexConsumers, layerType, backgroundColor, light); + offsetX = this.drawInternal(lines.get(i), x, y - (lines.size() * (fontHeight + 2)) + (i * (fontHeight + 2)), color, shadow, new Matrix4f(matrix), vertexConsumers, layerType, backgroundColor, light, true); } cir.setReturnValue(offsetX); } diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/MixinTextRenderer_Drawer.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/MixinTextRenderer_Drawer.java index 99e3d0055..f2f3a3adf 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/MixinTextRenderer_Drawer.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/MixinTextRenderer_Drawer.java @@ -33,7 +33,7 @@ public abstract class MixinTextRenderer_Drawer { @Unique private static final float viaFabricPlus$offset = 0.5F; // Magical offset to revert the changes done in 1.13 pre6->1.13 pre7 - @ModifyArg(method = "accept", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/font/GlyphRenderer$Rectangle;(FFFFFFFFF)V", ordinal = 0), index = 1) + @ModifyArg(method = "accept", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/font/BakedGlyph$Rectangle;(FFFFFI)V", ordinal = 0), index = 1) private float fixStrikethroughMinY(float value) { if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_12_2)) { return value - viaFabricPlus$offset; @@ -42,7 +42,7 @@ private float fixStrikethroughMinY(float value) { } } - @ModifyArg(method = "accept", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/font/GlyphRenderer$Rectangle;(FFFFFFFFF)V", ordinal = 0), index = 3) + @ModifyArg(method = "accept", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/font/BakedGlyph$Rectangle;(FFFFFI)V", ordinal = 0), index = 3) private float fixStrikethroughMaxY(float value) { if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_12_2)) { return value - viaFabricPlus$offset; diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/block/MixinFenceBlock.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/block/MixinFenceBlock.java index 918b8677d..cf13b8a7a 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/block/MixinFenceBlock.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/block/MixinFenceBlock.java @@ -22,18 +22,23 @@ import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import de.florianmichael.viafabricplus.protocoltranslator.ProtocolTranslator; import net.minecraft.block.*; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; import net.minecraft.util.ActionResult; +import net.minecraft.util.Hand; +import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; import net.minecraft.util.shape.VoxelShape; import net.minecraft.util.shape.VoxelShapes; import net.minecraft.world.BlockView; +import net.minecraft.world.World; import net.raphimc.vialegacy.api.LegacyProtocolVersion; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(FenceBlock.class) public abstract class MixinFenceBlock extends HorizontalConnectingBlock { @@ -51,10 +56,14 @@ protected MixinFenceBlock(float radius1, float radius2, float boundingHeight1, f super(radius1, radius2, boundingHeight1, boundingHeight2, collisionHeight, settings); } - @Inject(method = "onUseWithItem", at = @At("HEAD"), cancellable = true) - private void alwaysSuccess(CallbackInfoReturnable cir) { - if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_10)) { - cir.setReturnValue(ActionResult.SUCCESS); + @Override + protected ActionResult onUseWithItem(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { + if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_12_1)) { + return stack.isOf(Items.LEAD) ? ActionResult.SUCCESS : ActionResult.PASS; + } else if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_10)) { + return ActionResult.SUCCESS; + } else { + return super.onUseWithItem(stack, state, world, pos, player, hand, hit); } } diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/entity/MixinBipedEntityModel.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/entity/MixinBipedEntityModel.java index 86bd3fb4d..53f8e7c50 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/entity/MixinBipedEntityModel.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/entity/MixinBipedEntityModel.java @@ -24,7 +24,7 @@ import de.florianmichael.viafabricplus.settings.impl.VisualSettings; import net.minecraft.client.model.ModelPart; import net.minecraft.client.render.entity.model.BipedEntityModel; -import net.minecraft.entity.LivingEntity; +import net.minecraft.client.render.entity.state.BipedEntityRenderState; import net.minecraft.util.math.MathHelper; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -35,7 +35,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(BipedEntityModel.class) -public abstract class MixinBipedEntityModel { +public abstract class MixinBipedEntityModel { @Shadow @Final @@ -54,14 +54,17 @@ private float preventArmFollowingThirdPersonRotation(float value, float min, flo } } - @Inject(method = "setAngles(Lnet/minecraft/entity/LivingEntity;FFFFF)V", at = @At(value = "FIELD", target = "Lnet/minecraft/client/model/ModelPart;roll:F", ordinal = 1, shift = At.Shift.AFTER)) - private void addOldWalkAnimation(T livingEntity, float f, float g, float h, float i, float j, CallbackInfo ci) { + @Inject(method = "setAngles(Lnet/minecraft/client/render/entity/state/BipedEntityRenderState;)V", at = @At(value = "FIELD", target = "Lnet/minecraft/client/model/ModelPart;roll:F", ordinal = 1, shift = At.Shift.AFTER)) + private void addOldWalkAnimation(T bipedEntityRenderState, CallbackInfo ci) { if (VisualSettings.global().oldWalkingAnimation.isEnabled()) { - this.rightArm.pitch = MathHelper.cos(f * 0.6662F + 3.1415927F) * 2.0F * g; - this.rightArm.roll = (MathHelper.cos(f * 0.2312F) + 1.0F) * 1.0F * g; + final float limbFrequency = bipedEntityRenderState.limbFrequency; + final float limbAmplitudeMultiplier = bipedEntityRenderState.limbAmplitudeMultiplier; - this.leftArm.pitch = MathHelper.cos(f * 0.6662F) * 2.0F * g; - this.leftArm.roll = (MathHelper.cos(f * 0.2812F) - 1.0F) * 1.0F * g; + this.rightArm.pitch = MathHelper.cos(limbFrequency * 0.6662F + 3.1415927F) * 2.0F * limbAmplitudeMultiplier; + this.rightArm.roll = (MathHelper.cos(limbFrequency * 0.2312F) + 1.0F) * 1.0F * limbAmplitudeMultiplier; + + this.leftArm.pitch = MathHelper.cos(limbFrequency * 0.6662F) * 2.0F * limbAmplitudeMultiplier; + this.leftArm.roll = (MathHelper.cos(limbFrequency * 0.2812F) - 1.0F) * 1.0F * limbAmplitudeMultiplier; } } diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/entity/MixinLivingEntity.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/entity/MixinLivingEntity.java index 922e4ce38..c5d77c832 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/entity/MixinLivingEntity.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/entity/MixinLivingEntity.java @@ -153,6 +153,11 @@ private double dontApplyLavaMovement(LivingEntity instance, TagKey tagKey } } + @Redirect(method = "canGlide", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;hasStatusEffect(Lnet/minecraft/registry/entry/RegistryEntry;)Z")) + private boolean allowElytraWhenLevitating(LivingEntity instance, RegistryEntry effect) { + return ProtocolTranslator.getTargetVersion().newerThan(ProtocolVersion.v1_15_2) && instance.hasStatusEffect(effect); + } + @Redirect(method = "travel", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;isChunkLoaded(Lnet/minecraft/util/math/BlockPos;)Z")) private boolean modifyLoadedCheck(World instance, BlockPos blockPos) { if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_13_2)) { diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/entity/MixinPlayerEntity.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/entity/MixinPlayerEntity.java index 39be92061..8168775f8 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/entity/MixinPlayerEntity.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/entity/MixinPlayerEntity.java @@ -34,7 +34,6 @@ import net.minecraft.entity.player.PlayerAbilities; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.item.ElytraItem; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.registry.entry.RegistryEntry; @@ -116,11 +115,6 @@ private boolean dontSwingHand(PlayerEntity instance, Hand hand) { return ProtocolTranslator.getTargetVersion().newerThan(ProtocolVersion.v1_15_2); } - @Redirect(method = "checkFallFlying", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;hasStatusEffect(Lnet/minecraft/registry/entry/RegistryEntry;)Z")) - private boolean allowElytraWhenLevitating(PlayerEntity instance, RegistryEntry registryEntry) { - return ProtocolTranslator.getTargetVersion().newerThan(ProtocolVersion.v1_15_2) && instance.hasStatusEffect(registryEntry); - } - @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) { @@ -128,12 +122,12 @@ private void preventEatingFoodInCreative(boolean ignoreHunger, CallbackInfoRetur } } - @Inject(method = "checkFallFlying", at = @At("HEAD"), cancellable = true) - private void replaceFallFlyingCondition(CallbackInfoReturnable cir) { + @Inject(method = "checkGliding", at = @At("HEAD"), cancellable = true) + private void replaceGlidingCondition(CallbackInfoReturnable cir) { if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_14_4)) { - if (!this.isOnGround() && this.getVelocity().y < 0D && !this.isFallFlying()) { + if (!this.isOnGround() && this.getVelocity().y < 0D && !this.isGliding()) { final ItemStack itemStack = this.getEquippedStack(EquipmentSlot.CHEST); - if (itemStack.isOf(Items.ELYTRA) && ElytraItem.isUsable(itemStack)) { + if (itemStack.isOf(Items.ELYTRA) && canGlideWith(itemStack, EquipmentSlot.CHEST)) { cir.setReturnValue(true); return; } @@ -146,8 +140,8 @@ private void replaceFallFlyingCondition(CallbackInfoReturnable cir) { private void onUpdatePose(CallbackInfo ci) { if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_13_2)) { final EntityPose pose; - if (this.isFallFlying()) { - pose = EntityPose.FALL_FLYING; + if (this.isGliding()) { + pose = EntityPose.GLIDING; } else if (this.isSleeping()) { pose = EntityPose.SLEEPING; } else if (this.isSwimming()) { @@ -204,7 +198,7 @@ private boolean changeSpeedCalculation(PlayerEntity instance, RegistryEntry cir, @Local LocalFloatRef f) { - final float efficiency = (float) this.getAttributeValue(EntityAttributes.PLAYER_MINING_EFFICIENCY); + final float efficiency = (float) this.getAttributeValue(EntityAttributes.MINING_EFFICIENCY); if (efficiency <= 0) return; final float speed = this.inventory.getBlockBreakingSpeed(block); diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/entity/MixinPlayerEntityRenderer.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/entity/MixinPlayerEntityRenderer.java index 985166d3b..dfc0ac09c 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/entity/MixinPlayerEntityRenderer.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/entity/MixinPlayerEntityRenderer.java @@ -23,6 +23,7 @@ import de.florianmichael.viafabricplus.protocoltranslator.ProtocolTranslator; import net.minecraft.client.network.AbstractClientPlayerEntity; import net.minecraft.client.render.entity.PlayerEntityRenderer; +import net.minecraft.client.render.entity.state.PlayerEntityRenderState; import net.minecraft.entity.EntityPose; import net.minecraft.util.math.Direction; import net.minecraft.util.math.Vec3d; @@ -36,10 +37,10 @@ @Mixin(PlayerEntityRenderer.class) public abstract class MixinPlayerEntityRenderer { - @Inject(method = "getPositionOffset(Lnet/minecraft/client/network/AbstractClientPlayerEntity;F)Lnet/minecraft/util/math/Vec3d;", at = @At("RETURN"), cancellable = true) - private void modifySleepingOffset(AbstractClientPlayerEntity player, float delta, CallbackInfoReturnable cir) { - if (player.getPose() == EntityPose.SLEEPING) { - final Direction sleepingDir = player.getSleepingDirection(); + @Inject(method = "getPositionOffset(Lnet/minecraft/client/render/entity/state/PlayerEntityRenderState;)Lnet/minecraft/util/math/Vec3d;", at = @At("RETURN"), cancellable = true) + private void modifySleepingOffset(PlayerEntityRenderState playerEntityRenderState, CallbackInfoReturnable cir) { + if (playerEntityRenderState.pose == EntityPose.SLEEPING) { + final Direction sleepingDir = playerEntityRenderState.sleepingDirection; if (sleepingDir != null) { if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_13_2)) { cir.setReturnValue(cir.getReturnValue().subtract(sleepingDir.getOffsetX() * 0.4, 0, sleepingDir.getOffsetZ() * 0.4)); @@ -54,10 +55,10 @@ private void modifySleepingOffset(AbstractClientPlayerEntity player, float delta } } - @Redirect(method = "getPositionOffset(Lnet/minecraft/client/network/AbstractClientPlayerEntity;F)Lnet/minecraft/util/math/Vec3d;", - at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/AbstractClientPlayerEntity;isInSneakingPose()Z")) - private boolean disableSneakPositionOffset(AbstractClientPlayerEntity player) { - return ProtocolTranslator.getTargetVersion().newerThan(ProtocolVersion.v1_11_1) && player.isInSneakingPose(); + @Redirect(method = "getPositionOffset(Lnet/minecraft/client/render/entity/state/PlayerEntityRenderState;)Lnet/minecraft/util/math/Vec3d;", + at = @At(value = "FIELD", target = "Lnet/minecraft/client/render/entity/state/PlayerEntityRenderState;isInSneakingPose:Z")) + private boolean disableSneakPositionOffset(PlayerEntityRenderState instance) { + return ProtocolTranslator.getTargetVersion().newerThan(ProtocolVersion.v1_11_1) && instance.isInSneakingPose; } } diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinArmorItem.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinArmorItem.java deleted file mode 100644 index 2bff637e6..000000000 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinArmorItem.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus - * Copyright (C) 2021-2024 FlorianMichael/EnZaXD and RK_01/RaphiMC - * Copyright (C) 2023-2024 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 de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.item; - -import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; -import de.florianmichael.viafabricplus.protocoltranslator.ProtocolTranslator; -import net.minecraft.component.type.AttributeModifiersComponent; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ArmorItem; -import net.minecraft.item.Item; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.world.World; -import net.raphimc.vialegacy.api.LegacyProtocolVersion; -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(ArmorItem.class) -public abstract class MixinArmorItem extends Item { - - public MixinArmorItem(Settings settings) { - super(settings); - } - - @Inject(method = "use", at = @At("HEAD"), cancellable = true) - private void disableRightClick(World world, PlayerEntity user, Hand hand, CallbackInfoReturnable cir) { - if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(LegacyProtocolVersion.r1_4_6tor1_4_7)) { - cir.setReturnValue(ActionResult.FAIL); - } - } - - @Inject(method = "getAttributeModifiers", at = @At("HEAD"), cancellable = true) - private void changeAttributeModifiers(CallbackInfoReturnable cir) { - if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_8)) { - cir.setReturnValue(super.getAttributeModifiers()); - } - } - -} diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinDrawContext.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinDrawContext.java index 1d0f5a2f7..ff0462412 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinDrawContext.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinDrawContext.java @@ -30,12 +30,12 @@ @Mixin(DrawContext.class) public abstract class MixinDrawContext { - @Redirect(method = "drawItemInSlot(Lnet/minecraft/client/font/TextRenderer;Lnet/minecraft/item/ItemStack;IILjava/lang/String;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;getCount()I")) + @Redirect(method = "drawStackCount", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;getCount()I")) private int handleNegativeItemCount(ItemStack instance) { return ItemUtil.getCount(instance); } - @Redirect(method = "drawItemInSlot(Lnet/minecraft/client/font/TextRenderer;Lnet/minecraft/item/ItemStack;IILjava/lang/String;)V", at = @At(value = "INVOKE", target = "Ljava/lang/String;valueOf(I)Ljava/lang/String;", remap = false)) + @Redirect(method = "drawStackCount", at = @At(value = "INVOKE", target = "Ljava/lang/String;valueOf(I)Ljava/lang/String;", remap = false)) private String makeTextRed(int count) { if (count <= 0) { return Formatting.RED.toString() + count; diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinEquipment.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinEquippableComponent.java similarity index 63% rename from src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinEquipment.java rename to src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinEquippableComponent.java index 3b1f68187..15d1733ca 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinEquipment.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinEquippableComponent.java @@ -21,39 +21,43 @@ import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import de.florianmichael.viafabricplus.protocoltranslator.ProtocolTranslator; +import net.minecraft.component.type.EquippableComponent; import net.minecraft.entity.EquipmentSlot; import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.Equipment; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.util.Hand; -import net.minecraft.util.TypedActionResult; -import net.minecraft.world.World; +import net.minecraft.util.ActionResult; +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(Equipment.class) -public interface MixinEquipment { +@Mixin(EquippableComponent.class) +public class MixinEquippableComponent { - @Redirect(method = "equipAndSwap", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;isCreative()Z")) - default boolean removeCreativeCondition(PlayerEntity instance) { + @Shadow + @Final + private EquipmentSlot slot; + + @Redirect(method = "equip", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;isCreative()Z")) + private boolean removeCreativeCondition(PlayerEntity instance) { return ProtocolTranslator.getTargetVersion().newerThan(ProtocolVersion.v1_20) && instance.isCreative(); } - @Inject(method = "equipAndSwap", at = @At("HEAD"), cancellable = true) - private void cancelArmorSwap(Item item, World world, PlayerEntity user, Hand hand, CallbackInfoReturnable> cir) { + @Inject(method = "equip", at = @At("HEAD"), cancellable = true) + private void cancelArmorSwap(ItemStack stack, PlayerEntity player, CallbackInfoReturnable cir) { if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_19_3)) { - final ItemStack heldItem = user.getStackInHand(hand); - final EquipmentSlot targetSlot = user.getPreferredEquipmentSlot(heldItem); - final ItemStack targetItem = user.getEquippedStack(targetSlot); - + final ItemStack targetItem = player.getEquippedStack(this.slot); if (!targetItem.isEmpty()) { - cir.setReturnValue(TypedActionResult.fail(heldItem)); + cir.setReturnValue(ActionResult.FAIL); } } + if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(LegacyProtocolVersion.r1_4_6tor1_4_7)) { + cir.setReturnValue(ActionResult.FAIL); + } } } diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinMilkBucketItem.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinMilkBucketItem.java index 9e53d4b2e..c7209951a 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinMilkBucketItem.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinMilkBucketItem.java @@ -17,29 +17,29 @@ * along with this program. If not, see . */ -package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.item; - -import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; -import de.florianmichael.viafabricplus.protocoltranslator.ProtocolTranslator; -import net.minecraft.entity.LivingEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.item.MilkBucketItem; -import net.minecraft.world.World; -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(MilkBucketItem.class) -public abstract class MixinMilkBucketItem { - - @Inject(method = "finishUsing", at = @At("HEAD"), cancellable = true) - private void dontExchangeStack(ItemStack stack, World world, LivingEntity user, CallbackInfoReturnable cir) { - if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_20_5)) { - stack.decrementUnlessCreative(1, user); - cir.setReturnValue(stack.isEmpty() ? new ItemStack(Items.BUCKET) : stack); - } - } - -} +//package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.item; +// +//import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; +//import de.florianmichael.viafabricplus.protocoltranslator.ProtocolTranslator; +//import net.minecraft.entity.LivingEntity; +//import net.minecraft.item.ItemStack; +//import net.minecraft.item.Items; +//import net.minecraft.item.MilkBucketItem; +//import net.minecraft.world.World; +//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(MilkBucketItem.class) +//public abstract class MixinMilkBucketItem { +// +// @Inject(method = "finishUsing", at = @At("HEAD"), cancellable = true) +// private void dontExchangeStack(ItemStack stack, World world, LivingEntity user, CallbackInfoReturnable cir) { +// if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_20_5)) { +// stack.decrementUnlessCreative(1, user); +// cir.setReturnValue(stack.isEmpty() ? new ItemStack(Items.BUCKET) : stack); +// } +// } +// +//} diff --git a/src/main/resources/viafabricplus.mixins.json b/src/main/resources/viafabricplus.mixins.json index 861a8f32a..e26f98203 100644 --- a/src/main/resources/viafabricplus.mixins.json +++ b/src/main/resources/viafabricplus.mixins.json @@ -37,7 +37,6 @@ "compat.minecraftauth.MixinDefaultJwtParserBuilder", "fixes.authlib.MixinKeyPairResponse", "fixes.authlib.MixinYggdrasilUserApiService", - "fixes.minecraft.MixinActionResult", "fixes.minecraft.MixinAllowedAddressResolver", "fixes.minecraft.MixinBuiltChunk", "fixes.minecraft.MixinCamera", @@ -123,7 +122,6 @@ "fixes.minecraft.entity.MixinSkeletonHorseEntity", "fixes.minecraft.entity.MixinSquidEntity", "fixes.minecraft.entity.MixinWolfEntity", - "fixes.minecraft.item.MixinArmorItem", "fixes.minecraft.item.MixinAxeItem", "fixes.minecraft.item.MixinBlockItem", "fixes.minecraft.item.MixinBowItem", @@ -131,7 +129,7 @@ "fixes.minecraft.item.MixinBucketItem", "fixes.minecraft.item.MixinDrawContext", "fixes.minecraft.item.MixinEnderPearlItem", - "fixes.minecraft.item.MixinEquipment", + "fixes.minecraft.item.MixinEquippableComponent", "fixes.minecraft.item.MixinFireChargeItem", "fixes.minecraft.item.MixinFireworkRocketItem", "fixes.minecraft.item.MixinFishingRodItem", @@ -143,7 +141,6 @@ "fixes.minecraft.item.MixinItemRenderer", "fixes.minecraft.item.MixinItemStack", "fixes.minecraft.item.MixinKnowledgeBookItem", - "fixes.minecraft.item.MixinMilkBucketItem", "fixes.minecraft.item.MixinShovelItem", "fixes.minecraft.item.MixinSwordItem", "fixes.minecraft.network.MixinChatMessageC2SPacket",