Skip to content

Commit

Permalink
more setBlock methods
Browse files Browse the repository at this point in the history
  • Loading branch information
HSGamer committed Sep 17, 2024
1 parent d9c0665 commit f0f977b
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.bukkit.World;

import java.util.List;
import java.util.function.Supplier;

public interface BlockHandler {
BlockProcess setBlock(World world, PositionIterator iterator, BlockData blockData, boolean urgent);
Expand All @@ -17,6 +18,10 @@ public interface BlockHandler {

BlockProcess setBlock(World world, BlockBox blockBox, ProbabilityCollection<BlockData> probabilityCollection, boolean urgent);

BlockProcess setBlock(World world, PositionIterator iterator, Supplier<BlockData> blockDataSupplier, boolean urgent);

BlockProcess setBlock(World world, BlockBox blockBox, Supplier<BlockData> blockDataSupplier, boolean urgent);

BlockProcess setBlock(World world, List<Pair<Position, BlockData>> blocks, boolean urgent);

default BlockProcess clearBlock(World world, PositionIterator iterator, boolean urgent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;

public class FaweBlockHandler implements BlockHandler {
private int maxBlocks = -1;
Expand Down Expand Up @@ -141,6 +142,38 @@ public BlockProcess setBlock(World world, BlockBox blockBox, ProbabilityCollecti
return setBlocks(world, blockBox, createRandomPattern(probabilityCollection), urgent);
}

@Override
public BlockProcess setBlock(World world, PositionIterator iterator, Supplier<BlockData> blockDataSupplier, boolean urgent) {
com.sk89q.worldedit.world.World bukkitWorld = BukkitAdapter.adapt(world);
return runSession(bukkitWorld, session -> {
while (iterator.hasNext()) {
Position position = iterator.next();
int x = (int) Math.floor(position.x);
int y = (int) Math.floor(position.y);
int z = (int) Math.floor(position.z);
BlockData blockData = blockDataSupplier.get();
BlockState blockState = toBlockState(blockData);
session.setBlock(x, y, z, blockState);
}
}, urgent);
}

@Override
public BlockProcess setBlock(World world, BlockBox blockBox, Supplier<BlockData> blockDataSupplier, boolean urgent) {
com.sk89q.worldedit.world.World bukkitWorld = BukkitAdapter.adapt(world);
return runSession(bukkitWorld, session -> {
for (int x = blockBox.minX; x <= blockBox.maxX; x++) {
for (int y = blockBox.minY; y <= blockBox.maxY; y++) {
for (int z = blockBox.minZ; z <= blockBox.maxZ; z++) {
BlockData blockData = blockDataSupplier.get();
BlockState blockState = toBlockState(blockData);
session.setBlock(x, y, z, blockState);
}
}
}
}, urgent);
}

@Override
public BlockProcess setBlock(World world, List<Pair<Position, BlockData>> blocks, boolean urgent) {
com.sk89q.worldedit.world.World bukkitWorld = BukkitAdapter.adapt(world);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ public boolean hasContinue(Position current) {
};
}

BlockProcess setBlock(World world, PositionIterator iterator, Supplier<BlockData> blockDataSupplier, boolean urgent);

@Override
default BlockProcess setBlock(World world, PositionIterator iterator, BlockData blockData, boolean urgent) {
return setBlock(world, iterator, () -> blockData, urgent);
Expand All @@ -62,4 +60,9 @@ default BlockProcess setBlock(World world, PositionIterator iterator, Probabilit
default BlockProcess setBlock(World world, BlockBox blockBox, ProbabilityCollection<BlockData> probabilityCollection, boolean urgent) {
return setBlock(world, iterator(blockBox), probabilityCollection::get, urgent);
}

@Override
default BlockProcess setBlock(World world, BlockBox blockBox, Supplier<BlockData> blockDataSupplier, boolean urgent) {
return setBlock(world, iterator(blockBox), blockDataSupplier, urgent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.logging.Level;

public class WeBlockHandler implements BlockHandler {
Expand Down Expand Up @@ -140,6 +141,35 @@ public BlockProcess setBlock(World world, BlockBox blockBox, ProbabilityCollecti
return setBlocks(world, blockBox, createRandomPattern(probabilityCollection), urgent);
}

@Override
public BlockProcess setBlock(World world, PositionIterator iterator, Supplier<BlockData> blockDataSupplier, boolean urgent) {
com.sk89q.worldedit.world.World bukkitWorld = BukkitAdapter.adapt(world);
return runSession(bukkitWorld, session -> {
while (iterator.hasNext()) {
Position position = iterator.next();
BlockData blockData = blockDataSupplier.get();
BlockState blockState = toBlockState(blockData);
session.setBlock(BlockVector3.at(position.x, position.y, position.z), blockState);
}
}, urgent);
}

@Override
public BlockProcess setBlock(World world, BlockBox blockBox, Supplier<BlockData> blockDataSupplier, boolean urgent) {
com.sk89q.worldedit.world.World bukkitWorld = BukkitAdapter.adapt(world);
return runSession(bukkitWorld, session -> {
for (int x = blockBox.minX; x <= blockBox.maxX; x++) {
for (int y = blockBox.minY; y <= blockBox.maxY; y++) {
for (int z = blockBox.minZ; z <= blockBox.maxZ; z++) {
BlockData blockData = blockDataSupplier.get();
BlockState blockState = toBlockState(blockData);
session.setBlock(BlockVector3.at(x, y, z), blockState);
}
}
}
}, urgent);
}

@Override
public BlockProcess setBlock(World world, List<Pair<Position, BlockData>> blocks, boolean urgent) {
com.sk89q.worldedit.world.World bukkitWorld = BukkitAdapter.adapt(world);
Expand Down

0 comments on commit f0f977b

Please sign in to comment.