3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-22 14:28:09 +01:00
Paper/src/test/java/org/bukkit/PerMaterialTest.java

202 Zeilen
6.8 KiB
Java

2012-12-09 22:13:38 +01:00
package org.bukkit;
import static org.junit.Assert.*;
import static org.hamcrest.Matchers.*;
import java.util.List;
2013-11-04 14:07:38 +01:00
import net.minecraft.server.BlockFalling;
import net.minecraft.server.BlockFire;
import net.minecraft.server.Item;
import net.minecraft.server.ItemFood;
import net.minecraft.server.ItemRecord;
import net.minecraft.server.TileEntityFurnace;
2012-12-09 22:13:38 +01:00
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.inventory.ItemStack;
import org.bukkit.support.AbstractTestingBase;
import org.bukkit.support.Util;
import org.junit.BeforeClass;
2012-12-09 22:13:38 +01:00
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
import com.google.common.collect.Lists;
import java.util.Map;
import net.minecraft.server.Block;
2013-11-04 14:07:38 +01:00
import net.minecraft.server.Blocks;
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
import org.bukkit.enchantments.EnchantmentTarget;
2012-12-09 22:13:38 +01:00
@RunWith(Parameterized.class)
public class PerMaterialTest extends AbstractTestingBase {
private static Map<Block, Integer> fireValues;
@BeforeClass
public static void getFireValues() {
2015-05-05 22:43:47 +02:00
fireValues = Util.getInternalState(BlockFire.class, Blocks.FIRE, "flameChances");
2012-12-09 22:13:38 +01:00
}
@Parameters(name= "{index}: {0}")
public static List<Object[]> data() {
List<Object[]> list = Lists.newArrayList();
2012-12-09 22:13:38 +01:00
for (Material material : Material.values()) {
2018-07-15 02:00:00 +02:00
if (!material.isLegacy()) {
list.add(new Object[] {material});
}
2012-12-09 22:13:38 +01:00
}
return list;
}
@Parameter public Material material;
2018-07-15 02:00:00 +02:00
@Test
public void isBlock() {
if (material != Material.AIR && material != Material.CAVE_AIR && material != Material.VOID_AIR) {
assertThat(material.isBlock(), is(not(CraftMagicNumbers.getBlock(material).getBlockData().isAir())));
}
}
2012-12-09 22:13:38 +01:00
@Test
public void isSolid() {
if (material == Material.AIR) {
assertFalse(material.isSolid());
} else if (material.isBlock()) {
2016-02-29 22:32:46 +01:00
assertThat(material.isSolid(), is(CraftMagicNumbers.getBlock(material).getBlockData().getMaterial().isSolid()));
2012-12-09 22:13:38 +01:00
} else {
assertFalse(material.isSolid());
}
}
@Test
public void isEdible() {
2013-11-04 14:07:38 +01:00
assertThat(material.isEdible(), is(CraftMagicNumbers.getItem(material) instanceof ItemFood));
}
@Test
public void isRecord() {
2013-11-04 14:07:38 +01:00
assertThat(material.isRecord(), is(CraftMagicNumbers.getItem(material) instanceof ItemRecord));
}
@Test
public void maxDurability() {
if (INVALIDATED_MATERIALS.contains(material)) return;
if (material == Material.AIR) {
assertThat((int) material.getMaxDurability(), is(0));
2013-11-04 14:07:38 +01:00
} else if (material.isBlock()){
Item item = CraftMagicNumbers.getItem(material);
assertThat((int) material.getMaxDurability(), is(item.getMaxDurability()));
}
}
@Test
public void maxStackSize() {
if (INVALIDATED_MATERIALS.contains(material)) return;
final ItemStack bukkit = new ItemStack(material);
final CraftItemStack craft = CraftItemStack.asCraftCopy(bukkit);
if (material == Material.AIR) {
final int MAX_AIR_STACK = 0 /* Why can't I hold all of these AIR? */;
assertThat(material.getMaxStackSize(), is(MAX_AIR_STACK));
assertThat(bukkit.getMaxStackSize(), is(MAX_AIR_STACK));
assertThat(craft.getMaxStackSize(), is(MAX_AIR_STACK));
} else {
2013-11-04 14:07:38 +01:00
assertThat(material.getMaxStackSize(), is(CraftMagicNumbers.getItem(material).getMaxStackSize()));
assertThat(bukkit.getMaxStackSize(), is(material.getMaxStackSize()));
assertThat(craft.getMaxStackSize(), is(material.getMaxStackSize()));
}
}
@Test
public void isTransparent() {
if (material == Material.AIR) {
assertTrue(material.isTransparent());
} else if (material.isBlock()) {
2018-07-15 02:00:00 +02:00
// assertThat(material.isTransparent(), is(not(CraftMagicNumbers.getBlock(material).getBlockData().getMaterial().blocksLight()))); // PAIL: not unit testable anymore (17w50a)
} else {
assertFalse(material.isTransparent());
}
}
@Test
public void isFlammable() {
if (material != Material.AIR && material.isBlock()) {
2016-02-29 22:32:46 +01:00
assertThat(material.isFlammable(), is(CraftMagicNumbers.getBlock(material).getBlockData().getMaterial().isBurnable()));
} else {
assertFalse(material.isFlammable());
}
}
@Test
public void isBurnable() {
if (material.isBlock()) {
Block block = CraftMagicNumbers.getBlock(material);
assertThat(material.isBurnable(), is(fireValues.containsKey(block) && fireValues.get(block) > 0));
} else {
assertFalse(material.isBurnable());
}
}
@Test
public void isFuel() {
assertThat(material.isFuel(), is(TileEntityFurnace.isFuel(new net.minecraft.server.ItemStack(CraftMagicNumbers.getItem(material)))));
}
@Test
public void isOccluding() {
if (material.isBlock()) {
2016-02-29 22:32:46 +01:00
assertThat(material.isOccluding(), is(CraftMagicNumbers.getBlock(material).isOccluding(CraftMagicNumbers.getBlock(material).getBlockData())));
} else {
assertFalse(material.isOccluding());
}
}
@Test
public void hasGravity() {
if (material.isBlock()) {
2013-11-04 14:07:38 +01:00
assertThat(material.hasGravity(), is(CraftMagicNumbers.getBlock(material) instanceof BlockFalling));
} else {
assertFalse(material.hasGravity());
}
}
@Test
public void usesDurability() {
if (!material.isBlock()) {
assertThat(EnchantmentTarget.BREAKABLE.includes(material), is(CraftMagicNumbers.getItem(material).usesDurability()));
} else {
assertFalse(EnchantmentTarget.BREAKABLE.includes(material));
}
}
2018-01-15 23:57:47 +01:00
2018-07-15 02:00:00 +02:00
@Test
public void testDurability() {
if (!material.isBlock()) {
assertThat(material.getMaxDurability(), is((short) CraftMagicNumbers.getItem(material).getMaxDurability()));
} else {
assertThat(material.getMaxDurability(), is((short) 0));
}
}
2018-01-15 23:57:47 +01:00
@Test
public void testBlock() {
if (material == Material.AIR) {
assertTrue(material.isBlock());
} else {
assertThat(material.isBlock(), is(equalTo(CraftMagicNumbers.getBlock(material) != Blocks.AIR)));
}
}
@Test
2018-02-16 00:33:36 +01:00
public void testItem() {
2018-01-15 23:57:47 +01:00
if (material == Material.AIR) {
assertTrue(material.isItem());
} else {
assertThat(material.isItem(), is(equalTo(CraftMagicNumbers.getItem(material) != null)));
}
}
2012-12-09 22:13:38 +01:00
}