use of com.sk89q.worldedit.world.block.BlockType in project FastAsyncWorldEdit by IntellectualSites.
the class SimpleBukkitAdapter method adapt.
/**
* Create a Bukkit BlockData from a WorldEdit BlockStateHolder
*
* @param block The WorldEdit BlockStateHolder
* @return The Bukkit BlockData
*/
@Override
public <B extends BlockStateHolder<B>> BlockData adapt(B block) {
try {
checkNotNull(block);
int typeId = block.getInternalBlockTypeId();
BlockData[] dataCache = blockDataCache[typeId];
if (dataCache == null) {
BlockType type = BlockTypes.get(typeId);
blockDataCache[typeId] = dataCache = new BlockData[type.getMaxStateId() + 1];
}
int propId = block.getInternalPropertiesId();
BlockData blockData = dataCache[propId];
if (blockData == null) {
dataCache[propId] = blockData = Bukkit.createBlockData(block.getAsString());
}
return blockData;
} catch (NullPointerException e) {
if (init()) {
return adapt(block);
}
throw e;
}
}
use of com.sk89q.worldedit.world.block.BlockType 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;
}
use of com.sk89q.worldedit.world.block.BlockType in project FastAsyncWorldEdit by IntellectualSites.
the class DataValidatorExtent method setBlock.
@Override
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 location, B block) throws WorldEditException {
final int y = location.getBlockY();
final BlockType type = block.getBlockType();
if (y < world.getMinY() || y > world.getMaxY()) {
return false;
}
// No invalid blocks
if (type == null) {
return false;
}
return super.setBlock(location, block);
}
use of com.sk89q.worldedit.world.block.BlockType in project FastAsyncWorldEdit by IntellectualSites.
the class BannerBlockCompatibilityHandler method updateNBT.
@Override
public <B extends BlockStateHolder<B>> BlockStateHolder<?> updateNBT(B block, Map<String, Tag> values) {
Tag typeTag = values.get("Base");
if (typeTag instanceof IntTag) {
boolean isWall = block.getBlockType() == BlockTypes.WHITE_WALL_BANNER;
String bannerType = convertBannerType(((IntTag) typeTag).getValue(), isWall);
if (bannerType != null) {
BlockType type = BlockTypes.get("minecraft:" + bannerType);
if (type != null) {
BlockState state = type.getDefaultState();
if (isWall) {
Property<Direction> facingProp = type.getProperty("facing");
state = state.with(facingProp, block.getState(FacingProperty));
} else {
Property<Integer> rotationProp = type.getProperty("rotation");
state = state.with(rotationProp, block.getState(RotationProperty));
}
values.remove("Base");
Tag patternsTag = values.get("Patterns");
if (patternsTag instanceof ListTag) {
List<Tag> tempList = new ArrayList<>();
for (Tag pattern : ((ListTag) patternsTag).getValue()) {
if (pattern instanceof CompoundTag) {
Map<String, Tag> patternMap = ((CompoundTag) pattern).getValue();
Tag colorTag = patternMap.get("Color");
CompoundTagBuilder builder = CompoundTagBuilder.create();
builder.putAll(patternMap);
if (colorTag instanceof IntTag) {
builder.putInt("Color", 15 - ((IntTag) colorTag).getValue());
}
tempList.add(builder.build());
} else {
tempList.add(pattern);
}
}
values.put("Patterns", new ListTag(((ListTag) patternsTag).getType(), tempList));
}
return state;
}
}
}
return block;
}
use of com.sk89q.worldedit.world.block.BlockType in project FastAsyncWorldEdit by IntellectualSites.
the class Extent method getBlockDistributionWithData.
/**
* Get the block distribution (with data values) inside a region.
*
* @param region a region
* @return the results
*/
default List<Countable<BlockState>> getBlockDistributionWithData(final Region region) {
int[][] counter = new int[BlockTypes.size()][];
for (final BlockVector3 pt : region) {
BlockState blk = this.getBlock(pt);
BlockType type = blk.getBlockType();
if (type == BlockTypes.__RESERVED__) {
int[] stateCounter = counter[1];
if (stateCounter == null) {
counter[1] = stateCounter = new int[BlockTypes.AIR.getMaxStateId() + 1];
}
stateCounter[BlockTypes.AIR.getDefaultState().getInternalPropertiesId()]++;
}
int[] stateCounter = counter[type.getInternalId()];
if (stateCounter == null) {
counter[type.getInternalId()] = stateCounter = new int[type.getMaxStateId() + 1];
}
stateCounter[blk.getInternalPropertiesId()]++;
}
List<Countable<BlockState>> distribution = new ArrayList<>();
for (int typeId = 0; typeId < counter.length; typeId++) {
BlockType type = BlockTypes.get(typeId);
int[] stateCount = counter[typeId];
if (stateCount != null) {
for (int propId = 0; propId < stateCount.length; propId++) {
int count = stateCount[propId];
if (count != 0) {
BlockState state = type.withPropertyId(propId);
distribution.add(new Countable<>(state, count));
}
}
}
}
// Collections.reverse(distribution);
return distribution;
}
Aggregations