From 668f3d24c8e0a73ed92890d1306d066a253d5ab6 Mon Sep 17 00:00:00 2001 From: XiaoMoMi Date: Mon, 11 Aug 2025 02:01:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=96=84get=20item=E6=89=8B=E6=84=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bukkit/item/BukkitItemManager.java | 6 ++-- .../command/feature/GetItemCommand.java | 22 +++++++++---- .../command/feature/GiveItemCommand.java | 23 ++++++++----- .../default/configuration/blocks.yml | 31 ++++++++++++------ .../default/configuration/categories.yml | 2 +- .../resources/default/configuration/i18n.yml | 4 +-- .../textures/block/custom/chessboard.png | Bin 719 -> 0 bytes .../block/custom/chessboard_block.png | Bin 0 -> 446 bytes .../core/item/AbstractItemManager.java | 22 +++++++++---- .../craftengine/core/item/ItemManager.java | 2 ++ .../core/pack/AbstractPackManager.java | 1 + gradle.properties | 2 +- 12 files changed, 76 insertions(+), 39 deletions(-) delete mode 100644 common-files/src/main/resources/resources/default/resourcepack/assets/minecraft/textures/block/custom/chessboard.png create mode 100644 common-files/src/main/resources/resources/default/resourcepack/assets/minecraft/textures/block/custom/chessboard_block.png diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/BukkitItemManager.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/BukkitItemManager.java index 4d58dca43..39c1f336c 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/BukkitItemManager.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/BukkitItemManager.java @@ -335,7 +335,7 @@ public class BukkitItemManager extends AbstractItemManager { @Override public ItemStack buildCustomItemStack(Key id, Player player) { - return Optional.ofNullable(this.customItems.get(id)).map(it -> it.buildItemStack(new ItemBuildContext(player, ContextHolder.EMPTY), 1)).orElse(null); + return Optional.ofNullable(this.customItemsById.get(id)).map(it -> it.buildItemStack(new ItemBuildContext(player, ContextHolder.EMPTY), 1)).orElse(null); } @Override @@ -349,12 +349,12 @@ public class BukkitItemManager extends AbstractItemManager { @Override public Item createCustomWrappedItem(Key id, Player player) { - return Optional.ofNullable(customItems.get(id)).map(it -> it.buildItem(player)).orElse(null); + return Optional.ofNullable(customItemsById.get(id)).map(it -> it.buildItem(player)).orElse(null); } @Override public Item createWrappedItem(Key id, @Nullable Player player) { - CustomItem customItem = this.customItems.get(id); + CustomItem customItem = this.customItemsById.get(id); if (customItem != null) { return customItem.buildItem(player); } diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/GetItemCommand.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/GetItemCommand.java index 598167971..4005e7e5d 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/GetItemCommand.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/GetItemCommand.java @@ -1,8 +1,12 @@ package net.momirealms.craftengine.bukkit.plugin.command.feature; import net.kyori.adventure.text.Component; +import net.momirealms.craftengine.bukkit.api.CraftEngineItems; +import net.momirealms.craftengine.bukkit.item.BukkitItemManager; import net.momirealms.craftengine.bukkit.plugin.command.BukkitCommandFeature; +import net.momirealms.craftengine.bukkit.plugin.user.BukkitServerPlayer; import net.momirealms.craftengine.bukkit.util.PlayerUtils; +import net.momirealms.craftengine.core.item.CustomItem; import net.momirealms.craftengine.core.plugin.CraftEngine; import net.momirealms.craftengine.core.plugin.command.CraftEngineCommandManager; import net.momirealms.craftengine.core.plugin.command.FlagKeys; @@ -47,12 +51,18 @@ public class GetItemCommand extends BukkitCommandFeature { int amount = context.getOrDefault("amount", 1); boolean toInv = context.flags().hasFlag(FlagKeys.TO_INVENTORY); NamespacedKey namespacedKey = context.get("id"); - Key key = Key.of(namespacedKey.namespace(), namespacedKey.value()); - ItemStack builtItem = plugin().itemManager().buildCustomItemStack(key, plugin().adapt(context.sender())); - if (builtItem == null) { - handleFeedback(context, MessageConstants.COMMAND_ITEM_GET_FAILURE_NOT_EXIST, Component.text(key.toString())); - return; + Key itemId = Key.of(namespacedKey.namespace(), namespacedKey.value()); + CustomItem customItem = CraftEngineItems.byId(itemId); + if (customItem == null) { + customItem = BukkitItemManager.instance().getCustomItemByPathOnly(itemId.value()).orElse(null); + if (customItem == null) { + handleFeedback(context, MessageConstants.COMMAND_ITEM_GET_FAILURE_NOT_EXIST, Component.text(itemId.toString())); + return; + } else { + itemId = customItem.id(); + } } + ItemStack builtItem = customItem.buildItemStack(plugin().adapt(context.sender())); int amountToGive = amount; int maxStack = builtItem.getMaxStackSize(); while (amountToGive > 0) { @@ -66,7 +76,7 @@ public class GetItemCommand extends BukkitCommandFeature { PlayerUtils.dropItem(player, more, false, true, false); } } - handleFeedback(context, MessageConstants.COMMAND_ITEM_GET_SUCCESS, Component.text(amount), Component.text(key.toString())); + handleFeedback(context, MessageConstants.COMMAND_ITEM_GET_SUCCESS, Component.text(amount), Component.text(itemId.toString())); }); } diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/GiveItemCommand.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/GiveItemCommand.java index f258b70f4..430ee64be 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/GiveItemCommand.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/command/feature/GiveItemCommand.java @@ -1,6 +1,7 @@ package net.momirealms.craftengine.bukkit.plugin.command.feature; import net.kyori.adventure.text.Component; +import net.momirealms.craftengine.bukkit.api.CraftEngineItems; import net.momirealms.craftengine.bukkit.item.BukkitItemManager; import net.momirealms.craftengine.bukkit.plugin.command.BukkitCommandFeature; import net.momirealms.craftengine.bukkit.util.PlayerUtils; @@ -54,16 +55,20 @@ public class GiveItemCommand extends BukkitCommandFeature { int amount = context.getOrDefault("amount", 1); boolean toInv = context.flags().hasFlag(FlagKeys.TO_INVENTORY); NamespacedKey namespacedKey = context.get("id"); - Key key = Key.of(namespacedKey.namespace(), namespacedKey.value()); - Optional> optionalItem = BukkitItemManager.instance().getCustomItem(key); - if (optionalItem.isEmpty()) { - handleFeedback(context, MessageConstants.COMMAND_ITEM_GIVE_FAILURE_NOT_EXIST, Component.text(key.toString())); - return; + Key itemId = Key.of(namespacedKey.namespace(), namespacedKey.value()); + CustomItem customItem = CraftEngineItems.byId(itemId); + if (customItem == null) { + customItem = BukkitItemManager.instance().getCustomItemByPathOnly(itemId.value()).orElse(null); + if (customItem == null) { + handleFeedback(context, MessageConstants.COMMAND_ITEM_GIVE_FAILURE_NOT_EXIST, Component.text(itemId.toString())); + return; + } else { + itemId = customItem.id(); + } } - Collection players = selector.values(); for (Player player : players) { - ItemStack builtItem = optionalItem.get().buildItemStack(plugin().adapt(player)); + ItemStack builtItem = customItem.buildItemStack(plugin().adapt(player)); if (builtItem == null) { return; } @@ -90,9 +95,9 @@ public class GiveItemCommand extends BukkitCommandFeature { } } if (players.size() == 1) { - handleFeedback(context, MessageConstants.COMMAND_ITEM_GIVE_SUCCESS_SINGLE, Component.text(amount), Component.text(key.toString()), Component.text(players.iterator().next().getName())); + handleFeedback(context, MessageConstants.COMMAND_ITEM_GIVE_SUCCESS_SINGLE, Component.text(amount), Component.text(itemId.toString()), Component.text(players.iterator().next().getName())); } else if (players.size() > 1) { - handleFeedback(context, MessageConstants.COMMAND_ITEM_GIVE_SUCCESS_MULTIPLE, Component.text(amount), Component.text(key.toString()), Component.text(players.size())); + handleFeedback(context, MessageConstants.COMMAND_ITEM_GIVE_SUCCESS_MULTIPLE, Component.text(amount), Component.text(itemId.toString()), Component.text(players.size())); } }); } diff --git a/common-files/src/main/resources/resources/default/configuration/blocks.yml b/common-files/src/main/resources/resources/default/configuration/blocks.yml index 8df0578c9..530b5f9b9 100644 --- a/common-files/src/main/resources/resources/default/configuration/blocks.yml +++ b/common-files/src/main/resources/resources/default/configuration/blocks.yml @@ -364,16 +364,16 @@ items#misc: pebble=3: appearance: 'three' id: 4 - default:chessboard: + default:chessboard_block: material: nether_brick custom-model-data: 3006 data: - item-name: + item-name: model: type: minecraft:model - path: minecraft:item/custom/chessboard + path: minecraft:item/custom/chessboard_block generation: - parent: minecraft:block/custom/chessboard + parent: minecraft:block/custom/chessboard_block behavior: type: block_item block: @@ -402,25 +402,25 @@ items#misc: east: state: note_block:18 model: - path: minecraft:block/custom/chessboard + path: minecraft:block/custom/chessboard_block y: 270 generation: parent: minecraft:block/template_glazed_terracotta textures: - pattern: minecraft:block/custom/chessboard + pattern: minecraft:block/custom/chessboard_block north: state: note_block:19 model: - path: minecraft:block/custom/chessboard + path: minecraft:block/custom/chessboard_block y: 180 south: state: note_block:20 model: - path: minecraft:block/custom/chessboard + path: minecraft:block/custom/chessboard_block west: state: note_block:21 model: - path: minecraft:block/custom/chessboard + path: minecraft:block/custom/chessboard_block y: 90 variants: facing=east: @@ -506,4 +506,15 @@ recipes#misc: A: default:pebble result: id: minecraft:cobblestone - count: 1 \ No newline at end of file + count: 1 + default:chessboard_block: + type: shaped + pattern: + - AB + - BA + ingredients: + A: minecraft:white_terracotta + B: minecraft:black_terracotta + result: + id: default:chessboard_block + count: 4 \ No newline at end of file diff --git a/common-files/src/main/resources/resources/default/configuration/categories.yml b/common-files/src/main/resources/resources/default/configuration/categories.yml index 248c46162..79c4e3fa9 100644 --- a/common-files/src/main/resources/resources/default/configuration/categories.yml +++ b/common-files/src/main/resources/resources/default/configuration/categories.yml @@ -78,4 +78,4 @@ categories: - default:flame_elytra - default:cap - default:pebble - - default:chessboard \ No newline at end of file + - default:chessboard_block \ No newline at end of file diff --git a/common-files/src/main/resources/resources/default/configuration/i18n.yml b/common-files/src/main/resources/resources/default/configuration/i18n.yml index be1f59d04..a2cfc0ddc 100644 --- a/common-files/src/main/resources/resources/default/configuration/i18n.yml +++ b/common-files/src/main/resources/resources/default/configuration/i18n.yml @@ -45,7 +45,7 @@ i18n: item.pebble: Pebble item.cap: Cap item.flower_basket: Flower Basket - item.chessboard: Chessboard + item.chessboard_block: Chessboard Block category.default.name: Default Assets category.default.lore: Contains the default configuration of CraftEngine category.palm_tree: Palm Tree @@ -101,7 +101,7 @@ i18n: item.pebble: 石子 item.cap: 鸭舌帽 item.flower_basket: 花篮 - item.chessboard: 棋盘 + item.chessboard_block: 棋盘方块 category.default.name: 默认资产 category.default.lore: 包含了CraftEngine的默认配置 category.palm_tree: 棕榈树 diff --git a/common-files/src/main/resources/resources/default/resourcepack/assets/minecraft/textures/block/custom/chessboard.png b/common-files/src/main/resources/resources/default/resourcepack/assets/minecraft/textures/block/custom/chessboard.png deleted file mode 100644 index 97ebb52c9ddf530347479f0c3b1d68d5f0698007..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 719 zcmV;=0x1DAFRWC)$QmOf~k(M6mp#X+R_Tm&hO z7IacXm+Ds9TAHMVHc6Xzljc5-`Tme19=P1gJ^%S$|9@2W_gCF$G+?_PY}*D`C=@~_ zw~v*T6})=$PX1}FvaL}yq4PW z@o}is&o4Tc%ZWq+aFgHpVhPD)QWWg$>e~4;n#lCV45)+wc}@c(BO{2%O;NUR0?mIVAiz+bXLyopfB^a%g}002ovPDHLkV1ka2 BR9OH3 diff --git a/common-files/src/main/resources/resources/default/resourcepack/assets/minecraft/textures/block/custom/chessboard_block.png b/common-files/src/main/resources/resources/default/resourcepack/assets/minecraft/textures/block/custom/chessboard_block.png new file mode 100644 index 0000000000000000000000000000000000000000..b67b4bb2a47e8a1f29f80f298a077f94297d5884 GIT binary patch literal 446 zcmV;v0YUzWP)Px$cu7P-R5*=wlR>W2Pz*(n?H4|)V9F}kQa8qsA?$!<@CEv66e(&YlHb^7;G}7b z>Penr`}*GJ`{dWpAIX#Ghck!6;aQsFc%lIeZ@K&kOXZC?kj*+A};|Xc?tZ6YBOc=eKJ5Sh2Hi?kWTU0 zF%?V&-m7}?KuxPzHp=V_ik0B=0x3wR*S`R&N_b#qxZiRsrFH05SV@-oz9=HrfsU9W zc5S2e!ki(=6XEe+!8W;n zeWkq^=}{5_l4P2*ILCI&Pr_74FMnhtkqPVS6~N2@K}}Ir9yNI+Vp4wbI_Ju+d_dkw zkOzSFVr)!>-EbfU;E{Wiup4HLq7Q;p>I1N_OOVV}2ACM4jXNEZs0m_Ho_NpeJ89QF o`wF>z*XV~c(+vB|lDkLt4>5wzS5hggcK`qY07*qoM6N<$f_odq@Bjb+ literal 0 HcmV?d00001 diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/AbstractItemManager.java b/core/src/main/java/net/momirealms/craftengine/core/item/AbstractItemManager.java index 77d581dc1..8e8b9e043 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/AbstractItemManager.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/AbstractItemManager.java @@ -40,7 +40,8 @@ public abstract class AbstractItemManager extends AbstractModelGenerator impl private final ItemParser itemParser; private final EquipmentParser equipmentParser; protected final Map> externalItemSources = new HashMap<>(); - protected final Map> customItems = new HashMap<>(); + protected final Map> customItemsById = new HashMap<>(); + protected final Map> customItemsByPath = new HashMap<>(); protected final Map> customItemTags = new HashMap<>(); protected final Map> cmdConflictChecker = new HashMap<>(); protected final Map modernItemModels1_21_4 = new HashMap<>(); @@ -105,7 +106,8 @@ public abstract class AbstractItemManager extends AbstractModelGenerator impl @Override public void unload() { super.clearModelsToGenerate(); - this.customItems.clear(); + this.customItemsById.clear(); + this.customItemsByPath.clear(); this.cachedSuggestions.clear(); this.cachedTotemSuggestions.clear(); this.legacyOverrides.clear(); @@ -129,14 +131,20 @@ public abstract class AbstractItemManager extends AbstractModelGenerator impl @Override public Optional> getCustomItem(Key key) { - return Optional.ofNullable(this.customItems.get(key)); + return Optional.ofNullable(this.customItemsById.get(key)); + } + + @Override + public Optional> getCustomItemByPathOnly(String path) { + return Optional.ofNullable(this.customItemsByPath.get(path)); } @Override public boolean addCustomItem(CustomItem customItem) { Key id = customItem.id(); - if (this.customItems.containsKey(id)) return false; - this.customItems.put(id, customItem); + if (this.customItemsById.containsKey(id)) return false; + this.customItemsById.put(id, customItem); + this.customItemsByPath.put(id.value(), customItem); if (!customItem.isVanillaItem()) { // cache command suggestions this.cachedSuggestions.add(Suggestion.suggestion(id.toString())); @@ -199,7 +207,7 @@ public abstract class AbstractItemManager extends AbstractModelGenerator impl @Override public Collection items() { - return Collections.unmodifiableCollection(this.customItems.keySet()); + return Collections.unmodifiableCollection(this.customItemsById.keySet()); } @Override @@ -302,7 +310,7 @@ public abstract class AbstractItemManager extends AbstractModelGenerator impl @Override public void parseSection(Pack pack, Path path, Key id, Map section) { - if (AbstractItemManager.this.customItems.containsKey(id)) { + if (AbstractItemManager.this.customItemsById.containsKey(id)) { throw new LocalizedResourceConfigException("warning.config.item.duplicate"); } diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/ItemManager.java b/core/src/main/java/net/momirealms/craftengine/core/item/ItemManager.java index e1c18038d..9be0dfb7f 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/ItemManager.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/ItemManager.java @@ -76,6 +76,8 @@ public interface ItemManager extends Manageable, ModelGenerator { return getVanillaItem(key); } + Optional> getCustomItemByPathOnly(String path); + boolean addCustomItem(CustomItem customItem); default List itemIdsByTag(Key tag) { diff --git a/core/src/main/java/net/momirealms/craftengine/core/pack/AbstractPackManager.java b/core/src/main/java/net/momirealms/craftengine/core/pack/AbstractPackManager.java index 478d3e5bd..714cc2f60 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/pack/AbstractPackManager.java +++ b/core/src/main/java/net/momirealms/craftengine/core/pack/AbstractPackManager.java @@ -415,6 +415,7 @@ public abstract class AbstractPackManager implements PackManager { plugin.saveResource("resources/default/resourcepack/assets/minecraft/textures/block/custom/copper_coil_side.png"); plugin.saveResource("resources/default/resourcepack/assets/minecraft/textures/block/custom/copper_coil_on.png"); plugin.saveResource("resources/default/resourcepack/assets/minecraft/textures/block/custom/copper_coil_on_side.png"); + plugin.saveResource("resources/default/resourcepack/assets/minecraft/textures/block/custom/chessboard_block.png"); // items plugin.saveResource("resources/default/configuration/items.yml"); plugin.saveResource("resources/default/resourcepack/assets/minecraft/textures/item/custom/topaz_rod.png"); diff --git a/gradle.properties b/gradle.properties index 1cf25188b..199f62c5e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,7 +2,7 @@ org.gradle.jvmargs=-Xmx1G # Project settings # Rule: [major update].[feature update].[bug fix] -project_version=0.0.61.3 +project_version=0.0.61.4 config_version=43 lang_version=23 project_group=net.momirealms