mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-29 07:48:53 +01:00
Add API to locate structures.
This commit is contained in:
parent
8164f4b25b
commit
88a5346fea
3 changed files with 64 additions and 0 deletions
11
nms-patches/WorldGenFactory.patch
Normal file
11
nms-patches/WorldGenFactory.patch
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
--- a/net/minecraft/server/WorldGenFactory.java
|
||||||
|
+++ b/net/minecraft/server/WorldGenFactory.java
|
||||||
|
@@ -9,7 +9,7 @@
|
||||||
|
public class WorldGenFactory {
|
||||||
|
|
||||||
|
private static final Logger a = LogManager.getLogger();
|
||||||
|
- private static final Map<String, Class<? extends StructureStart>> b = Maps.newHashMap();
|
||||||
|
+ public static final Map<String, Class<? extends StructureStart>> b = Maps.newHashMap(); // CraftBukkit private -> public
|
||||||
|
private static final Map<Class<? extends StructureStart>, String> c = Maps.newHashMap();
|
||||||
|
private static final Map<String, Class<? extends StructurePiece>> d = Maps.newHashMap();
|
||||||
|
private static final Map<Class<? extends StructurePiece>, String> e = Maps.newHashMap();
|
|
@ -26,6 +26,7 @@ import org.bukkit.GameRule;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Particle;
|
import org.bukkit.Particle;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
|
import org.bukkit.StructureType;
|
||||||
import org.bukkit.TreeType;
|
import org.bukkit.TreeType;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.WorldBorder;
|
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() {
|
public void processChunkGC() {
|
||||||
chunkGCTickCount++;
|
chunkGCTickCount++;
|
||||||
|
|
||||||
|
|
45
src/test/java/org/bukkit/StructureTypeTest.java
Normal file
45
src/test/java/org/bukkit/StructureTypeTest.java
Normal file
|
@ -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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue