2014-04-03 02:08:50 +00:00
|
|
|
/*
|
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
|
2014-04-03 02:08:50 +00:00
|
|
|
*
|
2014-04-04 22:03:18 +00:00
|
|
|
* 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
|
2014-04-03 02:08:50 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
2014-04-04 22:03:18 +00:00
|
|
|
* 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.
|
2014-04-03 02:08:50 +00:00
|
|
|
*
|
2014-04-04 22:03:18 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
2014-04-03 02:08:50 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2014-04-04 22:03:18 +00:00
|
|
|
*/
|
2014-04-03 02:08:50 +00:00
|
|
|
|
|
|
|
package com.sk89q.worldedit.command;
|
|
|
|
|
2019-07-23 02:22:32 +00:00
|
|
|
import static com.google.common.base.Preconditions.checkNotNull;
|
2019-07-28 19:26:44 +00:00
|
|
|
import static com.sk89q.worldedit.command.MethodCommands.getArguments;
|
2019-07-23 02:22:32 +00:00
|
|
|
import static com.sk89q.worldedit.command.util.Logging.LogMode.ALL;
|
|
|
|
import static com.sk89q.worldedit.command.util.Logging.LogMode.PLACEMENT;
|
|
|
|
import static com.sk89q.worldedit.command.util.Logging.LogMode.POSITION;
|
2019-07-28 19:26:44 +00:00
|
|
|
import static com.sk89q.worldedit.internal.command.CommandUtil.checkCommandArgument;
|
2019-07-23 02:22:32 +00:00
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
import com.boydti.fawe.Fawe;
|
|
|
|
import com.boydti.fawe.config.BBC;
|
|
|
|
import com.boydti.fawe.object.FawePlayer;
|
|
|
|
import com.boydti.fawe.util.MainUtil;
|
|
|
|
import com.boydti.fawe.util.MathMan;
|
|
|
|
import com.boydti.fawe.util.TextureUtil;
|
|
|
|
import com.boydti.fawe.util.image.ImageUtil;
|
2018-12-23 16:19:33 +00:00
|
|
|
import com.sk89q.worldedit.EditSession;
|
|
|
|
import com.sk89q.worldedit.LocalSession;
|
|
|
|
import com.sk89q.worldedit.WorldEdit;
|
|
|
|
import com.sk89q.worldedit.WorldEditException;
|
2019-07-06 00:46:48 +00:00
|
|
|
import com.sk89q.worldedit.command.util.CommandPermissions;
|
|
|
|
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
|
|
|
|
import com.sk89q.worldedit.command.util.Logging;
|
2014-06-28 08:01:49 +00:00
|
|
|
import com.sk89q.worldedit.entity.Player;
|
2019-07-23 02:22:32 +00:00
|
|
|
import com.sk89q.worldedit.function.generator.CavesGen;
|
2018-08-12 14:03:07 +00:00
|
|
|
import com.sk89q.worldedit.function.mask.Mask;
|
|
|
|
import com.sk89q.worldedit.function.operation.Operations;
|
2014-06-28 08:01:49 +00:00
|
|
|
import com.sk89q.worldedit.function.pattern.Pattern;
|
2018-08-12 14:03:07 +00:00
|
|
|
import com.sk89q.worldedit.function.visitor.RegionVisitor;
|
2019-07-23 02:22:32 +00:00
|
|
|
import com.sk89q.worldedit.internal.annotation.Range;
|
2014-06-28 08:01:49 +00:00
|
|
|
import com.sk89q.worldedit.internal.annotation.Selection;
|
2014-04-03 02:08:50 +00:00
|
|
|
import com.sk89q.worldedit.internal.expression.ExpressionException;
|
2019-01-09 07:13:44 +00:00
|
|
|
import com.sk89q.worldedit.math.BlockVector2;
|
2018-12-23 16:19:33 +00:00
|
|
|
import com.sk89q.worldedit.math.BlockVector3;
|
|
|
|
import com.sk89q.worldedit.math.Vector3;
|
2019-06-12 21:12:12 +00:00
|
|
|
import com.sk89q.worldedit.regions.CuboidRegion;
|
2014-04-03 02:08:50 +00:00
|
|
|
import com.sk89q.worldedit.regions.Region;
|
2014-06-28 08:01:49 +00:00
|
|
|
import com.sk89q.worldedit.util.TreeGenerator.TreeType;
|
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.block.BlockType;
|
2019-07-06 00:46:48 +00:00
|
|
|
import java.awt.RenderingHints;
|
2019-04-03 13:25:16 +00:00
|
|
|
import java.awt.image.BufferedImage;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.net.URL;
|
2019-07-23 02:22:32 +00:00
|
|
|
import java.util.List;
|
|
|
|
import org.enginehub.piston.annotation.Command;
|
|
|
|
import org.enginehub.piston.annotation.CommandContainer;
|
|
|
|
import org.enginehub.piston.annotation.param.Arg;
|
|
|
|
import org.enginehub.piston.annotation.param.Switch;
|
|
|
|
import org.enginehub.piston.inject.InjectedValueAccess;
|
2019-04-03 13:25:16 +00:00
|
|
|
|
2014-04-03 02:08:50 +00:00
|
|
|
/**
|
2014-06-28 08:01:49 +00:00
|
|
|
* Commands for the generation of shapes and other objects.
|
2014-04-03 02:08:50 +00:00
|
|
|
*/
|
2019-07-06 00:46:48 +00:00
|
|
|
@CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class)
|
2019-07-25 18:44:10 +00:00
|
|
|
public class GenerationCommands {
|
2019-07-06 00:46:48 +00:00
|
|
|
|
|
|
|
private final WorldEdit worldEdit;
|
2014-06-28 08:01:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new instance.
|
|
|
|
*
|
|
|
|
* @param worldEdit reference to WorldEdit
|
|
|
|
*/
|
|
|
|
public GenerationCommands(WorldEdit worldEdit) {
|
2019-07-06 00:46:48 +00:00
|
|
|
checkNotNull(worldEdit);
|
|
|
|
this.worldEdit = worldEdit;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-07-06 00:46:48 +00:00
|
|
|
name = "/caves",
|
|
|
|
desc = "Generates a cave network"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
2018-08-12 14:03:07 +00:00
|
|
|
@CommandPermissions("worldedit.generation.caves")
|
2014-04-03 02:08:50 +00:00
|
|
|
@Logging(PLACEMENT)
|
2019-07-06 00:46:48 +00:00
|
|
|
public void caves(FawePlayer fp, LocalSession session, EditSession editSession, @Selection Region region,
|
2019-08-06 15:29:49 +00:00
|
|
|
@Arg(name = "size", desc = "TODO", def = "8") int sizeOpt,
|
2019-07-06 00:46:48 +00:00
|
|
|
@Arg(desc = "TODO", def = "40") int frequency,
|
|
|
|
@Arg(desc = "TODO", def = "7") int rarity,
|
|
|
|
@Arg(desc = "TODO", def = "8") int minY,
|
|
|
|
@Arg(desc = "TODO", def = "127") int maxY,
|
|
|
|
@Arg(desc = "TODO", def = "1") int systemFrequency,
|
|
|
|
@Arg(desc = "TODO", def = "25") int individualRarity,
|
|
|
|
@Arg(desc = "TODO", def = "0") int pocketChance,
|
|
|
|
@Arg(desc = "TODO", def = "0") int pocketMin,
|
2019-07-18 20:03:27 +00:00
|
|
|
@Arg(desc = "TODO", def = "3") int pocketMax, InjectedValueAccess context) throws WorldEditException {
|
2018-09-07 15:09:31 +00:00
|
|
|
fp.checkConfirmationRegion(() -> {
|
2019-08-06 15:29:49 +00:00
|
|
|
CavesGen gen = new CavesGen(sizeOpt, frequency, rarity, minY, maxY, systemFrequency, individualRarity, pocketChance, pocketMin, pocketMax);
|
2018-09-07 15:09:31 +00:00
|
|
|
editSession.generate(region, gen);
|
|
|
|
BBC.VISITOR_BLOCK.send(fp, editSession.getBlockChangeCount());
|
2019-08-06 15:29:49 +00:00
|
|
|
}, "/caves", region, context);
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
|
2014-04-03 02:08:50 +00:00
|
|
|
@Command(
|
2019-07-06 00:46:48 +00:00
|
|
|
name = "/ores",
|
|
|
|
desc = "Generates ores"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
2018-08-12 14:03:07 +00:00
|
|
|
@CommandPermissions("worldedit.generation.ore")
|
|
|
|
@Logging(PLACEMENT)
|
2019-08-06 15:29:49 +00:00
|
|
|
public void ores(FawePlayer fp, LocalSession session, EditSession editSession, @Selection Region region, Mask mask, InjectedValueAccess context) throws WorldEditException {
|
|
|
|
fp.checkConfirmationRegion(() -> {
|
2018-09-07 15:09:31 +00:00
|
|
|
editSession.addOres(region, mask);
|
2019-08-06 15:29:49 +00:00
|
|
|
BBC.VISITOR_BLOCK.send(fp, editSession.getBlockChangeCount());
|
|
|
|
}, "/ores", region, context);
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-07-17 03:57:35 +00:00
|
|
|
name = "/img",
|
|
|
|
desc = "Generate an image"
|
2018-08-12 14:03:07 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.generation.image")
|
2014-04-03 02:08:50 +00:00
|
|
|
@Logging(PLACEMENT)
|
2019-07-17 06:11:55 +00:00
|
|
|
public void image(Player player, LocalSession session, EditSession editSession, String arg, @Arg(name = "randomize", desc = "boolean", def = "true") boolean randomize,
|
|
|
|
@Arg(desc = "TODO", def = "100") int threshold, @Arg(name = "dimensions", desc = "BlockVector2", def = "") BlockVector2 dimensions) throws WorldEditException, IOException {
|
2018-08-12 14:03:07 +00:00
|
|
|
TextureUtil tu = Fawe.get().getCachedTextureUtil(randomize, 0, threshold);
|
|
|
|
URL url = new URL(arg);
|
|
|
|
if (!url.getHost().equalsIgnoreCase("i.imgur.com") && !url.getHost().equalsIgnoreCase("empcraft.com")) {
|
|
|
|
throw new IOException("Only i.imgur.com or empcraft.com/ui links are allowed!");
|
|
|
|
}
|
|
|
|
BufferedImage image = MainUtil.readImage(url);
|
|
|
|
if (dimensions != null) {
|
|
|
|
image = ImageUtil.getScaledInstance(image, dimensions.getBlockX(), dimensions.getBlockZ(), RenderingHints.VALUE_INTERPOLATION_BILINEAR, false);
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
2019-03-31 16:09:20 +00:00
|
|
|
BlockVector3 pos1 = player.getLocation().toBlockPoint();
|
2019-01-09 07:13:44 +00:00
|
|
|
BlockVector3 pos2 = pos1.add(image.getWidth() - 1, 0, image.getHeight() - 1);
|
2018-08-12 14:03:07 +00:00
|
|
|
CuboidRegion region = new CuboidRegion(pos1, pos2);
|
|
|
|
int[] count = new int[1];
|
|
|
|
final BufferedImage finalImage = image;
|
2019-07-06 00:46:48 +00:00
|
|
|
RegionVisitor visitor = new RegionVisitor(region, pos -> {
|
|
|
|
try {
|
|
|
|
int x = pos.getBlockX() - pos1.getBlockX();
|
|
|
|
int z = pos.getBlockZ() - pos1.getBlockZ();
|
|
|
|
int color = finalImage.getRGB(x, z);
|
|
|
|
BlockType block = tu.getNearestBlock(color);
|
|
|
|
count[0]++;
|
|
|
|
if (block != null) return editSession.setBlock(pos, block.getDefaultState());
|
2018-08-12 14:03:07 +00:00
|
|
|
return false;
|
2019-07-06 00:46:48 +00:00
|
|
|
} catch (Throwable e) {
|
|
|
|
e.printStackTrace();
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
2019-07-06 00:46:48 +00:00
|
|
|
return false;
|
2019-07-22 06:57:12 +00:00
|
|
|
});
|
2018-08-12 14:03:07 +00:00
|
|
|
Operations.completeBlindly(visitor);
|
|
|
|
BBC.VISITOR_BLOCK.send(player, editSession.getBlockChangeCount());
|
|
|
|
}
|
2014-04-03 02:08:50 +00:00
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
@Command(
|
2019-07-06 00:46:48 +00:00
|
|
|
name = "/ore",
|
|
|
|
desc = "Generates ores"
|
2018-08-12 14:03:07 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.generation.ore")
|
|
|
|
@Logging(PLACEMENT)
|
2019-08-06 15:29:49 +00:00
|
|
|
public void ore(FawePlayer fp, LocalSession session, EditSession editSession, @Selection Region region, Mask mask, Pattern material, @Range(min = 0) int size, int freq, @Range(min = 0, max = 100) int rarity, @Range(min = 0, max = 255) int minY, @Range(min = 0, max = 255) int maxY, InjectedValueAccess context) throws WorldEditException {
|
|
|
|
fp.checkConfirmationRegion(() -> {
|
2018-09-07 15:09:31 +00:00
|
|
|
editSession.addOre(region, mask, material, size, freq, rarity, minY, maxY);
|
2019-08-06 15:29:49 +00:00
|
|
|
BBC.VISITOR_BLOCK.send(fp, editSession.getBlockChangeCount());
|
|
|
|
}, "/ore", region, context);
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-07-06 00:46:48 +00:00
|
|
|
name = "/hcyl",
|
2019-07-17 03:57:35 +00:00
|
|
|
desc = "Generates a hollow cylinder."
|
2018-08-12 14:03:07 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.generation.cylinder")
|
|
|
|
@Logging(PLACEMENT)
|
2019-07-06 00:46:48 +00:00
|
|
|
public void hcyl(FawePlayer fp, Player player, LocalSession session, EditSession editSession,
|
|
|
|
@Arg(desc = "The pattern of blocks to generate")
|
|
|
|
Pattern pattern,
|
|
|
|
BlockVector2 radius,
|
|
|
|
@Arg(desc = "The height of the cylinder", def = "1")
|
|
|
|
int height,
|
2019-07-18 20:03:27 +00:00
|
|
|
@Range(min = 1) @Arg(name = "thickness", desc = "double", def = "1") double thickness, InjectedValueAccess context) throws WorldEditException {
|
2019-06-12 13:45:41 +00:00
|
|
|
double max = MathMan.max(radius.getBlockX(), radius.getBlockZ());
|
2018-08-12 14:03:07 +00:00
|
|
|
worldEdit.checkMaxRadius(max);
|
2019-01-09 07:13:44 +00:00
|
|
|
BlockVector3 pos = session.getPlacementPosition(player);
|
2018-09-07 15:09:31 +00:00
|
|
|
fp.checkConfirmationRadius(() -> {
|
|
|
|
int affected = editSession.makeHollowCylinder(pos, pattern, radius.getX(), radius.getZ(), Math.min(256, height), thickness - 1);
|
|
|
|
BBC.VISITOR_BLOCK.send(fp, affected);
|
2019-08-06 15:29:49 +00:00
|
|
|
}, "/hcyl", (int) max, context);
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-07-06 00:46:48 +00:00
|
|
|
name = "/cyl",
|
2019-07-17 03:57:35 +00:00
|
|
|
desc = "Generates a cylinder."
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
2018-08-12 14:03:07 +00:00
|
|
|
@CommandPermissions("worldedit.generation.cylinder")
|
2014-04-03 02:08:50 +00:00
|
|
|
@Logging(PLACEMENT)
|
2019-07-06 00:46:48 +00:00
|
|
|
public void cyl(FawePlayer fp, Player player, LocalSession session, EditSession editSession,
|
|
|
|
@Arg(desc = "The pattern of blocks to generate")
|
|
|
|
Pattern pattern,
|
|
|
|
BlockVector2 radius,
|
|
|
|
@Arg(desc = "The height of the cylinder", def = "1")
|
|
|
|
int height,
|
|
|
|
@Switch(name = 'h', desc = "Make a hollow cylinder")
|
2019-07-18 20:03:27 +00:00
|
|
|
boolean hollow, InjectedValueAccess context) throws WorldEditException {
|
2019-06-12 21:12:12 +00:00
|
|
|
double max = Math.max(radius.getBlockX(), radius.getBlockZ());
|
2018-08-12 14:03:07 +00:00
|
|
|
worldEdit.checkMaxRadius(max);
|
2019-01-09 07:13:44 +00:00
|
|
|
BlockVector3 pos = session.getPlacementPosition(player);
|
2018-09-07 15:09:31 +00:00
|
|
|
fp.checkConfirmationRadius(() -> {
|
|
|
|
int affected = editSession.makeCylinder(pos, pattern, radius.getX(), radius.getZ(), Math.min(256, height), !hollow);
|
|
|
|
BBC.VISITOR_BLOCK.send(fp, affected);
|
2019-08-06 15:29:49 +00:00
|
|
|
}, "/cyl", (int) max, context);
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-07-06 00:46:48 +00:00
|
|
|
name = "/hsphere",
|
2019-07-17 03:57:35 +00:00
|
|
|
desc = "Generates a hollow sphere."
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.generation.sphere")
|
|
|
|
@Logging(PLACEMENT)
|
2019-07-06 00:46:48 +00:00
|
|
|
public void hsphere(FawePlayer fp, Player player, LocalSession session, EditSession editSession,
|
|
|
|
@Arg(desc = "The pattern of blocks to generate")
|
|
|
|
Pattern pattern,
|
2019-07-17 10:50:54 +00:00
|
|
|
@Arg(desc = "The radii of the sphere. Order is N/S, U/D, E/W") BlockVector3 radii,
|
2019-07-06 00:46:48 +00:00
|
|
|
@Switch(name = 'r', desc = "Raise the bottom of the sphere to the placement position")
|
|
|
|
boolean raised,
|
2019-07-18 20:03:27 +00:00
|
|
|
InjectedValueAccess context) throws WorldEditException {
|
2019-07-06 00:46:48 +00:00
|
|
|
sphere(fp, player, session, editSession, pattern, radii, raised, true, context);
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
2014-04-03 02:08:50 +00:00
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
@Command(
|
2019-07-06 00:46:48 +00:00
|
|
|
name = "/sphere",
|
2019-07-17 03:57:35 +00:00
|
|
|
desc = "Generates a filled sphere."
|
2018-08-12 14:03:07 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.generation.sphere")
|
|
|
|
@Logging(PLACEMENT)
|
2019-07-17 10:50:54 +00:00
|
|
|
public void sphere(FawePlayer fp, Player player, LocalSession session, EditSession editSession,
|
2019-07-22 02:49:08 +00:00
|
|
|
@Arg(desc = "The pattern of blocks to generate")
|
|
|
|
Pattern pattern,
|
|
|
|
@Arg(desc = "The radii of the sphere. Order is N/S, U/D, E/W")
|
|
|
|
BlockVector3 radii,
|
|
|
|
@Switch(name = 'r', desc = "Raise the bottom of the sphere to the placement position")
|
|
|
|
boolean raised,
|
|
|
|
@Switch(name = 'h', desc = "Make a hollow sphere")
|
|
|
|
boolean hollow, InjectedValueAccess context) throws WorldEditException {
|
2019-07-22 06:57:12 +00:00
|
|
|
double max = MathMan.max(radii.getBlockX(), radii.getBlockY(), radii.getBlockZ());
|
|
|
|
worldEdit.checkMaxRadius(max);
|
2019-01-09 07:13:44 +00:00
|
|
|
BlockVector3 pos = session.getPlacementPosition(player);
|
2019-07-17 10:50:54 +00:00
|
|
|
BlockVector3 finalPos = raised ? pos.add(0, radii.getY(), 0) : pos;
|
2018-09-07 15:09:31 +00:00
|
|
|
fp.checkConfirmationRadius(() -> {
|
2019-07-17 10:50:54 +00:00
|
|
|
int affected = editSession.makeSphere(finalPos, pattern, radii.getX(), radii.getY(), radii.getZ(), !hollow);
|
2018-09-07 15:09:31 +00:00
|
|
|
player.findFreePosition();
|
|
|
|
BBC.VISITOR_BLOCK.send(fp, affected);
|
2019-08-06 15:29:49 +00:00
|
|
|
}, "sphere", (int) max, context);
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-07-06 00:46:48 +00:00
|
|
|
name = "forestgen",
|
|
|
|
desc = "Generate a forest"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.generation.forest")
|
|
|
|
@Logging(POSITION)
|
2019-07-06 00:46:48 +00:00
|
|
|
public int forestGen(Player player, LocalSession session, EditSession editSession,
|
2019-08-06 15:29:49 +00:00
|
|
|
@Arg(name = "size", desc = "The size of the forest, in blocks", def = "10")
|
|
|
|
int sizeOpt,
|
2019-07-06 00:46:48 +00:00
|
|
|
@Arg(desc = "The type of forest", def = "tree")
|
|
|
|
TreeType type,
|
2019-07-28 19:26:44 +00:00
|
|
|
@Range(min = 0, max = 100) @Arg(desc = "The density of the forest, between 0 and 100", def = "5")
|
2019-07-06 00:46:48 +00:00
|
|
|
double density) throws WorldEditException {
|
2019-07-25 18:44:10 +00:00
|
|
|
checkCommandArgument(0 <= density && density <= 100, "Density must be between 0 and 100");
|
|
|
|
density /= 100;
|
2019-08-06 15:29:49 +00:00
|
|
|
int affected = editSession.makeForest(session.getPlacementPosition(player), sizeOpt, density, type);
|
2019-06-12 21:12:12 +00:00
|
|
|
player.print(affected + " trees created.");
|
2019-07-06 00:46:48 +00:00
|
|
|
return affected;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-07-06 00:46:48 +00:00
|
|
|
name = "pumpkins",
|
|
|
|
desc = "Generate pumpkin patches"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.generation.pumpkins")
|
|
|
|
@Logging(POSITION)
|
2019-07-06 00:46:48 +00:00
|
|
|
public int pumpkins(Player player, LocalSession session, EditSession editSession,
|
2019-08-06 15:29:49 +00:00
|
|
|
@Arg(name = "size", desc = "The size of the patch", def = "10")
|
|
|
|
int sizeOpt,
|
2019-07-17 03:57:35 +00:00
|
|
|
@Arg(desc = "//TODO", def = "10")
|
|
|
|
int apothem,
|
2019-08-06 15:29:49 +00:00
|
|
|
@Arg(desc = "//TODO ", def = "0.02")
|
2019-07-17 03:57:35 +00:00
|
|
|
double density) throws WorldEditException {
|
2019-08-06 15:29:49 +00:00
|
|
|
checkCommandArgument(0 <= density && density <= 100, "Density must be between 0 and 100");
|
2019-06-28 14:01:51 +00:00
|
|
|
int affected = editSession.makePumpkinPatches(session.getPlacementPosition(player), apothem, density);
|
2018-08-12 14:03:07 +00:00
|
|
|
BBC.COMMAND_PUMPKIN.send(player, affected);
|
2019-07-06 00:46:48 +00:00
|
|
|
return affected;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-07-06 00:46:48 +00:00
|
|
|
name = "/hpyramid",
|
|
|
|
desc = "Generate a hollow pyramid"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.generation.pyramid")
|
|
|
|
@Logging(PLACEMENT)
|
2019-07-06 00:46:48 +00:00
|
|
|
public void hollowPyramid(FawePlayer fp, Player player, LocalSession session, EditSession editSession,
|
2019-07-17 03:57:35 +00:00
|
|
|
@Arg(desc = "The pattern of blocks to set")
|
|
|
|
Pattern pattern,
|
|
|
|
@Arg(desc = "The size of the pyramid")
|
2019-07-18 20:03:27 +00:00
|
|
|
int size, InjectedValueAccess context) throws WorldEditException {
|
2018-08-12 14:03:07 +00:00
|
|
|
pyramid(fp, player, session, editSession, pattern, size, true, context);
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-07-06 00:46:48 +00:00
|
|
|
name = "/pyramid",
|
|
|
|
desc = "Generate a filled pyramid"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.generation.pyramid")
|
|
|
|
@Logging(PLACEMENT)
|
2019-07-06 00:46:48 +00:00
|
|
|
public void pyramid(FawePlayer fp, Player player, LocalSession session, EditSession editSession,
|
2019-07-17 03:57:35 +00:00
|
|
|
@Arg(desc = "The pattern of blocks to set")
|
|
|
|
Pattern pattern,
|
|
|
|
@Arg(desc = "The size of the pyramid")
|
|
|
|
int size,
|
|
|
|
@Switch(name = 'h', desc = "Make a hollow pyramid")
|
|
|
|
boolean hollow,
|
2019-07-18 20:03:27 +00:00
|
|
|
InjectedValueAccess context) throws WorldEditException {
|
2018-12-23 16:19:33 +00:00
|
|
|
BlockVector3 pos = session.getPlacementPosition(player);
|
2014-06-28 08:01:49 +00:00
|
|
|
worldEdit.checkMaxRadius(size);
|
2018-09-07 15:09:31 +00:00
|
|
|
fp.checkConfirmationRadius(() -> {
|
|
|
|
int affected = editSession.makePyramid(pos, pattern, size, !hollow);
|
|
|
|
player.findFreePosition();
|
|
|
|
BBC.VISITOR_BLOCK.send(fp, affected);
|
2018-09-07 23:10:36 +00:00
|
|
|
}, getArguments(context), size, context);
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
2019-06-12 21:12:12 +00:00
|
|
|
|
2014-04-03 02:08:50 +00:00
|
|
|
@Command(
|
2019-07-06 00:46:48 +00:00
|
|
|
name = "/generate",
|
|
|
|
aliases = { "/gen", "/g" },
|
2019-06-12 21:12:12 +00:00
|
|
|
desc = "Generates a shape according to a formula.",
|
2019-07-17 03:57:35 +00:00
|
|
|
descFooter = "See also https://tinyurl.com/weexpr."
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.generation.shape")
|
|
|
|
@Logging(ALL)
|
2019-07-17 10:50:54 +00:00
|
|
|
public void generate(FawePlayer fp, Player player, LocalSession session, EditSession editSession,
|
2019-07-06 00:46:48 +00:00
|
|
|
@Selection Region region,
|
|
|
|
@Arg(desc = "The pattern of blocks to set")
|
|
|
|
Pattern pattern,
|
|
|
|
@Arg(desc = "Expression to test block placement locations and set block type", variable = true)
|
|
|
|
List<String> expression,
|
|
|
|
@Switch(name = 'h', desc = "Generate a hollow shape")
|
|
|
|
boolean hollow,
|
|
|
|
@Switch(name = 'r', desc = "Use the game's coordinate origin")
|
|
|
|
boolean useRawCoords,
|
|
|
|
@Switch(name = 'o', desc = "Use the placement's coordinate origin")
|
|
|
|
boolean offset,
|
|
|
|
@Switch(name = 'c', desc = "Use the selection's center as origin")
|
2019-07-22 06:57:12 +00:00
|
|
|
boolean offsetCenter,
|
|
|
|
InjectedValueAccess context) throws WorldEditException {
|
2018-12-23 16:19:33 +00:00
|
|
|
|
|
|
|
final Vector3 zero;
|
|
|
|
Vector3 unit;
|
2018-09-07 15:31:30 +00:00
|
|
|
|
|
|
|
if (useRawCoords) {
|
2018-12-23 16:19:33 +00:00
|
|
|
zero = Vector3.ZERO;
|
|
|
|
unit = Vector3.ONE;
|
2018-09-07 15:31:30 +00:00
|
|
|
} else if (offset) {
|
2018-12-23 16:19:33 +00:00
|
|
|
zero = session.getPlacementPosition(player).toVector3();
|
|
|
|
unit = Vector3.ONE;
|
2018-09-07 15:31:30 +00:00
|
|
|
} else if (offsetCenter) {
|
2018-12-23 16:19:33 +00:00
|
|
|
final Vector3 min = region.getMinimumPoint().toVector3();
|
|
|
|
final Vector3 max = region.getMaximumPoint().toVector3();
|
2018-09-07 15:31:30 +00:00
|
|
|
|
|
|
|
zero = max.add(min).multiply(0.5);
|
2018-12-23 16:19:33 +00:00
|
|
|
unit = Vector3.ONE;
|
2018-09-07 15:31:30 +00:00
|
|
|
} else {
|
2018-12-23 16:19:33 +00:00
|
|
|
final Vector3 min = region.getMinimumPoint().toVector3();
|
|
|
|
final Vector3 max = region.getMaximumPoint().toVector3();
|
2018-09-07 15:31:30 +00:00
|
|
|
|
|
|
|
zero = max.add(min).multiply(0.5);
|
|
|
|
unit = max.subtract(zero);
|
|
|
|
|
2018-12-23 16:19:33 +00:00
|
|
|
if (unit.getX() == 0) unit = unit.withX(1.0);
|
|
|
|
if (unit.getY() == 0) unit = unit.withY(1.0);
|
|
|
|
if (unit.getZ() == 0) unit = unit.withZ(1.0);
|
2018-09-07 15:31:30 +00:00
|
|
|
}
|
2019-06-12 21:12:12 +00:00
|
|
|
|
2019-01-09 07:13:44 +00:00
|
|
|
final Vector3 unit1 = unit;
|
2014-04-03 02:08:50 +00:00
|
|
|
|
2018-09-07 15:31:30 +00:00
|
|
|
fp.checkConfirmationRegion(() -> {
|
2018-09-07 15:09:31 +00:00
|
|
|
try {
|
2019-07-25 18:44:10 +00:00
|
|
|
final int affected = editSession.makeShape(region, zero, unit1, pattern, String.join(" ", expression), hollow, session.getTimeout());
|
2018-09-07 15:09:31 +00:00
|
|
|
player.findFreePosition();
|
|
|
|
BBC.VISITOR_BLOCK.send(fp, affected);
|
|
|
|
} catch (ExpressionException e) {
|
2019-07-06 00:46:48 +00:00
|
|
|
player.printError(e.getMessage());
|
2018-09-07 15:09:31 +00:00
|
|
|
}
|
2019-08-06 15:29:49 +00:00
|
|
|
}, "/generate", region, context);
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-07-06 00:46:48 +00:00
|
|
|
name = "/generatebiome",
|
|
|
|
aliases = { "/genbiome", "/gb" },
|
2019-06-12 21:12:12 +00:00
|
|
|
desc = "Sets biome according to a formula.",
|
2019-07-17 10:50:54 +00:00
|
|
|
descFooter = "Formula must return positive numbers (true) if the point is inside the shape\n" +
|
|
|
|
"Sets the biome of blocks in that shape.\n"
|
|
|
|
+"See also https://tinyurl.com/weexpr."
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
2019-03-07 00:58:32 +00:00
|
|
|
@CommandPermissions("worldedit.generation.shape.biome")
|
2014-04-03 02:08:50 +00:00
|
|
|
@Logging(ALL)
|
2019-07-22 06:57:12 +00:00
|
|
|
public void generateBiome(FawePlayer fp, LocalSession session, EditSession editSession,
|
2019-07-06 00:46:48 +00:00
|
|
|
@Selection Region region,
|
|
|
|
@Arg(desc = "The biome type to set")
|
|
|
|
BiomeType target,
|
|
|
|
@Arg(desc = "Expression to test block placement locations and set biome type", variable = true)
|
|
|
|
List<String> expression,
|
|
|
|
@Switch(name = 'h', desc = "Generate a hollow shape")
|
|
|
|
boolean hollow,
|
|
|
|
@Switch(name = 'r', desc = "Use the game's coordinate origin")
|
|
|
|
boolean useRawCoords,
|
|
|
|
@Switch(name = 'o', desc = "Use the placement's coordinate origin")
|
|
|
|
boolean offset,
|
|
|
|
@Switch(name = 'c', desc = "Use the selection's center as origin")
|
2019-07-22 06:57:12 +00:00
|
|
|
boolean offsetCenter,
|
|
|
|
InjectedValueAccess context) throws WorldEditException {
|
2018-12-23 16:19:33 +00:00
|
|
|
final Vector3 zero;
|
|
|
|
Vector3 unit;
|
2018-09-07 15:31:30 +00:00
|
|
|
|
|
|
|
if (useRawCoords) {
|
2018-12-23 16:19:33 +00:00
|
|
|
zero = Vector3.ZERO;
|
|
|
|
unit = Vector3.ONE;
|
2018-09-07 15:31:30 +00:00
|
|
|
} else if (offset) {
|
2019-07-17 03:57:35 +00:00
|
|
|
zero = session.getPlacementPosition(fp.toWorldEditPlayer()).toVector3();
|
2018-12-23 16:19:33 +00:00
|
|
|
unit = Vector3.ONE;
|
2018-09-07 15:31:30 +00:00
|
|
|
} else if (offsetCenter) {
|
2018-12-23 16:19:33 +00:00
|
|
|
final Vector3 min = region.getMinimumPoint().toVector3();
|
|
|
|
final Vector3 max = region.getMaximumPoint().toVector3();
|
2018-09-07 15:31:30 +00:00
|
|
|
|
|
|
|
zero = max.add(min).multiply(0.5);
|
2018-12-23 16:19:33 +00:00
|
|
|
unit = Vector3.ONE;
|
2018-09-07 15:31:30 +00:00
|
|
|
} else {
|
2018-12-23 16:19:33 +00:00
|
|
|
final Vector3 min = region.getMinimumPoint().toVector3();
|
|
|
|
final Vector3 max = region.getMaximumPoint().toVector3();
|
2018-09-07 15:31:30 +00:00
|
|
|
|
|
|
|
zero = max.add(min).multiply(0.5);
|
|
|
|
unit = max.subtract(zero);
|
|
|
|
|
2018-12-23 16:19:33 +00:00
|
|
|
if (unit.getX() == 0) unit = unit.withX(1.0);
|
|
|
|
if (unit.getY() == 0) unit = unit.withY(1.0);
|
|
|
|
if (unit.getZ() == 0) unit = unit.withZ(1.0);
|
|
|
|
}
|
2019-06-12 21:12:12 +00:00
|
|
|
|
2019-01-09 07:13:44 +00:00
|
|
|
final Vector3 unit1 = unit;
|
2018-09-07 15:09:31 +00:00
|
|
|
fp.checkConfirmationRegion(() -> {
|
|
|
|
try {
|
2019-07-17 03:57:35 +00:00
|
|
|
final int affected = editSession.makeBiomeShape(region, zero, unit1, target, String.join(" ", expression), hollow, session.getTimeout());
|
2018-09-07 15:09:31 +00:00
|
|
|
BBC.VISITOR_FLAT.send(fp, affected);
|
|
|
|
} catch (ExpressionException e) {
|
2019-07-22 06:57:12 +00:00
|
|
|
fp.printError(e.getMessage());
|
2018-09-07 15:09:31 +00:00
|
|
|
}
|
2019-08-06 15:29:49 +00:00
|
|
|
}, "/generatebiome", region, context);
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
2019-06-12 21:12:12 +00:00
|
|
|
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|