Skip to content

Commit

Permalink
[1.6.0-pre4]更改物品逻辑,以兼容非minecraft命名空间的物品
Browse files Browse the repository at this point in the history
  • Loading branch information
YufiriaMazenta committed Dec 8, 2023
1 parent fae6b55 commit 5c09fa5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import java.text.SimpleDateFormat
version = "1.6.0-pre3"
version = "1.6.0-pre4"

plugins {
`java-library`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(":");
Expand All @@ -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);
Expand All @@ -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);
}

}

0 comments on commit 5c09fa5

Please sign in to comment.