mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-06 23:22:10 -07:00
SPIGOT-1936: LootTable API
This commit is contained in:
22
src/test/java/org/bukkit/LootTablesTest.java
Normal file
22
src/test/java/org/bukkit/LootTablesTest.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package org.bukkit;
|
||||
|
||||
import org.bukkit.loot.LootTable;
|
||||
import org.bukkit.loot.LootTables;
|
||||
import org.bukkit.support.AbstractTestingBase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class LootTablesTest extends AbstractTestingBase {
|
||||
|
||||
@Test
|
||||
public void testLootTablesEnumExists() {
|
||||
LootTables[] tables = LootTables.values();
|
||||
|
||||
for (LootTables table : tables) {
|
||||
LootTable lootTable = Bukkit.getLootTable(table.getKey());
|
||||
|
||||
Assert.assertNotNull("Unknown LootTable " + table.getKey(), lootTable);
|
||||
Assert.assertEquals(lootTable.getKey(), table.getKey());
|
||||
}
|
||||
}
|
||||
}
|
@@ -5,6 +5,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import net.minecraft.server.DispenserRegistry;
|
||||
import net.minecraft.server.EnumResourcePackType;
|
||||
import net.minecraft.server.LootTableRegistry;
|
||||
import net.minecraft.server.ResourceManager;
|
||||
import net.minecraft.server.ResourcePackVanilla;
|
||||
import net.minecraft.server.TagRegistry;
|
||||
@@ -24,12 +25,16 @@ public abstract class AbstractTestingBase {
|
||||
// Materials that only exist in block form (or are legacy)
|
||||
public static final List<Material> INVALIDATED_MATERIALS;
|
||||
|
||||
public static final LootTableRegistry LOOT_TABLE_REGISTRY;
|
||||
public static final TagRegistry TAG_REGISTRY;
|
||||
|
||||
static {
|
||||
DispenserRegistry.c();
|
||||
// Set up resource manager
|
||||
ResourceManager resourceManager = new ResourceManager(EnumResourcePackType.SERVER_DATA);
|
||||
// add tags for unit tests
|
||||
resourceManager.a(new TagRegistry());
|
||||
// add tags and loot tables for unit tests
|
||||
resourceManager.a(TAG_REGISTRY = new TagRegistry());
|
||||
resourceManager.a(LOOT_TABLE_REGISTRY = new LootTableRegistry());
|
||||
// Register vanilla pack
|
||||
resourceManager.a(Collections.singletonList(new ResourcePackVanilla("minecraft")));
|
||||
|
||||
@@ -43,6 +48,6 @@ public abstract class AbstractTestingBase {
|
||||
}
|
||||
}
|
||||
INVALIDATED_MATERIALS = builder.build();
|
||||
Assert.assertTrue("Expected 543 invalidated materials (got " + INVALIDATED_MATERIALS.size() + ")", INVALIDATED_MATERIALS.size() == 543);
|
||||
Assert.assertEquals("Expected 543 invalidated materials (got " + INVALIDATED_MATERIALS.size() + ")", 543, INVALIDATED_MATERIALS.size());
|
||||
}
|
||||
}
|
||||
|
@@ -8,10 +8,13 @@ import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.craftbukkit.CraftLootTable;
|
||||
import org.bukkit.craftbukkit.block.data.CraftBlockData;
|
||||
import org.bukkit.craftbukkit.inventory.CraftItemFactory;
|
||||
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
import org.bukkit.craftbukkit.util.Versioning;
|
||||
|
||||
public class DummyServer implements InvocationHandler {
|
||||
@@ -79,6 +82,15 @@ public class DummyServer implements InvocationHandler {
|
||||
}
|
||||
}
|
||||
);
|
||||
methods.put(Server.class.getMethod("getLootTable", NamespacedKey.class),
|
||||
new MethodHandler() {
|
||||
@Override
|
||||
public Object handle(DummyServer server, Object[] args) {
|
||||
NamespacedKey key = (NamespacedKey) args[0];
|
||||
return new CraftLootTable(key, AbstractTestingBase.LOOT_TABLE_REGISTRY.a(CraftNamespacedKey.toMinecraft(key)));
|
||||
}
|
||||
}
|
||||
);
|
||||
Bukkit.setServer(Proxy.getProxyClass(Server.class.getClassLoader(), Server.class).asSubclass(Server.class).getConstructor(InvocationHandler.class).newInstance(new DummyServer()));
|
||||
} catch (Throwable t) {
|
||||
throw new Error(t);
|
||||
|
Reference in New Issue
Block a user