Skip to content

Commit b914cfa

Browse files
committed
Merge branch 'coral-tags' into grim/2.0
2 parents ff8b11e + e937bf6 commit b914cfa

File tree

14 files changed

+101
-25
lines changed

14 files changed

+101
-25
lines changed

.github/workflows/release.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ jobs:
1212

1313
steps:
1414
- name: Checkout code
15-
uses: actions/checkout@v4
15+
uses: actions/checkout@v5
1616

1717
- name: Validate gradle wrapper
18-
uses: gradle/actions/wrapper-validation@v4
18+
uses: gradle/actions/wrapper-validation@v5
1919

2020
- name: Setup java 21
21-
uses: actions/setup-java@v4
21+
uses: actions/setup-java@v5
2222
with:
2323
java-version: 21
2424
distribution: temurin

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,5 @@ run/
127127

128128
# Build Source Kotlin
129129
/buildSrc/.kotlin/
130+
131+
.env

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!--suppress HtmlDeprecatedAttribute -->
22
<div align="center">
33
<h2><i>PacketEvents</i></h2>
4-
<h3><i>A powerful networking library for Minecraft packet processing and manipulation.</i></h3>
4+
<h3>PacketEvents is a protocol library tailored to Minecraft Java Edition, designed to facilitate the processing and transmission of packets.</h3>
55
<a href="https://github.com/retrooper/packetevents/actions"><img src="https://img.shields.io/github/actions/workflow/status/retrooper/packetevents/gradle-publish.yml?style=for-the-badge&logo=github"></a>
66
<a href="https://discord.gg/DVHxPPxHZc"><img src="https://img.shields.io/discord/721686193061888071?color=5562e9&logo=discord&logoColor=white&style=for-the-badge"></a>
77
<img src="https://img.shields.io/github/license/retrooper/packetevents?style=for-the-badge&logo=github">
@@ -11,7 +11,7 @@
1111
<h3>Resources</h3>
1212

