From 3a2d0b0c2d7b635e4aa909187ffa69b3261cae4d Mon Sep 17 00:00:00 2001 From: daoge_cmd <3523206925@qq.com> Date: Tue, 14 Jan 2025 18:16:44 +0800 Subject: [PATCH] refactor: rename `Structure#pickStructure` to `Structure#pick` --- CHANGELOG.md | 1 + .../java/org/allaymc/api/utils/Structure.java | 43 +++++++++++++++++-- .../command/defaults/StructureCommand.java | 2 +- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c395c9d18..dbb539e54 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -61,6 +61,7 @@ Unless otherwise specified, any version comparison below is the comparison of se - (API) Removed `ScoreboardService#ServerEventListener` as it is not supposed to be touched by plugin. - (API) Methods `BlockEntityFurnaceBaseComponent#getStoredXP` and `BlockEntityFurnaceBaseComponent#setStoredXP` now accept `int` instead of `float`. +- (API) Renamed `Structure#pickStructure` to `Structure#pick`. - Removed useless class `PackageClassLoaderUtils`, dependency `org.reflections.reflections` is also removed. - Added `-dev` suffix to api version in development build. - Changed `ContainerActionProcessorHolder` to a final class instead of an interface, because this abstraction is diff --git a/api/src/main/java/org/allaymc/api/utils/Structure.java b/api/src/main/java/org/allaymc/api/utils/Structure.java index bed2bfb10..4031a7df4 100644 --- a/api/src/main/java/org/allaymc/api/utils/Structure.java +++ b/api/src/main/java/org/allaymc/api/utils/Structure.java @@ -31,11 +31,28 @@ public record Structure( private static final int FORMAT_VERSION = 1; private static final BlockState STRUCTURE_VOID_DEFAULT_STATE = BlockTypes.STRUCTURE_VOID.getDefaultState(); - public static Structure pickStructure(Dimension dimension, int x, int y, int z, int sizeX, int sizeY, int sizeZ) { - return pickStructure(dimension, x, y, z, sizeX, sizeY, sizeZ, true); + /** + * @see #pick(Dimension, int, int, int, int, int, int, boolean) + */ + public static Structure pick(Dimension dimension, int x, int y, int z, int sizeX, int sizeY, int sizeZ) { + return pick(dimension, x, y, z, sizeX, sizeY, sizeZ, true); } - public static Structure pickStructure(Dimension dimension, int x, int y, int z, int sizeX, int sizeY, int sizeZ, boolean saveEntities) { + /** + * Pick a structure from the dimension. + * + * @param dimension the dimension to pick the structure from. + * @param x the x coordinate of the structure. + * @param y the y coordinate of the structure. + * @param z the z coordinate of the structure. + * @param sizeX the size of the structure in x direction. + * @param sizeY the size of the structure in y direction. + * @param sizeZ the size of the structure in z direction. + * @param saveEntities whether to save the entities in the structure. + * + * @return the picked structure. + */ + public static Structure pick(Dimension dimension, int x, int y, int z, int sizeX, int sizeY, int sizeZ, boolean saveEntities) { var blockStates = new BlockState[2][sizeX][sizeY][sizeZ]; var blockEntities = new HashMap(); var entities = new ArrayList(); @@ -76,6 +93,13 @@ public static Structure pickStructure(Dimension dimension, int x, int y, int z, return new Structure(blockStates, blockEntities, entities, sizeX, sizeY, sizeZ, x, y, z); } + /** + * Load structure data from nbt. + * + * @param nbt the nbt data to load. + * + * @return the loaded structure. + */ public static Structure formNBT(NbtMap nbt) { if (nbt.getInt("format_version") != FORMAT_VERSION) { throw new StructureException("format_version should be " + FORMAT_VERSION); @@ -149,6 +173,14 @@ public static Structure formNBT(NbtMap nbt) { ); } + /** + * Place the structure in the dimension. + * + * @param dimension the dimension to place the structure in. + * @param x the x coordinate to place the structure. + * @param y the y coordinate to place the structure. + * @param z the z coordinate to place the structure. + */ public void place(Dimension dimension, int x, int y, int z) { for (int lx = 0; lx < sizeX; lx++) { for (int ly = 0; ly < sizeY; ly++) { @@ -195,6 +227,11 @@ public void place(Dimension dimension, int x, int y, int z) { } } + /** + * Save the structure data to nbt. + * + * @return the nbt data of the structure. + */ public NbtMap toNBT() { var capacity = sizeX * sizeY * sizeZ; var layer0 = new Integer[capacity]; diff --git a/server/src/main/java/org/allaymc/server/command/defaults/StructureCommand.java b/server/src/main/java/org/allaymc/server/command/defaults/StructureCommand.java index 2eef1b4a4..c5f4ce158 100644 --- a/server/src/main/java/org/allaymc/server/command/defaults/StructureCommand.java +++ b/server/src/main/java/org/allaymc/server/command/defaults/StructureCommand.java @@ -46,7 +46,7 @@ public void prepareCommandTree(CommandTree tree) { context.addError("Invalid size"); return context.fail(); } - var structure = Structure.pickStructure( + var structure = Structure.pick( player.getDimension(), (int) start.x, (int) start.y, (int) start.z, sizeX, sizeY, sizeZ,