diff options
author | Senmori <thesenmori@gmail.com> | 2018-09-21 08:49:54 -0400 |
---|---|---|
committer | md_5 <git@md-5.net> | 2018-09-22 17:11:17 +1000 |
commit | 88a5346feafd9517adb9347be6233460dbf45744 (patch) | |
tree | fccaf3d765986d068772656ed957a3c7d96c7a69 /src | |
parent | 8164f4b25bb557d4ded2db42ca4e6abb423bb5ee (diff) | |
download | craftbukkit-88a5346feafd9517adb9347be6233460dbf45744.tar craftbukkit-88a5346feafd9517adb9347be6233460dbf45744.tar.gz craftbukkit-88a5346feafd9517adb9347be6233460dbf45744.tar.lz craftbukkit-88a5346feafd9517adb9347be6233460dbf45744.tar.xz craftbukkit-88a5346feafd9517adb9347be6233460dbf45744.zip |
Add API to locate structures.
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/CraftWorld.java | 8 | ||||
-rw-r--r-- | src/test/java/org/bukkit/StructureTypeTest.java | 45 |
2 files changed, 53 insertions, 0 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index 90451598..adf232ea 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -26,6 +26,7 @@ import org.bukkit.GameRule; import org.bukkit.Location; import org.bukkit.Particle; import org.bukkit.Sound; +import org.bukkit.StructureType; import org.bukkit.TreeType; import org.bukkit.World; import org.bukkit.WorldBorder; @@ -1591,6 +1592,13 @@ public class CraftWorld implements World { } + @Override + public Location locateNearestStructure(Location origin, StructureType structureType, int radius, boolean findUnexplored) { + BlockPosition originPos = new BlockPosition(origin.getX(), origin.getY(), origin.getZ()); + BlockPosition nearest = getHandle().getChunkProviderServer().getChunkGenerator().findNearestMapFeature(getHandle(), structureType.getName(), originPos, radius, findUnexplored); + return (nearest == null) ? null : new Location(this, nearest.getX(), nearest.getY(), nearest.getZ()); + } + public void processChunkGC() { chunkGCTickCount++; diff --git a/src/test/java/org/bukkit/StructureTypeTest.java b/src/test/java/org/bukkit/StructureTypeTest.java new file mode 100644 index 00000000..57f68761 --- /dev/null +++ b/src/test/java/org/bukkit/StructureTypeTest.java @@ -0,0 +1,45 @@ +package org.bukkit; + +import java.util.Map; +import net.minecraft.server.WorldGenFactory; +import org.bukkit.support.AbstractTestingBase; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * This test makes sure that Bukkit always has Minecraft structure types up to + * date. + */ +public class StructureTypeTest extends AbstractTestingBase { + + private static Map<String, StructureType> structures; + + @BeforeClass + public static void setUp() { + structures = StructureType.getStructureTypes(); + } + + @Test + public void testMinecraftToBukkit() { + for (String key : WorldGenFactory.b.keySet()) { // PAIL rename structureStartMap + Assert.assertNotNull(structures.get(key)); + } + } + + @Test + public void testBukkit() { + for (Map.Entry<String, StructureType> entry : structures.entrySet()) { + Assert.assertNotNull(StructureType.getStructureTypes().get(entry.getKey())); + Assert.assertNotNull(StructureType.getStructureTypes().get(entry.getValue().getName())); + } + } + + @Test + public void testBukkitToMinecraft() { + for (Map.Entry<String, StructureType> entry : structures.entrySet()) { + Assert.assertNotNull(WorldGenFactory.b.get(entry.getKey())); + Assert.assertNotNull(WorldGenFactory.b.get(entry.getValue().getName())); + } + } +} |