From 694da5f5b1e96e921e8eff239413ebf37a712aa9 Mon Sep 17 00:00:00 2001 From: Hendrix-Shen Date: Mon, 21 Aug 2023 10:15:34 +0800 Subject: [PATCH] Support Minecraft 23w33a - Update Fabric Loom to 1.3 - Update Gradle to 8.3 - Since Minecraft 23w33a, Mojang broke CustomPayloadX2XPacket, introduced Fabric Network API --- build.gradle | 2 +- gradle.properties | 14 +++++------ gradle/wrapper/gradle-wrapper.properties | 2 +- .../masa/minihud/config/RendererToggle.java | 6 ++--- .../dy/masa/minihud/event/RenderHandler.java | 2 +- .../mixin/MixinClientPlayNetworkHandler.java | 2 +- .../network/StructurePacketHandlerCarpet.java | 20 +++++----------- .../network/StructurePacketHandlerServux.java | 23 ++++++------------- .../fi/dy/masa/minihud/util/DataStorage.java | 19 ++++++++------- .../dy/masa/minihud/util/DebugInfoUtils.java | 14 ++++++----- src/main/resources/fabric.mod.json | 4 ++-- 11 files changed, 46 insertions(+), 62 deletions(-) diff --git a/build.gradle b/build.gradle index 114ddd5db..e18b905c1 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version '1.2-SNAPSHOT' + id 'fabric-loom' version '1.3-SNAPSHOT' } sourceCompatibility = JavaVersion.VERSION_17 diff --git a/gradle.properties b/gradle.properties index 02aa6a628..530342803 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,15 +9,15 @@ author = masa mod_file_name = minihud-fabric # Current mod version -mod_version = 0.27.0 +mod_version = 0.27.0-nyan.1 # Required malilib version -malilib_version = 0.16.0 +malilib_version = 0.16.1-nyan.1 # Minecraft, Fabric and mappings versions -minecraft_version_out = 1.20.1 -minecraft_version = 1.20.1 -mappings_version = 1.20.1+build.2 +minecraft_version_out = 23w33a +minecraft_version = 23w33a +mappings_version = 23w33a+build.3 -fabric_loader_version = 0.14.21 -mod_menu_version = 7.0.1 +fabric_loader_version = 0.14.22 +mod_menu_version = 7.2.1 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index fae08049a..db9a6b825 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/fi/dy/masa/minihud/config/RendererToggle.java b/src/main/java/fi/dy/masa/minihud/config/RendererToggle.java index b492c9ab1..fb9873016 100644 --- a/src/main/java/fi/dy/masa/minihud/config/RendererToggle.java +++ b/src/main/java/fi/dy/masa/minihud/config/RendererToggle.java @@ -4,6 +4,7 @@ import com.google.common.collect.ImmutableList; import com.google.gson.JsonElement; import com.google.gson.JsonPrimitive; +import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; import net.minecraft.client.MinecraftClient; import fi.dy.masa.malilib.config.ConfigType; import fi.dy.masa.malilib.config.IConfigBoolean; @@ -14,7 +15,6 @@ import fi.dy.masa.malilib.hotkeys.KeybindMulti; import fi.dy.masa.malilib.hotkeys.KeybindSettings; import fi.dy.masa.malilib.interfaces.IValueChangeCallback; -import fi.dy.masa.malilib.network.ClientPacketChannelHandler; import fi.dy.masa.malilib.util.StringUtils; import fi.dy.masa.minihud.MiniHUD; import fi.dy.masa.minihud.hotkeys.KeyCallbackToggleRenderer; @@ -96,8 +96,8 @@ public enum RendererToggle implements IHotkeyTogglable, IConfigNotifiable CHANNELS = ImmutableList.of(new Identifier("carpet:structures")); +public class StructurePacketHandlerCarpet { + public static final Identifier CHANNEL = new Identifier("carpet:structures"); public static final int PACKET_S2C_DATA = 0; public static final int VERSION = 1; @@ -27,14 +26,7 @@ public void reset() this.registered = false; } - @Override - public List getChannels() - { - return CHANNELS; - } - - @Override - public void onPacketReceived(PacketByteBuf buf) + public void onPacketReceived(MinecraftClient client, ClientPlayNetworkHandler handler, PacketByteBuf buf, PacketSender sender) { int id = buf.readVarInt(); diff --git a/src/main/java/fi/dy/masa/minihud/network/StructurePacketHandlerServux.java b/src/main/java/fi/dy/masa/minihud/network/StructurePacketHandlerServux.java index 215c100e7..99990fd31 100644 --- a/src/main/java/fi/dy/masa/minihud/network/StructurePacketHandlerServux.java +++ b/src/main/java/fi/dy/masa/minihud/network/StructurePacketHandlerServux.java @@ -1,26 +1,24 @@ package fi.dy.masa.minihud.network; -import java.util.List; -import com.google.common.collect.ImmutableList; +import net.fabricmc.fabric.api.networking.v1.PacketSender; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.network.ClientPlayNetworkHandler; import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtList; import net.minecraft.network.PacketByteBuf; import net.minecraft.util.Identifier; -import fi.dy.masa.malilib.network.IPluginChannelHandler; import fi.dy.masa.malilib.util.Constants; import fi.dy.masa.minihud.MiniHUD; import fi.dy.masa.minihud.util.DataStorage; -public class StructurePacketHandlerServux implements IPluginChannelHandler -{ +public class StructurePacketHandlerServux { + public static final Identifier CHANNEL = new Identifier("servux:structures"); public static final int PROTOCOL_VERSION = 1; public static final int PACKET_S2C_METADATA = 1; public static final int PACKET_S2C_STRUCTURE_DATA = 2; public static final StructurePacketHandlerServux INSTANCE = new StructurePacketHandlerServux(); - private final Identifier channel = new Identifier("servux:structures"); - private final List channels = ImmutableList.of(this.channel); private boolean registered; private int timeout; @@ -29,14 +27,7 @@ public void reset() this.registered = false; } - @Override - public List getChannels() - { - return this.channels; - } - - @Override - public void onPacketReceived(PacketByteBuf buf) + public void onPacketReceived(MinecraftClient client, ClientPlayNetworkHandler handler, PacketByteBuf buf, PacketSender sender) { int id = buf.readVarInt(); @@ -58,7 +49,7 @@ else if (id == PACKET_S2C_METADATA) if (tag != null && tag.getInt("version") == PROTOCOL_VERSION && - tag.getString("id").equals(this.channel.toString())) + tag.getString("id").equals(CHANNEL.toString())) { this.timeout = tag.getInt("timeout"); this.registered = true; diff --git a/src/main/java/fi/dy/masa/minihud/util/DataStorage.java b/src/main/java/fi/dy/masa/minihud/util/DataStorage.java index a4ec9ffbf..042bca6a6 100644 --- a/src/main/java/fi/dy/masa/minihud/util/DataStorage.java +++ b/src/main/java/fi/dy/masa/minihud/util/DataStorage.java @@ -11,6 +11,9 @@ import com.google.common.util.concurrent.ThreadFactoryBuilder; import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; +import fi.dy.masa.minihud.network.StructurePacketHandlerCarpet; +import fi.dy.masa.minihud.network.StructurePacketHandlerServux; +import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; import net.minecraft.client.MinecraftClient; import net.minecraft.entity.Entity; import net.minecraft.nbt.NbtCompound; @@ -29,14 +32,12 @@ import net.minecraft.util.Identifier; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.ChunkPos; -import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3i; import net.minecraft.world.World; import net.minecraft.world.chunk.Chunk; import net.minecraft.world.chunk.ChunkStatus; import net.minecraft.world.gen.structure.Structure; -import fi.dy.masa.malilib.network.ClientPacketChannelHandler; import fi.dy.masa.malilib.util.Constants; import fi.dy.masa.malilib.util.InfoUtils; import fi.dy.masa.malilib.util.JsonUtils; @@ -45,8 +46,6 @@ import fi.dy.masa.minihud.config.Configs; import fi.dy.masa.minihud.config.RendererToggle; import fi.dy.masa.minihud.data.MobCapDataHandler; -import fi.dy.masa.minihud.network.StructurePacketHandlerCarpet; -import fi.dy.masa.minihud.network.StructurePacketHandlerServux; import fi.dy.masa.minihud.renderer.OverlayRendererBeaconRange; import fi.dy.masa.minihud.renderer.OverlayRendererBiomeBorders; import fi.dy.masa.minihud.renderer.OverlayRendererConduitRange; @@ -55,7 +54,6 @@ import fi.dy.masa.minihud.renderer.shapes.ShapeManager; import fi.dy.masa.minihud.renderer.worker.ChunkTask; import fi.dy.masa.minihud.renderer.worker.ThreadWorker; -import fi.dy.masa.minihud.util.MiscUtils; public class DataStorage { @@ -194,7 +192,7 @@ public void setIsServuxServer() { MiniHUD.printDebug("DataStorage#setIsServuxServer()"); this.servuxServer = true; - ClientPacketChannelHandler.getInstance().unregisterClientChannelHandler(StructurePacketHandlerCarpet.INSTANCE); + ClientPlayNetworking.unregisterGlobalReceiver(StructurePacketHandlerCarpet.CHANNEL); } public void onWorldJoin() @@ -563,8 +561,8 @@ else if (this.shouldRegisterStructureChannel && this.mc.getNetworkHandler() != n { MiniHUD.printDebug("DataStorage#updateStructureData(): Unregister channels"); // (re-)register the structure packet handlers - ClientPacketChannelHandler.getInstance().unregisterClientChannelHandler(StructurePacketHandlerCarpet.INSTANCE); - ClientPacketChannelHandler.getInstance().unregisterClientChannelHandler(StructurePacketHandlerServux.INSTANCE); + ClientPlayNetworking.unregisterGlobalReceiver(StructurePacketHandlerCarpet.CHANNEL); + ClientPlayNetworking.unregisterGlobalReceiver(StructurePacketHandlerServux.CHANNEL); this.registerStructureChannel(); } @@ -578,13 +576,14 @@ else if (this.shouldRegisterStructureChannel && this.mc.getNetworkHandler() != n public void registerStructureChannel() { MiniHUD.printDebug("DataStorage#registerStructureChannel(): Servux"); - ClientPacketChannelHandler.getInstance().registerClientChannelHandler(StructurePacketHandlerServux.INSTANCE); + ClientPlayNetworking.registerGlobalReceiver(StructurePacketHandlerServux.CHANNEL, StructurePacketHandlerServux.INSTANCE::onPacketReceived); // Don't register the Carpet structure channel if the server is known to have the Servux mod if (this.servuxServer == false) { MiniHUD.printDebug("DataStorage#registerStructureChannel(): Carpet"); - ClientPacketChannelHandler.getInstance().registerClientChannelHandler(StructurePacketHandlerCarpet.INSTANCE); + + ClientPlayNetworking.registerGlobalReceiver(StructurePacketHandlerCarpet.CHANNEL, StructurePacketHandlerCarpet.INSTANCE::onPacketReceived); } } diff --git a/src/main/java/fi/dy/masa/minihud/util/DebugInfoUtils.java b/src/main/java/fi/dy/masa/minihud/util/DebugInfoUtils.java index 8302a8ddb..09b850712 100644 --- a/src/main/java/fi/dy/masa/minihud/util/DebugInfoUtils.java +++ b/src/main/java/fi/dy/masa/minihud/util/DebugInfoUtils.java @@ -2,6 +2,7 @@ import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.function.Predicate; import com.google.common.collect.MapMaker; import com.mojang.blaze3d.systems.RenderSystem; @@ -19,7 +20,8 @@ import net.minecraft.entity.mob.MobEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.network.PacketByteBuf; -import net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket; +import net.minecraft.network.packet.s2c.common.CustomPayloadS2CPacket; +import net.minecraft.network.packet.s2c.custom.DebugPathCustomPayload; import net.minecraft.server.MinecraftServer; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld; @@ -47,8 +49,8 @@ public static void sendPacketDebugPath(MinecraftServer server, int entityId, Pat buffer.writeFloat(maxDistance); writePathToBuffer(buffer, path); - CustomPayloadS2CPacket packet = new CustomPayloadS2CPacket(CustomPayloadS2CPacket.DEBUG_PATH, buffer); - server.getPlayerManager().sendToAll(packet); + DebugPathCustomPayload packet = new DebugPathCustomPayload(buffer); + server.getPlayerManager().sendToAll(new CustomPayloadS2CPacket(packet)); } private static void writeBlockPosToBuffer(PacketByteBuf buf, BlockPos pos) @@ -104,8 +106,8 @@ private static void writePathToBuffer(PacketByteBuf buf, Path path) writeBlockPosToBuffer(buf, target); - PathNode[] openSet = path.getDebugNodes(); - PathNode[] closedSet = path.getDebugSecondNodes(); + PathNode[] openSet = Objects.requireNonNull(path.getDebugNodeInfos()).openSet(); + PathNode[] closedSet = path.getDebugNodeInfos().closedSet(); int length = path.getLength(); buf.writeInt(length); @@ -185,7 +187,7 @@ public static void onServerTickEnd(MinecraftServer server) { // Make a copy via a PacketBuffer... :/ PacketByteBuf buf = DebugInfoUtils.writePathTobuffer(path); - OLD_PATHS.put(entity, Path.fromBuffer(buf)); + OLD_PATHS.put(entity, Path.fromBuf(buf)); } else { diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 9c4e74140..157a9aee9 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -34,7 +34,7 @@ ], "depends": { - "minecraft": "1.20.x", - "malilib": "0.16.x" + "minecraft": ">=1.20.2-alpha.23.33.a", + "malilib": ">=0.16.1-nyan.1" } }