Skip to content
Open
3 changes: 3 additions & 0 deletions code-generators/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ plugins {
repositories {
mavenLocal()
mavenCentral()
maven("https://s01.oss.sonatype.org/content/repositories/releases/")
}

dependencies {
// Provides the input JSON to generate from
implementation(libs.minestomData)

implementation(libs.bundles.adventure)

// Common
implementation(libs.jetbrainsAnnotations)
implementation(libs.slf4j)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import com.squareup.javapoet.*;
import com.squareup.javapoet.AnnotationSpec;
import com.squareup.javapoet.ClassName;
import com.squareup.javapoet.FieldSpec;
import com.squareup.javapoet.JavaFile;
import com.squareup.javapoet.TypeSpec;
import net.kyori.adventure.key.Key;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -75,8 +80,7 @@ public void generateKeys(InputStream resourceFile, String packageName, String ty
}

ClassName typeClass = ClassName.bestGuess(packageName + "." + typeName); // Use bestGuess to handle nested class
ClassName registryKeyClass = ClassName.get("net.minestom.server.registry", "DynamicRegistry", "Key");
ParameterizedTypeName typedRegistryKeyClass = ParameterizedTypeName.get(registryKeyClass, typeClass);
ClassName registryKeyClass = ClassName.get(Key.class);

JsonObject json;
json = GSON.fromJson(new InputStreamReader(resourceFile), JsonObject.class);
Expand All @@ -97,11 +101,11 @@ public void generateKeys(InputStream resourceFile, String packageName, String ty
constantName = "_" + constantName;
}
blockConstantsClass.addField(
FieldSpec.builder(typedRegistryKeyClass, constantName)
FieldSpec.builder(registryKeyClass, constantName)
.addModifiers(Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL)
.initializer(
// TypeClass.STONE = NamespaceID.from("minecraft:stone")
"$T.of($S)",
// TypeClass.STONE = Key.key("minecraft:stone")
"$T.key($S)",
registryKeyClass,
namespace
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.squareup.javapoet.*;
import net.kyori.adventure.key.Key;
import net.minestom.codegen.MinestomCodeGenerator;
import net.minestom.codegen.util.GenerationHelper;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -50,7 +51,7 @@ public void generate() {
TypeSpec.Builder recipeTypeEnum = TypeSpec.enumBuilder(recipeTypeCN)
.addSuperinterface(ClassName.get("net.minestom.server.registry", "StaticProtocolObject"))
.addModifiers(Modifier.PUBLIC).addJavadoc("AUTOGENERATED by " + getClass().getSimpleName());
ClassName namespaceIdCN = ClassName.get("net.minestom.server.utils", "NamespaceID");
ClassName namespaceIdCN = ClassName.get(Key.class);

ClassName networkBufferCN = ClassName.get("net.minestom.server.network", "NetworkBuffer");
ParameterizedTypeName networkBufferTypeCN = ParameterizedTypeName.get(networkBufferCN.nestedClass("Type"), recipeTypeCN);
Expand Down Expand Up @@ -93,7 +94,7 @@ public void generate() {
for (JsonObject recipeTypeObject : StreamSupport.stream(recipeTypes.spliterator(), true).map(JsonElement::getAsJsonObject).sorted(Comparator.comparingInt(o -> o.get("id").getAsInt())).toList()) {
String recipeTypeName = recipeTypeObject.get("name").getAsString();
recipeTypeEnum.addEnumConstant(recipeTypeConstantName(recipeTypeName), TypeSpec.anonymousClassBuilder(
"$T.from($S)",
"$T.key($S)",
namespaceIdCN, recipeTypeName
).build()
);
Expand Down
8 changes: 4 additions & 4 deletions demo/src/main/java/net/minestom/demo/PlayerInit.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.minestom.demo;

import net.kyori.adventure.key.Key;
import net.kyori.adventure.sound.Sound;
import net.kyori.adventure.text.Component;
import net.minestom.server.FeatureFlag;
Expand Down Expand Up @@ -60,7 +61,6 @@
import net.minestom.server.sound.SoundEvent;
import net.minestom.server.notifications.Notification;
import net.minestom.server.utils.MathUtils;
import net.minestom.server.utils.NamespaceID;
import net.minestom.server.utils.time.TimeUnit;

import java.time.Duration;
Expand Down Expand Up @@ -130,9 +130,9 @@ class A {
static boolean b = false;
}
if (A.b) {
event.getPlayer().getAttribute(Attribute.GENERIC_MOVEMENT_SPEED).removeModifier(NamespaceID.from("test"));
event.getPlayer().getAttribute(Attribute.GENERIC_MOVEMENT_SPEED).removeModifier(Key.key("test"));
} else {
event.getPlayer().getAttribute(Attribute.GENERIC_MOVEMENT_SPEED).addModifier(new AttributeModifier(NamespaceID.from("test"), 0.5, AttributeOperation.ADD_VALUE));
event.getPlayer().getAttribute(Attribute.GENERIC_MOVEMENT_SPEED).addModifier(new AttributeModifier(Key.key("test"), 0.5, AttributeOperation.ADD_VALUE));
}
A.b = !A.b;
})
Expand Down Expand Up @@ -167,7 +167,7 @@ class A {
player.getInventory().addItemStack(bundle);

player.getInventory().addItemStack(ItemStack.builder(Material.COMPASS)
.set(ItemComponent.LODESTONE_TRACKER, new LodestoneTracker(player.getInstance().getDimensionName(), new Vec(10, 10, 10), true))
.set(ItemComponent.LODESTONE_TRACKER, new LodestoneTracker(player.getInstance().getDimensionType(), new Vec(10, 10, 10), true))
.build());

player.getInventory().addItemStack(ItemStack.builder(Material.STONE_SWORD)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.minestom.demo.block;

import net.kyori.adventure.key.Key;
import net.kyori.adventure.nbt.BinaryTag;
import net.kyori.adventure.nbt.BinaryTagTypes;
import net.kyori.adventure.nbt.CompoundBinaryTag;
Expand All @@ -11,7 +12,6 @@
import net.minestom.server.tag.TagReadable;
import net.minestom.server.tag.TagSerializer;
import net.minestom.server.tag.TagWritable;
import net.minestom.server.utils.NamespaceID;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -65,7 +65,7 @@ public void write(@NotNull TagWritable writer, @Nullable List<ItemStack> value)
}

@Override
public @NotNull NamespaceID getNamespaceId() {
return NamespaceID.from("minestom:test");
public @NotNull Key getNamespaceId() {
return Key.key("minestom:test");
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package net.minestom.demo.block;

import net.kyori.adventure.key.Key;
import net.minestom.server.instance.block.BlockHandler;
import net.minestom.server.utils.NamespaceID;
import org.jetbrains.annotations.NotNull;

public class TestBlockHandler implements BlockHandler {
public static final BlockHandler INSTANCE = new TestBlockHandler();

@Override
public @NotNull NamespaceID getNamespaceId() {
return NamespaceID.from("minestom", "test");
public @NotNull Key getNamespaceId() {
return Key.key("minestom", "test");
}

@Override
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
dependencyResolutionManagement {
repositories {
maven("https://s01.oss.sonatype.org/content/repositories/snapshots")
maven("https://s01.oss.sonatype.org/content/repositories/releases/")
maven("https://jitpack.io")
mavenCentral()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,103 +1,103 @@
package net.minestom.server.entity.damage;

import net.minestom.server.registry.DynamicRegistry;
import net.kyori.adventure.key.Key;

/**
* Code autogenerated, do not edit!
*/
@SuppressWarnings("unused")
interface DamageTypes {
DynamicRegistry.Key<DamageType> WITHER = DynamicRegistry.Key.of("minecraft:wither");
Key WITHER = Key.key("minecraft:wither");

DynamicRegistry.Key<DamageType> SONIC_BOOM = DynamicRegistry.Key.of("minecraft:sonic_boom");
Key SONIC_BOOM = Key.key("minecraft:sonic_boom");

DynamicRegistry.Key<DamageType> WITHER_SKULL = DynamicRegistry.Key.of("minecraft:wither_skull");
Key WITHER_SKULL = Key.key("minecraft:wither_skull");

DynamicRegistry.Key<DamageType> DRY_OUT = DynamicRegistry.Key.of("minecraft:dry_out");
Key DRY_OUT = Key.key("minecraft:dry_out");

DynamicRegistry.Key<DamageType> TRIDENT = DynamicRegistry.Key.of("minecraft:trident");
Key TRIDENT = Key.key("minecraft:trident");

DynamicRegistry.Key<DamageType> ON_FIRE = DynamicRegistry.Key.of("minecraft:on_fire");
Key ON_FIRE = Key.key("minecraft:on_fire");

DynamicRegistry.Key<DamageType> FALL = DynamicRegistry.Key.of("minecraft:fall");
Key FALL = Key.key("minecraft:fall");

DynamicRegistry.Key<DamageType> MOB_ATTACK = DynamicRegistry.Key.of("minecraft:mob_attack");
Key MOB_ATTACK = Key.key("minecraft:mob_attack");

DynamicRegistry.Key<DamageType> MOB_PROJECTILE = DynamicRegistry.Key.of("minecraft:mob_projectile");
Key MOB_PROJECTILE = Key.key("minecraft:mob_projectile");

DynamicRegistry.Key<DamageType> CAMPFIRE = DynamicRegistry.Key.of("minecraft:campfire");
Key CAMPFIRE = Key.key("minecraft:campfire");

DynamicRegistry.Key<DamageType> THROWN = DynamicRegistry.Key.of("minecraft:thrown");
Key THROWN = Key.key("minecraft:thrown");

DynamicRegistry.Key<DamageType> FALLING_STALACTITE = DynamicRegistry.Key.of("minecraft:falling_stalactite");
Key FALLING_STALACTITE = Key.key("minecraft:falling_stalactite");

DynamicRegistry.Key<DamageType> FIREBALL = DynamicRegistry.Key.of("minecraft:fireball");
Key FIREBALL = Key.key("minecraft:fireball");

DynamicRegistry.Key<DamageType> FALLING_BLOCK = DynamicRegistry.Key.of("minecraft:falling_block");
Key FALLING_BLOCK = Key.key("minecraft:falling_block");

DynamicRegistry.Key<DamageType> WIND_CHARGE = DynamicRegistry.Key.of("minecraft:wind_charge");
Key WIND_CHARGE = Key.key("minecraft:wind_charge");

DynamicRegistry.Key<DamageType> PLAYER_EXPLOSION = DynamicRegistry.Key.of("minecraft:player_explosion");
Key PLAYER_EXPLOSION = Key.key("minecraft:player_explosion");

DynamicRegistry.Key<DamageType> SPIT = DynamicRegistry.Key.of("minecraft:spit");
Key SPIT = Key.key("minecraft:spit");

DynamicRegistry.Key<DamageType> STING = DynamicRegistry.Key.of("minecraft:sting");
Key STING = Key.key("minecraft:sting");

DynamicRegistry.Key<DamageType> UNATTRIBUTED_FIREBALL = DynamicRegistry.Key.of("minecraft:unattributed_fireball");
Key UNATTRIBUTED_FIREBALL = Key.key("minecraft:unattributed_fireball");

DynamicRegistry.Key<DamageType> IN_WALL = DynamicRegistry.Key.of("minecraft:in_wall");
Key IN_WALL = Key.key("minecraft:in_wall");

DynamicRegistry.Key<DamageType> IN_FIRE = DynamicRegistry.Key.of("minecraft:in_fire");
Key IN_FIRE = Key.key("minecraft:in_fire");

DynamicRegistry.Key<DamageType> ARROW = DynamicRegistry.Key.of("minecraft:arrow");
Key ARROW = Key.key("minecraft:arrow");

DynamicRegistry.Key<DamageType> HOT_FLOOR = DynamicRegistry.Key.of("minecraft:hot_floor");
Key HOT_FLOOR = Key.key("minecraft:hot_floor");

DynamicRegistry.Key<DamageType> DROWN = DynamicRegistry.Key.of("minecraft:drown");
Key DROWN = Key.key("minecraft:drown");

DynamicRegistry.Key<DamageType> STARVE = DynamicRegistry.Key.of("minecraft:starve");
Key STARVE = Key.key("minecraft:starve");

DynamicRegistry.Key<DamageType> GENERIC_KILL = DynamicRegistry.Key.of("minecraft:generic_kill");
Key GENERIC_KILL = Key.key("minecraft:generic_kill");

DynamicRegistry.Key<DamageType> DRAGON_BREATH = DynamicRegistry.Key.of("minecraft:dragon_breath");
Key DRAGON_BREATH = Key.key("minecraft:dragon_breath");

DynamicRegistry.Key<DamageType> MOB_ATTACK_NO_AGGRO = DynamicRegistry.Key.of("minecraft:mob_attack_no_aggro");
Key MOB_ATTACK_NO_AGGRO = Key.key("minecraft:mob_attack_no_aggro");

DynamicRegistry.Key<DamageType> LAVA = DynamicRegistry.Key.of("minecraft:lava");
Key LAVA = Key.key("minecraft:lava");

DynamicRegistry.Key<DamageType> OUTSIDE_BORDER = DynamicRegistry.Key.of("minecraft:outside_border");
Key OUTSIDE_BORDER = Key.key("minecraft:outside_border");

DynamicRegistry.Key<DamageType> FLY_INTO_WALL = DynamicRegistry.Key.of("minecraft:fly_into_wall");
Key FLY_INTO_WALL = Key.key("minecraft:fly_into_wall");

DynamicRegistry.Key<DamageType> LIGHTNING_BOLT = DynamicRegistry.Key.of("minecraft:lightning_bolt");
Key LIGHTNING_BOLT = Key.key("minecraft:lightning_bolt");

DynamicRegistry.Key<DamageType> PLAYER_ATTACK = DynamicRegistry.Key.of("minecraft:player_attack");
Key PLAYER_ATTACK = Key.key("minecraft:player_attack");

DynamicRegistry.Key<DamageType> FREEZE = DynamicRegistry.Key.of("minecraft:freeze");
Key FREEZE = Key.key("minecraft:freeze");

DynamicRegistry.Key<DamageType> FALLING_ANVIL = DynamicRegistry.Key.of("minecraft:falling_anvil");
Key FALLING_ANVIL = Key.key("minecraft:falling_anvil");

DynamicRegistry.Key<DamageType> OUT_OF_WORLD = DynamicRegistry.Key.of("minecraft:out_of_world");
Key OUT_OF_WORLD = Key.key("minecraft:out_of_world");

DynamicRegistry.Key<DamageType> MAGIC = DynamicRegistry.Key.of("minecraft:magic");
Key MAGIC = Key.key("minecraft:magic");

DynamicRegistry.Key<DamageType> SWEET_BERRY_BUSH = DynamicRegistry.Key.of("minecraft:sweet_berry_bush");
Key SWEET_BERRY_BUSH = Key.key("minecraft:sweet_berry_bush");

DynamicRegistry.Key<DamageType> FIREWORKS = DynamicRegistry.Key.of("minecraft:fireworks");
Key FIREWORKS = Key.key("minecraft:fireworks");

DynamicRegistry.Key<DamageType> EXPLOSION = DynamicRegistry.Key.of("minecraft:explosion");
Key EXPLOSION = Key.key("minecraft:explosion");

DynamicRegistry.Key<DamageType> BAD_RESPAWN_POINT = DynamicRegistry.Key.of("minecraft:bad_respawn_point");
Key BAD_RESPAWN_POINT = Key.key("minecraft:bad_respawn_point");

DynamicRegistry.Key<DamageType> STALAGMITE = DynamicRegistry.Key.of("minecraft:stalagmite");
Key STALAGMITE = Key.key("minecraft:stalagmite");

DynamicRegistry.Key<DamageType> THORNS = DynamicRegistry.Key.of("minecraft:thorns");
Key THORNS = Key.key("minecraft:thorns");

DynamicRegistry.Key<DamageType> INDIRECT_MAGIC = DynamicRegistry.Key.of("minecraft:indirect_magic");
Key INDIRECT_MAGIC = Key.key("minecraft:indirect_magic");

DynamicRegistry.Key<DamageType> CRAMMING = DynamicRegistry.Key.of("minecraft:cramming");
Key CRAMMING = Key.key("minecraft:cramming");

DynamicRegistry.Key<DamageType> CACTUS = DynamicRegistry.Key.of("minecraft:cactus");
Key CACTUS = Key.key("minecraft:cactus");

DynamicRegistry.Key<DamageType> GENERIC = DynamicRegistry.Key.of("minecraft:generic");
Key GENERIC = Key.key("minecraft:generic");
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
package net.minestom.server.entity.metadata.animal.tameable;

import net.minestom.server.registry.DynamicRegistry;
import net.kyori.adventure.key.Key;

/**
* Code autogenerated, do not edit!
*/
@SuppressWarnings("unused")
interface WolfVariants {
DynamicRegistry.Key<WolfMeta.Variant> BLACK = DynamicRegistry.Key.of("minecraft:black");
Key BLACK = Key.key("minecraft:black");

DynamicRegistry.Key<WolfMeta.Variant> CHESTNUT = DynamicRegistry.Key.of("minecraft:chestnut");
Key CHESTNUT = Key.key("minecraft:chestnut");

DynamicRegistry.Key<WolfMeta.Variant> SNOWY = DynamicRegistry.Key.of("minecraft:snowy");
Key SNOWY = Key.key("minecraft:snowy");

DynamicRegistry.Key<WolfMeta.Variant> STRIPED = DynamicRegistry.Key.of("minecraft:striped");
Key STRIPED = Key.key("minecraft:striped");

DynamicRegistry.Key<WolfMeta.Variant> ASHEN = DynamicRegistry.Key.of("minecraft:ashen");
Key ASHEN = Key.key("minecraft:ashen");

DynamicRegistry.Key<WolfMeta.Variant> SPOTTED = DynamicRegistry.Key.of("minecraft:spotted");
Key SPOTTED = Key.key("minecraft:spotted");

DynamicRegistry.Key<WolfMeta.Variant> RUSTY = DynamicRegistry.Key.of("minecraft:rusty");
Key RUSTY = Key.key("minecraft:rusty");

DynamicRegistry.Key<WolfMeta.Variant> WOODS = DynamicRegistry.Key.of("minecraft:woods");
Key WOODS = Key.key("minecraft:woods");

DynamicRegistry.Key<WolfMeta.Variant> PALE = DynamicRegistry.Key.of("minecraft:pale");
Key PALE = Key.key("minecraft:pale");
}
Loading
Loading