1313
- [Read documentation](https://docs.packetevents.com/)
14-
- [Getting Started](https://docs.packetevents.com/getting-started)
14+
- [Getting Started](https://docs.packetevents.com/development-setup)
1515
- [JavaDocs](https://javadocs.packetevents.com)
1616
- [Releases](https://github.com/retrooper/packetevents/releases/)
1717
- [Modrinth](https://modrinth.com/plugin/packetevents)

api/src/main/java/com/github/retrooper/packetevents/protocol/packettype/PacketType.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,10 @@ public final class PacketType {
438438
ClientVersion.V_1_21_6,
439439
ClientVersion.V_1_21_9);
440440

441+
private PacketType() {
442+
}
443+
444+
@ApiStatus.Internal
441445
public static void prepare() {
442446
if (PREPARED) {
443447
return;
@@ -457,6 +461,7 @@ public static void prepare() {
457461
}
458462
}
459463

464+
@ApiStatus.Internal
460465
public static boolean isPrepared() {
461466
return PREPARED;
462467
}

api/src/main/java/com/github/retrooper/packetevents/protocol/util/NbtCodec.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,27 @@ public NBT encode(PacketWrapper<?> wrapper, List<T> value) {
113113
}
114114
};
115115
}
116+
117+
default NbtCodec<T> withAlternative(NbtDecoder<T> alternative) {
118+
return new NbtCodec<T>() {
119+
@Override
120+
public T decode(NBT nbt, PacketWrapper<?> wrapper) throws NbtCodecException {
121+
try {
122+
return NbtCodec.this.decode(nbt, wrapper);
123+
} catch (NbtCodecException primaryException) {
124+
try {
125+
return alternative.decode(nbt, wrapper);
126+
} catch (NbtCodecException altException) {
127+
primaryException.addSuppressed(altException);
128+
throw primaryException;
129+
}
130+
}
131+
}
132+
133+
@Override
134+
public NBT encode(PacketWrapper<?> wrapper, T value) throws NbtCodecException {
135+
return NbtCodec.this.encode(wrapper, value);
136+
}
137+
};
138+
}
116139
}

api/src/main/java/com/github/retrooper/packetevents/protocol/util/NbtCodecs.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,26 @@ public NBT encode(PacketWrapper<?> wrapper, int[] value) {
212212

213213
public static final NbtCodec<UUID> UUID = INT_ARRAY
214214
.apply(UniqueIdUtil::fromIntArray, UniqueIdUtil::toIntArray);
215+
public static final NbtCodec<UUID> STRING_UUID = new NbtCodec<UUID>() {
216+
@Override
217+
public UUID decode(NBT nbt, PacketWrapper<?> wrapper) throws NbtCodecException {
218+
String uuidStr = ((NBTString) nbt).getValue();
219+
if (uuidStr.length() == 36) { // fast length check
220+
try {
221+
// try parsing uuid
222+
return java.util.UUID.fromString(uuidStr);
223+
} catch (IllegalArgumentException ignored) {
224+
}
225+
}
226+
throw new NbtCodecException("Invalid UUID " + uuidStr);
227+
}
228+
229+
@Override
230+
public NBT encode(PacketWrapper<?> wrapper, UUID value) throws NbtCodecException {
231+
return new NBTString(value.toString());
232+
}
233+
};
234+
public static final NbtCodec<UUID> LENIENT_UUID = UUID.withAlternative(STRING_UUID);
215235

216236
public static final NbtCodec<Color> RGB_COLOR = new NbtCodec<Color>() {
217237
@Override

api/src/main/java/com/github/retrooper/packetevents/protocol/world/dimension/DimensionType.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,14 @@ public DimensionType decode(NBTCompound compound, PacketWrapper<?> wrapper) thro
103103
builder.setCoordinateScale(compound.getBoolean("shrunk") ? 8d : 1d);
104104
}
105105

106+
builder.setInfiniburn(version.isNewerThanOrEquals(ServerVersion.V_1_18_2)
107+
? compound.getOrThrow("infiniburn", TagKey.CODEC, wrapper)
108+
: new TagKey(compound.getOrThrow("infiniburn", ResourceLocation.CODEC, wrapper)));
109+
106110
return builder
107111
.setHasSkylight(compound.getBooleanOrThrow("has_skylight"))
108112
.setHasCeiling(compound.getBooleanOrThrow("has_ceiling"))
109113
.setLogicalHeight(compound.getNumberTagValueOrThrow("logical_height").intValue())
110-
.setInfiniburn(compound.getOrThrow("infiniburn", TagKey.CODEC, wrapper))
111114
.setAmbientLight(compound.getNumberTagValueOrThrow("ambient_light").floatValue())
112115
.build();
113116
}
@@ -172,7 +175,11 @@ public void encode(NBTCompound compound, PacketWrapper<?> wrapper, DimensionType
172175
compound.setTag("has_skylight", new NBTByte(value.hasSkyLight()));
173176
compound.setTag("has_ceiling", new NBTByte(value.hasCeiling()));
174177
compound.setTag("logical_height", new NBTInt(value.getLogicalHeight()));
175-
compound.set("infiniburn", value.getInfiniburn(), TagKey.CODEC, wrapper);
178+
if (wrapper.getServerVersion().isNewerThanOrEquals(ServerVersion.V_1_18_2)) {
179+
compound.set("infiniburn", value.getInfiniburn(), TagKey.CODEC, wrapper);
180+
} else {
181+
compound.set("infiniburn", value.getInfiniburn().getId(), ResourceLocation.CODEC, wrapper);
182+
}
176183
compound.setTag("ambient_light", new NBTFloat(value.getAmbientLight()));
177184
}
178185
}.codec();

api/src/main/java/com/github/retrooper/packetevents/protocol/world/states/defaulttags/BlockTags.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -387,14 +387,22 @@ public class BlockTags {
387387
* Unofficial tag for all glass panes
388388
*/
389389
public static final BlockTags GLASS_PANES = bind("glass_panes");
390+
/**
391+
* Unofficial tag for all dead coral plants
392+
*/
393+
public static final BlockTags DEAD_CORAL_PLANTS = bind("dead_coral_plants");
394+
/**
395+
* Unofficial tag for all dead coral plants
396+
*/
397+
public static final BlockTags DEAD_CORALS = bind("dead_corals");
390398
/**
391399
* Unofficial tag for all coral plants
392400
*/
393401
public static final BlockTags ALL_CORAL_PLANTS = bind("alive_coral_plants");
394402
/**
395-
* Unofficial tag for all dead coral plants
403+
* Unofficial tag for all corals
396404
*/
397-
public static final BlockTags DEAD_CORAL_PLANTS = bind("dead_coral_plants");
405+
public static final BlockTags ALL_CORALS = bind("all_corals");
398406

399407
/**
400408
* Unofficial tag for all blocks added in 1.20.5
@@ -644,8 +652,10 @@ public class BlockTags {
644652
// Unofficial blocks to help packetevents users
645653
BlockTags.GLASS_BLOCKS.add(StateTypes.GLASS, StateTypes.WHITE_STAINED_GLASS, StateTypes.ORANGE_STAINED_GLASS, StateTypes.MAGENTA_STAINED_GLASS, StateTypes.LIGHT_BLUE_STAINED_GLASS, StateTypes.YELLOW_STAINED_GLASS, StateTypes.LIME_STAINED_GLASS, StateTypes.PINK_STAINED_GLASS, StateTypes.GRAY_STAINED_GLASS, StateTypes.LIGHT_GRAY_STAINED_GLASS, StateTypes.CYAN_STAINED_GLASS, StateTypes.PURPLE_STAINED_GLASS, StateTypes.BLUE_STAINED_GLASS, StateTypes.BROWN_STAINED_GLASS, StateTypes.GREEN_STAINED_GLASS, StateTypes.RED_STAINED_GLASS, StateTypes.BLACK_STAINED_GLASS, StateTypes.TINTED_GLASS);
646654
BlockTags.GLASS_PANES.add(StateTypes.GLASS_PANE, StateTypes.WHITE_STAINED_GLASS_PANE, StateTypes.ORANGE_STAINED_GLASS_PANE, StateTypes.MAGENTA_STAINED_GLASS_PANE, StateTypes.LIGHT_BLUE_STAINED_GLASS_PANE, StateTypes.YELLOW_STAINED_GLASS_PANE, StateTypes.LIME_STAINED_GLASS_PANE, StateTypes.PINK_STAINED_GLASS_PANE, StateTypes.GRAY_STAINED_GLASS_PANE, StateTypes.LIGHT_GRAY_STAINED_GLASS_PANE, StateTypes.CYAN_STAINED_GLASS_PANE, StateTypes.PURPLE_STAINED_GLASS_PANE, StateTypes.BLUE_STAINED_GLASS_PANE, StateTypes.BROWN_STAINED_GLASS_PANE, StateTypes.GREEN_STAINED_GLASS_PANE, StateTypes.RED_STAINED_GLASS_PANE, StateTypes.BLACK_STAINED_GLASS_PANE);
647-
BlockTags.ALL_CORAL_PLANTS.add(StateTypes.TUBE_CORAL, StateTypes.BRAIN_CORAL, StateTypes.BUBBLE_CORAL, StateTypes.FIRE_CORAL, StateTypes.HORN_CORAL, StateTypes.DEAD_TUBE_CORAL, StateTypes.DEAD_BRAIN_CORAL, StateTypes.DEAD_BUBBLE_CORAL, StateTypes.DEAD_FIRE_CORAL, StateTypes.DEAD_HORN_CORAL);
648655
BlockTags.DEAD_CORAL_PLANTS.add(StateTypes.DEAD_TUBE_CORAL, StateTypes.DEAD_BRAIN_CORAL, StateTypes.DEAD_BUBBLE_CORAL, StateTypes.DEAD_FIRE_CORAL, StateTypes.DEAD_HORN_CORAL);
656+
BlockTags.DEAD_CORALS.addTag(DEAD_CORAL_PLANTS).add(StateTypes.DEAD_TUBE_CORAL_FAN, StateTypes.DEAD_BRAIN_CORAL_FAN, StateTypes.DEAD_BUBBLE_CORAL_FAN, StateTypes.DEAD_FIRE_CORAL_FAN, StateTypes.DEAD_HORN_CORAL_FAN);
657+
BlockTags.ALL_CORAL_PLANTS.addTag(CORAL_PLANTS).addTag(DEAD_CORAL_PLANTS);
658+
BlockTags.ALL_CORALS.addTag(CORALS).addTag(DEAD_CORALS);
649659
BlockTags.V_1_20_5.add(StateTypes.VAULT, StateTypes.HEAVY_CORE);
650660
BlockTags.V_1_21_2.add(StateTypes.PALE_OAK_WOOD, StateTypes.PALE_OAK_PLANKS, StateTypes.PALE_OAK_SAPLING, StateTypes.PALE_OAK_LOG, StateTypes.STRIPPED_PALE_OAK_LOG, StateTypes.STRIPPED_PALE_OAK_WOOD, StateTypes.PALE_OAK_LEAVES, StateTypes.CREAKING_HEART, StateTypes.PALE_OAK_SIGN, StateTypes.PALE_OAK_WALL_SIGN, StateTypes.PALE_OAK_HANGING_SIGN, StateTypes.PALE_OAK_WALL_HANGING_SIGN, StateTypes.PALE_OAK_PRESSURE_PLATE, StateTypes.PALE_OAK_TRAPDOOR, StateTypes.POTTED_PALE_OAK_SAPLING, StateTypes.PALE_OAK_BUTTON, StateTypes.PALE_OAK_STAIRS, StateTypes.PALE_OAK_SLAB, StateTypes.PALE_OAK_FENCE_GATE, StateTypes.PALE_OAK_FENCE, StateTypes.PALE_OAK_DOOR, StateTypes.PALE_MOSS_BLOCK, StateTypes.PALE_MOSS_CARPET, StateTypes.PALE_HANGING_MOSS);
651661
BlockTags.V_1_21_4.add(StateTypes.RESIN_CLUMP, StateTypes.RESIN_BLOCK, StateTypes.RESIN_BRICKS, StateTypes.RESIN_BRICK_STAIRS, StateTypes.RESIN_BRICK_SLAB, StateTypes.RESIN_BRICK_WALL, StateTypes.CHISELED_RESIN_BRICKS, StateTypes.OPEN_EYEBLOSSOM, StateTypes.CLOSED_EYEBLOSSOM, StateTypes.POTTED_OPEN_EYEBLOSSOM, StateTypes.POTTED_CLOSED_EYEBLOSSOM);

api/src/main/java/com/github/retrooper/packetevents/util/adventure/AdventureNBTSerializer.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
import com.github.retrooper.packetevents.protocol.nbt.NBTString;
3939
import com.github.retrooper.packetevents.protocol.nbt.NBTType;
4040
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
41+
import com.github.retrooper.packetevents.protocol.util.NbtCodecs;
42+
import com.github.retrooper.packetevents.protocol.util.NbtDecoder;
4143
import com.github.retrooper.packetevents.util.UniqueIdUtil;
4244
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
4345
import net.kyori.adventure.key.Key;
@@ -169,7 +171,7 @@ public AdventureNBTSerializer(boolean downsampleColor) {
169171

170172
// Serialized as tree
171173
NBTCompound compound = requireType(input, NBTType.COMPOUND);
172-
NBTReader reader = new NBTReader(compound);
174+
NBTReader reader = new NBTReader(wrapper, compound);
173175

174176
Function<NBT, String> textFunction = nbt -> {
175177
if (nbt.getType() == NBTType.STRING) {
@@ -461,7 +463,7 @@ public AdventureNBTSerializer(boolean downsampleColor) {
461463
if (input.isEmpty()) return Style.empty();
462464

463465
Style.Builder style = Style.style();
464-
NBTReader reader = new NBTReader(input);
466+
NBTReader reader = new NBTReader(wrapper, input);
465467

466468
reader.useUTF("font", value -> style.font(Key.key(value)));
467469
reader.useUTF("color", value -> {
@@ -569,7 +571,7 @@ public AdventureNBTSerializer(boolean downsampleColor) {
569571
if (entity != null) {
570572
style.hoverEvent(HoverEvent.showEntity(
571573
entity.readUTF(modernEvents ? "id" : "type", Key::key),
572-
entity.readIntArray(modernEvents ? "uuid" : "id", UniqueIdUtil::fromIntArray),
574+
entity.read(modernEvents ? "uuid" : "id", NbtCodecs.LENIENT_UUID),
573575
entity.read("name", name -> this.deserialize(name, wrapper))));
574576
}
575577
break;
@@ -808,9 +810,12 @@ private List<NBTCompound> serializeTranslationArgumentList(List<TranslationArgum
808810
// -------------------------------------------------
809811

810812
static class NBTReader {
813+
814+
private final PacketWrapper<?> wrapper;
811815
private final NBTCompound compound;
812816

813-
public NBTReader(NBTCompound compound) {
817+
public NBTReader(PacketWrapper<?> wrapper, NBTCompound compound) {
818+
this.wrapper = wrapper;
814819
this.compound = compound;
815820
}
816821

@@ -894,12 +899,19 @@ public void use(String key, Consumer<NBT> consumer) {
894899
useTag(key, consumer);
895900
}
896901

902+
public <R> R read(String key, NbtDecoder<R> decoder) {
903+
return withTag(key, tag -> decoder.decode(tag, this.wrapper));
904+
}
905+
897906
public <R> R read(String key, Function<NBT, R> function) {
898907
return withTag(key, function);
899908
}
900909

901910
public NBTReader child(String key) {
902-
return withTag(key, tag -> new NBTReader(requireType(tag, NBTType.COMPOUND)));
911+
return withTag(key, tag -> {
912+
NBTCompound compound = requireType(tag, NBTType.COMPOUND);
913+
return new NBTReader(this.wrapper, compound);
914+
});
903915
}
904916

905917
public NBTType<?> type(String key) {

api/src/test/java/com/github/retrooper/packetevents/test/base/TestPacketEventsBuilder.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,7 @@ public void load() {
9393
PacketEvents.SERVER_CHANNEL_HANDLER_NAME = "pe-connection-initializer-" + id;
9494
PacketEvents.TIMEOUT_HANDLER_NAME = "pe-timeout-handler-" + id;
9595

96-
if (!PacketType.isPrepared()) {
97-
PacketType.prepare();
98-
}
96+
PacketType.prepare();
9997

10098
loaded = true;
10199
}

0 commit comments

Comments
 (0)