本文整理汇总了Java中com.sk89q.worldedit.regions.CuboidRegion类的典型用法代码示例。如果您正苦于以下问题:Java CuboidRegion类的具体用法?Java CuboidRegion怎么用?Java CuboidRegion使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CuboidRegion类属于com.sk89q.worldedit.regions包,在下文中一共展示了CuboidRegion类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setBlocks
import com.sk89q.worldedit.regions.CuboidRegion; //导入依赖的package包/类
/**
* Sets all the blocks inside a region to a given block type.
*
* @param region the region
* @param block the block
* @return number of blocks affected
* @throws MaxChangedBlocksException thrown if too many blocks are changed
*/
@SuppressWarnings("deprecation")
public int setBlocks(final Region region, final BaseBlock block) {
checkNotNull(region);
checkNotNull(block);
if (canBypassAll(region, false, true) && !block.hasNbtData()) {
return changes = queue.setBlocks((CuboidRegion) region, block.getId(), block.getData());
}
try {
if (hasExtraExtents()) {
RegionVisitor visitor = new RegionVisitor(region, new BlockReplace(extent, (block)), this);
Operations.completeBlindly(visitor);
this.changes += visitor.getAffected();
} else {
Iterator<BlockVector> iter = region.iterator();
while (iter.hasNext()) {
if (this.extent.setBlock(iter.next(), block)) {
changes++;
}
}
}
} catch (final WorldEditException e) {
throw new RuntimeException("Unexpected exception", e);
}
return changes;
}
示例2: run
import com.sk89q.worldedit.regions.CuboidRegion; //导入依赖的package包/类
@Override
public void run() {
// This only runs once if period is zero
// convert only once, after placement:
//TODO: do in RoomTask!?
if (!convertedToGlobal) {
targetRegion = new CuboidRegion(parent.toGlobal(targetRegion.getPos1()), parent.toGlobal(targetRegion.getPos2()));
convertedToGlobal = true;
}
// Spawns air only if onTime == 0
// Redstone only if onTime == 1
// Redstone and Air after it if onTime between 0 and 1 and a period is present
if (onTime == 0)
depower(null);
else
empower();
}
示例3: execute
import com.sk89q.worldedit.regions.CuboidRegion; //导入依赖的package包/类
protected void execute(Event event) {
String name = (String) this.name.getSingle(event);
World world = (World) this.world.getSingle(event);
ItemStack block = (ItemStack) this.block.getSingle(event);
RegionManager regionManager = WGBukkit.getRegionManager((org.bukkit.World) world);
if (!regionManager.hasRegion(name)) {
Skript.error("Region \"" + name + "\" in world \"" + world.getName() + "\" does not exists.");
return;
}
Vector v1 = regionManager.getRegion(name).getMaximumPoint();
Vector v2 = regionManager.getRegion(name).getMinimumPoint();
Region region = new CuboidRegion(v1, v2);
BaseBlock b = new BaseBlock(block.getTypeId(), block.getData().getData());
EditSession es = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1);
try {
es.setBlocks(region, b);
} catch (Exception e) {
e.printStackTrace();
}
}
示例4: getCompoundTag
import com.sk89q.worldedit.regions.CuboidRegion; //导入依赖的package包/类
@Override
public void getCompoundTag(final String world, final Set<RegionWrapper> regions, final RunnableVal<CompoundTag> whenDone) {
TaskManager.IMP.async(new Runnable() {
@Override
public void run() {
Location[] corners = MainUtil.getCorners(world, regions);
Location pos1 = corners[0];
Location pos2 = corners[1];
final CuboidRegion region = new CuboidRegion(new Vector(pos1.getX(), pos1.getY(), pos1.getZ()), new Vector(pos2.getX(), pos2.getY(), pos2.getZ()));
final EditSession editSession = new EditSessionBuilder(world).checkMemory(false).fastmode(true).limitUnlimited().changeSetNull().autoQueue(false).build();
final int mx = pos1.getX();
final int my = pos1.getY();
final int mz = pos1.getZ();
ReadOnlyClipboard clipboard = ReadOnlyClipboard.of(editSession, region);
Clipboard holder = new BlockArrayClipboard(region, clipboard);
com.sk89q.jnbt.CompoundTag weTag = SchematicWriter.writeTag(holder);
CompoundTag tag = new CompoundTag((Map<String, Tag>) (Map<?, ?>) weTag.getValue());
whenDone.run(tag);
}
});
}
示例5: swap
import com.sk89q.worldedit.regions.CuboidRegion; //导入依赖的package包/类
@Override
public void swap(final Location pos1, final Location pos2, final Location pos3, final Location pos4, final Runnable whenDone) {
TaskManager.IMP.async(new Runnable() {
@Override
public void run() {
EditSession sessionA = new EditSessionBuilder(pos1.getWorld()).checkMemory(false).fastmode(true).limitUnlimited().changeSetNull().autoQueue(false).build();
EditSession sessionB = new EditSessionBuilder(pos3.getWorld()).checkMemory(false).fastmode(true).limitUnlimited().changeSetNull().autoQueue(false).build();
CuboidRegion regionA = new CuboidRegion(new Vector(pos1.getX(), pos1.getY(), pos1.getZ()), new Vector(pos2.getX(), pos2.getY(), pos2.getZ()));
CuboidRegion regionB = new CuboidRegion(new Vector(pos3.getX(), pos3.getY(), pos3.getZ()), new Vector(pos4.getX(), pos4.getY(), pos4.getZ()));
ForwardExtentCopy copyA = new ForwardExtentCopy(sessionA, regionA, sessionB, regionB.getMinimumPoint());
ForwardExtentCopy copyB = new ForwardExtentCopy(sessionB, regionB, sessionA, regionA.getMinimumPoint());
try {
Operations.completeLegacy(copyA);
Operations.completeLegacy(copyB);
sessionA.flushQueue();
sessionB.flushQueue();
} catch (MaxChangedBlocksException e) {
e.printStackTrace();
}
TaskManager.IMP.task(whenDone);
}
});
}
示例6: copyRegion
import com.sk89q.worldedit.regions.CuboidRegion; //导入依赖的package包/类
@Override
public boolean copyRegion(final Location pos1, final Location pos2, final Location pos3, final Runnable whenDone) {
TaskManager.IMP.async(new Runnable() {
@Override
public void run() {
EditSession from = new EditSessionBuilder(pos1.getWorld()).checkMemory(false).fastmode(true).limitUnlimited().changeSetNull().autoQueue(false).build();
EditSession to = new EditSessionBuilder(pos3.getWorld()).checkMemory(false).fastmode(true).limitUnlimited().changeSetNull().autoQueue(false).build();
CuboidRegion region = new CuboidRegion(new Vector(pos1.getX(), pos1.getY(), pos1.getZ()), new Vector(pos2.getX(), pos2.getY(), pos2.getZ()));
ForwardExtentCopy copy = new ForwardExtentCopy(from, region, to, new Vector(pos3.getX(), pos3.getY(), pos3.getZ()));
try {
Operations.completeLegacy(copy);
to.flushQueue();
} catch (MaxChangedBlocksException e) {
e.printStackTrace();
}
TaskManager.IMP.task(whenDone);
}
});
return true;
}
示例7: getClipboard
import com.sk89q.worldedit.regions.CuboidRegion; //导入依赖的package包/类
public Clipboard getClipboard() throws IOException {
try {
addDimensionReaders();
addBlockReaders();
readFully();
Vector min = new Vector(originX, originY, originZ);
Vector offset = new Vector(offsetX, offsetY, offsetZ);
Vector origin = min.subtract(offset);
Vector dimensions = new Vector(width, height, length);
fc.setDimensions(dimensions);
CuboidRegion region = new CuboidRegion(min, min.add(width, height, length).subtract(Vector.ONE));
clipboard.init(region, fc);
clipboard.setOrigin(origin);
return clipboard;
} catch (Throwable e) {
if (fc != null) {
fc.close();
}
throw e;
}
}
示例8: runWithSelection
import com.sk89q.worldedit.regions.CuboidRegion; //导入依赖的package包/类
/**
* Run safely on an existing world within a selection
*
* @param player
* @param editSession
* @param selection
* @param filter
* @param <G>
* @param <T>
* @return
*/
@Deprecated
public static <G, T extends MCAFilter<G>> T runWithSelection(Player player, EditSession editSession, Region selection, T filter) {
if (!(selection instanceof CuboidRegion)) {
BBC.NO_REGION.send(player);
return null;
}
CuboidRegion cuboid = (CuboidRegion) selection;
RegionWrapper wrappedRegion = new RegionWrapper(cuboid.getMinimumPoint(), cuboid.getMaximumPoint());
String worldName = Fawe.imp().getWorldName(editSession.getWorld());
FaweQueue tmp = SetQueue.IMP.getNewQueue(worldName, true, false);
MCAQueue queue = new MCAQueue(tmp);
FawePlayer<Object> fp = FawePlayer.wrap(player);
fp.checkAllowedRegion(selection);
recordHistory(fp, editSession.getWorld(), iAnvilHistory -> {
queue.filterCopy(filter, wrappedRegion, iAnvilHistory);
});
return filter;
}
示例9: copy
import com.sk89q.worldedit.regions.CuboidRegion; //导入依赖的package包/类
@Command(
aliases = {"copy"},
desc = "Lazily copy chunks to your anvil clipboard"
)
@CommandPermissions("worldedit.anvil.copychunks")
public void copy(Player player, LocalSession session, EditSession editSession, @Selection Region selection) throws WorldEditException {
if (!(selection instanceof CuboidRegion)) {
BBC.NO_REGION.send(player);
return;
}
CuboidRegion cuboid = (CuboidRegion) selection;
String worldName = Fawe.imp().getWorldName(editSession.getWorld());
FaweQueue tmp = SetQueue.IMP.getNewQueue(worldName, true, false);
MCAQueue queue = new MCAQueue(tmp);
Vector origin = session.getPlacementPosition(player);
MCAClipboard clipboard = new MCAClipboard(queue, cuboid, origin);
FawePlayer fp = FawePlayer.wrap(player);
fp.setMeta(FawePlayer.METADATA_KEYS.ANVIL_CLIPBOARD, clipboard);
BBC.COMMAND_COPY.send(player, selection.getArea());
}
示例10: canBypassAll
import com.sk89q.worldedit.regions.CuboidRegion; //导入依赖的package包/类
public boolean canBypassAll(Region region, boolean get, boolean set) {
if (wrapped) return false;
FaweRegionExtent regionExtent = getRegionExtent();
if (!(region instanceof CuboidRegion)) return false;
if (regionExtent != null) {
if (!(region instanceof CuboidRegion)) return false;
Vector pos1 = region.getMinimumPoint();
Vector pos2 = region.getMaximumPoint();
boolean contains = false;
for (RegionWrapper current : regionExtent.getRegions()) {
if (current.isIn((int) pos1.getX(), pos1.getBlockY(), pos1.getBlockZ()) && current.isIn(pos2.getBlockX(), pos2.getBlockY(), pos2.getBlockZ())) {
contains = true;
break;
}
}
if (!contains) return false;
}
long area = region.getArea();
FaweLimit left = getLimitLeft();
if (!left.isUnlimited() && (((get || getChangeTask() != null) && left.MAX_CHECKS <= area) || (set && left.MAX_CHANGES <= area)))
return false;
if (getChangeTask() != getChangeSet()) return false;
if (!Masks.isNull(getMask()) || !Masks.isNull(getSourceMask())) return false;
if (getBlockBag() != null) return false;
return true;
}
示例11: makeWalls
import com.sk89q.worldedit.regions.CuboidRegion; //导入依赖的package包/类
/**
* 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.
*
* @param region the region
* @param pattern the pattern to place
* @return number of blocks affected
* @throws MaxChangedBlocksException thrown if too many blocks are changed
*/
@SuppressWarnings("deprecation")
public int makeWalls(final Region region, final Pattern pattern) throws WorldEditException {
checkNotNull(region);
checkNotNull(pattern);
if (region instanceof CuboidRegion) {
return this.makeCuboidWalls(region, pattern);
} else {
final int minY = region.getMinimumPoint().getBlockY();
final int maxY = region.getMaximumPoint().getBlockY();
final ArbitraryShape shape = new RegionShape(region) {
@Override
public BaseBlock getMaterial(final int x, final int y, final int z, final 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);
}
}
示例12: makePumpkinPatches
import com.sk89q.worldedit.regions.CuboidRegion; //导入依赖的package包/类
/**
* Makes pumpkin patches randomly in an area around the given position.
*
* @param position the base position
* @param apothem the apothem of the (square) area
* @return number of patches created
* @throws MaxChangedBlocksException thrown if too many blocks are changed
*/
public int makePumpkinPatches(final Vector position, final int apothem) {
// We want to generate pumpkins
final GardenPatchGenerator generator = new GardenPatchGenerator(EditSession.this);
generator.setPlant(GardenPatchGenerator.getPumpkinPattern());
// In a region of the given radius
final FlatRegion region = new CuboidRegion(EditSession.this.getWorld(), // Causes clamping of Y range
position.add(-apothem, -5, -apothem), position.add(apothem, 10, apothem));
final double density = 0.02;
final GroundFunction ground = new GroundFunction(new ExistingBlockMask(EditSession.this), generator);
final LayerVisitor visitor = new LayerVisitor(region, minimumBlockY(region), maximumBlockY(region), ground);
visitor.setMask(new NoiseFilter2D(new RandomNoise(), density));
Operations.completeBlindly(visitor);
return this.changes = ground.getAffected();
}
示例13: generateSpawnpoints
import com.sk89q.worldedit.regions.CuboidRegion; //导入依赖的package包/类
@Override
public void generateSpawnpoints(CuboidRegion region, World world, List<Location> spawnpoints, int n) {
Vector min = region.getMinimumPoint();
Vector max = region.getMaximumPoint();
int dx = max.getBlockX() - min.getBlockX();
int dz = max.getBlockZ() - min.getBlockZ();
int py = max.getBlockY() + 1;
for (int i = 0; i < n; i++) {
int rx = (int) (Math.random() * dx);
int rz = (int) (Math.random() * dz);
int px = min.getBlockX() + rx;
int pz = min.getBlockZ() + rz;
Location location = new Location(world, px + 0.5, py, pz + 0.5);
spawnpoints.add(location);
}
}
示例14: apply
import com.sk89q.worldedit.regions.CuboidRegion; //导入依赖的package包/类
@Override
public void apply(Element applyTo, CuboidRegion region) {
Vector pos1 = region.getPos1();
Vector pos2 = region.getPos2();
Element pos1Element = applyTo.addElement("pos1");
Element x1Element = pos1Element.addElement("x");
Element y1Element = pos1Element.addElement("y");
Element zElement = pos1Element.addElement("z");
Element pos2Element = applyTo.addElement("pos2");
Element x2Element = pos2Element.addElement("x");
Element y2Element = pos2Element.addElement("y");
Element z2Element = pos2Element.addElement("z");
x1Element.addText(String.valueOf(pos1.getBlockX()));
y1Element.addText(String.valueOf(pos1.getBlockY()));
zElement.addText(String.valueOf(pos1.getBlockZ()));
x2Element.addText(String.valueOf(pos2.getBlockX()));
y2Element.addText(String.valueOf(pos2.getBlockY()));
z2Element.addText(String.valueOf(pos2.getBlockZ()));
}
示例15: asRegion
import com.sk89q.worldedit.regions.CuboidRegion; //导入依赖的package包/类
@Override
public CuboidRegion asRegion(Element container) {
Element pos1Element = container.element("pos1");
Element pos2Element = container.element("pos2");
int x1 = Integer.parseInt(pos1Element.elementText("x"));
int y1 = Integer.parseInt(pos1Element.elementText("y"));
int z1 = Integer.parseInt(pos1Element.elementText("z"));
int x2 = Integer.parseInt(pos2Element.elementText("x"));
int y2 = Integer.parseInt(pos2Element.elementText("y"));
int z2 = Integer.parseInt(pos2Element.elementText("z"));
Vector pos1 = new Vector(x1, y1, z1);
Vector pos2 = new Vector(x2, y2, z2);
return new CuboidRegion(pos1, pos2);
}