use of com.sk89q.worldedit.world.block.BlockState in project CoreProtect by PlayPro.
the class CoreProtectLogger method setBlock.
@Override
public <T extends BlockStateHolder<T>> boolean setBlock(BlockVector3 position, T block) throws WorldEditException {
org.bukkit.World world = BukkitAdapter.adapt(eventWorld);
if (!Config.getConfig(world).WORLDEDIT) {
return eventExtent.setBlock(position, block);
}
BlockState oldBlock = eventExtent.getBlock(position);
Material oldType = BukkitAdapter.adapt(oldBlock.getBlockType());
Location location = new Location(world, position.getBlockX(), position.getBlockY(), position.getBlockZ());
BaseBlock baseBlock = WorldEditLogger.getBaseBlock(eventExtent, position, location, oldType, oldBlock);
// No clear way to get container content data from within the WorldEdit API
// Data may be available by converting oldBlock.toBaseBlock().getNbtData()
// e.g. BaseBlock block = eventWorld.getBlock(position);
ItemStack[] containerData = Util.getContainerContents(oldType, null, location);
if (eventExtent.setBlock(position, block)) {
WorldEditLogger.postProcess(eventExtent, eventActor, position, location, block, baseBlock, oldType, oldBlock, containerData);
return true;
}
return false;
}
use of com.sk89q.worldedit.world.block.BlockState in project FastAsyncWorldEdit by IntellectualSites.
the class AngleColorPattern method apply.
@Override
public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException {
BlockState block = get.getBlock(extent);
int slope = getSlope(block, get, extent);
if (slope == -1) {
return false;
}
BlockType type = block.getBlockType();
int color;
if (type == BlockTypes.GRASS_BLOCK) {
color = holder.getTextureUtil().getColor(extent.getBiome(get));
} else {
color = holder.getTextureUtil().getColor(type);
}
if (color == 0) {
return false;
}
int newColor = getColor(color, slope);
BlockType newBlock = holder.getTextureUtil().getNearestBlock(newColor);
if (newBlock == null) {
return false;
}
return set.setBlock(extent, newBlock.getDefaultState());
}
use of com.sk89q.worldedit.world.block.BlockState in project FastAsyncWorldEdit by IntellectualSites.
the class AngleColorPattern method getSlope.
@Override
public <T extends BlockStateHolder<T>> int getSlope(T block, BlockVector3 vector, Extent extent) {
int slope = super.getSlope(block, vector, extent);
if (slope != -1) {
int x = vector.getBlockX();
int y = vector.getBlockY();
int z = vector.getBlockZ();
int height = extent.getNearestSurfaceTerrainBlock(x, z, y, minY, maxY);
if (height > minY) {
BlockState below = extent.getBlock(x, height - 1, z);
if (!below.getBlockType().getMaterial().isMovementBlocker()) {
return Integer.MAX_VALUE;
}
}
}
return slope;
}
use of com.sk89q.worldedit.world.block.BlockState in project FastAsyncWorldEdit by IntellectualSites.
the class LayerBrushMask method test.
@Override
public boolean test(BlockVector3 pos) {
int depth = (visitor.getDepth() + 1) % layers.length;
if (depth > 1) {
boolean found = false;
BlockState previous = layers[depth - 1];
BlockState previous2 = layers[depth - 2];
for (BlockVector3 dir : BreadthFirstSearch.DEFAULT_DIRECTIONS) {
mutable.setComponents(pos.getBlockX() + dir.getBlockX(), pos.getBlockY() + dir.getBlockY(), pos.getBlockZ() + dir.getBlockZ());
if (visitor.isVisited(mutable) && editSession.getBlock(mutable.getBlockX(), mutable.getBlockY(), mutable.getBlockZ()) == previous) {
mutable.setComponents(pos.getBlockX() + dir.getBlockX() * 2, pos.getBlockY() + dir.getBlockY() * 2, pos.getBlockZ() + dir.getBlockZ() * 2);
if (visitor.isVisited(mutable) && editSession.getBlock(mutable.getBlockX(), mutable.getBlockY(), mutable.getBlockZ()) == previous2) {
found = true;
break;
} else {
return false;
}
}
}
if (!found) {
return false;
}
}
return !adjacent.test(pos);
}
use of com.sk89q.worldedit.world.block.BlockState in project FastAsyncWorldEdit by IntellectualSites.
the class BlockTransformExtent method transformState.
private static int transformState(BlockState state, Transform transform) {
int newMaskedId = state.getInternalId();
BlockType type = state.getBlockType();
// Rotate North, East, South, West
if (type.hasProperty(PropertyKey.NORTH) && type.hasProperty(PropertyKey.EAST) && type.hasProperty(PropertyKey.SOUTH) && type.hasProperty(PropertyKey.WEST)) {
BlockState tmp = state;
for (Map.Entry<Direction, PropertyKey> entry : directionMap.entrySet()) {
Direction newDir = findClosest(transform.apply(entry.getKey().toVector()), Flag.CARDINAL);
if (newDir != null) {
Object dirState = state.getState(entry.getValue());
tmp = tmp.with(directionMap.get(newDir), dirState);
}
}
newMaskedId = tmp.getInternalId();
}
// True if relying on two different "directions" for the result, e.g. stairs with both facing and shape
for (AbstractProperty property : (List<AbstractProperty<?>>) type.getProperties()) {
if (isDirectional(property)) {
long[] directions = getDirections(property);
if (directions != null) {
int oldIndex = property.getIndex(state.getInternalId());
if (oldIndex >= directions.length) {
if (Settings.settings().ENABLED_COMPONENTS.DEBUG) {
LOGGER.warn(String.format("Index outside direction array length found for block:{%s} property:{%s}", state.getBlockType().getId(), property.getName()));
}
continue;
}
Integer newIndex = getNewStateIndex(transform, directions, oldIndex);
if (newIndex != null) {
newMaskedId = property.modifyIndex(newMaskedId, newIndex);
}
}
}
}
return newMaskedId;
}
Aggregations