diff --git a/src/autogenerated/java/net/minestom/server/registry/Registries.java b/src/autogenerated/java/net/minestom/server/registry/Registries.java index 30522f212..90614d763 100644 --- a/src/autogenerated/java/net/minestom/server/registry/Registries.java +++ b/src/autogenerated/java/net/minestom/server/registry/Registries.java @@ -4,9 +4,7 @@ package net.minestom.server.registry; import net.kyori.adventure.key.Key; import net.minestom.server.entity.EntityType; import net.minestom.server.fluid.Fluid; -import net.minestom.server.instance.block.Block; import net.minestom.server.item.Enchantment; -import net.minestom.server.item.Material; import net.minestom.server.particle.Particle; import net.minestom.server.potion.PotionEffect; import net.minestom.server.potion.PotionType; @@ -17,23 +15,11 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.HashMap; -import java.util.Objects; /** * AUTOGENERATED */ public final class Registries { - /** - * Should only be used for internal code, please use the get* methods. - */ - @Deprecated - public static final HashMap blocks = new HashMap<>(); - - /** - * Should only be used for internal code, please use the get* methods. - */ - @Deprecated - public static final HashMap materials = new HashMap<>(); /** * Should only be used for internal code, please use the get* methods. @@ -83,54 +69,6 @@ public final class Registries { @Deprecated public static final HashMap fluids = new HashMap<>(); - /** - * Returns the corresponding Block matching the given id. Returns 'AIR' if none match. - */ - @Deprecated - public static @NotNull Block getBlock(String id) { - return Objects.requireNonNullElse(Block.fromNamespaceId(id), Block.AIR); - } - - /** - * Returns the corresponding Block matching the given id. Returns 'AIR' if none match. - */ - @Deprecated - public static @NotNull Block getBlock(NamespaceID id) { - return Objects.requireNonNullElse(Block.fromNamespaceId(id), Block.AIR); - } - - /** - * Returns the corresponding Block matching the given key. Returns 'AIR' if none match. - */ - @NotNull - public static Block getBlock(Key key) { - return getBlock(NamespaceID.from(key)); - } - - /** - * Returns the corresponding Material matching the given id. Returns 'AIR' if none match. - */ - @NotNull - public static Material getMaterial(String id) { - return getMaterial(NamespaceID.from(id)); - } - - /** - * Returns the corresponding Material matching the given id. Returns 'AIR' if none match. - */ - @NotNull - public static Material getMaterial(NamespaceID id) { - return materials.getOrDefault(id, Material.AIR); - } - - /** - * Returns the corresponding Material matching the given key. Returns 'AIR' if none match. - */ - @NotNull - public static Material getMaterial(Key key) { - return getMaterial(NamespaceID.from(key)); - } - /** * Returns the corresponding Enchantment matching the given id. Returns null if none match. */ diff --git a/src/main/java/net/minestom/server/command/builder/arguments/minecraft/ArgumentItemStack.java b/src/main/java/net/minestom/server/command/builder/arguments/minecraft/ArgumentItemStack.java index 594526e43..905113fcb 100644 --- a/src/main/java/net/minestom/server/command/builder/arguments/minecraft/ArgumentItemStack.java +++ b/src/main/java/net/minestom/server/command/builder/arguments/minecraft/ArgumentItemStack.java @@ -6,7 +6,6 @@ import net.minestom.server.command.builder.exception.ArgumentSyntaxException; import net.minestom.server.item.ItemStack; import net.minestom.server.item.Material; import net.minestom.server.network.packet.server.play.DeclareCommandsPacket; -import net.minestom.server.registry.Registries; import org.jetbrains.annotations.NotNull; import org.jglrxavpok.hephaistos.nbt.NBTCompound; import org.jglrxavpok.hephaistos.nbt.NBTException; @@ -56,12 +55,12 @@ public class ArgumentItemStack extends Argument { if (nbtIndex == -1) { // Only material name - final Material material = Registries.getMaterial(input); + final Material material = Material.fromNamespaceId(input); return ItemStack.of(material); } else { // Material plus additional NBT final String materialName = input.substring(0, nbtIndex); - final Material material = Registries.getMaterial(materialName); + final Material material = Material.fromNamespaceId(materialName); final String sNBT = input.substring(nbtIndex).replace("\\\"", "\""); diff --git a/src/main/java/net/minestom/server/gamedata/loottables/entries/ItemType.java b/src/main/java/net/minestom/server/gamedata/loottables/entries/ItemType.java index bd46cef22..dc3fc8be7 100644 --- a/src/main/java/net/minestom/server/gamedata/loottables/entries/ItemType.java +++ b/src/main/java/net/minestom/server/gamedata/loottables/entries/ItemType.java @@ -5,7 +5,7 @@ import net.minestom.server.gamedata.loottables.LootTable; import net.minestom.server.gamedata.loottables.LootTableEntryType; import net.minestom.server.gamedata.loottables.LootTableFunction; import net.minestom.server.gamedata.loottables.LootTableManager; -import net.minestom.server.registry.Registries; +import net.minestom.server.item.Material; import net.minestom.server.utils.NamespaceID; import java.util.List; @@ -17,6 +17,6 @@ public class ItemType implements LootTableEntryType { @Override public LootTable.Entry create(LootTableManager lootTableManager, String name, List conditions, List children, boolean expand, List functions, int weight, int quality) { NamespaceID itemID = NamespaceID.from(name); - return new ItemEntry(this, Registries.getMaterial(itemID), weight, quality, functions, conditions); + return new ItemEntry(this, Material.fromNamespaceId(itemID), weight, quality, functions, conditions); } } diff --git a/src/main/java/net/minestom/server/gamedata/loottables/entries/TagEntry.java b/src/main/java/net/minestom/server/gamedata/loottables/entries/TagEntry.java index 9dfa7a3ea..c01eb7284 100644 --- a/src/main/java/net/minestom/server/gamedata/loottables/entries/TagEntry.java +++ b/src/main/java/net/minestom/server/gamedata/loottables/entries/TagEntry.java @@ -6,7 +6,6 @@ import net.minestom.server.gamedata.loottables.LootTable; import net.minestom.server.gamedata.tags.Tag; import net.minestom.server.item.ItemStack; import net.minestom.server.item.Material; -import net.minestom.server.registry.Registries; import net.minestom.server.utils.NamespaceID; import java.util.List; @@ -32,7 +31,7 @@ public class TagEntry extends LootTable.Entry { Material[] asArrayOfItems = new Material[values.size()]; int ptr = 0; for (NamespaceID id : values) { - asArrayOfItems[ptr++] = Registries.getMaterial(id); + asArrayOfItems[ptr++] = Material.fromNamespaceId(id); } if (expand) { Material selectedMaterial = asArrayOfItems[rng.nextInt(asArrayOfItems.length)]; diff --git a/src/main/java/net/minestom/server/item/metadata/CrossbowMeta.java b/src/main/java/net/minestom/server/item/metadata/CrossbowMeta.java index 5835430ae..6cadf1c58 100644 --- a/src/main/java/net/minestom/server/item/metadata/CrossbowMeta.java +++ b/src/main/java/net/minestom/server/item/metadata/CrossbowMeta.java @@ -4,7 +4,6 @@ import net.minestom.server.item.ItemMeta; import net.minestom.server.item.ItemMetaBuilder; import net.minestom.server.item.ItemStack; import net.minestom.server.item.Material; -import net.minestom.server.registry.Registries; import net.minestom.server.utils.validate.Check; import org.jetbrains.annotations.NotNull; import org.jglrxavpok.hephaistos.nbt.NBTCompound; @@ -152,7 +151,7 @@ public class CrossbowMeta extends ItemMeta implements ItemMetaBuilder.Provider Registries.getMaterial(materialNamespace) : () -> null; + this.materialSupplier = materialNamespace != null ? () -> Material.fromNamespaceId(materialNamespace) : () -> null; } } diff --git a/src/main/java/net/minestom/server/utils/NBTUtils.java b/src/main/java/net/minestom/server/utils/NBTUtils.java index 4d6be1624..7d3a9f068 100644 --- a/src/main/java/net/minestom/server/utils/NBTUtils.java +++ b/src/main/java/net/minestom/server/utils/NBTUtils.java @@ -26,7 +26,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; -import java.io.StringReader; import java.util.*; // for lack of a better name @@ -69,7 +68,7 @@ public final class NBTUtils { public static void loadAllItems(@NotNull NBTList items, @NotNull Inventory destination) { destination.clear(); for (NBTCompound tag : items) { - Material material = Registries.getMaterial(tag.getString("id")); + Material material = Material.fromNamespaceId(tag.getString("id")); if (material == Material.AIR) { material = Material.STONE; } diff --git a/src/test/java/demo/block/CampfireHandler.java b/src/test/java/demo/block/CampfireHandler.java index 67af009ea..aaca3a9f1 100644 --- a/src/test/java/demo/block/CampfireHandler.java +++ b/src/test/java/demo/block/CampfireHandler.java @@ -3,7 +3,6 @@ package demo.block; import net.minestom.server.instance.block.BlockHandler; import net.minestom.server.item.ItemStack; import net.minestom.server.item.Material; -import net.minestom.server.registry.Registries; import net.minestom.server.tag.Tag; import net.minestom.server.tag.TagReadable; import net.minestom.server.tag.TagSerializer; @@ -33,7 +32,7 @@ public class CampfireHandler implements BlockHandler { item.forEach(nbtCompound -> { int amount = nbtCompound.getAsByte("Count"); String id = nbtCompound.getString("id"); - Material material = Registries.getMaterial(id); + Material material = Material.fromNamespaceId(id); result.add(ItemStack.of(material, amount)); }); return result;