use of com.sk89q.worldedit.world.block.BlockType in project FastAsyncWorldEdit by IntellectualSites.
the class AverageColorPattern method apply.
@Override
public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException {
BlockType blockType = get.getBlock(extent).getBlockType();
TextureUtil util = holder.getTextureUtil();
int currentColor;
if (blockType == BlockTypes.GRASS_BLOCK) {
currentColor = holder.getTextureUtil().getColor(extent.getBiome(get));
} else {
currentColor = holder.getTextureUtil().getColor(blockType);
}
if (currentColor == 0) {
return false;
}
int newColor = TextureUtil.averageColor(currentColor, color);
BlockType newBlock = util.getNearestBlock(newColor);
if (newBlock == blockType) {
return false;
}
return set.setBlock(extent, newBlock.getDefaultState());
}
use of com.sk89q.worldedit.world.block.BlockType in project FastAsyncWorldEdit by IntellectualSites.
the class DesaturatePattern method apply.
@Override
public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException {
BlockType type = get.getBlock(extent).getBlockType();
TextureUtil util = holder.getTextureUtil();
int color;
if (type == BlockTypes.GRASS_BLOCK) {
color = holder.getTextureUtil().getColor(extent.getBiome(get));
} else {
color = holder.getTextureUtil().getColor(type);
}
int newColor = getColor(color);
if (newColor == color) {
return false;
}
BlockType newType = util.getNextNearestBlock(newColor);
if (type.equals(newType)) {
return false;
}
return set.setBlock(extent, newType.getDefaultState());
}
use of com.sk89q.worldedit.world.block.BlockType in project FastAsyncWorldEdit by IntellectualSites.
the class BedBlockCompatibilityHandler method updateNBT.
@Override
public <B extends BlockStateHolder<B>> BlockStateHolder<?> updateNBT(B block, Map<String, Tag> values) {
Tag typeTag = values.get("color");
if (typeTag instanceof IntTag) {
String bedType = convertBedType(((IntTag) typeTag).getValue());
if (bedType != null) {
BlockType type = BlockTypes.get("minecraft:" + bedType);
if (type != null) {
BlockState state = type.getDefaultState();
Property<Direction> facingProp = type.getProperty("facing");
state = state.with(facingProp, block.getState(FACING_PROPERTY));
Property<Boolean> occupiedProp = type.getProperty("occupied");
state = state.with(occupiedProp, false);
Property<String> partProp = type.getProperty("part");
state = state.with(partProp, block.getState(PART_PROPERTY));
values.remove("color");
return state;
}
}
}
return block;
}
use of com.sk89q.worldedit.world.block.BlockType in project FastAsyncWorldEdit by IntellectualSites.
the class FlowerPotCompatibilityHandler method convertLegacyBlockType.
private BlockState convertLegacyBlockType(String id, int data) {
int newId = 0;
switch(id) {
case "minecraft:red_flower":
// now poppy
newId = 38;
break;
case "minecraft:yellow_flower":
// now dandelion
newId = 37;
break;
case "minecraft:sapling":
// oak_sapling
newId = 6;
break;
case "minecraft:deadbush":
case "minecraft:tallgrass":
// dead_bush with fern and grass (not 32!)
newId = 31;
break;
default:
break;
}
String plantedName = null;
if (newId == 0 && id.startsWith("minecraft:")) {
plantedName = id.substring(10);
} else {
BlockState plantedWithData = LegacyMapper.getInstance().getBlockFromLegacy(newId, data);
if (plantedWithData != null) {
// remove "minecraft:"
plantedName = plantedWithData.getBlockType().getId().substring(10);
}
}
if (plantedName != null) {
BlockType potAndPlanted = BlockTypes.get("minecraft:potted_" + plantedName);
if (potAndPlanted != null) {
return potAndPlanted.getDefaultState();
}
}
return null;
}
use of com.sk89q.worldedit.world.block.BlockType in project FastAsyncWorldEdit by IntellectualSites.
the class SkullBlockCompatibilityHandler method updateNBT.
@Override
public <B extends BlockStateHolder<B>> BlockStateHolder<?> updateNBT(B block, Map<String, Tag> values) {
boolean isWall = block.getBlockType() == BlockTypes.SKELETON_WALL_SKULL;
Tag typeTag = values.get("SkullType");
if (typeTag instanceof ByteTag) {
String skullType = convertSkullType(((ByteTag) typeTag).getValue(), isWall);
if (skullType != null) {
BlockType type = BlockTypes.get("minecraft:" + skullType);
if (type != null) {
BlockState state = type.getDefaultState();
if (isWall) {
Property<Direction> newProp = type.getProperty("facing");
state = state.with(newProp, block.getState(FacingProperty));
} else {
Tag rotTag = values.get("Rot");
if (rotTag instanceof ByteTag) {
Property<Integer> newProp = type.getProperty("rotation");
state = state.with(newProp, (int) ((ByteTag) rotTag).getValue());
}
}
values.remove("SkullType");
values.remove("Rot");
return state;
}
}
}
return block;
}
Aggregations