From c90fad69f1a21a36b8835fe7eba041dbcd79ec12 Mon Sep 17 00:00:00 2001 From: XiaoMoMi Date: Sat, 27 Dec 2025 23:21:52 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E6=96=B9=E5=9D=97=E5=AE=9E?= =?UTF-8?q?=E4=BD=93=E6=98=BE=E7=A4=BA=E6=B3=A8=E5=86=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BukkitBlockEntityElementConfigs.java | 15 ++++---- .../render/ConstantBlockEntityRenderer.java | 2 +- .../element/BlockEntityElementConfigType.java | 6 +++ .../element/BlockEntityElementConfigs.java | 37 ++++++++++--------- .../item/processor/ItemModelProcessor.java | 3 +- .../core/registry/BuiltInRegistries.java | 3 +- .../craftengine/core/registry/Registries.java | 3 +- .../momirealms/craftengine/core/util/Key.java | 11 ++++-- 8 files changed, 47 insertions(+), 33 deletions(-) create mode 100644 core/src/main/java/net/momirealms/craftengine/core/block/entity/render/element/BlockEntityElementConfigType.java diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/entity/renderer/element/BukkitBlockEntityElementConfigs.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/entity/renderer/element/BukkitBlockEntityElementConfigs.java index 7d7ad348a..aef524967 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/entity/renderer/element/BukkitBlockEntityElementConfigs.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/entity/renderer/element/BukkitBlockEntityElementConfigs.java @@ -1,15 +1,14 @@ package net.momirealms.craftengine.bukkit.block.entity.renderer.element; +import net.momirealms.craftengine.core.block.entity.render.element.BlockEntityElementConfigType; import net.momirealms.craftengine.core.block.entity.render.element.BlockEntityElementConfigs; +import net.momirealms.craftengine.core.util.Key; -public class BukkitBlockEntityElementConfigs extends BlockEntityElementConfigs { - - static { - register(ITEM_DISPLAY, ItemDisplayBlockEntityElementConfig.FACTORY); - register(TEXT_DISPLAY, TextDisplayBlockEntityElementConfig.FACTORY); - register(ITEM, ItemBlockEntityElementConfig.FACTORY); - register(ARMOR_STAND, ArmorStandBlockEntityElementConfig.FACTORY); - } +public final class BukkitBlockEntityElementConfigs extends BlockEntityElementConfigs { + public static final BlockEntityElementConfigType ITEM_DISPLAY = register(Key.ce("item_display"), ItemDisplayBlockEntityElementConfig.FACTORY); + public static final BlockEntityElementConfigType TEXT_DISPLAY = register(Key.ce("text_display"), TextDisplayBlockEntityElementConfig.FACTORY); + public static final BlockEntityElementConfigType ITEM = register(Key.ce("item"), ItemBlockEntityElementConfig.FACTORY); + public static final BlockEntityElementConfigType ARMOR_STAND = register(Key.ce("armor_stand"), ArmorStandBlockEntityElementConfig.FACTORY); private BukkitBlockEntityElementConfigs() {} diff --git a/core/src/main/java/net/momirealms/craftengine/core/block/entity/render/ConstantBlockEntityRenderer.java b/core/src/main/java/net/momirealms/craftengine/core/block/entity/render/ConstantBlockEntityRenderer.java index 2c0ad0c4c..0e19ba0a6 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/block/entity/render/ConstantBlockEntityRenderer.java +++ b/core/src/main/java/net/momirealms/craftengine/core/block/entity/render/ConstantBlockEntityRenderer.java @@ -6,7 +6,7 @@ import net.momirealms.craftengine.core.entity.player.Player; import net.momirealms.craftengine.core.plugin.entityculling.CullingData; import org.jetbrains.annotations.Nullable; -public class ConstantBlockEntityRenderer implements Cullable { +public final class ConstantBlockEntityRenderer implements Cullable { private final BlockEntityElement[] elements; public final CullingData cullingData; diff --git a/core/src/main/java/net/momirealms/craftengine/core/block/entity/render/element/BlockEntityElementConfigType.java b/core/src/main/java/net/momirealms/craftengine/core/block/entity/render/element/BlockEntityElementConfigType.java new file mode 100644 index 000000000..a0ee38dc1 --- /dev/null +++ b/core/src/main/java/net/momirealms/craftengine/core/block/entity/render/element/BlockEntityElementConfigType.java @@ -0,0 +1,6 @@ +package net.momirealms.craftengine.core.block.entity.render.element; + +import net.momirealms.craftengine.core.util.Key; + +public record BlockEntityElementConfigType(Key id, BlockEntityElementConfigFactory factory) { +} diff --git a/core/src/main/java/net/momirealms/craftengine/core/block/entity/render/element/BlockEntityElementConfigs.java b/core/src/main/java/net/momirealms/craftengine/core/block/entity/render/element/BlockEntityElementConfigs.java index 380ece537..11527d4ca 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/block/entity/render/element/BlockEntityElementConfigs.java +++ b/core/src/main/java/net/momirealms/craftengine/core/block/entity/render/element/BlockEntityElementConfigs.java @@ -11,30 +11,33 @@ import java.util.Map; import java.util.Optional; public abstract class BlockEntityElementConfigs { - public static final Key ITEM_DISPLAY = Key.of("craftengine:item_display"); - public static final Key TEXT_DISPLAY = Key.of("craftengine:text_display"); - public static final Key ITEM = Key.of("craftengine:item"); - public static final Key ARMOR_STAND = Key.of("craftengine:armor_stand"); - public static void register(Key key, BlockEntityElementConfigFactory type) { - ((WritableRegistry>) BuiltInRegistries.BLOCK_ENTITY_ELEMENT_TYPE) + protected BlockEntityElementConfigs() {} + + public static BlockEntityElementConfigType register(Key key, BlockEntityElementConfigFactory factory) { + BlockEntityElementConfigType type = new BlockEntityElementConfigType<>(key, factory); + ((WritableRegistry>) BuiltInRegistries.BLOCK_ENTITY_ELEMENT_TYPE) .register(ResourceKey.create(Registries.BLOCK_ENTITY_ELEMENT_TYPE.location(), key), type); + return type; } public static BlockEntityElementConfig fromMap(Map arguments) { - Key type = Optional.ofNullable(arguments.get("type")).map(String::valueOf).map(it -> Key.withDefaultNamespace(it, "craftengine")).orElse(null); - if (type == null) { - if (arguments.containsKey("text")) { - type = TEXT_DISPLAY; - } else { - type = ITEM_DISPLAY; - } - } + Key type = guessType(arguments); @SuppressWarnings("unchecked") - BlockEntityElementConfigFactory factory = (BlockEntityElementConfigFactory) BuiltInRegistries.BLOCK_ENTITY_ELEMENT_TYPE.getValue(type); - if (factory == null) { + BlockEntityElementConfigType configType = (BlockEntityElementConfigType) BuiltInRegistries.BLOCK_ENTITY_ELEMENT_TYPE.getValue(type); + if (configType == null) { throw new LocalizedResourceConfigException("warning.config.block.state.entity_renderer.invalid_type", type.toString()); } - return factory.create(arguments); + return configType.factory().create(arguments); + } + + private static Key guessType(Map arguments) { + return Key.ce(Optional.ofNullable(arguments.get("type")).map(String::valueOf).orElseGet(() -> { + if (arguments.containsKey("text")) { + return "text_display"; + } else { + return "item_display"; + } + })); } } diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/processor/ItemModelProcessor.java b/core/src/main/java/net/momirealms/craftengine/core/item/processor/ItemModelProcessor.java index bb35287bd..3bbaa026b 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/processor/ItemModelProcessor.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/processor/ItemModelProcessor.java @@ -18,12 +18,11 @@ public class ItemModelProcessor implements SimpleNetworkItemProcessor { } public Key data() { - return data; + return this.data; } @Override public Item apply(Item item, ItemBuildContext context) { - if (!VersionHelper.isOrAbove1_21_2()) return item; return item.itemModel(this.data.asString()); } diff --git a/core/src/main/java/net/momirealms/craftengine/core/registry/BuiltInRegistries.java b/core/src/main/java/net/momirealms/craftengine/core/registry/BuiltInRegistries.java index 3cb656687..67b263860 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/registry/BuiltInRegistries.java +++ b/core/src/main/java/net/momirealms/craftengine/core/registry/BuiltInRegistries.java @@ -4,6 +4,7 @@ import net.momirealms.craftengine.core.block.CustomBlock; import net.momirealms.craftengine.core.block.behavior.BlockBehaviorType; import net.momirealms.craftengine.core.block.entity.BlockEntityType; import net.momirealms.craftengine.core.block.entity.render.element.BlockEntityElementConfigFactory; +import net.momirealms.craftengine.core.block.entity.render.element.BlockEntityElementConfigType; import net.momirealms.craftengine.core.block.properties.PropertyType; import net.momirealms.craftengine.core.entity.furniture.behavior.FurnitureBehaviorType; import net.momirealms.craftengine.core.entity.furniture.element.FurnitureElementConfigFactory; @@ -76,7 +77,7 @@ public final class BuiltInRegistries { public static final Registry> ITEM_UPDATER_TYPE = createConstantBoundRegistry(Registries.ITEM_UPDATER_TYPE, 16); public static final Registry> MOD_PACKET = createConstantBoundRegistry(Registries.MOD_PACKET, 16); public static final Registry> BLOCK_ENTITY_TYPE = createConstantBoundRegistry(Registries.BLOCK_ENTITY_TYPE, 64); - public static final Registry> BLOCK_ENTITY_ELEMENT_TYPE = createConstantBoundRegistry(Registries.BLOCK_ENTITY_ELEMENT_TYPE, 16); + public static final Registry> BLOCK_ENTITY_ELEMENT_TYPE = createConstantBoundRegistry(Registries.BLOCK_ENTITY_ELEMENT_TYPE, 16); public static final Registry> CRAFT_REMAINDER_FACTORY = createConstantBoundRegistry(Registries.CRAFT_REMAINDER_FACTORY, 16); public static final Registry> FURNITURE_ELEMENT_TYPE = createConstantBoundRegistry(Registries.FURNITURE_ELEMENT_TYPE, 16); public static final Registry> FURNITURE_HITBOX_TYPE = createConstantBoundRegistry(Registries.FURNITURE_HITBOX_TYPE, 16); diff --git a/core/src/main/java/net/momirealms/craftengine/core/registry/Registries.java b/core/src/main/java/net/momirealms/craftengine/core/registry/Registries.java index 100f732b4..414adc24d 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/registry/Registries.java +++ b/core/src/main/java/net/momirealms/craftengine/core/registry/Registries.java @@ -4,6 +4,7 @@ import net.momirealms.craftengine.core.block.CustomBlock; import net.momirealms.craftengine.core.block.behavior.BlockBehaviorType; import net.momirealms.craftengine.core.block.entity.BlockEntityType; import net.momirealms.craftengine.core.block.entity.render.element.BlockEntityElementConfigFactory; +import net.momirealms.craftengine.core.block.entity.render.element.BlockEntityElementConfigType; import net.momirealms.craftengine.core.block.properties.PropertyType; import net.momirealms.craftengine.core.entity.furniture.behavior.FurnitureBehaviorType; import net.momirealms.craftengine.core.entity.furniture.element.FurnitureElementConfigFactory; @@ -80,7 +81,7 @@ public final class Registries { public static final ResourceKey>> ITEM_UPDATER_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("item_updater_type")); public static final ResourceKey>> MOD_PACKET = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("mod_packet_type")); public static final ResourceKey>> BLOCK_ENTITY_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("block_entity_type")); - public static final ResourceKey>> BLOCK_ENTITY_ELEMENT_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("block_entity_element_type")); + public static final ResourceKey>> BLOCK_ENTITY_ELEMENT_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("block_entity_element_type")); public static final ResourceKey>> CRAFT_REMAINDER_FACTORY = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("craft_remainder_factory")); public static final ResourceKey>> FURNITURE_ELEMENT_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("furniture_element_type")); public static final ResourceKey>> FURNITURE_HITBOX_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("furniture_hitbox_type")); diff --git a/core/src/main/java/net/momirealms/craftengine/core/util/Key.java b/core/src/main/java/net/momirealms/craftengine/core/util/Key.java index f580210ac..e6c980ab4 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/util/Key.java +++ b/core/src/main/java/net/momirealms/craftengine/core/util/Key.java @@ -4,6 +4,7 @@ import org.jetbrains.annotations.NotNull; public record Key(String namespace, String value) { public static final String DEFAULT_NAMESPACE = "craftengine"; + public static final String MINECRAFT_NAMESPACE = "minecraft"; public static Key withDefaultNamespace(String value) { return new Key(DEFAULT_NAMESPACE, value); @@ -22,11 +23,15 @@ public record Key(String namespace, String value) { } public static Key of(String namespacedId) { - return of(decompose(namespacedId, "minecraft")); + return of(decompose(namespacedId, MINECRAFT_NAMESPACE)); + } + + public static Key ce(String namespacedId) { + return of(decompose(namespacedId, DEFAULT_NAMESPACE)); } public static Key from(String namespacedId) { - return of(decompose(namespacedId, "minecraft")); + return of(decompose(namespacedId, MINECRAFT_NAMESPACE)); } public static Key fromNamespaceAndPath(String namespace, String path) { @@ -65,7 +70,7 @@ public record Key(String namespace, String value) { } public String asMinimalString() { - if (this.namespace.equals("minecraft")) { + if (this.namespace.equals(MINECRAFT_NAMESPACE)) { return this.value; } return asString();