summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java2
-rw-r--r--src/test/java/org/bukkit/BlockDataConversionTest.java38
-rw-r--r--src/test/java/org/bukkit/PerMaterialTest.java7
3 files changed, 47 insertions, 0 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java b/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java
index 8ee5d217..d470e2b3 100644
--- a/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java
@@ -352,6 +352,7 @@ public class CraftBlockData implements BlockData {
private static final Map<Class<? extends Block>, Function<IBlockData, CraftBlockData>> MAP = new HashMap<>();
static {
+ //<editor-fold desc="CraftBlockData Registration" defaultstate="collapsed">
register(net.minecraft.server.BlockAnvil.class, org.bukkit.craftbukkit.block.impl.CraftAnvil::new);
register(net.minecraft.server.BlockBanner.class, org.bukkit.craftbukkit.block.impl.CraftBanner::new);
register(net.minecraft.server.BlockBannerWall.class, org.bukkit.craftbukkit.block.impl.CraftBannerWall::new);
@@ -460,6 +461,7 @@ public class CraftBlockData implements BlockData {
register(net.minecraft.server.BlockWitherSkull.class, org.bukkit.craftbukkit.block.impl.CraftWitherSkull::new);
register(net.minecraft.server.BlockWitherSkullWall.class, org.bukkit.craftbukkit.block.impl.CraftWitherSkullWall::new);
register(net.minecraft.server.BlockWoodButton.class, org.bukkit.craftbukkit.block.impl.CraftWoodButton::new);
+ //</editor-fold>
}
private static void register(Class<? extends Block> nms, Function<IBlockData, CraftBlockData> bukkit) {
diff --git a/src/test/java/org/bukkit/BlockDataConversionTest.java b/src/test/java/org/bukkit/BlockDataConversionTest.java
new file mode 100644
index 00000000..46cc26b3
--- /dev/null
+++ b/src/test/java/org/bukkit/BlockDataConversionTest.java
@@ -0,0 +1,38 @@
+package org.bukkit;
+
+import java.util.ArrayList;
+import java.util.List;
+import net.minecraft.server.Block;
+import net.minecraft.server.IBlockData;
+import net.minecraft.server.IRegistry;
+import org.bukkit.craftbukkit.block.data.CraftBlockData;
+import org.bukkit.support.AbstractTestingBase;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+/**
+ * This test class ensures that all Blocks (as registered in IRegistry.BLOCK)
+ * can be converted into their CraftBlockData equivalent.
+ */
+@RunWith(Parameterized.class)
+public class BlockDataConversionTest extends AbstractTestingBase {
+
+ @Parameterized.Parameters(name = "{index}: {0}")
+ public static List<Object[]> args() {
+ List<Object[]> list = new ArrayList<>();
+ for (Block block : (Iterable<Block>) IRegistry.BLOCK) {
+ list.add(new Object[]{block.getBlockData()});
+ }
+ return list;
+ }
+
+ @Parameterized.Parameter(0) public IBlockData data;
+
+ @Test
+ public void testNotNull() {
+ Assert.assertNotNull(data);
+ Assert.assertNotNull(CraftBlockData.fromData(data));
+ }
+}
diff --git a/src/test/java/org/bukkit/PerMaterialTest.java b/src/test/java/org/bukkit/PerMaterialTest.java
index 82b5b1af..7967c4c3 100644
--- a/src/test/java/org/bukkit/PerMaterialTest.java
+++ b/src/test/java/org/bukkit/PerMaterialTest.java
@@ -229,4 +229,11 @@ public class PerMaterialTest extends AbstractTestingBase {
assertThat(material.getBlastResistance(), is(CraftMagicNumbers.getBlock(material).getDurability()));
}
}
+
+ @Test
+ public void testBlockDataCreation() {
+ if (material.isBlock()) {
+ assertNotNull(material.createBlockData());
+ }
+ }
}