Skip to content

Commit

Permalink
update mcpl
Browse files Browse the repository at this point in the history
  • Loading branch information
rfresh2 committed Jan 22, 2025
1 parent 6774412 commit ec56229
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 25 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ dependencies {
implementation("com.github.rfresh2.discord4j:discord4j-core:3.4.4.12") {
exclude(group = "io.netty")
}
implementation("com.github.rfresh2:MCProtocolLib:1.21.0.25") {
implementation("com.github.rfresh2:MCProtocolLib:1.21.0.27") {
exclude(group = "io.netty")
}
val nettyVersion = "4.1.117.Final"
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/zenith/Proxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import org.geysermc.mcprotocollib.network.tcp.TcpServer;
import org.geysermc.mcprotocollib.protocol.MinecraftConstants;
import org.geysermc.mcprotocollib.protocol.MinecraftProtocol;
import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper;
import org.geysermc.mcprotocollib.protocol.codec.MinecraftTypes;
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundSystemChatPacket;
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundTabListPacket;
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundSetCarriedItemPacket;
Expand Down Expand Up @@ -158,7 +158,7 @@ public void start() {
NotificationEventListener.INSTANCE.subscribeEvents();
Queue.start();
saveConfigAsync();
MinecraftCodecHelper.useBinaryNbtComponentSerializer = CONFIG.debug.binaryNbtComponentSerializer;
MinecraftTypes.useBinaryNbtComponentSerializer = CONFIG.debug.binaryNbtComponentSerializer;
MinecraftConstants.CHUNK_SECTION_COUNT_PROVIDER = CACHE.getSectionCountProvider();
if (CONFIG.client.viaversion.enabled || CONFIG.server.viaversion.enabled) {
VIA_INITIALIZER.init();
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/com/zenith/cache/data/chunk/ChunkCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import net.kyori.adventure.key.Key;
import org.geysermc.mcprotocollib.network.packet.Packet;
import org.geysermc.mcprotocollib.network.tcp.TcpSession;
import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodec;
import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper;
import org.geysermc.mcprotocollib.protocol.data.game.RegistryEntry;
import org.geysermc.mcprotocollib.protocol.data.game.chunk.ChunkBiomeData;
import org.geysermc.mcprotocollib.protocol.data.game.chunk.ChunkSection;
Expand Down Expand Up @@ -67,7 +65,6 @@ public class ChunkCache implements CachedData {
protected List<Key> worldNames = new ArrayList<>();
protected int serverViewDistance = -1;
protected int serverSimulationDistance = -1;
protected MinecraftCodecHelper codec;
protected int centerX;
protected int centerZ;
protected int dimensionType;
Expand All @@ -86,7 +83,6 @@ public ChunkCache() {
5L,
5L,
TimeUnit.MINUTES);
codec = MinecraftCodec.CODEC.getHelper();
resetDimensionRegistry();
}

Expand Down Expand Up @@ -313,8 +309,8 @@ public boolean updateBlockEntity(final ClientboundBlockEntityDataPacket packet)

public byte[] getServerBrand() {
return serverBrand == null
? BrandSerializer.defaultBrand(codec)
: BrandSerializer.appendBrand(codec, serverBrand);
? BrandSerializer.defaultBrand()
: BrandSerializer.appendBrand(serverBrand);
}

private static final byte[] fullBrightSkyLightData;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/zenith/command/impl/DebugCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import com.zenith.command.brigadier.CommandCategory;
import com.zenith.command.brigadier.CommandContext;
import com.zenith.discord.Embed;
import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper;
import org.geysermc.mcprotocollib.protocol.codec.MinecraftTypes;
import org.geysermc.mcprotocollib.protocol.data.game.entity.Effect;
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.ClientboundRemoveMobEffectPacket;

Expand Down Expand Up @@ -135,7 +135,7 @@ public LiteralArgumentBuilder<CommandContext> register() {
.then(literal("binaryNbtComponentSerializer")
.then(argument("toggle", toggle()).executes(c -> {
CONFIG.debug.binaryNbtComponentSerializer = getToggle(c, "toggle");
MinecraftCodecHelper.useBinaryNbtComponentSerializer = CONFIG.debug.binaryNbtComponentSerializer;
MinecraftTypes.useBinaryNbtComponentSerializer = CONFIG.debug.binaryNbtComponentSerializer;
c.getSource().getEmbed()
.title("Binary Nbt Component Serializer " + toggleStrCaps(CONFIG.debug.binaryNbtComponentSerializer));
return OK;
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/com/zenith/feature/replay/ReplayRecording.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import net.kyori.adventure.key.Key;
import org.geysermc.mcprotocollib.network.Session;
import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodec;
import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper;
import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket;
import org.geysermc.mcprotocollib.protocol.data.ProtocolState;
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.PlayerSpawnInfo;
Expand Down Expand Up @@ -159,10 +158,9 @@ private synchronized void writeToFile(final long time, final MinecraftPacket pac
var lenIndex = packetBuf.writerIndex();
packetBuf.writeInt(0); // write dummy length
var packetProtocol = session.getPacketProtocol();
var codecHelper = (MinecraftCodecHelper) session.getCodecHelper();
var packetId = MinecraftCodec.CODEC.getCodec(protocolState).getClientboundId(packet);
packetProtocol.getPacketHeader().writePacketId(packetBuf, codecHelper, packetId);
packet.serialize(packetBuf, codecHelper);
packetProtocol.getPacketHeader().writePacketId(packetBuf, packetId);
packet.serialize(packetBuf);
var packetSize = packetBuf.readableBytes();
var packetBodySize = packetSize - 8;
packetBuf.setInt(lenIndex, packetBodySize); // write actual length
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.zenith.network.registry.PacketHandler;
import com.zenith.util.BrandSerializer;
import net.kyori.adventure.key.Key;
import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper;
import org.geysermc.mcprotocollib.protocol.packet.common.clientbound.ClientboundCustomPayloadPacket;

import static com.zenith.Shared.CACHE;
Expand All @@ -18,7 +17,7 @@ public ClientboundCustomPayloadPacket apply(ClientboundCustomPayloadPacket packe
CACHE.getChunkCache().setServerBrand(packet.getData());
return new ClientboundCustomPayloadPacket(
packet.getChannel(),
BrandSerializer.appendBrand((MinecraftCodecHelper) session.getCodecHelper(), packet.getData()));
BrandSerializer.appendBrand(packet.getData()));
}
return packet;
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/zenith/util/BrandSerializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@

import io.netty.buffer.Unpooled;
import lombok.experimental.UtilityClass;
import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper;
import org.geysermc.mcprotocollib.protocol.codec.MinecraftTypes;

@UtilityClass
public class BrandSerializer {
private static final String BRAND = "ZenithProxy";

public static byte[] defaultBrand(final MinecraftCodecHelper codec) {
public static byte[] defaultBrand() {
final var byteBuf = Unpooled.buffer(100);
codec.writeString(byteBuf, BRAND);
MinecraftTypes.writeString(byteBuf, BRAND);
final var bytes = new byte[byteBuf.readableBytes()];
byteBuf.readBytes(bytes);
byteBuf.release();
return bytes;
}

// append ' (ZenithProxy)' to the end of the original brand
public static byte[] appendBrand(final MinecraftCodecHelper codec, final byte[] original) {
public static byte[] appendBrand(final byte[] original) {
final var inBuf = Unpooled.wrappedBuffer(original);
final var outBuf = Unpooled.buffer(100);
final var originalStr = codec.readString(inBuf);
final var originalStr = MinecraftTypes.readString(inBuf);
final var appendedStr = originalStr + " (" + BRAND + ")";
codec.writeString(outBuf, appendedStr);
MinecraftTypes.writeString(outBuf, appendedStr);
final var bytes = new byte[outBuf.readableBytes()];
outBuf.readBytes(bytes);
outBuf.release();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/zenith/util/ReplayReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ private void readRecordingEntry(final DataInputStream recordingStream, final Min
ByteBuf byteBuf = ALLOC.buffer();
try {
byteBuf.writeBytes(recordingStream, len);
int packetId = packetProtocol.getPacketHeader().readPacketId(byteBuf, packetProtocol.getHelper());
Packet packet = packetProtocol.getInboundPacketRegistry().createClientboundPacket(packetId, byteBuf, packetProtocol.getHelper());
int packetId = packetProtocol.getPacketHeader().readPacketId(byteBuf);
Packet packet = packetProtocol.getInboundPacketRegistry().createClientboundPacket(packetId, byteBuf);
String out = "\n[" + t + "] " + packet.toString();
outputWriter.write(out.getBytes(StandardCharsets.UTF_8));
switch (packetProtocol.getInboundState()) {
Expand Down

0 comments on commit ec56229

Please sign in to comment.