Add methods to ProtoWorld for working with BlockStates (#5929)

This commit is contained in:
dfsek 2021-07-07 03:23:16 -07:00 committed by GitHub
parent 5059ada8d7
commit b5be382d00
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 328 additions and 10 deletions

View file

@ -6,13 +6,14 @@ Subject: [PATCH] Add Feature Stage API
diff --git a/src/main/java/io/papermc/paper/world/generation/ProtoWorld.java b/src/main/java/io/papermc/paper/world/generation/ProtoWorld.java
new file mode 100644
index 0000000000000000000000000000000000000000..cf9443f1cd3039f0e53c645c894483027455465b
index 0000000000000000000000000000000000000000..f3b465d3883547d53e55183c2a4e22c63525a787
--- /dev/null
+++ b/src/main/java/io/papermc/paper/world/generation/ProtoWorld.java
@@ -0,0 +1,270 @@
@@ -0,0 +1,313 @@
+package io.papermc.paper.world.generation;
+
+import org.bukkit.World;
+import org.bukkit.block.BlockState;
+import org.bukkit.block.data.BlockData;
+import org.bukkit.entity.Entity;
+import org.bukkit.entity.EntityType;
@ -58,6 +59,48 @@ index 0000000000000000000000000000000000000000..cf9443f1cd3039f0e53c645c89448302
+ }
+
+ /**
+ * Sets the {@link BlockState} at a location.
+ *
+ * @param x X coordinate.
+ * @param y Y coordinate.
+ * @param z Z coordinate.
+ * @param state The block state.
+ */
+ void setBlockState(int x, int y, int z, @NotNull BlockState state);
+
+ /**
+ * Sets the {@link BlockState} at a location.
+ *
+ * @param location Location to set block state.
+ * @param state The block state.
+ */
+ default void setBlockState(@NotNull Vector location, @NotNull BlockState state) {
+ setBlockState(location.getBlockX(), location.getBlockY(), location.getBlockZ(), state);
+ }
+
+ /**
+ * Gets the {@link BlockState} at a location.
+ *
+ * @param x X coordinate.
+ * @param y Y coordinate.
+ * @param z Z coordinate.
+ * @return The block state.
+ */
+ @NotNull
+ BlockState getBlockState(int x, int y, int z);
+
+ /**
+ * Gets the {@link BlockState} at a location.
+ *
+ * @param location Location to get block state from.
+ * @return The block state.
+ */
+ @NotNull
+ default BlockState getBlockState(@NotNull Vector location) {
+ return getBlockState(location.getBlockX(), location.getBlockY(), location.getBlockZ());
+ }
+
+ /**
+ * Schedule a block update at (x, y, z).
+ *
+ * @param x X coordinate in this ProtoWorld
@ -134,7 +177,7 @@ index 0000000000000000000000000000000000000000..cf9443f1cd3039f0e53c645c89448302
+ int getCenterChunkX();
+
+ /**
+ * Get the X-coordinate of the block in the center of this ProtoWorld
+ * Get the X-coordinate of the block in the center of this {@link ProtoWorld}
+ *
+ * @return The center chunk's X coordinate.
+ */
@ -143,14 +186,14 @@ index 0000000000000000000000000000000000000000..cf9443f1cd3039f0e53c645c89448302
+ }
+
+ /**
+ * Get the Z-coordinate of the chunk in the center of this ProtoWorld
+ * Get the Z-coordinate of the chunk in the center of this {@link ProtoWorld}
+ *
+ * @return The center chunk's Z coordinate.
+ */
+ int getCenterChunkZ();
+
+ /**
+ * Get the Z-coordinate of the block in the center of this ProtoWorld
+ * Get the Z-coordinate of the block in the center of this {@link ProtoWorld}
+ *
+ * @return The center chunk's Z coordinate.
+ */
@ -159,7 +202,7 @@ index 0000000000000000000000000000000000000000..cf9443f1cd3039f0e53c645c89448302
+ }
+
+ /**
+ * Creates a entity at the location represented by the given {@link Vector}
+ * Creates an entity at the location represented by the given {@link Vector}
+ *
+ * @param loc The {@link Vector} representing the location to spawn the entity
+ * @param type The entity to spawn
@ -245,7 +288,7 @@ index 0000000000000000000000000000000000000000..cf9443f1cd3039f0e53c645c89448302
+ }
+
+ /**
+ * Creates a entity at the location represented by the given {@link Vector}
+ * Creates an entity at the location represented by the given {@link Vector}
+ *
+ * @param loc The {@link Vector} representing the location to spawn the entity
+ * @param type The entity to spawn
@ -259,7 +302,7 @@ index 0000000000000000000000000000000000000000..cf9443f1cd3039f0e53c645c89448302
+ }
+
+ /**
+ * Creates a entity at the location represented by the given {@link Vector}, with
+ * Creates an entity at the location represented by the given {@link Vector}, with
+ * the supplied function run before the entity is added to the world.
+ * <br>
+ * Note that when the function is run, the entity will not be actually in