use of com.sk89q.worldedit.world.block.BlockType in project FastAsyncWorldEdit by IntellectualSites.
the class TextureUtil method fromClipboard.
public static TextureUtil fromClipboard(Clipboard clipboard) throws FileNotFoundException {
boolean[] ids = new boolean[BlockTypes.size()];
for (BlockVector3 pt : clipboard.getRegion()) {
ids[clipboard.getBlock(pt).getInternalBlockTypeId()] = true;
}
HashSet<BlockType> blocks = new HashSet<>();
for (int typeId = 0; typeId < ids.length; typeId++) {
if (ids[typeId]) {
blocks.add(BlockTypes.get(typeId));
}
}
return fromBlocks(blocks);
}
use of com.sk89q.worldedit.world.block.BlockType in project FastAsyncWorldEdit by IntellectualSites.
the class TextureUtil method getIsBlockCloserThanBiome.
protected boolean getIsBlockCloserThanBiome(char[] blockAndBiomeIdOutput, int color, int biomePriority) {
BlockType block = getNearestBlock(color);
TextureUtil.BiomeColor biome = getNearestBiome(color);
int blockColor = getColor(block);
blockAndBiomeIdOutput[0] = block.getDefaultState().getOrdinalChar();
blockAndBiomeIdOutput[1] = (char) biome.id;
return colorDistance(biome.grassCombined, color) - biomePriority > colorDistance(blockColor, color);
}
use of com.sk89q.worldedit.world.block.BlockType in project FastAsyncWorldEdit by IntellectualSites.
the class RandomTextureUtil method getNearestBlock.
@Override
public BlockType getNearestBlock(int color) {
int offsetColor = offsets.getOrDefault((Object) color, 0);
if (offsetColor != 0) {
offsetColor = addRandomColor(color, offsetColor);
} else {
offsetColor = color;
}
BlockType res = super.getNearestBlock(offsetColor);
if (res == null) {
return null;
}
int newColor = getColor(res);
byte dr = (byte) (((color >> 16) & 0xFF) - ((newColor >> 16) & 0xFF));
byte dg = (byte) (((color >> 8) & 0xFF) - ((newColor >> 8) & 0xFF));
byte db = (byte) (((color >> 0) & 0xFF) - ((newColor >> 0) & 0xFF));
offsets.put(color, (Integer) ((dr << 16) + (dg << 8) + (db << 0)));
return res;
}
use of com.sk89q.worldedit.world.block.BlockType in project FastAsyncWorldEdit by IntellectualSites.
the class PropertyGroup method get.
public <B extends BlockStateHolder<B>> G get(BlockStateHolder<B> state) {
BlockType type = state.getBlockType();
PropertyFunction func = states[type.getInternalId()];
if (func == null) {
return defaultValue;
}
Object value = state.getState(func.key);
return (G) func.getFunc.apply(value);
}
use of com.sk89q.worldedit.world.block.BlockType in project FastAsyncWorldEdit by IntellectualSites.
the class MinecraftStructure method read.
@Override
public Clipboard read(UUID clipboardId) throws IOException {
NamedTag rootTag = inputStream.readNamedTag();
// MC structures are all unnamed, but this doesn't seem to be necessary? might remove this later
if (!rootTag.getName().isEmpty()) {
throw new IOException("Root tag has name - are you sure this is a structure?");
}
Map<String, Tag> tags = ((CompoundTag) rootTag.getTag()).getValue();
ListTag size = (ListTag) tags.get("size");
int width = size.getInt(0);
int height = size.getInt(1);
int length = size.getInt(2);
// Init clipboard
BlockVector3 origin = BlockVector3.at(0, 0, 0);
CuboidRegion region = new CuboidRegion(origin, origin.add(width, height, length).subtract(BlockVector3.ONE));
Clipboard clipboard = new BlockArrayClipboard(region, clipboardId);
// Blocks
ListTag blocks = (ListTag) tags.get("blocks");
if (blocks != null) {
// Palette
List<CompoundTag> palette = (List<CompoundTag>) tags.get("palette").getValue();
BlockState[] combinedArray = new BlockState[palette.size()];
for (int i = 0; i < palette.size(); i++) {
CompoundTag compound = palette.get(i);
Map<String, Tag> map = compound.getValue();
String name = ((StringTag) map.get("Name")).getValue();
BlockType type = BlockTypes.get(name);
BlockState state = type.getDefaultState();
CompoundTag properties = (CompoundTag) map.get("Properties");
if (properties != null) {
for (Map.Entry<String, Tag> entry : properties.getValue().entrySet()) {
String key = entry.getKey();
String value = ((StringTag) entry.getValue()).getValue();
Property<Object> property = type.getProperty(key);
state = state.with(property, property.getValueFor(value));
}
}
combinedArray[i] = state;
}
// Populate blocks
List<CompoundTag> blocksList = (List<CompoundTag>) tags.get("blocks").getValue();
try {
for (CompoundTag compound : blocksList) {
Map<String, Tag> blockMap = compound.getValue();
IntTag stateTag = (IntTag) blockMap.get("state");
ListTag posTag = (ListTag) blockMap.get("pos");
BlockState state = combinedArray[stateTag.getValue()];
int x = posTag.getInt(0);
int y = posTag.getInt(1);
int z = posTag.getInt(2);
if (state.getBlockType().getMaterial().hasContainer()) {
CompoundTag nbt = (CompoundTag) blockMap.get("nbt");
if (nbt != null) {
BaseBlock block = state.toBaseBlock(nbt);
clipboard.setBlock(x, y, z, block);
continue;
}
}
clipboard.setBlock(x, y, z, state);
}
} catch (Exception e) {
e.printStackTrace();
}
}
// Entities
ListTag entities = (ListTag) tags.get("entities");
if (entities != null) {
List<CompoundTag> entityList = (List<CompoundTag>) (List<?>) entities.getValue();
for (CompoundTag entityEntry : entityList) {
Map<String, Tag> entityEntryMap = entityEntry.getValue();
ListTag posTag = (ListTag) entityEntryMap.get("pos");
CompoundTag nbtTag = (CompoundTag) entityEntryMap.get("nbt");
String id = nbtTag.getString("Id");
Location location = NBTConversions.toLocation(clipboard, posTag, nbtTag.getListTag("Rotation"));
if (!id.isEmpty()) {
BaseEntity state = new BaseEntity(EntityTypes.get(id), nbtTag);
clipboard.createEntity(location, state);
}
}
}
return clipboard;
}
Aggregations