Skip to content
10 changes: 10 additions & 0 deletions src/main/java/ch/njol/skript/aliases/Aliases.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.jetbrains.annotations.Nullable;
import org.skriptlang.skript.lang.script.Script;

Expand Down Expand Up @@ -316,6 +317,15 @@ private static ItemType getAlias(final String rawInput) {
if (itemType != null)
return itemType.clone();

// Try to parse as Minecraft key `minecraft:some_item` or `some_item`
if ((input.contains(":") || input.contains("_")) && !input.contains(" ")) {
NamespacedKey namespacedKey = NamespacedKey.fromString(input);
if (namespacedKey != null) {
Material material = Registry.MATERIAL.get(namespacedKey);
if (material != null)
return new ItemType(material);
}
}
// try to parse `ACTUALNAME block` as ACTUALNAME
if (input.endsWith(" " + blockSingular) || input.endsWith(" " + blockPlural)) {
String stripped = input.substring(0, input.lastIndexOf(" "));
Expand Down
44 changes: 44 additions & 0 deletions src/test/skript/tests/regressions/7492-aliases-from-key.sk
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
aliases:
my_cool_custom_item = netherite axe

test "Aliases from Minecraft keys":

# Test as fully qualified NamespacedKey
set {_i} to 1 of minecraft:diamond_sword
assert {_i} = diamond sword with "Should have gotten a diamond sword"

# Test with just key
set {_i} to 1 of oak_stairs
assert {_i} = oak stairs with "Should have gotten oak stairs"

# Test that this doesn't break any other aliases
set {_i} to 1 of my_cool_custom_item
assert {_i} = netherite axe with "Should be a netherite axe"
set {_i} to 1 of potion of harming
assert {_i} = potion of harming with "Should be potion of harming"

# Test this works with enchantments (as per ItemType parsing)
set {_i} to minecraft:diamond_axe of unbreaking 3 and sharpness 10
assert {_i} is a diamond axe with "Should be a diamond axe"
assert enchantments of {_i} contains unbreaking 3 and sharpness 10 with "Should be enchanted"

# Test with amount (as per ItemType parsing)
set {_i} to 10 of minecraft:pink_wool
assert {_i} = 10 of pink wool with "Should be 10 of pink wool"

# Test with parsing
set {_i} to "minecraft:oak_door" parsed as itemtype
assert {_i} = oak door with "Should have parsed as oak door"

# Test that this doesn't conflict with BlockData
set {_data} to minecraft:oak_stairs[]
assert {_data} is set with "This should be set"

set {_loc} to event-location
set {_data} to block data of block at {_loc}
set block at {_loc} to oak_stairs[waterlogged=false]
assert block at {_loc} = oak_stairs[waterlogged=false] with "Should match blockdata"
assert block at {_loc} = oak stairs with "Should match itemtype"
assert block at {_loc} = minecraft:oak_stairs with "Should match MC key'd itemtype"

set block at {_loc} to {_data}