From d66035560638f031feab264f847d42a073401279 Mon Sep 17 00:00:00 2001 From: Owen <23108066+Owen1212055@users.noreply.github.com> Date: Sat, 4 Jun 2022 20:17:10 -0400 Subject: [PATCH 1/4] Fix break effect and deprecate World#playEffect --- .../sk89q/worldedit/bukkit/BukkitWorld.java | 8 +++++ .../sk89q/worldedit/world/AbstractWorld.java | 22 +++++++------- .../java/com/sk89q/worldedit/world/World.java | 30 ++++++++++++++++++- .../sk89q/worldedit/fabric/FabricWorld.java | 8 +++++ .../com/sk89q/worldedit/forge/ForgeWorld.java | 8 +++++ 5 files changed, 65 insertions(+), 11 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java index 8fdae57089..15637795c6 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java @@ -370,6 +370,14 @@ public boolean playEffect(Vector3 position, int type, int data) { return true; } + @Override + public boolean playBreakBlockEffect(Vector3 position, com.sk89q.worldedit.world.block.BlockState block) { + World world = getWorld(); + + world.playEffect(BukkitAdapter.adapt(world, position), Effect.STEP_SOUND, BukkitAdapter.adapt(block.getBlockType())); // Bukkit doesn't use a blockstate, instead uses material + return true; + } + @Override public WeatherType getWeather() { if (getWorld().isThundering()) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/AbstractWorld.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/AbstractWorld.java index 01a0cc9f13..ee98c8936e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/AbstractWorld.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/AbstractWorld.java @@ -31,9 +31,7 @@ import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.util.SideEffectSet; -import com.sk89q.worldedit.world.block.BlockStateHolder; -import com.sk89q.worldedit.world.block.BlockType; -import com.sk89q.worldedit.world.block.BlockTypes; +import com.sk89q.worldedit.world.block.*; import com.sk89q.worldedit.world.weather.WeatherType; import com.sk89q.worldedit.world.weather.WeatherTypes; @@ -104,7 +102,12 @@ public boolean playEffect(Vector3 position, int type, int data) { } @Override - public boolean queueBlockBreakEffect(Platform server, BlockVector3 position, BlockType blockType, double priority) { + public boolean playBreakBlockEffect(Vector3 position, BlockState block) { + return false; + } + + @Override + public boolean queueBlockBreakEffect(Platform server, BlockVector3 position, BlockState blockState, double priority) { if (taskId == -1) { taskId = server.schedule(0, 1, () -> { int max = Math.max(1, Math.min(30, effectQueue.size() / 3)); @@ -122,7 +125,7 @@ public boolean queueBlockBreakEffect(Platform server, BlockVector3 position, Blo return false; } - effectQueue.offer(new QueuedEffect(position.toVector3(), blockType, priority)); + effectQueue.offer(new QueuedEffect(position.toVector3(), blockState, priority)); return true; } @@ -162,18 +165,17 @@ public void setWeather(WeatherType weatherType, long duration) { private class QueuedEffect implements Comparable { private final Vector3 position; - private final BlockType blockType; + private final BlockState blockState; private final double priority; - private QueuedEffect(Vector3 position, BlockType blockType, double priority) { + private QueuedEffect(Vector3 position, BlockState blockState, double priority) { this.position = position; - this.blockType = blockType; + this.blockState = blockState; this.priority = priority; } - @SuppressWarnings("deprecation") public void play() { - playEffect(position, 2001, blockType.getLegacyId()); + playBreakBlockEffect(position, blockState); } @Override diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/World.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/World.java index 276b206ff9..f4752ae45c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/World.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/World.java @@ -307,9 +307,22 @@ default boolean regenerate(Region region, Extent extent, RegenOptions options) { * @param type the effect type * @param data the effect data * @return true if the effect was played + * @deprecated magic numbers */ + @Deprecated boolean playEffect(Vector3 position, int type, int data); + + /** + * Plays a block break effect and sound at + * the given position. + * + * @param position position + * @param block block + * @return true if the effect was played + */ + boolean playBreakBlockEffect(Vector3 position, BlockState block); + /** * Queue a block break effect. * @@ -318,8 +331,23 @@ default boolean regenerate(Region region, Extent extent, RegenOptions options) { * @param blockType the block type * @param priority the priority * @return true if the effect was played + * @deprecated use a blockstate instead of block type + */ + @Deprecated + default boolean queueBlockBreakEffect(Platform server, BlockVector3 position, BlockType blockType, double priority) { + return queueBlockBreakEffect(server, position, blockType.getDefaultState(), priority); + } + + /** + * Queue a block break effect. + * + * @param server the server + * @param position the position + * @param blockState the block state + * @param priority the priority + * @return true if the effect was played */ - boolean queueBlockBreakEffect(Platform server, BlockVector3 position, BlockType blockType, double priority); + boolean queueBlockBreakEffect(Platform server, BlockVector3 position, BlockState blockState, double priority); /** * Gets the weather type of the world. diff --git a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricWorld.java b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricWorld.java index c5a12f6145..793343f549 100644 --- a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricWorld.java +++ b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricWorld.java @@ -86,6 +86,8 @@ import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.Level; import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.LevelEvent; import net.minecraft.world.level.block.LiquidBlock; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.chunk.ChunkAccess; @@ -494,6 +496,12 @@ public boolean playEffect(Vector3 position, int type, int data) { return true; } + @Override + public boolean playBreakBlockEffect(Vector3 position, BlockState block) { + getWorld().globalLevelEvent(LevelEvent.PARTICLES_DESTROY_BLOCK, FabricAdapter.toBlockPos(position.toBlockPoint()), Block.getId(FabricAdapter.adapt(block))); + return true; + } + @Override public WeatherType getWeather() { LevelData info = getWorld().getLevelData(); diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorld.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorld.java index 3376da2f9f..1806282449 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorld.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorld.java @@ -83,6 +83,8 @@ import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.Level; import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.LevelEvent; import net.minecraft.world.level.block.LiquidBlock; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.chunk.ChunkAccess; @@ -477,6 +479,12 @@ public boolean playEffect(Vector3 position, int type, int data) { return true; } + @Override + public boolean playBreakBlockEffect(Vector3 position, BlockState block) { + getWorld().globalLevelEvent(LevelEvent.PARTICLES_DESTROY_BLOCK, ForgeAdapter.toBlockPos(position.toBlockPoint()), Block.getId(ForgeAdapter.adapt(block))); + return true; + } + @Override public WeatherType getWeather() { LevelData info = getWorld().getLevelData(); From 03899a7c016272b1f9ad752d290404ba59b8ec5f Mon Sep 17 00:00:00 2001 From: Owen <23108066+Owen1212055@users.noreply.github.com> Date: Sat, 4 Jun 2022 20:17:57 -0400 Subject: [PATCH 2/4] Remove wildcard --- .../main/java/com/sk89q/worldedit/world/AbstractWorld.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/AbstractWorld.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/AbstractWorld.java index ee98c8936e..7e06041a07 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/AbstractWorld.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/AbstractWorld.java @@ -31,7 +31,9 @@ import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.util.SideEffectSet; -import com.sk89q.worldedit.world.block.*; +import com.sk89q.worldedit.world.block.BlockState; +import com.sk89q.worldedit.world.block.BlockStateHolder; +import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.weather.WeatherType; import com.sk89q.worldedit.world.weather.WeatherTypes; From e6e625a513c5977dce45ee33f4837efb5818573d Mon Sep 17 00:00:00 2001 From: Owen <23108066+Owen1212055@users.noreply.github.com> Date: Sat, 4 Jun 2022 20:33:09 -0400 Subject: [PATCH 3/4] Use initial state instead of types --- .../worldedit/command/tool/AreaPickaxe.java | 6 ++++-- .../command/tool/RecursivePickaxe.java | 21 +++++++++++-------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/AreaPickaxe.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/AreaPickaxe.java index a211128a4d..6ab729dca2 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/AreaPickaxe.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/AreaPickaxe.java @@ -31,6 +31,7 @@ import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; import com.sk89q.worldedit.world.World; +import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; @@ -57,7 +58,8 @@ public boolean actPrimary(Platform server, LocalConfiguration config, Player pla int ox = clicked.getBlockX(); int oy = clicked.getBlockY(); int oz = clicked.getBlockZ(); - BlockType initialType = clicked.getExtent().getBlock(clicked.toVector().toBlockPoint()).getBlockType(); + BlockState initialState = clicked.getExtent().getBlock(clicked.toVector().toBlockPoint()); + BlockType initialType = initialState.getBlockType(); if (initialType.getMaterial().isAir()) { return false; @@ -81,7 +83,7 @@ public boolean actPrimary(Platform server, LocalConfiguration config, Player pla editSession.setBlock(pos, BlockTypes.AIR.getDefaultState()); - ((World) clicked.getExtent()).queueBlockBreakEffect(server, pos, initialType, + ((World) clicked.getExtent()).queueBlockBreakEffect(server, pos, initialState, clicked.toVector().toBlockPoint().distanceSq(pos)); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/RecursivePickaxe.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/RecursivePickaxe.java index e114b77078..e6a1229d4e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/RecursivePickaxe.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/RecursivePickaxe.java @@ -31,6 +31,7 @@ import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; import com.sk89q.worldedit.world.World; +import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; @@ -60,7 +61,8 @@ public boolean actPrimary(Platform server, LocalConfiguration config, Player pla World world = (World) clicked.getExtent(); BlockVector3 origin = clicked.toVector().toBlockPoint(); - BlockType initialType = world.getBlock(origin).getBlockType(); + BlockState initialState = world.getBlock(origin); + BlockType initialType = initialState.getBlockType(); if (initialType.getMaterial().isAir()) { return false; @@ -75,7 +77,7 @@ public boolean actPrimary(Platform server, LocalConfiguration config, Player pla try { recurse(server, editSession, world, clicked.toVector().toBlockPoint(), - clicked.toVector().toBlockPoint(), range, initialType, new HashSet<>()); + clicked.toVector().toBlockPoint(), range, initialState, new HashSet<>()); } catch (MaxChangedBlocksException e) { player.printError(TranslatableComponent.of("worldedit.tool.max-block-changes")); } finally { @@ -87,7 +89,8 @@ public boolean actPrimary(Platform server, LocalConfiguration config, Player pla } private static void recurse(Platform server, EditSession editSession, World world, BlockVector3 pos, - BlockVector3 origin, double size, BlockType initialType, Set visited) throws MaxChangedBlocksException { + BlockVector3 origin, double size, BlockState initialState, Set visited) throws MaxChangedBlocksException { + BlockType initialType = initialState.getBlockType(); final double distanceSq = origin.distanceSq(pos); if (distanceSq > size * size || visited.contains(pos)) { @@ -105,17 +108,17 @@ private static void recurse(Platform server, EditSession editSession, World worl world.queueBlockBreakEffect(server, pos, initialType, distanceSq); recurse(server, editSession, world, pos.add(1, 0, 0), - origin, size, initialType, visited); + origin, size, initialState, visited); recurse(server, editSession, world, pos.add(-1, 0, 0), - origin, size, initialType, visited); + origin, size, initialState, visited); recurse(server, editSession, world, pos.add(0, 0, 1), - origin, size, initialType, visited); + origin, size, initialState, visited); recurse(server, editSession, world, pos.add(0, 0, -1), - origin, size, initialType, visited); + origin, size, initialState, visited); recurse(server, editSession, world, pos.add(0, 1, 0), - origin, size, initialType, visited); + origin, size, initialState, visited); recurse(server, editSession, world, pos.add(0, -1, 0), - origin, size, initialType, visited); + origin, size, initialState, visited); } } From 153972c638ad83aa00fef572ae615289e5079eb7 Mon Sep 17 00:00:00 2001 From: Owen <23108066+Owen1212055@users.noreply.github.com> Date: Sat, 4 Jun 2022 20:33:44 -0400 Subject: [PATCH 4/4] Use initial state instead of types --- .../java/com/sk89q/worldedit/command/tool/RecursivePickaxe.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/RecursivePickaxe.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/RecursivePickaxe.java index e6a1229d4e..1f3671ff8d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/RecursivePickaxe.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/RecursivePickaxe.java @@ -105,7 +105,7 @@ private static void recurse(Platform server, EditSession editSession, World worl editSession.setBlock(pos, BlockTypes.AIR.getDefaultState()); - world.queueBlockBreakEffect(server, pos, initialType, distanceSq); + world.queueBlockBreakEffect(server, pos, initialState, distanceSq); recurse(server, editSession, world, pos.add(1, 0, 0), origin, size, initialState, visited);