Skip to content

Commit 8c170fa

Browse files
authored
Merge 1.21.5 feature into master
2 parents 3557864 + c69cefd commit 8c170fa

File tree

72 files changed

+1018
-527
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+1018
-527
lines changed

example/src/main/java/org/geysermc/mcprotocollib/protocol/example/MinecraftProtocolTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ private static void login() {
220220
@Override
221221
public void packetReceived(Session session, Packet packet) {
222222
if (packet instanceof ClientboundLoginPacket) {
223-
session.send(new ServerboundChatPacket("Hello, this is a test of MCProtocolLib.", Instant.now().toEpochMilli(), 0L, null, 0, new BitSet()));
223+
session.send(new ServerboundChatPacket("Hello, this is a test of MCProtocolLib.", Instant.now().toEpochMilli(), 0L, null, 0, new BitSet(), 0));
224224
} else if (packet instanceof ClientboundSystemChatPacket systemChatPacket) {
225225
Component message = systemChatPacket.getContent();
226226
log.info("Received Message: {}", message);

gradle/libs.versions.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ cloudburstnbt = "3.0.0.Final"
77
slf4j = "2.0.9"
88
math = "2.0"
99
fastutil-maps = "8.5.3"
10-
netty = "4.1.103.Final"
11-
netty-io_uring = "0.0.24.Final"
10+
netty = "4.2.1.Final"
1211
gson = "2.11.0"
1312
minecraftauth = "4.1.1"
1413
checkerframework = "3.42.0"
@@ -37,7 +36,6 @@ fastutil-int2object-maps = { module = "com.nukkitx.fastutil:fastutil-int-object-
3736
fastutil-int2int-maps = { module = "com.nukkitx.fastutil:fastutil-int-int-maps", version.ref = "fastutil-maps" }
3837

3938
netty-all = { module = "io.netty:netty-all", version.ref = "netty" }
40-
netty-incubator-transport-native-io_uring = { module = "io.netty.incubator:netty-incubator-transport-native-io_uring", version.ref = "netty-io_uring" }
4139

4240
gson = { module = "com.google.code.gson:gson", version.ref = "gson" }
4341

@@ -57,4 +55,3 @@ lombok = { module = "io.freefair.gradle:lombok-plugin", version.ref = "lombok-pl
5755
adventure = ["adventure-text-serializer-gson", "adventure-text-serializer-json-legacy-impl"]
5856
math = ["math-api", "math-immutable"]
5957
fastutil = ["fastutil-object2int-maps", "fastutil-int2object-maps", "fastutil-int2int-maps"]
60-
netty = ["netty-all", "netty-incubator-transport-native-io_uring"]

protocol/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins {
33
jacoco
44
}
55

6-
version = "1.21.4-SNAPSHOT"
6+
version = "1.21.5-SNAPSHOT"
77
description = "MCProtocolLib is a simple library for communicating with Minecraft clients and servers."
88

99
dependencies {
@@ -29,7 +29,7 @@ dependencies {
2929
api(libs.bundles.fastutil)
3030

3131
// Netty
32-
api(libs.bundles.netty)
32+
api(libs.netty.all)
3333

3434
// Checker Framework
3535
api(libs.checkerframework.qual)

protocol/src/main/java/org/geysermc/mcprotocollib/network/BuiltinFlags.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.geysermc.mcprotocollib.network;
22

3+
import io.netty.buffer.ByteBufAllocator;
4+
35
import java.net.InetSocketAddress;
46

57
/**
@@ -46,6 +48,12 @@ public class BuiltinFlags {
4648
*/
4749
public static final Flag<Integer> WRITE_TIMEOUT = new Flag<>("write-timeout", Integer.class);
4850

51+
/**
52+
* The netty allocator to use.
53+
* Used by both server and client
54+
*/
55+
public static final Flag<ByteBufAllocator> ALLOCATOR = new Flag<>("allocator", ByteBufAllocator.class);
56+
4957
private BuiltinFlags() {
5058
}
5159
}

protocol/src/main/java/org/geysermc/mcprotocollib/network/helper/TransportHelper.java

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,39 @@
22

33
import io.netty.channel.ChannelFactory;
44
import io.netty.channel.EventLoopGroup;
5+
import io.netty.channel.MultiThreadIoEventLoopGroup;
56
import io.netty.channel.epoll.Epoll;
67
import io.netty.channel.epoll.EpollDatagramChannel;
78
import io.netty.channel.epoll.EpollEventLoopGroup;
9+
import io.netty.channel.epoll.EpollIoHandler;
810
import io.netty.channel.epoll.EpollServerSocketChannel;
911
import io.netty.channel.epoll.EpollSocketChannel;
1012
import io.netty.channel.kqueue.KQueue;
1113
import io.netty.channel.kqueue.KQueueDatagramChannel;
1214
import io.netty.channel.kqueue.KQueueEventLoopGroup;
15+
import io.netty.channel.kqueue.KQueueIoHandler;
1316
import io.netty.channel.kqueue.KQueueServerSocketChannel;
1417
import io.netty.channel.kqueue.KQueueSocketChannel;
1518
import io.netty.channel.nio.NioEventLoopGroup;
19+
import io.netty.channel.nio.NioIoHandler;
1620
import io.netty.channel.socket.DatagramChannel;
1721
import io.netty.channel.socket.ServerSocketChannel;
1822
import io.netty.channel.socket.SocketChannel;
1923
import io.netty.channel.socket.nio.NioDatagramChannel;
2024
import io.netty.channel.socket.nio.NioServerSocketChannel;
2125
import io.netty.channel.socket.nio.NioSocketChannel;
22-
import io.netty.incubator.channel.uring.IOUring;
23-
import io.netty.incubator.channel.uring.IOUringDatagramChannel;
24-
import io.netty.incubator.channel.uring.IOUringEventLoopGroup;
25-
import io.netty.incubator.channel.uring.IOUringServerSocketChannel;
26-
import io.netty.incubator.channel.uring.IOUringSocketChannel;
26+
import io.netty.channel.uring.IoUring;
27+
import io.netty.channel.uring.IoUringDatagramChannel;
28+
import io.netty.channel.uring.IoUringIoHandler;
29+
import io.netty.channel.uring.IoUringServerSocketChannel;
30+
import io.netty.channel.uring.IoUringSocketChannel;
2731

2832
import java.util.concurrent.ThreadFactory;
29-
import java.util.function.Function;
33+
import java.util.function.BiFunction;
3034

3135
public class TransportHelper {
3236
public static final TransportHelper.TransportType TRANSPORT_TYPE = TransportHelper.determineTransportMethod();
37+
public static final boolean NEW_NETTY = isClassAvailable("io.netty.channel.MultiThreadIoEventLoopGroup");
3338

3439
public enum TransportMethod {
3540
NIO, EPOLL, KQUEUE, IO_URING
@@ -42,24 +47,28 @@ public record TransportType(TransportMethod method,
4247
ChannelFactory<? extends SocketChannel> socketChannelFactory,
4348
Class<? extends DatagramChannel> datagramChannelClass,
4449
ChannelFactory<? extends DatagramChannel> datagramChannelFactory,
45-
Function<ThreadFactory, EventLoopGroup> eventLoopGroupFactory,
50+
BiFunction<Integer, ThreadFactory, EventLoopGroup> eventLoopGroupFactory,
4651
boolean supportsTcpFastOpenServer,
4752
boolean supportsTcpFastOpenClient) {
4853
}
4954

55+
@SuppressWarnings("deprecation")
5056
private static TransportType determineTransportMethod() {
51-
if (isClassAvailable("io.netty.incubator.channel.uring.IOUring") && IOUring.isAvailable()) {
57+
if (isClassAvailable("io.netty.channel.uring.IoUring")
58+
&& IoUring.isAvailable()
59+
&& Boolean.getBoolean("Mcpl.io_uring")
60+
) {
5261
return new TransportType(
5362
TransportMethod.IO_URING,
54-
IOUringServerSocketChannel.class,
55-
IOUringServerSocketChannel::new,
56-
IOUringSocketChannel.class,
57-
IOUringSocketChannel::new,
58-
IOUringDatagramChannel.class,
59-
IOUringDatagramChannel::new,
60-
factory -> new IOUringEventLoopGroup(0, factory),
61-
IOUring.isTcpFastOpenServerSideAvailable(),
62-
IOUring.isTcpFastOpenClientSideAvailable()
63+
IoUringServerSocketChannel.class,
64+
IoUringServerSocketChannel::new,
65+
IoUringSocketChannel.class,
66+
IoUringSocketChannel::new,
67+
IoUringDatagramChannel.class,
68+
IoUringDatagramChannel::new,
69+
(threads, factory) -> new MultiThreadIoEventLoopGroup(threads, factory, IoUringIoHandler.newFactory()),
70+
IoUring.isTcpFastOpenServerSideAvailable(),
71+
IoUring.isTcpFastOpenClientSideAvailable()
6372
);
6473
}
6574

@@ -72,7 +81,8 @@ private static TransportType determineTransportMethod() {
7281
EpollSocketChannel::new,
7382
EpollDatagramChannel.class,
7483
EpollDatagramChannel::new,
75-
factory -> new EpollEventLoopGroup(0, factory),
84+
NEW_NETTY ? (threads, factory) ->
85+
new MultiThreadIoEventLoopGroup(threads, factory, EpollIoHandler.newFactory()) : EpollEventLoopGroup::new,
7686
Epoll.isTcpFastOpenServerSideAvailable(),
7787
Epoll.isTcpFastOpenClientSideAvailable()
7888
);
@@ -87,7 +97,8 @@ private static TransportType determineTransportMethod() {
8797
KQueueSocketChannel::new,
8898
KQueueDatagramChannel.class,
8999
KQueueDatagramChannel::new,
90-
factory -> new KQueueEventLoopGroup(0, factory),
100+
NEW_NETTY ? (threads, factory) ->
101+
new MultiThreadIoEventLoopGroup(threads, factory, KQueueIoHandler.newFactory()) : KQueueEventLoopGroup::new,
91102
KQueue.isTcpFastOpenServerSideAvailable(),
92103
KQueue.isTcpFastOpenClientSideAvailable()
93104
);
@@ -101,7 +112,8 @@ private static TransportType determineTransportMethod() {
101112
NioSocketChannel::new,
102113
NioDatagramChannel.class,
103114
NioDatagramChannel::new,
104-
factory -> new NioEventLoopGroup(0, factory),
115+
NEW_NETTY ? (threads, factory) ->
116+
new MultiThreadIoEventLoopGroup(threads, factory, NioIoHandler.newFactory()) : NioEventLoopGroup::new,
105117
false,
106118
false
107119
);

protocol/src/main/java/org/geysermc/mcprotocollib/network/netty/PacketEncryptorCodec.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) t
4747
try {
4848
config.encryption().decrypt(heapBuf.array(), baseOffset, inBytes, heapBuf.array(), baseOffset);
4949
out.add(heapBuf);
50+
if (in.hasArray()) in.readerIndex(inBytes); // This is required as otherwise the ByteBuf doesn't know it has been read
5051
} catch (Exception e) {
5152
heapBuf.release();
5253
throw e;

protocol/src/main/java/org/geysermc/mcprotocollib/network/server/NetworkServer.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.geysermc.mcprotocollib.network.server;
22

33
import io.netty.bootstrap.ServerBootstrap;
4+
import io.netty.buffer.ByteBufAllocator;
45
import io.netty.channel.Channel;
56
import io.netty.channel.ChannelFactory;
67
import io.netty.channel.ChannelFutureListener;
@@ -86,11 +87,11 @@ protected ChannelFactory<? extends ServerChannel> getChannelFactory() {
8687
}
8788

8889
protected EventLoopGroup createBossEventLoopGroup() {
89-
return TransportHelper.TRANSPORT_TYPE.eventLoopGroupFactory().apply(null);
90+
return TransportHelper.TRANSPORT_TYPE.eventLoopGroupFactory().apply(0, null);
9091
}
9192

9293
protected EventLoopGroup createWorkerEventLoopGroup() {
93-
return TransportHelper.TRANSPORT_TYPE.eventLoopGroupFactory().apply(null);
94+
return TransportHelper.TRANSPORT_TYPE.eventLoopGroupFactory().apply(0, null);
9495
}
9596

9697
protected void setOptions(ServerBootstrap bootstrap) {
@@ -100,6 +101,8 @@ protected void setOptions(ServerBootstrap bootstrap) {
100101
if (getGlobalFlag(BuiltinFlags.TCP_FAST_OPEN, false) && TransportHelper.TRANSPORT_TYPE.supportsTcpFastOpenServer()) {
101102
bootstrap.option(ChannelOption.TCP_FASTOPEN, 3);
102103
}
104+
105+
bootstrap.option(ChannelOption.ALLOCATOR, getGlobalFlag(BuiltinFlags.ALLOCATOR, ByteBufAllocator.DEFAULT));
103106
}
104107

105108
protected ChannelHandler getChannelHandler() {

protocol/src/main/java/org/geysermc/mcprotocollib/network/session/ClientNetworkSession.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.geysermc.mcprotocollib.network.session;
22

33
import io.netty.bootstrap.Bootstrap;
4+
import io.netty.buffer.ByteBufAllocator;
45
import io.netty.channel.Channel;
56
import io.netty.channel.ChannelFactory;
67
import io.netty.channel.ChannelHandler;
@@ -100,6 +101,8 @@ protected void setOptions(Bootstrap bootstrap) {
100101
if (getFlag(BuiltinFlags.TCP_FAST_OPEN, false) && TransportHelper.TRANSPORT_TYPE.supportsTcpFastOpenClient()) {
101102
bootstrap.option(ChannelOption.TCP_FASTOPEN_CONNECT, true);
102103
}
104+
105+
bootstrap.option(ChannelOption.ALLOCATOR, getFlag(BuiltinFlags.ALLOCATOR, ByteBufAllocator.DEFAULT));
103106
}
104107

105108
protected ChannelHandler getChannelHandler() {
@@ -124,7 +127,7 @@ private static void createEventLoopGroup() {
124127
return;
125128
}
126129

127-
EVENT_LOOP_GROUP = TransportHelper.TRANSPORT_TYPE.eventLoopGroupFactory().apply(newThreadFactory());
130+
EVENT_LOOP_GROUP = TransportHelper.TRANSPORT_TYPE.eventLoopGroupFactory().apply(0, newThreadFactory());
128131

129132
Runtime.getRuntime().addShutdownHook(new Thread(
130133
() -> EVENT_LOOP_GROUP.shutdownGracefully(SHUTDOWN_QUIET_PERIOD_MS, SHUTDOWN_TIMEOUT_MS, TimeUnit.MILLISECONDS)));

protocol/src/main/java/org/geysermc/mcprotocollib/protocol/codec/MinecraftCodec.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundStopSoundPacket;
5555
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundSystemChatPacket;
5656
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundTabListPacket;
57+
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundTestInstanceBlockStatus;
5758
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundTickingStatePacket;
5859
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundTickingStepPacket;
5960
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundUpdateAdvancementsPacket;
@@ -92,8 +93,7 @@
9293
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.player.ClientboundSetExperiencePacket;
9394
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.player.ClientboundSetHealthPacket;
9495
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.player.ClientboundSetHeldSlotPacket;
95-
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.spawn.ClientboundAddEntityPacket;
96-
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.spawn.ClientboundAddExperienceOrbPacket;
96+
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.ClientboundAddEntityPacket;
9797
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.inventory.ClientboundContainerClosePacket;
9898
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.inventory.ClientboundContainerSetContentPacket;
9999
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.inventory.ClientboundContainerSetDataPacket;
@@ -186,8 +186,10 @@
186186
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.level.ServerboundMoveVehiclePacket;
187187
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.level.ServerboundPaddleBoatPacket;
188188
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.level.ServerboundPlayerInputPacket;
189+
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.level.ServerboundSetTestBlockPacket;
189190
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.level.ServerboundSignUpdatePacket;
190191
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.level.ServerboundTeleportToEntityPacket;
192+
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.level.ServerboundTestInstanceBlockActionPacket;
191193
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundInteractPacket;
192194
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundMovePlayerPosPacket;
193195
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundMovePlayerPosRotPacket;
@@ -216,8 +218,8 @@
216218

217219
public class MinecraftCodec {
218220
public static final PacketCodec CODEC = PacketCodec.builder()
219-
.protocolVersion(769)
220-
.minecraftVersion("1.21.4")
221+
.protocolVersion(770)
222+
.minecraftVersion("1.21.5")
221223
.state(ProtocolState.HANDSHAKE, MinecraftPacketRegistry.builder()
222224
.registerServerboundPacket(ClientIntentionPacket.class, ClientIntentionPacket::new)
223225
)
@@ -267,7 +269,6 @@ public class MinecraftCodec {
267269
).state(ProtocolState.GAME, MinecraftPacketRegistry.builder()
268270
.registerClientboundPacket(ClientboundDelimiterPacket.class, ClientboundDelimiterPacket::new)
269271
.registerClientboundPacket(ClientboundAddEntityPacket.class, ClientboundAddEntityPacket::new)
270-
.registerClientboundPacket(ClientboundAddExperienceOrbPacket.class, ClientboundAddExperienceOrbPacket::new)
271272
.registerClientboundPacket(ClientboundAnimatePacket.class, ClientboundAnimatePacket::new)
272273
.registerClientboundPacket(ClientboundAwardStatsPacket.class, ClientboundAwardStatsPacket::new)
273274
.registerClientboundPacket(ClientboundBlockChangedAckPacket.class, ClientboundBlockChangedAckPacket::new)
@@ -385,6 +386,7 @@ public class MinecraftCodec {
385386
.registerClientboundPacket(ClientboundTagQueryPacket.class, ClientboundTagQueryPacket::new)
386387
.registerClientboundPacket(ClientboundTakeItemEntityPacket.class, ClientboundTakeItemEntityPacket::new)
387388
.registerClientboundPacket(ClientboundTeleportEntityPacket.class, ClientboundTeleportEntityPacket::new)
389+
.registerClientboundPacket(ClientboundTestInstanceBlockStatus.class, ClientboundTestInstanceBlockStatus::new)
388390
.registerClientboundPacket(ClientboundTickingStatePacket.class, ClientboundTickingStatePacket::new)
389391
.registerClientboundPacket(ClientboundTickingStepPacket.class, ClientboundTickingStepPacket::new)
390392
.registerClientboundPacket(ClientboundTransferPacket.class, ClientboundTransferPacket::new)
@@ -453,9 +455,11 @@ public class MinecraftCodec {
453455
.registerServerboundPacket(ServerboundSetCreativeModeSlotPacket.class, ServerboundSetCreativeModeSlotPacket::new)
454456
.registerServerboundPacket(ServerboundSetJigsawBlockPacket.class, ServerboundSetJigsawBlockPacket::new)
455457
.registerServerboundPacket(ServerboundSetStructureBlockPacket.class, ServerboundSetStructureBlockPacket::new)
458+
.registerServerboundPacket(ServerboundSetTestBlockPacket.class, ServerboundSetTestBlockPacket::new)
456459
.registerServerboundPacket(ServerboundSignUpdatePacket.class, ServerboundSignUpdatePacket::new)
457460
.registerServerboundPacket(ServerboundSwingPacket.class, ServerboundSwingPacket::new)
458461
.registerServerboundPacket(ServerboundTeleportToEntityPacket.class, ServerboundTeleportToEntityPacket::new)
462+
.registerServerboundPacket(ServerboundTestInstanceBlockActionPacket.class, ServerboundTestInstanceBlockActionPacket::new)
459463
.registerServerboundPacket(ServerboundUseItemOnPacket.class, ServerboundUseItemOnPacket::new)
460464
.registerServerboundPacket(ServerboundUseItemPacket.class, ServerboundUseItemPacket::new)
461465
)

0 commit comments

Comments
 (0)