2010-10-02 21:52:42 +00:00
|
|
|
/*
|
2014-03-31 23:55:58 +00:00
|
|
|
* WorldEdit, a Minecraft world manipulation toolkit
|
|
|
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
|
|
|
* Copyright (C) WorldEdit team and contributors
|
2010-10-02 21:52:42 +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
|
2010-10-02 21:52:42 +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.
|
2010-10-02 21:52:42 +00:00
|
|
|
*
|
2014-04-04 22:03:18 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
2010-10-02 21:52:42 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2011-01-01 18:33:18 +00:00
|
|
|
*/
|
2014-03-31 23:55:58 +00:00
|
|
|
|
2011-01-01 01:06:42 +00:00
|
|
|
package com.sk89q.worldedit;
|
|
|
|
|
2012-08-23 23:52:37 +00:00
|
|
|
import com.sk89q.worldedit.blocks.BaseBlock;
|
|
|
|
import com.sk89q.worldedit.blocks.BlockID;
|
|
|
|
import com.sk89q.worldedit.blocks.BlockType;
|
2014-04-28 06:34:39 +00:00
|
|
|
import com.sk89q.worldedit.entity.BaseEntity;
|
|
|
|
import com.sk89q.worldedit.entity.Entity;
|
2014-04-03 01:57:25 +00:00
|
|
|
import com.sk89q.worldedit.event.extent.EditSessionEvent;
|
2014-04-23 07:33:00 +00:00
|
|
|
import com.sk89q.worldedit.extent.ChangeSetExtent;
|
|
|
|
import com.sk89q.worldedit.extent.Extent;
|
|
|
|
import com.sk89q.worldedit.extent.MaskingExtent;
|
|
|
|
import com.sk89q.worldedit.extent.NullExtent;
|
|
|
|
import com.sk89q.worldedit.extent.buffer.ForgetfulExtentBuffer;
|
|
|
|
import com.sk89q.worldedit.extent.cache.LastAccessExtentCache;
|
|
|
|
import com.sk89q.worldedit.extent.inventory.BlockBag;
|
2014-04-03 02:08:50 +00:00
|
|
|
import com.sk89q.worldedit.extent.inventory.BlockBagExtent;
|
2014-04-01 03:29:05 +00:00
|
|
|
import com.sk89q.worldedit.extent.reorder.MultiStageReorder;
|
2014-04-03 02:08:50 +00:00
|
|
|
import com.sk89q.worldedit.extent.validation.BlockChangeLimiter;
|
|
|
|
import com.sk89q.worldedit.extent.validation.DataValidatorExtent;
|
|
|
|
import com.sk89q.worldedit.extent.world.BlockQuirkExtent;
|
|
|
|
import com.sk89q.worldedit.extent.world.ChunkLoadingExtent;
|
|
|
|
import com.sk89q.worldedit.extent.world.FastModeExtent;
|
2014-04-23 07:33:00 +00:00
|
|
|
import com.sk89q.worldedit.extent.world.SurvivalModeExtent;
|
2014-03-28 23:49:01 +00:00
|
|
|
import com.sk89q.worldedit.function.GroundFunction;
|
|
|
|
import com.sk89q.worldedit.function.RegionMaskingFilter;
|
2014-03-28 23:15:40 +00:00
|
|
|
import com.sk89q.worldedit.function.block.BlockReplace;
|
2014-04-23 07:33:00 +00:00
|
|
|
import com.sk89q.worldedit.function.block.Counter;
|
2014-03-30 01:32:10 +00:00
|
|
|
import com.sk89q.worldedit.function.block.Naturalizer;
|
2014-03-28 23:15:40 +00:00
|
|
|
import com.sk89q.worldedit.function.generator.GardenPatchGenerator;
|
2014-03-30 08:36:02 +00:00
|
|
|
import com.sk89q.worldedit.function.mask.*;
|
2014-03-31 23:55:58 +00:00
|
|
|
import com.sk89q.worldedit.function.operation.*;
|
2014-03-30 20:54:57 +00:00
|
|
|
import com.sk89q.worldedit.function.pattern.BlockPattern;
|
2014-03-30 19:59:39 +00:00
|
|
|
import com.sk89q.worldedit.function.pattern.Patterns;
|
2014-03-28 23:49:01 +00:00
|
|
|
import com.sk89q.worldedit.function.util.RegionOffset;
|
2014-03-30 21:45:42 +00:00
|
|
|
import com.sk89q.worldedit.function.visitor.*;
|
2014-03-31 05:33:16 +00:00
|
|
|
import com.sk89q.worldedit.history.UndoContext;
|
|
|
|
import com.sk89q.worldedit.history.change.BlockChange;
|
2014-03-31 23:55:58 +00:00
|
|
|
import com.sk89q.worldedit.history.changeset.BlockOptimizedHistory;
|
|
|
|
import com.sk89q.worldedit.history.changeset.ChangeSet;
|
2014-04-23 07:33:00 +00:00
|
|
|
import com.sk89q.worldedit.internal.expression.Expression;
|
|
|
|
import com.sk89q.worldedit.internal.expression.ExpressionException;
|
|
|
|
import com.sk89q.worldedit.internal.expression.runtime.RValue;
|
2014-03-30 19:13:45 +00:00
|
|
|
import com.sk89q.worldedit.math.interpolation.Interpolation;
|
|
|
|
import com.sk89q.worldedit.math.interpolation.KochanekBartelsInterpolation;
|
|
|
|
import com.sk89q.worldedit.math.interpolation.Node;
|
2014-03-30 08:36:02 +00:00
|
|
|
import com.sk89q.worldedit.math.noise.RandomNoise;
|
2014-03-30 10:08:56 +00:00
|
|
|
import com.sk89q.worldedit.math.transform.AffineTransform;
|
2012-08-23 23:52:37 +00:00
|
|
|
import com.sk89q.worldedit.patterns.Pattern;
|
2014-03-27 06:10:47 +00:00
|
|
|
import com.sk89q.worldedit.patterns.SingleBlockPattern;
|
2014-03-30 01:32:10 +00:00
|
|
|
import com.sk89q.worldedit.regions.*;
|
2014-04-03 02:08:50 +00:00
|
|
|
import com.sk89q.worldedit.regions.shape.ArbitraryBiomeShape;
|
|
|
|
import com.sk89q.worldedit.regions.shape.ArbitraryShape;
|
|
|
|
import com.sk89q.worldedit.regions.shape.RegionShape;
|
|
|
|
import com.sk89q.worldedit.regions.shape.WorldEditExpressionEnvironment;
|
2014-04-28 06:34:39 +00:00
|
|
|
import com.sk89q.worldedit.util.*;
|
2014-04-01 03:11:23 +00:00
|
|
|
import com.sk89q.worldedit.util.collection.DoubleArrayList;
|
2014-04-03 01:57:25 +00:00
|
|
|
import com.sk89q.worldedit.util.eventbus.EventBus;
|
2014-04-23 07:33:00 +00:00
|
|
|
import com.sk89q.worldedit.world.NullWorld;
|
2014-04-05 09:59:38 +00:00
|
|
|
import com.sk89q.worldedit.world.World;
|
2010-10-02 21:52:42 +00:00
|
|
|
|
2014-03-31 23:55:58 +00:00
|
|
|
import javax.annotation.Nullable;
|
2014-03-01 00:14:44 +00:00
|
|
|
import java.util.*;
|
|
|
|
|
2014-03-28 02:57:24 +00:00
|
|
|
import static com.google.common.base.Preconditions.checkArgument;
|
|
|
|
import static com.google.common.base.Preconditions.checkNotNull;
|
2014-03-30 04:05:09 +00:00
|
|
|
import static com.sk89q.worldedit.regions.Regions.*;
|
2014-03-28 02:57:24 +00:00
|
|
|
|
2010-10-02 21:52:42 +00:00
|
|
|
/**
|
2014-03-31 23:55:58 +00:00
|
|
|
* An {@link Extent} that handles history, {@link BlockBag}s, change limits,
|
|
|
|
* block re-ordering, and much more. Most operations in WorldEdit use this class.
|
|
|
|
* </p>
|
|
|
|
* Most of the actual functionality is implemented with a number of other
|
|
|
|
* {@link Extent}s that are chained together. For example, history is logged
|
|
|
|
* using the {@link ChangeSetExtent}.
|
2010-10-02 21:52:42 +00:00
|
|
|
*/
|
2014-04-03 01:57:25 +00:00
|
|
|
@SuppressWarnings("FieldCanBeLocal")
|
2014-03-30 04:05:09 +00:00
|
|
|
public class EditSession implements Extent {
|
2011-08-07 00:40:48 +00:00
|
|
|
|
2010-10-05 07:40:50 +00:00
|
|
|
/**
|
2014-04-04 01:24:06 +00:00
|
|
|
* Used by {@link #setBlock(Vector, BaseBlock, Stage)} to
|
2014-03-31 23:55:58 +00:00
|
|
|
* determine which {@link Extent}s should be bypassed.
|
2010-10-05 07:40:50 +00:00
|
|
|
*/
|
2014-04-04 01:24:06 +00:00
|
|
|
public enum Stage {
|
|
|
|
BEFORE_HISTORY,
|
|
|
|
BEFORE_REORDER,
|
|
|
|
BEFORE_CHANGE
|
2014-03-31 23:55:58 +00:00
|
|
|
}
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2014-03-31 23:55:58 +00:00
|
|
|
@SuppressWarnings("ProtectedField")
|
2014-04-05 09:59:38 +00:00
|
|
|
protected final World world;
|
2014-03-31 23:55:58 +00:00
|
|
|
private final ChangeSet changeSet = new BlockOptimizedHistory();
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2014-04-06 04:49:25 +00:00
|
|
|
private @Nullable FastModeExtent fastModeExtent;
|
2014-04-23 07:33:00 +00:00
|
|
|
private final SurvivalModeExtent survivalExtent;
|
2014-04-06 04:49:25 +00:00
|
|
|
private @Nullable ChunkLoadingExtent chunkLoadingExtent;
|
|
|
|
private @Nullable LastAccessExtentCache cacheExtent;
|
|
|
|
private @Nullable BlockQuirkExtent quirkExtent;
|
|
|
|
private @Nullable DataValidatorExtent validator;
|
2014-03-31 23:55:58 +00:00
|
|
|
private final BlockBagExtent blockBagExtent;
|
2014-04-01 03:29:05 +00:00
|
|
|
private final MultiStageReorder reorderExtent;
|
2014-04-06 04:49:25 +00:00
|
|
|
private @Nullable ChangeSetExtent changeSetExtent;
|
2014-03-31 23:55:58 +00:00
|
|
|
private final MaskingExtent maskingExtent;
|
|
|
|
private final BlockChangeLimiter changeLimiter;
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2014-03-31 23:55:58 +00:00
|
|
|
private final Extent bypassReorderHistory;
|
|
|
|
private final Extent bypassHistory;
|
|
|
|
private final Extent bypassNone;
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2014-03-31 23:55:58 +00:00
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
private Mask oldMask;
|
2010-10-05 07:40:50 +00:00
|
|
|
|
2014-04-04 03:48:42 +00:00
|
|
|
/**
|
|
|
|
* @deprecated use {@link WorldEdit#getEditSessionFactory()} to create {@link EditSession}s
|
|
|
|
*/
|
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
@Deprecated
|
|
|
|
public EditSession(LocalWorld world, int maxBlocks) {
|
|
|
|
this(world, maxBlocks, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @deprecated use {@link WorldEdit#getEditSessionFactory()} to create {@link EditSession}s
|
|
|
|
*/
|
|
|
|
@Deprecated
|
|
|
|
public EditSession(LocalWorld world, int maxBlocks, @Nullable BlockBag blockBag) {
|
|
|
|
this(WorldEdit.getInstance().getEventBus(), world, maxBlocks, blockBag, new EditSessionEvent(world, null, maxBlocks, null));
|
|
|
|
}
|
|
|
|
|
2010-12-31 22:31:49 +00:00
|
|
|
/**
|
|
|
|
* Construct the object with a maximum number of blocks and a block bag.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2014-04-03 01:57:25 +00:00
|
|
|
* @param eventBus the event bus
|
2014-03-31 23:55:58 +00:00
|
|
|
* @param world the world
|
|
|
|
* @param maxBlocks the maximum number of blocks that can be changed, or -1 to use no limit
|
|
|
|
* @param blockBag an optional {@link BlockBag} to use, otherwise null
|
2014-04-03 01:57:25 +00:00
|
|
|
* @param event the event to call with the extent
|
2010-12-31 22:31:49 +00:00
|
|
|
*/
|
2014-04-05 09:59:38 +00:00
|
|
|
EditSession(EventBus eventBus, World world, int maxBlocks, @Nullable BlockBag blockBag, EditSessionEvent event) {
|
2014-04-03 01:57:25 +00:00
|
|
|
checkNotNull(eventBus);
|
2014-03-31 23:55:58 +00:00
|
|
|
checkArgument(maxBlocks >= -1, "maxBlocks >= -1 required");
|
2014-04-03 01:57:25 +00:00
|
|
|
checkNotNull(event);
|
2011-01-01 18:33:18 +00:00
|
|
|
|
|
|
|
this.world = world;
|
2010-12-31 22:31:49 +00:00
|
|
|
|
2014-04-06 04:49:25 +00:00
|
|
|
if (world != null) {
|
|
|
|
Extent extent;
|
|
|
|
|
|
|
|
// This extents are ALWAYS used
|
|
|
|
extent = fastModeExtent = new FastModeExtent(world, false);
|
2014-04-23 07:33:00 +00:00
|
|
|
extent = survivalExtent = new SurvivalModeExtent(extent, world);
|
2014-04-22 08:19:02 +00:00
|
|
|
extent = quirkExtent = new BlockQuirkExtent(extent, world);
|
2014-04-06 04:49:25 +00:00
|
|
|
extent = chunkLoadingExtent = new ChunkLoadingExtent(extent, world);
|
|
|
|
extent = cacheExtent = new LastAccessExtentCache(extent);
|
|
|
|
extent = wrapExtent(extent, eventBus, event, Stage.BEFORE_CHANGE);
|
|
|
|
extent = validator = new DataValidatorExtent(extent, world);
|
|
|
|
extent = blockBagExtent = new BlockBagExtent(extent, blockBag);
|
|
|
|
|
|
|
|
// This extent can be skipped by calling rawSetBlock()
|
|
|
|
extent = reorderExtent = new MultiStageReorder(extent, false);
|
|
|
|
extent = wrapExtent(extent, eventBus, event, Stage.BEFORE_REORDER);
|
|
|
|
|
|
|
|
// These extents can be skipped by calling smartSetBlock()
|
|
|
|
extent = changeSetExtent = new ChangeSetExtent(extent, changeSet);
|
|
|
|
extent = maskingExtent = new MaskingExtent(extent, Masks.alwaysTrue());
|
|
|
|
extent = changeLimiter = new BlockChangeLimiter(extent, maxBlocks);
|
|
|
|
extent = wrapExtent(extent, eventBus, event, Stage.BEFORE_HISTORY);
|
|
|
|
|
|
|
|
this.bypassReorderHistory = blockBagExtent;
|
|
|
|
this.bypassHistory = reorderExtent;
|
|
|
|
this.bypassNone = extent;
|
|
|
|
} else {
|
|
|
|
Extent extent = new NullExtent();
|
2014-04-23 07:33:00 +00:00
|
|
|
extent = survivalExtent = new SurvivalModeExtent(extent, new NullWorld());
|
2014-04-06 04:49:25 +00:00
|
|
|
extent = blockBagExtent = new BlockBagExtent(extent, blockBag);
|
|
|
|
extent = reorderExtent = new MultiStageReorder(extent, false);
|
|
|
|
extent = maskingExtent = new MaskingExtent(extent, Masks.alwaysTrue());
|
|
|
|
extent = changeLimiter = new BlockChangeLimiter(extent, maxBlocks);
|
|
|
|
this.bypassReorderHistory = extent;
|
|
|
|
this.bypassHistory = extent;
|
|
|
|
this.bypassNone = extent;
|
|
|
|
}
|
2014-04-04 01:24:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private Extent wrapExtent(Extent extent, EventBus eventBus, EditSessionEvent event, Stage stage) {
|
|
|
|
event = event.clone(stage);
|
|
|
|
event.setExtent(extent);
|
|
|
|
eventBus.post(event);
|
|
|
|
return event.getExtent();
|
2014-03-30 04:05:09 +00:00
|
|
|
}
|
|
|
|
|
2010-10-11 08:22:47 +00:00
|
|
|
/**
|
2014-03-31 23:55:58 +00:00
|
|
|
* Get the world.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2014-03-31 23:55:58 +00:00
|
|
|
* @return the world
|
2010-10-11 08:22:47 +00:00
|
|
|
*/
|
2014-04-05 09:59:38 +00:00
|
|
|
public World getWorld() {
|
2014-03-31 23:55:58 +00:00
|
|
|
return world;
|
2010-10-05 07:40:50 +00:00
|
|
|
}
|
|
|
|
|
2011-03-13 00:37:07 +00:00
|
|
|
/**
|
2014-03-31 05:33:16 +00:00
|
|
|
* Get the underlying {@link ChangeSet}.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2014-03-31 05:33:16 +00:00
|
|
|
* @return the change set
|
2011-03-13 00:37:07 +00:00
|
|
|
*/
|
2014-03-31 05:33:16 +00:00
|
|
|
public ChangeSet getChangeSet() {
|
|
|
|
return changeSet;
|
|
|
|
}
|
2011-03-13 00:37:07 +00:00
|
|
|
|
2014-03-31 05:33:16 +00:00
|
|
|
/**
|
2014-03-31 23:55:58 +00:00
|
|
|
* Get the maximum number of blocks that can be changed. -1 will be returned
|
|
|
|
* if it the limit disabled.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2014-03-31 23:55:58 +00:00
|
|
|
* @return the limit (>= 0) or -1 for no limit
|
2011-02-18 23:14:43 +00:00
|
|
|
*/
|
2014-03-31 23:55:58 +00:00
|
|
|
public int getBlockChangeLimit() {
|
|
|
|
return changeLimiter.getLimit();
|
2011-02-18 23:14:43 +00:00
|
|
|
}
|
|
|
|
|
2010-10-13 05:38:05 +00:00
|
|
|
/**
|
2014-03-31 23:55:58 +00:00
|
|
|
* Set the maximum number of blocks that can be changed.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2014-03-31 23:55:58 +00:00
|
|
|
* @param limit the limit (>= 0) or -1 for no limit
|
2010-10-13 05:38:05 +00:00
|
|
|
*/
|
2014-03-31 23:55:58 +00:00
|
|
|
public void setBlockChangeLimit(int limit) {
|
|
|
|
changeLimiter.setLimit(limit);
|
2010-10-13 05:38:05 +00:00
|
|
|
}
|
|
|
|
|
2010-10-05 07:40:50 +00:00
|
|
|
/**
|
2014-03-31 23:55:58 +00:00
|
|
|
* Returns queue status.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2014-03-31 23:55:58 +00:00
|
|
|
* @return whether the queue is enabled
|
2010-10-05 07:40:50 +00:00
|
|
|
*/
|
2014-03-31 23:55:58 +00:00
|
|
|
public boolean isQueueEnabled() {
|
|
|
|
return reorderExtent.isEnabled();
|
2010-10-02 21:52:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-03-31 23:55:58 +00:00
|
|
|
* Queue certain types of block for better reproduction of those blocks.
|
2010-10-02 21:52:42 +00:00
|
|
|
*/
|
2014-03-31 23:55:58 +00:00
|
|
|
public void enableQueue() {
|
|
|
|
reorderExtent.setEnabled(true);
|
2010-10-11 08:22:47 +00:00
|
|
|
}
|
|
|
|
|
2011-01-31 06:15:08 +00:00
|
|
|
/**
|
2014-03-31 23:55:58 +00:00
|
|
|
* Disable the queue. This will flush the queue.
|
2011-01-31 06:15:08 +00:00
|
|
|
*/
|
2014-03-31 23:55:58 +00:00
|
|
|
public void disableQueue() {
|
|
|
|
if (isQueueEnabled()) {
|
|
|
|
flushQueue();
|
2011-07-15 07:00:48 +00:00
|
|
|
}
|
2014-03-31 23:55:58 +00:00
|
|
|
reorderExtent.setEnabled(true);
|
2011-07-15 07:00:48 +00:00
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2010-10-11 08:22:47 +00:00
|
|
|
/**
|
2014-03-31 23:55:58 +00:00
|
|
|
* Get the mask.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2014-03-31 23:55:58 +00:00
|
|
|
* @return mask, may be null
|
2010-10-11 08:22:47 +00:00
|
|
|
*/
|
2014-03-31 23:55:58 +00:00
|
|
|
public Mask getMask() {
|
|
|
|
return oldMask;
|
2010-10-02 21:52:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-03-31 23:55:58 +00:00
|
|
|
* Set a mask.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2014-03-31 23:55:58 +00:00
|
|
|
* @param mask mask or null
|
2010-10-02 21:52:42 +00:00
|
|
|
*/
|
2014-03-31 23:55:58 +00:00
|
|
|
public void setMask(Mask mask) {
|
|
|
|
this.oldMask = mask;
|
|
|
|
if (mask == null) {
|
|
|
|
maskingExtent.setMask(Masks.alwaysTrue());
|
|
|
|
} else {
|
2014-06-28 02:55:38 +00:00
|
|
|
maskingExtent.setMask(mask);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @deprecated Use {@link #setMask(Mask)}
|
|
|
|
*/
|
|
|
|
@Deprecated
|
|
|
|
public void setMask(com.sk89q.worldedit.masks.Mask mask) {
|
|
|
|
if (mask == null) {
|
|
|
|
setMask((Mask) null);
|
|
|
|
} else {
|
|
|
|
setMask(Masks.wrap(mask));
|
2014-03-31 23:55:58 +00:00
|
|
|
}
|
2010-10-02 21:52:42 +00:00
|
|
|
}
|
|
|
|
|
2014-04-23 07:33:00 +00:00
|
|
|
/**
|
|
|
|
* Get the {@link SurvivalModeExtent}.
|
|
|
|
*
|
|
|
|
* @return the survival simulation extent
|
|
|
|
*/
|
|
|
|
public SurvivalModeExtent getSurvivalExtent() {
|
|
|
|
return survivalExtent;
|
|
|
|
}
|
|
|
|
|
2010-10-02 21:52:42 +00:00
|
|
|
/**
|
2014-03-31 23:55:58 +00:00
|
|
|
* Set whether fast mode is enabled.
|
|
|
|
* </p>
|
|
|
|
* Fast mode may skip lighting checks or adjacent block notification.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2014-03-31 23:55:58 +00:00
|
|
|
* @param enabled true to enable
|
2010-10-02 21:52:42 +00:00
|
|
|
*/
|
2014-03-31 23:55:58 +00:00
|
|
|
public void setFastMode(boolean enabled) {
|
2014-04-06 04:49:25 +00:00
|
|
|
if (fastModeExtent != null) {
|
|
|
|
fastModeExtent.setEnabled(enabled);
|
|
|
|
}
|
2010-10-02 21:52:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-03-31 23:55:58 +00:00
|
|
|
* Return fast mode status.
|
|
|
|
* </p>
|
|
|
|
* Fast mode may skip lighting checks or adjacent block notification.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2014-03-31 23:55:58 +00:00
|
|
|
* @return true if enabled
|
2010-10-02 21:52:42 +00:00
|
|
|
*/
|
2014-03-31 23:55:58 +00:00
|
|
|
public boolean hasFastMode() {
|
2014-04-06 04:49:25 +00:00
|
|
|
return fastModeExtent != null ? fastModeExtent.isEnabled() : false;
|
2010-10-02 21:52:42 +00:00
|
|
|
}
|
2010-10-04 23:39:35 +00:00
|
|
|
|
|
|
|
/**
|
2014-03-31 23:55:58 +00:00
|
|
|
* Get the {@link BlockBag} is used.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2014-03-31 23:55:58 +00:00
|
|
|
* @return a block bag or null
|
2010-10-04 23:39:35 +00:00
|
|
|
*/
|
2014-03-31 23:55:58 +00:00
|
|
|
public BlockBag getBlockBag() {
|
|
|
|
return blockBagExtent.getBlockBag();
|
2010-10-04 23:39:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-03-31 23:55:58 +00:00
|
|
|
* Set a {@link BlockBag} to use.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2014-03-31 23:55:58 +00:00
|
|
|
* @param blockBag the block bag to set, or null to use none
|
2010-10-04 23:39:35 +00:00
|
|
|
*/
|
2014-03-31 23:55:58 +00:00
|
|
|
public void setBlockBag(BlockBag blockBag) {
|
|
|
|
blockBagExtent.setBlockBag(blockBag);
|
2010-10-04 23:39:35 +00:00
|
|
|
}
|
2010-10-05 07:40:50 +00:00
|
|
|
|
|
|
|
/**
|
2014-03-31 23:55:58 +00:00
|
|
|
* Gets the list of missing blocks and clears the list for the next
|
|
|
|
* operation.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2014-03-31 23:55:58 +00:00
|
|
|
* @return a map of missing blocks
|
2010-10-05 07:40:50 +00:00
|
|
|
*/
|
2014-03-31 23:55:58 +00:00
|
|
|
public Map<Integer, Integer> popMissingBlocks() {
|
|
|
|
return blockBagExtent.popMissing();
|
2010-10-05 07:40:50 +00:00
|
|
|
}
|
2011-08-07 00:40:48 +00:00
|
|
|
|
2011-06-04 17:30:45 +00:00
|
|
|
/**
|
2014-03-31 23:55:58 +00:00
|
|
|
* Get the number of blocks changed, including repeated block changes.
|
|
|
|
* </p>
|
|
|
|
* This number may not be accurate.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2014-03-31 23:55:58 +00:00
|
|
|
* @return the number of block changes
|
2011-06-04 17:30:45 +00:00
|
|
|
*/
|
2014-03-31 23:55:58 +00:00
|
|
|
public int getBlockChangeCount() {
|
|
|
|
return changeSet.size();
|
2011-06-04 17:30:45 +00:00
|
|
|
}
|
2011-08-07 00:40:48 +00:00
|
|
|
|
2014-04-01 01:22:44 +00:00
|
|
|
@Override
|
|
|
|
public BaseBlock getLazyBlock(Vector position) {
|
|
|
|
return world.getLazyBlock(position);
|
|
|
|
}
|
|
|
|
|
2014-03-31 23:55:58 +00:00
|
|
|
@Override
|
|
|
|
public BaseBlock getBlock(Vector position) {
|
|
|
|
return world.getBlock(position);
|
2011-06-04 17:30:45 +00:00
|
|
|
}
|
2010-10-05 07:40:50 +00:00
|
|
|
|
2014-04-01 01:22:44 +00:00
|
|
|
/**
|
|
|
|
* Get a block type at the given position.
|
|
|
|
*
|
|
|
|
* @param position the position
|
|
|
|
* @return the block type
|
|
|
|
* @deprecated Use {@link #getLazyBlock(Vector)} or {@link #getBlock(Vector)}
|
|
|
|
*/
|
|
|
|
@Deprecated
|
2014-03-31 23:55:58 +00:00
|
|
|
public int getBlockType(Vector position) {
|
|
|
|
return world.getBlockType(position);
|
2011-11-01 13:54:32 +00:00
|
|
|
}
|
|
|
|
|
2014-04-01 01:22:44 +00:00
|
|
|
/**
|
|
|
|
* Get a block data at the given position.
|
|
|
|
*
|
|
|
|
* @param position the position
|
|
|
|
* @return the block data
|
|
|
|
* @deprecated Use {@link #getLazyBlock(Vector)} or {@link #getBlock(Vector)}
|
|
|
|
*/
|
|
|
|
@Deprecated
|
2014-03-31 23:55:58 +00:00
|
|
|
public int getBlockData(Vector position) {
|
|
|
|
return world.getBlockData(position);
|
2013-01-19 14:31:00 +00:00
|
|
|
}
|
|
|
|
|
2011-11-01 13:54:32 +00:00
|
|
|
/**
|
2014-03-31 23:55:58 +00:00
|
|
|
* Gets the block type at a position.
|
2011-11-01 13:54:32 +00:00
|
|
|
*
|
2014-03-31 23:55:58 +00:00
|
|
|
* @param position the position
|
|
|
|
* @return a block
|
|
|
|
* @deprecated Use {@link #getBlock(Vector)}
|
2011-11-01 13:54:32 +00:00
|
|
|
*/
|
2014-03-31 23:55:58 +00:00
|
|
|
@Deprecated
|
|
|
|
public BaseBlock rawGetBlock(Vector position) {
|
|
|
|
return getBlock(position);
|
2011-11-01 13:54:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the highest solid 'terrain' block which can occur naturally.
|
|
|
|
*
|
2014-03-31 23:55:58 +00:00
|
|
|
* @param x the X coordinate
|
|
|
|
* @param z the Z cooridnate
|
2011-11-01 13:54:32 +00:00
|
|
|
* @param minY minimal height
|
|
|
|
* @param maxY maximal height
|
|
|
|
* @return height of highest block found or 'minY'
|
|
|
|
*/
|
|
|
|
public int getHighestTerrainBlock(int x, int z, int minY, int maxY) {
|
|
|
|
return getHighestTerrainBlock(x, z, minY, maxY, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the highest solid 'terrain' block which can occur naturally.
|
|
|
|
*
|
2014-03-31 23:55:58 +00:00
|
|
|
* @param x the X coordinate
|
|
|
|
* @param z the Z coordinate
|
2011-11-01 13:54:32 +00:00
|
|
|
* @param minY minimal height
|
|
|
|
* @param maxY maximal height
|
|
|
|
* @param naturalOnly look at natural blocks or all blocks
|
|
|
|
* @return height of highest block found or 'minY'
|
|
|
|
*/
|
|
|
|
public int getHighestTerrainBlock(int x, int z, int minY, int maxY, boolean naturalOnly) {
|
|
|
|
for (int y = maxY; y >= minY; --y) {
|
|
|
|
Vector pt = new Vector(x, y, z);
|
|
|
|
int id = getBlockType(pt);
|
2013-06-23 19:04:23 +00:00
|
|
|
int data = getBlockData(pt);
|
|
|
|
if (naturalOnly ? BlockType.isNaturalTerrainBlock(id, data) : !BlockType.canPassThrough(id, data)) {
|
2011-11-01 13:54:32 +00:00
|
|
|
return y;
|
|
|
|
}
|
|
|
|
}
|
2014-03-31 23:55:58 +00:00
|
|
|
|
2011-11-01 13:54:32 +00:00
|
|
|
return minY;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-03-31 23:55:58 +00:00
|
|
|
* Set a block, bypassing both history and block re-ordering.
|
2011-11-01 13:54:32 +00:00
|
|
|
*
|
2014-03-31 23:55:58 +00:00
|
|
|
* @param position the position to set the block at
|
|
|
|
* @param block the block
|
2014-04-04 01:24:06 +00:00
|
|
|
* @param stage the level
|
2014-03-31 23:55:58 +00:00
|
|
|
* @return whether the block changed
|
|
|
|
*/
|
2014-04-04 01:24:06 +00:00
|
|
|
public boolean setBlock(Vector position, BaseBlock block, Stage stage) throws WorldEditException {
|
|
|
|
switch (stage) {
|
|
|
|
case BEFORE_HISTORY:
|
2014-04-01 00:20:54 +00:00
|
|
|
return bypassNone.setBlock(position, block);
|
2014-04-04 01:24:06 +00:00
|
|
|
case BEFORE_CHANGE:
|
2014-04-01 00:20:54 +00:00
|
|
|
return bypassHistory.setBlock(position, block);
|
2014-04-04 01:24:06 +00:00
|
|
|
case BEFORE_REORDER:
|
2014-04-01 00:20:54 +00:00
|
|
|
return bypassReorderHistory.setBlock(position, block);
|
2014-03-31 23:55:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
throw new RuntimeException("New enum entry added that is unhandled here");
|
|
|
|
}
|
|
|
|
|
2011-11-01 13:54:32 +00:00
|
|
|
/**
|
2014-03-31 23:55:58 +00:00
|
|
|
* Set a block, bypassing both history and block re-ordering.
|
|
|
|
*
|
|
|
|
* @param position the position to set the block at
|
|
|
|
* @param block the block
|
|
|
|
* @return whether the block changed
|
2011-11-01 13:54:32 +00:00
|
|
|
*/
|
2014-03-31 23:55:58 +00:00
|
|
|
public boolean rawSetBlock(Vector position, BaseBlock block) {
|
|
|
|
try {
|
2014-04-04 01:24:06 +00:00
|
|
|
return setBlock(position, block, Stage.BEFORE_CHANGE);
|
2014-03-31 23:55:58 +00:00
|
|
|
} catch (WorldEditException e) {
|
|
|
|
throw new RuntimeException("Unexpected exception", e);
|
|
|
|
}
|
2011-11-01 13:54:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-03-31 23:55:58 +00:00
|
|
|
* Set a block, bypassing history but still utilizing block re-ordering.
|
|
|
|
*
|
|
|
|
* @param position the position to set the block at
|
|
|
|
* @param block the block
|
|
|
|
* @return whether the block changed
|
2011-11-01 13:54:32 +00:00
|
|
|
*/
|
2014-03-31 23:55:58 +00:00
|
|
|
public boolean smartSetBlock(Vector position, BaseBlock block) {
|
|
|
|
try {
|
2014-04-04 01:24:06 +00:00
|
|
|
return setBlock(position, block, Stage.BEFORE_REORDER);
|
2014-03-31 23:55:58 +00:00
|
|
|
} catch (WorldEditException e) {
|
|
|
|
throw new RuntimeException("Unexpected exception", e);
|
|
|
|
}
|
2011-11-01 13:54:32 +00:00
|
|
|
}
|
|
|
|
|
2014-04-01 00:20:54 +00:00
|
|
|
@Override
|
2014-03-31 23:55:58 +00:00
|
|
|
public boolean setBlock(Vector position, BaseBlock block) throws MaxChangedBlocksException {
|
|
|
|
try {
|
2014-04-04 01:24:06 +00:00
|
|
|
return setBlock(position, block, Stage.BEFORE_HISTORY);
|
2014-03-31 23:55:58 +00:00
|
|
|
} catch (MaxChangedBlocksException e) {
|
|
|
|
throw e;
|
|
|
|
} catch (WorldEditException e) {
|
|
|
|
throw new RuntimeException("Unexpected exception", e);
|
|
|
|
}
|
2011-11-01 13:54:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-03-31 23:55:58 +00:00
|
|
|
* Sets the block at a position, subject to both history and block re-ordering.
|
2011-11-01 13:54:32 +00:00
|
|
|
*
|
2014-03-31 23:55:58 +00:00
|
|
|
* @param position the position
|
|
|
|
* @param pattern a pattern to use
|
|
|
|
* @return Whether the block changed -- not entirely dependable
|
|
|
|
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
2011-11-01 13:54:32 +00:00
|
|
|
*/
|
2014-03-31 23:55:58 +00:00
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
public boolean setBlock(Vector position, Pattern pattern) throws MaxChangedBlocksException {
|
|
|
|
return setBlock(position, pattern.next(position));
|
2011-11-01 13:54:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-03-31 23:55:58 +00:00
|
|
|
* Set blocks that are in a set of positions and return the number of times
|
|
|
|
* that the block set calls returned true.
|
2011-11-01 13:54:32 +00:00
|
|
|
*
|
2014-03-31 23:55:58 +00:00
|
|
|
* @param vset a set of positions
|
|
|
|
* @param pattern the pattern
|
|
|
|
* @return the number of changed blocks
|
|
|
|
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
2011-11-01 13:54:32 +00:00
|
|
|
*/
|
2014-03-31 23:55:58 +00:00
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
private int setBlocks(Set<Vector> vset, Pattern pattern) throws MaxChangedBlocksException {
|
|
|
|
int affected = 0;
|
|
|
|
for (Vector v : vset) {
|
|
|
|
affected += setBlock(v, pattern) ? 1 : 0;
|
|
|
|
}
|
|
|
|
return affected;
|
2011-11-01 13:54:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-03-31 23:55:58 +00:00
|
|
|
* Set a block (only if a previous block was not there) if {@link Math#random()}
|
|
|
|
* returns a number less than the given probability.
|
2011-11-01 13:54:32 +00:00
|
|
|
*
|
2014-03-31 23:55:58 +00:00
|
|
|
* @param position the position
|
|
|
|
* @param block the block
|
|
|
|
* @param probability a probability between 0 and 1, inclusive
|
|
|
|
* @return whether a block was changed
|
|
|
|
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
2011-11-01 13:54:32 +00:00
|
|
|
*/
|
2014-03-31 23:55:58 +00:00
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
public boolean setChanceBlockIfAir(Vector position, BaseBlock block, double probability)
|
|
|
|
throws MaxChangedBlocksException {
|
|
|
|
return Math.random() <= probability && setBlockIfAir(position, block);
|
2011-11-01 13:54:32 +00:00
|
|
|
}
|
|
|
|
|
2010-10-05 07:40:50 +00:00
|
|
|
/**
|
2014-03-31 23:55:58 +00:00
|
|
|
* Set a block only if there's no block already there.
|
|
|
|
*
|
|
|
|
* @param position the position
|
|
|
|
* @param block the block to set
|
|
|
|
* @return if block was changed
|
|
|
|
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
|
|
|
* @deprecated Use your own method
|
2010-10-05 07:40:50 +00:00
|
|
|
*/
|
2014-03-31 23:55:58 +00:00
|
|
|
@Deprecated
|
|
|
|
public boolean setBlockIfAir(Vector position, BaseBlock block) throws MaxChangedBlocksException {
|
|
|
|
return getBlock(position).isAir() && setBlock(position, block);
|
|
|
|
}
|
2013-11-17 21:03:37 +00:00
|
|
|
|
2014-04-28 06:34:39 +00:00
|
|
|
@Override
|
|
|
|
public List<Entity> getEntities() {
|
|
|
|
return world.getEntities();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Nullable
|
|
|
|
public Entity createEntity(com.sk89q.worldedit.util.Location location, BaseEntity entity) {
|
|
|
|
return world.createEntity(location, entity);
|
|
|
|
}
|
|
|
|
|
2014-03-31 23:55:58 +00:00
|
|
|
/**
|
|
|
|
* Insert a contrived block change into the history.
|
|
|
|
*
|
|
|
|
* @param position the position
|
|
|
|
* @param existing the previous block at that position
|
|
|
|
* @param block the new block
|
|
|
|
* @deprecated Get the change set with {@link #getChangeSet()} and add the change with that
|
|
|
|
*/
|
|
|
|
@Deprecated
|
|
|
|
public void rememberChange(Vector position, BaseBlock existing, BaseBlock block) {
|
|
|
|
changeSet.add(new BlockChange(position.toBlockVector(), existing, block));
|
|
|
|
}
|
2011-10-24 02:04:45 +00:00
|
|
|
|
2014-03-31 23:55:58 +00:00
|
|
|
/**
|
|
|
|
* Restores all blocks to their initial state.
|
|
|
|
*
|
2014-04-01 01:49:39 +00:00
|
|
|
* @param editSession a new {@link EditSession} to perform the undo in
|
2014-03-31 23:55:58 +00:00
|
|
|
*/
|
2014-04-01 01:49:39 +00:00
|
|
|
public void undo(EditSession editSession) {
|
2014-03-31 23:55:58 +00:00
|
|
|
UndoContext context = new UndoContext();
|
2014-04-01 01:49:39 +00:00
|
|
|
context.setExtent(editSession.bypassHistory);
|
2014-04-01 23:21:27 +00:00
|
|
|
Operations.completeBlindly(ChangeSetExecutor.createUndo(changeSet, context));
|
2014-04-01 01:49:39 +00:00
|
|
|
editSession.flushQueue();
|
2014-03-31 23:55:58 +00:00
|
|
|
}
|
2011-10-24 02:04:45 +00:00
|
|
|
|
2014-03-31 23:55:58 +00:00
|
|
|
/**
|
|
|
|
* Sets to new state.
|
|
|
|
*
|
2014-04-01 01:49:39 +00:00
|
|
|
* @param editSession a new {@link EditSession} to perform the redo in
|
2014-03-31 23:55:58 +00:00
|
|
|
*/
|
2014-04-01 01:49:39 +00:00
|
|
|
public void redo(EditSession editSession) {
|
2014-03-31 23:55:58 +00:00
|
|
|
UndoContext context = new UndoContext();
|
2014-04-01 01:49:39 +00:00
|
|
|
context.setExtent(editSession.bypassHistory);
|
2014-04-01 23:21:27 +00:00
|
|
|
Operations.completeBlindly(ChangeSetExecutor.createRedo(changeSet, context));
|
2014-04-01 01:49:39 +00:00
|
|
|
editSession.flushQueue();
|
2014-03-31 23:55:58 +00:00
|
|
|
}
|
2011-10-24 02:04:45 +00:00
|
|
|
|
2014-03-31 23:55:58 +00:00
|
|
|
/**
|
|
|
|
* Get the number of changed blocks.
|
|
|
|
*
|
|
|
|
* @return the number of changes
|
|
|
|
*/
|
|
|
|
public int size() {
|
|
|
|
return getBlockChangeCount();
|
|
|
|
}
|
2011-10-24 02:04:45 +00:00
|
|
|
|
2014-04-04 00:52:53 +00:00
|
|
|
@Override
|
|
|
|
public Vector getMinimumPoint() {
|
|
|
|
return getWorld().getMinimumPoint();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Vector getMaximumPoint() {
|
|
|
|
return getWorld().getMaximumPoint();
|
|
|
|
}
|
|
|
|
|
2014-03-31 23:55:58 +00:00
|
|
|
/**
|
|
|
|
* Finish off the queue.
|
|
|
|
*/
|
|
|
|
public void flushQueue() {
|
2014-04-01 23:21:27 +00:00
|
|
|
Operations.completeBlindly(commit());
|
2014-03-31 23:55:58 +00:00
|
|
|
}
|
2011-10-24 02:04:45 +00:00
|
|
|
|
2014-03-31 23:55:58 +00:00
|
|
|
@Override
|
|
|
|
public @Nullable Operation commit() {
|
|
|
|
return bypassNone.commit();
|
|
|
|
}
|
2011-10-17 04:07:58 +00:00
|
|
|
|
2014-03-31 23:55:58 +00:00
|
|
|
public int countBlock(Region region, Set<Integer> searchIDs) {
|
|
|
|
Set<BaseBlock> passOn = new HashSet<BaseBlock>();
|
|
|
|
for (Integer i : searchIDs) {
|
|
|
|
passOn.add(new BaseBlock(i, -1));
|
2010-10-05 07:40:50 +00:00
|
|
|
}
|
2014-03-31 23:55:58 +00:00
|
|
|
return countBlocks(region, passOn);
|
|
|
|
}
|
2010-11-27 07:24:55 +00:00
|
|
|
|
2014-03-31 23:55:58 +00:00
|
|
|
/**
|
|
|
|
* Count the number of blocks of a list of types in a region.
|
|
|
|
*
|
|
|
|
* @param region the region
|
|
|
|
* @param searchBlocks the list of blocks to search
|
|
|
|
* @return the number of blocks that matched the pattern
|
|
|
|
*/
|
|
|
|
public int countBlocks(Region region, Set<BaseBlock> searchBlocks) {
|
|
|
|
FuzzyBlockMask mask = new FuzzyBlockMask(this, searchBlocks);
|
2014-04-01 03:29:05 +00:00
|
|
|
Counter count = new Counter();
|
2014-03-31 23:55:58 +00:00
|
|
|
RegionMaskingFilter filter = new RegionMaskingFilter(mask, count);
|
|
|
|
RegionVisitor visitor = new RegionVisitor(region, filter);
|
2014-04-01 23:21:27 +00:00
|
|
|
Operations.completeBlindly(visitor); // We can't throw exceptions, nor do we expect any
|
2014-03-31 23:55:58 +00:00
|
|
|
return count.getCount();
|
2010-10-05 07:40:50 +00:00
|
|
|
}
|
2010-10-11 08:22:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Fills an area recursively in the X/Z directions.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2014-03-27 06:10:47 +00:00
|
|
|
* @param origin the location to start from
|
|
|
|
* @param block the block to fill with
|
|
|
|
* @param radius the radius of the spherical area to fill
|
|
|
|
* @param depth the maximum depth, starting from the origin
|
|
|
|
* @param recursive whether a breadth-first search should be performed
|
2010-10-11 15:56:19 +00:00
|
|
|
* @return number of blocks affected
|
2014-03-27 06:10:47 +00:00
|
|
|
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
2010-10-11 08:22:47 +00:00
|
|
|
*/
|
2014-03-30 20:54:57 +00:00
|
|
|
@SuppressWarnings("deprecation")
|
2014-03-27 06:10:47 +00:00
|
|
|
public int fillXZ(Vector origin, BaseBlock block, double radius, int depth, boolean recursive)
|
2011-01-01 18:33:18 +00:00
|
|
|
throws MaxChangedBlocksException {
|
2014-03-27 06:10:47 +00:00
|
|
|
return fillXZ(origin, new SingleBlockPattern(block), radius, depth, recursive);
|
2010-10-11 08:22:47 +00:00
|
|
|
}
|
|
|
|
|
2010-11-16 22:07:52 +00:00
|
|
|
/**
|
|
|
|
* Fills an area recursively in the X/Z directions.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2014-03-28 03:48:36 +00:00
|
|
|
* @param origin the origin to start the fill from
|
2014-03-27 06:10:47 +00:00
|
|
|
* @param pattern the pattern to fill with
|
2014-03-28 03:48:36 +00:00
|
|
|
* @param radius the radius of the spherical area to fill, with 0 as the smallest radius
|
|
|
|
* @param depth the maximum depth, starting from the origin, with 1 as the smallest depth
|
2014-03-27 06:10:47 +00:00
|
|
|
* @param recursive whether a breadth-first search should be performed
|
2010-11-16 22:07:52 +00:00
|
|
|
* @return number of blocks affected
|
2014-03-27 06:10:47 +00:00
|
|
|
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
2010-11-16 22:07:52 +00:00
|
|
|
*/
|
2014-03-30 20:54:57 +00:00
|
|
|
@SuppressWarnings("deprecation")
|
2014-03-28 03:48:36 +00:00
|
|
|
public int fillXZ(Vector origin, Pattern pattern, double radius, int depth, boolean recursive) throws MaxChangedBlocksException {
|
2014-03-28 07:41:00 +00:00
|
|
|
checkNotNull(origin);
|
|
|
|
checkNotNull(pattern);
|
2014-03-28 03:48:36 +00:00
|
|
|
checkArgument(radius >= 0, "radius >= 0");
|
|
|
|
checkArgument(depth >= 1, "depth >= 1");
|
2010-11-17 04:03:54 +00:00
|
|
|
|
2014-03-30 08:36:02 +00:00
|
|
|
MaskIntersection mask = new MaskIntersection(
|
2014-03-27 06:10:47 +00:00
|
|
|
new RegionMask(new EllipsoidRegion(null, origin, new Vector(radius, radius, radius))),
|
2014-03-30 20:46:20 +00:00
|
|
|
new BoundedHeightMask(
|
|
|
|
Math.max(origin.getBlockY() - depth + 1, 0),
|
|
|
|
Math.min(getWorld().getMaxY(), origin.getBlockY())),
|
2014-03-30 08:36:02 +00:00
|
|
|
Masks.negate(new ExistingBlockMask(this)));
|
2010-11-17 04:03:54 +00:00
|
|
|
|
2014-03-27 06:10:47 +00:00
|
|
|
// Want to replace blocks
|
2014-03-30 19:59:39 +00:00
|
|
|
BlockReplace replace = new BlockReplace(this, Patterns.wrap(pattern));
|
2010-11-16 22:07:52 +00:00
|
|
|
|
2014-03-27 06:10:47 +00:00
|
|
|
// Pick how we're going to visit blocks
|
|
|
|
RecursiveVisitor visitor;
|
|
|
|
if (recursive) {
|
2014-03-30 20:46:20 +00:00
|
|
|
visitor = new RecursiveVisitor(mask, replace);
|
2014-03-27 06:10:47 +00:00
|
|
|
} else {
|
2014-03-30 20:46:20 +00:00
|
|
|
visitor = new DownwardVisitor(mask, replace, origin.getBlockY());
|
2010-11-16 22:07:52 +00:00
|
|
|
}
|
|
|
|
|
2014-03-27 06:10:47 +00:00
|
|
|
// Start at the origin
|
|
|
|
visitor.visit(origin);
|
2010-11-16 22:07:52 +00:00
|
|
|
|
2014-03-27 06:10:47 +00:00
|
|
|
// Execute
|
2014-04-01 23:21:27 +00:00
|
|
|
Operations.completeLegacy(visitor);
|
2010-11-16 22:07:52 +00:00
|
|
|
|
2014-03-27 06:10:47 +00:00
|
|
|
return visitor.getAffected();
|
2010-11-16 22:07:52 +00:00
|
|
|
}
|
|
|
|
|
2010-10-11 08:22:47 +00:00
|
|
|
/**
|
2014-03-28 02:57:24 +00:00
|
|
|
* Remove a cuboid above the given position with a given apothem and a given height.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2014-03-28 02:57:24 +00:00
|
|
|
* @param position base position
|
2014-03-28 03:48:36 +00:00
|
|
|
* @param apothem an apothem of the cuboid (on the XZ plane), where the minimum is 1
|
2014-03-28 02:57:24 +00:00
|
|
|
* @param height the height of the cuboid, where the minimum is 1
|
2010-10-11 15:56:19 +00:00
|
|
|
* @return number of blocks affected
|
2014-03-28 03:48:36 +00:00
|
|
|
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
2010-10-11 08:22:47 +00:00
|
|
|
*/
|
2014-03-30 20:54:57 +00:00
|
|
|
@SuppressWarnings("deprecation")
|
2014-03-28 02:57:24 +00:00
|
|
|
public int removeAbove(Vector position, int apothem, int height) throws MaxChangedBlocksException {
|
2014-03-28 07:41:00 +00:00
|
|
|
checkNotNull(position);
|
2014-03-28 02:57:24 +00:00
|
|
|
checkArgument(apothem >= 1, "apothem >= 1");
|
|
|
|
checkArgument(height >= 1, "height >= 1");
|
2010-10-11 08:22:47 +00:00
|
|
|
|
2014-03-28 02:57:24 +00:00
|
|
|
Region region = new CuboidRegion(
|
2014-03-28 03:57:20 +00:00
|
|
|
getWorld(), // Causes clamping of Y range
|
2014-03-28 02:57:24 +00:00
|
|
|
position.add(-apothem + 1, 0, -apothem + 1),
|
|
|
|
position.add(apothem - 1, height - 1, apothem - 1));
|
|
|
|
Pattern pattern = new SingleBlockPattern(new BaseBlock(BlockID.AIR));
|
|
|
|
return setBlocks(region, pattern);
|
2010-10-11 08:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-03-28 02:57:24 +00:00
|
|
|
* Remove a cuboid below the given position with a given apothem and a given height.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2014-03-28 02:57:24 +00:00
|
|
|
* @param position base position
|
2014-03-28 03:48:36 +00:00
|
|
|
* @param apothem an apothem of the cuboid (on the XZ plane), where the minimum is 1
|
2014-03-28 02:57:24 +00:00
|
|
|
* @param height the height of the cuboid, where the minimum is 1
|
2010-10-11 15:56:19 +00:00
|
|
|
* @return number of blocks affected
|
2014-03-28 03:48:36 +00:00
|
|
|
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
2010-10-11 08:22:47 +00:00
|
|
|
*/
|
2014-03-30 20:54:57 +00:00
|
|
|
@SuppressWarnings("deprecation")
|
2014-03-28 02:57:24 +00:00
|
|
|
public int removeBelow(Vector position, int apothem, int height) throws MaxChangedBlocksException {
|
2014-03-28 07:41:00 +00:00
|
|
|
checkNotNull(position);
|
2014-03-28 02:57:24 +00:00
|
|
|
checkArgument(apothem >= 1, "apothem >= 1");
|
|
|
|
checkArgument(height >= 1, "height >= 1");
|
2010-11-06 22:09:32 +00:00
|
|
|
|
2014-03-28 02:57:24 +00:00
|
|
|
Region region = new CuboidRegion(
|
2014-03-28 03:57:20 +00:00
|
|
|
getWorld(), // Causes clamping of Y range
|
2014-03-28 02:57:24 +00:00
|
|
|
position.add(-apothem + 1, 0, -apothem + 1),
|
|
|
|
position.add(apothem - 1, -height + 1, apothem - 1));
|
|
|
|
Pattern pattern = new SingleBlockPattern(new BaseBlock(BlockID.AIR));
|
|
|
|
return setBlocks(region, pattern);
|
2010-10-11 08:22:47 +00:00
|
|
|
}
|
|
|
|
|
2010-10-18 23:36:22 +00:00
|
|
|
/**
|
2014-03-28 03:48:36 +00:00
|
|
|
* Remove blocks of a certain type nearby a given position.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2014-03-28 03:48:36 +00:00
|
|
|
* @param position center position of cuboid
|
|
|
|
* @param blockType the block type to match
|
|
|
|
* @param apothem an apothem of the cuboid, where the minimum is 1
|
2010-10-18 23:36:22 +00:00
|
|
|
* @return number of blocks affected
|
2014-03-28 03:48:36 +00:00
|
|
|
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
2010-10-18 23:36:22 +00:00
|
|
|
*/
|
2014-03-30 20:54:57 +00:00
|
|
|
@SuppressWarnings("deprecation")
|
2014-03-28 03:48:36 +00:00
|
|
|
public int removeNear(Vector position, int blockType, int apothem) throws MaxChangedBlocksException {
|
2014-03-28 07:41:00 +00:00
|
|
|
checkNotNull(position);
|
2014-03-28 03:48:36 +00:00
|
|
|
checkArgument(apothem >= 1, "apothem >= 1");
|
2010-10-18 23:36:22 +00:00
|
|
|
|
2014-06-28 02:55:38 +00:00
|
|
|
Mask mask = new FuzzyBlockMask(this, new BaseBlock(blockType, -1));
|
2014-03-28 03:48:36 +00:00
|
|
|
Vector adjustment = new Vector(1, 1, 1).multiply(apothem - 1);
|
2014-03-28 03:57:20 +00:00
|
|
|
Region region = new CuboidRegion(
|
|
|
|
getWorld(), // Causes clamping of Y range
|
|
|
|
position.add(adjustment.multiply(-1)),
|
|
|
|
position.add(adjustment));
|
2014-03-28 03:48:36 +00:00
|
|
|
Pattern pattern = new SingleBlockPattern(new BaseBlock(BlockID.AIR));
|
|
|
|
return replaceBlocks(region, mask, pattern);
|
2010-10-18 23:36:22 +00:00
|
|
|
}
|
|
|
|
|
2010-10-11 08:22:47 +00:00
|
|
|
/**
|
2014-03-28 02:57:24 +00:00
|
|
|
* Sets all the blocks inside a region to a given block type.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2014-03-28 02:57:24 +00:00
|
|
|
* @param region the region
|
|
|
|
* @param block the block
|
2010-10-11 15:56:19 +00:00
|
|
|
* @return number of blocks affected
|
2014-03-28 02:57:24 +00:00
|
|
|
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
2010-10-11 08:22:47 +00:00
|
|
|
*/
|
2014-03-30 20:54:57 +00:00
|
|
|
@SuppressWarnings("deprecation")
|
2014-03-28 02:57:24 +00:00
|
|
|
public int setBlocks(Region region, BaseBlock block) throws MaxChangedBlocksException {
|
|
|
|
return setBlocks(region, new SingleBlockPattern(block));
|
2010-11-06 21:43:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-03-28 02:57:24 +00:00
|
|
|
* Sets all the blocks inside a region to a given pattern.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2014-03-28 02:57:24 +00:00
|
|
|
* @param region the region
|
|
|
|
* @param pattern the pattern that provides the replacement block
|
2010-11-06 21:43:56 +00:00
|
|
|
* @return number of blocks affected
|
2014-03-28 02:57:24 +00:00
|
|
|
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
2010-11-06 21:43:56 +00:00
|
|
|
*/
|
2014-03-30 20:54:57 +00:00
|
|
|
@SuppressWarnings("deprecation")
|
2014-03-28 02:57:24 +00:00
|
|
|
public int setBlocks(Region region, Pattern pattern) throws MaxChangedBlocksException {
|
2014-03-28 07:41:00 +00:00
|
|
|
checkNotNull(region);
|
|
|
|
checkNotNull(pattern);
|
2014-03-28 03:48:36 +00:00
|
|
|
|
2014-03-30 19:59:39 +00:00
|
|
|
BlockReplace replace = new BlockReplace(this, Patterns.wrap(pattern));
|
2014-03-28 02:57:24 +00:00
|
|
|
RegionVisitor visitor = new RegionVisitor(region, replace);
|
2014-04-01 23:21:27 +00:00
|
|
|
Operations.completeLegacy(visitor);
|
2014-03-28 02:57:24 +00:00
|
|
|
return visitor.getAffected();
|
2010-10-11 08:22:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-03-28 03:48:36 +00:00
|
|
|
* Replaces all the blocks matching a given filter, within a given region, to a block
|
|
|
|
* returned by a given pattern.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2014-03-28 03:48:36 +00:00
|
|
|
* @param region the region to replace the blocks within
|
|
|
|
* @param filter a list of block types to match, or null to use {@link com.sk89q.worldedit.masks.ExistingBlockMask}
|
|
|
|
* @param replacement the replacement block
|
2010-10-11 15:56:19 +00:00
|
|
|
* @return number of blocks affected
|
2014-03-28 03:48:36 +00:00
|
|
|
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
2010-10-11 08:22:47 +00:00
|
|
|
*/
|
2014-03-30 20:54:57 +00:00
|
|
|
@SuppressWarnings("deprecation")
|
2014-03-28 03:48:36 +00:00
|
|
|
public int replaceBlocks(Region region, Set<BaseBlock> filter, BaseBlock replacement) throws MaxChangedBlocksException {
|
|
|
|
return replaceBlocks(region, filter, new SingleBlockPattern(replacement));
|
2010-10-11 08:22:47 +00:00
|
|
|
}
|
2010-11-16 22:07:52 +00:00
|
|
|
|
|
|
|
/**
|
2014-03-28 03:48:36 +00:00
|
|
|
* Replaces all the blocks matching a given filter, within a given region, to a block
|
|
|
|
* returned by a given pattern.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2014-03-28 03:48:36 +00:00
|
|
|
* @param region the region to replace the blocks within
|
|
|
|
* @param filter a list of block types to match, or null to use {@link com.sk89q.worldedit.masks.ExistingBlockMask}
|
|
|
|
* @param pattern the pattern that provides the new blocks
|
2010-11-16 22:07:52 +00:00
|
|
|
* @return number of blocks affected
|
2014-03-28 03:48:36 +00:00
|
|
|
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
2010-11-16 22:07:52 +00:00
|
|
|
*/
|
2014-03-30 20:54:57 +00:00
|
|
|
@SuppressWarnings("deprecation")
|
2014-03-28 03:48:36 +00:00
|
|
|
public int replaceBlocks(Region region, Set<BaseBlock> filter, Pattern pattern) throws MaxChangedBlocksException {
|
2014-06-28 02:55:38 +00:00
|
|
|
Mask mask = filter == null ? new ExistingBlockMask(this) : new FuzzyBlockMask(this, filter);
|
2014-03-28 03:48:36 +00:00
|
|
|
return replaceBlocks(region, mask, pattern);
|
|
|
|
}
|
2012-01-31 15:57:40 +00:00
|
|
|
|
2014-03-28 03:48:36 +00:00
|
|
|
/**
|
|
|
|
* Replaces all the blocks matching a given mask, within a given region, to a block
|
|
|
|
* returned by a given pattern.
|
|
|
|
*
|
|
|
|
* @param region the region to replace the blocks within
|
|
|
|
* @param mask the mask that blocks must match
|
|
|
|
* @param pattern the pattern that provides the new blocks
|
|
|
|
* @return number of blocks affected
|
|
|
|
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
|
|
|
*/
|
2014-03-30 20:54:57 +00:00
|
|
|
@SuppressWarnings("deprecation")
|
2014-03-28 03:48:36 +00:00
|
|
|
public int replaceBlocks(Region region, Mask mask, Pattern pattern) throws MaxChangedBlocksException {
|
2014-03-28 07:41:00 +00:00
|
|
|
checkNotNull(region);
|
|
|
|
checkNotNull(mask);
|
|
|
|
checkNotNull(pattern);
|
2010-11-16 22:07:52 +00:00
|
|
|
|
2014-03-30 19:59:39 +00:00
|
|
|
BlockReplace replace = new BlockReplace(this, Patterns.wrap(pattern));
|
2014-06-28 02:55:38 +00:00
|
|
|
RegionMaskingFilter filter = new RegionMaskingFilter(mask, replace);
|
2014-03-28 03:48:36 +00:00
|
|
|
RegionVisitor visitor = new RegionVisitor(region, filter);
|
2014-04-01 23:21:27 +00:00
|
|
|
Operations.completeLegacy(visitor);
|
2014-03-28 03:48:36 +00:00
|
|
|
return visitor.getAffected();
|
2010-11-16 22:07:52 +00:00
|
|
|
}
|
2010-10-11 08:22:47 +00:00
|
|
|
|
2014-03-28 04:04:07 +00:00
|
|
|
/**
|
|
|
|
* Sets the blocks at the center of the given region to the given pattern.
|
|
|
|
* If the center sits between two blocks on a certain axis, then two blocks
|
|
|
|
* will be placed to mark the center.
|
|
|
|
*
|
|
|
|
* @param region the region to find the center of
|
|
|
|
* @param pattern the replacement pattern
|
|
|
|
* @return the number of blocks placed
|
|
|
|
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
|
|
|
*/
|
2014-03-30 20:54:57 +00:00
|
|
|
@SuppressWarnings("deprecation")
|
2014-03-28 04:04:07 +00:00
|
|
|
public int center(Region region, Pattern pattern) throws MaxChangedBlocksException {
|
2014-03-28 07:41:00 +00:00
|
|
|
checkNotNull(region);
|
|
|
|
checkNotNull(pattern);
|
2012-08-29 08:00:26 +00:00
|
|
|
|
2014-03-28 04:04:07 +00:00
|
|
|
Vector center = region.getCenter();
|
|
|
|
Region centerRegion = new CuboidRegion(
|
|
|
|
getWorld(), // Causes clamping of Y range
|
|
|
|
new Vector((int) center.getX(), (int) center.getY(), (int) center.getZ()),
|
|
|
|
center.toBlockVector());
|
|
|
|
return setBlocks(centerRegion, pattern);
|
2012-08-29 08:00:26 +00:00
|
|
|
}
|
|
|
|
|
2010-10-11 08:22:47 +00:00
|
|
|
/**
|
2014-03-28 07:40:04 +00:00
|
|
|
* Make the faces of the given region as if it was a {@link CuboidRegion}.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2014-03-28 07:40:04 +00:00
|
|
|
* @param region the region
|
|
|
|
* @param block the block to place
|
2010-10-11 15:56:19 +00:00
|
|
|
* @return number of blocks affected
|
2010-10-11 08:22:47 +00:00
|
|
|
* @throws MaxChangedBlocksException
|
|
|
|
*/
|
2014-03-30 20:54:57 +00:00
|
|
|
@SuppressWarnings("deprecation")
|
2014-03-28 07:40:04 +00:00
|
|
|
public int makeCuboidFaces(Region region, BaseBlock block) throws MaxChangedBlocksException {
|
|
|
|
return makeCuboidFaces(region, new SingleBlockPattern(block));
|
2010-10-11 08:22:47 +00:00
|
|
|
}
|
2011-08-24 22:27:18 +00:00
|
|
|
|
|
|
|
/**
|
2014-03-28 07:40:04 +00:00
|
|
|
* Make the faces of the given region as if it was a {@link CuboidRegion}.
|
2011-08-22 06:55:50 +00:00
|
|
|
*
|
2014-03-28 07:40:04 +00:00
|
|
|
* @param region the region
|
|
|
|
* @param pattern the pattern to place
|
2011-08-22 06:55:50 +00:00
|
|
|
* @return number of blocks affected
|
2014-03-28 07:40:04 +00:00
|
|
|
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
2011-08-22 06:55:50 +00:00
|
|
|
*/
|
2014-03-30 20:54:57 +00:00
|
|
|
@SuppressWarnings("deprecation")
|
2014-03-28 07:40:04 +00:00
|
|
|
public int makeCuboidFaces(Region region, Pattern pattern) throws MaxChangedBlocksException {
|
|
|
|
checkNotNull(region);
|
|
|
|
checkNotNull(pattern);
|
2011-08-22 06:55:50 +00:00
|
|
|
|
2014-03-28 07:40:04 +00:00
|
|
|
CuboidRegion cuboid = CuboidRegion.makeCuboid(region);
|
|
|
|
Region faces = cuboid.getFaces();
|
|
|
|
return setBlocks(faces, pattern);
|
2011-08-22 06:55:50 +00:00
|
|
|
}
|
2010-10-11 08:22:47 +00:00
|
|
|
|
2013-11-01 18:05:49 +00:00
|
|
|
/**
|
2014-03-28 07:40:04 +00:00
|
|
|
* Make the faces of the given region. The method by which the faces are found
|
|
|
|
* may be inefficient, because there may not be an efficient implementation supported
|
|
|
|
* for that specific shape.
|
2013-11-01 18:05:49 +00:00
|
|
|
*
|
2014-03-28 07:40:04 +00:00
|
|
|
* @param region the region
|
|
|
|
* @param pattern the pattern to place
|
2013-11-01 18:05:49 +00:00
|
|
|
* @return number of blocks affected
|
2014-03-28 07:40:04 +00:00
|
|
|
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
2013-11-01 18:05:49 +00:00
|
|
|
*/
|
2014-03-30 20:54:57 +00:00
|
|
|
@SuppressWarnings("deprecation")
|
2013-11-01 18:05:49 +00:00
|
|
|
public int makeFaces(final Region region, Pattern pattern) throws MaxChangedBlocksException {
|
2014-03-28 07:40:04 +00:00
|
|
|
checkNotNull(region);
|
|
|
|
checkNotNull(pattern);
|
|
|
|
|
|
|
|
if (region instanceof CuboidRegion) {
|
|
|
|
return makeCuboidFaces(region, pattern);
|
|
|
|
} else {
|
|
|
|
return new RegionShape(region).generate(this, pattern, true);
|
|
|
|
}
|
2013-11-01 18:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-18 17:45:03 +00:00
|
|
|
/**
|
2014-03-28 07:40:04 +00:00
|
|
|
* Make the walls (all faces but those parallel to the X-Z plane) of the given region
|
|
|
|
* as if it was a {@link CuboidRegion}.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2014-03-28 07:40:04 +00:00
|
|
|
* @param region the region
|
|
|
|
* @param block the block to place
|
2010-10-18 17:45:03 +00:00
|
|
|
* @return number of blocks affected
|
|
|
|
* @throws MaxChangedBlocksException
|
|
|
|
*/
|
2014-03-30 20:54:57 +00:00
|
|
|
@SuppressWarnings("deprecation")
|
2014-03-28 07:40:04 +00:00
|
|
|
public int makeCuboidWalls(Region region, BaseBlock block) throws MaxChangedBlocksException {
|
|
|
|
return makeCuboidWalls(region, new SingleBlockPattern(block));
|
2010-10-18 17:45:03 +00:00
|
|
|
}
|
|
|
|
|
2011-08-22 06:55:50 +00:00
|
|
|
/**
|
2014-03-28 07:40:04 +00:00
|
|
|
* Make the walls (all faces but those parallel to the X-Z plane) of the given region
|
|
|
|
* as if it was a {@link CuboidRegion}.
|
2011-08-22 06:55:50 +00:00
|
|
|
*
|
2014-03-28 07:40:04 +00:00
|
|
|
* @param region the region
|
|
|
|
* @param pattern the pattern to place
|
2011-08-22 06:55:50 +00:00
|
|
|
* @return number of blocks affected
|
2014-03-28 07:40:04 +00:00
|
|
|
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
2011-08-22 06:55:50 +00:00
|
|
|
*/
|
2014-03-30 20:54:57 +00:00
|
|
|
@SuppressWarnings("deprecation")
|
2014-03-28 07:40:04 +00:00
|
|
|
public int makeCuboidWalls(Region region, Pattern pattern) throws MaxChangedBlocksException {
|
|
|
|
checkNotNull(region);
|
|
|
|
checkNotNull(pattern);
|
2011-08-22 06:55:50 +00:00
|
|
|
|
2014-03-28 07:40:04 +00:00
|
|
|
CuboidRegion cuboid = CuboidRegion.makeCuboid(region);
|
|
|
|
Region faces = cuboid.getWalls();
|
|
|
|
return setBlocks(faces, pattern);
|
2011-08-22 06:55:50 +00:00
|
|
|
}
|
|
|
|
|
2013-11-01 18:05:49 +00:00
|
|
|
/**
|
2014-03-28 07:40:04 +00:00
|
|
|
* Make the walls of the given region. The method by which the walls are found
|
|
|
|
* may be inefficient, because there may not be an efficient implementation supported
|
|
|
|
* for that specific shape.
|
2013-11-01 18:05:49 +00:00
|
|
|
*
|
2014-03-28 07:40:04 +00:00
|
|
|
* @param region the region
|
|
|
|
* @param pattern the pattern to place
|
2013-11-01 18:05:49 +00:00
|
|
|
* @return number of blocks affected
|
2014-03-28 07:40:04 +00:00
|
|
|
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
2013-11-01 18:05:49 +00:00
|
|
|
*/
|
2014-03-30 20:54:57 +00:00
|
|
|
@SuppressWarnings("deprecation")
|
2013-11-01 18:05:49 +00:00
|
|
|
public int makeWalls(final Region region, Pattern pattern) throws MaxChangedBlocksException {
|
2014-03-28 07:40:04 +00:00
|
|
|
checkNotNull(region);
|
|
|
|
checkNotNull(pattern);
|
2013-11-03 09:15:28 +00:00
|
|
|
|
2014-03-28 07:40:04 +00:00
|
|
|
if (region instanceof CuboidRegion) {
|
|
|
|
return makeCuboidWalls(region, pattern);
|
|
|
|
} else {
|
|
|
|
final int minY = region.getMinimumPoint().getBlockY();
|
|
|
|
final int maxY = region.getMaximumPoint().getBlockY();
|
|
|
|
final ArbitraryShape shape = new RegionShape(region) {
|
|
|
|
@Override
|
|
|
|
protected BaseBlock getMaterial(int x, int y, int z, BaseBlock defaultMaterial) {
|
|
|
|
if (y > maxY || y < minY) {
|
|
|
|
// Put holes into the floor and ceiling by telling ArbitraryShape that the shape goes on outside the region
|
|
|
|
return defaultMaterial;
|
|
|
|
}
|
|
|
|
|
|
|
|
return super.getMaterial(x, y, z, defaultMaterial);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
return shape.generate(this, pattern, true);
|
|
|
|
}
|
2013-11-01 18:05:49 +00:00
|
|
|
}
|
|
|
|
|
2010-10-11 08:22:47 +00:00
|
|
|
/**
|
2014-03-28 23:49:01 +00:00
|
|
|
* Places a layer of blocks on top of ground blocks in the given region
|
|
|
|
* (as if it were a cuboid).
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2014-03-28 23:49:01 +00:00
|
|
|
* @param region the region
|
|
|
|
* @param block the placed block
|
2010-10-11 15:56:19 +00:00
|
|
|
* @return number of blocks affected
|
2014-03-28 23:49:01 +00:00
|
|
|
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
2010-10-11 08:22:47 +00:00
|
|
|
*/
|
2014-03-30 20:54:57 +00:00
|
|
|
@SuppressWarnings("deprecation")
|
2014-03-28 23:49:01 +00:00
|
|
|
public int overlayCuboidBlocks(Region region, BaseBlock block) throws MaxChangedBlocksException {
|
|
|
|
checkNotNull(block);
|
2011-01-30 08:47:02 +00:00
|
|
|
|
2014-03-28 23:49:01 +00:00
|
|
|
return overlayCuboidBlocks(region, new SingleBlockPattern(block));
|
2011-01-30 08:47:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-03-28 23:49:01 +00:00
|
|
|
* Places a layer of blocks on top of ground blocks in the given region
|
|
|
|
* (as if it were a cuboid).
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2014-03-28 23:49:01 +00:00
|
|
|
* @param region the region
|
|
|
|
* @param pattern the placed block pattern
|
2011-01-30 08:47:02 +00:00
|
|
|
* @return number of blocks affected
|
2014-03-28 23:49:01 +00:00
|
|
|
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
2011-01-30 08:47:02 +00:00
|
|
|
*/
|
2014-03-30 20:54:57 +00:00
|
|
|
@SuppressWarnings("deprecation")
|
2014-03-28 23:49:01 +00:00
|
|
|
public int overlayCuboidBlocks(Region region, Pattern pattern) throws MaxChangedBlocksException {
|
|
|
|
checkNotNull(region);
|
|
|
|
checkNotNull(pattern);
|
2011-01-30 08:47:02 +00:00
|
|
|
|
2014-03-30 19:59:39 +00:00
|
|
|
BlockReplace replace = new BlockReplace(this, Patterns.wrap(pattern));
|
2014-03-28 23:49:01 +00:00
|
|
|
RegionOffset offset = new RegionOffset(new Vector(0, 1, 0), replace);
|
2014-04-01 03:29:05 +00:00
|
|
|
GroundFunction ground = new GroundFunction(new ExistingBlockMask(this), offset);
|
2014-03-30 20:49:26 +00:00
|
|
|
LayerVisitor visitor = new LayerVisitor(asFlatRegion(region), minimumBlockY(region), maximumBlockY(region), ground);
|
2014-04-01 23:21:27 +00:00
|
|
|
Operations.completeLegacy(visitor);
|
2014-03-30 01:51:33 +00:00
|
|
|
return ground.getAffected();
|
2010-10-11 08:22:47 +00:00
|
|
|
}
|
|
|
|
|
2011-08-02 22:46:11 +00:00
|
|
|
/**
|
|
|
|
* Turns the first 3 layers into dirt/grass and the bottom layers
|
|
|
|
* into rock, like a natural Minecraft mountain.
|
|
|
|
*
|
2014-03-30 01:32:10 +00:00
|
|
|
* @param region the region to affect
|
2011-08-02 22:46:11 +00:00
|
|
|
* @return number of blocks affected
|
2014-03-30 01:32:10 +00:00
|
|
|
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
2011-08-02 22:46:11 +00:00
|
|
|
*/
|
2014-03-30 01:32:10 +00:00
|
|
|
public int naturalizeCuboidBlocks(Region region) throws MaxChangedBlocksException {
|
|
|
|
checkNotNull(region);
|
2011-08-02 22:46:11 +00:00
|
|
|
|
2014-03-30 01:32:10 +00:00
|
|
|
Naturalizer naturalizer = new Naturalizer(this);
|
|
|
|
FlatRegion flatRegion = Regions.asFlatRegion(region);
|
2014-03-30 20:49:26 +00:00
|
|
|
LayerVisitor visitor = new LayerVisitor(flatRegion, minimumBlockY(region), maximumBlockY(region), naturalizer);
|
2014-04-01 23:21:27 +00:00
|
|
|
Operations.completeLegacy(visitor);
|
2014-03-30 01:32:10 +00:00
|
|
|
return naturalizer.getAffected();
|
2011-08-02 22:46:11 +00:00
|
|
|
}
|
|
|
|
|
2010-10-11 17:27:18 +00:00
|
|
|
/**
|
|
|
|
* Stack a cuboid region.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2014-03-30 10:08:56 +00:00
|
|
|
* @param region the region to stack
|
|
|
|
* @param dir the direction to stack
|
|
|
|
* @param count the number of times to stack
|
|
|
|
* @param copyAir true to also copy air blocks
|
2010-10-11 17:27:18 +00:00
|
|
|
* @return number of blocks affected
|
2014-03-30 10:08:56 +00:00
|
|
|
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
2010-10-11 17:27:18 +00:00
|
|
|
*/
|
2014-03-30 10:08:56 +00:00
|
|
|
public int stackCuboidRegion(Region region, Vector dir, int count, boolean copyAir) throws MaxChangedBlocksException {
|
|
|
|
checkNotNull(region);
|
|
|
|
checkNotNull(dir);
|
|
|
|
checkArgument(count >= 1, "count >= 1 required");
|
2014-03-30 17:29:00 +00:00
|
|
|
|
2014-03-30 10:08:56 +00:00
|
|
|
Vector size = region.getMaximumPoint().subtract(region.getMinimumPoint()).add(1, 1, 1);
|
|
|
|
Vector to = region.getMinimumPoint();
|
|
|
|
ForwardExtentCopy copy = new ForwardExtentCopy(this, region, this, to);
|
|
|
|
copy.setRepetitions(count);
|
|
|
|
copy.setTransform(new AffineTransform().translate(dir.multiply(size)));
|
|
|
|
if (!copyAir) {
|
|
|
|
copy.setSourceMask(new ExistingBlockMask(this));
|
2010-10-11 08:22:47 +00:00
|
|
|
}
|
2014-04-01 23:21:27 +00:00
|
|
|
Operations.completeLegacy(copy);
|
2014-03-30 10:08:56 +00:00
|
|
|
return copy.getAffected();
|
2010-10-11 08:22:47 +00:00
|
|
|
}
|
2010-10-11 18:17:32 +00:00
|
|
|
|
2013-08-03 23:22:29 +00:00
|
|
|
/**
|
2014-03-30 17:29:00 +00:00
|
|
|
* Move the blocks in a region a certain direction.
|
2013-08-03 23:22:29 +00:00
|
|
|
*
|
2014-03-30 17:29:00 +00:00
|
|
|
* @param region the region to move
|
|
|
|
* @param dir the direction
|
|
|
|
* @param distance the distance to move
|
|
|
|
* @param copyAir true to copy air blocks
|
|
|
|
* @param replacement the replacement block to fill in after moving, or null to use air
|
2013-08-03 23:22:29 +00:00
|
|
|
* @return number of blocks moved
|
2014-03-30 17:29:00 +00:00
|
|
|
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
2013-08-03 23:22:29 +00:00
|
|
|
*/
|
2014-03-30 17:29:00 +00:00
|
|
|
public int moveRegion(Region region, Vector dir, int distance, boolean copyAir, BaseBlock replacement) throws MaxChangedBlocksException {
|
|
|
|
checkNotNull(region);
|
|
|
|
checkNotNull(dir);
|
|
|
|
checkArgument(distance >= 1, "distance >= 1 required");
|
2013-08-03 23:22:29 +00:00
|
|
|
|
2014-03-30 17:29:00 +00:00
|
|
|
Vector to = region.getMinimumPoint();
|
2013-08-03 23:22:29 +00:00
|
|
|
|
2014-03-30 17:29:00 +00:00
|
|
|
// Remove the original blocks
|
2014-03-30 20:54:57 +00:00
|
|
|
com.sk89q.worldedit.function.pattern.Pattern pattern = replacement != null ?
|
|
|
|
new BlockPattern(replacement) :
|
|
|
|
new BlockPattern(new BaseBlock(BlockID.AIR));
|
|
|
|
BlockReplace remove = new BlockReplace(this, pattern);
|
2014-03-30 17:29:00 +00:00
|
|
|
|
|
|
|
// Copy to a buffer so we don't destroy our original before we can copy all the blocks from it
|
2014-03-31 23:55:58 +00:00
|
|
|
ForgetfulExtentBuffer buffer = new ForgetfulExtentBuffer(this, new RegionMask(region));
|
2014-03-30 17:29:00 +00:00
|
|
|
ForwardExtentCopy copy = new ForwardExtentCopy(this, region, buffer, to);
|
|
|
|
copy.setTransform(new AffineTransform().translate(dir.multiply(distance)));
|
|
|
|
copy.setSourceFunction(remove); // Remove
|
|
|
|
if (!copyAir) {
|
|
|
|
copy.setSourceMask(new ExistingBlockMask(this));
|
2013-08-03 23:22:29 +00:00
|
|
|
}
|
|
|
|
|
2014-03-30 17:29:00 +00:00
|
|
|
// Then we need to copy the buffer to the world
|
|
|
|
BlockReplace replace = new BlockReplace(this, buffer);
|
|
|
|
RegionVisitor visitor = new RegionVisitor(buffer.asRegion(), replace);
|
|
|
|
|
|
|
|
OperationQueue operation = new OperationQueue(copy, visitor);
|
2014-04-01 23:21:27 +00:00
|
|
|
Operations.completeLegacy(operation);
|
2013-08-03 23:22:29 +00:00
|
|
|
|
2014-03-30 17:29:00 +00:00
|
|
|
return copy.getAffected();
|
2013-08-03 23:22:29 +00:00
|
|
|
}
|
|
|
|
|
2010-10-18 20:51:43 +00:00
|
|
|
/**
|
2014-03-30 20:56:12 +00:00
|
|
|
* Move the blocks in a region a certain direction.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2014-03-30 20:56:12 +00:00
|
|
|
* @param region the region to move
|
|
|
|
* @param dir the direction
|
|
|
|
* @param distance the distance to move
|
|
|
|
* @param copyAir true to copy air blocks
|
|
|
|
* @param replacement the replacement block to fill in after moving, or null to use air
|
2010-10-18 20:51:43 +00:00
|
|
|
* @return number of blocks moved
|
2014-03-30 20:56:12 +00:00
|
|
|
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
2010-10-18 20:51:43 +00:00
|
|
|
*/
|
2014-03-30 20:56:12 +00:00
|
|
|
public int moveCuboidRegion(Region region, Vector dir, int distance, boolean copyAir, BaseBlock replacement) throws MaxChangedBlocksException {
|
|
|
|
return moveRegion(region, dir, distance, copyAir, replacement);
|
2010-10-18 20:51:43 +00:00
|
|
|
}
|
|
|
|
|
2010-10-11 18:17:32 +00:00
|
|
|
/**
|
|
|
|
* Drain nearby pools of water or lava.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2014-03-30 21:10:01 +00:00
|
|
|
* @param origin the origin to drain from, which will search a 3x3 area
|
|
|
|
* @param radius the radius of the removal, where a value should be 0 or greater
|
2010-10-11 18:17:32 +00:00
|
|
|
* @return number of blocks affected
|
2014-03-30 21:46:50 +00:00
|
|
|
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
2010-10-11 18:17:32 +00:00
|
|
|
*/
|
2014-03-30 21:10:01 +00:00
|
|
|
public int drainArea(Vector origin, double radius) throws MaxChangedBlocksException {
|
|
|
|
checkNotNull(origin);
|
|
|
|
checkArgument(radius >= 0, "radius >= 0 required");
|
2010-10-11 18:17:32 +00:00
|
|
|
|
2014-03-30 21:10:01 +00:00
|
|
|
MaskIntersection mask = new MaskIntersection(
|
|
|
|
new BoundedHeightMask(0, getWorld().getMaxY()),
|
|
|
|
new RegionMask(new EllipsoidRegion(null, origin, new Vector(radius, radius, radius))),
|
2014-03-30 21:16:06 +00:00
|
|
|
getWorld().createLiquidMask());
|
2014-03-30 21:10:01 +00:00
|
|
|
|
|
|
|
BlockReplace replace = new BlockReplace(this, new BlockPattern(new BaseBlock(BlockID.AIR)));
|
|
|
|
RecursiveVisitor visitor = new RecursiveVisitor(mask, replace);
|
|
|
|
|
|
|
|
// Around the origin in a 3x3 block
|
|
|
|
for (BlockVector position : CuboidRegion.fromCenter(origin, 1)) {
|
|
|
|
if (mask.test(position)) {
|
|
|
|
visitor.visit(position);
|
2010-10-11 18:17:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-01 23:21:27 +00:00
|
|
|
Operations.completeLegacy(visitor);
|
2010-10-15 08:07:48 +00:00
|
|
|
|
2014-03-30 21:10:01 +00:00
|
|
|
return visitor.getAffected();
|
2010-10-15 08:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-03-30 21:46:50 +00:00
|
|
|
* Fix liquids so that they turn into stationary blocks and extend outward.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2014-03-30 21:46:50 +00:00
|
|
|
* @param origin the original position
|
|
|
|
* @param radius the radius to fix
|
|
|
|
* @param moving the block ID of the moving liquid
|
|
|
|
* @param stationary the block ID of the stationary liquid
|
2010-10-15 08:07:48 +00:00
|
|
|
* @return number of blocks affected
|
2014-03-30 21:46:50 +00:00
|
|
|
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
2010-10-15 08:07:48 +00:00
|
|
|
*/
|
2014-03-30 21:45:42 +00:00
|
|
|
public int fixLiquid(Vector origin, double radius, int moving, int stationary) throws MaxChangedBlocksException {
|
|
|
|
checkNotNull(origin);
|
|
|
|
checkArgument(radius >= 0, "radius >= 0 required");
|
2010-10-15 08:07:48 +00:00
|
|
|
|
2014-03-30 21:45:42 +00:00
|
|
|
// Our origins can only be liquids
|
|
|
|
BlockMask liquidMask = new BlockMask(
|
|
|
|
this,
|
|
|
|
new BaseBlock(moving, -1),
|
|
|
|
new BaseBlock(stationary, -1));
|
2010-10-15 08:07:48 +00:00
|
|
|
|
2014-03-30 21:45:42 +00:00
|
|
|
// But we will also visit air blocks
|
|
|
|
MaskIntersection blockMask =
|
|
|
|
new MaskUnion(liquidMask,
|
|
|
|
new BlockMask(
|
|
|
|
this,
|
|
|
|
new BaseBlock(BlockID.AIR)));
|
2010-10-15 08:07:48 +00:00
|
|
|
|
2014-03-30 21:45:42 +00:00
|
|
|
// There are boundaries that the routine needs to stay in
|
|
|
|
MaskIntersection mask = new MaskIntersection(
|
|
|
|
new BoundedHeightMask(0, Math.min(origin.getBlockY(), getWorld().getMaxY())),
|
|
|
|
new RegionMask(new EllipsoidRegion(null, origin, new Vector(radius, radius, radius))),
|
|
|
|
blockMask);
|
2010-10-15 08:07:48 +00:00
|
|
|
|
2014-03-30 21:45:42 +00:00
|
|
|
BlockReplace replace = new BlockReplace(this, new BlockPattern(new BaseBlock(stationary)));
|
|
|
|
NonRisingVisitor visitor = new NonRisingVisitor(mask, replace);
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2014-03-30 21:45:42 +00:00
|
|
|
// Around the origin in a 3x3 block
|
|
|
|
for (BlockVector position : CuboidRegion.fromCenter(origin, 1)) {
|
|
|
|
if (liquidMask.test(position)) {
|
|
|
|
visitor.visit(position);
|
2010-10-15 08:07:48 +00:00
|
|
|
}
|
|
|
|
}
|
2010-10-11 18:17:32 +00:00
|
|
|
|
2014-04-01 23:21:27 +00:00
|
|
|
Operations.completeLegacy(visitor);
|
2014-03-30 21:45:42 +00:00
|
|
|
|
|
|
|
return visitor.getAffected();
|
2010-10-11 18:17:32 +00:00
|
|
|
}
|
2010-10-18 00:22:29 +00:00
|
|
|
|
|
|
|
/**
|
2011-10-26 20:50:46 +00:00
|
|
|
* Makes a cylinder.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2011-10-26 20:50:46 +00:00
|
|
|
* @param pos Center of the cylinder
|
|
|
|
* @param block The block pattern to use
|
|
|
|
* @param radius The cylinder's radius
|
|
|
|
* @param height The cylinder's up/down extent. If negative, extend downward.
|
|
|
|
* @param filled If false, only a shell will be generated.
|
|
|
|
* @return number of blocks changed
|
|
|
|
* @throws MaxChangedBlocksException
|
|
|
|
*/
|
|
|
|
public int makeCylinder(Vector pos, Pattern block, double radius, int height, boolean filled) throws MaxChangedBlocksException {
|
|
|
|
return makeCylinder(pos, block, radius, radius, height, filled);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Makes a cylinder.
|
|
|
|
*
|
|
|
|
* @param pos Center of the cylinder
|
2011-10-28 18:16:19 +00:00
|
|
|
* @param block The block pattern to use
|
|
|
|
* @param radiusX The cylinder's largest north/south extent
|
|
|
|
* @param radiusZ The cylinder's largest east/west extent
|
|
|
|
* @param height The cylinder's up/down extent. If negative, extend downward.
|
|
|
|
* @param filled If false, only a shell will be generated.
|
|
|
|
* @return number of blocks changed
|
2010-10-18 00:22:29 +00:00
|
|
|
* @throws MaxChangedBlocksException
|
|
|
|
*/
|
2011-10-28 18:16:19 +00:00
|
|
|
public int makeCylinder(Vector pos, Pattern block, double radiusX, double radiusZ, int height, boolean filled) throws MaxChangedBlocksException {
|
2010-10-18 00:22:29 +00:00
|
|
|
int affected = 0;
|
2011-01-01 18:33:18 +00:00
|
|
|
|
2011-10-28 18:16:19 +00:00
|
|
|
radiusX += 0.5;
|
|
|
|
radiusZ += 0.5;
|
2010-10-18 00:22:29 +00:00
|
|
|
|
2010-10-18 00:39:20 +00:00
|
|
|
if (height == 0) {
|
|
|
|
return 0;
|
|
|
|
} else if (height < 0) {
|
|
|
|
height = -height;
|
|
|
|
pos = pos.subtract(0, height, 0);
|
|
|
|
}
|
|
|
|
|
2012-02-11 23:21:07 +00:00
|
|
|
if (pos.getBlockY() < 0) {
|
|
|
|
pos = pos.setY(0);
|
2011-12-13 03:20:31 +00:00
|
|
|
} else if (pos.getBlockY() + height - 1 > world.getMaxY()) {
|
|
|
|
height = world.getMaxY() - pos.getBlockY() + 1;
|
2010-10-18 00:39:20 +00:00
|
|
|
}
|
|
|
|
|
2011-10-28 18:16:19 +00:00
|
|
|
final double invRadiusX = 1 / radiusX;
|
|
|
|
final double invRadiusZ = 1 / radiusZ;
|
2010-10-18 00:22:29 +00:00
|
|
|
|
2011-10-28 18:16:19 +00:00
|
|
|
final int ceilRadiusX = (int) Math.ceil(radiusX);
|
|
|
|
final int ceilRadiusZ = (int) Math.ceil(radiusZ);
|
2010-10-18 00:22:29 +00:00
|
|
|
|
2011-10-28 18:16:19 +00:00
|
|
|
double nextXn = 0;
|
2011-11-23 01:29:48 +00:00
|
|
|
forX: for (int x = 0; x <= ceilRadiusX; ++x) {
|
2011-10-28 18:16:19 +00:00
|
|
|
final double xn = nextXn;
|
|
|
|
nextXn = (x + 1) * invRadiusX;
|
|
|
|
double nextZn = 0;
|
2011-11-23 01:29:48 +00:00
|
|
|
forZ: for (int z = 0; z <= ceilRadiusZ; ++z) {
|
2011-10-28 18:16:19 +00:00
|
|
|
final double zn = nextZn;
|
|
|
|
nextZn = (z + 1) * invRadiusZ;
|
|
|
|
|
|
|
|
double distanceSq = lengthSq(xn, zn);
|
|
|
|
if (distanceSq > 1) {
|
|
|
|
if (z == 0) {
|
|
|
|
break forX;
|
|
|
|
}
|
|
|
|
break forZ;
|
|
|
|
}
|
2010-10-18 00:22:29 +00:00
|
|
|
|
2011-10-28 18:16:19 +00:00
|
|
|
if (!filled) {
|
|
|
|
if (lengthSq(nextXn, zn) <= 1 && lengthSq(xn, nextZn) <= 1) {
|
|
|
|
continue;
|
|
|
|
}
|
2010-10-18 00:22:29 +00:00
|
|
|
}
|
2011-10-28 18:16:19 +00:00
|
|
|
|
|
|
|
for (int y = 0; y < height; ++y) {
|
|
|
|
if (setBlock(pos.add(x, y, z), block)) {
|
|
|
|
++affected;
|
|
|
|
}
|
|
|
|
if (setBlock(pos.add(-x, y, z), block)) {
|
|
|
|
++affected;
|
|
|
|
}
|
|
|
|
if (setBlock(pos.add(x, y, -z), block)) {
|
|
|
|
++affected;
|
|
|
|
}
|
|
|
|
if (setBlock(pos.add(-x, y, -z), block)) {
|
2011-07-15 07:00:48 +00:00
|
|
|
++affected;
|
2010-10-18 00:22:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return affected;
|
|
|
|
}
|
|
|
|
|
2011-10-26 20:50:46 +00:00
|
|
|
/**
|
|
|
|
* Makes a sphere.
|
|
|
|
*
|
|
|
|
* @param pos Center of the sphere or ellipsoid
|
|
|
|
* @param block The block pattern to use
|
|
|
|
* @param radius The sphere's radius
|
|
|
|
* @param filled If false, only a shell will be generated.
|
|
|
|
* @return number of blocks changed
|
|
|
|
* @throws MaxChangedBlocksException
|
|
|
|
*/
|
|
|
|
public int makeSphere(Vector pos, Pattern block, double radius, boolean filled) throws MaxChangedBlocksException {
|
|
|
|
return makeSphere(pos, block, radius, radius, radius, filled);
|
|
|
|
}
|
|
|
|
|
2010-10-18 17:39:32 +00:00
|
|
|
/**
|
2011-09-02 19:38:38 +00:00
|
|
|
* Makes a sphere or ellipsoid.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2011-09-02 19:38:38 +00:00
|
|
|
* @param pos Center of the sphere or ellipsoid
|
|
|
|
* @param block The block pattern to use
|
|
|
|
* @param radiusX The sphere/ellipsoid's largest north/south extent
|
|
|
|
* @param radiusY The sphere/ellipsoid's largest up/down extent
|
|
|
|
* @param radiusZ The sphere/ellipsoid's largest east/west extent
|
|
|
|
* @param filled If false, only a shell will be generated.
|
2010-10-18 17:39:32 +00:00
|
|
|
* @return number of blocks changed
|
|
|
|
* @throws MaxChangedBlocksException
|
|
|
|
*/
|
2011-09-02 19:38:38 +00:00
|
|
|
public int makeSphere(Vector pos, Pattern block, double radiusX, double radiusY, double radiusZ, boolean filled) throws MaxChangedBlocksException {
|
2010-10-18 17:39:32 +00:00
|
|
|
int affected = 0;
|
2011-01-01 18:33:18 +00:00
|
|
|
|
2011-09-02 19:38:38 +00:00
|
|
|
radiusX += 0.5;
|
|
|
|
radiusY += 0.5;
|
|
|
|
radiusZ += 0.5;
|
|
|
|
|
|
|
|
final double invRadiusX = 1 / radiusX;
|
|
|
|
final double invRadiusY = 1 / radiusY;
|
|
|
|
final double invRadiusZ = 1 / radiusZ;
|
|
|
|
|
|
|
|
final int ceilRadiusX = (int) Math.ceil(radiusX);
|
|
|
|
final int ceilRadiusY = (int) Math.ceil(radiusY);
|
|
|
|
final int ceilRadiusZ = (int) Math.ceil(radiusZ);
|
|
|
|
|
|
|
|
double nextXn = 0;
|
2011-11-23 01:29:48 +00:00
|
|
|
forX: for (int x = 0; x <= ceilRadiusX; ++x) {
|
2011-09-02 19:38:38 +00:00
|
|
|
final double xn = nextXn;
|
2011-09-03 16:54:20 +00:00
|
|
|
nextXn = (x + 1) * invRadiusX;
|
2011-09-02 19:38:38 +00:00
|
|
|
double nextYn = 0;
|
2011-11-23 01:29:48 +00:00
|
|
|
forY: for (int y = 0; y <= ceilRadiusY; ++y) {
|
2011-09-02 19:38:38 +00:00
|
|
|
final double yn = nextYn;
|
2011-09-03 16:54:20 +00:00
|
|
|
nextYn = (y + 1) * invRadiusY;
|
2011-09-02 19:38:38 +00:00
|
|
|
double nextZn = 0;
|
2011-11-23 01:29:48 +00:00
|
|
|
forZ: for (int z = 0; z <= ceilRadiusZ; ++z) {
|
2011-09-02 19:38:38 +00:00
|
|
|
final double zn = nextZn;
|
2011-09-03 16:54:20 +00:00
|
|
|
nextZn = (z + 1) * invRadiusZ;
|
2011-09-02 19:38:38 +00:00
|
|
|
|
|
|
|
double distanceSq = lengthSq(xn, yn, zn);
|
|
|
|
if (distanceSq > 1) {
|
|
|
|
if (z == 0) {
|
2011-09-03 16:54:20 +00:00
|
|
|
if (y == 0) {
|
2011-09-02 19:38:38 +00:00
|
|
|
break forX;
|
2011-09-03 16:54:20 +00:00
|
|
|
}
|
2011-09-02 19:38:38 +00:00
|
|
|
break forY;
|
|
|
|
}
|
|
|
|
break forZ;
|
|
|
|
}
|
2011-08-12 06:16:53 +00:00
|
|
|
|
|
|
|
if (!filled) {
|
2011-09-03 16:54:20 +00:00
|
|
|
if (lengthSq(nextXn, yn, zn) <= 1 && lengthSq(xn, nextYn, zn) <= 1 && lengthSq(xn, yn, nextZn) <= 1) {
|
2011-08-12 06:16:53 +00:00
|
|
|
continue;
|
2011-09-03 16:54:20 +00:00
|
|
|
}
|
2011-08-12 06:16:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (setBlock(pos.add(x, y, z), block)) {
|
|
|
|
++affected;
|
|
|
|
}
|
|
|
|
if (setBlock(pos.add(-x, y, z), block)) {
|
|
|
|
++affected;
|
|
|
|
}
|
|
|
|
if (setBlock(pos.add(x, -y, z), block)) {
|
|
|
|
++affected;
|
|
|
|
}
|
|
|
|
if (setBlock(pos.add(x, y, -z), block)) {
|
|
|
|
++affected;
|
|
|
|
}
|
|
|
|
if (setBlock(pos.add(-x, -y, z), block)) {
|
|
|
|
++affected;
|
|
|
|
}
|
|
|
|
if (setBlock(pos.add(x, -y, -z), block)) {
|
|
|
|
++affected;
|
|
|
|
}
|
|
|
|
if (setBlock(pos.add(-x, y, -z), block)) {
|
|
|
|
++affected;
|
|
|
|
}
|
|
|
|
if (setBlock(pos.add(-x, -y, -z), block)) {
|
|
|
|
++affected;
|
2010-10-18 17:39:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return affected;
|
|
|
|
}
|
|
|
|
|
2011-08-07 00:40:48 +00:00
|
|
|
/**
|
|
|
|
* Makes a pyramid.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2011-08-07 00:40:48 +00:00
|
|
|
* @param pos
|
|
|
|
* @param block
|
|
|
|
* @param size
|
|
|
|
* @param filled
|
|
|
|
* @return number of blocks changed
|
|
|
|
* @throws MaxChangedBlocksException
|
|
|
|
*/
|
|
|
|
public int makePyramid(Vector pos, Pattern block, int size,
|
|
|
|
boolean filled) throws MaxChangedBlocksException {
|
|
|
|
int affected = 0;
|
|
|
|
|
|
|
|
int height = size;
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2011-08-07 00:40:48 +00:00
|
|
|
for (int y = 0; y <= height; ++y) {
|
|
|
|
size--;
|
|
|
|
for (int x = 0; x <= size; ++x) {
|
|
|
|
for (int z = 0; z <= size; ++z) {
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2011-08-07 00:40:48 +00:00
|
|
|
if ((filled && z <= size && x <= size) || z == size || x == size) {
|
2011-09-24 19:32:03 +00:00
|
|
|
|
2011-08-07 00:40:48 +00:00
|
|
|
if (setBlock(pos.add(x, y, z), block)) {
|
|
|
|
++affected;
|
|
|
|
}
|
|
|
|
if (setBlock(pos.add(-x, y, z), block)) {
|
|
|
|
++affected;
|
|
|
|
}
|
|
|
|
if (setBlock(pos.add(x, y, -z), block)) {
|
|
|
|
++affected;
|
|
|
|
}
|
|
|
|
if (setBlock(pos.add(-x, y, -z), block)) {
|
|
|
|
++affected;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return affected;
|
|
|
|
}
|
|
|
|
|
2011-01-08 19:40:18 +00:00
|
|
|
/**
|
|
|
|
* Thaw.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2011-01-08 19:40:18 +00:00
|
|
|
* @param pos
|
|
|
|
* @param radius
|
|
|
|
* @return number of blocks affected
|
|
|
|
* @throws MaxChangedBlocksException
|
|
|
|
*/
|
2011-08-15 12:35:21 +00:00
|
|
|
public int thaw(Vector pos, double radius)
|
2011-01-08 19:40:18 +00:00
|
|
|
throws MaxChangedBlocksException {
|
|
|
|
int affected = 0;
|
2011-11-23 01:29:48 +00:00
|
|
|
double radiusSq = radius * radius;
|
2011-01-08 19:40:18 +00:00
|
|
|
|
|
|
|
int ox = pos.getBlockX();
|
|
|
|
int oy = pos.getBlockY();
|
|
|
|
int oz = pos.getBlockZ();
|
|
|
|
|
|
|
|
BaseBlock air = new BaseBlock(0);
|
|
|
|
BaseBlock water = new BaseBlock(BlockID.STATIONARY_WATER);
|
|
|
|
|
2011-08-15 12:35:21 +00:00
|
|
|
int ceilRadius = (int) Math.ceil(radius);
|
|
|
|
for (int x = ox - ceilRadius; x <= ox + ceilRadius; ++x) {
|
|
|
|
for (int z = oz - ceilRadius; z <= oz + ceilRadius; ++z) {
|
2011-01-08 19:40:18 +00:00
|
|
|
if ((new Vector(x, oy, z)).distanceSq(pos) > radiusSq) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-12-13 03:20:31 +00:00
|
|
|
for (int y = world.getMaxY(); y >= 1; --y) {
|
2011-01-08 19:40:18 +00:00
|
|
|
Vector pt = new Vector(x, y, z);
|
2011-01-31 07:42:18 +00:00
|
|
|
int id = getBlockType(pt);
|
2011-01-08 19:40:18 +00:00
|
|
|
|
2011-09-05 01:53:39 +00:00
|
|
|
switch (id) {
|
|
|
|
case BlockID.ICE:
|
2011-01-08 19:40:18 +00:00
|
|
|
if (setBlock(pt, water)) {
|
2011-07-15 07:00:48 +00:00
|
|
|
++affected;
|
2011-01-08 19:40:18 +00:00
|
|
|
}
|
2011-09-05 01:53:39 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BlockID.SNOW:
|
2011-01-08 19:40:18 +00:00
|
|
|
if (setBlock(pt, air)) {
|
2011-07-15 07:00:48 +00:00
|
|
|
++affected;
|
2011-01-08 19:40:18 +00:00
|
|
|
}
|
2011-09-05 01:53:39 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BlockID.AIR:
|
|
|
|
continue;
|
|
|
|
|
|
|
|
default:
|
2011-01-08 19:40:18 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-09-05 01:53:39 +00:00
|
|
|
|
|
|
|
break;
|
2011-01-08 19:40:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return affected;
|
|
|
|
}
|
|
|
|
|
2010-11-07 04:26:52 +00:00
|
|
|
/**
|
|
|
|
* Make snow.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2010-11-07 04:26:52 +00:00
|
|
|
* @param pos
|
|
|
|
* @param radius
|
|
|
|
* @return number of blocks affected
|
|
|
|
* @throws MaxChangedBlocksException
|
|
|
|
*/
|
2011-08-15 12:35:21 +00:00
|
|
|
public int simulateSnow(Vector pos, double radius)
|
2010-11-07 04:26:52 +00:00
|
|
|
throws MaxChangedBlocksException {
|
|
|
|
int affected = 0;
|
2011-11-23 01:29:48 +00:00
|
|
|
double radiusSq = radius * radius;
|
2010-11-07 04:26:52 +00:00
|
|
|
|
|
|
|
int ox = pos.getBlockX();
|
|
|
|
int oy = pos.getBlockY();
|
|
|
|
int oz = pos.getBlockZ();
|
|
|
|
|
2011-09-03 16:54:20 +00:00
|
|
|
BaseBlock ice = new BaseBlock(BlockID.ICE);
|
|
|
|
BaseBlock snow = new BaseBlock(BlockID.SNOW);
|
2010-11-07 04:26:52 +00:00
|
|
|
|
2011-08-15 12:35:21 +00:00
|
|
|
int ceilRadius = (int) Math.ceil(radius);
|
|
|
|
for (int x = ox - ceilRadius; x <= ox + ceilRadius; ++x) {
|
|
|
|
for (int z = oz - ceilRadius; z <= oz + ceilRadius; ++z) {
|
2011-01-08 18:59:06 +00:00
|
|
|
if ((new Vector(x, oy, z)).distanceSq(pos) > radiusSq) {
|
2010-11-07 04:26:52 +00:00
|
|
|
continue;
|
|
|
|
}
|
2011-01-01 18:33:18 +00:00
|
|
|
|
2011-12-13 03:20:31 +00:00
|
|
|
for (int y = world.getMaxY(); y >= 1; --y) {
|
2010-11-07 04:26:52 +00:00
|
|
|
Vector pt = new Vector(x, y, z);
|
2011-01-31 07:42:18 +00:00
|
|
|
int id = getBlockType(pt);
|
2010-11-07 04:26:52 +00:00
|
|
|
|
2011-09-05 01:53:39 +00:00
|
|
|
if (id == BlockID.AIR) {
|
|
|
|
continue;
|
2010-11-07 04:26:52 +00:00
|
|
|
}
|
2011-01-01 18:33:18 +00:00
|
|
|
|
2010-11-07 04:26:52 +00:00
|
|
|
// Ice!
|
2011-09-03 16:54:20 +00:00
|
|
|
if (id == BlockID.WATER || id == BlockID.STATIONARY_WATER) {
|
2010-11-07 04:26:52 +00:00
|
|
|
if (setBlock(pt, ice)) {
|
2011-07-15 07:00:48 +00:00
|
|
|
++affected;
|
2010-11-07 04:26:52 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-09-05 01:53:39 +00:00
|
|
|
// Snow should not cover these blocks
|
2012-12-25 23:40:34 +00:00
|
|
|
if (BlockType.isTranslucent(id)) {
|
2011-09-05 01:53:39 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-01-01 18:33:18 +00:00
|
|
|
|
2011-09-05 01:53:39 +00:00
|
|
|
// Too high?
|
2011-12-13 03:20:31 +00:00
|
|
|
if (y == world.getMaxY()) {
|
2010-11-07 04:26:52 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-09-05 01:53:39 +00:00
|
|
|
|
|
|
|
// add snow cover
|
|
|
|
if (setBlock(pt.add(0, 1, 0), snow)) {
|
|
|
|
++affected;
|
|
|
|
}
|
|
|
|
break;
|
2010-11-07 04:26:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return affected;
|
|
|
|
}
|
2011-01-01 18:33:18 +00:00
|
|
|
|
2011-08-16 16:43:13 +00:00
|
|
|
/**
|
|
|
|
* Green.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2011-08-16 16:43:13 +00:00
|
|
|
* @param pos
|
|
|
|
* @param radius
|
|
|
|
* @return number of blocks affected
|
|
|
|
* @throws MaxChangedBlocksException
|
2013-12-29 17:28:42 +00:00
|
|
|
* @deprecated Use {@link #green(Vector, double, boolean)}.
|
2011-08-16 16:43:13 +00:00
|
|
|
*/
|
2013-12-29 17:28:42 +00:00
|
|
|
@Deprecated
|
2011-08-16 16:43:13 +00:00
|
|
|
public int green(Vector pos, double radius)
|
|
|
|
throws MaxChangedBlocksException {
|
2013-12-29 17:28:42 +00:00
|
|
|
return green(pos, radius, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Green.
|
|
|
|
*
|
|
|
|
* @param pos
|
|
|
|
* @param radius
|
|
|
|
* @param onlyNormalDirt only affect normal dirt (data value 0)
|
|
|
|
* @return number of blocks affected
|
|
|
|
* @throws MaxChangedBlocksException
|
|
|
|
*/
|
|
|
|
public int green(Vector pos, double radius, boolean onlyNormalDirt)
|
|
|
|
throws MaxChangedBlocksException {
|
2011-08-16 16:43:13 +00:00
|
|
|
int affected = 0;
|
2011-12-10 11:16:57 +00:00
|
|
|
final double radiusSq = radius * radius;
|
2011-08-16 16:43:13 +00:00
|
|
|
|
2011-12-10 11:16:57 +00:00
|
|
|
final int ox = pos.getBlockX();
|
|
|
|
final int oy = pos.getBlockY();
|
|
|
|
final int oz = pos.getBlockZ();
|
2011-08-16 16:43:13 +00:00
|
|
|
|
2011-12-10 11:16:57 +00:00
|
|
|
final BaseBlock grass = new BaseBlock(BlockID.GRASS);
|
2011-08-16 16:43:13 +00:00
|
|
|
|
2011-12-10 11:16:57 +00:00
|
|
|
final int ceilRadius = (int) Math.ceil(radius);
|
2011-08-16 16:43:13 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-12-13 03:20:31 +00:00
|
|
|
loop: for (int y = world.getMaxY(); y >= 1; --y) {
|
2011-12-10 11:16:57 +00:00
|
|
|
final Vector pt = new Vector(x, y, z);
|
|
|
|
final int id = getBlockType(pt);
|
2013-06-23 19:04:23 +00:00
|
|
|
final int data = getBlockData(pt);
|
2011-08-16 16:43:13 +00:00
|
|
|
|
2011-12-10 11:16:57 +00:00
|
|
|
switch (id) {
|
|
|
|
case BlockID.DIRT:
|
2013-12-29 17:28:42 +00:00
|
|
|
if (onlyNormalDirt && data != 0) {
|
|
|
|
break loop;
|
|
|
|
}
|
|
|
|
|
2011-08-16 16:43:13 +00:00
|
|
|
if (setBlock(pt, grass)) {
|
|
|
|
++affected;
|
|
|
|
}
|
2011-12-10 11:16:57 +00:00
|
|
|
break loop;
|
|
|
|
|
|
|
|
case BlockID.WATER:
|
|
|
|
case BlockID.STATIONARY_WATER:
|
|
|
|
case BlockID.LAVA:
|
|
|
|
case BlockID.STATIONARY_LAVA:
|
|
|
|
// break on liquids...
|
|
|
|
break loop;
|
|
|
|
|
|
|
|
default:
|
|
|
|
// ...and all non-passable blocks
|
2013-06-23 19:04:23 +00:00
|
|
|
if (!BlockType.canPassThrough(id, data)) {
|
2011-12-10 11:16:57 +00:00
|
|
|
break loop;
|
|
|
|
}
|
2011-08-16 16:43:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return affected;
|
|
|
|
}
|
|
|
|
|
2010-10-31 01:20:15 +00:00
|
|
|
/**
|
2014-03-01 23:41:40 +00:00
|
|
|
* Makes pumpkin patches randomly in an area around the given position.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2014-03-01 23:41:40 +00:00
|
|
|
* @param position the base position
|
|
|
|
* @param apothem the apothem of the (square) area
|
|
|
|
* @return number of patches created
|
2011-09-24 19:32:03 +00:00
|
|
|
* @throws MaxChangedBlocksException
|
2010-10-31 01:20:15 +00:00
|
|
|
*/
|
2014-03-01 23:41:40 +00:00
|
|
|
public int makePumpkinPatches(Vector position, int apothem) throws MaxChangedBlocksException {
|
|
|
|
// We want to generate pumpkins
|
|
|
|
GardenPatchGenerator generator = new GardenPatchGenerator(this);
|
|
|
|
generator.setPlant(GardenPatchGenerator.getPumpkinPattern());
|
2010-10-31 01:20:15 +00:00
|
|
|
|
2014-03-01 23:41:40 +00:00
|
|
|
// In a region of the given radius
|
2014-03-30 01:51:33 +00:00
|
|
|
FlatRegion region = new CuboidRegion(
|
2014-03-28 03:57:20 +00:00
|
|
|
getWorld(), // Causes clamping of Y range
|
|
|
|
position.add(-apothem, -5, -apothem),
|
|
|
|
position.add(apothem, 10, apothem));
|
2014-03-28 23:13:27 +00:00
|
|
|
double density = 0.02;
|
|
|
|
|
2014-04-01 03:29:05 +00:00
|
|
|
GroundFunction ground = new GroundFunction(new ExistingBlockMask(this), generator);
|
2014-03-30 20:49:26 +00:00
|
|
|
LayerVisitor visitor = new LayerVisitor(region, minimumBlockY(region), maximumBlockY(region), ground);
|
2014-03-30 01:51:33 +00:00
|
|
|
visitor.setMask(new NoiseFilter2D(new RandomNoise(), density));
|
2014-04-01 23:21:27 +00:00
|
|
|
Operations.completeLegacy(visitor);
|
2014-03-30 01:51:33 +00:00
|
|
|
return ground.getAffected();
|
2010-10-31 01:20:15 +00:00
|
|
|
}
|
|
|
|
|
2010-10-13 05:38:05 +00:00
|
|
|
/**
|
2010-11-07 04:03:34 +00:00
|
|
|
* Makes a forest.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2010-10-13 05:38:05 +00:00
|
|
|
* @param basePos
|
|
|
|
* @param size
|
2010-11-07 04:03:34 +00:00
|
|
|
* @param density
|
2011-01-30 22:54:42 +00:00
|
|
|
* @param treeGenerator
|
2010-10-13 05:38:05 +00:00
|
|
|
* @return number of trees created
|
2011-09-24 19:32:03 +00:00
|
|
|
* @throws MaxChangedBlocksException
|
2010-10-13 05:38:05 +00:00
|
|
|
*/
|
2010-11-07 04:03:34 +00:00
|
|
|
public int makeForest(Vector basePos, int size, double density,
|
2011-01-30 22:54:42 +00:00
|
|
|
TreeGenerator treeGenerator) throws MaxChangedBlocksException {
|
2010-10-13 05:38:05 +00:00
|
|
|
int affected = 0;
|
2011-01-01 18:33:18 +00:00
|
|
|
|
|
|
|
for (int x = basePos.getBlockX() - size; x <= basePos.getBlockX()
|
2011-07-15 07:00:48 +00:00
|
|
|
+ size; ++x) {
|
2011-01-01 18:33:18 +00:00
|
|
|
for (int z = basePos.getBlockZ() - size; z <= basePos.getBlockZ()
|
2011-07-15 07:00:48 +00:00
|
|
|
+ size; ++z) {
|
2010-10-13 05:38:05 +00:00
|
|
|
// Don't want to be in the ground
|
2011-09-03 16:54:20 +00:00
|
|
|
if (!getBlock(new Vector(x, basePos.getBlockY(), z)).isAir()) {
|
2010-10-13 23:49:35 +00:00
|
|
|
continue;
|
2011-09-03 16:54:20 +00:00
|
|
|
}
|
2010-10-13 05:38:05 +00:00
|
|
|
// The gods don't want a tree here
|
2011-01-01 18:33:18 +00:00
|
|
|
if (Math.random() >= density) {
|
|
|
|
continue;
|
|
|
|
} // def 0.05
|
2010-10-13 05:38:05 +00:00
|
|
|
|
2011-07-15 07:00:48 +00:00
|
|
|
for (int y = basePos.getBlockY(); y >= basePos.getBlockY() - 10; --y) {
|
2010-10-13 05:38:05 +00:00
|
|
|
// Check if we hit the ground
|
2011-01-16 17:39:11 +00:00
|
|
|
int t = getBlock(new Vector(x, y, z)).getType();
|
2011-09-03 16:54:20 +00:00
|
|
|
if (t == BlockID.GRASS || t == BlockID.DIRT) {
|
2011-01-30 22:54:42 +00:00
|
|
|
treeGenerator.generate(this, new Vector(x, y + 1, z));
|
2011-07-15 07:00:48 +00:00
|
|
|
++affected;
|
2010-10-13 05:38:05 +00:00
|
|
|
break;
|
2013-12-24 23:44:00 +00:00
|
|
|
} else if (t == BlockID.SNOW) {
|
|
|
|
setBlock(new Vector(x, y, z), new BaseBlock(BlockID.AIR));
|
2011-09-03 16:54:20 +00:00
|
|
|
} else if (t != BlockID.AIR) { // Trees won't grow on this!
|
2010-10-13 05:38:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return affected;
|
|
|
|
}
|
2010-11-07 04:03:34 +00:00
|
|
|
|
2010-11-17 06:59:53 +00:00
|
|
|
/**
|
|
|
|
* Get the block distribution inside a region.
|
2011-09-24 19:32:03 +00:00
|
|
|
*
|
2010-11-17 06:59:53 +00:00
|
|
|
* @param region
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public List<Countable<Integer>> getBlockDistribution(Region region) {
|
2011-01-01 18:33:18 +00:00
|
|
|
List<Countable<Integer>> distribution = new ArrayList<Countable<Integer>>();
|
|
|
|
Map<Integer, Countable<Integer>> map = new HashMap<Integer, Countable<Integer>>();
|
2010-11-17 06:59:53 +00:00
|
|
|
|
|
|
|
if (region instanceof CuboidRegion) {
|
|
|
|
// Doing this for speed
|
|
|
|
Vector min = region.getMinimumPoint();
|
|
|
|
Vector max = region.getMaximumPoint();
|
|
|
|
|
|
|
|
int minX = min.getBlockX();
|
|
|
|
int minY = min.getBlockY();
|
|
|
|
int minZ = min.getBlockZ();
|
|
|
|
int maxX = max.getBlockX();
|
|
|
|
int maxY = max.getBlockY();
|
|
|
|
int maxZ = max.getBlockZ();
|
|
|
|
|
2011-07-15 07:00:48 +00:00
|
|
|
for (int x = minX; x <= maxX; ++x) {
|
|
|
|
for (int y = minY; y <= maxY; ++y) {
|
|
|
|
for (int z = minZ; z <= maxZ; ++z) {
|
2010-11-17 06:59:53 +00:00
|
|
|
Vector pt = new Vector(x, y, z);
|
|
|
|
|
2011-01-31 07:42:18 +00:00
|
|
|
int id = getBlockType(pt);
|
2010-11-17 06:59:53 +00:00
|
|
|
|
|
|
|
if (map.containsKey(id)) {
|
|
|
|
map.get(id).increment();
|
|
|
|
} else {
|
|
|
|
Countable<Integer> c = new Countable<Integer>(id, 1);
|
|
|
|
map.put(id, c);
|
|
|
|
distribution.add(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (Vector pt : region) {
|
2011-01-31 07:42:18 +00:00
|
|
|
int id = getBlockType(pt);
|
2010-11-17 06:59:53 +00:00
|
|
|
|
|
|
|
if (map.containsKey(id)) {
|
|
|
|
map.get(id).increment();
|
|
|
|
} else {
|
|
|
|
Countable<Integer> c = new Countable<Integer>(id, 1);
|
|
|
|
map.put(id, c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Collections.sort(distribution);
|
2011-01-01 18:33:18 +00:00
|
|
|
// Collections.reverse(distribution);
|
2010-11-17 06:59:53 +00:00
|
|
|
|
|
|
|
return distribution;
|
|
|
|
}
|
2011-11-01 13:57:58 +00:00
|
|
|
|
2013-01-19 14:31:00 +00:00
|
|
|
/**
|
|
|
|
* Get the block distribution (with data values) inside a region.
|
|
|
|
*
|
|
|
|
* @param region
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
// TODO reduce code duplication - probably during ops-redux
|
|
|
|
public List<Countable<BaseBlock>> getBlockDistributionWithData(Region region) {
|
|
|
|
List<Countable<BaseBlock>> distribution = new ArrayList<Countable<BaseBlock>>();
|
|
|
|
Map<BaseBlock, Countable<BaseBlock>> map = new HashMap<BaseBlock, Countable<BaseBlock>>();
|
|
|
|
|
|
|
|
if (region instanceof CuboidRegion) {
|
|
|
|
// Doing this for speed
|
|
|
|
Vector min = region.getMinimumPoint();
|
|
|
|
Vector max = region.getMaximumPoint();
|
|
|
|
|
|
|
|
int minX = min.getBlockX();
|
|
|
|
int minY = min.getBlockY();
|
|
|
|
int minZ = min.getBlockZ();
|
|
|
|
int maxX = max.getBlockX();
|
|
|
|
int maxY = max.getBlockY();
|
|
|
|
int maxZ = max.getBlockZ();
|
|
|
|
|
|
|
|
for (int x = minX; x <= maxX; ++x) {
|
|
|
|
for (int y = minY; y <= maxY; ++y) {
|
|
|
|
for (int z = minZ; z <= maxZ; ++z) {
|
|
|
|
Vector pt = new Vector(x, y, z);
|
|
|
|
|
|
|
|
BaseBlock blk = new BaseBlock(getBlockType(pt), getBlockData(pt));
|
|
|
|
|
|
|
|
if (map.containsKey(blk)) {
|
|
|
|
map.get(blk).increment();
|
|
|
|
} else {
|
|
|
|
Countable<BaseBlock> c = new Countable<BaseBlock>(blk, 1);
|
|
|
|
map.put(blk, c);
|
|
|
|
distribution.add(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (Vector pt : region) {
|
|
|
|
BaseBlock blk = new BaseBlock(getBlockType(pt), getBlockData(pt));
|
|
|
|
|
|
|
|
if (map.containsKey(blk)) {
|
|
|
|
map.get(blk).increment();
|
|
|
|
} else {
|
|
|
|
Countable<BaseBlock> c = new Countable<BaseBlock>(blk, 1);
|
|
|
|
map.put(blk, c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Collections.sort(distribution);
|
|
|
|
// Collections.reverse(distribution);
|
|
|
|
|
|
|
|
return distribution;
|
|
|
|
}
|
|
|
|
|
2011-11-01 13:57:58 +00:00
|
|
|
public int makeShape(final Region region, final Vector zero, final Vector unit, final Pattern pattern, final String expressionString, final boolean hollow) throws ExpressionException, MaxChangedBlocksException {
|
|
|
|
final Expression expression = Expression.compile(expressionString, "x", "y", "z", "type", "data");
|
|
|
|
expression.optimize();
|
|
|
|
|
2011-11-30 03:21:10 +00:00
|
|
|
final RValue typeVariable = expression.getVariable("type", false);
|
|
|
|
final RValue dataVariable = expression.getVariable("data", false);
|
2011-11-01 13:57:58 +00:00
|
|
|
|
2013-09-21 12:35:57 +00:00
|
|
|
final WorldEditExpressionEnvironment environment = new WorldEditExpressionEnvironment(this, unit, zero);
|
|
|
|
expression.setEnvironment(environment);
|
|
|
|
|
2011-11-01 13:57:58 +00:00
|
|
|
final ArbitraryShape shape = new ArbitraryShape(region) {
|
|
|
|
@Override
|
|
|
|
protected BaseBlock getMaterial(int x, int y, int z, BaseBlock defaultMaterial) {
|
2013-09-21 12:35:57 +00:00
|
|
|
final Vector current = new Vector(x, y, z);
|
|
|
|
environment.setCurrentBlock(current);
|
|
|
|
final Vector scaled = current.subtract(zero).divide(unit);
|
2011-11-01 13:57:58 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
if (expression.evaluate(scaled.getX(), scaled.getY(), scaled.getZ(), defaultMaterial.getType(), defaultMaterial.getData()) <= 0) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2011-11-23 01:29:48 +00:00
|
|
|
return new BaseBlock((int) typeVariable.getValue(), (int) dataVariable.getValue());
|
2011-11-01 13:57:58 +00:00
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return shape.generate(this, pattern, hollow);
|
|
|
|
}
|
2011-11-01 14:23:42 +00:00
|
|
|
|
|
|
|
public int deformRegion(final Region region, final Vector zero, final Vector unit, final String expressionString) throws ExpressionException, MaxChangedBlocksException {
|
|
|
|
final Expression expression = Expression.compile(expressionString, "x", "y", "z");
|
|
|
|
expression.optimize();
|
|
|
|
|
2011-11-30 03:21:10 +00:00
|
|
|
final RValue x = expression.getVariable("x", false);
|
|
|
|
final RValue y = expression.getVariable("y", false);
|
|
|
|
final RValue z = expression.getVariable("z", false);
|
2011-11-01 14:23:42 +00:00
|
|
|
|
2013-09-21 12:35:57 +00:00
|
|
|
final WorldEditExpressionEnvironment environment = new WorldEditExpressionEnvironment(this, unit, zero);
|
|
|
|
expression.setEnvironment(environment);
|
2011-11-02 02:39:02 +00:00
|
|
|
|
|
|
|
final DoubleArrayList<BlockVector, BaseBlock> queue = new DoubleArrayList<BlockVector, BaseBlock>(false);
|
2011-11-01 14:23:42 +00:00
|
|
|
|
|
|
|
for (BlockVector position : region) {
|
2011-11-02 02:39:02 +00:00
|
|
|
// offset, scale
|
2011-11-01 14:23:42 +00:00
|
|
|
final Vector scaled = position.subtract(zero).divide(unit);
|
|
|
|
|
2011-11-02 02:39:02 +00:00
|
|
|
// transform
|
2011-11-01 14:23:42 +00:00
|
|
|
expression.evaluate(scaled.getX(), scaled.getY(), scaled.getZ());
|
|
|
|
|
2013-11-30 16:18:53 +00:00
|
|
|
final BlockVector sourcePosition = environment.toWorld(x.getValue(), y.getValue(), z.getValue());
|
2011-11-01 14:23:42 +00:00
|
|
|
|
2011-11-02 02:39:02 +00:00
|
|
|
// read block from world
|
2013-09-21 12:35:57 +00:00
|
|
|
// TODO: use getBlock here once the reflection is out of the way
|
|
|
|
final BaseBlock material = new BaseBlock(world.getBlockType(sourcePosition), world.getBlockData(sourcePosition));
|
2011-11-01 14:23:42 +00:00
|
|
|
|
2011-11-02 02:39:02 +00:00
|
|
|
// queue operation
|
|
|
|
queue.put(position, material);
|
|
|
|
}
|
|
|
|
|
|
|
|
int affected = 0;
|
|
|
|
for (Map.Entry<BlockVector, BaseBlock> entry : queue) {
|
|
|
|
BlockVector position = entry.getKey();
|
|
|
|
BaseBlock material = entry.getValue();
|
|
|
|
|
|
|
|
// set at new position
|
2011-11-01 14:23:42 +00:00
|
|
|
if (setBlock(position, material)) {
|
|
|
|
++affected;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return affected;
|
|
|
|
}
|
2011-12-08 09:31:12 +00:00
|
|
|
|
|
|
|
/**
|
2011-12-20 10:20:18 +00:00
|
|
|
* Hollows out the region (Semi-well-defined for non-cuboid selections).
|
2011-12-08 09:31:12 +00:00
|
|
|
*
|
2011-12-20 10:20:18 +00:00
|
|
|
* @param region the region to hollow out.
|
|
|
|
* @param thickness the thickness of the shell to leave (manhattan distance)
|
2012-03-17 22:24:30 +00:00
|
|
|
* @param pattern The block pattern to use
|
|
|
|
*
|
2011-12-08 09:31:12 +00:00
|
|
|
* @return number of blocks affected
|
|
|
|
* @throws MaxChangedBlocksException
|
|
|
|
*/
|
2011-12-20 10:20:18 +00:00
|
|
|
public int hollowOutRegion(Region region, int thickness, Pattern pattern) throws MaxChangedBlocksException {
|
2011-12-08 09:31:12 +00:00
|
|
|
int affected = 0;
|
|
|
|
|
2011-12-20 10:20:18 +00:00
|
|
|
final Set<BlockVector> outside = new HashSet<BlockVector>();
|
2011-12-08 09:31:12 +00:00
|
|
|
|
2011-12-20 10:20:18 +00:00
|
|
|
final Vector min = region.getMinimumPoint();
|
|
|
|
final Vector max = region.getMaximumPoint();
|
2011-12-08 09:31:12 +00:00
|
|
|
|
2011-12-20 10:20:18 +00:00
|
|
|
final int minX = min.getBlockX();
|
|
|
|
final int minY = min.getBlockY();
|
|
|
|
final int minZ = min.getBlockZ();
|
|
|
|
final int maxX = max.getBlockX();
|
|
|
|
final int maxY = max.getBlockY();
|
|
|
|
final int maxZ = max.getBlockZ();
|
2011-12-08 09:31:12 +00:00
|
|
|
|
|
|
|
for (int x = minX; x <= maxX; ++x) {
|
|
|
|
for (int y = minY; y <= maxY; ++y) {
|
|
|
|
recurseHollow(region, new BlockVector(x, y, minZ), outside);
|
|
|
|
recurseHollow(region, new BlockVector(x, y, maxZ), outside);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int y = minY; y <= maxY; ++y) {
|
|
|
|
for (int z = minZ; z <= maxZ; ++z) {
|
|
|
|
recurseHollow(region, new BlockVector(minX, y, z), outside);
|
|
|
|
recurseHollow(region, new BlockVector(maxX, y, z), outside);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int z = minZ; z <= maxZ; ++z) {
|
|
|
|
for (int x = minX; x <= maxX; ++x) {
|
|
|
|
recurseHollow(region, new BlockVector(x, minY, z), outside);
|
|
|
|
recurseHollow(region, new BlockVector(x, maxY, z), outside);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-19 10:58:38 +00:00
|
|
|
for (int i = 1; i < thickness; ++i) {
|
2011-12-20 10:20:18 +00:00
|
|
|
final Set<BlockVector> newOutside = new HashSet<BlockVector>();
|
2011-12-19 10:58:38 +00:00
|
|
|
outer: for (BlockVector position : region) {
|
|
|
|
for (Vector recurseDirection: recurseDirections) {
|
|
|
|
BlockVector neighbor = position.add(recurseDirection).toBlockVector();
|
|
|
|
|
|
|
|
if (outside.contains(neighbor)) {
|
|
|
|
newOutside.add(position);
|
|
|
|
continue outer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-20 10:20:18 +00:00
|
|
|
outside.addAll(newOutside);
|
2011-12-19 10:58:38 +00:00
|
|
|
}
|
|
|
|
|
2011-12-08 09:31:12 +00:00
|
|
|
outer: for (BlockVector position : region) {
|
|
|
|
for (Vector recurseDirection: recurseDirections) {
|
|
|
|
BlockVector neighbor = position.add(recurseDirection).toBlockVector();
|
|
|
|
|
|
|
|
if (outside.contains(neighbor)) {
|
|
|
|
continue outer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-20 10:20:18 +00:00
|
|
|
if (setBlock(position, pattern.next(position))) {
|
2011-12-08 09:31:12 +00:00
|
|
|
++affected;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return affected;
|
|
|
|
}
|
|
|
|
|
2013-07-26 05:45:17 +00:00
|
|
|
/**
|
|
|
|
* Draws a line (out of blocks) between two vectors.
|
|
|
|
*
|
2013-08-05 16:53:30 +00:00
|
|
|
* @param pattern The block pattern used to draw the line.
|
2013-07-26 05:45:17 +00:00
|
|
|
* @param pos1 One of the points that define the line.
|
|
|
|
* @param pos2 The other point that defines the line.
|
2013-08-05 16:53:30 +00:00
|
|
|
* @param radius The radius (thickness) of the line.
|
2013-08-04 01:42:19 +00:00
|
|
|
* @param filled If false, only a shell will be generated.
|
2013-07-26 05:45:17 +00:00
|
|
|
*
|
|
|
|
* @return number of blocks affected
|
|
|
|
* @throws MaxChangedBlocksException
|
|
|
|
*/
|
2013-08-04 01:42:19 +00:00
|
|
|
public int drawLine(Pattern pattern, Vector pos1, Vector pos2, double radius, boolean filled)
|
2013-08-05 16:53:30 +00:00
|
|
|
throws MaxChangedBlocksException {
|
2013-07-26 05:45:17 +00:00
|
|
|
|
2013-08-04 01:42:19 +00:00
|
|
|
Set<Vector> vset = new HashSet<Vector>();
|
2013-07-26 05:45:17 +00:00
|
|
|
boolean notdrawn = true;
|
|
|
|
|
|
|
|
int x1 = pos1.getBlockX(), y1 = pos1.getBlockY(), z1 = pos1.getBlockZ();
|
|
|
|
int x2 = pos2.getBlockX(), y2 = pos2.getBlockY(), z2 = pos2.getBlockZ();
|
|
|
|
int tipx = x1, tipy = y1, tipz = z1;
|
|
|
|
int dx = Math.abs(x2 - x1), dy = Math.abs(y2 - y1), dz = Math.abs(z2 - z1);
|
|
|
|
|
|
|
|
if (dx + dy + dz == 0) {
|
2013-08-05 16:53:30 +00:00
|
|
|
vset.add(new Vector(tipx, tipy, tipz));
|
2013-08-04 01:42:19 +00:00
|
|
|
notdrawn = false;
|
2013-07-26 05:45:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Math.max(Math.max(dx, dy), dz) == dx && notdrawn) {
|
|
|
|
for (int domstep = 0; domstep <= dx; domstep++) {
|
|
|
|
tipx = x1 + domstep * (x2 - x1 > 0 ? 1 : -1);
|
|
|
|
tipy = (int) Math.round(y1 + domstep * ((double) dy) / ((double) dx) * (y2 - y1 > 0 ? 1 : -1));
|
|
|
|
tipz = (int) Math.round(z1 + domstep * ((double) dz) / ((double) dx) * (z2 - z1 > 0 ? 1 : -1));
|
|
|
|
|
2013-08-05 16:53:30 +00:00
|
|
|
vset.add(new Vector(tipx, tipy, tipz));
|
2013-07-26 05:45:17 +00:00
|
|
|
}
|
|
|
|
notdrawn = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Math.max(Math.max(dx, dy), dz) == dy && notdrawn) {
|
|
|
|
for (int domstep = 0; domstep <= dy; domstep++) {
|
|
|
|
tipy = y1 + domstep * (y2 - y1 > 0 ? 1 : -1);
|
|
|
|
tipx = (int) Math.round(x1 + domstep * ((double) dx) / ((double) dy) * (x2 - x1 > 0 ? 1 : -1));
|
|
|
|
tipz = (int) Math.round(z1 + domstep * ((double) dz) / ((double) dy) * (z2 - z1 > 0 ? 1 : -1));
|
|
|
|
|
2013-08-05 16:53:30 +00:00
|
|
|
vset.add(new Vector(tipx, tipy, tipz));
|
2013-07-26 05:45:17 +00:00
|
|
|
}
|
|
|
|
notdrawn = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Math.max(Math.max(dx, dy), dz) == dz && notdrawn) {
|
|
|
|
for (int domstep = 0; domstep <= dz; domstep++) {
|
|
|
|
tipz = z1 + domstep * (z2 - z1 > 0 ? 1 : -1);
|
|
|
|
tipy = (int) Math.round(y1 + domstep * ((double) dy) / ((double) dz) * (y2-y1>0 ? 1 : -1));
|
|
|
|
tipx = (int) Math.round(x1 + domstep * ((double) dx) / ((double) dz) * (x2-x1>0 ? 1 : -1));
|
|
|
|
|
2013-08-05 16:53:30 +00:00
|
|
|
vset.add(new Vector(tipx, tipy, tipz));
|
2013-07-26 05:45:17 +00:00
|
|
|
}
|
|
|
|
notdrawn = false;
|
|
|
|
}
|
|
|
|
|
2013-08-05 16:53:30 +00:00
|
|
|
vset = getBallooned(vset, radius);
|
|
|
|
if (!filled) {
|
|
|
|
vset = getHollowed(vset);
|
|
|
|
}
|
|
|
|
return setBlocks(vset, pattern);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draws a spline (out of blocks) between specified vectors.
|
|
|
|
*
|
|
|
|
* @param pattern The block pattern used to draw the spline.
|
|
|
|
* @param nodevectors The list of vectors to draw through.
|
|
|
|
* @param tension The tension of every node.
|
|
|
|
* @param bias The bias of every node.
|
|
|
|
* @param continuity The continuity of every node.
|
|
|
|
* @param quality The quality of the spline. Must be greater than 0.
|
|
|
|
* @param radius The radius (thickness) of the spline.
|
|
|
|
* @param filled If false, only a shell will be generated.
|
|
|
|
*
|
|
|
|
* @return number of blocks affected
|
|
|
|
* @throws MaxChangedBlocksException
|
|
|
|
*/
|
|
|
|
public int drawSpline(Pattern pattern, List<Vector> nodevectors, double tension, double bias, double continuity, double quality, double radius, boolean filled)
|
|
|
|
throws MaxChangedBlocksException {
|
|
|
|
|
|
|
|
Set<Vector> vset = new HashSet<Vector>();
|
|
|
|
List<Node> nodes = new ArrayList(nodevectors.size());
|
|
|
|
|
|
|
|
Interpolation interpol = new KochanekBartelsInterpolation();
|
|
|
|
|
|
|
|
for (int loop = 0; loop < nodevectors.size(); loop++) {
|
|
|
|
Node n = new Node(nodevectors.get(loop));
|
|
|
|
n.setTension(tension);
|
|
|
|
n.setBias(bias);
|
|
|
|
n.setContinuity(continuity);
|
|
|
|
nodes.add(n);
|
|
|
|
}
|
|
|
|
|
|
|
|
interpol.setNodes(nodes);
|
|
|
|
double splinelength = interpol.arcLength(0, 1);
|
|
|
|
for (double loop = 0; loop <= 1; loop += 1D / splinelength / quality) {
|
|
|
|
Vector tipv = interpol.getPosition(loop);
|
|
|
|
int tipx = (int) Math.round(tipv.getX());
|
|
|
|
int tipy = (int) Math.round(tipv.getY());
|
|
|
|
int tipz = (int) Math.round(tipv.getZ());
|
|
|
|
|
|
|
|
vset.add(new Vector(tipx, tipy, tipz));
|
|
|
|
}
|
|
|
|
|
|
|
|
vset = getBallooned(vset, radius);
|
2013-08-04 01:42:19 +00:00
|
|
|
if (!filled) {
|
|
|
|
vset = getHollowed(vset);
|
|
|
|
}
|
|
|
|
return setBlocks(vset, pattern);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static double hypot(double... pars) {
|
|
|
|
double sum = 0;
|
|
|
|
for (double d : pars) {
|
|
|
|
sum += Math.pow(d, 2);
|
|
|
|
}
|
|
|
|
return Math.sqrt(sum);
|
|
|
|
}
|
|
|
|
|
2013-08-05 16:53:30 +00:00
|
|
|
private static Set<Vector> getBallooned(Set<Vector> vset, double radius) {
|
|
|
|
Set<Vector> returnset = new HashSet<Vector>();
|
|
|
|
int ceilrad = (int) Math.ceil(radius);
|
|
|
|
|
|
|
|
for (Vector v : vset) {
|
|
|
|
int tipx = v.getBlockX(), tipy = v.getBlockY(), tipz = v.getBlockZ();
|
|
|
|
|
|
|
|
for (int loopx = tipx - ceilrad; loopx <= tipx + ceilrad; loopx++) {
|
|
|
|
for (int loopy = tipy - ceilrad; loopy <= tipy + ceilrad; loopy++) {
|
|
|
|
for (int loopz = tipz - ceilrad; loopz <= tipz + ceilrad; loopz++) {
|
|
|
|
if (hypot(loopx - tipx, loopy - tipy, loopz - tipz) <= radius) {
|
|
|
|
returnset.add(new Vector(loopx, loopy, loopz));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return returnset;
|
|
|
|
}
|
|
|
|
|
2013-08-04 01:42:19 +00:00
|
|
|
private static Set<Vector> getHollowed(Set<Vector> vset) {
|
|
|
|
Set<Vector> returnset = new HashSet<Vector>();
|
|
|
|
for (Vector v : vset) {
|
|
|
|
double x = v.getX(), y = v.getY(), z = v.getZ();
|
|
|
|
if (!(vset.contains(new Vector(x + 1, y, z)) &&
|
|
|
|
vset.contains(new Vector(x - 1, y, z)) &&
|
|
|
|
vset.contains(new Vector(x, y + 1, z)) &&
|
|
|
|
vset.contains(new Vector(x, y - 1, z)) &&
|
|
|
|
vset.contains(new Vector(x, y, z + 1)) &&
|
|
|
|
vset.contains(new Vector(x, y, z - 1)))) {
|
|
|
|
returnset.add(v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return returnset;
|
|
|
|
}
|
|
|
|
|
2011-12-08 09:31:12 +00:00
|
|
|
private void recurseHollow(Region region, BlockVector origin, Set<BlockVector> outside) {
|
|
|
|
final LinkedList<BlockVector> queue = new LinkedList<BlockVector>();
|
|
|
|
queue.addLast(origin);
|
|
|
|
|
|
|
|
while (!queue.isEmpty()) {
|
|
|
|
final BlockVector current = queue.removeFirst();
|
2013-06-23 19:04:23 +00:00
|
|
|
if (!BlockType.canPassThrough(getBlockType(current), getBlockData(current))) {
|
2011-12-08 09:31:12 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!outside.add(current)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!region.contains(current)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Vector recurseDirection: recurseDirections) {
|
|
|
|
queue.addLast(current.add(recurseDirection).toBlockVector());
|
|
|
|
}
|
|
|
|
} // while
|
|
|
|
}
|
2013-01-19 14:31:00 +00:00
|
|
|
|
2013-10-20 14:26:06 +00:00
|
|
|
public int makeBiomeShape(final Region region, final Vector zero, final Vector unit, final BiomeType biomeType, final String expressionString, final boolean hollow) throws ExpressionException, MaxChangedBlocksException {
|
|
|
|
final Vector2D zero2D = zero.toVector2D();
|
|
|
|
final Vector2D unit2D = unit.toVector2D();
|
|
|
|
|
|
|
|
final Expression expression = Expression.compile(expressionString, "x", "z");
|
|
|
|
expression.optimize();
|
|
|
|
|
|
|
|
final EditSession editSession = this;
|
|
|
|
final WorldEditExpressionEnvironment environment = new WorldEditExpressionEnvironment(editSession, unit, zero);
|
|
|
|
expression.setEnvironment(environment);
|
|
|
|
|
|
|
|
final ArbitraryBiomeShape shape = new ArbitraryBiomeShape(region) {
|
|
|
|
@Override
|
|
|
|
protected BiomeType getBiome(int x, int z, BiomeType defaultBiomeType) {
|
|
|
|
final Vector2D current = new Vector2D(x, z);
|
|
|
|
environment.setCurrentBlock(current.toVector(0));
|
|
|
|
final Vector2D scaled = current.subtract(zero2D).divide(unit2D);
|
|
|
|
|
|
|
|
try {
|
|
|
|
if (expression.evaluate(scaled.getX(), scaled.getZ()) <= 0) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Allow biome setting via a script variable (needs BiomeType<->int mapping)
|
|
|
|
return defaultBiomeType;
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return shape.generate(this, biomeType, hollow);
|
|
|
|
}
|
2014-03-31 23:55:58 +00:00
|
|
|
|
|
|
|
private static final Vector[] recurseDirections = {
|
|
|
|
PlayerDirection.NORTH.vector(),
|
|
|
|
PlayerDirection.EAST.vector(),
|
|
|
|
PlayerDirection.SOUTH.vector(),
|
|
|
|
PlayerDirection.WEST.vector(),
|
|
|
|
PlayerDirection.UP.vector(),
|
|
|
|
PlayerDirection.DOWN.vector(),
|
|
|
|
};
|
|
|
|
|
|
|
|
private static final double lengthSq(double x, double y, double z) {
|
|
|
|
return (x * x) + (y * y) + (z * z);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static final double lengthSq(double x, double z) {
|
|
|
|
return (x * x) + (z * z);
|
|
|
|
}
|
|
|
|
|
2010-10-02 21:52:42 +00:00
|
|
|
}
|