use of com.sk89q.worldedit.world.block.BlockType in project FastAsyncWorldEdit by IntellectualSites.
the class MinecraftStructure method write.
public void write(Clipboard clipboard, String owner) throws IOException {
Region region = clipboard.getRegion();
int width = region.getWidth();
int height = region.getHeight();
int length = region.getLength();
if (width > WARN_SIZE || height > WARN_SIZE || length > WARN_SIZE) {
LOGGER.info("A structure longer than 32 is unsupported by minecraft (but probably still works)");
}
Map<String, Object> structure = FaweCache.INSTANCE.asMap("version", 1, "author", owner);
// ignored: version / owner
Int2ObjectArrayMap<Integer> indexes = new Int2ObjectArrayMap<>();
// Size
structure.put("size", Arrays.asList(width, height, length));
// Palette
ArrayList<HashMap<String, Object>> palette = new ArrayList<>();
for (BlockVector3 point : region) {
BlockState block = clipboard.getBlock(point);
int combined = block.getInternalId();
BlockType type = block.getBlockType();
if (type == BlockTypes.STRUCTURE_VOID || indexes.containsKey(combined)) {
continue;
}
indexes.put(combined, (Integer) palette.size());
HashMap<String, Object> paletteEntry = new HashMap<>();
paletteEntry.put("Name", type.getId());
if (block.getInternalId() != type.getInternalId()) {
Map<String, Object> properties = null;
for (AbstractProperty property : (List<AbstractProperty<?>>) type.getProperties()) {
int propIndex = property.getIndex(block.getInternalId());
if (propIndex != 0) {
if (properties == null) {
properties = new HashMap<>();
}
Object value = property.getValues().get(propIndex);
properties.put(property.getName(), value.toString());
}
}
if (properties != null) {
paletteEntry.put("Properties", properties);
}
}
palette.add(paletteEntry);
}
if (!palette.isEmpty()) {
structure.put("palette", palette);
}
// Blocks
ArrayList<Map<String, Object>> blocks = new ArrayList<>();
BlockVector3 min = region.getMinimumPoint();
for (BlockVector3 point : region) {
BaseBlock block = clipboard.getFullBlock(point);
if (block.getBlockType() != BlockTypes.STRUCTURE_VOID) {
int combined = block.getInternalId();
int index = indexes.get(combined);
List<Integer> pos = Arrays.asList(point.getX() - min.getX(), point.getY() - min.getY(), point.getZ() - min.getZ());
if (!block.hasNbtData()) {
blocks.add(FaweCache.INSTANCE.asMap("state", index, "pos", pos));
} else {
blocks.add(FaweCache.INSTANCE.asMap("state", index, "pos", pos, "nbt", block.getNbtData()));
}
}
}
if (!blocks.isEmpty()) {
structure.put("blocks", blocks);
}
// Entities
ArrayList<Map<String, Object>> entities = new ArrayList<>();
for (Entity entity : clipboard.getEntities()) {
Location loc = entity.getLocation();
List<Double> pos = Arrays.asList(loc.getX(), loc.getY(), loc.getZ());
List<Integer> blockPos = Arrays.asList(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
BaseEntity state = entity.getState();
if (state != null) {
CompoundTag nbt = state.getNbtData();
Map<String, Tag> nbtMap = nbt.getValue();
// Replace rotation data
nbtMap.put("Rotation", writeRotation(entity.getLocation()));
nbtMap.put("id", new StringTag(state.getType().getId()));
Map<String, Object> entityMap = FaweCache.INSTANCE.asMap("pos", pos, "blockPos", blockPos, "nbt", nbt);
entities.add(entityMap);
}
}
if (!entities.isEmpty()) {
structure.put("entities", entities);
}
out.writeNamedTag("", FaweCache.INSTANCE.asTag(structure));
close();
}
use of com.sk89q.worldedit.world.block.BlockType in project FastAsyncWorldEdit by IntellectualSites.
the class BrushCommands method sphereBrush.
@Command(name = "sphere", aliases = { "s" }, desc = "Choose the sphere brush")
@CommandPermissions("worldedit.brush.sphere")
public void sphereBrush(Player player, InjectedValueAccess context, @Arg(desc = "The pattern of blocks to set") Pattern pattern, @Arg(desc = "The radius of the sphere", def = "2") Expression radius, @Switch(name = 'h', desc = "Create hollow spheres instead") boolean hollow, @Switch(name = 'f', desc = "Create falling spheres instead") boolean falling) throws WorldEditException {
worldEdit.checkMaxBrushRadius(radius);
Brush brush;
if (hollow) {
brush = new HollowSphereBrush();
} else {
// FAWE start - Suggest different brush material if sand or gravel is used
if (pattern instanceof BlockStateHolder) {
BlockType type = ((BlockStateHolder) pattern).getBlockType();
switch(type.getId()) {
case "minecraft:sand":
case "minecraft:gravel":
player.print(Caption.of("fawe.worldedit.brush.brush.try.other"));
falling = true;
break;
default:
break;
}
}
if (falling) {
brush = new FallingSphere();
} else {
brush = new SphereBrush();
}
}
// FAWE end
set(context, brush, "worldedit.brush.sphere").setSize(radius).setFill(pattern);
}
use of com.sk89q.worldedit.world.block.BlockType in project FastAsyncWorldEdit by IntellectualSites.
the class EditSession method thaw.
/**
* Thaw blocks in a cylinder.
*
* @param position the position
* @param radius the radius
* @param height the height (upwards and downwards)
* @return number of blocks affected
* @throws MaxChangedBlocksException thrown if too many blocks are changed
*/
public int thaw(BlockVector3 position, double radius, int height) throws MaxChangedBlocksException {
int affected = 0;
double radiusSq = radius * radius;
int ox = position.getBlockX();
int oy = position.getBlockY();
int oz = position.getBlockZ();
BlockState air = BlockTypes.AIR.getDefaultState();
BlockState water = BlockTypes.WATER.getDefaultState();
int centerY = Math.max(minY, Math.min(maxY, oy));
int minY = Math.max(this.minY, centerY - height);
int maxY = Math.min(this.maxY, centerY + height);
// FAWE start - mutable
MutableBlockVector3 mutable = new MutableBlockVector3();
MutableBlockVector3 mutable2 = new MutableBlockVector3();
// FAWE end
int ceilRadius = (int) Math.ceil(radius);
for (int x = ox - ceilRadius; x <= ox + ceilRadius; ++x) {
for (int z = oz - ceilRadius; z <= oz + ceilRadius; ++z) {
// FAWE start - mutable
if ((mutable.setComponents(x, oy, z)).distanceSq(position) > radiusSq) {
// FAWE end
continue;
}
for (int y = maxY; y > minY; --y) {
// FAWE start - mutable
mutable.setComponents(x, y, z);
mutable2.setComponents(x, y - 1, z);
BlockType id = getBlock(mutable).getBlockType();
if (id == BlockTypes.ICE) {
if (setBlock(mutable, water)) {
++affected;
}
} else if (id == BlockTypes.SNOW) {
// FAWE start
if (setBlock(mutable, air)) {
if (y > getMinY()) {
BlockState block = getBlock(mutable2);
if (block.getStates().containsKey(snowy)) {
if (setBlock(mutable2, block.with(snowy, false))) {
affected++;
}
}
}
// FAWE end
++affected;
}
} else if (id.getMaterial().isAir()) {
continue;
}
break;
}
}
}
return affected;
}
use of com.sk89q.worldedit.world.block.BlockType in project FastAsyncWorldEdit by IntellectualSites.
the class WorldEdit method flushBlockBag.
/**
* Flush a block bag's changes to a player.
*
* @param actor the actor
* @param editSession the edit session
*/
public void flushBlockBag(Actor actor, EditSession editSession) {
BlockBag blockBag = editSession.getBlockBag();
if (blockBag != null) {
blockBag.flushChanges();
}
Map<BlockType, Integer> missingBlocks = editSession.popMissingBlocks();
if (!missingBlocks.isEmpty()) {
TextComponent.Builder str = TextComponent.builder();
str.append("Missing these blocks: ");
int size = missingBlocks.size();
int i = 0;
for (Map.Entry<BlockType, Integer> blockTypeIntegerEntry : missingBlocks.entrySet()) {
str.append((blockTypeIntegerEntry.getKey()).getRichName());
str.append(" [Amt: ").append(String.valueOf(blockTypeIntegerEntry.getValue())).append("]");
++i;
if (i != size) {
str.append(", ");
}
}
actor.printError(str.build());
}
}
use of com.sk89q.worldedit.world.block.BlockType in project WorldGuard by EngineHub.
the class WorldConfiguration method convertLegacyBlock.
public String convertLegacyBlock(String legacy) {
String[] splitter = legacy.split(":", 2);
try {
int id;
byte data;
if (splitter.length == 1) {
id = Integer.parseInt(splitter[0]);
data = 0;
} else {
id = Integer.parseInt(splitter[0]);
data = Byte.parseByte(splitter[1]);
}
BlockState legacyBlock = LegacyMapper.getInstance().getBlockFromLegacy(id, data);
if (legacyBlock != null) {
return legacyBlock.getBlockType().getId();
}
} catch (NumberFormatException ignored) {
}
final BlockType blockType = BlockTypes.get(legacy);
if (blockType != null) {
return blockType.getId();
}
return null;
}
Aggregations