Properly check if a loot table exists (#10190)

This commit is contained in:
Jake Potrebic 2024-01-27 11:21:18 -08:00
parent adf45d523a
commit cc0082f248

View file

@ -94,10 +94,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
- return new CraftLootTable(key, registry.getLootTable(CraftNamespacedKey.toMinecraft(key))); - return new CraftLootTable(key, registry.getLootTable(CraftNamespacedKey.toMinecraft(key)));
+ // Paper start - honor method contract + // Paper start - honor method contract
+ final ResourceLocation lootTableKey = CraftNamespacedKey.toMinecraft(key); + final ResourceLocation lootTableKey = CraftNamespacedKey.toMinecraft(key);
+ if (registry.getLootTable(lootTableKey) == net.minecraft.world.level.storage.loot.LootTable.EMPTY) { + final Optional<net.minecraft.world.level.storage.loot.LootTable> table = registry.getElementOptional(net.minecraft.world.level.storage.loot.LootDataType.TABLE, lootTableKey);
+ return null; + return table.map(lootTable -> new CraftLootTable(key, lootTable)).orElse(null);
+ }
+ return new CraftLootTable(key, registry.getLootTable(lootTableKey));
+ // Paper end + // Paper end
} }