Added support for non-integer radius to //fill, //fillr, //drain, //fixlava, //fixwater, //snow and //thaw.

This commit is contained in:
TomyLobo 2011-08-15 14:35:21 +02:00
parent a57830706e
commit c79d90bb99
3 changed files with 20 additions and 18 deletions

View File

@ -590,7 +590,7 @@ public void flushQueue() {
* @return number of blocks affected
* @throws MaxChangedBlocksException
*/
public int fillXZ(Vector origin, BaseBlock block, int radius, int depth,
public int fillXZ(Vector origin, BaseBlock block, double radius, int depth,
boolean recursive) throws MaxChangedBlocksException {
int affected = 0;
@ -695,7 +695,7 @@ private int fillY(int x, int cy, int z, BaseBlock block, int minY)
* @return number of blocks affected
* @throws MaxChangedBlocksException
*/
public int fillXZ(Vector origin, Pattern pattern, int radius, int depth,
public int fillXZ(Vector origin, Pattern pattern, double radius, int depth,
boolean recursive) throws MaxChangedBlocksException {
int affected = 0;
@ -1492,7 +1492,7 @@ public int moveCuboidRegion(Region region, Vector dir, int distance,
* @return number of blocks affected
* @throws MaxChangedBlocksException
*/
public int drainArea(Vector pos, int radius)
public int drainArea(Vector pos, double radius)
throws MaxChangedBlocksException {
int affected = 0;
@ -1559,7 +1559,7 @@ public int drainArea(Vector pos, int radius)
* @return number of blocks affected
* @throws MaxChangedBlocksException
*/
public int fixLiquid(Vector pos, int radius, int moving, int stationary)
public int fixLiquid(Vector pos, double radius, int moving, int stationary)
throws MaxChangedBlocksException {
int affected = 0;
@ -1920,7 +1920,7 @@ public int makePyramid(Vector pos, Pattern block, int size,
* @return number of blocks affected
* @throws MaxChangedBlocksException
*/
public int thaw(Vector pos, int radius)
public int thaw(Vector pos, double radius)
throws MaxChangedBlocksException {
int affected = 0;
int radiusSq = (int)Math.pow(radius, 2);
@ -1932,8 +1932,9 @@ public int thaw(Vector pos, int radius)
BaseBlock air = new BaseBlock(0);
BaseBlock water = new BaseBlock(BlockID.STATIONARY_WATER);
for (int x = ox - radius; x <= ox + radius; ++x) {
for (int z = oz - radius; z <= oz + radius; ++z) {
int ceilRadius = (int) Math.ceil(radius);
for (int x = ox - ceilRadius; x <= ox + ceilRadius; ++x) {
for (int z = oz - ceilRadius; z <= oz + ceilRadius; ++z) {
if ((new Vector(x, oy, z)).distanceSq(pos) > radiusSq) {
continue;
}
@ -1968,7 +1969,7 @@ public int thaw(Vector pos, int radius)
* @return number of blocks affected
* @throws MaxChangedBlocksException
*/
public int simulateSnow(Vector pos, int radius)
public int simulateSnow(Vector pos, double radius)
throws MaxChangedBlocksException {
int affected = 0;
int radiusSq = (int)Math.pow(radius, 2);
@ -1980,8 +1981,9 @@ public int simulateSnow(Vector pos, int radius)
BaseBlock ice = new BaseBlock(79);
BaseBlock snow = new BaseBlock(78);
for (int x = ox - radius; x <= ox + radius; ++x) {
for (int z = oz - radius; z <= oz + radius; ++z) {
int ceilRadius = (int) Math.ceil(radius);
for (int x = ox - ceilRadius; x <= ox + ceilRadius; ++x) {
for (int z = oz - ceilRadius; z <= oz + ceilRadius; ++z) {
if ((new Vector(x, oy, z)).distanceSq(pos) > radiusSq) {
continue;
}

View File

@ -661,7 +661,7 @@ private File getSafeFile(LocalPlayer player, File dir, String filename,
* @param radius
* @throws MaxRadiusException
*/
public void checkMaxRadius(int radius) throws MaxRadiusException {
public void checkMaxRadius(double radius) throws MaxRadiusException {
if (config.maxRadius > 0 && radius > config.maxRadius) {
throw new MaxRadiusException();
}

View File

@ -52,7 +52,7 @@ public static void fill(CommandContext args, WorldEdit we,
throws WorldEditException {
Pattern pattern = we.getBlockPattern(player, args.getString(0));
int radius = Math.max(1, args.getInteger(1));
double radius = Math.max(1, args.getDouble(1));
we.checkMaxRadius(radius);
int depth = args.argsLength() > 2 ? Math.max(1, args.getInteger(2)) : 1;
@ -82,7 +82,7 @@ public static void fillr(CommandContext args, WorldEdit we,
throws WorldEditException {
Pattern pattern = we.getBlockPattern(player, args.getString(0));
int radius = Math.max(1, args.getInteger(1));
double radius = Math.max(1, args.getDouble(1));
we.checkMaxRadius(radius);
int depth = args.argsLength() > 2 ? Math.max(1, args.getInteger(2)) : 1;
@ -111,7 +111,7 @@ public static void drain(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
int radius = Math.max(0, args.getInteger(0));
double radius = Math.max(0, args.getDouble(0));
we.checkMaxRadius(radius);
int affected = editSession.drainArea(
session.getPlacementPosition(player), radius);
@ -131,7 +131,7 @@ public static void fixLava(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
int radius = Math.max(0, args.getInteger(0));
double radius = Math.max(0, args.getDouble(0));
we.checkMaxRadius(radius);
int affected = editSession.fixLiquid(
session.getPlacementPosition(player), radius, 10, 11);
@ -151,7 +151,7 @@ public static void fixWater(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
int radius = Math.max(0, args.getInteger(0));
double radius = Math.max(0, args.getDouble(0));
we.checkMaxRadius(radius);
int affected = editSession.fixLiquid(
session.getPlacementPosition(player), radius, 8, 9);
@ -270,7 +270,7 @@ public static void snow(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
int size = args.argsLength() > 0 ? Math.max(1, args.getInteger(0)) : 10;
double size = args.argsLength() > 0 ? Math.max(1, args.getDouble(0)) : 10;
int affected = editSession.simulateSnow(session.getPlacementPosition(player), size);
player.print(affected + " surfaces covered. Let it snow~");
@ -289,7 +289,7 @@ public static void thaw(CommandContext args, WorldEdit we,
LocalSession session, LocalPlayer player, EditSession editSession)
throws WorldEditException {
int size = args.argsLength() > 0 ? Math.max(1, args.getInteger(0)) : 10;
double size = args.argsLength() > 0 ? Math.max(1, args.getDouble(0)) : 10;
int affected = editSession.thaw(session.getPlacementPosition(player), size);
player.print(affected + " surfaces thawed.");