mirror of
https://github.com/ViaVersion/ViaFabricPlus.git
synced 2024-12-22 16:48:25 +01:00
More fixes to font rendering, item interactions, entity movement
This commit is contained in:
parent
15e6914c86
commit
6ef7bbb22a
@ -1,44 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
|
||||
* Copyright (C) 2021-2024 FlorianMichael/EnZaXD <florian.michael07@gmail.com> 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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<Boolean> cir) {
|
||||
if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_14_4)) {
|
||||
cir.setReturnValue(this.isAccepted());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -38,22 +38,20 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
@Mixin(FontStorage.class)
|
||||
public abstract class MixinFontStorage {
|
||||
|
||||
@Shadow
|
||||
private GlyphRenderer blankGlyphRenderer;
|
||||
|
||||
@Shadow
|
||||
protected abstract GlyphRenderer getGlyphRenderer(RenderableGlyph c);
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
private Identifier id;
|
||||
|
||||
@Unique
|
||||
private GlyphRenderer viaFabricPlus$blankGlyphRenderer1_12_2;
|
||||
@Shadow private BakedGlyph blankBakedGlyph;
|
||||
|
||||
@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))
|
||||
@Shadow protected abstract BakedGlyph bake(RenderableGlyph c);
|
||||
|
||||
@Unique
|
||||
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/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 @@ public abstract class MixinFontStorage {
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "findGlyphRenderer", at = @At("RETURN"), cancellable = true)
|
||||
private void filterGlyphRenderer(int codePoint, CallbackInfoReturnable<GlyphRenderer> cir) {
|
||||
@Inject(method = "bake(I)Lnet/minecraft/client/font/BakedGlyph;", at = @At("RETURN"), cancellable = true)
|
||||
private void filterBakedGlyph(int codePoint, CallbackInfoReturnable<BakedGlyph> cir) {
|
||||
if (this.viaFabricPlus$shouldBeInvisible(codePoint)) {
|
||||
cir.setReturnValue(this.viaFabricPlus$getBlankGlyphRenderer());
|
||||
cir.setReturnValue(this.viaFabricPlus$getBlankBakedGlyph());
|
||||
}
|
||||
}
|
||||
|
||||
@ -80,9 +78,9 @@ public abstract class MixinFontStorage {
|
||||
}
|
||||
}
|
||||
|
||||
@Redirect(method = "findGlyphRenderer", at = @At(value = "FIELD", target = "Lnet/minecraft/client/font/FontStorage;blankGlyphRenderer:Lnet/minecraft/client/font/GlyphRenderer;"))
|
||||
private GlyphRenderer fixBlankGlyphRenderer1_12_2(FontStorage instance) {
|
||||
return this.viaFabricPlus$getBlankGlyphRenderer();
|
||||
@Redirect(method = "bake(I)Lnet/minecraft/client/font/BakedGlyph;", at = @At(value = "FIELD", target = "Lnet/minecraft/client/font/FontStorage;blankBakedGlyph:Lnet/minecraft/client/font/BakedGlyph;"))
|
||||
private BakedGlyph fixBlankBakedGlyph1_12_2(FontStorage instance) {
|
||||
return this.viaFabricPlus$getBlankBakedGlyph();
|
||||
}
|
||||
|
||||
@Unique
|
||||
@ -104,11 +102,11 @@ public abstract class MixinFontStorage {
|
||||
}
|
||||
|
||||
@Unique
|
||||
private GlyphRenderer viaFabricPlus$getBlankGlyphRenderer() {
|
||||
private BakedGlyph viaFabricPlus$getBlankBakedGlyph() {
|
||||
if (VisualSettings.global().changeFontRendererBehaviour.isEnabled()) {
|
||||
return this.viaFabricPlus$blankGlyphRenderer1_12_2;
|
||||
return this.viaFabricPlus$blankBakedGlyph1_12_2;
|
||||
} else {
|
||||
return this.blankGlyphRenderer;
|
||||
return this.blankBakedGlyph;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -35,6 +35,7 @@ import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.Mouse;
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
import net.minecraft.client.network.ClientPlayerInteractionManager;
|
||||
import net.minecraft.client.render.item.HeldItemRenderer;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ActionResult;
|
||||
@ -87,21 +88,25 @@ public abstract class MixinMinecraftClient {
|
||||
}
|
||||
}
|
||||
|
||||
@Redirect(method = "doItemUse", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/ActionResult;shouldSwingHand()Z", ordinal = 0))
|
||||
private boolean disableSwing(ActionResult instance) {
|
||||
return instance.shouldSwingHand() && ProtocolTranslator.getTargetVersion().newerThanOrEqualTo(ProtocolVersion.v1_15);
|
||||
}
|
||||
|
||||
@Redirect(method = "doItemUse", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/ActionResult;shouldSwingHand()Z", ordinal = 2))
|
||||
private boolean disableSwing2(ActionResult instance) {
|
||||
return instance.shouldSwingHand() && ProtocolTranslator.getTargetVersion().newerThanOrEqualTo(ProtocolVersion.v1_15);
|
||||
}
|
||||
|
||||
@WrapWithCondition(method = "handleInputEvents", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;swingHand(Lnet/minecraft/util/Hand;)V"))
|
||||
private boolean disableSwing(ClientPlayerEntity instance, Hand hand) {
|
||||
return ProtocolTranslator.getTargetVersion().newerThanOrEqualTo(ProtocolVersion.v1_15);
|
||||
}
|
||||
|
||||
@WrapWithCondition(method = "doItemUse", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/item/HeldItemRenderer;resetEquipProgress(Lnet/minecraft/util/Hand;)V"))
|
||||
private boolean disableSwing2(HeldItemRenderer instance, Hand hand) {
|
||||
return ProtocolTranslator.getTargetVersion().newerThanOrEqualTo(ProtocolVersion.v1_15);
|
||||
}
|
||||
|
||||
@Redirect(method = "doItemUse", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/ActionResult$Success;swingSource()Lnet/minecraft/util/ActionResult$SwingSource;"))
|
||||
private ActionResult.SwingSource swingWhenConsume(ActionResult.Success instance) {
|
||||
if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_14_4) && instance.isAccepted()) {
|
||||
return ActionResult.SwingSource.CLIENT;
|
||||
} else {
|
||||
return instance.swingSource();
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "tick",
|
||||
at = @At(value = "FIELD", target = "Lnet/minecraft/client/MinecraftClient;currentScreen:Lnet/minecraft/client/gui/screen/Screen;", ordinal = 0, shift = At.Shift.BEFORE),
|
||||
slice = @Slice(
|
||||
|
@ -54,20 +54,21 @@ public abstract class MixinTextRenderer {
|
||||
@Final
|
||||
public int fontHeight;
|
||||
|
||||
@Shadow
|
||||
protected abstract int drawInternal(OrderedText text, float x, float y, int color, boolean shadow, Matrix4f matrix, VertexConsumerProvider vertexConsumers, TextRenderer.TextLayerType layerType, int backgroundColor, int light);
|
||||
|
||||
@Shadow
|
||||
public abstract int getWidth(OrderedText text);
|
||||
|
||||
@Inject(method = "draw(Ljava/lang/String;FFIZLorg/joml/Matrix4f;Lnet/minecraft/client/render/VertexConsumerProvider;Lnet/minecraft/client/font/TextRenderer$TextLayerType;IIZ)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, boolean rightToLeft, CallbackInfoReturnable<Integer> 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<Integer> cir) {
|
||||
if (ProtocolTranslator.getTargetVersion() == BedrockProtocolVersion.bedrockLatest) {
|
||||
final List<OrderedText> lines = wrapLines(StringVisitable.plain(rightToLeft ? this.mirror(text) : text), Integer.MAX_VALUE);
|
||||
final List<OrderedText> 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);
|
||||
}
|
||||
|
@ -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;<init>(FFFFFFFFF)V", ordinal = 0), index = 1)
|
||||
@ModifyArg(method = "accept", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/font/BakedGlyph$Rectangle;<init>(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 @@ public abstract class MixinTextRenderer_Drawer {
|
||||
}
|
||||
}
|
||||
|
||||
@ModifyArg(method = "accept", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/font/GlyphRenderer$Rectangle;<init>(FFFFFFFFF)V", ordinal = 0), index = 3)
|
||||
@ModifyArg(method = "accept", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/font/BakedGlyph$Rectangle;<init>(FFFFFI)V", ordinal = 0), index = 3)
|
||||
private float fixStrikethroughMaxY(float value) {
|
||||
if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_12_2)) {
|
||||
return value - viaFabricPlus$offset;
|
||||
|
@ -22,18 +22,23 @@ package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.block;
|
||||
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 @@ public abstract class MixinFenceBlock extends HorizontalConnectingBlock {
|
||||
super(radius1, radius2, boundingHeight1, boundingHeight2, collisionHeight, settings);
|
||||
}
|
||||
|
||||
@Inject(method = "onUseWithItem", at = @At("HEAD"), cancellable = true)
|
||||
private void alwaysSuccess(CallbackInfoReturnable<ActionResult> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@ import de.florianmichael.viafabricplus.protocoltranslator.ProtocolTranslator;
|
||||
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.Redirect;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(BipedEntityModel.class)
|
||||
public abstract class MixinBipedEntityModel<T extends LivingEntity> {
|
||||
public abstract class MixinBipedEntityModel<T extends BipedEntityRenderState> {
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
@ -54,14 +54,17 @@ public abstract class MixinBipedEntityModel<T extends LivingEntity> {
|
||||
}
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -153,6 +153,11 @@ public abstract class MixinLivingEntity extends Entity {
|
||||
}
|
||||
}
|
||||
|
||||
@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<StatusEffect> 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)) {
|
||||
|
@ -34,7 +34,6 @@ import net.minecraft.entity.effect.StatusEffects;
|
||||
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 @@ public abstract class MixinPlayerEntity extends LivingEntity {
|
||||
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<StatusEffect> 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<Boolean> cir) {
|
||||
if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_14_4) && this.abilities.invulnerable) {
|
||||
@ -128,12 +122,12 @@ public abstract class MixinPlayerEntity extends LivingEntity {
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "checkFallFlying", at = @At("HEAD"), cancellable = true)
|
||||
private void replaceFallFlyingCondition(CallbackInfoReturnable<Boolean> cir) {
|
||||
@Inject(method = "checkGliding", at = @At("HEAD"), cancellable = true)
|
||||
private void replaceGlidingCondition(CallbackInfoReturnable<Boolean> 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 @@ public abstract class MixinPlayerEntity extends LivingEntity {
|
||||
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 @@ public abstract class MixinPlayerEntity extends LivingEntity {
|
||||
|
||||
@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<Float> 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);
|
||||
|
@ -23,6 +23,7 @@ import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
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 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
@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<Vec3d> 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<Vec3d> 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 @@ public abstract class MixinPlayerEntityRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
|
||||
* Copyright (C) 2021-2024 FlorianMichael/EnZaXD <florian.michael07@gmail.com> 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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<ActionResult> 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<AttributeModifiersComponent> cir) {
|
||||
if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_8)) {
|
||||
cir.setReturnValue(super.getAttributeModifiers());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -30,12 +30,12 @@ import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
@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;
|
||||
|
@ -21,39 +21,43 @@ 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.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<TypedActionResult<ItemStack>> cir) {
|
||||
@Inject(method = "equip", at = @At("HEAD"), cancellable = true)
|
||||
private void cancelArmorSwap(ItemStack stack, PlayerEntity player, CallbackInfoReturnable<ActionResult> 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -17,29 +17,29 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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<ItemStack> 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<ItemStack> cir) {
|
||||
// if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_20_5)) {
|
||||
// stack.decrementUnlessCreative(1, user);
|
||||
// cir.setReturnValue(stack.isEmpty() ? new ItemStack(Items.BUCKET) : stack);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user