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/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..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 @@ -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)) { @@ -102,20 +105,20 @@ 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, 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); } } 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..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,8 +31,8 @@ import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.util.SideEffectSet; +import com.sk89q.worldedit.world.block.BlockState; 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.weather.WeatherType; import com.sk89q.worldedit.world.weather.WeatherTypes; @@ -104,7 +104,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 +127,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 +167,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();