Skip to content

Commit

Permalink
Support Minecraft 23w33a
Browse files Browse the repository at this point in the history
- Update Fabric Loom to 1.3
- Update Gradle to 8.3
- Since Minecraft 23w33a, Mojang broke CustomPayloadX2XPacket, introduced Fabric Network API
  • Loading branch information
Hendrix-Shen committed Aug 21, 2023
1 parent d2b9093 commit 694da5f
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 62 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.2-SNAPSHOT'
id 'fabric-loom' version '1.3-SNAPSHOT'
}

sourceCompatibility = JavaVersion.VERSION_17
Expand Down
14 changes: 7 additions & 7 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions src/main/java/fi/dy/masa/minihud/config/RendererToggle.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -96,8 +96,8 @@ public enum RendererToggle implements IHotkeyTogglable, IConfigNotifiable<IConfi
}
else
{
ClientPacketChannelHandler.getInstance().unregisterClientChannelHandler(StructurePacketHandlerCarpet.INSTANCE);
ClientPacketChannelHandler.getInstance().unregisterClientChannelHandler(StructurePacketHandlerServux.INSTANCE);
ClientPlayNetworking.unregisterGlobalReceiver(StructurePacketHandlerCarpet.CHANNEL);
ClientPlayNetworking.unregisterGlobalReceiver(StructurePacketHandlerServux.CHANNEL);
}
}
else
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/fi/dy/masa/minihud/event/RenderHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void onRenderGameOverlayPost(DrawContext context)
return;
}

if (this.mc.options.debugEnabled == false &&
if (this.mc.getDebugHud().shouldShowDebugHud() == false &&
this.mc.player != null && this.mc.options.hudHidden == false &&
(Configs.Generic.REQUIRE_SNEAK.getBooleanValue() == false || this.mc.player.isSneaking()) &&
Configs.Generic.REQUIRED_KEY.getKeybind().isKeybindHeld())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ private void markChunkChangedBlockChange(net.minecraft.network.packet.s2c.play.B
@Inject(method = "onChunkData", at = @At("RETURN"))
private void markChunkChangedFullChunk(net.minecraft.network.packet.s2c.play.ChunkDataS2CPacket packet, CallbackInfo ci)
{
NotificationUtils.onChunkData(packet.getX(), packet.getZ(), packet.getChunkData());
NotificationUtils.onChunkData(packet.getChunkX(), packet.getChunkZ(), packet.getChunkData());
}

@Inject(method = "onChunkDeltaUpdate", at = @At("RETURN"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
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 StructurePacketHandlerCarpet implements IPluginChannelHandler
{
public static final List<Identifier> 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;

Expand All @@ -27,14 +26,7 @@ public void reset()
this.registered = false;
}

@Override
public List<Identifier> getChannels()
{
return CHANNELS;
}

@Override
public void onPacketReceived(PacketByteBuf buf)
public void onPacketReceived(MinecraftClient client, ClientPlayNetworkHandler handler, PacketByteBuf buf, PacketSender sender)
{
int id = buf.readVarInt();

Expand Down
Original file line number Diff line number Diff line change
@@ -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<Identifier> channels = ImmutableList.of(this.channel);
private boolean registered;
private int timeout;

Expand All @@ -29,14 +27,7 @@ public void reset()
this.registered = false;
}

@Override
public List<Identifier> 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();

Expand All @@ -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;
Expand Down
19 changes: 9 additions & 10 deletions src/main/java/fi/dy/masa/minihud/util/DataStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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
{
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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();
}
Expand All @@ -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);
}
}

Expand Down
14 changes: 8 additions & 6 deletions src/main/java/fi/dy/masa/minihud/util/DebugInfoUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
{
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

0 comments on commit 694da5f

Please sign in to comment.