use of com.sk89q.worldedit.world.biome.BiomeType in project FastAsyncWorldEdit by IntellectualSites.
the class ArbitraryBiomeShape method generate.
/**
* Generates the shape.
*
* @param editSession The EditSession to use.
* @param baseBiome The default biome type.
* @param hollow Specifies whether to generate a hollow shape.
* @return number of affected blocks.
*/
public int generate(EditSession editSession, BiomeType baseBiome, boolean hollow) {
int affected = 0;
for (BlockVector3 position : getExtent()) {
int x = position.getBlockX();
int y = position.getBlockY();
int z = position.getBlockZ();
if (!hollow) {
final BiomeType material = getBiome(x, y, z, baseBiome);
if (material != null) {
editSession.setBiome(position, material);
++affected;
}
continue;
}
final BiomeType material = getBiomeCached(x, y, z, baseBiome);
if (material == null) {
continue;
}
if (!shouldDraw(x, y, z, material)) {
continue;
}
editSession.setBiome(position, material);
++affected;
}
return affected;
}
use of com.sk89q.worldedit.world.biome.BiomeType in project FastAsyncWorldEdit by IntellectualSites.
the class ArbitraryBiomeShape method getBiomeCached.
private BiomeType getBiomeCached(int x, int y, int z, BiomeType baseBiome) {
final int index = (y - cacheOffsetY) + (z - cacheOffsetZ) * cacheSizeY + (x - cacheOffsetX) * cacheSizeY * cacheSizeZ;
if (!isCached.get(index)) {
final BiomeType material = getBiome(x, y, z, baseBiome);
isCached.set(index);
cache[index] = material;
return material;
}
return cache[index];
}
use of com.sk89q.worldedit.world.biome.BiomeType in project FastAsyncWorldEdit by IntellectualSites.
the class PlotSetBiome method execute.
@Override
public CompletableFuture<Boolean> execute(final PlotPlayer<?> player, String[] args, RunnableVal3<Command, Runnable, Runnable> confirm, RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
final Plot plot = check(player.getCurrentPlot(), TranslatableCaption.of("errors.not_in_plot"));
checkTrue(plot.isOwner(player.getUUID()) || Permissions.hasPermission(player, "plots.admin.command.generatebiome"), TranslatableCaption.of("permission.no_plot_perms"));
if (plot.getRunning() != 0) {
player.sendMessage(TranslatableCaption.of("errors.wait_for_timer"));
return null;
}
checkTrue(args.length == 1, TranslatableCaption.of("commandconfig.command_syntax"), Templates.of("value", getUsage()));
final Set<CuboidRegion> regions = plot.getRegions();
BiomeRegistry biomeRegistry = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getRegistries().getBiomeRegistry();
Collection<BiomeType> knownBiomes = BiomeTypes.values();
final BiomeType biome = Biomes.findBiomeByName(knownBiomes, args[0], biomeRegistry);
if (biome == null) {
String biomes = StringMan.join(BiomeType.REGISTRY.values(), TranslatableCaption.of("blocklist.block_list_separator").getComponent(player));
player.sendMessage(TranslatableCaption.of("biome.need_biome"));
player.sendMessage(TranslatableCaption.of("commandconfig.subcommand_set_options_header"), Templates.of("values", biomes));
return CompletableFuture.completedFuture(false);
}
confirm.run(this, () -> {
if (plot.getRunning() != 0) {
player.sendMessage(TranslatableCaption.of("errors.wait_for_timer"));
return;
}
plot.addRunning();
TaskManager.taskManager().async(() -> {
EditSession session = WorldEdit.getInstance().newEditSessionBuilder().world(BukkitAdapter.adapt(Bukkit.getWorld(plot.getArea().getWorldName()))).checkMemory(false).allowedRegionsEverywhere().actor(BukkitAdapter.adapt(Bukkit.getPlayer(player.getUUID()))).limitUnlimited().build();
long seed = ThreadLocalRandom.current().nextLong();
for (CuboidRegion region : regions) {
session.regenerate(region, biome, seed);
}
session.flushQueue();
plot.removeRunning();
});
}, null);
return CompletableFuture.completedFuture(true);
}
use of com.sk89q.worldedit.world.biome.BiomeType in project FastAsyncWorldEdit by IntellectualSites.
the class FaweDelegateRegionManager method handleClear.
public boolean handleClear(@Nonnull Plot plot, @Nullable Runnable whenDone, @Nonnull PlotManager manager) {
TaskManager.taskManager().async(() -> {
synchronized (FaweDelegateRegionManager.class) {
final HybridPlotWorld hybridPlotWorld = ((HybridPlotManager) manager).getHybridPlotWorld();
World world = BukkitAdapter.adapt(getWorld(hybridPlotWorld.getWorldName()));
EditSession editSession = WorldEdit.getInstance().newEditSessionBuilder().world(world).checkMemory(false).fastMode(true).limitUnlimited().changeSetNull().build();
if (!hybridPlotWorld.PLOT_SCHEMATIC || !Settings.Schematics.PASTE_ON_TOP) {
final BlockType bedrock;
final BlockType air = BlockTypes.AIR;
if (hybridPlotWorld.PLOT_BEDROCK) {
bedrock = BlockTypes.BEDROCK;
} else {
bedrock = air;
}
final Pattern filling = hybridPlotWorld.MAIN_BLOCK.toPattern();
final Pattern plotfloor = hybridPlotWorld.TOP_BLOCK.toPattern();
final BiomeType biome = hybridPlotWorld.getPlotBiome();
BlockVector3 pos1 = plot.getBottomAbs().getBlockVector3();
BlockVector3 pos2 = pos1.add(BlockVector3.at(hybridPlotWorld.PLOT_WIDTH - 1, hybridPlotWorld.getMaxGenHeight(), hybridPlotWorld.PLOT_WIDTH - 1));
if (hybridPlotWorld.PLOT_BEDROCK) {
Region bedrockRegion = new CuboidRegion(pos1, pos2.withY(hybridPlotWorld.getMinGenHeight()));
editSession.setBlocks(bedrockRegion, bedrock);
}
Region fillingRegion = new CuboidRegion(pos1.withY(hybridPlotWorld.getMinGenHeight() + 1), pos2.withY(hybridPlotWorld.PLOT_HEIGHT - 1));
Region floorRegion = new CuboidRegion(pos1.withY(hybridPlotWorld.PLOT_HEIGHT), pos2.withY(hybridPlotWorld.PLOT_HEIGHT));
Region airRegion = new CuboidRegion(pos1.withY(hybridPlotWorld.PLOT_HEIGHT + 1), pos2.withY(hybridPlotWorld.getMaxGenHeight()));
editSession.setBlocks(fillingRegion, filling);
editSession.setBlocks(floorRegion, plotfloor);
editSession.setBlocks(airRegion, air);
}
if (hybridPlotWorld.PLOT_SCHEMATIC) {
// We cannot reuse the editsession
EditSession scheditsession = !Settings.Schematics.PASTE_ON_TOP ? editSession : WorldEdit.getInstance().newEditSessionBuilder().world(world).checkMemory(false).fastMode(true).limitUnlimited().changeSetNull().build();
File schematicFile = new File(hybridPlotWorld.getRoot(), "plot.schem");
if (!schematicFile.exists()) {
schematicFile = new File(hybridPlotWorld.getRoot(), "plot.schematic");
}
BlockVector3 to = plot.getBottomAbs().getBlockVector3().withY(Settings.Schematics.PASTE_ON_TOP ? hybridPlotWorld.SCHEM_Y : hybridPlotWorld.getMinBuildHeight());
try {
Clipboard clip = ClipboardFormats.findByFile(schematicFile).getReader(new FileInputStream(schematicFile)).read();
clip.paste(scheditsession, to, true, true, true);
} catch (IOException e) {
e.printStackTrace();
}
// Be verbose in editsession flushing
scheditsession.flushQueue();
}
editSession.flushQueue();
FaweAPI.fixLighting(world, new CuboidRegion(plot.getBottomAbs().getBlockVector3(), plot.getTopAbs().getBlockVector3()), null, RelightMode.valueOf(com.fastasyncworldedit.core.configuration.Settings.settings().LIGHTING.MODE));
if (whenDone != null) {
TaskManager.taskManager().task(whenDone);
}
}
});
return true;
}
use of com.sk89q.worldedit.world.biome.BiomeType in project FastAsyncWorldEdit by IntellectualSites.
the class SpongeSchematicReader method readBiomes.
private void readBiomes(BlockArrayClipboard clipboard, Map<String, Tag> schematic) throws IOException {
ByteArrayTag dataTag = requireTag(schematic, "BiomeData", ByteArrayTag.class);
IntTag maxTag = requireTag(schematic, "BiomePaletteMax", IntTag.class);
CompoundTag paletteTag = requireTag(schematic, "BiomePalette", CompoundTag.class);
Map<Integer, BiomeType> palette = new HashMap<>();
if (maxTag.getValue() != paletteTag.getValue().size()) {
throw new IOException("Biome palette size does not match expected size.");
}
for (Entry<String, Tag> palettePart : paletteTag.getValue().entrySet()) {
String key = palettePart.getKey();
if (fixer != null) {
key = fixer.fixUp(DataFixer.FixTypes.BIOME, key, dataVersion);
}
BiomeType biome = BiomeTypes.get(key);
if (biome == null) {
LOGGER.warn("Unknown biome type :" + key + " in palette. Are you missing a mod or using a schematic made in a newer version of Minecraft?");
}
Tag idTag = palettePart.getValue();
if (!(idTag instanceof IntTag)) {
throw new IOException("Biome mapped to non-Int tag.");
}
palette.put(((IntTag) idTag).getValue(), biome);
}
int width = clipboard.getDimensions().getX();
byte[] biomes = dataTag.getValue();
int biomeIndex = 0;
int biomeJ = 0;
int bVal;
int varIntLength;
BlockVector3 min = clipboard.getMinimumPoint();
while (biomeJ < biomes.length) {
bVal = 0;
varIntLength = 0;
while (true) {
bVal |= (biomes[biomeJ] & 127) << (varIntLength++ * 7);
if (varIntLength > 5) {
throw new IOException("VarInt too big (probably corrupted data)");
}
if (((biomes[biomeJ] & 128) != 128)) {
biomeJ++;
break;
}
biomeJ++;
}
int z = biomeIndex / width;
int x = biomeIndex % width;
BiomeType type = palette.get(bVal);
for (int y = 0; y < clipboard.getRegion().getHeight(); y++) {
clipboard.setBiome(min.add(x, y, z), type);
}
biomeIndex++;
}
}
Aggregations