2014-04-04 22:03:18 +00:00
|
|
|
/*
|
|
|
|
* WorldEdit, a Minecraft world manipulation toolkit
|
|
|
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
|
|
|
* Copyright (C) WorldEdit team and contributors
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU Lesser General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2014-04-03 02:08:50 +00:00
|
|
|
package com.sk89q.worldedit.command;
|
2012-03-17 15:35:29 +00:00
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
import com.boydti.fawe.config.BBC;
|
|
|
|
import com.boydti.fawe.config.Commands;
|
|
|
|
import com.boydti.fawe.object.FawePlayer;
|
|
|
|
import com.boydti.fawe.object.visitor.Fast2DIterator;
|
|
|
|
import com.boydti.fawe.util.chat.Message;
|
2012-03-17 15:35:29 +00:00
|
|
|
import com.sk89q.minecraft.util.commands.Command;
|
|
|
|
import com.sk89q.minecraft.util.commands.CommandContext;
|
|
|
|
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
2012-12-27 16:45:37 +00:00
|
|
|
import com.sk89q.minecraft.util.commands.Logging;
|
2014-07-17 07:21:13 +00:00
|
|
|
import com.sk89q.worldedit.EditSession;
|
|
|
|
import com.sk89q.worldedit.LocalSession;
|
|
|
|
import com.sk89q.worldedit.WorldEdit;
|
|
|
|
import com.sk89q.worldedit.WorldEditException;
|
2014-06-28 01:04:34 +00:00
|
|
|
import com.sk89q.worldedit.entity.Player;
|
2018-06-19 00:53:15 +00:00
|
|
|
import com.sk89q.worldedit.extension.platform.Capability;
|
2014-07-17 07:21:13 +00:00
|
|
|
import com.sk89q.worldedit.function.FlatRegionFunction;
|
|
|
|
import com.sk89q.worldedit.function.FlatRegionMaskingFilter;
|
2018-08-12 14:03:07 +00:00
|
|
|
import com.sk89q.worldedit.function.RegionFunction;
|
2014-07-17 07:21:13 +00:00
|
|
|
import com.sk89q.worldedit.function.biome.BiomeReplace;
|
2014-06-28 02:55:38 +00:00
|
|
|
import com.sk89q.worldedit.function.mask.Mask;
|
2014-07-17 07:21:13 +00:00
|
|
|
import com.sk89q.worldedit.function.mask.Mask2D;
|
|
|
|
import com.sk89q.worldedit.function.operation.Operations;
|
|
|
|
import com.sk89q.worldedit.function.visitor.FlatRegionVisitor;
|
2018-08-12 14:03:07 +00:00
|
|
|
import com.sk89q.worldedit.function.visitor.RegionVisitor;
|
2018-12-23 16:19:33 +00:00
|
|
|
import com.sk89q.worldedit.math.BlockVector2;
|
|
|
|
import com.sk89q.worldedit.math.BlockVector3;
|
2014-07-17 07:21:13 +00:00
|
|
|
import com.sk89q.worldedit.regions.CuboidRegion;
|
2012-03-17 15:35:29 +00:00
|
|
|
import com.sk89q.worldedit.regions.FlatRegion;
|
|
|
|
import com.sk89q.worldedit.regions.Region;
|
2014-07-17 07:21:13 +00:00
|
|
|
import com.sk89q.worldedit.regions.Regions;
|
2018-08-12 14:03:07 +00:00
|
|
|
import com.sk89q.worldedit.util.Countable;
|
2018-06-16 05:29:48 +00:00
|
|
|
import com.sk89q.worldedit.util.Location;
|
2014-07-17 07:21:13 +00:00
|
|
|
import com.sk89q.worldedit.util.command.binding.Switch;
|
2014-04-05 09:59:38 +00:00
|
|
|
import com.sk89q.worldedit.world.World;
|
2019-04-03 05:53:34 +00:00
|
|
|
import com.sk89q.worldedit.world.biome.BiomeType;
|
2014-07-17 07:21:13 +00:00
|
|
|
import com.sk89q.worldedit.world.biome.BiomeData;
|
2019-02-16 07:27:00 +00:00
|
|
|
import com.sk89q.worldedit.world.biome.BiomeType;
|
2019-04-03 13:25:16 +00:00
|
|
|
import com.sk89q.worldedit.world.biome.BiomeTypes;
|
2014-07-17 07:21:13 +00:00
|
|
|
import com.sk89q.worldedit.world.registry.BiomeRegistry;
|
2014-04-05 09:59:38 +00:00
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
import java.util.ArrayList;
|
2019-02-16 07:27:00 +00:00
|
|
|
import java.util.Collection;
|
2018-08-12 14:03:07 +00:00
|
|
|
import java.util.Collections;
|
2014-04-05 09:59:38 +00:00
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Set;
|
|
|
|
|
2019-04-03 13:25:16 +00:00
|
|
|
import static com.sk89q.minecraft.util.commands.Logging.LogMode.REGION;
|
|
|
|
|
2014-06-28 01:04:34 +00:00
|
|
|
/**
|
|
|
|
* Implements biome-related commands such as "/biomelist".
|
|
|
|
*/
|
2018-08-12 14:03:07 +00:00
|
|
|
@Command(aliases = {}, desc = "Change, list and inspect biomes")
|
|
|
|
public class BiomeCommands extends MethodCommands {
|
2012-03-17 15:35:29 +00:00
|
|
|
|
2014-06-28 01:04:34 +00:00
|
|
|
/**
|
|
|
|
* Create a new instance.
|
|
|
|
*
|
|
|
|
* @param worldEdit reference to WorldEdit
|
|
|
|
*/
|
|
|
|
public BiomeCommands(WorldEdit worldEdit) {
|
2018-08-12 14:03:07 +00:00
|
|
|
super(worldEdit);
|
|
|
|
}
|
|
|
|
|
|
|
|
private BiomeRegistry getBiomeRegistry() {
|
|
|
|
return worldEdit.getPlatformManager().queryCapability(Capability.GAME_HOOKS).getRegistries().getBiomeRegistry();
|
2012-03-17 15:35:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2018-08-12 14:03:07 +00:00
|
|
|
aliases = {"biomelist", "biomels"},
|
|
|
|
usage = "[page]",
|
|
|
|
desc = "Gets all biomes available.",
|
|
|
|
max = 1
|
2012-03-17 15:35:29 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.biome.list")
|
2014-07-17 07:21:13 +00:00
|
|
|
public void biomeList(Player player, CommandContext args) throws WorldEditException {
|
2012-03-17 15:35:29 +00:00
|
|
|
int page;
|
|
|
|
int offset;
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
if (args.argsLength() == 0 || (page = args.getInteger(0)) < 2) {
|
|
|
|
page = 1;
|
|
|
|
offset = 0;
|
|
|
|
} else {
|
|
|
|
offset = (page - 1) * 19;
|
|
|
|
}
|
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
BiomeRegistry biomeRegistry = getBiomeRegistry();
|
2019-04-03 13:25:16 +00:00
|
|
|
List<BiomeType> biomes = BiomeTypes.values();
|
2012-03-17 15:35:29 +00:00
|
|
|
int totalPages = biomes.size() / 19 + 1;
|
2018-08-12 14:03:07 +00:00
|
|
|
Message msg = BBC.BIOME_LIST_HEADER.m(page, totalPages);
|
|
|
|
String setBiome = Commands.getAlias(BiomeCommands.class, "/setbiome");
|
2019-02-16 07:27:00 +00:00
|
|
|
for (BiomeType biome : biomes) {
|
2012-03-17 15:35:29 +00:00
|
|
|
if (offset > 0) {
|
|
|
|
offset--;
|
|
|
|
} else {
|
2014-07-17 07:21:13 +00:00
|
|
|
BiomeData data = biomeRegistry.getData(biome);
|
|
|
|
if (data != null) {
|
2018-08-12 14:03:07 +00:00
|
|
|
msg.newline().text(data.getName()).cmdTip(setBiome + " " + data.getName());
|
2014-07-17 07:21:13 +00:00
|
|
|
} else {
|
2018-08-12 14:03:07 +00:00
|
|
|
msg.newline().text("<? #" + biome.getId() + ">").cmdTip(setBiome + " " + biome.getId());
|
|
|
|
}
|
|
|
|
if (++count == 18) {
|
|
|
|
break;
|
2012-03-17 15:35:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-08-12 14:03:07 +00:00
|
|
|
msg.newline().paginate(getCommand().aliases()[0], page, totalPages);
|
|
|
|
msg.send(player);
|
2012-03-17 15:35:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2018-08-12 14:03:07 +00:00
|
|
|
aliases = {"biomeinfo"},
|
|
|
|
flags = "pt",
|
|
|
|
desc = "Get the biome of the targeted block.",
|
|
|
|
help =
|
|
|
|
"Get the biome of the block.\n" +
|
|
|
|
"By default use all the blocks contained in your selection.\n" +
|
|
|
|
"-t use the block you are looking at.\n" +
|
|
|
|
"-p use the block you are currently in",
|
|
|
|
max = 0
|
2012-03-17 15:35:29 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.biome.info")
|
2018-08-12 14:03:07 +00:00
|
|
|
public void biomeInfo(Player player, LocalSession session, final EditSession editSession, CommandContext args) throws WorldEditException {
|
|
|
|
BiomeRegistry biomeRegistry = getBiomeRegistry();
|
2019-04-03 13:25:16 +00:00
|
|
|
List<BiomeType> values = BiomeTypes.values();
|
|
|
|
final int[] biomes = new int[values.size()];
|
2018-08-12 14:03:07 +00:00
|
|
|
final String qualifier;
|
2014-07-17 07:21:13 +00:00
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
int size = 0;
|
2012-03-28 18:04:59 +00:00
|
|
|
if (args.hasFlag('t')) {
|
2018-06-16 05:29:48 +00:00
|
|
|
Location blockPosition = player.getBlockTrace(300);
|
2012-03-28 18:04:59 +00:00
|
|
|
if (blockPosition == null) {
|
2018-08-12 14:03:07 +00:00
|
|
|
BBC.NO_BLOCK.send(player);
|
2012-03-28 18:04:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-03 05:53:34 +00:00
|
|
|
BiomeType biome = player.getWorld().getBiome(blockPosition.toBlockPoint().toBlockVector2());
|
|
|
|
biomes[biome.getInternalId()]++;
|
2018-08-12 14:03:07 +00:00
|
|
|
size = 1;
|
2012-03-28 18:04:59 +00:00
|
|
|
} else if (args.hasFlag('p')) {
|
2019-04-03 05:53:34 +00:00
|
|
|
BiomeType biome = player.getWorld().getBiome(player.getLocation().toBlockPoint().toBlockVector2());
|
|
|
|
biomes[biome.getInternalId()]++;
|
2018-08-12 14:03:07 +00:00
|
|
|
size = 1;
|
2012-03-28 18:04:59 +00:00
|
|
|
} else {
|
2014-04-05 09:59:38 +00:00
|
|
|
World world = player.getWorld();
|
2012-03-17 15:35:29 +00:00
|
|
|
Region region = session.getSelection(world);
|
|
|
|
|
|
|
|
if (region instanceof FlatRegion) {
|
2019-01-09 07:13:44 +00:00
|
|
|
for (BlockVector2 pt : new Fast2DIterator(((FlatRegion) region).asFlatRegion(), editSession)) {
|
2019-04-03 13:25:16 +00:00
|
|
|
biomes[editSession.getBiome(pt).getInternalId()]++;
|
2018-08-12 14:03:07 +00:00
|
|
|
size++;
|
2012-03-17 15:35:29 +00:00
|
|
|
}
|
|
|
|
} else {
|
2018-08-12 14:03:07 +00:00
|
|
|
RegionVisitor visitor = new RegionVisitor(region, new RegionFunction() {
|
|
|
|
@Override
|
2019-01-09 07:13:44 +00:00
|
|
|
public boolean apply(BlockVector3 position) throws WorldEditException {
|
2019-04-03 13:25:16 +00:00
|
|
|
biomes[editSession.getBiome(position.toBlockVector2()).getInternalId()]++;
|
2018-08-12 14:03:07 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}, editSession);
|
|
|
|
Operations.completeBlindly(visitor);
|
|
|
|
size += visitor.getAffected();
|
2012-03-17 15:35:29 +00:00
|
|
|
}
|
2014-07-17 07:21:13 +00:00
|
|
|
}
|
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
BBC.BIOME_LIST_HEADER.send(player, 1, 1);
|
|
|
|
|
2019-04-03 05:53:34 +00:00
|
|
|
List<Countable<BiomeType>> distribution = new ArrayList<>();
|
2018-08-12 14:03:07 +00:00
|
|
|
for (int i = 0; i < biomes.length; i++) {
|
|
|
|
int count = biomes[i];
|
|
|
|
if (count != 0) {
|
2019-04-03 13:25:16 +00:00
|
|
|
distribution.add(new Countable<>(BiomeTypes.get(i), count));
|
2012-03-17 15:35:29 +00:00
|
|
|
}
|
|
|
|
}
|
2018-08-12 14:03:07 +00:00
|
|
|
Collections.sort(distribution);
|
2019-04-03 05:53:34 +00:00
|
|
|
for (Countable<BiomeType> c : distribution) {
|
2018-08-12 14:03:07 +00:00
|
|
|
BiomeData data = biomeRegistry.getData(c.getID());
|
|
|
|
String str = String.format("%-7s (%.3f%%) %s #%d",
|
|
|
|
String.valueOf(c.getAmount()),
|
|
|
|
c.getAmount() / (double) size * 100,
|
|
|
|
data == null ? "Unknown" : data.getName(),
|
|
|
|
c.getID().getId());
|
|
|
|
player.print(BBC.getPrefix() + str);
|
|
|
|
}
|
2012-03-17 15:35:29 +00:00
|
|
|
}
|
2012-03-21 06:40:35 +00:00
|
|
|
|
|
|
|
@Command(
|
2018-08-12 14:03:07 +00:00
|
|
|
aliases = {"/setbiome"},
|
2012-03-21 06:40:35 +00:00
|
|
|
usage = "<biome>",
|
|
|
|
flags = "p",
|
|
|
|
desc = "Sets the biome of the player's current block or region.",
|
|
|
|
help =
|
|
|
|
"Set the biome of the region.\n" +
|
2018-08-12 14:03:07 +00:00
|
|
|
"By default use all the blocks contained in your selection.\n" +
|
|
|
|
"-p use the block you are currently in"
|
2012-03-21 06:40:35 +00:00
|
|
|
)
|
2012-12-27 16:45:37 +00:00
|
|
|
@Logging(REGION)
|
2012-03-21 06:40:35 +00:00
|
|
|
@CommandPermissions("worldedit.biome.set")
|
2019-02-16 07:27:00 +00:00
|
|
|
public void setBiome(Player player, LocalSession session, EditSession editSession, BiomeType target, @Switch('p') boolean atPosition) throws WorldEditException {
|
2014-07-17 07:21:13 +00:00
|
|
|
World world = player.getWorld();
|
|
|
|
Region region;
|
2013-03-28 23:53:42 +00:00
|
|
|
Mask mask = editSession.getMask();
|
2014-07-17 07:21:13 +00:00
|
|
|
Mask2D mask2d = mask != null ? mask.toMask2D() : null;
|
2013-03-28 23:53:42 +00:00
|
|
|
|
2014-07-17 07:21:13 +00:00
|
|
|
if (atPosition) {
|
2019-03-31 16:09:20 +00:00
|
|
|
region = new CuboidRegion(player.getLocation().toBlockPoint(), player.getLocation().toBlockPoint());
|
2012-03-28 18:04:59 +00:00
|
|
|
} else {
|
2014-07-17 07:21:13 +00:00
|
|
|
region = session.getSelection(world);
|
|
|
|
}
|
2012-03-21 06:40:35 +00:00
|
|
|
|
2014-07-17 07:21:13 +00:00
|
|
|
FlatRegionFunction replace = new BiomeReplace(editSession, target);
|
|
|
|
if (mask2d != null) {
|
|
|
|
replace = new FlatRegionMaskingFilter(mask2d, replace);
|
2012-03-21 06:40:35 +00:00
|
|
|
}
|
2014-07-17 07:21:13 +00:00
|
|
|
FlatRegionVisitor visitor = new FlatRegionVisitor(Regions.asFlatRegion(region), replace);
|
|
|
|
Operations.completeLegacy(visitor);
|
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
BBC.BIOME_CHANGED.send(player, visitor.getAffected());
|
|
|
|
if (!FawePlayer.wrap(player).hasPermission("fawe.tips"))
|
|
|
|
BBC.TIP_BIOME_PATTERN.or(BBC.TIP_BIOME_MASK).send(player);
|
2012-03-21 06:40:35 +00:00
|
|
|
}
|
2012-03-17 15:35:29 +00:00
|
|
|
}
|