use of com.sk89q.worldedit.world.block.BlockType in project FastAsyncWorldEdit by IntellectualSites.
the class CachedBukkitAdapter method adapt.
/**
* Create a WorldEdit BlockStateHolder from a Bukkit BlockData.
*
* @param blockData The Bukkit BlockData
* @return The WorldEdit BlockState
*/
@Override
public BlockState adapt(BlockData blockData) {
try {
checkNotNull(blockData);
Material material = blockData.getMaterial();
BlockType type = BlockTypes.getFromStateId(blockTypes[material.ordinal()]);
List<? extends Property> propList = type.getProperties();
if (propList.size() == 0) {
return type.getDefaultState();
}
String properties = blockData.getAsString();
return BlockState.get(type, properties, type.getDefaultState());
} catch (NullPointerException e) {
if (init()) {
return adapt(blockData);
}
throw e;
}
}
use of com.sk89q.worldedit.world.block.BlockType in project FastAsyncWorldEdit by IntellectualSites.
the class FloatingTreeRemover method bfs.
/**
* Helper method.
*
* @param world the world that contains the tree
* @param origin any point contained in the floating tree
* @return a set containing all blocks in the tree/shroom or null if this is not a floating tree/shroom.
*/
private Set<BlockVector3> bfs(World world, BlockVector3 origin) {
// FAWE start - Use a LBVS over a HashMap & LinkedList
final LocalBlockVectorSet visited = new LocalBlockVectorSet();
final LocalBlockVectorSet queue = new LocalBlockVectorSet();
// FAWE end
queue.add(origin);
visited.add(origin);
while (!queue.isEmpty()) {
Iterator<BlockVector3> iter = queue.iterator();
while (iter.hasNext()) {
final BlockVector3 current = iter.next();
iter.remove();
for (BlockVector3 recurseDirection : recurseDirections) {
final BlockVector3 next = current.add(recurseDirection);
if (origin.distanceSq(next) > rangeSq) {
// Maximum range exceeded => stop walking
continue;
}
if (visited.add(next)) {
BlockState state = world.getBlock(next);
if (state.getBlockType().getMaterial().isAir() || state.getBlockType() == BlockTypes.SNOW) {
continue;
}
if (isTreeBlock(state.getBlockType())) {
queue.add(next);
} else {
// we hit something solid - evaluate where we came from
final BlockType currentType = world.getBlock(current).getBlockType();
if (!BlockCategories.LEAVES.contains(currentType) && currentType != BlockTypes.VINE) {
// log/shroom touching a wall/the ground => this is not a floating tree, bail out
return null;
}
}
}
}
}
}
return visited;
}
use of com.sk89q.worldedit.world.block.BlockType in project FastAsyncWorldEdit by IntellectualSites.
the class FloodFillTool method actPrimary.
@Override
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked, @Nullable Direction face) {
World world = (World) clicked.getExtent();
BlockVector3 origin = clicked.toVector().toBlockPoint();
BlockType initialType = world.getBlock(origin).getBlockType();
if (initialType.getMaterial().isAir()) {
return true;
}
if (initialType == BlockTypes.BEDROCK && !player.canDestroyBedrock()) {
return true;
}
try (EditSession editSession = session.createEditSession(player, "FloodFillTool")) {
try {
// FAWE start - Respect masks
Mask mask = initialType.toMask(editSession);
BlockReplace function = new BlockReplace(editSession, pattern);
RecursiveVisitor visitor = new RecursiveVisitor(mask, function, range, editSession.getMinY(), editSession.getMaxY(), editSession);
visitor.visit(origin);
Operations.completeLegacy(visitor);
// FAWE end
} catch (MaxChangedBlocksException e) {
player.print(Caption.of("worldedit.tool.max-block-changes"));
} finally {
session.remember(editSession);
}
}
return true;
}
use of com.sk89q.worldedit.world.block.BlockType in project FastAsyncWorldEdit by IntellectualSites.
the class RecursivePickaxe method actPrimary.
@Override
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked, @Nullable Direction face) {
World world = (World) clicked.getExtent();
final BlockVector3 pos = clicked.toBlockPoint();
BlockVector3 origin = clicked.toVector().toBlockPoint();
BlockType initialType = world.getBlock(origin).getBlockType();
if (initialType.getMaterial().isAir()) {
return false;
}
if (initialType == BlockTypes.BEDROCK && !player.canDestroyBedrock()) {
return false;
}
try (EditSession editSession = session.createEditSession(player, "RecursivePickaxe")) {
editSession.getSurvivalExtent().setToolUse(config.superPickaxeManyDrop);
// FAWE start
final int radius = (int) range;
final BlockReplace replace = new BlockReplace(editSession, (BlockTypes.AIR.getDefaultState()));
editSession.setMask(null);
RecursiveVisitor visitor = new RecursiveVisitor(new IdMask(editSession), replace, radius, editSession.getMinY(), editSession.getMaxY(), editSession);
// TODO: Fix below
// visitor.visit(pos);
// Operations.completeBlindly(visitor);
recurse(server, editSession, world, pos, origin, radius, initialType, visitor.getVisited());
// FAWE end
editSession.flushQueue();
session.remember(editSession);
}
return true;
}
use of com.sk89q.worldedit.world.block.BlockType in project FastAsyncWorldEdit by IntellectualSites.
the class EditSession method popMissingBlocks.
/**
* Gets the list of missing blocks and clears the list for the next
* operation.
*
* @return a map of missing blocks
*/
public Map<BlockType, Integer> popMissingBlocks() {
BlockBag bag = getBlockBag();
if (bag != null) {
bag.flushChanges();
Map<BlockType, Integer> missingBlocks;
ChangeSet changeSet = getChangeSet();
if (changeSet instanceof BlockBagChangeSet) {
missingBlocks = ((BlockBagChangeSet) changeSet).popMissing();
} else {
ExtentTraverser<BlockBagExtent> find = new ExtentTraverser<>(getExtent()).find(BlockBagExtent.class);
if (find != null && find.get() != null) {
missingBlocks = find.get().popMissing();
} else {
missingBlocks = null;
}
}
if (missingBlocks != null && !missingBlocks.isEmpty()) {
StringBuilder str = new StringBuilder();
int size = missingBlocks.size();
int i = 0;
for (Map.Entry<BlockType, Integer> entry : missingBlocks.entrySet()) {
BlockType type = entry.getKey();
int amount = entry.getValue();
str.append((type.getName())).append((amount != 1 ? "x" + amount : ""));
++i;
if (i != size) {
str.append(", ");
}
}
actor.print(Caption.of("fawe.error.worldedit.some.fails.blockbag", str.toString()));
}
}
return Collections.emptyMap();
}
Aggregations