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
|
|
|
*
|
2020-08-25 01:31:47 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU 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.
|
|
|
|
*
|
2020-08-25 01:31:47 +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 General Public License for more details.
|
2014-04-03 02:08:50 +00:00
|
|
|
*
|
2020-08-25 01:31:47 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://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
|
|
|
|
2021-07-01 20:16:25 +00:00
|
|
|
import com.fastasyncworldedit.core.Fawe;
|
|
|
|
import com.fastasyncworldedit.core.configuration.Caption;
|
2021-07-24 15:34:05 +00:00
|
|
|
import com.fastasyncworldedit.core.function.generator.CavesGen;
|
2021-07-01 20:16:25 +00:00
|
|
|
import com.fastasyncworldedit.core.util.MainUtil;
|
|
|
|
import com.fastasyncworldedit.core.util.TextureUtil;
|
|
|
|
import com.fastasyncworldedit.core.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;
|
2019-11-21 06:50:37 +00:00
|
|
|
import com.sk89q.worldedit.command.util.annotation.Confirm;
|
2021-08-17 00:47:09 +00:00
|
|
|
import com.sk89q.worldedit.command.util.annotation.Preload;
|
2014-06-28 08:01:49 +00:00
|
|
|
import com.sk89q.worldedit.entity.Player;
|
2019-10-07 19:09:52 +00:00
|
|
|
import com.sk89q.worldedit.extension.platform.Actor;
|
2021-07-24 14:47:22 +00:00
|
|
|
import com.sk89q.worldedit.function.mask.AbstractExtentMask;
|
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;
|
2020-01-26 18:01:16 +00:00
|
|
|
import com.sk89q.worldedit.internal.annotation.Radii;
|
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;
|
2020-01-03 17:30:46 +00:00
|
|
|
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
2021-07-27 17:45:31 +00:00
|
|
|
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
|
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-23 02:22:32 +00:00
|
|
|
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;
|
2019-11-20 00:11:54 +00:00
|
|
|
import org.jetbrains.annotations.Range;
|
2019-04-03 13:25:16 +00:00
|
|
|
|
2021-07-24 15:34:05 +00:00
|
|
|
import java.awt.RenderingHints;
|
2020-07-14 02:50:59 +00:00
|
|
|
import java.awt.image.BufferedImage;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.net.URL;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import static com.google.common.base.Preconditions.checkNotNull;
|
|
|
|
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;
|
|
|
|
import static com.sk89q.worldedit.internal.command.CommandUtil.checkCommandArgument;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
@Command(
|
2021-07-24 15:34:05 +00:00
|
|
|
name = "/hcyl",
|
|
|
|
desc = "Generates a hollow cylinder."
|
2018-08-12 14:03:07 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.generation.cylinder")
|
|
|
|
@Logging(PLACEMENT)
|
2021-07-24 15:34:05 +00:00
|
|
|
public int hcyl(
|
|
|
|
Actor actor, LocalSession session, EditSession editSession,
|
|
|
|
@Arg(desc = "The pattern of blocks to generate")
|
|
|
|
Pattern pattern,
|
|
|
|
@Arg(desc = "The radii of the cylinder. 1st is N/S, 2nd is E/W")
|
|
|
|
@Radii(2)
|
|
|
|
List<Double> radii,
|
|
|
|
@Arg(desc = "The height of the cylinder", def = "1")
|
2021-08-08 09:02:58 +00:00
|
|
|
int height,
|
|
|
|
//FAWE start - hcyl thickness
|
|
|
|
@Arg(desc = "Thickness of the cyclinder. 0 creates a normal //hcyl.", def = "0")
|
|
|
|
double thickness
|
2021-07-24 15:34:05 +00:00
|
|
|
) throws WorldEditException {
|
2021-08-08 09:02:58 +00:00
|
|
|
final double radiusX;
|
|
|
|
final double radiusZ;
|
|
|
|
switch (radii.size()) {
|
|
|
|
case 1:
|
|
|
|
radiusX = radiusZ = Math.max(1, radii.get(0));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
radiusX = Math.max(1, radii.get(0));
|
|
|
|
radiusZ = Math.max(1, radii.get(1));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
actor.print(Caption.of("worldedit.cyl.invalid-radius"));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
worldEdit.checkMaxRadius(radiusX);
|
|
|
|
worldEdit.checkMaxRadius(radiusZ);
|
|
|
|
worldEdit.checkMaxRadius(height);
|
|
|
|
|
|
|
|
if (thickness > radiusX || thickness > radiusZ) {
|
|
|
|
actor.print(Caption.of("worldedit.hcyl.thickness-too-large"));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
BlockVector3 pos = session.getPlacementPosition(actor);
|
|
|
|
int affected = editSession.makeCylinder(pos, pattern, radiusX, radiusZ, height, thickness, false);
|
|
|
|
actor.print(Caption.of("worldedit.cyl.created", TextComponent.of(affected)));
|
|
|
|
return affected;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
2021-08-08 09:02:58 +00:00
|
|
|
//FAWE end
|
2014-04-03 02:08:50 +00:00
|
|
|
|
|
|
|
@Command(
|
2021-07-24 15:34:05 +00:00
|
|
|
name = "/cyl",
|
|
|
|
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)
|
2021-07-24 15:34:05 +00:00
|
|
|
public int cyl(
|
|
|
|
Actor actor, LocalSession session, EditSession editSession,
|
|
|
|
@Arg(desc = "The pattern of blocks to generate")
|
|
|
|
Pattern pattern,
|
|
|
|
@Arg(desc = "The radii of the cylinder. 1st is N/S, 2nd is E/W")
|
|
|
|
@Radii(2)
|
|
|
|
List<Double> radii,
|
|
|
|
@Arg(desc = "The height of the cylinder", def = "1")
|
|
|
|
int height,
|
|
|
|
@Switch(name = 'h', desc = "Make a hollow cylinder")
|
|
|
|
boolean hollow
|
|
|
|
) throws WorldEditException {
|
2020-10-05 17:41:41 +00:00
|
|
|
final double radiusX;
|
|
|
|
final double radiusZ;
|
2020-01-26 18:01:16 +00:00
|
|
|
switch (radii.size()) {
|
|
|
|
case 1:
|
|
|
|
radiusX = radiusZ = Math.max(1, radii.get(0));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
radiusX = Math.max(1, radii.get(0));
|
|
|
|
radiusZ = Math.max(1, radii.get(1));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2021-04-05 17:54:49 +00:00
|
|
|
actor.print(Caption.of("worldedit.cyl.invalid-radius"));
|
2020-01-26 18:01:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
worldEdit.checkMaxRadius(radiusX);
|
|
|
|
worldEdit.checkMaxRadius(radiusZ);
|
|
|
|
worldEdit.checkMaxRadius(height);
|
2020-08-25 01:31:47 +00:00
|
|
|
|
2019-10-07 19:23:40 +00:00
|
|
|
BlockVector3 pos = session.getPlacementPosition(actor);
|
2020-01-26 18:01:16 +00:00
|
|
|
int affected = editSession.makeCylinder(pos, pattern, radiusX, radiusZ, height, !hollow);
|
2021-04-05 17:54:49 +00:00
|
|
|
actor.print(Caption.of("worldedit.cyl.created", TextComponent.of(affected)));
|
2020-01-26 18:01:16 +00:00
|
|
|
return affected;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2021-07-24 15:34:05 +00:00
|
|
|
name = "/hsphere",
|
|
|
|
desc = "Generates a hollow sphere."
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.generation.sphere")
|
|
|
|
@Logging(PLACEMENT)
|
2021-07-24 15:34:05 +00:00
|
|
|
public int hsphere(
|
|
|
|
Actor actor, LocalSession session, EditSession editSession,
|
|
|
|
@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")
|
|
|
|
@Radii(3)
|
|
|
|
List<Double> radii,
|
|
|
|
@Switch(name = 'r', desc = "Raise the bottom of the sphere to the placement position")
|
|
|
|
boolean raised
|
|
|
|
) throws WorldEditException {
|
|
|
|
return sphere(actor, session, editSession, pattern, radii, raised, true);
|
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(
|
2021-07-24 15:34:05 +00:00
|
|
|
name = "/sphere",
|
|
|
|
desc = "Generates a filled sphere."
|
2018-08-12 14:03:07 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.generation.sphere")
|
|
|
|
@Logging(PLACEMENT)
|
2021-07-24 15:34:05 +00:00
|
|
|
public int sphere(
|
|
|
|
Actor actor, LocalSession session, EditSession editSession,
|
|
|
|
@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")
|
|
|
|
@Radii(3)
|
|
|
|
List<Double> 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
|
|
|
|
) throws WorldEditException {
|
2020-10-05 17:41:41 +00:00
|
|
|
final double radiusX;
|
|
|
|
final double radiusY;
|
|
|
|
final double radiusZ;
|
2020-01-26 18:01:16 +00:00
|
|
|
switch (radii.size()) {
|
|
|
|
case 1:
|
|
|
|
radiusX = radiusY = radiusZ = Math.max(0, radii.get(0));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
radiusX = Math.max(0, radii.get(0));
|
|
|
|
radiusY = Math.max(0, radii.get(1));
|
|
|
|
radiusZ = Math.max(0, radii.get(2));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2021-04-05 17:54:49 +00:00
|
|
|
actor.print(Caption.of("worldedit.sphere.invalid-radius"));
|
2020-01-26 18:01:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
worldEdit.checkMaxRadius(radiusX);
|
|
|
|
worldEdit.checkMaxRadius(radiusY);
|
|
|
|
worldEdit.checkMaxRadius(radiusZ);
|
2019-10-07 19:23:40 +00:00
|
|
|
BlockVector3 pos = session.getPlacementPosition(actor);
|
2020-01-26 18:01:16 +00:00
|
|
|
if (raised) {
|
|
|
|
pos = pos.add(0, (int) radiusY, 0);
|
|
|
|
}
|
2020-08-25 01:31:47 +00:00
|
|
|
|
2020-01-26 18:01:16 +00:00
|
|
|
int affected = editSession.makeSphere(pos, pattern, radiusX, radiusY, radiusZ, !hollow);
|
2019-11-21 06:50:37 +00:00
|
|
|
if (actor instanceof Player) {
|
|
|
|
((Player) actor).findFreePosition();
|
|
|
|
}
|
2021-04-05 17:54:49 +00:00
|
|
|
actor.print(Caption.of("worldedit.sphere.created", TextComponent.of(affected)));
|
2020-01-26 18:01:16 +00:00
|
|
|
return affected;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2021-07-24 15:34:05 +00:00
|
|
|
name = "forestgen",
|
|
|
|
aliases = {"/forestgen"},
|
|
|
|
desc = "Generate a forest"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.generation.forest")
|
|
|
|
@Logging(POSITION)
|
2021-07-24 15:34:05 +00:00
|
|
|
public int forestGen(
|
|
|
|
Actor actor, LocalSession session, EditSession editSession,
|
|
|
|
@Arg(desc = "The size of the forest, in blocks", def = "10")
|
|
|
|
int size,
|
|
|
|
@Arg(desc = "The type of forest", def = "tree")
|
|
|
|
TreeType type,
|
|
|
|
@Arg(desc = "The density of the forest, between 0 and 100", def = "5")
|
|
|
|
double density
|
|
|
|
) throws WorldEditException {
|
2019-07-25 18:44:10 +00:00
|
|
|
checkCommandArgument(0 <= density && density <= 100, "Density must be between 0 and 100");
|
2019-08-05 21:39:00 +00:00
|
|
|
worldEdit.checkMaxRadius(size);
|
2019-07-25 18:44:10 +00:00
|
|
|
density /= 100;
|
2019-11-11 21:02:28 +00:00
|
|
|
int affected = editSession.makeForest(session.getPlacementPosition(actor), size, density, type);
|
2021-04-05 17:54:49 +00:00
|
|
|
actor.print(Caption.of("worldedit.forestgen.created", TextComponent.of(affected)));
|
2019-07-06 00:46:48 +00:00
|
|
|
return affected;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2021-07-24 15:34:05 +00:00
|
|
|
name = "pumpkins",
|
|
|
|
aliases = {"/pumpkins"},
|
|
|
|
desc = "Generate pumpkin patches"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.generation.pumpkins")
|
|
|
|
@Logging(POSITION)
|
2021-07-24 15:34:05 +00:00
|
|
|
public int pumpkins(
|
|
|
|
Actor actor, LocalSession session, EditSession editSession,
|
|
|
|
@Arg(desc = "The size of the patch", def = "10")
|
|
|
|
int size,
|
|
|
|
@Arg(desc = "//TODO ", def = "0.02")
|
|
|
|
double density
|
|
|
|
) throws WorldEditException {
|
2019-11-20 00:11:54 +00:00
|
|
|
checkCommandArgument(0 <= density && density <= 100, "Density must be between 0 and 100");
|
2019-08-05 21:39:00 +00:00
|
|
|
worldEdit.checkMaxRadius(size);
|
2019-11-20 00:11:54 +00:00
|
|
|
int affected = editSession.makePumpkinPatches(session.getPlacementPosition(actor), size, density);
|
2021-04-05 17:54:49 +00:00
|
|
|
actor.print(Caption.of("worldedit.pumpkins.created", TextComponent.of(affected)));
|
2019-07-06 00:46:48 +00:00
|
|
|
return affected;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2021-07-24 15:34:05 +00:00
|
|
|
name = "/hpyramid",
|
|
|
|
desc = "Generate a hollow pyramid"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.generation.pyramid")
|
|
|
|
@Logging(PLACEMENT)
|
2021-07-24 15:34:05 +00:00
|
|
|
public int hollowPyramid(
|
|
|
|
Actor actor, LocalSession session, EditSession editSession,
|
|
|
|
@Arg(desc = "The pattern of blocks to set")
|
|
|
|
Pattern pattern,
|
|
|
|
@Confirm(Confirm.Processor.RADIUS) @Arg(desc = "The size of the pyramid")
|
|
|
|
int size
|
|
|
|
) throws WorldEditException {
|
2020-01-26 18:01:16 +00:00
|
|
|
return pyramid(actor, session, editSession, pattern, size, true);
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2021-07-24 15:34:05 +00:00
|
|
|
name = "/pyramid",
|
|
|
|
desc = "Generate a filled pyramid"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.generation.pyramid")
|
|
|
|
@Logging(PLACEMENT)
|
2021-07-24 15:34:05 +00:00
|
|
|
public int pyramid(
|
|
|
|
Actor actor, LocalSession session, EditSession editSession,
|
|
|
|
@Arg(desc = "The pattern of blocks to set")
|
|
|
|
Pattern pattern,
|
|
|
|
@Confirm(Confirm.Processor.RADIUS) @Arg(desc = "The size of the pyramid")
|
|
|
|
int size,
|
|
|
|
@Switch(name = 'h', desc = "Make a hollow pyramid")
|
|
|
|
boolean hollow
|
|
|
|
) throws WorldEditException {
|
2014-06-28 08:01:49 +00:00
|
|
|
worldEdit.checkMaxRadius(size);
|
2020-01-26 18:01:16 +00:00
|
|
|
BlockVector3 pos = session.getPlacementPosition(actor);
|
2019-11-21 06:50:37 +00:00
|
|
|
int affected = editSession.makePyramid(pos, pattern, size, !hollow);
|
|
|
|
if (actor instanceof Player) {
|
|
|
|
((Player) actor).findFreePosition();
|
|
|
|
}
|
2021-04-05 17:54:49 +00:00
|
|
|
actor.print(Caption.of("worldedit.pyramid.created", TextComponent.of(affected)));
|
2020-01-26 18:01:16 +00:00
|
|
|
return affected;
|
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(
|
2021-07-24 15:34:05 +00:00
|
|
|
name = "/generate",
|
|
|
|
aliases = {"/gen", "/g"},
|
|
|
|
desc = "Generates a shape according to a formula.",
|
|
|
|
descFooter = "See also https://tinyurl.com/weexpr."
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.generation.shape")
|
|
|
|
@Logging(ALL)
|
2019-11-21 06:50:37 +00:00
|
|
|
@Confirm(Confirm.Processor.REGION)
|
2021-07-24 15:34:05 +00:00
|
|
|
public int generate(
|
|
|
|
Actor actor, LocalSession session, EditSession editSession,
|
|
|
|
@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")
|
|
|
|
boolean offsetCenter
|
|
|
|
) 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-10-07 19:23:40 +00:00
|
|
|
zero = session.getPlacementPosition(actor).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);
|
|
|
|
|
2020-10-05 17:41:41 +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
|
|
|
|
2019-11-21 06:50:37 +00:00
|
|
|
try {
|
2021-07-24 15:34:05 +00:00
|
|
|
final int affected = editSession.makeShape(
|
|
|
|
region,
|
|
|
|
zero,
|
|
|
|
unit1,
|
|
|
|
pattern,
|
|
|
|
String.join(" ", expression),
|
|
|
|
hollow,
|
|
|
|
session.getTimeout()
|
|
|
|
);
|
2019-11-21 06:50:37 +00:00
|
|
|
if (actor instanceof Player) {
|
|
|
|
((Player) actor).findFreePosition();
|
2018-09-07 15:09:31 +00:00
|
|
|
}
|
2021-04-05 17:54:49 +00:00
|
|
|
actor.print(Caption.of("worldedit.generate.created", TextComponent.of(affected)));
|
2020-01-26 18:01:16 +00:00
|
|
|
return affected;
|
2019-11-21 06:50:37 +00:00
|
|
|
} catch (ExpressionException e) {
|
2019-10-22 10:14:52 +00:00
|
|
|
actor.printError(TextComponent.of(e.getMessage()));
|
2020-01-26 18:01:16 +00:00
|
|
|
return 0;
|
2019-11-21 06:50:37 +00:00
|
|
|
}
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2021-07-24 15:34:05 +00:00
|
|
|
name = "/generatebiome",
|
|
|
|
aliases = {"/genbiome", "/gb"},
|
|
|
|
desc = "Sets biome according to a formula.",
|
|
|
|
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)
|
2021-08-17 00:47:09 +00:00
|
|
|
@Preload(Preload.PreloadCheck.PRELOAD)
|
2019-11-21 06:50:37 +00:00
|
|
|
@Confirm(Confirm.Processor.REGION)
|
2021-07-24 15:34:05 +00:00
|
|
|
public int generateBiome(
|
|
|
|
Actor actor, LocalSession session, EditSession editSession,
|
|
|
|
@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")
|
|
|
|
boolean offsetCenter
|
|
|
|
) 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-10-07 19:23:40 +00:00
|
|
|
zero = session.getPlacementPosition(actor).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);
|
|
|
|
|
2020-10-05 17:41:41 +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-12-23 16:19:33 +00:00
|
|
|
}
|
2019-06-12 21:12:12 +00:00
|
|
|
|
2019-01-09 07:13:44 +00:00
|
|
|
final Vector3 unit1 = unit;
|
2019-11-21 06:50:37 +00:00
|
|
|
try {
|
2021-07-24 15:34:05 +00:00
|
|
|
final int affected = editSession.makeBiomeShape(
|
|
|
|
region,
|
|
|
|
zero,
|
|
|
|
unit1,
|
|
|
|
target,
|
|
|
|
String.join(" ", expression),
|
|
|
|
hollow,
|
|
|
|
session.getTimeout()
|
|
|
|
);
|
2021-04-05 17:54:49 +00:00
|
|
|
actor.print(Caption.of("worldedit.generatebiome.changed", TextComponent.of(affected)));
|
2020-01-26 18:01:16 +00:00
|
|
|
return affected;
|
2019-11-21 06:50:37 +00:00
|
|
|
} catch (ExpressionException e) {
|
2019-10-22 10:14:52 +00:00
|
|
|
actor.printError(TextComponent.of(e.getMessage()));
|
2020-01-26 18:01:16 +00:00
|
|
|
return 0;
|
2019-11-21 06:50:37 +00:00
|
|
|
}
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
2019-06-12 21:12:12 +00:00
|
|
|
|
2021-07-23 15:48:51 +00:00
|
|
|
//FAWE start
|
|
|
|
@Command(
|
|
|
|
name = "/caves",
|
|
|
|
desc = "Generates a cave network"
|
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.generation.caves")
|
|
|
|
@Logging(PLACEMENT)
|
2021-08-17 00:47:09 +00:00
|
|
|
@Preload(Preload.PreloadCheck.PRELOAD)
|
2021-07-23 15:48:51 +00:00
|
|
|
@Confirm(Confirm.Processor.REGION)
|
2021-07-24 15:34:05 +00:00
|
|
|
public void caves(
|
|
|
|
Actor actor, LocalSession session, EditSession editSession, @Selection Region region,
|
|
|
|
@Arg(name = "size", desc = "TODO", def = "8") int sizeOpt,
|
|
|
|
@Arg(name = "frequency", desc = "TODO", def = "40") int frequencyOpt,
|
|
|
|
@Arg(name = "rarity", desc = "TODO", def = "7") int rarityOpt,
|
|
|
|
@Arg(name = "minY", desc = "TODO", def = "8") int minYOpt,
|
|
|
|
@Arg(name = "maxY", desc = "TODO", def = "127") int maxYOpt,
|
|
|
|
@Arg(name = "systemFrequency", desc = "TODO", def = "1") int systemFrequencyOpt,
|
|
|
|
@Arg(name = "individualRarity", desc = "TODO", def = "25") int individualRarityOpt,
|
|
|
|
@Arg(name = "pocketChance", desc = "TODO", def = "0") int pocketChanceOpt,
|
|
|
|
@Arg(name = "pocketMin", desc = "TODO", def = "0") int pocketMinOpt,
|
|
|
|
@Arg(name = "pocketMax", desc = "TODO", def = "3") int pocketMaxOpt
|
|
|
|
) throws WorldEditException {
|
|
|
|
CavesGen gen = new CavesGen(
|
|
|
|
sizeOpt,
|
|
|
|
frequencyOpt,
|
|
|
|
rarityOpt,
|
|
|
|
minYOpt,
|
|
|
|
maxYOpt,
|
|
|
|
systemFrequencyOpt,
|
|
|
|
individualRarityOpt,
|
|
|
|
pocketChanceOpt,
|
|
|
|
pocketMinOpt,
|
|
|
|
pocketMaxOpt
|
|
|
|
);
|
2021-07-23 15:48:51 +00:00
|
|
|
editSession.generate(region, gen);
|
|
|
|
actor.print(Caption.of("fawe.worldedit.visitor.visitor.block", editSession.getBlockChangeCount()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
name = "/ores",
|
|
|
|
desc = "Generates ores"
|
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.generation.ore")
|
|
|
|
@Logging(PLACEMENT)
|
2021-08-17 00:47:09 +00:00
|
|
|
@Preload(Preload.PreloadCheck.PRELOAD)
|
2021-07-23 15:48:51 +00:00
|
|
|
@Confirm(Confirm.Processor.REGION)
|
2021-07-24 15:34:05 +00:00
|
|
|
public void ores(
|
|
|
|
Actor actor,
|
|
|
|
LocalSession session,
|
|
|
|
EditSession editSession,
|
|
|
|
@Selection Region region,
|
|
|
|
@Arg(desc = "Mask") Mask mask
|
|
|
|
) throws WorldEditException {
|
2021-07-24 14:47:22 +00:00
|
|
|
if (mask instanceof AbstractExtentMask) {
|
|
|
|
((AbstractExtentMask) mask).setExtent(editSession);
|
|
|
|
}
|
2021-07-23 15:48:51 +00:00
|
|
|
editSession.addOres(region, mask);
|
|
|
|
actor.print(Caption.of("fawe.worldedit.visitor.visitor.block", editSession.getBlockChangeCount()));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
|
|
|
name = "/img",
|
2021-07-24 15:34:05 +00:00
|
|
|
aliases = {"/image", "image"},
|
2021-07-23 15:48:51 +00:00
|
|
|
desc = "Generate an image"
|
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.generation.image")
|
|
|
|
@Logging(PLACEMENT)
|
2021-07-24 15:34:05 +00:00
|
|
|
public void image(
|
|
|
|
Actor actor,
|
|
|
|
LocalSession session,
|
|
|
|
EditSession editSession,
|
|
|
|
@Arg(desc = "Image URL (imgur only)") String imageURL,
|
|
|
|
@Arg(desc = "boolean", def = "true") boolean randomize,
|
|
|
|
@Arg(desc = "TODO", def = "100") int threshold,
|
|
|
|
@Arg(desc = "BlockVector2", def = "") BlockVector2 dimensions
|
|
|
|
) throws WorldEditException, IOException {
|
2021-07-23 15:48:51 +00:00
|
|
|
TextureUtil tu = Fawe.get().getCachedTextureUtil(randomize, 0, threshold);
|
|
|
|
URL url = new URL(imageURL);
|
|
|
|
if (!url.getHost().equalsIgnoreCase("i.imgur.com")) {
|
|
|
|
throw new IOException("Only i.imgur.com links are allowed!");
|
|
|
|
}
|
|
|
|
BufferedImage image = MainUtil.readImage(url);
|
|
|
|
if (dimensions != null) {
|
|
|
|
image = ImageUtil.getScaledInstance(image, dimensions.getBlockX(), dimensions.getBlockZ(),
|
2021-07-24 15:34:05 +00:00
|
|
|
RenderingHints.VALUE_INTERPOLATION_BILINEAR, false
|
|
|
|
);
|
2021-07-23 15:48:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BlockVector3 pos1 = session.getPlacementPosition(actor);
|
|
|
|
BlockVector3 pos2 = pos1.add(image.getWidth() - 1, 0, image.getHeight() - 1);
|
|
|
|
CuboidRegion region = new CuboidRegion(pos1, pos2);
|
|
|
|
int[] count = new int[1];
|
|
|
|
final BufferedImage finalImage = image;
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
} catch (Throwable e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
return false;
|
2021-07-24 14:47:22 +00:00
|
|
|
}, editSession);
|
2021-07-23 15:48:51 +00:00
|
|
|
Operations.completeBlindly(visitor);
|
|
|
|
actor.print(Caption.of("fawe.worldedit.visitor.visitor.block", editSession.getBlockChangeCount()));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(name = "/ore", desc = "Generates ores")
|
|
|
|
@CommandPermissions("worldedit.generation.ore")
|
|
|
|
@Logging(PLACEMENT)
|
2021-08-17 00:47:09 +00:00
|
|
|
@Preload(Preload.PreloadCheck.PRELOAD)
|
2021-07-23 15:48:51 +00:00
|
|
|
@Confirm(Confirm.Processor.REGION)
|
2021-07-24 15:34:05 +00:00
|
|
|
public void ore(
|
|
|
|
Actor actor,
|
|
|
|
LocalSession session,
|
|
|
|
EditSession editSession,
|
|
|
|
@Selection Region region,
|
|
|
|
@Arg(desc = "Mask") Mask mask,
|
|
|
|
@Arg(desc = "Pattern") Pattern material,
|
|
|
|
@Arg(desc = "Ore vein size") @Range(from = 0, to = Integer.MAX_VALUE) int size,
|
|
|
|
@Arg(desc = "Ore vein frequency (number of times to attempt to place ore)", def = "10") @Range(from = 0, to = Integer.MAX_VALUE) int freq,
|
|
|
|
@Arg(desc = "Ore vein rarity (% chance each attempt is placed)", def = "100") @Range(from = 0, to = 100) int rarity,
|
2021-08-17 21:13:51 +00:00
|
|
|
@Arg(desc = "Ore vein min y", def = "0") int minY,
|
|
|
|
@Arg(desc = "Ore vein max y", def = "63") int maxY
|
2021-07-24 15:34:05 +00:00
|
|
|
) throws WorldEditException {
|
2021-07-24 14:47:22 +00:00
|
|
|
if (mask instanceof AbstractExtentMask) {
|
|
|
|
((AbstractExtentMask) mask).setExtent(editSession);
|
|
|
|
}
|
2021-08-17 21:13:51 +00:00
|
|
|
checkCommandArgument(minY >= editSession.getMinY(), Caption.of("fawe.error.outside-range-lower", "miny",
|
|
|
|
editSession.getMinY()));
|
|
|
|
checkCommandArgument(maxY <= editSession.getMaxY(), Caption.of("fawe.error.outside-range-upper", "maxy",
|
|
|
|
editSession.getMaxY()));
|
|
|
|
checkCommandArgument(minY < maxY, Caption.of("fawe.error.argument-size-mismatch", "miny",
|
|
|
|
"maxy"));
|
2021-07-23 15:48:51 +00:00
|
|
|
editSession.addOre(region, mask, material, size, freq, rarity, minY, maxY);
|
|
|
|
actor.print(Caption.of("fawe.worldedit.visitor.visitor.block", editSession.getBlockChangeCount()));
|
|
|
|
}
|
|
|
|
//FAWE end
|
|
|
|
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|