From 8aca0ea93562df058291cb162d138c174e69ac85 Mon Sep 17 00:00:00 2001 From: FlorianMichael <60033407+FlorianMichael@users.noreply.github.com> Date: Mon, 18 Sep 2023 17:02:21 +0200 Subject: [PATCH 1/4] Fixed Anvil block shape not rendering properly in <= 1.12.2 Fixed https://github.com/ViaVersion/ViaFabricPlus/issues/246 --- .../minecraft/block/MixinAnvilBlock.java | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/block/MixinAnvilBlock.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/block/MixinAnvilBlock.java index 4f9adfbb..c43560ba 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/block/MixinAnvilBlock.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/block/MixinAnvilBlock.java @@ -17,13 +17,10 @@ */ package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.block; +import net.minecraft.block.*; import net.raphimc.vialoader.util.VersionEnum; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import de.florianmichael.viafabricplus.protocolhack.ProtocolHack; -import net.minecraft.block.AnvilBlock; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.ShapeContext; import net.minecraft.state.property.DirectionProperty; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; @@ -38,7 +35,7 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(AnvilBlock.class) -public class MixinAnvilBlock { +public class MixinAnvilBlock extends FallingBlock { @Unique private final static VoxelShape viafabricplus_x_axis_shape_v1_12_2 = Block.createCuboidShape(0, 0, 2, 16, 16, 14); @@ -50,10 +47,27 @@ public class MixinAnvilBlock { @Final public static DirectionProperty FACING; + public MixinAnvilBlock(Settings settings) { + super(settings); + } + + @Unique + private boolean viafabricplus_requireOriginalShape; + @Inject(method = "getOutlineShape", at = @At("HEAD"), cancellable = true) public void injectGetOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context, CallbackInfoReturnable cir) { + if (viafabricplus_requireOriginalShape) { + viafabricplus_requireOriginalShape = false; + return; + } if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_12_2)) { cir.setReturnValue(state.get(FACING).getAxis() == Direction.Axis.X ? viafabricplus_x_axis_shape_v1_12_2 : viafabricplus_z_axis_shape_v1_12_2); } } + + @Override + public VoxelShape getCullingShape(BlockState state, BlockView world, BlockPos pos) { + viafabricplus_requireOriginalShape = true; + return super.getCullingShape(state, world, pos); + } } From fe5cdf2c8c549d7542575d48f130ccc4e48b5caf Mon Sep 17 00:00:00 2001 From: FlorianMichael <60033407+FlorianMichael@users.noreply.github.com> Date: Mon, 18 Sep 2023 17:43:28 +0200 Subject: [PATCH 2/4] Added Mixin Plugin to disable compat mixins Fixed DashLoader compat Fixed ArmorSkin compat (Fixes https://github.com/ViaVersion/ViaFabricPlus/issues/221) Repackage compat mixins into own package --- README.md | 1 + .../definition/ClientsideFixes.java | 10 +-- .../viafabricplus/injection/MixinPlugin.java | 73 +++++++++++++++++++ ...ixinAutoRefillHandler_ItemSlotMonitor.java | 4 +- .../sodium/MixinChunkTracker.java | 2 +- .../fixes/minecraft/MixinFontStorage.java | 4 +- src/main/resources/fabric.mod.json | 3 +- src/main/resources/viafabricplus.mixins.json | 5 +- 8 files changed, 86 insertions(+), 16 deletions(-) create mode 100644 src/main/java/de/florianmichael/viafabricplus/injection/MixinPlugin.java rename src/main/java/de/florianmichael/viafabricplus/injection/mixin/{ => compat}/ipnext/MixinAutoRefillHandler_ItemSlotMonitor.java (97%) rename src/main/java/de/florianmichael/viafabricplus/injection/mixin/{fixes => compat}/sodium/MixinChunkTracker.java (95%) diff --git a/README.md b/README.md index 512fab05..32466d17 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ ViaFabricPlus is intended to replace [multiconnect](https://github.com/Earthcomp ### Conflicts - ***[DashLoader (*)](https://github.com/alphaqu/DashLoader/tree/fabric-1.20)*** - Font rendering related fixes aren't working +- ***[Armor Skin (*)](https://github.com/IzzyDotExe/ArmorSkin)*** - Beta HUD changes aren't working ## List of all clientside related fixes and TODO
diff --git a/src/main/java/de/florianmichael/viafabricplus/definition/ClientsideFixes.java b/src/main/java/de/florianmichael/viafabricplus/definition/ClientsideFixes.java index 6122edd8..d311f969 100644 --- a/src/main/java/de/florianmichael/viafabricplus/definition/ClientsideFixes.java +++ b/src/main/java/de/florianmichael/viafabricplus/definition/ClientsideFixes.java @@ -22,13 +22,12 @@ import com.viaversion.viaversion.protocols.protocol1_9to1_8.ArmorType; import de.florianmichael.viafabricplus.base.event.ChangeProtocolVersionCallback; import de.florianmichael.viafabricplus.base.event.FinishMinecraftLoadCallback; import de.florianmichael.viafabricplus.base.event.LoadClassicProtocolExtensionCallback; +import de.florianmichael.viafabricplus.injection.MixinPlugin; import de.florianmichael.viafabricplus.injection.access.IFontStorage; -import net.fabricmc.loader.api.FabricLoader; import net.minecraft.block.Block; import net.minecraft.block.Blocks; import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.FontStorage; -import net.minecraft.client.network.ServerAddress; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; @@ -57,11 +56,6 @@ public class ClientsideFixes { */ public final static VersionRange LEGACY_SRV_RESOLVE = VersionRange.andOlder(VersionEnum.r1_2_4tor1_2_5).add(VersionRange.single(VersionEnum.bedrockLatest)); - /** - * Tracks if the client is using DashLoader, so we can skip some fixes in the font rendering since they break DashLoader - */ - public final static boolean DASH_LOADER = FabricLoader.getInstance().isModLoaded("dashloader"); - /** * Contains the armor points of all armor items in legacy versions (<= 1.8.x) */ @@ -124,7 +118,7 @@ public class ClientsideFixes { } } - if (DASH_LOADER) { + if (!MixinPlugin.DASH_LOADER_PRESENT) { // Reloads all font storages to fix the font renderer for (FontStorage storage : MinecraftClient.getInstance().fontManager.fontStorages.values()) { RenderSystem.recordRenderCall(() -> ((IFontStorage) storage).viafabricplus_clearCaches()); diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/MixinPlugin.java b/src/main/java/de/florianmichael/viafabricplus/injection/MixinPlugin.java new file mode 100644 index 00000000..4349b28e --- /dev/null +++ b/src/main/java/de/florianmichael/viafabricplus/injection/MixinPlugin.java @@ -0,0 +1,73 @@ +/* + * This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus + * Copyright (C) 2021-2023 FlorianMichael/EnZaXD 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 de.florianmichael.viafabricplus.injection; + +import net.fabricmc.loader.api.FabricLoader; +import org.objectweb.asm.tree.ClassNode; +import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; +import org.spongepowered.asm.mixin.extensibility.IMixinInfo; + +import java.util.List; +import java.util.Set; + +public class MixinPlugin implements IMixinConfigPlugin { + public final static String INJECTOR_PACKAGE = "de.florianmichael.viafabricplus.injection.mixin"; + private final static String MC_FIXES_PACKAGE = ".fixes.minecraft"; + + public static boolean DASH_LOADER_PRESENT; + public static boolean ARMOR_SKIN_PRESENT; + + @Override + public void onLoad(String mixinPackage) { + final var loader = FabricLoader.getInstance(); + + DASH_LOADER_PRESENT = loader.isModLoaded("dashloader"); + ARMOR_SKIN_PRESENT = loader.isModLoaded("armorskin"); + } + + @Override + public String getRefMapperConfig() { + return null; + } + + @Override + public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { + if (mixinClassName.equals(INJECTOR_PACKAGE + MC_FIXES_PACKAGE + ".MixinFontStorage")) { + return !DASH_LOADER_PRESENT; + } + if (mixinClassName.equals(INJECTOR_PACKAGE + MC_FIXES_PACKAGE + ".MixinInGameHud")) { + return !ARMOR_SKIN_PRESENT; + } + + return true; + } + + @Override + public void acceptTargets(Set myTargets, Set otherTargets) {} + + @Override + public List getMixins() { + return null; + } + + @Override + public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {} + + @Override + public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {} +} diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/ipnext/MixinAutoRefillHandler_ItemSlotMonitor.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/compat/ipnext/MixinAutoRefillHandler_ItemSlotMonitor.java similarity index 97% rename from src/main/java/de/florianmichael/viafabricplus/injection/mixin/ipnext/MixinAutoRefillHandler_ItemSlotMonitor.java rename to src/main/java/de/florianmichael/viafabricplus/injection/mixin/compat/ipnext/MixinAutoRefillHandler_ItemSlotMonitor.java index 88e77f2a..2ff6b004 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/ipnext/MixinAutoRefillHandler_ItemSlotMonitor.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/compat/ipnext/MixinAutoRefillHandler_ItemSlotMonitor.java @@ -15,7 +15,7 @@ * 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.ipnext; +package de.florianmichael.viafabricplus.injection.mixin.compat.ipnext; import de.florianmichael.viafabricplus.protocolhack.ProtocolHack; import net.raphimc.vialoader.util.VersionEnum; @@ -29,7 +29,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; /* * https://github.com/blackd/Inventory-Profiles/tree/all-in-one is handling the offhand slot even when * ViaFabricPlus removes the slot in <= 1.8.9, so we have to cancel the handling of the offhand slot - *

+ * * Fixes https://github.com/ViaVersion/ViaFabricPlus/issues/209 */ @Pseudo diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/sodium/MixinChunkTracker.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/compat/sodium/MixinChunkTracker.java similarity index 95% rename from src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/sodium/MixinChunkTracker.java rename to src/main/java/de/florianmichael/viafabricplus/injection/mixin/compat/sodium/MixinChunkTracker.java index 48e15286..bf178276 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/sodium/MixinChunkTracker.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/compat/sodium/MixinChunkTracker.java @@ -15,7 +15,7 @@ * 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.sodium; +package de.florianmichael.viafabricplus.injection.mixin.compat.sodium; import de.florianmichael.viafabricplus.base.settings.groups.VisualSettings; import it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap; 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 7f25a28a..6b87ebed 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 @@ -83,7 +83,7 @@ public abstract class MixinFontStorage implements IFontStorage { @Inject(method = "findGlyph", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/font/Font;getGlyph(I)Lnet/minecraft/client/font/Glyph;"), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true) public void injectFindGlyph(int codePoint, CallbackInfoReturnable cir, Glyph glyph, Iterator var3, Font font) { - if (ClientsideFixes.DASH_LOADER || !this.id.getNamespace().equals("minecraft")) return; + if (!this.id.getNamespace().equals("minecraft")) return; if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_19_4)) { if (viafabricplus_isForbiddenCharacter(font, codePoint)) cir.setReturnValue(FontStorage.GlyphPair.MISSING); @@ -96,7 +96,7 @@ public abstract class MixinFontStorage implements IFontStorage { @Inject(method = "findGlyphRenderer", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/font/Font;getGlyph(I)Lnet/minecraft/client/font/Glyph;"), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true) public void injectFindGlyphRenderer(int codePoint, CallbackInfoReturnable cir, Iterator var2, Font font) { - if (ClientsideFixes.DASH_LOADER || !this.id.getNamespace().equals("minecraft")) return; + if (!this.id.getNamespace().equals("minecraft")) return; if (!viafabricplus_obfuscation && ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_19_4)) { if (viafabricplus_isForbiddenCharacter(font, codePoint)) cir.setReturnValue(this.blankGlyphRenderer); diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 019a14ed..62c93f0b 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -44,6 +44,7 @@ "krypton": "<=0.2.2" }, "conflicts": { - "dashloader": "*" + "dashloader": "*", + "armorskin": "*" } } diff --git a/src/main/resources/viafabricplus.mixins.json b/src/main/resources/viafabricplus.mixins.json index 5fe519d6..19bc4cb1 100644 --- a/src/main/resources/viafabricplus.mixins.json +++ b/src/main/resources/viafabricplus.mixins.json @@ -3,6 +3,7 @@ "minVersion": "0.8", "package": "de.florianmichael.viafabricplus.injection.mixin", "compatibilityLevel": "JAVA_17", + "plugin": "de.florianmichael.viafabricplus.injection.MixinPlugin", "client": [ "base.MixinAddServerScreen", "base.MixinClientConnection", @@ -129,7 +130,7 @@ "fixes.minecraft.screen.screenhandler.MixinBrewingStandScreenHandler_FuelSlot", "fixes.minecraft.screen.screenhandler.MixinPlayerScreenHandler", "fixes.minecraft.screen.screenhandler.MixinScreenHandler", - "fixes.sodium.MixinChunkTracker", + "compat.sodium.MixinChunkTracker", "fixes.viabedrock.MixinBedrockProtocol", "fixes.viabedrock.MixinJoinPackets", "fixes.vialegacy.MixinClassicProtocolExtension", @@ -166,7 +167,7 @@ "fixes.viaversion.protocol1_9to1_8.MixinEntityTracker1_9", "fixes.viaversion.protocol1_9to1_8.MixinMetadataRewriter1_9To1_8", "fixes.viaversion.protocol1_9to1_8.MixinViaIdleThread", - "ipnext.MixinAutoRefillHandler_ItemSlotMonitor", + "compat.ipnext.MixinAutoRefillHandler_ItemSlotMonitor", "jsonwebtoken.MixinClasses", "jsonwebtoken.MixinDefaultCompressionCodecResolver", "jsonwebtoken.MixinDefaultJwtParserBuilder" From 93bfa6a5ff72016c2cfdc26de94878b6690c0c19 Mon Sep 17 00:00:00 2001 From: FlorianMichael <60033407+FlorianMichael@users.noreply.github.com> Date: Mon, 18 Sep 2023 22:15:05 +0200 Subject: [PATCH 3/4] Don't reload all block shape caches on early init (mod compat) Fixed https://github.com/ViaVersion/ViaFabricPlus/issues/245 --- .../viafabricplus/definition/ClientsideFixes.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/florianmichael/viafabricplus/definition/ClientsideFixes.java b/src/main/java/de/florianmichael/viafabricplus/definition/ClientsideFixes.java index d311f969..2c442de2 100644 --- a/src/main/java/de/florianmichael/viafabricplus/definition/ClientsideFixes.java +++ b/src/main/java/de/florianmichael/viafabricplus/definition/ClientsideFixes.java @@ -105,8 +105,10 @@ public class ClientsideFixes { // Reloads some clientside stuff when the protocol version changes ChangeProtocolVersionCallback.EVENT.register(protocolVersion -> { // Reloads all bounding boxes - for (Block block : RELOADABLE_BLOCKS) { - block.getDefaultState().initShapeCache(); + if (MinecraftClient.getInstance() != null && MinecraftClient.getInstance().player != null) { // Make sure that the game is loaded when reloading the cache + for (Block block : RELOADABLE_BLOCKS) { + block.getDefaultState().initShapeCache(); + } } // Calculates the current chat limit, since it changes depending on the protocol version From d3b89bed8d6b1bfe6e26a2c637d3e6b17e4e597e Mon Sep 17 00:00:00 2001 From: FlorianMichael <60033407+FlorianMichael@users.noreply.github.com> Date: Mon, 18 Sep 2023 23:58:55 +0200 Subject: [PATCH 4/4] Fixed hopper culling not being correct when installing MoreCulling mod --- .../minecraft/block/MixinHopperBlock.java | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/block/MixinHopperBlock.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/block/MixinHopperBlock.java index 20447cb4..bc3a6387 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/block/MixinHopperBlock.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/block/MixinHopperBlock.java @@ -17,13 +17,10 @@ */ package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.block; +import net.minecraft.block.*; import net.raphimc.vialoader.util.VersionEnum; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import de.florianmichael.viafabricplus.protocolhack.ProtocolHack; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.HopperBlock; -import net.minecraft.block.ShapeContext; import net.minecraft.util.function.BooleanBiFunction; import net.minecraft.util.math.BlockPos; import net.minecraft.util.shape.VoxelShape; @@ -36,19 +33,27 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(HopperBlock.class) -public class MixinHopperBlock { +public abstract class MixinHopperBlock extends BlockWithEntity { @Unique private final static VoxelShape viafabricplus_inside_shape_v1_12_2 = Block.createCuboidShape(2, 10, 2, 14, 16, 14); @Unique - private final static VoxelShape viafabricplus_hopper_shape_v1_12_2 = VoxelShapes.combineAndSimplify( - VoxelShapes.fullCube(), - viafabricplus_inside_shape_v1_12_2, - BooleanBiFunction.ONLY_FIRST); + private final static VoxelShape viafabricplus_hopper_shape_v1_12_2 = VoxelShapes.combineAndSimplify(VoxelShapes.fullCube(), viafabricplus_inside_shape_v1_12_2, BooleanBiFunction.ONLY_FIRST); + + @Unique + private boolean viafabricplus_requireOriginalShape; + + public MixinHopperBlock(Settings settings) { + super(settings); + } @Inject(method = "getOutlineShape", at = @At("HEAD"), cancellable = true) public void injectGetOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context, CallbackInfoReturnable cir) { + if (viafabricplus_requireOriginalShape) { + viafabricplus_requireOriginalShape = false; + return; + } if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_12_2)) { cir.setReturnValue(viafabricplus_hopper_shape_v1_12_2); } @@ -60,4 +65,10 @@ public class MixinHopperBlock { cir.setReturnValue(viafabricplus_inside_shape_v1_12_2); } } + + @Override + public VoxelShape getCullingShape(BlockState state, BlockView world, BlockPos pos) { + viafabricplus_requireOriginalShape = true; + return super.getCullingShape(state, world, pos); + } }