From 5c09fa562b671c591890a53848157331dadac09c Mon Sep 17 00:00:00 2001 From: YufiriaMazenta <2199098065@qq.com> Date: Fri, 8 Dec 2023 18:32:55 +0800 Subject: [PATCH] =?UTF-8?q?[1.6.0-pre4]=E6=9B=B4=E6=94=B9=E7=89=A9?= =?UTF-8?q?=E5=93=81=E9=80=BB=E8=BE=91,=E4=BB=A5=E5=85=BC=E5=AE=B9?= =?UTF-8?q?=E9=9D=9Eminecraft=E5=91=BD=E5=90=8D=E7=A9=BA=E9=97=B4=E7=9A=84?= =?UTF-8?q?=E7=89=A9=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 2 +- .../craftorithm/item/ItemManager.java | 22 ++++++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index f61b40e8..240782f2 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,5 +1,5 @@ import java.text.SimpleDateFormat -version = "1.6.0-pre3" +version = "1.6.0-pre4" plugins { `java-library` diff --git a/src/main/java/com/github/yufiriamazenta/craftorithm/item/ItemManager.java b/src/main/java/com/github/yufiriamazenta/craftorithm/item/ItemManager.java index 054d1605..6338793b 100644 --- a/src/main/java/com/github/yufiriamazenta/craftorithm/item/ItemManager.java +++ b/src/main/java/com/github/yufiriamazenta/craftorithm/item/ItemManager.java @@ -45,10 +45,7 @@ public void regItemProvider(ItemProvider itemProvider) { } itemKey = itemKey.replace(" ", ""); if (!itemKey.contains(":")) { - Material material = Material.matchMaterial(itemKey); - if (material == null) - throw new IllegalArgumentException("Can not found item " + itemKey); - return new ItemStack(material, amountScale); + return matchVanillaItem(itemKey, amountScale); } int index = itemKey.indexOf(":"); @@ -57,7 +54,7 @@ public void regItemProvider(ItemProvider itemProvider) { ItemProvider provider = itemProviderMap.get(namespace); if (provider == null) { - throw new IllegalArgumentException("Can not found item provider: " + namespace); + return matchVanillaItem(itemKey, amountScale); } item = provider.getItem(name); @@ -84,7 +81,20 @@ public String matchItemName(ItemStack item, boolean ignoreAmount) { return itemProviderEntry.getKey() + ":" + tmpName; } - return null; + return item.getType().getKey().toString(); + } + + /** + * 获取原版物品 + * @param itemKey 物品名字 + * @param amount 物品数量 + * @return 物品 + */ + public ItemStack matchVanillaItem(String itemKey, int amount) { + Material material = Material.matchMaterial(itemKey); + if (material == null) + throw new IllegalArgumentException("Can not found item " + itemKey); + return new ItemStack(material, amount); } }