Skip to content

Commit

Permalink
More fixes to font rendering, item interactions, entity movement
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianMichael committed Oct 24, 2024
1 parent 0c04759 commit cf56d9c
Show file tree
Hide file tree
Showing 15 changed files with 135 additions and 220 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -63,10 +61,10 @@ private void filterGlyphs(int codePoint, CallbackInfoReturnable<FontStorage.Glyp
}
}

@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());
}
}

Expand All @@ -80,9 +78,9 @@ private void fixBlankGlyph1_12_2(int codePoint, CallbackInfoReturnable<FontStora
}
}

@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
Expand All @@ -104,11 +102,11 @@ private GlyphRenderer fixBlankGlyphRenderer1_12_2(FontStorage instance) {
}

@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;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
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;
Expand Down Expand Up @@ -87,19 +88,23 @@ private void dontSendEmptyItem(ClientPlayerInteractionManager instance, ItemStac
}
}

@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);
@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);
}

@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 = "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);
}

@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);
@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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -42,7 +42,7 @@ private float fixStrikethroughMinY(float value) {
}
}

@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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -35,7 +35,7 @@
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
Expand All @@ -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;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ private double dontApplyLavaMovement(LivingEntity instance, TagKey<Fluid> 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<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)) {
Expand Down
Loading

0 comments on commit cf56d9c

Please sign in to comment.