From 3b6a4ffe699ca919113392eac90b8e6b6e75e028 Mon Sep 17 00:00:00 2001 From: AlexProgrammerDE <40795980+AlexProgrammerDE@users.noreply.github.com> Date: Tue, 14 May 2024 18:13:09 +0200 Subject: [PATCH 01/11] Use built-in ResourceLocation type --- .../protocol/ServerListener.java | 5 +++-- .../protocol/codec/MinecraftCodecHelper.java | 14 ++++++------- .../protocol/data/game/Identifier.java | 10 ---------- .../protocol/data/game/RegistryEntry.java | 2 +- .../protocol/data/game/ResourceLocation.java | 20 +++++++++++++++++++ .../data/game/chat/BuiltinChatType.java | 12 +++++------ .../data/game/command/CommandNode.java | 3 ++- .../data/game/command/SuggestionType.java | 12 +++++------ .../properties/ResourceProperties.java | 6 +++--- .../data/game/entity/metadata/GlobalPos.java | 7 ++++--- .../component/AdventureModePredicate.java | 3 ++- .../data/game/item/component/ArmorTrim.java | 3 ++- .../item/component/BannerPatternLayer.java | 3 ++- .../item/component/DataComponentType.java | 3 ++- .../game/item/component/ItemCodecHelper.java | 7 ++++--- .../data/game/item/component/ToolData.java | 3 ++- .../protocol/data/game/recipe/Recipe.java | 3 ++- .../ClientboundCookieRequestPacket.java | 3 ++- .../ClientboundStoreCookiePacket.java | 3 ++- .../ClientboundUpdateTagsPacket.java | 13 ++++++------ .../ServerboundCookieResponsePacket.java | 3 ++- .../ClientboundRegistryDataPacket.java | 3 ++- .../ClientboundCommandsPacket.java | 5 +++-- .../ClientboundStopSoundPacket.java | 3 ++- .../ClientboundUpdateRecipesPacket.java | 3 ++- .../clientbound/ServerDeclareRecipesTest.java | 11 +++++----- 26 files changed, 96 insertions(+), 67 deletions(-) delete mode 100644 protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/Identifier.java create mode 100644 protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/ResourceLocation.java diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/ServerListener.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/ServerListener.java index 3d72d0db0..038f95950 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/ServerListener.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/ServerListener.java @@ -14,6 +14,7 @@ import org.geysermc.mcprotocollib.network.packet.Packet; import org.geysermc.mcprotocollib.protocol.data.ProtocolState; import org.geysermc.mcprotocollib.protocol.data.game.RegistryEntry; +import org.geysermc.mcprotocollib.protocol.data.game.ResourceLocation; import org.geysermc.mcprotocollib.protocol.data.status.PlayerInfo; import org.geysermc.mcprotocollib.protocol.data.status.ServerStatusInfo; import org.geysermc.mcprotocollib.protocol.data.status.VersionInfo; @@ -137,11 +138,11 @@ public void packetReceived(Session session, Packet packet) { // Credit ViaVersion: https://github.com/ViaVersion/ViaVersion/blob/dev/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/EntityPacketRewriter1_20_5.java for (Map.Entry entry : networkCodec.entrySet()) { NbtMap entryTag = (NbtMap) entry.getValue(); - String typeTag = entryTag.getString("type"); + ResourceLocation typeTag = ResourceLocation.fromString(entryTag.getString("type")); List valueTag = entryTag.getList("value", NbtType.COMPOUND); List entries = new ArrayList<>(); for (NbtMap compoundTag : valueTag) { - String nameTag = compoundTag.getString("name"); + ResourceLocation nameTag = ResourceLocation.fromString(compoundTag.getString("name")); int id = compoundTag.getInt("id"); entries.add(id, new RegistryEntry(nameTag, compoundTag.getCompound("element"))); } diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/codec/MinecraftCodecHelper.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/codec/MinecraftCodecHelper.java index b81a095c1..3687896bf 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/codec/MinecraftCodecHelper.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/codec/MinecraftCodecHelper.java @@ -20,7 +20,7 @@ import org.geysermc.mcprotocollib.network.codec.BasePacketCodecHelper; import org.geysermc.mcprotocollib.protocol.data.DefaultComponentSerializer; import org.geysermc.mcprotocollib.protocol.data.game.Holder; -import org.geysermc.mcprotocollib.protocol.data.game.Identifier; +import org.geysermc.mcprotocollib.protocol.data.game.ResourceLocation; import org.geysermc.mcprotocollib.protocol.data.game.chat.numbers.BlankFormat; import org.geysermc.mcprotocollib.protocol.data.game.chat.numbers.FixedFormat; import org.geysermc.mcprotocollib.protocol.data.game.chat.numbers.NumberFormat; @@ -144,12 +144,12 @@ public void writeHolder(ByteBuf buf, Holder holder, BiConsumer type) { } public GlobalPos readGlobalPos(ByteBuf buf) { - String dimension = Identifier.formalize(this.readString(buf)); + ResourceLocation dimension = ResourceLocation.fromString(this.readString(buf)); Vector3i pos = this.readPosition(buf); return new GlobalPos(dimension, pos); } public void writeGlobalPos(ByteBuf buf, GlobalPos pos) { - this.writeString(buf, pos.getDimension()); + this.writeResourceLocation(buf, pos.getDimension()); this.writePosition(buf, pos.getPosition()); } diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/Identifier.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/Identifier.java deleted file mode 100644 index 7044f1164..000000000 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/Identifier.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.geysermc.mcprotocollib.protocol.data.game; - -public final class Identifier { - private Identifier() { - } - - public static String formalize(String identifier) { - return !identifier.contains(":") ? "minecraft:" + identifier : identifier; - } -} diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/RegistryEntry.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/RegistryEntry.java index 55b3f7728..9f9b2b507 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/RegistryEntry.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/RegistryEntry.java @@ -8,6 +8,6 @@ @Data @AllArgsConstructor public class RegistryEntry { - private final String id; + private final ResourceLocation id; private final @Nullable NbtMap data; } diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/ResourceLocation.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/ResourceLocation.java new file mode 100644 index 000000000..2b153ef9b --- /dev/null +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/ResourceLocation.java @@ -0,0 +1,20 @@ +package org.geysermc.mcprotocollib.protocol.data.game; + +public record ResourceLocation(String namespace, String path) { + public static ResourceLocation fromString(String identifier) { + int index = identifier.indexOf(':'); + if (index == -1) { + return new ResourceLocation("minecraft", identifier); + } else { + return new ResourceLocation( + identifier.substring(0, index), + identifier.substring(index + 1) + ); + } + } + + @Override + public String toString() { + return namespace + ":" + path; + } +} diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/chat/BuiltinChatType.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/chat/BuiltinChatType.java index 9edddbee2..14600cc68 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/chat/BuiltinChatType.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/chat/BuiltinChatType.java @@ -1,6 +1,6 @@ package org.geysermc.mcprotocollib.protocol.data.game.chat; -import org.geysermc.mcprotocollib.protocol.data.game.Identifier; +import org.geysermc.mcprotocollib.protocol.data.game.ResourceLocation; import java.util.HashMap; import java.util.Locale; @@ -15,19 +15,19 @@ public enum BuiltinChatType { TEAM_MSG_COMMAND_OUTGOING, EMOTE_COMMAND; - private final String resourceLocation; + private final ResourceLocation resourceLocation; BuiltinChatType() { - this.resourceLocation = Identifier.formalize(name().toLowerCase(Locale.ROOT)); + this.resourceLocation = ResourceLocation.fromString(name().toLowerCase(Locale.ROOT)); } - public String getResourceLocation() { + public ResourceLocation getResourceLocation() { return resourceLocation; } - private static final Map VALUES = new HashMap<>(); + private static final Map VALUES = new HashMap<>(); - public static BuiltinChatType from(String resourceLocation) { + public static BuiltinChatType from(ResourceLocation resourceLocation) { return VALUES.get(resourceLocation); } diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/command/CommandNode.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/command/CommandNode.java index f36a555c3..da66733a8 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/command/CommandNode.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/command/CommandNode.java @@ -3,6 +3,7 @@ import lombok.AllArgsConstructor; import lombok.Data; import lombok.NonNull; +import org.geysermc.mcprotocollib.protocol.data.game.ResourceLocation; import org.geysermc.mcprotocollib.protocol.data.game.command.properties.CommandProperties; import java.util.OptionalInt; @@ -49,5 +50,5 @@ public class CommandNode { * Suggestions type, if present. * See {@link SuggestionType} for vanilla defaults. */ - private final String suggestionType; + private final ResourceLocation suggestionType; } diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/command/SuggestionType.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/command/SuggestionType.java index 9a6ec9af1..ba3e3c4f9 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/command/SuggestionType.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/command/SuggestionType.java @@ -1,7 +1,7 @@ package org.geysermc.mcprotocollib.protocol.data.game.command; import org.checkerframework.checker.nullness.qual.NonNull; -import org.geysermc.mcprotocollib.protocol.data.game.Identifier; +import org.geysermc.mcprotocollib.protocol.data.game.ResourceLocation; import java.util.HashMap; import java.util.Locale; @@ -13,20 +13,20 @@ public enum SuggestionType { AVAILABLE_SOUNDS, SUMMONABLE_ENTITIES; - private final String resourceLocation; + private final ResourceLocation resourceLocation; SuggestionType() { - this.resourceLocation = Identifier.formalize(name().toLowerCase(Locale.ROOT)); + this.resourceLocation = ResourceLocation.fromString(name().toLowerCase(Locale.ROOT)); } - public String getResourceLocation() { + public ResourceLocation getResourceLocation() { return resourceLocation; } - private static final Map VALUES = new HashMap<>(); + private static final Map VALUES = new HashMap<>(); @NonNull - public static SuggestionType from(String resourceLocation) { + public static SuggestionType from(ResourceLocation resourceLocation) { // Vanilla behavior as of 1.19.3 // 1.16.5 still has AVAILABLE_BIOMES and vanilla doesn't care return VALUES.getOrDefault(resourceLocation, ASK_SERVER); diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/command/properties/ResourceProperties.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/command/properties/ResourceProperties.java index 75ffaefa4..35918af01 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/command/properties/ResourceProperties.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/command/properties/ResourceProperties.java @@ -1,13 +1,13 @@ package org.geysermc.mcprotocollib.protocol.data.game.command.properties; import lombok.Data; -import org.geysermc.mcprotocollib.protocol.data.game.Identifier; +import org.geysermc.mcprotocollib.protocol.data.game.ResourceLocation; @Data public class ResourceProperties implements CommandProperties { - private final String registryKey; + private final ResourceLocation registryKey; public ResourceProperties(String registryKey) { - this.registryKey = Identifier.formalize(registryKey); + this.registryKey = ResourceLocation.fromString(registryKey); } } diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/entity/metadata/GlobalPos.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/entity/metadata/GlobalPos.java index 6489b59e0..99747abc6 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/entity/metadata/GlobalPos.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/entity/metadata/GlobalPos.java @@ -1,17 +1,18 @@ package org.geysermc.mcprotocollib.protocol.data.game.entity.metadata; import org.cloudburstmc.math.vector.Vector3i; +import org.geysermc.mcprotocollib.protocol.data.game.ResourceLocation; public class GlobalPos { - private final String dimension; + private final ResourceLocation dimension; private final Vector3i position; - public GlobalPos(String dimension, Vector3i position) { + public GlobalPos(ResourceLocation dimension, Vector3i position) { this.dimension = dimension; this.position = position; } - public String getDimension() { + public ResourceLocation getDimension() { return dimension; } diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/AdventureModePredicate.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/AdventureModePredicate.java index 4b0666937..db9482bbc 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/AdventureModePredicate.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/AdventureModePredicate.java @@ -3,6 +3,7 @@ import lombok.AllArgsConstructor; import lombok.Data; import org.cloudburstmc.nbt.NbtMap; +import org.geysermc.mcprotocollib.protocol.data.game.ResourceLocation; import org.jetbrains.annotations.Nullable; import java.util.List; @@ -16,7 +17,7 @@ public class AdventureModePredicate { @Data @AllArgsConstructor public static class BlockPredicate { - private final @Nullable String location; + private final @Nullable ResourceLocation location; private final int @Nullable [] holders; private final @Nullable List properties; private final @Nullable NbtMap nbt; diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/ArmorTrim.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/ArmorTrim.java index 285f5ea55..d2a5d7222 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/ArmorTrim.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/ArmorTrim.java @@ -3,12 +3,13 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import net.kyori.adventure.text.Component; import org.geysermc.mcprotocollib.protocol.data.game.Holder; +import org.geysermc.mcprotocollib.protocol.data.game.ResourceLocation; public record ArmorTrim(Holder material, Holder pattern, boolean showInTooltip) { public record TrimMaterial(String assetName, int ingredientId, float itemModelIndex, Int2ObjectMap overrideArmorMaterials, Component description) { } - public record TrimPattern(String assetId, int templateItemId, Component description, boolean decal) { + public record TrimPattern(ResourceLocation assetId, int templateItemId, Component description, boolean decal) { } } diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/BannerPatternLayer.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/BannerPatternLayer.java index e16a50eb0..0797aec9e 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/BannerPatternLayer.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/BannerPatternLayer.java @@ -3,6 +3,7 @@ import lombok.AllArgsConstructor; import lombok.Data; import org.geysermc.mcprotocollib.protocol.data.game.Holder; +import org.geysermc.mcprotocollib.protocol.data.game.ResourceLocation; @Data @AllArgsConstructor @@ -13,7 +14,7 @@ public class BannerPatternLayer { @Data @AllArgsConstructor public static class BannerPattern { - private final String assetId; + private final ResourceLocation assetId; private final String translationKey; } } diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/DataComponentType.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/DataComponentType.java index 24453b959..c90e5acd7 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/DataComponentType.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/DataComponentType.java @@ -8,6 +8,7 @@ import org.cloudburstmc.nbt.NbtMap; import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper; import org.geysermc.mcprotocollib.protocol.data.game.Holder; +import org.geysermc.mcprotocollib.protocol.data.game.ResourceLocation; import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack; import org.geysermc.mcprotocollib.protocol.data.game.item.component.type.BooleanDataComponent; import org.geysermc.mcprotocollib.protocol.data.game.item.component.type.IntDataComponent; @@ -67,7 +68,7 @@ public class DataComponentType { public static final DataComponentType FIREWORK_EXPLOSION = new DataComponentType<>(ItemCodecHelper::readFireworkExplosion, ItemCodecHelper::writeFireworkExplosion, ObjectDataComponent::new); public static final DataComponentType FIREWORKS = new DataComponentType<>(ItemCodecHelper::readFireworks, ItemCodecHelper::writeFireworks, ObjectDataComponent::new); public static final DataComponentType PROFILE = new DataComponentType<>(ItemCodecHelper::readResolvableProfile, ItemCodecHelper::writeResolvableProfile, ObjectDataComponent::new); - public static final DataComponentType NOTE_BLOCK_SOUND = new DataComponentType<>(ItemCodecHelper::readResourceLocation, ItemCodecHelper::writeResourceLocation, ObjectDataComponent::new); + public static final DataComponentType NOTE_BLOCK_SOUND = new DataComponentType<>(ItemCodecHelper::readResourceLocation, ItemCodecHelper::writeResourceLocation, ObjectDataComponent::new); public static final DataComponentType> BANNER_PATTERNS = new DataComponentType<>(listReader(ItemCodecHelper::readBannerPatternLayer), listWriter(ItemCodecHelper::writeBannerPatternLayer), ObjectDataComponent::new); public static final IntComponentType BASE_COLOR = new IntComponentType(ItemCodecHelper::readVarInt, ItemCodecHelper::writeVarInt, IntDataComponent::new); public static final DataComponentType> POT_DECORATIONS = new DataComponentType<>(listReader(ItemCodecHelper::readVarInt), listWriter(ItemCodecHelper::writeVarInt), ObjectDataComponent::new); diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/ItemCodecHelper.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/ItemCodecHelper.java index 80b76383a..8fd78be58 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/ItemCodecHelper.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/ItemCodecHelper.java @@ -10,6 +10,7 @@ import org.cloudburstmc.nbt.NbtType; import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper; import org.geysermc.mcprotocollib.protocol.data.game.Holder; +import org.geysermc.mcprotocollib.protocol.data.game.ResourceLocation; import org.geysermc.mcprotocollib.protocol.data.game.entity.Effect; import org.geysermc.mcprotocollib.protocol.data.game.entity.attribute.ModifierOperation; import org.geysermc.mcprotocollib.protocol.data.game.level.sound.BuiltinSound; @@ -92,7 +93,7 @@ public void writeAdventureModePredicate(ByteBuf buf, AdventureModePredicate adve } public AdventureModePredicate.BlockPredicate readBlockPredicate(ByteBuf buf) { - String location = null; + ResourceLocation location = null; int[] holders = null; List propertyMatchers = null; @@ -164,7 +165,7 @@ public ToolData readToolData(ByteBuf buf) { List rules = new ArrayList<>(); int ruleCount = this.readVarInt(buf); for (int i = 0; i < ruleCount; i++) { - String location = null; + ResourceLocation location = null; int[] holders = null; int length = this.readVarInt(buf) - 1; @@ -431,7 +432,7 @@ public void writeTrimMaterial(ByteBuf buf, ArmorTrim.TrimMaterial material) { } public ArmorTrim.TrimPattern readTrimPattern(ByteBuf buf) { - String assetId = this.readResourceLocation(buf); + ResourceLocation assetId = this.readResourceLocation(buf); int templateItemId = this.readVarInt(buf); Component description = this.readComponent(buf); boolean decal = buf.readBoolean(); diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/ToolData.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/ToolData.java index 93891af39..143184474 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/ToolData.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/ToolData.java @@ -2,6 +2,7 @@ import lombok.AllArgsConstructor; import lombok.Data; +import org.geysermc.mcprotocollib.protocol.data.game.ResourceLocation; import org.jetbrains.annotations.Nullable; import java.util.List; @@ -16,7 +17,7 @@ public class ToolData { @Data @AllArgsConstructor public static class Rule { - private final @Nullable String location; + private final @Nullable ResourceLocation location; private final int @Nullable [] holders; private final @Nullable Float speed; private final @Nullable Boolean correctForDrops; diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/recipe/Recipe.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/recipe/Recipe.java index 378547f0d..de304565d 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/recipe/Recipe.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/recipe/Recipe.java @@ -3,12 +3,13 @@ import lombok.AllArgsConstructor; import lombok.Data; import lombok.NonNull; +import org.geysermc.mcprotocollib.protocol.data.game.ResourceLocation; import org.geysermc.mcprotocollib.protocol.data.game.recipe.data.RecipeData; @Data @AllArgsConstructor public class Recipe { private final @NonNull RecipeType type; - private final @NonNull String identifier; + private final @NonNull ResourceLocation identifier; private final RecipeData data; } diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/common/clientbound/ClientboundCookieRequestPacket.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/common/clientbound/ClientboundCookieRequestPacket.java index 664a61ada..8f8f156d5 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/common/clientbound/ClientboundCookieRequestPacket.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/common/clientbound/ClientboundCookieRequestPacket.java @@ -6,12 +6,13 @@ import lombok.With; import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper; import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket; +import org.geysermc.mcprotocollib.protocol.data.game.ResourceLocation; @Data @With @AllArgsConstructor public class ClientboundCookieRequestPacket implements MinecraftPacket { - private final String key; + private final ResourceLocation key; public ClientboundCookieRequestPacket(ByteBuf in, MinecraftCodecHelper helper) { this.key = helper.readResourceLocation(in); diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/common/clientbound/ClientboundStoreCookiePacket.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/common/clientbound/ClientboundStoreCookiePacket.java index 0adace16f..20b7f1765 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/common/clientbound/ClientboundStoreCookiePacket.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/common/clientbound/ClientboundStoreCookiePacket.java @@ -6,12 +6,13 @@ import lombok.With; import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper; import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket; +import org.geysermc.mcprotocollib.protocol.data.game.ResourceLocation; @Data @With @AllArgsConstructor public class ClientboundStoreCookiePacket implements MinecraftPacket { - private final String key; + private final ResourceLocation key; private final byte[] payload; public ClientboundStoreCookiePacket(ByteBuf in, MinecraftCodecHelper helper) { diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/common/clientbound/ClientboundUpdateTagsPacket.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/common/clientbound/ClientboundUpdateTagsPacket.java index aadad28a9..72d5ed875 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/common/clientbound/ClientboundUpdateTagsPacket.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/common/clientbound/ClientboundUpdateTagsPacket.java @@ -7,6 +7,7 @@ import lombok.With; import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper; import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket; +import org.geysermc.mcprotocollib.protocol.data.game.ResourceLocation; import java.util.HashMap; import java.util.Map; @@ -15,16 +16,16 @@ @With @AllArgsConstructor public class ClientboundUpdateTagsPacket implements MinecraftPacket { - private final @NonNull Map> tags = new HashMap<>(); + private final @NonNull Map> tags = new HashMap<>(); public ClientboundUpdateTagsPacket(ByteBuf in, MinecraftCodecHelper helper) { int totalTagCount = helper.readVarInt(in); for (int i = 0; i < totalTagCount; i++) { - Map tag = new HashMap<>(); - String tagName = helper.readResourceLocation(in); + Map tag = new HashMap<>(); + ResourceLocation tagName = helper.readResourceLocation(in); int tagsCount = helper.readVarInt(in); for (int j = 0; j < tagsCount; j++) { - String name = helper.readResourceLocation(in); + ResourceLocation name = helper.readResourceLocation(in); int entriesCount = helper.readVarInt(in); int[] entries = new int[entriesCount]; for (int index = 0; index < entriesCount; index++) { @@ -40,10 +41,10 @@ public ClientboundUpdateTagsPacket(ByteBuf in, MinecraftCodecHelper helper) { @Override public void serialize(ByteBuf out, MinecraftCodecHelper helper) { helper.writeVarInt(out, tags.size()); - for (Map.Entry> tagSet : tags.entrySet()) { + for (Map.Entry> tagSet : tags.entrySet()) { helper.writeResourceLocation(out, tagSet.getKey()); helper.writeVarInt(out, tagSet.getValue().size()); - for (Map.Entry tag : tagSet.getValue().entrySet()) { + for (Map.Entry tag : tagSet.getValue().entrySet()) { helper.writeResourceLocation(out, tag.getKey()); helper.writeVarInt(out, tag.getValue().length); for (int id : tag.getValue()) { diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/common/clientbound/ServerboundCookieResponsePacket.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/common/clientbound/ServerboundCookieResponsePacket.java index 876272281..14515eead 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/common/clientbound/ServerboundCookieResponsePacket.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/common/clientbound/ServerboundCookieResponsePacket.java @@ -6,13 +6,14 @@ import lombok.With; import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper; import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket; +import org.geysermc.mcprotocollib.protocol.data.game.ResourceLocation; import org.jetbrains.annotations.Nullable; @Data @With @AllArgsConstructor public class ServerboundCookieResponsePacket implements MinecraftPacket { - private final String key; + private final ResourceLocation key; private final byte @Nullable [] payload; public ServerboundCookieResponsePacket(ByteBuf in, MinecraftCodecHelper helper) { diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/configuration/clientbound/ClientboundRegistryDataPacket.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/configuration/clientbound/ClientboundRegistryDataPacket.java index d93c14f99..21900bafa 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/configuration/clientbound/ClientboundRegistryDataPacket.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/configuration/clientbound/ClientboundRegistryDataPacket.java @@ -7,6 +7,7 @@ import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper; import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket; import org.geysermc.mcprotocollib.protocol.data.game.RegistryEntry; +import org.geysermc.mcprotocollib.protocol.data.game.ResourceLocation; import java.util.ArrayList; import java.util.List; @@ -15,7 +16,7 @@ @With @AllArgsConstructor public class ClientboundRegistryDataPacket implements MinecraftPacket { - private final String registry; + private final ResourceLocation registry; private final List entries; public ClientboundRegistryDataPacket(ByteBuf in, MinecraftCodecHelper helper) { diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/ingame/clientbound/ClientboundCommandsPacket.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/ingame/clientbound/ClientboundCommandsPacket.java index c89045ef7..6e00ec7bf 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/ingame/clientbound/ClientboundCommandsPacket.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/ingame/clientbound/ClientboundCommandsPacket.java @@ -7,6 +7,7 @@ import lombok.With; import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper; import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket; +import org.geysermc.mcprotocollib.protocol.data.game.ResourceLocation; import org.geysermc.mcprotocollib.protocol.data.game.command.CommandNode; import org.geysermc.mcprotocollib.protocol.data.game.command.CommandParser; import org.geysermc.mcprotocollib.protocol.data.game.command.CommandType; @@ -67,7 +68,7 @@ public ClientboundCommandsPacket(ByteBuf in, MinecraftCodecHelper helper) { CommandParser parser = null; CommandProperties properties = null; - String suggestionType = null; + ResourceLocation suggestionType = null; if (type == CommandType.ARGUMENT) { parser = CommandParser.from(helper.readVarInt(in)); switch (parser) { @@ -286,7 +287,7 @@ public void serialize(ByteBuf out, MinecraftCodecHelper helper) { } case SCORE_HOLDER -> out.writeBoolean(((ScoreHolderProperties) node.getProperties()).isAllowMultiple()); case TIME -> out.writeInt(((TimeProperties) node.getProperties()).getMin()); - case RESOURCE_OR_TAG, RESOURCE_OR_TAG_KEY, RESOURCE, RESOURCE_KEY -> helper.writeString(out, ((ResourceProperties) node.getProperties()).getRegistryKey()); + case RESOURCE_OR_TAG, RESOURCE_OR_TAG_KEY, RESOURCE, RESOURCE_KEY -> helper.writeResourceLocation(out, ((ResourceProperties) node.getProperties()).getRegistryKey()); default -> { } } diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/ingame/clientbound/ClientboundStopSoundPacket.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/ingame/clientbound/ClientboundStopSoundPacket.java index 79b61ea2a..b82771637 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/ingame/clientbound/ClientboundStopSoundPacket.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/ingame/clientbound/ClientboundStopSoundPacket.java @@ -7,6 +7,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper; import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket; +import org.geysermc.mcprotocollib.protocol.data.game.ResourceLocation; import org.geysermc.mcprotocollib.protocol.data.game.level.sound.SoundCategory; @Data @@ -17,7 +18,7 @@ public class ClientboundStopSoundPacket implements MinecraftPacket { private static final int FLAG_SOUND = 0x02; private final @Nullable SoundCategory category; - private final @Nullable String sound; + private final @Nullable ResourceLocation sound; public ClientboundStopSoundPacket(ByteBuf in, MinecraftCodecHelper helper) { int flags = in.readByte(); diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/ingame/clientbound/ClientboundUpdateRecipesPacket.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/ingame/clientbound/ClientboundUpdateRecipesPacket.java index 9cdd0afe8..f863eacd4 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/ingame/clientbound/ClientboundUpdateRecipesPacket.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/ingame/clientbound/ClientboundUpdateRecipesPacket.java @@ -7,6 +7,7 @@ import lombok.With; import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper; import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket; +import org.geysermc.mcprotocollib.protocol.data.game.ResourceLocation; import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack; import org.geysermc.mcprotocollib.protocol.data.game.recipe.CraftingBookCategory; import org.geysermc.mcprotocollib.protocol.data.game.recipe.Ingredient; @@ -30,7 +31,7 @@ public class ClientboundUpdateRecipesPacket implements MinecraftPacket { public ClientboundUpdateRecipesPacket(ByteBuf in, MinecraftCodecHelper helper) { this.recipes = new Recipe[helper.readVarInt(in)]; for (int i = 0; i < this.recipes.length; i++) { - String identifier = helper.readResourceLocation(in); + ResourceLocation identifier = helper.readResourceLocation(in); RecipeType type = RecipeType.from(helper.readVarInt(in)); RecipeData data; switch (type) { diff --git a/protocol/src/test/java/org/geysermc/mcprotocollib/protocol/packet/ingame/clientbound/ServerDeclareRecipesTest.java b/protocol/src/test/java/org/geysermc/mcprotocollib/protocol/packet/ingame/clientbound/ServerDeclareRecipesTest.java index 26ea4a640..4d3cf1ae7 100644 --- a/protocol/src/test/java/org/geysermc/mcprotocollib/protocol/packet/ingame/clientbound/ServerDeclareRecipesTest.java +++ b/protocol/src/test/java/org/geysermc/mcprotocollib/protocol/packet/ingame/clientbound/ServerDeclareRecipesTest.java @@ -1,5 +1,6 @@ package org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound; +import org.geysermc.mcprotocollib.protocol.data.game.ResourceLocation; import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack; import org.geysermc.mcprotocollib.protocol.data.game.recipe.CraftingBookCategory; import org.geysermc.mcprotocollib.protocol.data.game.recipe.Ingredient; @@ -21,7 +22,7 @@ public void setup() { new Recipe[]{ new Recipe( RecipeType.CRAFTING_SHAPELESS, - "minecraft:Recipe1", + ResourceLocation.fromString("minecraft:Recipe1"), new ShapelessRecipeData( "Group1", CraftingBookCategory.MISC, @@ -35,7 +36,7 @@ public void setup() { ), new Recipe( RecipeType.CRAFTING_SHAPED, - "minecraft:Recipe2", + ResourceLocation.fromString("minecraft:Recipe2"), new ShapedRecipeData( 2, 3, @@ -67,7 +68,7 @@ public void setup() { ), new Recipe( RecipeType.SMELTING, - "minecraft:Recipe3", + ResourceLocation.fromString("minecraft:Recipe3"), new CookedRecipeData( "Group3", CraftingBookCategory.EQUIPMENT, @@ -81,7 +82,7 @@ public void setup() { ), new Recipe( RecipeType.STONECUTTING, - "minecraft:Recipe4", + ResourceLocation.fromString("minecraft:Recipe4"), new StoneCuttingRecipeData( "Group4", new Ingredient(new ItemStack[]{ @@ -93,7 +94,7 @@ public void setup() { ), new Recipe( RecipeType.SMITHING_TRANSFORM, - "minecraft:Recipe5", + ResourceLocation.fromString("minecraft:Recipe5"), new SmithingTransformRecipeData( new Ingredient(new ItemStack[]{ new ItemStack(10) From 6e388122ccdbfe88c82a5ef4e2ca968475576a3d Mon Sep 17 00:00:00 2001 From: AlexProgrammerDE <40795980+AlexProgrammerDE@users.noreply.github.com> Date: Tue, 14 May 2024 18:36:11 +0200 Subject: [PATCH 02/11] Use kyori Key instead of built-in type --- .../protocol/ServerListener.java | 6 +++--- .../protocol/codec/MinecraftCodecHelper.java | 10 +++++----- .../protocol/data/game/RegistryEntry.java | 3 ++- .../protocol/data/game/ResourceLocation.java | 20 ------------------- .../data/game/chat/BuiltinChatType.java | 12 +++++------ .../data/game/command/CommandNode.java | 4 ++-- .../data/game/command/SuggestionType.java | 12 +++++------ .../properties/ResourceProperties.java | 4 ++-- .../data/game/entity/metadata/GlobalPos.java | 8 ++++---- .../component/AdventureModePredicate.java | 4 ++-- .../data/game/item/component/ArmorTrim.java | 4 ++-- .../item/component/BannerPatternLayer.java | 4 ++-- .../item/component/DataComponentType.java | 4 ++-- .../game/item/component/ItemCodecHelper.java | 8 ++++---- .../data/game/item/component/ToolData.java | 4 ++-- .../protocol/data/game/recipe/Recipe.java | 4 ++-- .../ClientboundCookieRequestPacket.java | 4 ++-- .../ClientboundStoreCookiePacket.java | 4 ++-- .../ClientboundUpdateTagsPacket.java | 14 ++++++------- .../ServerboundCookieResponsePacket.java | 4 ++-- .../ClientboundRegistryDataPacket.java | 4 ++-- .../ClientboundCommandsPacket.java | 4 ++-- .../ClientboundStopSoundPacket.java | 4 ++-- .../ClientboundUpdateRecipesPacket.java | 4 ++-- .../clientbound/ServerDeclareRecipesTest.java | 1 - 25 files changed, 67 insertions(+), 87 deletions(-) delete mode 100644 protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/ResourceLocation.java diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/ServerListener.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/ServerListener.java index 038f95950..058c3a216 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/ServerListener.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/ServerListener.java @@ -4,6 +4,7 @@ import com.github.steveice10.mc.auth.exception.request.RequestException; import com.github.steveice10.mc.auth.service.SessionService; import lombok.RequiredArgsConstructor; +import net.kyori.adventure.key.Key; import net.kyori.adventure.text.Component; import org.cloudburstmc.nbt.NbtMap; import org.cloudburstmc.nbt.NbtType; @@ -14,7 +15,6 @@ import org.geysermc.mcprotocollib.network.packet.Packet; import org.geysermc.mcprotocollib.protocol.data.ProtocolState; import org.geysermc.mcprotocollib.protocol.data.game.RegistryEntry; -import org.geysermc.mcprotocollib.protocol.data.game.ResourceLocation; import org.geysermc.mcprotocollib.protocol.data.status.PlayerInfo; import org.geysermc.mcprotocollib.protocol.data.status.ServerStatusInfo; import org.geysermc.mcprotocollib.protocol.data.status.VersionInfo; @@ -138,11 +138,11 @@ public void packetReceived(Session session, Packet packet) { // Credit ViaVersion: https://github.com/ViaVersion/ViaVersion/blob/dev/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/EntityPacketRewriter1_20_5.java for (Map.Entry entry : networkCodec.entrySet()) { NbtMap entryTag = (NbtMap) entry.getValue(); - ResourceLocation typeTag = ResourceLocation.fromString(entryTag.getString("type")); + Key typeTag = Key.key(entryTag.getString("type")); List valueTag = entryTag.getList("value", NbtType.COMPOUND); List entries = new ArrayList<>(); for (NbtMap compoundTag : valueTag) { - ResourceLocation nameTag = ResourceLocation.fromString(compoundTag.getString("name")); + Key nameTag = Key.key(compoundTag.getString("name")); int id = compoundTag.getInt("id"); entries.add(id, new RegistryEntry(nameTag, compoundTag.getCompound("element"))); } diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/codec/MinecraftCodecHelper.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/codec/MinecraftCodecHelper.java index 3687896bf..55726b4ac 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/codec/MinecraftCodecHelper.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/codec/MinecraftCodecHelper.java @@ -7,6 +7,7 @@ import io.netty.buffer.ByteBufOutputStream; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import lombok.RequiredArgsConstructor; +import net.kyori.adventure.key.Key; import net.kyori.adventure.text.Component; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; @@ -20,7 +21,6 @@ import org.geysermc.mcprotocollib.network.codec.BasePacketCodecHelper; import org.geysermc.mcprotocollib.protocol.data.DefaultComponentSerializer; import org.geysermc.mcprotocollib.protocol.data.game.Holder; -import org.geysermc.mcprotocollib.protocol.data.game.ResourceLocation; import org.geysermc.mcprotocollib.protocol.data.game.chat.numbers.BlankFormat; import org.geysermc.mcprotocollib.protocol.data.game.chat.numbers.FixedFormat; import org.geysermc.mcprotocollib.protocol.data.game.chat.numbers.NumberFormat; @@ -144,11 +144,11 @@ public void writeHolder(ByteBuf buf, Holder holder, BiConsumer type) { } public GlobalPos readGlobalPos(ByteBuf buf) { - ResourceLocation dimension = ResourceLocation.fromString(this.readString(buf)); + Key dimension = readResourceLocation(buf); Vector3i pos = this.readPosition(buf); return new GlobalPos(dimension, pos); } diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/RegistryEntry.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/RegistryEntry.java index 9f9b2b507..b33f51de4 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/RegistryEntry.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/RegistryEntry.java @@ -2,12 +2,13 @@ import lombok.AllArgsConstructor; import lombok.Data; +import net.kyori.adventure.key.Key; import org.cloudburstmc.nbt.NbtMap; import org.jetbrains.annotations.Nullable; @Data @AllArgsConstructor public class RegistryEntry { - private final ResourceLocation id; + private final Key id; private final @Nullable NbtMap data; } diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/ResourceLocation.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/ResourceLocation.java deleted file mode 100644 index 2b153ef9b..000000000 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/ResourceLocation.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.geysermc.mcprotocollib.protocol.data.game; - -public record ResourceLocation(String namespace, String path) { - public static ResourceLocation fromString(String identifier) { - int index = identifier.indexOf(':'); - if (index == -1) { - return new ResourceLocation("minecraft", identifier); - } else { - return new ResourceLocation( - identifier.substring(0, index), - identifier.substring(index + 1) - ); - } - } - - @Override - public String toString() { - return namespace + ":" + path; - } -} diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/chat/BuiltinChatType.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/chat/BuiltinChatType.java index 14600cc68..ed6d08e81 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/chat/BuiltinChatType.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/chat/BuiltinChatType.java @@ -1,6 +1,6 @@ package org.geysermc.mcprotocollib.protocol.data.game.chat; -import org.geysermc.mcprotocollib.protocol.data.game.ResourceLocation; +import net.kyori.adventure.key.Key; import java.util.HashMap; import java.util.Locale; @@ -15,19 +15,19 @@ public enum BuiltinChatType { TEAM_MSG_COMMAND_OUTGOING, EMOTE_COMMAND; - private final ResourceLocation resourceLocation; + private final Key resourceLocation; BuiltinChatType() { - this.resourceLocation = ResourceLocation.fromString(name().toLowerCase(Locale.ROOT)); + this.resourceLocation = Key.key(name().toLowerCase(Locale.ROOT)); } - public ResourceLocation getResourceLocation() { + public Key getResourceLocation() { return resourceLocation; } - private static final Map VALUES = new HashMap<>(); + private static final Map VALUES = new HashMap<>(); - public static BuiltinChatType from(ResourceLocation resourceLocation) { + public static BuiltinChatType from(Key resourceLocation) { return VALUES.get(resourceLocation); } diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/command/CommandNode.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/command/CommandNode.java index da66733a8..df10bab17 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/command/CommandNode.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/command/CommandNode.java @@ -3,7 +3,7 @@ import lombok.AllArgsConstructor; import lombok.Data; import lombok.NonNull; -import org.geysermc.mcprotocollib.protocol.data.game.ResourceLocation; +import net.kyori.adventure.key.Key; import org.geysermc.mcprotocollib.protocol.data.game.command.properties.CommandProperties; import java.util.OptionalInt; @@ -50,5 +50,5 @@ public class CommandNode { * Suggestions type, if present. * See {@link SuggestionType} for vanilla defaults. */ - private final ResourceLocation suggestionType; + private final Key suggestionType; } diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/command/SuggestionType.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/command/SuggestionType.java index ba3e3c4f9..11674f840 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/command/SuggestionType.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/command/SuggestionType.java @@ -1,7 +1,7 @@ package org.geysermc.mcprotocollib.protocol.data.game.command; +import net.kyori.adventure.key.Key; import org.checkerframework.checker.nullness.qual.NonNull; -import org.geysermc.mcprotocollib.protocol.data.game.ResourceLocation; import java.util.HashMap; import java.util.Locale; @@ -13,20 +13,20 @@ public enum SuggestionType { AVAILABLE_SOUNDS, SUMMONABLE_ENTITIES; - private final ResourceLocation resourceLocation; + private final Key resourceLocation; SuggestionType() { - this.resourceLocation = ResourceLocation.fromString(name().toLowerCase(Locale.ROOT)); + this.resourceLocation = Key.key(name().toLowerCase(Locale.ROOT)); } - public ResourceLocation getResourceLocation() { + public Key getResourceLocation() { return resourceLocation; } - private static final Map VALUES = new HashMap<>(); + private static final Map VALUES = new HashMap<>(); @NonNull - public static SuggestionType from(ResourceLocation resourceLocation) { + public static SuggestionType from(Key resourceLocation) { // Vanilla behavior as of 1.19.3 // 1.16.5 still has AVAILABLE_BIOMES and vanilla doesn't care return VALUES.getOrDefault(resourceLocation, ASK_SERVER); diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/command/properties/ResourceProperties.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/command/properties/ResourceProperties.java index 35918af01..f38ff8239 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/command/properties/ResourceProperties.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/command/properties/ResourceProperties.java @@ -1,11 +1,11 @@ package org.geysermc.mcprotocollib.protocol.data.game.command.properties; import lombok.Data; -import org.geysermc.mcprotocollib.protocol.data.game.ResourceLocation; +import net.kyori.adventure.key.Key; @Data public class ResourceProperties implements CommandProperties { - private final ResourceLocation registryKey; + private final Key registryKey; public ResourceProperties(String registryKey) { this.registryKey = ResourceLocation.fromString(registryKey); diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/entity/metadata/GlobalPos.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/entity/metadata/GlobalPos.java index 99747abc6..efae5e49a 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/entity/metadata/GlobalPos.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/entity/metadata/GlobalPos.java @@ -1,18 +1,18 @@ package org.geysermc.mcprotocollib.protocol.data.game.entity.metadata; +import net.kyori.adventure.key.Key; import org.cloudburstmc.math.vector.Vector3i; -import org.geysermc.mcprotocollib.protocol.data.game.ResourceLocation; public class GlobalPos { - private final ResourceLocation dimension; + private final Key dimension; private final Vector3i position; - public GlobalPos(ResourceLocation dimension, Vector3i position) { + public GlobalPos(Key dimension, Vector3i position) { this.dimension = dimension; this.position = position; } - public ResourceLocation getDimension() { + public Key getDimension() { return dimension; } diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/AdventureModePredicate.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/AdventureModePredicate.java index db9482bbc..5cb520d1c 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/AdventureModePredicate.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/AdventureModePredicate.java @@ -2,8 +2,8 @@ import lombok.AllArgsConstructor; import lombok.Data; +import net.kyori.adventure.key.Key; import org.cloudburstmc.nbt.NbtMap; -import org.geysermc.mcprotocollib.protocol.data.game.ResourceLocation; import org.jetbrains.annotations.Nullable; import java.util.List; @@ -17,7 +17,7 @@ public class AdventureModePredicate { @Data @AllArgsConstructor public static class BlockPredicate { - private final @Nullable ResourceLocation location; + private final @Nullable Key location; private final int @Nullable [] holders; private final @Nullable List properties; private final @Nullable NbtMap nbt; diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/ArmorTrim.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/ArmorTrim.java index d2a5d7222..d698ca26a 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/ArmorTrim.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/ArmorTrim.java @@ -1,15 +1,15 @@ package org.geysermc.mcprotocollib.protocol.data.game.item.component; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import net.kyori.adventure.key.Key; import net.kyori.adventure.text.Component; import org.geysermc.mcprotocollib.protocol.data.game.Holder; -import org.geysermc.mcprotocollib.protocol.data.game.ResourceLocation; public record ArmorTrim(Holder material, Holder pattern, boolean showInTooltip) { public record TrimMaterial(String assetName, int ingredientId, float itemModelIndex, Int2ObjectMap overrideArmorMaterials, Component description) { } - public record TrimPattern(ResourceLocation assetId, int templateItemId, Component description, boolean decal) { + public record TrimPattern(Key assetId, int templateItemId, Component description, boolean decal) { } } diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/BannerPatternLayer.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/BannerPatternLayer.java index 0797aec9e..091a7fe7f 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/BannerPatternLayer.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/BannerPatternLayer.java @@ -2,8 +2,8 @@ import lombok.AllArgsConstructor; import lombok.Data; +import net.kyori.adventure.key.Key; import org.geysermc.mcprotocollib.protocol.data.game.Holder; -import org.geysermc.mcprotocollib.protocol.data.game.ResourceLocation; @Data @AllArgsConstructor @@ -14,7 +14,7 @@ public class BannerPatternLayer { @Data @AllArgsConstructor public static class BannerPattern { - private final ResourceLocation assetId; + private final Key assetId; private final String translationKey; } } diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/DataComponentType.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/DataComponentType.java index c90e5acd7..28c929512 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/DataComponentType.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/DataComponentType.java @@ -3,12 +3,12 @@ import com.github.steveice10.mc.auth.data.GameProfile; import io.netty.buffer.ByteBuf; import lombok.Getter; +import net.kyori.adventure.key.Key; import net.kyori.adventure.text.Component; import org.cloudburstmc.nbt.NbtList; import org.cloudburstmc.nbt.NbtMap; import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper; import org.geysermc.mcprotocollib.protocol.data.game.Holder; -import org.geysermc.mcprotocollib.protocol.data.game.ResourceLocation; import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack; import org.geysermc.mcprotocollib.protocol.data.game.item.component.type.BooleanDataComponent; import org.geysermc.mcprotocollib.protocol.data.game.item.component.type.IntDataComponent; @@ -68,7 +68,7 @@ public class DataComponentType { public static final DataComponentType FIREWORK_EXPLOSION = new DataComponentType<>(ItemCodecHelper::readFireworkExplosion, ItemCodecHelper::writeFireworkExplosion, ObjectDataComponent::new); public static final DataComponentType FIREWORKS = new DataComponentType<>(ItemCodecHelper::readFireworks, ItemCodecHelper::writeFireworks, ObjectDataComponent::new); public static final DataComponentType PROFILE = new DataComponentType<>(ItemCodecHelper::readResolvableProfile, ItemCodecHelper::writeResolvableProfile, ObjectDataComponent::new); - public static final DataComponentType NOTE_BLOCK_SOUND = new DataComponentType<>(ItemCodecHelper::readResourceLocation, ItemCodecHelper::writeResourceLocation, ObjectDataComponent::new); + public static final DataComponentType NOTE_BLOCK_SOUND = new DataComponentType<>(ItemCodecHelper::readResourceLocation, ItemCodecHelper::writeResourceLocation, ObjectDataComponent::new); public static final DataComponentType> BANNER_PATTERNS = new DataComponentType<>(listReader(ItemCodecHelper::readBannerPatternLayer), listWriter(ItemCodecHelper::writeBannerPatternLayer), ObjectDataComponent::new); public static final IntComponentType BASE_COLOR = new IntComponentType(ItemCodecHelper::readVarInt, ItemCodecHelper::writeVarInt, IntDataComponent::new); public static final DataComponentType> POT_DECORATIONS = new DataComponentType<>(listReader(ItemCodecHelper::readVarInt), listWriter(ItemCodecHelper::writeVarInt), ObjectDataComponent::new); diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/ItemCodecHelper.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/ItemCodecHelper.java index 8fd78be58..ea757fae0 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/ItemCodecHelper.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/ItemCodecHelper.java @@ -5,12 +5,12 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMaps; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; +import net.kyori.adventure.key.Key; import net.kyori.adventure.text.Component; import org.cloudburstmc.nbt.NbtList; import org.cloudburstmc.nbt.NbtType; import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper; import org.geysermc.mcprotocollib.protocol.data.game.Holder; -import org.geysermc.mcprotocollib.protocol.data.game.ResourceLocation; import org.geysermc.mcprotocollib.protocol.data.game.entity.Effect; import org.geysermc.mcprotocollib.protocol.data.game.entity.attribute.ModifierOperation; import org.geysermc.mcprotocollib.protocol.data.game.level.sound.BuiltinSound; @@ -93,7 +93,7 @@ public void writeAdventureModePredicate(ByteBuf buf, AdventureModePredicate adve } public AdventureModePredicate.BlockPredicate readBlockPredicate(ByteBuf buf) { - ResourceLocation location = null; + Key location = null; int[] holders = null; List propertyMatchers = null; @@ -165,7 +165,7 @@ public ToolData readToolData(ByteBuf buf) { List rules = new ArrayList<>(); int ruleCount = this.readVarInt(buf); for (int i = 0; i < ruleCount; i++) { - ResourceLocation location = null; + Key location = null; int[] holders = null; int length = this.readVarInt(buf) - 1; @@ -432,7 +432,7 @@ public void writeTrimMaterial(ByteBuf buf, ArmorTrim.TrimMaterial material) { } public ArmorTrim.TrimPattern readTrimPattern(ByteBuf buf) { - ResourceLocation assetId = this.readResourceLocation(buf); + Key assetId = this.readResourceLocation(buf); int templateItemId = this.readVarInt(buf); Component description = this.readComponent(buf); boolean decal = buf.readBoolean(); diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/ToolData.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/ToolData.java index 143184474..477689315 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/ToolData.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/ToolData.java @@ -2,7 +2,7 @@ import lombok.AllArgsConstructor; import lombok.Data; -import org.geysermc.mcprotocollib.protocol.data.game.ResourceLocation; +import net.kyori.adventure.key.Key; import org.jetbrains.annotations.Nullable; import java.util.List; @@ -17,7 +17,7 @@ public class ToolData { @Data @AllArgsConstructor public static class Rule { - private final @Nullable ResourceLocation location; + private final @Nullable Key location; private final int @Nullable [] holders; private final @Nullable Float speed; private final @Nullable Boolean correctForDrops; diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/recipe/Recipe.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/recipe/Recipe.java index de304565d..55e43a6f4 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/recipe/Recipe.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/recipe/Recipe.java @@ -3,13 +3,13 @@ import lombok.AllArgsConstructor; import lombok.Data; import lombok.NonNull; -import org.geysermc.mcprotocollib.protocol.data.game.ResourceLocation; +import net.kyori.adventure.key.Key; import org.geysermc.mcprotocollib.protocol.data.game.recipe.data.RecipeData; @Data @AllArgsConstructor public class Recipe { private final @NonNull RecipeType type; - private final @NonNull ResourceLocation identifier; + private final @NonNull Key identifier; private final RecipeData data; } diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/common/clientbound/ClientboundCookieRequestPacket.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/common/clientbound/ClientboundCookieRequestPacket.java index 8f8f156d5..df2ed4233 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/common/clientbound/ClientboundCookieRequestPacket.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/common/clientbound/ClientboundCookieRequestPacket.java @@ -4,15 +4,15 @@ import lombok.AllArgsConstructor; import lombok.Data; import lombok.With; +import net.kyori.adventure.key.Key; import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper; import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket; -import org.geysermc.mcprotocollib.protocol.data.game.ResourceLocation; @Data @With @AllArgsConstructor public class ClientboundCookieRequestPacket implements MinecraftPacket { - private final ResourceLocation key; + private final Key key; public ClientboundCookieRequestPacket(ByteBuf in, MinecraftCodecHelper helper) { this.key = helper.readResourceLocation(in); diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/common/clientbound/ClientboundStoreCookiePacket.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/common/clientbound/ClientboundStoreCookiePacket.java index 20b7f1765..a7a9753cd 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/common/clientbound/ClientboundStoreCookiePacket.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/common/clientbound/ClientboundStoreCookiePacket.java @@ -4,15 +4,15 @@ import lombok.AllArgsConstructor; import lombok.Data; import lombok.With; +import net.kyori.adventure.key.Key; import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper; import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket; -import org.geysermc.mcprotocollib.protocol.data.game.ResourceLocation; @Data @With @AllArgsConstructor public class ClientboundStoreCookiePacket implements MinecraftPacket { - private final ResourceLocation key; + private final Key key; private final byte[] payload; public ClientboundStoreCookiePacket(ByteBuf in, MinecraftCodecHelper helper) { diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/common/clientbound/ClientboundUpdateTagsPacket.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/common/clientbound/ClientboundUpdateTagsPacket.java index 72d5ed875..0bfff1fe2 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/common/clientbound/ClientboundUpdateTagsPacket.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/common/clientbound/ClientboundUpdateTagsPacket.java @@ -5,9 +5,9 @@ import lombok.Data; import lombok.NonNull; import lombok.With; +import net.kyori.adventure.key.Key; import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper; import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket; -import org.geysermc.mcprotocollib.protocol.data.game.ResourceLocation; import java.util.HashMap; import java.util.Map; @@ -16,16 +16,16 @@ @With @AllArgsConstructor public class ClientboundUpdateTagsPacket implements MinecraftPacket { - private final @NonNull Map> tags = new HashMap<>(); + private final @NonNull Map> tags = new HashMap<>(); public ClientboundUpdateTagsPacket(ByteBuf in, MinecraftCodecHelper helper) { int totalTagCount = helper.readVarInt(in); for (int i = 0; i < totalTagCount; i++) { - Map tag = new HashMap<>(); - ResourceLocation tagName = helper.readResourceLocation(in); + Map tag = new HashMap<>(); + Key tagName = helper.readResourceLocation(in); int tagsCount = helper.readVarInt(in); for (int j = 0; j < tagsCount; j++) { - ResourceLocation name = helper.readResourceLocation(in); + Key name = helper.readResourceLocation(in); int entriesCount = helper.readVarInt(in); int[] entries = new int[entriesCount]; for (int index = 0; index < entriesCount; index++) { @@ -41,10 +41,10 @@ public ClientboundUpdateTagsPacket(ByteBuf in, MinecraftCodecHelper helper) { @Override public void serialize(ByteBuf out, MinecraftCodecHelper helper) { helper.writeVarInt(out, tags.size()); - for (Map.Entry> tagSet : tags.entrySet()) { + for (Map.Entry> tagSet : tags.entrySet()) { helper.writeResourceLocation(out, tagSet.getKey()); helper.writeVarInt(out, tagSet.getValue().size()); - for (Map.Entry tag : tagSet.getValue().entrySet()) { + for (Map.Entry tag : tagSet.getValue().entrySet()) { helper.writeResourceLocation(out, tag.getKey()); helper.writeVarInt(out, tag.getValue().length); for (int id : tag.getValue()) { diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/common/clientbound/ServerboundCookieResponsePacket.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/common/clientbound/ServerboundCookieResponsePacket.java index 14515eead..66afbff02 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/common/clientbound/ServerboundCookieResponsePacket.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/common/clientbound/ServerboundCookieResponsePacket.java @@ -4,16 +4,16 @@ import lombok.AllArgsConstructor; import lombok.Data; import lombok.With; +import net.kyori.adventure.key.Key; import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper; import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket; -import org.geysermc.mcprotocollib.protocol.data.game.ResourceLocation; import org.jetbrains.annotations.Nullable; @Data @With @AllArgsConstructor public class ServerboundCookieResponsePacket implements MinecraftPacket { - private final ResourceLocation key; + private final Key key; private final byte @Nullable [] payload; public ServerboundCookieResponsePacket(ByteBuf in, MinecraftCodecHelper helper) { diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/configuration/clientbound/ClientboundRegistryDataPacket.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/configuration/clientbound/ClientboundRegistryDataPacket.java index 21900bafa..37e95e534 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/configuration/clientbound/ClientboundRegistryDataPacket.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/configuration/clientbound/ClientboundRegistryDataPacket.java @@ -4,10 +4,10 @@ import lombok.AllArgsConstructor; import lombok.Data; import lombok.With; +import net.kyori.adventure.key.Key; import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper; import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket; import org.geysermc.mcprotocollib.protocol.data.game.RegistryEntry; -import org.geysermc.mcprotocollib.protocol.data.game.ResourceLocation; import java.util.ArrayList; import java.util.List; @@ -16,7 +16,7 @@ @With @AllArgsConstructor public class ClientboundRegistryDataPacket implements MinecraftPacket { - private final ResourceLocation registry; + private final Key registry; private final List entries; public ClientboundRegistryDataPacket(ByteBuf in, MinecraftCodecHelper helper) { diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/ingame/clientbound/ClientboundCommandsPacket.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/ingame/clientbound/ClientboundCommandsPacket.java index 6e00ec7bf..494c96d3e 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/ingame/clientbound/ClientboundCommandsPacket.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/ingame/clientbound/ClientboundCommandsPacket.java @@ -5,9 +5,9 @@ import lombok.Data; import lombok.NonNull; import lombok.With; +import net.kyori.adventure.key.Key; import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper; import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket; -import org.geysermc.mcprotocollib.protocol.data.game.ResourceLocation; import org.geysermc.mcprotocollib.protocol.data.game.command.CommandNode; import org.geysermc.mcprotocollib.protocol.data.game.command.CommandParser; import org.geysermc.mcprotocollib.protocol.data.game.command.CommandType; @@ -68,7 +68,7 @@ public ClientboundCommandsPacket(ByteBuf in, MinecraftCodecHelper helper) { CommandParser parser = null; CommandProperties properties = null; - ResourceLocation suggestionType = null; + Key suggestionType = null; if (type == CommandType.ARGUMENT) { parser = CommandParser.from(helper.readVarInt(in)); switch (parser) { diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/ingame/clientbound/ClientboundStopSoundPacket.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/ingame/clientbound/ClientboundStopSoundPacket.java index b82771637..cc20b54be 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/ingame/clientbound/ClientboundStopSoundPacket.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/ingame/clientbound/ClientboundStopSoundPacket.java @@ -4,10 +4,10 @@ import lombok.AllArgsConstructor; import lombok.Data; import lombok.With; +import net.kyori.adventure.key.Key; import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper; import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket; -import org.geysermc.mcprotocollib.protocol.data.game.ResourceLocation; import org.geysermc.mcprotocollib.protocol.data.game.level.sound.SoundCategory; @Data @@ -18,7 +18,7 @@ public class ClientboundStopSoundPacket implements MinecraftPacket { private static final int FLAG_SOUND = 0x02; private final @Nullable SoundCategory category; - private final @Nullable ResourceLocation sound; + private final @Nullable Key sound; public ClientboundStopSoundPacket(ByteBuf in, MinecraftCodecHelper helper) { int flags = in.readByte(); diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/ingame/clientbound/ClientboundUpdateRecipesPacket.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/ingame/clientbound/ClientboundUpdateRecipesPacket.java index f863eacd4..7c72d58b6 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/ingame/clientbound/ClientboundUpdateRecipesPacket.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/ingame/clientbound/ClientboundUpdateRecipesPacket.java @@ -5,9 +5,9 @@ import lombok.Data; import lombok.NonNull; import lombok.With; +import net.kyori.adventure.key.Key; import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper; import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket; -import org.geysermc.mcprotocollib.protocol.data.game.ResourceLocation; import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack; import org.geysermc.mcprotocollib.protocol.data.game.recipe.CraftingBookCategory; import org.geysermc.mcprotocollib.protocol.data.game.recipe.Ingredient; @@ -31,7 +31,7 @@ public class ClientboundUpdateRecipesPacket implements MinecraftPacket { public ClientboundUpdateRecipesPacket(ByteBuf in, MinecraftCodecHelper helper) { this.recipes = new Recipe[helper.readVarInt(in)]; for (int i = 0; i < this.recipes.length; i++) { - ResourceLocation identifier = helper.readResourceLocation(in); + Key identifier = helper.readResourceLocation(in); RecipeType type = RecipeType.from(helper.readVarInt(in)); RecipeData data; switch (type) { diff --git a/protocol/src/test/java/org/geysermc/mcprotocollib/protocol/packet/ingame/clientbound/ServerDeclareRecipesTest.java b/protocol/src/test/java/org/geysermc/mcprotocollib/protocol/packet/ingame/clientbound/ServerDeclareRecipesTest.java index 4d3cf1ae7..17e6956d5 100644 --- a/protocol/src/test/java/org/geysermc/mcprotocollib/protocol/packet/ingame/clientbound/ServerDeclareRecipesTest.java +++ b/protocol/src/test/java/org/geysermc/mcprotocollib/protocol/packet/ingame/clientbound/ServerDeclareRecipesTest.java @@ -1,6 +1,5 @@ package org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound; -import org.geysermc.mcprotocollib.protocol.data.game.ResourceLocation; import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack; import org.geysermc.mcprotocollib.protocol.data.game.recipe.CraftingBookCategory; import org.geysermc.mcprotocollib.protocol.data.game.recipe.Ingredient; From 10d5595685b3d0d2cd7b1c148bb453da306ba7a8 Mon Sep 17 00:00:00 2001 From: AlexProgrammerDE <40795980+AlexProgrammerDE@users.noreply.github.com> Date: Tue, 14 May 2024 18:41:04 +0200 Subject: [PATCH 03/11] Fix missing keys --- .../game/command/properties/ResourceProperties.java | 2 +- .../ingame/clientbound/ServerDeclareRecipesTest.java | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/command/properties/ResourceProperties.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/command/properties/ResourceProperties.java index f38ff8239..ff363c248 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/command/properties/ResourceProperties.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/command/properties/ResourceProperties.java @@ -8,6 +8,6 @@ public class ResourceProperties implements CommandProperties { private final Key registryKey; public ResourceProperties(String registryKey) { - this.registryKey = ResourceLocation.fromString(registryKey); + this.registryKey = Key.key(registryKey); } } diff --git a/protocol/src/test/java/org/geysermc/mcprotocollib/protocol/packet/ingame/clientbound/ServerDeclareRecipesTest.java b/protocol/src/test/java/org/geysermc/mcprotocollib/protocol/packet/ingame/clientbound/ServerDeclareRecipesTest.java index 17e6956d5..d79ad6c43 100644 --- a/protocol/src/test/java/org/geysermc/mcprotocollib/protocol/packet/ingame/clientbound/ServerDeclareRecipesTest.java +++ b/protocol/src/test/java/org/geysermc/mcprotocollib/protocol/packet/ingame/clientbound/ServerDeclareRecipesTest.java @@ -1,5 +1,6 @@ package org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound; +import net.kyori.adventure.key.Key; import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack; import org.geysermc.mcprotocollib.protocol.data.game.recipe.CraftingBookCategory; import org.geysermc.mcprotocollib.protocol.data.game.recipe.Ingredient; @@ -21,7 +22,7 @@ public void setup() { new Recipe[]{ new Recipe( RecipeType.CRAFTING_SHAPELESS, - ResourceLocation.fromString("minecraft:Recipe1"), + Key.key("minecraft:recipe1"), new ShapelessRecipeData( "Group1", CraftingBookCategory.MISC, @@ -35,7 +36,7 @@ public void setup() { ), new Recipe( RecipeType.CRAFTING_SHAPED, - ResourceLocation.fromString("minecraft:Recipe2"), + Key.key("minecraft:recipe2"), new ShapedRecipeData( 2, 3, @@ -67,7 +68,7 @@ public void setup() { ), new Recipe( RecipeType.SMELTING, - ResourceLocation.fromString("minecraft:Recipe3"), + Key.key("minecraft:recipe3"), new CookedRecipeData( "Group3", CraftingBookCategory.EQUIPMENT, @@ -81,7 +82,7 @@ public void setup() { ), new Recipe( RecipeType.STONECUTTING, - ResourceLocation.fromString("minecraft:Recipe4"), + Key.key("minecraft:recipe4"), new StoneCuttingRecipeData( "Group4", new Ingredient(new ItemStack[]{ @@ -93,7 +94,7 @@ public void setup() { ), new Recipe( RecipeType.SMITHING_TRANSFORM, - ResourceLocation.fromString("minecraft:Recipe5"), + Key.key("minecraft:recipe5"), new SmithingTransformRecipeData( new Ingredient(new ItemStack[]{ new ItemStack(10) From 98d85fe075ed5e2eb92f65239acc6c1dd7e657b5 Mon Sep 17 00:00:00 2001 From: AlexProgrammerDE <40795980+AlexProgrammerDE@users.noreply.github.com> Date: Tue, 14 May 2024 18:48:21 +0200 Subject: [PATCH 04/11] Fix packets with incorrect resource location types --- .../example/MinecraftProtocolTest.java | 5 +- .../protocol/codec/MinecraftCodecHelper.java | 4 +- .../game/entity/attribute/AttributeType.java | 55 ++++++++++--------- .../game/entity/player/PlayerSpawnInfo.java | 3 +- .../clientbound/ClientboundLoginPacket.java | 11 ++-- .../protocol/MinecraftProtocolTest.java | 3 +- 6 files changed, 43 insertions(+), 38 deletions(-) diff --git a/example/src/main/java/org/geysermc/mcprotocollib/protocol/example/MinecraftProtocolTest.java b/example/src/main/java/org/geysermc/mcprotocollib/protocol/example/MinecraftProtocolTest.java index db88bcae7..d1be16f6d 100644 --- a/example/src/main/java/org/geysermc/mcprotocollib/protocol/example/MinecraftProtocolTest.java +++ b/example/src/main/java/org/geysermc/mcprotocollib/protocol/example/MinecraftProtocolTest.java @@ -5,6 +5,7 @@ import com.github.steveice10.mc.auth.service.AuthenticationService; import com.github.steveice10.mc.auth.service.MojangAuthenticationService; import com.github.steveice10.mc.auth.service.SessionService; +import net.kyori.adventure.key.Key; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.TextDecoration; @@ -73,7 +74,7 @@ public static void main(String[] args) { session.send(new ClientboundLoginPacket( 0, false, - new String[]{"minecraft:world"}, + new Key[]{Key.key("minecraft:world")}, 0, 16, 16, @@ -82,7 +83,7 @@ public static void main(String[] args) { false, new PlayerSpawnInfo( 0, - "minecraft:world", + Key.key("minecraft:world"), 100, GameMode.SURVIVAL, GameMode.SURVIVAL, diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/codec/MinecraftCodecHelper.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/codec/MinecraftCodecHelper.java index 55726b4ac..5b08cb4f6 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/codec/MinecraftCodecHelper.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/codec/MinecraftCodecHelper.java @@ -558,7 +558,7 @@ public void writeGlobalPos(ByteBuf buf, GlobalPos pos) { public PlayerSpawnInfo readPlayerSpawnInfo(ByteBuf buf) { int dimension = this.readVarInt(buf); - String worldName = this.readString(buf); + Key worldName = this.readResourceLocation(buf); long hashedSeed = buf.readLong(); GameMode gameMode = GameMode.byId(buf.readByte()); GameMode previousGamemode = GameMode.byNullableId(buf.readByte()); @@ -571,7 +571,7 @@ public PlayerSpawnInfo readPlayerSpawnInfo(ByteBuf buf) { public void writePlayerSpawnInfo(ByteBuf buf, PlayerSpawnInfo info) { this.writeVarInt(buf, info.getDimension()); - this.writeString(buf, info.getWorldName()); + this.writeResourceLocation(buf, info.getWorldName()); buf.writeLong(info.getHashedSeed()); buf.writeByte(info.getGameMode().ordinal()); buf.writeByte(GameMode.toNullableId(info.getPreviousGamemode())); diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/entity/attribute/AttributeType.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/entity/attribute/AttributeType.java index d735809d7..77e62c261 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/entity/attribute/AttributeType.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/entity/attribute/AttributeType.java @@ -4,10 +4,11 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import lombok.AllArgsConstructor; import lombok.Getter; +import net.kyori.adventure.key.Key; public interface AttributeType { - String getIdentifier(); + Key getIdentifier(); int getId(); @@ -18,13 +19,13 @@ public interface AttributeType { // @Getter // @EqualsAndHashCode // class Custom implements AttributeType { -// private final String identifier; +// private final Key identifier; // -// public Custom(String identifier) { +// public Custom(Key identifier) { // this.identifier = identifier; // } // -// public String getIdentifier() { +// public Key getIdentifier() { // return identifier; // } // } @@ -32,30 +33,30 @@ public interface AttributeType { @Getter @AllArgsConstructor enum Builtin implements AttributeType { - GENERIC_ARMOR("minecraft:generic.armor", 0, 0, 30), - GENERIC_ARMOR_TOUGHNESS("minecraft:generic.armor_toughness", 0, 0, 20), - GENERIC_ATTACK_DAMAGE("minecraft:generic.attack_damage", 2, 0, 2048), - GENERIC_ATTACK_KNOCKBACK("minecraft:generic.attack_knockback", 0, 0, 5), - GENERIC_ATTACK_SPEED("minecraft:generic.attack_speed", 4, 0, 1024), - PLAYER_BLOCK_BREAK_SPEED("minecraft:player.block_break_speed", 1, 0, 1024), - PLAYER_BLOCK_INTERACTION_RANGE("minecraft:player.block_interaction_range", 4.5, 0, 64), - PLAYER_ENTITY_INTERACTION_RANGE("minecraft:player.entity_interaction_range", 3, 0, 64), - GENERIC_FALL_DAMAGE_MULTIPLIER("minecraft:generic.fall_damage_multiplier", 1, 0, 100), - GENERIC_FLYING_SPEED("minecraft:generic.flying_speed", 0.4F, 0, 1024), - GENERIC_FOLLOW_RANGE("minecraft:generic.follow_range", 32, 0, 2048), - GENERIC_GRAVITY("minecraft:generic.gravity", 0.08, -1, 1), - GENERIC_JUMP_STRENGTH("minecraft:generic.jump_strength", 0.42, 0, 32), - GENERIC_KNOCKBACK_RESISTANCE("minecraft:generic.knockback_resistance", 0, 0, 1), - GENERIC_LUCK("minecraft:generic.luck", 0, -1024, 1024), - GENERIC_MAX_ABSORPTION("minecraft:generic.max_absorption", 0, 0, 2048), - GENERIC_MAX_HEALTH("minecraft:generic.max_health", 20, 1, 1024), - GENERIC_MOVEMENT_SPEED("minecraft:generic.movement_speed", 0.7F, 0, 1024), - GENERIC_SAFE_FALL_DISTANCE("minecraft:generic.safe_fall_distance", 3, -1024, 1024), - GENERIC_SCALE("minecraft:generic.scale", 1, 0.0625, 16), - ZOMBIE_SPAWN_REINFORCEMENTS("minecraft:zombie.spawn_reinforcements", 0, 0, 1), - GENERIC_STEP_HEIGHT("minecraft:generic.step_height", 0.6, 0, 10); + GENERIC_ARMOR(Key.key("minecraft:generic.armor"), 0, 0, 30), + GENERIC_ARMOR_TOUGHNESS(Key.key("minecraft:generic.armor_toughness"), 0, 0, 20), + GENERIC_ATTACK_DAMAGE(Key.key("minecraft:generic.attack_damage"), 2, 0, 2048), + GENERIC_ATTACK_KNOCKBACK(Key.key("minecraft:generic.attack_knockback"), 0, 0, 5), + GENERIC_ATTACK_SPEED(Key.key("minecraft:generic.attack_speed"), 4, 0, 1024), + PLAYER_BLOCK_BREAK_SPEED(Key.key("minecraft:player.block_break_speed"), 1, 0, 1024), + PLAYER_BLOCK_INTERACTION_RANGE(Key.key("minecraft:player.block_interaction_range"), 4.5, 0, 64), + PLAYER_ENTITY_INTERACTION_RANGE(Key.key("minecraft:player.entity_interaction_range"), 3, 0, 64), + GENERIC_FALL_DAMAGE_MULTIPLIER(Key.key("minecraft:generic.fall_damage_multiplier"), 1, 0, 100), + GENERIC_FLYING_SPEED(Key.key("minecraft:generic.flying_speed"), 0.4F, 0, 1024), + GENERIC_FOLLOW_RANGE(Key.key("minecraft:generic.follow_range"), 32, 0, 2048), + GENERIC_GRAVITY(Key.key("minecraft:generic.gravity"), 0.08, -1, 1), + GENERIC_JUMP_STRENGTH(Key.key("minecraft:generic.jump_strength"), 0.42, 0, 32), + GENERIC_KNOCKBACK_RESISTANCE(Key.key("minecraft:generic.knockback_resistance"), 0, 0, 1), + GENERIC_LUCK(Key.key("minecraft:generic.luck"), 0, -1024, 1024), + GENERIC_MAX_ABSORPTION(Key.key("minecraft:generic.max_absorption"), 0, 0, 2048), + GENERIC_MAX_HEALTH(Key.key("minecraft:generic.max_health"), 20, 1, 1024), + GENERIC_MOVEMENT_SPEED(Key.key("minecraft:generic.movement_speed"), 0.7F, 0, 1024), + GENERIC_SAFE_FALL_DISTANCE(Key.key("minecraft:generic.safe_fall_distance"), 3, -1024, 1024), + GENERIC_SCALE(Key.key("minecraft:generic.scale"), 1, 0.0625, 16), + ZOMBIE_SPAWN_REINFORCEMENTS(Key.key("minecraft:zombie.spawn_reinforcements"), 0, 0, 1), + GENERIC_STEP_HEIGHT(Key.key("minecraft:generic.step_height"), 0.6, 0, 10); - private final String identifier; + private final Key identifier; private final double def; private final double min; private final double max; diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/entity/player/PlayerSpawnInfo.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/entity/player/PlayerSpawnInfo.java index ed7f076fc..a56dcad2f 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/entity/player/PlayerSpawnInfo.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/entity/player/PlayerSpawnInfo.java @@ -3,6 +3,7 @@ import lombok.AllArgsConstructor; import lombok.Data; import lombok.NonNull; +import net.kyori.adventure.key.Key; import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.GlobalPos; @@ -10,7 +11,7 @@ @AllArgsConstructor public class PlayerSpawnInfo { private final int dimension; - private final @NonNull String worldName; + private final @NonNull Key worldName; private final long hashedSeed; private final @NonNull GameMode gameMode; private final @Nullable GameMode previousGamemode; diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/ingame/clientbound/ClientboundLoginPacket.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/ingame/clientbound/ClientboundLoginPacket.java index b94854e93..8465b9045 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/ingame/clientbound/ClientboundLoginPacket.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/ingame/clientbound/ClientboundLoginPacket.java @@ -5,6 +5,7 @@ import lombok.Data; import lombok.NonNull; import lombok.With; +import net.kyori.adventure.key.Key; import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper; import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket; import org.geysermc.mcprotocollib.protocol.data.game.entity.player.PlayerSpawnInfo; @@ -15,7 +16,7 @@ public class ClientboundLoginPacket implements MinecraftPacket { private final int entityId; private final boolean hardcore; - private final @NonNull String[] worldNames; + private final @NonNull Key[] worldNames; private final int maxPlayers; private final int viewDistance; private final int simulationDistance; @@ -29,9 +30,9 @@ public ClientboundLoginPacket(ByteBuf in, MinecraftCodecHelper helper) { this.entityId = in.readInt(); this.hardcore = in.readBoolean(); int worldCount = helper.readVarInt(in); - this.worldNames = new String[worldCount]; + this.worldNames = new Key[worldCount]; for (int i = 0; i < worldCount; i++) { - this.worldNames[i] = helper.readString(in); + this.worldNames[i] = helper.readResourceLocation(in); } this.maxPlayers = helper.readVarInt(in); this.viewDistance = helper.readVarInt(in); @@ -48,8 +49,8 @@ public void serialize(ByteBuf out, MinecraftCodecHelper helper) { out.writeInt(this.entityId); out.writeBoolean(this.hardcore); helper.writeVarInt(out, this.worldNames.length); - for (String worldName : this.worldNames) { - helper.writeString(out, worldName); + for (Key worldName : this.worldNames) { + helper.writeResourceLocation(out, worldName); } helper.writeVarInt(out, this.maxPlayers); helper.writeVarInt(out, this.viewDistance); diff --git a/protocol/src/test/java/org/geysermc/mcprotocollib/protocol/MinecraftProtocolTest.java b/protocol/src/test/java/org/geysermc/mcprotocollib/protocol/MinecraftProtocolTest.java index 0578034dc..82c9ac6cc 100644 --- a/protocol/src/test/java/org/geysermc/mcprotocollib/protocol/MinecraftProtocolTest.java +++ b/protocol/src/test/java/org/geysermc/mcprotocollib/protocol/MinecraftProtocolTest.java @@ -1,5 +1,6 @@ package org.geysermc.mcprotocollib.protocol; +import net.kyori.adventure.key.Key; import net.kyori.adventure.text.Component; import org.geysermc.mcprotocollib.network.Server; import org.geysermc.mcprotocollib.network.Session; @@ -39,7 +40,7 @@ public class MinecraftProtocolTest { null, false ); - private static final ClientboundLoginPacket JOIN_GAME_PACKET = new ClientboundLoginPacket(0, false, new String[]{"minecraft:world"}, 0, 16, 16, false, false, false, new PlayerSpawnInfo(0, "minecraft:world", 100, GameMode.SURVIVAL, GameMode.SURVIVAL, false, false, null, 100), true); + private static final ClientboundLoginPacket JOIN_GAME_PACKET = new ClientboundLoginPacket(0, false, new Key[]{Key.key("minecraft:world")}, 0, 16, 16, false, false, false, new PlayerSpawnInfo(0, Key.key("minecraft:world"), 100, GameMode.SURVIVAL, GameMode.SURVIVAL, false, false, null, 100), true); private static Server server; From f747f81c07ed8a7ca6395f57a2d5c04ebd2ef59f Mon Sep 17 00:00:00 2001 From: AlexProgrammerDE <40795980+AlexProgrammerDE@users.noreply.github.com> Date: Tue, 14 May 2024 18:51:13 +0200 Subject: [PATCH 05/11] Fix more packets with invalid resource locations --- .../clientbound/ClientboundCustomPayloadPacket.java | 7 ++++--- .../serverbound/ServerboundCustomPayloadPacket.java | 7 ++++--- .../ClientboundUpdateEnabledFeaturesPacket.java | 11 ++++++----- .../clientbound/ClientboundCustomQueryPacket.java | 7 ++++--- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/common/clientbound/ClientboundCustomPayloadPacket.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/common/clientbound/ClientboundCustomPayloadPacket.java index 2a472247b..fcd917eec 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/common/clientbound/ClientboundCustomPayloadPacket.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/common/clientbound/ClientboundCustomPayloadPacket.java @@ -5,6 +5,7 @@ import lombok.Data; import lombok.NonNull; import lombok.With; +import net.kyori.adventure.key.Key; import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper; import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket; @@ -12,17 +13,17 @@ @With @AllArgsConstructor public class ClientboundCustomPayloadPacket implements MinecraftPacket { - private final @NonNull String channel; + private final @NonNull Key channel; private final byte @NonNull [] data; public ClientboundCustomPayloadPacket(ByteBuf in, MinecraftCodecHelper helper) { - this.channel = helper.readString(in); + this.channel = helper.readResourceLocation(in); this.data = helper.readByteArray(in, ByteBuf::readableBytes); } @Override public void serialize(ByteBuf out, MinecraftCodecHelper helper) { - helper.writeString(out, this.channel); + helper.writeResourceLocation(out, this.channel); out.writeBytes(this.data); } } diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/common/serverbound/ServerboundCustomPayloadPacket.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/common/serverbound/ServerboundCustomPayloadPacket.java index 3be7cd3d5..1264383ee 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/common/serverbound/ServerboundCustomPayloadPacket.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/common/serverbound/ServerboundCustomPayloadPacket.java @@ -5,6 +5,7 @@ import lombok.Data; import lombok.NonNull; import lombok.With; +import net.kyori.adventure.key.Key; import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper; import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket; @@ -12,17 +13,17 @@ @With @AllArgsConstructor public class ServerboundCustomPayloadPacket implements MinecraftPacket { - private final @NonNull String channel; + private final @NonNull Key channel; private final byte @NonNull [] data; public ServerboundCustomPayloadPacket(ByteBuf in, MinecraftCodecHelper helper) { - this.channel = helper.readString(in); + this.channel = helper.readResourceLocation(in); this.data = helper.readByteArray(in, ByteBuf::readableBytes); } @Override public void serialize(ByteBuf out, MinecraftCodecHelper helper) { - helper.writeString(out, this.channel); + helper.writeResourceLocation(out, this.channel); out.writeBytes(this.data); } } diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/configuration/clientbound/ClientboundUpdateEnabledFeaturesPacket.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/configuration/clientbound/ClientboundUpdateEnabledFeaturesPacket.java index 3559512f3..df445dd29 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/configuration/clientbound/ClientboundUpdateEnabledFeaturesPacket.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/configuration/clientbound/ClientboundUpdateEnabledFeaturesPacket.java @@ -4,6 +4,7 @@ import lombok.AllArgsConstructor; import lombok.Data; import lombok.With; +import net.kyori.adventure.key.Key; import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper; import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket; @@ -11,19 +12,19 @@ @With @AllArgsConstructor public class ClientboundUpdateEnabledFeaturesPacket implements MinecraftPacket { - private final String[] features; + private final Key[] features; public ClientboundUpdateEnabledFeaturesPacket(ByteBuf in, MinecraftCodecHelper helper) { - this.features = new String[helper.readVarInt(in)]; + this.features = new Key[helper.readVarInt(in)]; for (int i = 0; i < this.features.length; i++) { - this.features[i] = helper.readString(in); + this.features[i] = helper.readResourceLocation(in); } } public void serialize(ByteBuf out, MinecraftCodecHelper helper) { helper.writeVarInt(out, this.features.length); - for (String feature : this.features) { - helper.writeString(out, feature); + for (Key feature : this.features) { + helper.writeResourceLocation(out, feature); } } } diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/login/clientbound/ClientboundCustomQueryPacket.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/login/clientbound/ClientboundCustomQueryPacket.java index 8836deb13..e6daa25f2 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/login/clientbound/ClientboundCustomQueryPacket.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/login/clientbound/ClientboundCustomQueryPacket.java @@ -5,6 +5,7 @@ import lombok.Data; import lombok.NonNull; import lombok.With; +import net.kyori.adventure.key.Key; import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper; import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket; @@ -13,19 +14,19 @@ @AllArgsConstructor public class ClientboundCustomQueryPacket implements MinecraftPacket { private final int messageId; - private final @NonNull String channel; + private final @NonNull Key channel; private final byte @NonNull [] data; public ClientboundCustomQueryPacket(ByteBuf in, MinecraftCodecHelper helper) { this.messageId = helper.readVarInt(in); - this.channel = helper.readString(in); + this.channel = helper.readResourceLocation(in); this.data = helper.readByteArray(in, ByteBuf::readableBytes); } @Override public void serialize(ByteBuf out, MinecraftCodecHelper helper) { helper.writeVarInt(out, this.messageId); - helper.writeString(out, this.channel); + helper.writeResourceLocation(out, this.channel); out.writeBytes(this.data); } } From f50b2fc36621aefdced320a3f9b9e60fcc95b5db Mon Sep 17 00:00:00 2001 From: AlexProgrammerDE <40795980+AlexProgrammerDE@users.noreply.github.com> Date: Tue, 14 May 2024 18:57:20 +0200 Subject: [PATCH 06/11] Update jigsaw packet to use ResourceLocation --- .../ServerboundSetJigsawBlockPacket.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/ingame/serverbound/inventory/ServerboundSetJigsawBlockPacket.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/ingame/serverbound/inventory/ServerboundSetJigsawBlockPacket.java index 783cca61c..d49dc500b 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/ingame/serverbound/inventory/ServerboundSetJigsawBlockPacket.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/ingame/serverbound/inventory/ServerboundSetJigsawBlockPacket.java @@ -5,6 +5,7 @@ import lombok.Data; import lombok.NonNull; import lombok.With; +import net.kyori.adventure.key.Key; import org.cloudburstmc.math.vector.Vector3i; import org.geysermc.mcprotocollib.protocol.codec.MinecraftCodecHelper; import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket; @@ -14,9 +15,9 @@ @AllArgsConstructor public class ServerboundSetJigsawBlockPacket implements MinecraftPacket { private final @NonNull Vector3i position; - private final @NonNull String name; - private final @NonNull String target; - private final @NonNull String pool; + private final @NonNull Key name; + private final @NonNull Key target; + private final @NonNull Key pool; private final @NonNull String finalState; private final @NonNull String jointType; private final int selectionPriority; @@ -24,9 +25,9 @@ public class ServerboundSetJigsawBlockPacket implements MinecraftPacket { public ServerboundSetJigsawBlockPacket(ByteBuf in, MinecraftCodecHelper helper) { this.position = helper.readPosition(in); - this.name = helper.readString(in); - this.target = helper.readString(in); - this.pool = helper.readString(in); + this.name = helper.readResourceLocation(in); + this.target = helper.readResourceLocation(in); + this.pool = helper.readResourceLocation(in); this.finalState = helper.readString(in); this.jointType = helper.readString(in); this.selectionPriority = helper.readVarInt(in); @@ -36,9 +37,9 @@ public ServerboundSetJigsawBlockPacket(ByteBuf in, MinecraftCodecHelper helper) @Override public void serialize(ByteBuf out, MinecraftCodecHelper helper) { helper.writePosition(out, this.position); - helper.writeString(out, this.name); - helper.writeString(out, this.target); - helper.writeString(out, this.pool); + helper.writeResourceLocation(out, this.name); + helper.writeResourceLocation(out, this.target); + helper.writeResourceLocation(out, this.pool); helper.writeString(out, this.finalState); helper.writeString(out, this.jointType); helper.writeVarInt(out, this.selectionPriority); From 3ac888272abad23b59ebf921275868b593930f07 Mon Sep 17 00:00:00 2001 From: AlexProgrammerDE <40795980+AlexProgrammerDE@users.noreply.github.com> Date: Tue, 14 May 2024 18:57:59 +0200 Subject: [PATCH 07/11] Fix test compilation --- .../login/clientbound/ClientboundCustomQueryPacketTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/protocol/src/test/java/org/geysermc/mcprotocollib/protocol/packet/login/clientbound/ClientboundCustomQueryPacketTest.java b/protocol/src/test/java/org/geysermc/mcprotocollib/protocol/packet/login/clientbound/ClientboundCustomQueryPacketTest.java index d3bbc1efc..ce716b3d1 100644 --- a/protocol/src/test/java/org/geysermc/mcprotocollib/protocol/packet/login/clientbound/ClientboundCustomQueryPacketTest.java +++ b/protocol/src/test/java/org/geysermc/mcprotocollib/protocol/packet/login/clientbound/ClientboundCustomQueryPacketTest.java @@ -1,5 +1,6 @@ package org.geysermc.mcprotocollib.protocol.packet.login.clientbound; +import net.kyori.adventure.key.Key; import org.geysermc.mcprotocollib.protocol.packet.PacketTest; import org.junit.jupiter.api.BeforeEach; @@ -11,6 +12,6 @@ public void setup() { byte[] data = new byte[1024]; new Random().nextBytes(data); - this.setPackets(new ClientboundCustomQueryPacket(0, "Channel", data)); + this.setPackets(new ClientboundCustomQueryPacket(0, Key.key("channel"), data)); } } From d0d1c2a3a719a7f95ca5dd474d3fa2a5539b7ffd Mon Sep 17 00:00:00 2001 From: AlexProgrammerDE <40795980+AlexProgrammerDE@users.noreply.github.com> Date: Wed, 15 May 2024 08:09:11 +0200 Subject: [PATCH 08/11] Fully use Key for ResourceProperties --- .../data/game/command/properties/ResourceProperties.java | 4 ++-- .../packet/ingame/clientbound/ClientboundCommandsPacket.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/command/properties/ResourceProperties.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/command/properties/ResourceProperties.java index ff363c248..73dea2bae 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/command/properties/ResourceProperties.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/command/properties/ResourceProperties.java @@ -7,7 +7,7 @@ public class ResourceProperties implements CommandProperties { private final Key registryKey; - public ResourceProperties(String registryKey) { - this.registryKey = Key.key(registryKey); + public ResourceProperties(Key registryKey) { + this.registryKey = registryKey; } } diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/ingame/clientbound/ClientboundCommandsPacket.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/ingame/clientbound/ClientboundCommandsPacket.java index 494c96d3e..9187c49a1 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/ingame/clientbound/ClientboundCommandsPacket.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/ingame/clientbound/ClientboundCommandsPacket.java @@ -136,7 +136,7 @@ public ClientboundCommandsPacket(ByteBuf in, MinecraftCodecHelper helper) { } case SCORE_HOLDER -> properties = new ScoreHolderProperties(in.readBoolean()); case TIME -> properties = new TimeProperties(in.readInt()); - case RESOURCE_OR_TAG, RESOURCE_OR_TAG_KEY, RESOURCE, RESOURCE_KEY -> properties = new ResourceProperties(helper.readString(in)); + case RESOURCE_OR_TAG, RESOURCE_OR_TAG_KEY, RESOURCE, RESOURCE_KEY -> properties = new ResourceProperties(helper.readResourceLocation(in)); default -> { } } From aaa84c9f8e69ab7381c49bf9b9790c2251cbdfad Mon Sep 17 00:00:00 2001 From: AlexProgrammerDE <40795980+AlexProgrammerDE@users.noreply.github.com> Date: Wed, 15 May 2024 08:17:33 +0200 Subject: [PATCH 09/11] Fix all Key.key() warnings --- .../mcprotocollib/network/codec/BasePacketCodecHelper.java | 1 + .../org/geysermc/mcprotocollib/protocol/ServerListener.java | 3 +++ .../mcprotocollib/protocol/codec/MinecraftCodecHelper.java | 1 + .../protocol/data/game/chat/BuiltinChatType.java | 4 +++- .../protocol/data/game/command/SuggestionType.java | 4 +++- 5 files changed, 11 insertions(+), 2 deletions(-) diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/network/codec/BasePacketCodecHelper.java b/protocol/src/main/java/org/geysermc/mcprotocollib/network/codec/BasePacketCodecHelper.java index 4d93a2272..6aec58f54 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/network/codec/BasePacketCodecHelper.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/network/codec/BasePacketCodecHelper.java @@ -140,6 +140,7 @@ public long readVarLong(ByteBuf buf) { return value | ((b & 0x7FL) << (size * 7)); } + @Override public String readString(ByteBuf buf) { return this.readString(buf, Short.MAX_VALUE); } diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/ServerListener.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/ServerListener.java index 058c3a216..261e21955 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/ServerListener.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/ServerListener.java @@ -137,11 +137,14 @@ public void packetReceived(Session session, Packet packet) { // Credit ViaVersion: https://github.com/ViaVersion/ViaVersion/blob/dev/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/EntityPacketRewriter1_20_5.java for (Map.Entry entry : networkCodec.entrySet()) { + @SuppressWarnings("PatternValidation") NbtMap entryTag = (NbtMap) entry.getValue(); + @SuppressWarnings("PatternValidation") Key typeTag = Key.key(entryTag.getString("type")); List valueTag = entryTag.getList("value", NbtType.COMPOUND); List entries = new ArrayList<>(); for (NbtMap compoundTag : valueTag) { + @SuppressWarnings("PatternValidation") Key nameTag = Key.key(compoundTag.getString("name")); int id = compoundTag.getInt("id"); entries.add(id, new RegistryEntry(nameTag, compoundTag.getCompound("element"))); diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/codec/MinecraftCodecHelper.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/codec/MinecraftCodecHelper.java index 5b08cb4f6..66e4b0f41 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/codec/MinecraftCodecHelper.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/codec/MinecraftCodecHelper.java @@ -144,6 +144,7 @@ public void writeHolder(ByteBuf buf, Holder holder, BiConsumer Date: Mon, 20 May 2024 07:48:05 +0200 Subject: [PATCH 10/11] Fix HolderSet revert --- .../protocol/data/game/item/component/HolderSet.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/HolderSet.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/HolderSet.java index d9c454653..5e9617341 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/HolderSet.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/item/component/HolderSet.java @@ -2,6 +2,7 @@ import lombok.Data; import lombok.NonNull; +import net.kyori.adventure.key.Key; import org.checkerframework.checker.nullness.qual.Nullable; import java.util.function.Function; @@ -12,7 +13,7 @@ */ @Data public final class HolderSet { - private final @Nullable String location; + private final @Nullable Key location; private final int @Nullable [] holders; public HolderSet(int @NonNull [] holders) { @@ -20,7 +21,7 @@ public HolderSet(int @NonNull [] holders) { this.holders = holders; } - public HolderSet(@NonNull String location) { + public HolderSet(@NonNull Key location) { this.location = location; this.holders = null; } @@ -31,7 +32,7 @@ public HolderSet(@NonNull String location) { * @param tagResolver The function to resolve the tag location to get the holders. * @return The holders. */ - public int[] resolve(Function tagResolver) { + public int[] resolve(Function tagResolver) { if (holders != null) { return holders; } From 894ecff370b83298a52a340f31d9e8796ac16c89 Mon Sep 17 00:00:00 2001 From: AlexProgrammerDE <40795980+AlexProgrammerDE@users.noreply.github.com> Date: Sun, 9 Jun 2024 20:40:29 +0200 Subject: [PATCH 11/11] Address review --- .../protocol/codec/MinecraftCodecHelper.java | 2 +- .../game/entity/attribute/AttributeType.java | 54 ++++++++++--------- 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/codec/MinecraftCodecHelper.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/codec/MinecraftCodecHelper.java index 61f169ec8..562a09f74 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/codec/MinecraftCodecHelper.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/codec/MinecraftCodecHelper.java @@ -167,7 +167,7 @@ public Key readResourceLocation(ByteBuf buf) { } public void writeResourceLocation(ByteBuf buf, Key location) { - this.writeString(buf, location.toString()); + this.writeString(buf, location.asString()); } public UUID readUUID(ByteBuf buf) { diff --git a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/entity/attribute/AttributeType.java b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/entity/attribute/AttributeType.java index 77e62c261..5d0963d41 100644 --- a/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/entity/attribute/AttributeType.java +++ b/protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/entity/attribute/AttributeType.java @@ -2,9 +2,9 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; -import lombok.AllArgsConstructor; import lombok.Getter; import net.kyori.adventure.key.Key; +import net.kyori.adventure.key.KeyPattern; public interface AttributeType { @@ -31,36 +31,42 @@ public interface AttributeType { // } @Getter - @AllArgsConstructor enum Builtin implements AttributeType { - GENERIC_ARMOR(Key.key("minecraft:generic.armor"), 0, 0, 30), - GENERIC_ARMOR_TOUGHNESS(Key.key("minecraft:generic.armor_toughness"), 0, 0, 20), - GENERIC_ATTACK_DAMAGE(Key.key("minecraft:generic.attack_damage"), 2, 0, 2048), - GENERIC_ATTACK_KNOCKBACK(Key.key("minecraft:generic.attack_knockback"), 0, 0, 5), - GENERIC_ATTACK_SPEED(Key.key("minecraft:generic.attack_speed"), 4, 0, 1024), - PLAYER_BLOCK_BREAK_SPEED(Key.key("minecraft:player.block_break_speed"), 1, 0, 1024), - PLAYER_BLOCK_INTERACTION_RANGE(Key.key("minecraft:player.block_interaction_range"), 4.5, 0, 64), - PLAYER_ENTITY_INTERACTION_RANGE(Key.key("minecraft:player.entity_interaction_range"), 3, 0, 64), - GENERIC_FALL_DAMAGE_MULTIPLIER(Key.key("minecraft:generic.fall_damage_multiplier"), 1, 0, 100), - GENERIC_FLYING_SPEED(Key.key("minecraft:generic.flying_speed"), 0.4F, 0, 1024), - GENERIC_FOLLOW_RANGE(Key.key("minecraft:generic.follow_range"), 32, 0, 2048), - GENERIC_GRAVITY(Key.key("minecraft:generic.gravity"), 0.08, -1, 1), - GENERIC_JUMP_STRENGTH(Key.key("minecraft:generic.jump_strength"), 0.42, 0, 32), - GENERIC_KNOCKBACK_RESISTANCE(Key.key("minecraft:generic.knockback_resistance"), 0, 0, 1), - GENERIC_LUCK(Key.key("minecraft:generic.luck"), 0, -1024, 1024), - GENERIC_MAX_ABSORPTION(Key.key("minecraft:generic.max_absorption"), 0, 0, 2048), - GENERIC_MAX_HEALTH(Key.key("minecraft:generic.max_health"), 20, 1, 1024), - GENERIC_MOVEMENT_SPEED(Key.key("minecraft:generic.movement_speed"), 0.7F, 0, 1024), - GENERIC_SAFE_FALL_DISTANCE(Key.key("minecraft:generic.safe_fall_distance"), 3, -1024, 1024), - GENERIC_SCALE(Key.key("minecraft:generic.scale"), 1, 0.0625, 16), - ZOMBIE_SPAWN_REINFORCEMENTS(Key.key("minecraft:zombie.spawn_reinforcements"), 0, 0, 1), - GENERIC_STEP_HEIGHT(Key.key("minecraft:generic.step_height"), 0.6, 0, 10); + GENERIC_ARMOR("minecraft:generic.armor", 0, 0, 30), + GENERIC_ARMOR_TOUGHNESS("minecraft:generic.armor_toughness", 0, 0, 20), + GENERIC_ATTACK_DAMAGE("minecraft:generic.attack_damage", 2, 0, 2048), + GENERIC_ATTACK_KNOCKBACK("minecraft:generic.attack_knockback", 0, 0, 5), + GENERIC_ATTACK_SPEED("minecraft:generic.attack_speed", 4, 0, 1024), + PLAYER_BLOCK_BREAK_SPEED("minecraft:player.block_break_speed", 1, 0, 1024), + PLAYER_BLOCK_INTERACTION_RANGE("minecraft:player.block_interaction_range", 4.5, 0, 64), + PLAYER_ENTITY_INTERACTION_RANGE("minecraft:player.entity_interaction_range", 3, 0, 64), + GENERIC_FALL_DAMAGE_MULTIPLIER("minecraft:generic.fall_damage_multiplier", 1, 0, 100), + GENERIC_FLYING_SPEED("minecraft:generic.flying_speed", 0.4F, 0, 1024), + GENERIC_FOLLOW_RANGE("minecraft:generic.follow_range", 32, 0, 2048), + GENERIC_GRAVITY("minecraft:generic.gravity", 0.08, -1, 1), + GENERIC_JUMP_STRENGTH("minecraft:generic.jump_strength", 0.42, 0, 32), + GENERIC_KNOCKBACK_RESISTANCE("minecraft:generic.knockback_resistance", 0, 0, 1), + GENERIC_LUCK("minecraft:generic.luck", 0, -1024, 1024), + GENERIC_MAX_ABSORPTION("minecraft:generic.max_absorption", 0, 0, 2048), + GENERIC_MAX_HEALTH("minecraft:generic.max_health", 20, 1, 1024), + GENERIC_MOVEMENT_SPEED("minecraft:generic.movement_speed", 0.7F, 0, 1024), + GENERIC_SAFE_FALL_DISTANCE("minecraft:generic.safe_fall_distance", 3, -1024, 1024), + GENERIC_SCALE("minecraft:generic.scale", 1, 0.0625, 16), + ZOMBIE_SPAWN_REINFORCEMENTS("minecraft:zombie.spawn_reinforcements", 0, 0, 1), + GENERIC_STEP_HEIGHT("minecraft:generic.step_height", 0.6, 0, 10); private final Key identifier; private final double def; private final double min; private final double max; + Builtin(@KeyPattern String identifier, double def, double min, double max) { + this.identifier = Key.key(identifier); + this.def = def; + this.min = min; + this.max = max; + } + public int getId() { return this.ordinal(); }