Make meta filter more strict, move custom -> custom_data to match NBT

This commit is contained in:
fullwall 2024-09-09 01:26:27 +08:00
parent 1ab4bfe177
commit a87756616d
3 changed files with 9 additions and 4 deletions

View File

@ -161,6 +161,7 @@ public class ItemAction extends NPCShopAction {
private boolean metaMatches(ItemStack needle, ItemStack haystack, List<String> meta) {
Map<String, Object> source = NMS.getComponentMap(needle);
Map<String, Object> compare = NMS.getComponentMap(haystack);
System.out.println(source + " " + compare);
for (String nbt : meta) {
String[] parts = nbt.split("\\.");
Object acc = source;
@ -168,10 +169,14 @@ public class ItemAction extends NPCShopAction {
for (int i = 0; i < parts.length; i++) {
if (acc == null || cmp == null)
return false;
if (i < parts.length - 1 && !(acc instanceof Map))
return false;
if (i < parts.length - 1 && !(cmp instanceof Map))
return false;
Map<String, Object> nextAcc = (Map<String, Object>) acc;
Map<String, Object> nextCmp = (Map<String, Object>) cmp;
if (!nextAcc.containsKey(parts[i]) && !nextCmp.containsKey(parts[i]))
continue;
if (!nextAcc.containsKey(parts[i]) || !nextCmp.containsKey(parts[i]))
return false;
acc = nextAcc.get(parts[i]);
cmp = nextCmp.get(parts[i]);
if (i == parts.length - 1 && !acc.equals(cmp))

View File

@ -655,7 +655,7 @@ public class NMSImpl implements NMSBridge {
for (String key : ct.getAllKeys()) {
custom.put(key, deserialiseNBT(ct.get(key)));
}
base.put("custom", custom);
base.put("custom_data", custom);
return base;
}

View File

@ -635,7 +635,7 @@ public class NMSImpl implements NMSBridge {
for (String key : ct.getAllKeys()) {
custom.put(key, deserialiseNBT(ct.get(key)));
}
base.put("custom", custom);
base.put("custom_data", custom);
return base;
}