Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into 1.20.2-recode
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianMichael committed Sep 19, 2023
2 parents 7bbc8bf + d3b89be commit 2f9dc58
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 32 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<details>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@
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;
Expand Down Expand Up @@ -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)
*/
Expand Down Expand Up @@ -111,8 +105,10 @@ public static void init() {
// 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
Expand All @@ -124,7 +120,7 @@ public static void init() {
}
}

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());
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/
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<String> myTargets, Set<String> otherTargets) {}

@Override
public List<String> 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) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* 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.ipnext;
package de.florianmichael.viafabricplus.injection.mixin.compat.ipnext;

import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
import net.raphimc.vialoader.util.VersionEnum;
Expand All @@ -29,7 +29,7 @@
/*
* 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
* <p>
*
* Fixes https://github.com/ViaVersion/ViaFabricPlus/issues/209
*/
@Pseudo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* 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.sodium;
package de.florianmichael.viafabricplus.injection.mixin.compat.sodium;

import de.florianmichael.viafabricplus.base.settings.groups.VisualSettings;
import it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private boolean viafabricplus_isForbiddenCharacter(final Font font, final int co

@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<FontStorage.GlyphPair> 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);
Expand All @@ -96,7 +96,7 @@ public void injectFindGlyph(int codePoint, CallbackInfoReturnable<FontStorage.Gl

@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<GlyphRenderer> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -38,7 +35,7 @@
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);
Expand All @@ -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<VoxelShape> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -36,19 +33,27 @@
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<VoxelShape> cir) {
if (viafabricplus_requireOriginalShape) {
viafabricplus_requireOriginalShape = false;
return;
}
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_12_2)) {
cir.setReturnValue(viafabricplus_hopper_shape_v1_12_2);
}
Expand All @@ -60,4 +65,10 @@ public void injectGetRaycastShape(BlockState state, BlockView world, BlockPos po
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);
}
}
3 changes: 2 additions & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"krypton": "<=0.2.2"
},
"conflicts": {
"dashloader": "*"
"dashloader": "*",
"armorskin": "*"
}
}
5 changes: 3 additions & 2 deletions src/main/resources/viafabricplus.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -130,7 +131,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",
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 2f9dc58

Please sign in to comment.