use of com.sk89q.worldedit.world.biome.BiomeType in project FastAsyncWorldEdit by IntellectualSites.
the class Regenerator method copyToWorld.
private void copyToWorld() {
// Setting Blocks
boolean genbiomes = options.shouldRegenBiomes();
boolean hasBiome = options.hasBiomeType();
BiomeType biome = options.getBiomeType();
if (!genbiomes && !hasBiome) {
target.setBlocks(region, new PlacementPattern());
}
if (hasBiome) {
target.setBlocks(region, new WithBiomePlacementPattern(ignored -> biome));
} else if (genbiomes) {
target.setBlocks(region, new WithBiomePlacementPattern(vec -> source.getBiome(vec)));
}
}
use of com.sk89q.worldedit.world.biome.BiomeType in project FastAsyncWorldEdit by IntellectualSites.
the class BiomePatternParser method parseFromInput.
// overridden to provide $<biome> too
@Override
public Pattern parseFromInput(String input, ParserContext context) throws InputParseException {
if (input.startsWith(BIOME_PREFIX)) {
String biomeId = input.substring(1);
BiomeType biomeType = BiomeTypes.get(biomeId);
if (biomeType == null) {
throw new NoMatchException(Caption.of("worldedit.error.unknown-biome", TextComponent.of(biomeId)));
}
return new BiomeApplyingPattern(context.requireExtent(), biomeType);
} else {
return super.parseFromInput(input, context);
}
}
use of com.sk89q.worldedit.world.biome.BiomeType in project FastAsyncWorldEdit by IntellectualSites.
the class FastSchematicWriter method writeBiomes.
private void writeBiomes(Clipboard clipboard, NBTOutputStream out) throws IOException {
ByteArrayOutputStream biomesCompressed = new ByteArrayOutputStream();
DataOutputStream biomesOut = new DataOutputStream(new LZ4BlockOutputStream(biomesCompressed));
List<Integer> paletteList = new ArrayList<>();
int[] palette = new int[BiomeTypes.getMaxId() + 1];
Arrays.fill(palette, Integer.MAX_VALUE);
int[] paletteMax = { 0 };
IntValueReader task = new IntValueReader() {
@Override
public void applyInt(int index, int ordinal) {
try {
int value = palette[ordinal];
if (value == Integer.MAX_VALUE) {
int size = paletteMax[0]++;
palette[ordinal] = value = size;
paletteList.add(ordinal);
}
IOUtil.writeVarInt(biomesOut, value);
} catch (IOException e) {
e.printStackTrace();
}
}
};
BlockVector3 min = clipboard.getMinimumPoint();
int width = clipboard.getRegion().getWidth();
int length = clipboard.getRegion().getLength();
MutableBlockVector3 mutable = new MutableBlockVector3();
for (int z = 0, i = 0; z < length; z++) {
int z0 = min.getBlockZ() + z;
for (int x = 0; x < width; x++, i++) {
int x0 = min.getBlockX() + x;
BiomeType biome = clipboard.getBiome(mutable.setComponents(x0, min.getY(), z0));
task.applyInt(i, biome.getInternalId());
}
}
biomesOut.close();
out.writeNamedTag("BiomePaletteMax", paletteMax[0]);
out.writeLazyCompoundTag("BiomePalette", out12 -> {
for (int i = 0; i < paletteList.size(); i++) {
int ordinal = paletteList.get(i);
BiomeType state = BiomeTypes.get(ordinal);
out12.writeNamedTag(state.getId(), i);
}
});
out.writeNamedTagName("BiomeData", NBTConstants.TYPE_BYTE_ARRAY);
out.writeInt(biomesOut.size());
try (LZ4BlockInputStream in = new LZ4BlockInputStream(new ByteArrayInputStream(biomesCompressed.toByteArray()))) {
IOUtil.copy(in, (DataOutput) out);
}
}
use of com.sk89q.worldedit.world.biome.BiomeType in project FastAsyncWorldEdit by IntellectualSites.
the class BiomeCommands method biomeInfo.
@Command(name = "biomeinfo", desc = "Get the biome of the targeted block.", descFooter = "By default, uses all blocks in your selection.")
@CommandPermissions("worldedit.biome.info")
public void biomeInfo(Actor actor, World world, LocalSession session, @Switch(name = 't', desc = "Use the block you are looking at.") boolean useLineOfSight, @Switch(name = 'p', desc = "Use the block you are currently in.") boolean usePosition) throws WorldEditException {
BiomeRegistry biomeRegistry = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getRegistries().getBiomeRegistry();
Set<BiomeType> biomes = new HashSet<>();
String messageKey;
if (useLineOfSight) {
if (actor instanceof Player) {
Location blockPosition = ((Player) actor).getBlockTrace(300);
if (blockPosition == null) {
actor.print(Caption.of("worldedit.raytrace.noblock"));
return;
}
BiomeType biome = world.getBiome(blockPosition.toVector().toBlockPoint());
biomes.add(biome);
messageKey = "worldedit.biomeinfo.lineofsight";
} else {
actor.print(Caption.of("worldedit.raytrace.require-player"));
return;
}
} else if (usePosition) {
if (actor instanceof Locatable) {
BiomeType biome = world.getBiome(((Locatable) actor).getLocation().toVector().toBlockPoint());
biomes.add(biome);
messageKey = "worldedit.biomeinfo.position";
} else {
actor.print(Caption.of("worldedit.biomeinfo.not-locatable"));
return;
}
} else {
Region region = session.getSelection(world);
for (BlockVector3 pt : region) {
biomes.add(world.getBiome(pt));
}
messageKey = "worldedit.biomeinfo.selection";
}
List<Component> components = biomes.stream().map(biome -> biomeRegistry.getRichName(biome).hoverEvent(HoverEvent.showText(TextComponent.of(biome.getId())))).collect(Collectors.toList());
actor.print(Caption.of(messageKey, TextUtils.join(components, TextComponent.of(", "))));
}
use of com.sk89q.worldedit.world.biome.BiomeType in project FastAsyncWorldEdit by IntellectualSites.
the class ArbitraryBiomeShape method isInsideCached.
// FAWE start
private boolean isInsideCached(int x, int y, int z, BiomeType baseBiome) {
final int index = (y - cacheOffsetY) + (z - cacheOffsetZ) * cacheSizeY + (x - cacheOffsetX) * cacheSizeY * cacheSizeZ;
final BiomeType cacheEntry = cache[index];
if (cacheEntry == null) {
// unknown block, meaning they must be outside the extent at this stage, but might still be inside the shape
return getBiomeCached(x, y, z, baseBiome) != null;
}
return cacheEntry != BiomeTypes.THE_VOID;
}
Aggregations