Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-12-24 01:50:06 +01:00
Revert matt's changes
Let's not break Fawe, thanks
Dieser Commit ist enthalten in:
Ursprung
56f29a3962
Commit
bfcc6184ad
@ -7,7 +7,7 @@ New contributions must be licensed under:
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
@ -180,7 +180,7 @@ WorldEdit as a whole is licensed under:
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
import org.gradle.api.Project
|
||||
|
||||
object Versions {
|
||||
const val TEXT = "3.0.4"
|
||||
const val TEXT_EXTRAS = "3.0.5"
|
||||
const val TEXT = "3.0.3"
|
||||
const val TEXT_EXTRAS = "3.0.3"
|
||||
const val PISTON = "0.5.5"
|
||||
const val AUTO_VALUE = "1.7"
|
||||
const val JUNIT = "5.6.1"
|
||||
|
@ -73,7 +73,6 @@
|
||||
<allow pkg="org.spongepowered.api" />
|
||||
<allow pkg="com.mojang.brigadier" />
|
||||
<allow pkg="com.mojang.datafixers" />
|
||||
<allow pkg="org.apache.commons" />
|
||||
</subpackage>
|
||||
|
||||
<subpackage name="fabric">
|
||||
|
@ -128,7 +128,6 @@ public class BukkitGetBlocks_1_14 extends CharGetBlocks {
|
||||
public int getSkyLight(int x, int y, int z) {
|
||||
int layer = y >> 4;
|
||||
if (skyLight[layer] == null) {
|
||||
//getDataLayerData
|
||||
skyLight[layer] = world.getChunkProvider().getLightEngine().a(EnumSkyBlock.SKY).a(SectionPosition.a(nmsChunk.getPos(), layer));
|
||||
}
|
||||
long l = BlockPosition.a(x, y, z);
|
||||
@ -139,7 +138,6 @@ public class BukkitGetBlocks_1_14 extends CharGetBlocks {
|
||||
public int getEmmittedLight(int x, int y, int z) {
|
||||
int layer = y >> 4;
|
||||
if (blockLight[layer] == null) {
|
||||
//getDataLayerData
|
||||
blockLight[layer] = world.getChunkProvider().getLightEngine().a(EnumSkyBlock.BLOCK).a(SectionPosition.a(nmsChunk.getPos(), layer));
|
||||
}
|
||||
long l = BlockPosition.a(x, y, z);
|
||||
|
@ -20,6 +20,11 @@
|
||||
package com.sk89q.bukkit.util;
|
||||
|
||||
import com.sk89q.util.ReflectionUtil;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
@ -28,12 +33,6 @@ import org.bukkit.command.PluginIdentifiableCommand;
|
||||
import org.bukkit.command.SimpleCommandMap;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class CommandRegistration {
|
||||
|
||||
static {
|
||||
@ -62,7 +61,6 @@ public class CommandRegistration {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean register(List<CommandInfo> registered) {
|
||||
CommandMap commandMap = getCommandMap();
|
||||
if (registered == null || commandMap == null) {
|
||||
@ -84,13 +82,12 @@ public class CommandRegistration {
|
||||
if (fallbackCommands != null) {
|
||||
return fallbackCommands;
|
||||
}
|
||||
|
||||
CommandMap commandMap = ReflectionUtil.getField(plugin.getServer().getPluginManager(), "commandMap");
|
||||
if (commandMap == null) {
|
||||
Bukkit.getServer().getLogger().severe(plugin.getDescription().getName() +
|
||||
": Could not retrieve server CommandMap, using fallback instead!");
|
||||
fallbackCommands = commandMap = new SimpleCommandMap(Bukkit.getServer());
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new FallbackRegistrationListener(fallbackCommands), plugin);
|
||||
Bukkit.getServer().getLogger().severe(plugin.getDescription().getName() +
|
||||
": Could not retrieve server CommandMap, using fallback instead!");
|
||||
fallbackCommands = commandMap = new SimpleCommandMap(Bukkit.getServer());
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new FallbackRegistrationListener(fallbackCommands), plugin);
|
||||
} else {
|
||||
serverCommandMap = commandMap;
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ import java.nio.charset.StandardCharsets;
|
||||
*/
|
||||
public class CUIChannelListener implements PluginMessageListener {
|
||||
|
||||
public static final Charset UTF_8_CHARSET = StandardCharsets.UTF_8;
|
||||
public static final Charset UTF_8_CHARSET = Charset.forName("UTF-8");
|
||||
private final WorldEditPlugin plugin;
|
||||
|
||||
public CUIChannelListener(WorldEditPlugin plugin) {
|
||||
|
@ -117,6 +117,27 @@ public class FaweAPI {
|
||||
// return parser != null;
|
||||
// }
|
||||
|
||||
public static <T> T getParser(Class<T> parserClass) {
|
||||
try {
|
||||
Field field = AbstractFactory.class.getDeclaredField("parsers");
|
||||
field.setAccessible(true);
|
||||
ArrayList<InputParser> parsers = new ArrayList<>();
|
||||
parsers.addAll((List<InputParser>) field.get(WorldEdit.getInstance().getMaskFactory()));
|
||||
parsers.addAll((List<InputParser>) field.get(WorldEdit.getInstance().getBlockFactory()));
|
||||
parsers.addAll((List<InputParser>) field.get(WorldEdit.getInstance().getItemFactory()));
|
||||
parsers.addAll((List<InputParser>) field.get(WorldEdit.getInstance().getPatternFactory()));
|
||||
for (InputParser parser : parsers) {
|
||||
if (parserClass.isAssignableFrom(parser.getClass())) {
|
||||
return (T) parser;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* You can either use a IQueueExtent or an EditSession to change blocks<br>
|
||||
* - The IQueueExtent skips a bit of overhead so it's marginally faster<br>
|
||||
|
@ -50,7 +50,7 @@ public class AsyncPreloader implements Preloader, Runnable {
|
||||
MutablePair<World, Set<BlockVector2>> existing = cancelAndGet(player);
|
||||
try {
|
||||
Region region = session.getSelection(world);
|
||||
if (!(region instanceof CuboidRegion) || region.getVolume() > 50466816) {
|
||||
if (!(region instanceof CuboidRegion) || region.getArea() > 50466816) {
|
||||
// TOO LARGE or NOT CUBOID
|
||||
return;
|
||||
}
|
||||
|
@ -428,7 +428,7 @@ public class NMSRelighter implements Relighter {
|
||||
}
|
||||
}
|
||||
for (int y = 255; y > 0; y--) {
|
||||
for (RelightSkyEntry chunk : chunks) { // Propagate skylight
|
||||
for (RelightSkyEntry chunk : chunks) { // Propogate skylight
|
||||
int layer = y >> 4;
|
||||
byte[] mask = chunk.mask;
|
||||
if ((y & 15) == 15 && chunk.fix[layer] != SkipReason.NONE) {
|
||||
@ -596,7 +596,7 @@ public class NMSRelighter implements Relighter {
|
||||
}
|
||||
}
|
||||
|
||||
private class RelightSkyEntry implements Comparable<RelightSkyEntry> {
|
||||
private class RelightSkyEntry implements Comparable {
|
||||
public final int x;
|
||||
public final int z;
|
||||
public final byte[] mask;
|
||||
@ -625,17 +625,18 @@ public class NMSRelighter implements Relighter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(RelightSkyEntry o) {
|
||||
if (o.x < x) {
|
||||
public int compareTo(Object o) {
|
||||
RelightSkyEntry other = (RelightSkyEntry) o;
|
||||
if (other.x < x) {
|
||||
return 1;
|
||||
}
|
||||
if (o.x > x) {
|
||||
if (other.x > x) {
|
||||
return -1;
|
||||
}
|
||||
if (o.z < z) {
|
||||
if (other.z < z) {
|
||||
return 1;
|
||||
}
|
||||
if (o.z > z) {
|
||||
if (other.z > z) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
@ -52,7 +52,7 @@ public class LimitExtent extends PassthroughExtent {
|
||||
|
||||
@Override
|
||||
public List<? extends Entity> getEntities(Region region) {
|
||||
limit.THROW_MAX_CHECKS(region.getVolume());
|
||||
limit.THROW_MAX_CHECKS(region.getArea());
|
||||
try {
|
||||
return getExtent().getEntities(region);
|
||||
} catch (FaweException e) {
|
||||
@ -223,8 +223,8 @@ public class LimitExtent extends PassthroughExtent {
|
||||
|
||||
@Override
|
||||
public void addCaves(Region region) throws WorldEditException {
|
||||
limit.THROW_MAX_CHECKS(region.getVolume());
|
||||
limit.THROW_MAX_CHANGES(region.getVolume());
|
||||
limit.THROW_MAX_CHECKS(region.getArea());
|
||||
limit.THROW_MAX_CHANGES(region.getArea());
|
||||
try {
|
||||
getExtent().addCaves(region);
|
||||
} catch (FaweException e) {
|
||||
@ -236,8 +236,8 @@ public class LimitExtent extends PassthroughExtent {
|
||||
|
||||
@Override
|
||||
public void generate(Region region, GenBase gen) throws WorldEditException {
|
||||
limit.THROW_MAX_CHECKS(region.getVolume());
|
||||
limit.THROW_MAX_CHANGES(region.getVolume());
|
||||
limit.THROW_MAX_CHECKS(region.getArea());
|
||||
limit.THROW_MAX_CHANGES(region.getArea());
|
||||
try {
|
||||
getExtent().generate(region, gen);
|
||||
} catch (FaweException e) {
|
||||
@ -249,8 +249,8 @@ public class LimitExtent extends PassthroughExtent {
|
||||
|
||||
@Override
|
||||
public void addSchems(Region region, Mask mask, List<ClipboardHolder> clipboards, int rarity, boolean rotate) throws WorldEditException {
|
||||
limit.THROW_MAX_CHECKS(region.getVolume());
|
||||
limit.THROW_MAX_CHANGES(region.getVolume());
|
||||
limit.THROW_MAX_CHECKS(region.getArea());
|
||||
limit.THROW_MAX_CHANGES(region.getArea());
|
||||
try {
|
||||
getExtent().addSchems(region, mask, clipboards, rarity, rotate);
|
||||
} catch (FaweException e) {
|
||||
@ -262,8 +262,8 @@ public class LimitExtent extends PassthroughExtent {
|
||||
|
||||
@Override
|
||||
public void spawnResource(Region region, Resource gen, int rarity, int frequency) throws WorldEditException {
|
||||
limit.THROW_MAX_CHECKS(region.getVolume());
|
||||
limit.THROW_MAX_CHANGES(region.getVolume());
|
||||
limit.THROW_MAX_CHECKS(region.getArea());
|
||||
limit.THROW_MAX_CHANGES(region.getArea());
|
||||
try {
|
||||
getExtent().spawnResource(region, gen, rarity, frequency);
|
||||
} catch (FaweException e) {
|
||||
@ -275,8 +275,8 @@ public class LimitExtent extends PassthroughExtent {
|
||||
|
||||
@Override
|
||||
public void addOre(Region region, Mask mask, Pattern material, int size, int frequency, int rarity, int minY, int maxY) throws WorldEditException {
|
||||
limit.THROW_MAX_CHECKS(region.getVolume());
|
||||
limit.THROW_MAX_CHANGES(region.getVolume());
|
||||
limit.THROW_MAX_CHECKS(region.getArea());
|
||||
limit.THROW_MAX_CHANGES(region.getArea());
|
||||
try {
|
||||
getExtent().addOre(region, mask, material, size, frequency, rarity, minY, maxY);
|
||||
} catch (FaweException e) {
|
||||
@ -288,8 +288,8 @@ public class LimitExtent extends PassthroughExtent {
|
||||
|
||||
@Override
|
||||
public void addOres(Region region, Mask mask) throws WorldEditException {
|
||||
limit.THROW_MAX_CHECKS(region.getVolume());
|
||||
limit.THROW_MAX_CHANGES(region.getVolume());
|
||||
limit.THROW_MAX_CHECKS(region.getArea());
|
||||
limit.THROW_MAX_CHANGES(region.getArea());
|
||||
try {
|
||||
getExtent().addOres(region, mask);
|
||||
} catch (FaweException e) {
|
||||
@ -301,7 +301,7 @@ public class LimitExtent extends PassthroughExtent {
|
||||
|
||||
@Override
|
||||
public List<Countable<BlockType>> getBlockDistribution(Region region) {
|
||||
limit.THROW_MAX_CHECKS(region.getVolume());
|
||||
limit.THROW_MAX_CHECKS(region.getArea());
|
||||
try {
|
||||
return getExtent().getBlockDistribution(region);
|
||||
} catch (FaweException e) {
|
||||
@ -314,7 +314,7 @@ public class LimitExtent extends PassthroughExtent {
|
||||
|
||||
@Override
|
||||
public List<Countable<BlockState>> getBlockDistributionWithData(Region region) {
|
||||
limit.THROW_MAX_CHECKS(region.getVolume());
|
||||
limit.THROW_MAX_CHECKS(region.getArea());
|
||||
try {
|
||||
return getExtent().getBlockDistributionWithData(region);
|
||||
} catch (FaweException e) {
|
||||
@ -327,7 +327,7 @@ public class LimitExtent extends PassthroughExtent {
|
||||
|
||||
@Override
|
||||
public int countBlocks(Region region, Set<BaseBlock> searchBlocks) {
|
||||
limit.THROW_MAX_CHECKS(region.getVolume());
|
||||
limit.THROW_MAX_CHECKS(region.getArea());
|
||||
try {
|
||||
return getExtent().countBlocks(region, searchBlocks);
|
||||
} catch (FaweException e) {
|
||||
@ -340,7 +340,7 @@ public class LimitExtent extends PassthroughExtent {
|
||||
|
||||
@Override
|
||||
public int countBlocks(Region region, Mask searchMask) {
|
||||
limit.THROW_MAX_CHECKS(region.getVolume());
|
||||
limit.THROW_MAX_CHECKS(region.getArea());
|
||||
try {
|
||||
return getExtent().countBlocks(region, searchMask);
|
||||
} catch (FaweException e) {
|
||||
@ -353,7 +353,7 @@ public class LimitExtent extends PassthroughExtent {
|
||||
|
||||
@Override
|
||||
public <B extends BlockStateHolder<B>> int setBlocks(Region region, B block) throws MaxChangedBlocksException {
|
||||
limit.THROW_MAX_CHANGES(region.getVolume());
|
||||
limit.THROW_MAX_CHANGES(region.getArea());
|
||||
try {
|
||||
return getExtent().setBlocks(region, block);
|
||||
} catch (FaweException e) {
|
||||
@ -366,7 +366,7 @@ public class LimitExtent extends PassthroughExtent {
|
||||
|
||||
@Override
|
||||
public int setBlocks(Region region, Pattern pattern) throws MaxChangedBlocksException {
|
||||
limit.THROW_MAX_CHANGES(region.getVolume());
|
||||
limit.THROW_MAX_CHANGES(region.getArea());
|
||||
try {
|
||||
return getExtent().setBlocks(region, pattern);
|
||||
} catch (FaweException e) {
|
||||
@ -379,8 +379,8 @@ public class LimitExtent extends PassthroughExtent {
|
||||
|
||||
@Override
|
||||
public <B extends BlockStateHolder<B>> int replaceBlocks(Region region, Set<BaseBlock> filter, B replacement) throws MaxChangedBlocksException {
|
||||
limit.THROW_MAX_CHECKS(region.getVolume());
|
||||
limit.THROW_MAX_CHANGES(region.getVolume());
|
||||
limit.THROW_MAX_CHECKS(region.getArea());
|
||||
limit.THROW_MAX_CHANGES(region.getArea());
|
||||
try {
|
||||
return getExtent().replaceBlocks(region, filter, replacement);
|
||||
} catch (FaweException e) {
|
||||
@ -393,8 +393,8 @@ public class LimitExtent extends PassthroughExtent {
|
||||
|
||||
@Override
|
||||
public int replaceBlocks(Region region, Set<BaseBlock> filter, Pattern pattern) throws MaxChangedBlocksException {
|
||||
limit.THROW_MAX_CHECKS(region.getVolume());
|
||||
limit.THROW_MAX_CHANGES(region.getVolume());
|
||||
limit.THROW_MAX_CHECKS(region.getArea());
|
||||
limit.THROW_MAX_CHANGES(region.getArea());
|
||||
try {
|
||||
return getExtent().replaceBlocks(region, filter, pattern);
|
||||
} catch (FaweException e) {
|
||||
@ -407,8 +407,8 @@ public class LimitExtent extends PassthroughExtent {
|
||||
|
||||
@Override
|
||||
public int replaceBlocks(Region region, Mask mask, Pattern pattern) throws MaxChangedBlocksException {
|
||||
limit.THROW_MAX_CHECKS(region.getVolume());
|
||||
limit.THROW_MAX_CHANGES(region.getVolume());
|
||||
limit.THROW_MAX_CHECKS(region.getArea());
|
||||
limit.THROW_MAX_CHANGES(region.getArea());
|
||||
try {
|
||||
return getExtent().replaceBlocks(region, mask, pattern);
|
||||
} catch (FaweException e) {
|
||||
@ -421,8 +421,8 @@ public class LimitExtent extends PassthroughExtent {
|
||||
|
||||
@Override
|
||||
public int center(Region region, Pattern pattern) throws MaxChangedBlocksException {
|
||||
limit.THROW_MAX_CHECKS(region.getVolume());
|
||||
limit.THROW_MAX_CHANGES(region.getVolume());
|
||||
limit.THROW_MAX_CHECKS(region.getArea());
|
||||
limit.THROW_MAX_CHANGES(region.getArea());
|
||||
try {
|
||||
return getExtent().center(region, pattern);
|
||||
} catch (FaweException e) {
|
||||
@ -448,8 +448,8 @@ public class LimitExtent extends PassthroughExtent {
|
||||
|
||||
@Override
|
||||
public <T extends Filter> T apply(Region region, T filter, boolean full) {
|
||||
limit.THROW_MAX_CHECKS(region.getVolume());
|
||||
limit.THROW_MAX_CHANGES(region.getVolume());
|
||||
limit.THROW_MAX_CHECKS(region.getArea());
|
||||
limit.THROW_MAX_CHANGES(region.getArea());
|
||||
try {
|
||||
return getExtent().apply(region, filter, full);
|
||||
} catch (FaweException e) {
|
||||
|
@ -151,6 +151,10 @@ public abstract class QueueHandler implements Trimable, Runnable {
|
||||
return forkJoinPoolPrimary.submit(call);
|
||||
}
|
||||
|
||||
public <T> Future<T> sync(Runnable run, T value) {
|
||||
return sync(run, value, syncTasks);
|
||||
}
|
||||
|
||||
public <T> Future<T> sync(Runnable run) {
|
||||
return sync(run, syncTasks);
|
||||
}
|
||||
|
@ -1,3 +1,22 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.boydti.fawe.function.mask;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
|
@ -1,3 +1,22 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.boydti.fawe.function.mask;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
|
@ -9,10 +9,6 @@ public class XAxisMask extends AbstractMask implements ResettableMask {
|
||||
|
||||
private transient int layer = -1;
|
||||
|
||||
public XAxisMask(Extent extent) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
if (layer == -1) {
|
||||
|
@ -9,9 +9,6 @@ public class YAxisMask extends AbstractMask implements ResettableMask {
|
||||
|
||||
private transient int layer = -1;
|
||||
|
||||
public YAxisMask(Extent extent) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
if (layer == -1) {
|
||||
|
@ -9,9 +9,6 @@ public class ZAxisMask extends AbstractMask implements ResettableMask {
|
||||
|
||||
private transient int layer = -1;
|
||||
|
||||
public ZAxisMask(Extent extent) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Extent extent, BlockVector3 vector) {
|
||||
if (layer == -1) {
|
||||
|
@ -162,9 +162,6 @@ public class FaweLimit {
|
||||
public void THROW_MAX_CHANGES(int amt) {
|
||||
if ((MAX_CHANGES -= amt) <= 0) throw FaweCache.MAX_CHANGES;
|
||||
}
|
||||
public void THROW_MAX_CHANGES(long amt) {
|
||||
if ((MAX_CHANGES -= amt) <= 0) throw FaweCache.MAX_CHANGES;
|
||||
}
|
||||
|
||||
public void THROW_MAX_FAILS(int amt) {
|
||||
if ((MAX_FAILS -= amt) <= 0) throw FaweCache.MAX_CHECKS;
|
||||
@ -174,10 +171,6 @@ public class FaweLimit {
|
||||
if ((MAX_CHECKS -= amt) <= 0) throw FaweCache.MAX_CHECKS;
|
||||
}
|
||||
|
||||
public void THROW_MAX_CHECKS(long amt) {
|
||||
if ((MAX_CHECKS -= amt) <= 0) throw FaweCache.MAX_CHECKS;
|
||||
}
|
||||
|
||||
public void THROW_MAX_ITERATIONS(int amt) {
|
||||
if ((MAX_ITERATIONS -= amt) <= 0) throw FaweCache.MAX_ITERATIONS;
|
||||
}
|
||||
|
@ -2,9 +2,9 @@ package com.boydti.fawe.object;
|
||||
|
||||
public final class IntTriple {
|
||||
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int z;
|
||||
public int x;
|
||||
public int y;
|
||||
public int z;
|
||||
|
||||
public IntTriple(int x, int y, int z) {
|
||||
this.x = x;
|
||||
|
8
worldedit-core/src/main/java/com/boydti/fawe/object/Lazy.java
Normale Datei
8
worldedit-core/src/main/java/com/boydti/fawe/object/Lazy.java
Normale Datei
@ -0,0 +1,8 @@
|
||||
package com.boydti.fawe.object;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public interface Lazy<T> extends Supplier<T> {
|
||||
Supplier<T> init();
|
||||
public default T get() { return init().get(); }
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package com.boydti.fawe.object;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
public abstract class RunnableVal2<T, U> implements Runnable, BiConsumer<T, U> {
|
||||
public T value1;
|
||||
public U value2;
|
||||
|
||||
public RunnableVal2() {
|
||||
}
|
||||
|
||||
public RunnableVal2(T value1, U value2) {
|
||||
this.value1 = value1;
|
||||
this.value2 = value2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
run(this.value1, this.value2);
|
||||
}
|
||||
|
||||
public abstract void run(T value1, U value2);
|
||||
|
||||
public RunnableVal2<T, U> runAndGet(T value1, U value2) {
|
||||
run(value1, value2);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(T t, U u) {
|
||||
run(t, u);
|
||||
}
|
||||
}
|
@ -93,7 +93,7 @@ public class CPUOptimizedClipboard extends LinearClipboard {
|
||||
}
|
||||
for (Map.Entry<IntTriple, CompoundTag> entry : nbtMapLoc.entrySet()) {
|
||||
IntTriple key = entry.getKey();
|
||||
setTile(getIndex(key.getX(), key.getY(), key.getZ()), entry.getValue());
|
||||
setTile(getIndex(key.x, key.y, key.z), entry.getValue());
|
||||
}
|
||||
nbtMapLoc.clear();
|
||||
}
|
||||
|
@ -324,7 +324,7 @@ public class DiskOptimizedClipboard extends LinearClipboard implements Closeable
|
||||
nbt = null;
|
||||
for (Map.Entry<IntTriple, CompoundTag> entry : nbtMap.entrySet()) {
|
||||
IntTriple key = entry.getKey();
|
||||
int index = getIndex(key.getX(), key.getY(), key.getZ());
|
||||
int index = getIndex(key.x, key.y, key.z);
|
||||
if (index == i) {
|
||||
nbt = entry.getValue();
|
||||
break;
|
||||
|
@ -200,7 +200,7 @@ public class MemoryOptimizedClipboard extends LinearClipboard {
|
||||
nbt = null;
|
||||
for (Map.Entry<IntTriple, CompoundTag> entry : nbtMap.entrySet()) {
|
||||
IntTriple trio = entry.getKey();
|
||||
int index = getIndex(trio.getX(), trio.getY(), trio.getZ());
|
||||
int index = getIndex(trio.x, trio.y, trio.z);
|
||||
if (index == i) {
|
||||
nbt = entry.getValue();
|
||||
break;
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.boydti.fawe.object.mask;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.function.mask.AbstractExtentMask;
|
||||
import com.sk89q.worldedit.function.mask.AbstractMask;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
@ -15,7 +14,7 @@ public class AdjacentAnyMask extends AbstractMask implements ResettableMask {
|
||||
private final CachedMask mask;
|
||||
private final MutableBlockVector3 mutable;
|
||||
|
||||
public AdjacentAnyMask(AbstractExtentMask mask) {
|
||||
public AdjacentAnyMask(Mask mask) {
|
||||
this.mask = CachedMask.cache(mask);
|
||||
mutable = new MutableBlockVector3();
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.boydti.fawe.object.mask;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.function.mask.AbstractExtentMask;
|
||||
import com.sk89q.worldedit.function.mask.BlockMaskBuilder;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
@ -12,7 +11,7 @@ public class SurfaceMask extends AdjacentAnyMask {
|
||||
super(getMask(extent));
|
||||
}
|
||||
|
||||
public static AbstractExtentMask getMask(Extent extent) {
|
||||
public static Mask getMask(Extent extent) {
|
||||
return new BlockMaskBuilder()
|
||||
.addTypes(BlockTypes.AIR, BlockTypes.CAVE_AIR, BlockTypes.VOID_AIR)
|
||||
.addAll(b -> !b.getMaterial().isMovementBlocker())
|
||||
|
@ -87,12 +87,14 @@ public class FuzzyRegionSelector extends PassthroughExtent implements RegionSele
|
||||
|
||||
@Override
|
||||
public void explainPrimarySelection(Actor actor, LocalSession session, BlockVector3 position) {
|
||||
player.print(Caption.of("fawe.worldedit.selector.selector.fuzzy.pos1", position, "(" + region.getVolume() + ")"));
|
||||
int size = this.region.getArea();
|
||||
player.print(Caption.of("fawe.worldedit.selector.selector.fuzzy.pos1", position, "(" + region.getArea() + ")"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void explainSecondarySelection(Actor actor, LocalSession session, BlockVector3 position) {
|
||||
player.print(Caption.of("fawe.worldedit.selector.selector.fuzzy.pos2", position, "(" + region.getVolume() + ")"));
|
||||
int size = this.region.getArea();
|
||||
player.print(Caption.of("fawe.worldedit.selector.selector.fuzzy.pos2", position, "(" + region.getArea() + ")"));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -99,8 +99,8 @@ public abstract class DFSVisitor implements Operation {
|
||||
// mutable2.mutY(from.getY() + direction.y);
|
||||
// mutable2.mutZ(from.getZ() + direction.z);
|
||||
BlockVector3 bv2 = BlockVector3
|
||||
.at(from.getX() + direction.getX(), from.getY() + direction.getY(),
|
||||
from.getZ() + direction.getZ());
|
||||
.at(from.getX() + direction.x, from.getY() + direction.y,
|
||||
from.getZ() + direction.z);
|
||||
if (isVisitable(bv, bv2)) {
|
||||
Node adjacent = new Node(bv2.getBlockX(), bv2.getBlockY(), bv2.getBlockZ());
|
||||
if (!adjacent.equals(current.from)) {
|
||||
|
@ -5,17 +5,29 @@ import com.boydti.fawe.FaweCache;
|
||||
import com.boydti.fawe.beta.IBatchProcessor;
|
||||
import com.boydti.fawe.beta.IQueueChunk;
|
||||
import com.boydti.fawe.beta.IQueueExtent;
|
||||
import com.boydti.fawe.beta.implementation.lighting.NMSRelighter;
|
||||
import com.boydti.fawe.beta.implementation.lighting.NullRelighter;
|
||||
import com.boydti.fawe.beta.implementation.lighting.Relighter;
|
||||
import com.boydti.fawe.beta.implementation.processors.LimitProcessor;
|
||||
import com.boydti.fawe.beta.implementation.queue.ParallelQueueExtent;
|
||||
import com.boydti.fawe.config.Settings;
|
||||
import com.boydti.fawe.logging.rollback.RollbackOptimizedHistory;
|
||||
import com.boydti.fawe.object.*;
|
||||
import com.boydti.fawe.object.FaweLimit;
|
||||
import com.boydti.fawe.object.HistoryExtent;
|
||||
import com.boydti.fawe.object.NullChangeSet;
|
||||
import com.boydti.fawe.object.RegionWrapper;
|
||||
import com.boydti.fawe.object.RelightMode;
|
||||
import com.boydti.fawe.object.brush.visualization.VirtualWorld;
|
||||
import com.boydti.fawe.object.changeset.AbstractChangeSet;
|
||||
import com.boydti.fawe.object.changeset.BlockBagChangeSet;
|
||||
import com.boydti.fawe.object.changeset.DiskStorageHistory;
|
||||
import com.boydti.fawe.object.changeset.MemoryOptimizedHistory;
|
||||
import com.boydti.fawe.object.extent.*;
|
||||
import com.boydti.fawe.object.extent.FaweRegionExtent;
|
||||
import com.boydti.fawe.object.extent.MultiRegionExtent;
|
||||
import com.boydti.fawe.object.extent.NullExtent;
|
||||
import com.boydti.fawe.object.extent.SingleRegionExtent;
|
||||
import com.boydti.fawe.object.extent.SlowExtent;
|
||||
import com.boydti.fawe.object.extent.StripNBTExtent;
|
||||
import com.boydti.fawe.wrappers.WorldWrapper;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
|
@ -4,7 +4,6 @@ import com.sk89q.worldedit.extent.AbstractDelegateExtent;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ExtentTraverser<T extends Extent> {
|
||||
@ -49,8 +48,21 @@ public class ExtentTraverser<T extends Extent> {
|
||||
return last;
|
||||
}
|
||||
|
||||
public boolean insert(T extent) {
|
||||
try {
|
||||
Field field = AbstractDelegateExtent.class.getDeclaredField("extent");
|
||||
field.setAccessible(true);
|
||||
field.set(extent, field.get(root));
|
||||
field.set(root, extent);
|
||||
return true;
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public <U> U findAndGet(Class<U> clazz) {
|
||||
ExtentTraverser<Extent> traverser = find(clazz);
|
||||
ExtentTraverser<Extent> traverser = find( clazz);
|
||||
return (traverser != null) ? (U) traverser.get() : null;
|
||||
}
|
||||
|
||||
|
@ -1,51 +1,92 @@
|
||||
package com.boydti.fawe.util;
|
||||
|
||||
import static java.lang.System.arraycopy;
|
||||
import static org.slf4j.LoggerFactory.getLogger;
|
||||
|
||||
import com.boydti.fawe.Fawe;
|
||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
|
||||
import com.boydti.fawe.config.Settings;
|
||||
import com.boydti.fawe.object.FaweInputStream;
|
||||
import com.boydti.fawe.object.FaweOutputStream;
|
||||
import com.boydti.fawe.object.RegionWrapper;
|
||||
import com.boydti.fawe.object.RunnableVal;
|
||||
import com.boydti.fawe.object.RunnableVal2;
|
||||
import com.boydti.fawe.object.changeset.FaweStreamChangeSet;
|
||||
import com.boydti.fawe.object.io.AbstractDelegateOutputStream;
|
||||
import com.github.luben.zstd.ZstdInputStream;
|
||||
import com.github.luben.zstd.ZstdOutputStream;
|
||||
import com.sk89q.jnbt.*;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.jnbt.DoubleTag;
|
||||
import com.sk89q.jnbt.IntTag;
|
||||
import com.sk89q.jnbt.ListTag;
|
||||
import com.sk89q.jnbt.StringTag;
|
||||
import com.sk89q.jnbt.Tag;
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats;
|
||||
import com.sk89q.worldedit.history.changeset.ChangeSet;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
|
||||
import it.unimi.dsi.fastutil.io.FastBufferedInputStream;
|
||||
import net.jpountz.lz4.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.*;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.*;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.lang.reflect.Array;
|
||||
import java.net.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.nio.channels.Channels;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.*;
|
||||
import java.nio.file.FileVisitResult;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.SimpleFileVisitor;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.Map;
|
||||
import java.util.Scanner;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ForkJoinPool;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.zip.*;
|
||||
import java.util.zip.DataFormatException;
|
||||
import java.util.zip.Deflater;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.Inflater;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import static java.lang.System.arraycopy;
|
||||
import static org.slf4j.LoggerFactory.getLogger;
|
||||
import it.unimi.dsi.fastutil.io.FastBufferedInputStream;
|
||||
import net.jpountz.lz4.LZ4BlockInputStream;
|
||||
import net.jpountz.lz4.LZ4BlockOutputStream;
|
||||
import net.jpountz.lz4.LZ4Compressor;
|
||||
import net.jpountz.lz4.LZ4Factory;
|
||||
import net.jpountz.lz4.LZ4FastDecompressor;
|
||||
import net.jpountz.lz4.LZ4InputStream;
|
||||
import net.jpountz.lz4.LZ4Utils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class MainUtil {
|
||||
|
||||
@ -71,22 +112,22 @@ public class MainUtil {
|
||||
|
||||
public static long getTotalSize(Path path) {
|
||||
final AtomicLong size = new AtomicLong(0);
|
||||
traverse(path, new RunnableVal<BasicFileAttributes>() {
|
||||
traverse(path, new RunnableVal2<Path, BasicFileAttributes>() {
|
||||
@Override
|
||||
public void run(BasicFileAttributes attrs) {
|
||||
public void run(Path path, BasicFileAttributes attrs) {
|
||||
size.addAndGet(attrs.size());
|
||||
}
|
||||
});
|
||||
return size.get();
|
||||
}
|
||||
|
||||
public static void traverse(Path path, final Consumer<BasicFileAttributes> onEach) {
|
||||
public static void traverse(Path path, final BiConsumer<Path, BasicFileAttributes> onEach) {
|
||||
try {
|
||||
Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
|
||||
@Override
|
||||
public FileVisitResult
|
||||
visitFile(Path file, BasicFileAttributes attrs) {
|
||||
onEach.accept(attrs);
|
||||
onEach.accept(file, attrs);
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
|
||||
@ -128,7 +169,7 @@ public class MainUtil {
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
public static void forEachFile(Path path, final RunnableVal<BasicFileAttributes> onEach, Comparator<File> comparator) {
|
||||
public static void forEachFile(Path path, final RunnableVal2<Path, BasicFileAttributes> onEach, Comparator<File> comparator) {
|
||||
File dir = path.toFile();
|
||||
if (!dir.exists()) return;
|
||||
File[] files = path.toFile().listFiles();
|
||||
@ -137,7 +178,7 @@ public class MainUtil {
|
||||
Path filePath = file.toPath();
|
||||
try {
|
||||
BasicFileAttributes attr = Files.readAttributes(filePath, BasicFileAttributes.class);
|
||||
onEach.run(attr);
|
||||
onEach.run(file.toPath(), attr);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -4,8 +4,6 @@ import com.boydti.fawe.object.mask.ResettableMask;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.function.mask.AbstractExtentMask;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.mask.MaskIntersection;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Collection;
|
||||
|
||||
@ -40,18 +38,6 @@ public class MaskTraverser {
|
||||
} catch (NoSuchFieldException | IllegalAccessException ignored) {
|
||||
}
|
||||
}
|
||||
if (mask instanceof MaskIntersection) {
|
||||
MaskIntersection mask1 = (MaskIntersection) mask;
|
||||
try {
|
||||
Field field = mask1.getClass().getDeclaredField("masks");
|
||||
field.setAccessible(true);
|
||||
Collection<Mask> masks = (Collection<Mask>) field.get(mask);
|
||||
for (Mask next : masks) {
|
||||
reset(next, newExtent);
|
||||
}
|
||||
} catch (NoSuchFieldException | IllegalAccessException ignored) {
|
||||
}
|
||||
}
|
||||
try {
|
||||
Field field = current.getDeclaredField("mask");
|
||||
field.setAccessible(true);
|
||||
|
@ -0,0 +1,27 @@
|
||||
package com.boydti.fawe.util;
|
||||
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
public class RegionCacheUtil {
|
||||
public RegionCacheUtil() {
|
||||
|
||||
}
|
||||
|
||||
public void cache(Region region) {
|
||||
Iterator<BlockVector3> iter = region.iterator();
|
||||
}
|
||||
|
||||
public void run() {
|
||||
TaskManager.IMP.async(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -33,9 +33,15 @@ public class WEManager {
|
||||
|
||||
public void cancelEditSafe(AbstractDelegateExtent parent, FaweException reason) throws FaweException {
|
||||
log.warn("CancelEditSafe was hit. Please ignore this message.");
|
||||
Extent currentExtent = parent.getExtent();
|
||||
if (!(currentExtent instanceof NullExtent)) {
|
||||
parent.extent = new NullExtent(parent.extent, reason);
|
||||
try {
|
||||
final Field field = AbstractDelegateExtent.class.getDeclaredField("extent");
|
||||
field.setAccessible(true);
|
||||
Extent currentExtent = parent.getExtent();
|
||||
if (!(currentExtent instanceof NullExtent)) {
|
||||
field.set(parent, new NullExtent((Extent) field.get(parent), reason));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
throw reason;
|
||||
}
|
||||
|
@ -1102,7 +1102,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
|
||||
* @param radius the radius of the spherical area to fill
|
||||
* @param depth the maximum depth, starting from the origin
|
||||
* @param direction the direction to fill
|
||||
* @return the number of blocks affected
|
||||
* @return number of blocks affected
|
||||
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
||||
*/
|
||||
public int fillDirection(final BlockVector3 origin, final Pattern pattern, final double radius, final int depth, BlockVector3 direction) throws MaxChangedBlocksException {
|
||||
@ -1181,7 +1181,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
|
||||
visitor.visit(origin);
|
||||
|
||||
// Execute
|
||||
Operations.completeLegacy(visitor);
|
||||
Operations.completeBlindly(visitor);
|
||||
|
||||
return this.changes = visitor.getAffected();
|
||||
}
|
||||
@ -2185,13 +2185,12 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
|
||||
*
|
||||
* @param position a position
|
||||
* @param radius a radius
|
||||
* @param onlyNormalDirt only affect normal dirt (all default properties)
|
||||
* @param onlyNormalDirt only affect normal dirt (data value 0)
|
||||
* @return number of blocks affected
|
||||
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
||||
*/
|
||||
@Deprecated
|
||||
public int green(BlockVector3 position, double radius, boolean onlyNormalDirt)
|
||||
throws MaxChangedBlocksException {
|
||||
throws MaxChangedBlocksException {
|
||||
final double radiusSq = radius * radius;
|
||||
|
||||
final int ox = position.getBlockX();
|
||||
@ -2258,7 +2257,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
|
||||
GroundFunction ground = new GroundFunction(new ExistingBlockMask(this), generator);
|
||||
LayerVisitor visitor = new LayerVisitor(region, minimumBlockY(region), maximumBlockY(region), ground);
|
||||
visitor.setMask(new NoiseFilter2D(new RandomNoise(), density));
|
||||
Operations.completeLegacy(visitor);
|
||||
Operations.completeBlindly(visitor);
|
||||
return this.changes = ground.getAffected();
|
||||
}
|
||||
|
||||
@ -2404,42 +2403,11 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
|
||||
return changed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deforms the region by a given expression. A deform provides a block's x, y, and z coordinates (possibly scaled)
|
||||
* to an expression, and then sets the block to the block given by the resulting values of the variables, if they
|
||||
* have changed.
|
||||
*
|
||||
* @param region the region to deform
|
||||
* @param zero the origin of the coordinate system
|
||||
* @param unit the scale of the coordinate system
|
||||
* @param expressionString the expression to evaluate for each block
|
||||
*
|
||||
* @return number of blocks changed
|
||||
*
|
||||
* @throws ExpressionException thrown on invalid expression input
|
||||
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
||||
*/
|
||||
public int deformRegion(final Region region, final Vector3 zero, final Vector3 unit, final String expressionString)
|
||||
throws ExpressionException, MaxChangedBlocksException {
|
||||
return deformRegion(region, zero, unit, expressionString, WorldEdit.getInstance().getConfiguration().calculationTimeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deforms the region by a given expression. A deform provides a block's x, y, and z coordinates (possibly scaled)
|
||||
* to an expression, and then sets the block to the block given by the resulting values of the variables, if they
|
||||
* have changed.
|
||||
*
|
||||
* @param region the region to deform
|
||||
* @param zero the origin of the coordinate system
|
||||
* @param unit the scale of the coordinate system
|
||||
* @param expressionString the expression to evaluate for each block
|
||||
* @param timeout maximum time for the expression to evaluate for each block. -1 for unlimited.
|
||||
*
|
||||
* @return number of blocks changed
|
||||
*
|
||||
* @throws ExpressionException thrown on invalid expression input
|
||||
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
||||
*/
|
||||
public int deformRegion(final Region region, final Vector3 zero, final Vector3 unit, final String expressionString,
|
||||
final int timeout) throws ExpressionException, MaxChangedBlocksException {
|
||||
final Expression expression = Expression.compile(expressionString, "x", "y", "z");
|
||||
@ -2457,6 +2425,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
|
||||
final Vector3 zero2 = zero.add(0.5, 0.5, 0.5);
|
||||
|
||||
RegionVisitor visitor = new RegionVisitor(region, new RegionFunction() {
|
||||
private final MutableBlockVector3 mutable = new MutableBlockVector3();
|
||||
|
||||
@Override
|
||||
public boolean apply(BlockVector3 position) throws WorldEditException {
|
||||
|
@ -176,7 +176,7 @@ public class ClipboardCommands {
|
||||
|
||||
lazyClipboard.setOrigin(session.getPlacementPosition(actor));
|
||||
session.setClipboard(new ClipboardHolder(lazyClipboard));
|
||||
actor.print(Caption.of("fawe.worldedit.copy.command.copy" , region.getVolume()));
|
||||
actor.print(Caption.of("fawe.worldedit.copy.command.copy" , region.getArea()));
|
||||
}
|
||||
|
||||
// @Command(
|
||||
|
@ -104,14 +104,14 @@ public class ExpandCommands {
|
||||
private static void expandVert(LocalSession session, Actor actor, World world) throws IncompleteRegionException {
|
||||
Region region = session.getSelection(world);
|
||||
try {
|
||||
long oldSize = region.getVolume();
|
||||
int oldSize = region.getArea();
|
||||
region.expand(
|
||||
BlockVector3.at(0, (world.getMaxY() + 1), 0),
|
||||
BlockVector3.at(0, -(world.getMaxY() + 1), 0));
|
||||
session.getRegionSelector(world).learnChanges();
|
||||
long newSize = region.getVolume();
|
||||
int newSize = region.getArea();
|
||||
session.getRegionSelector(world).explainRegionAdjust(actor, session);
|
||||
long changeSize = newSize - oldSize;
|
||||
int changeSize = newSize - oldSize;
|
||||
actor.printInfo(
|
||||
TranslatableComponent.of("worldedit.expand.expanded.vert", TextComponent.of(changeSize))
|
||||
);
|
||||
@ -134,7 +134,7 @@ public class ExpandCommands {
|
||||
@MultiDirection
|
||||
List<BlockVector3> direction) throws WorldEditException {
|
||||
Region region = session.getSelection(world);
|
||||
long oldSize = region.getVolume();
|
||||
int oldSize = region.getArea();
|
||||
|
||||
if (reverseAmount == 0) {
|
||||
for (BlockVector3 dir : direction) {
|
||||
@ -147,11 +147,11 @@ public class ExpandCommands {
|
||||
}
|
||||
|
||||
session.getRegionSelector(world).learnChanges();
|
||||
long newSize = region.getVolume();
|
||||
int newSize = region.getArea();
|
||||
|
||||
session.getRegionSelector(world).explainRegionAdjust(actor, session);
|
||||
|
||||
long changeSize = newSize - oldSize;
|
||||
int changeSize = newSize - oldSize;
|
||||
actor.printInfo(TranslatableComponent.of("worldedit.expand.expanded", TextComponent.of(changeSize)));
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,10 @@
|
||||
//import com.boydti.fawe.object.mask.BiomeMask;
|
||||
//import com.boydti.fawe.object.mask.BlockLightMask;
|
||||
//import com.boydti.fawe.object.mask.BrightnessMask;
|
||||
//import com.boydti.fawe.object.mask.DataMask;
|
||||
//import com.boydti.fawe.object.mask.ExtremaMask;
|
||||
//import com.boydti.fawe.object.mask.IdDataMask;
|
||||
//import com.boydti.fawe.object.mask.IdMask;
|
||||
//import com.boydti.fawe.object.mask.LightMask;
|
||||
//import com.boydti.fawe.object.mask.OpacityMask;
|
||||
//import com.boydti.fawe.object.mask.ROCAngleMask;
|
||||
@ -168,6 +171,22 @@
|
||||
// }
|
||||
//
|
||||
// @Command(
|
||||
// name = "#id",
|
||||
// desc = "Restrict to initial id"
|
||||
// )
|
||||
// public Mask id(Extent extent) {
|
||||
// return new IdMask(extent);
|
||||
// }
|
||||
//
|
||||
// @Command(
|
||||
// name = "#data",
|
||||
// desc = "Restrict to initial data"
|
||||
// )
|
||||
// public Mask data(Extent extent) {
|
||||
// return new DataMask(extent);
|
||||
// }
|
||||
//
|
||||
// @Command(
|
||||
// name = "#iddata",
|
||||
// desc = "Restrict to initial block id and data"
|
||||
// )
|
||||
|
@ -205,7 +205,7 @@ public class RegionCommands {
|
||||
desc = "Set block lighting in a selection"
|
||||
)
|
||||
@CommandPermissions("worldedit.light.set")
|
||||
public void setlighting(Player player, EditSession editSession, @Selection Region region) {
|
||||
public void setlighting(Player player, EditSession editSession, @Selection Region region, @Range(from = 0, to = 15) int value) {
|
||||
player.print(TextComponent.of("Temporarily not working"));
|
||||
}
|
||||
|
||||
@ -214,7 +214,7 @@ public class RegionCommands {
|
||||
desc = "Set sky lighting in a selection"
|
||||
)
|
||||
@CommandPermissions("worldedit.light.set")
|
||||
public void setskylighting(Player player, @Selection Region region) {
|
||||
public void setskylighting(Player player, @Selection Region region, @Range(from = 0, to= 15) int value) {
|
||||
player.printInfo(TextComponent.of("Temporarily not working"));
|
||||
}
|
||||
|
||||
|
@ -339,7 +339,7 @@ public class SelectionCommands {
|
||||
List<BlockVector3> direction) throws WorldEditException {
|
||||
try {
|
||||
Region region = session.getSelection(world);
|
||||
long oldSize = region.getVolume();
|
||||
int oldSize = region.getArea();
|
||||
if (reverseAmount == 0) {
|
||||
for (BlockVector3 dir : direction) {
|
||||
region.contract(dir.multiply(amount));
|
||||
@ -350,7 +350,7 @@ public class SelectionCommands {
|
||||
}
|
||||
}
|
||||
session.getRegionSelector(world).learnChanges();
|
||||
long newSize = region.getVolume();
|
||||
int newSize = region.getArea();
|
||||
|
||||
session.getRegionSelector(world).explainRegionAdjust(actor, session);
|
||||
|
||||
@ -501,7 +501,7 @@ public class SelectionCommands {
|
||||
|
||||
actor.printInfo(TranslatableComponent.of("worldedit.size.size", TextComponent.of(size.toString())));
|
||||
actor.printInfo(TranslatableComponent.of("worldedit.size.distance", TextComponent.of(region.getMaximumPoint().distance(region.getMinimumPoint()))));
|
||||
actor.printInfo(TranslatableComponent.of("worldedit.size.blocks", TextComponent.of(region.getVolume())));
|
||||
actor.printInfo(TranslatableComponent.of("worldedit.size.blocks", TextComponent.of(region.getArea())));
|
||||
}
|
||||
|
||||
@Command(
|
||||
|
@ -20,7 +20,22 @@
|
||||
package com.sk89q.worldedit.extension.factory;
|
||||
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.factory.parser.mask.*;
|
||||
import com.sk89q.worldedit.extension.factory.parser.mask.AirMaskParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.mask.BiomeMaskParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.mask.BlockCategoryMaskParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.mask.BlockStateMaskParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.mask.BlocksMaskParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.mask.ExistingMaskParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.mask.ExpressionMaskParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.mask.FalseMaskParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.mask.LazyRegionMaskParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.mask.LiquidMaskParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.mask.NegateMaskParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.mask.NoiseMaskParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.mask.OffsetMaskParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.mask.RegionMaskParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.mask.SolidMaskParser;
|
||||
import com.sk89q.worldedit.extension.factory.parser.mask.TrueMaskParser;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.NoMatchException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
@ -66,9 +81,6 @@ public final class MaskFactory extends AbstractFactory<Mask> {
|
||||
register(new TrueMaskParser(worldEdit));
|
||||
register(new AirMaskParser(worldEdit));
|
||||
register(new LiquidMaskParser(worldEdit));
|
||||
register(new XAxisMaskParser(worldEdit));
|
||||
register(new YAxisMaskParser(worldEdit));
|
||||
register(new ZAxisMaskParser(worldEdit));
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,3 +1,22 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.extension.factory.parser.mask;
|
||||
|
||||
import com.boydti.fawe.function.mask.AirMask;
|
||||
|
@ -1,3 +1,22 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.extension.factory.parser.mask;
|
||||
|
||||
import com.boydti.fawe.function.mask.LiquidMask;
|
||||
|
@ -1,48 +0,0 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.extension.factory.parser.mask;
|
||||
|
||||
import com.boydti.fawe.function.mask.XAxisMask;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.internal.registry.SimpleInputParser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class XAxisMaskParser extends SimpleInputParser<Mask> {
|
||||
|
||||
private final List<String> aliases = ImmutableList.of("#xaxis");
|
||||
|
||||
public XAxisMaskParser(WorldEdit worldEdit) {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getMatchedAliases() {
|
||||
return aliases;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mask parseFromSimpleInput(String input, ParserContext context) {
|
||||
return new XAxisMask(context.getExtent());
|
||||
}
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.extension.factory.parser.mask;
|
||||
|
||||
import com.boydti.fawe.function.mask.XAxisMask;
|
||||
import com.boydti.fawe.function.mask.YAxisMask;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.internal.registry.SimpleInputParser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class YAxisMaskParser extends SimpleInputParser<Mask> {
|
||||
|
||||
private final List<String> aliases = ImmutableList.of("#yaxis");
|
||||
|
||||
public YAxisMaskParser(WorldEdit worldEdit) {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getMatchedAliases() {
|
||||
return aliases;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mask parseFromSimpleInput(String input, ParserContext context) {
|
||||
return new YAxisMask(context.getExtent());
|
||||
}
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.extension.factory.parser.mask;
|
||||
|
||||
import com.boydti.fawe.function.mask.XAxisMask;
|
||||
import com.boydti.fawe.function.mask.ZAxisMask;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.internal.registry.SimpleInputParser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ZAxisMaskParser extends SimpleInputParser<Mask> {
|
||||
|
||||
private final List<String> aliases = ImmutableList.of("#zaxis");
|
||||
|
||||
public ZAxisMaskParser(WorldEdit worldEdit) {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getMatchedAliases() {
|
||||
return aliases;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mask parseFromSimpleInput(String input, ParserContext context) {
|
||||
return new ZAxisMask(context.getExtent());
|
||||
}
|
||||
}
|
@ -19,6 +19,7 @@
|
||||
|
||||
package com.sk89q.worldedit.extension.platform;
|
||||
|
||||
import com.boydti.fawe.config.Caption;
|
||||
import com.boydti.fawe.object.task.AsyncNotifyQueue;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
|
||||
@ -700,10 +701,10 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
|
||||
* @return
|
||||
*/
|
||||
public Region getLargestRegion() {
|
||||
long area = 0;
|
||||
int area = 0;
|
||||
Region max = null;
|
||||
for (Region region : this.getCurrentRegions()) {
|
||||
final long tmp = region.getVolume();
|
||||
final int tmp = region.getArea();
|
||||
if (tmp > area) {
|
||||
area = tmp;
|
||||
max = region;
|
||||
|
@ -59,8 +59,7 @@ public class AbstractDelegateExtent implements Extent {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(AbstractDelegateExtent.class);
|
||||
|
||||
//Not safe for public usage
|
||||
public Extent extent;
|
||||
private final Extent extent;
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
|
@ -27,9 +27,8 @@ public class SelectionPoint2DEvent implements CUIEvent {
|
||||
protected final int id;
|
||||
protected final int blockX;
|
||||
protected final int blockZ;
|
||||
protected final long area;
|
||||
protected final int area;
|
||||
|
||||
@Deprecated
|
||||
public SelectionPoint2DEvent(int id, BlockVector2 pos, int area) {
|
||||
this.id = id;
|
||||
this.blockX = pos.getX();
|
||||
@ -37,7 +36,6 @@ public class SelectionPoint2DEvent implements CUIEvent {
|
||||
this.area = area;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public SelectionPoint2DEvent(int id, BlockVector3 pos, int area) {
|
||||
this.id = id;
|
||||
this.blockX = pos.getX();
|
||||
@ -45,20 +43,6 @@ public class SelectionPoint2DEvent implements CUIEvent {
|
||||
this.area = area;
|
||||
}
|
||||
|
||||
public SelectionPoint2DEvent(int id, BlockVector2 pos, long area) {
|
||||
this.id = id;
|
||||
this.blockX = pos.getX();
|
||||
this.blockZ = pos.getZ();
|
||||
this.area = area;
|
||||
}
|
||||
|
||||
public SelectionPoint2DEvent(int id, BlockVector3 pos, long area) {
|
||||
this.id = id;
|
||||
this.blockX = pos.getX();
|
||||
this.blockZ = pos.getZ();
|
||||
this.area = area;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeId() {
|
||||
return "p2";
|
||||
|
@ -25,21 +25,14 @@ public class SelectionPointEvent implements CUIEvent {
|
||||
|
||||
protected final int id;
|
||||
protected final BlockVector3 pos;
|
||||
protected final long area;
|
||||
protected final int area;
|
||||
|
||||
@Deprecated
|
||||
public SelectionPointEvent(int id, BlockVector3 pos, int area) {
|
||||
this.id = id;
|
||||
this.pos = pos;
|
||||
this.area = area;
|
||||
}
|
||||
|
||||
public SelectionPointEvent(int id, BlockVector3 pos, long area) {
|
||||
this.id = id;
|
||||
this.pos = pos;
|
||||
this.area = area;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeId() {
|
||||
return "p";
|
||||
|
@ -20,7 +20,6 @@
|
||||
package com.sk89q.worldedit.regions;
|
||||
|
||||
import com.boydti.fawe.object.collection.BlockVectorSet;
|
||||
import com.google.common.primitives.Longs;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
@ -45,7 +44,7 @@ public abstract class AbstractRegion extends AbstractSet<BlockVector3> implement
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return com.google.common.primitives.Ints.saturatedCast(getVolume());
|
||||
return getArea();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -107,14 +106,19 @@ public abstract class AbstractRegion extends AbstractSet<BlockVector3> implement
|
||||
return points;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of blocks in the region.
|
||||
*
|
||||
* @return number of blocks
|
||||
*/
|
||||
@Override
|
||||
public long getVolume() {
|
||||
public int getArea() {
|
||||
BlockVector3 min = getMinimumPoint();
|
||||
BlockVector3 max = getMaximumPoint();
|
||||
|
||||
return (max.getX() - min.getX() + 1L) *
|
||||
(max.getY() - min.getY() + 1L) *
|
||||
(max.getZ() - min.getZ() + 1L);
|
||||
return (max.getX() - min.getX() + 1) *
|
||||
(max.getY() - min.getY() + 1) *
|
||||
(max.getZ() - min.getZ() + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -214,7 +218,7 @@ public abstract class AbstractRegion extends AbstractSet<BlockVector3> implement
|
||||
int result = worldHash ^ (worldHash >>> 32);
|
||||
result = 31 * result + this.getMinimumPoint().hashCode();
|
||||
result = 31 * result + this.getMaximumPoint().hashCode();
|
||||
result = (int) (31 * result + this.getVolume());
|
||||
result = 31 * result + this.getArea();
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -235,7 +239,7 @@ public abstract class AbstractRegion extends AbstractSet<BlockVector3> implement
|
||||
if(this.getWorld().equals(region.getWorld())
|
||||
&& this.getMinimumPoint().equals(region.getMinimumPoint())
|
||||
&& this.getMaximumPoint().equals(region.getMaximumPoint())
|
||||
&& this.getVolume() == region.getVolume()){
|
||||
&& this.getArea() == region.getArea()){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -35,9 +35,6 @@ import com.sk89q.worldedit.math.geom.Polygons;
|
||||
import com.sk89q.worldedit.regions.iterator.FlatRegion3DIterator;
|
||||
import com.sk89q.worldedit.regions.iterator.FlatRegionIterator;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
@ -199,16 +196,9 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
|
||||
return minY;
|
||||
}
|
||||
|
||||
private static final BigDecimal PI = BigDecimal.valueOf(Math.PI);
|
||||
|
||||
@Override
|
||||
public long getVolume() {
|
||||
return BigDecimal.valueOf(radius.getX())
|
||||
.multiply(BigDecimal.valueOf(radius.getZ()))
|
||||
.multiply(PI)
|
||||
.multiply(BigDecimal.valueOf(getHeight()))
|
||||
.setScale(0, RoundingMode.FLOOR)
|
||||
.longValue();
|
||||
public int getArea() {
|
||||
return (int) Math.floor(radius.getX() * radius.getZ() * Math.PI * getHeight());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -32,8 +32,6 @@ import com.sk89q.worldedit.math.Vector3;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.storage.ChunkStore;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@ -70,7 +68,7 @@ public class EllipsoidRegion extends AbstractRegion {
|
||||
/**
|
||||
* Construct a new instance of this ellipsoid region.
|
||||
*
|
||||
* @param world the world
|
||||
* @param world the world
|
||||
* @param center the center
|
||||
* @param radius the radius
|
||||
*/
|
||||
@ -94,16 +92,10 @@ public class EllipsoidRegion extends AbstractRegion {
|
||||
return center.toVector3().add(getRadius()).toBlockPoint();
|
||||
}
|
||||
|
||||
private static final BigDecimal ELLIPSOID_BASE_MULTIPLIER = BigDecimal.valueOf((4.0 / 3.0) * Math.PI);
|
||||
|
||||
@Override
|
||||
public long getVolume() {
|
||||
return ELLIPSOID_BASE_MULTIPLIER
|
||||
.multiply(BigDecimal.valueOf(radius.getX()))
|
||||
.multiply(BigDecimal.valueOf(radius.getY()))
|
||||
.multiply(BigDecimal.valueOf(radius.getZ()))
|
||||
.setScale(0, RoundingMode.FLOOR)
|
||||
.longValue();
|
||||
public int getArea() {
|
||||
return (int) Math
|
||||
.floor((4.0 / 3.0) * Math.PI * radius.getX() * radius.getY() * radius.getZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -126,7 +118,7 @@ public class EllipsoidRegion extends AbstractRegion {
|
||||
|
||||
if ((diff.getBlockX() & 1) + (diff.getBlockY() & 1) + (diff.getBlockZ() & 1) != 0) {
|
||||
throw new RegionOperationException(
|
||||
"Ellipsoid changes must be even for each dimensions.");
|
||||
"Ellipsoid changes must be even for each dimensions.");
|
||||
}
|
||||
|
||||
return diff.divide(2).floor();
|
||||
|
@ -53,7 +53,7 @@ public class NullRegion implements Region {
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getVolume() {
|
||||
public int getArea() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -25,8 +25,6 @@ import com.sk89q.worldedit.regions.iterator.FlatRegion3DIterator;
|
||||
import com.sk89q.worldedit.regions.iterator.FlatRegionIterator;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
@ -199,22 +197,18 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion {
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getVolume() {
|
||||
long area = 0;
|
||||
public int getArea() {
|
||||
double area = 0;
|
||||
int i, j = points.size() - 1;
|
||||
|
||||
for (i = 0; i < points.size(); ++i) {
|
||||
long x = points.get(j).getBlockX() + points.get(i).getBlockX();
|
||||
long z = points.get(j).getBlockZ() - points.get(i).getBlockZ();
|
||||
area += x * z;
|
||||
area += (points.get(j).getBlockX() + points.get(i).getBlockX())
|
||||
* (points.get(j).getBlockZ() - points.get(i).getBlockZ());
|
||||
j = i;
|
||||
}
|
||||
|
||||
return BigDecimal.valueOf(area)
|
||||
.multiply(BigDecimal.valueOf(0.5))
|
||||
.abs()
|
||||
.setScale(0, RoundingMode.FLOOR)
|
||||
.longValue() * (maxY - minY + 1);
|
||||
return (int) Math.floor(Math.abs(area * 0.5)
|
||||
* (maxY - minY + 1));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -32,10 +32,8 @@ import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
@ -76,40 +74,14 @@ public interface Region extends Iterable<BlockVector3>, Cloneable, IBatchProcess
|
||||
* Get the number of blocks in the region.
|
||||
*
|
||||
* @return number of blocks
|
||||
* @deprecated use {@link Region#getVolume()} to prevent overflows
|
||||
*/
|
||||
@Deprecated
|
||||
default int getArea() {
|
||||
return (int) getVolume();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of blocks in the region.
|
||||
*
|
||||
* <p>Note: This method <b>must</b> be overridden.</p>
|
||||
*
|
||||
* @return number of blocks
|
||||
*/
|
||||
default long getVolume() {
|
||||
// TODO Remove default status when getArea is removed.
|
||||
try {
|
||||
if (getClass().getMethod("getArea").getDeclaringClass().equals(Region.class)) {
|
||||
throw new IllegalStateException("Class " + getClass().getName() + " must override getVolume.");
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
return getArea();
|
||||
}
|
||||
|
||||
/* FAWE code for getArea() before merge:
|
||||
default int getArea() {
|
||||
BlockVector3 min = getMinimumPoint();
|
||||
BlockVector3 max = getMaximumPoint();
|
||||
|
||||
return (max.getX() - min.getX() + 1) * (max.getY() - min.getY() + 1) * (max.getZ() - min.getZ() + 1);
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Get X-size.
|
||||
*
|
||||
|
@ -135,31 +135,8 @@ public interface RegionSelector {
|
||||
* Get the number of blocks inside the region.
|
||||
*
|
||||
* @return number of blocks, or -1 if undefined
|
||||
* @deprecated use {@link RegionSelector#getVolume()}
|
||||
*/
|
||||
@Deprecated
|
||||
default int getArea() {
|
||||
return (int) getVolume();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of blocks inside the region.
|
||||
*
|
||||
* <p>Note: This method <b>must</b> be overridden.</p>
|
||||
*
|
||||
* @return number of blocks, or -1 if undefined
|
||||
*/
|
||||
default long getVolume() {
|
||||
// TODO Remove default once getArea is removed
|
||||
try {
|
||||
if (getClass().getMethod("getArea").getDeclaringClass().equals(RegionSelector.class)) {
|
||||
throw new IllegalStateException("Class " + getClass().getName() + " must override getVolume.");
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
return getArea();
|
||||
}
|
||||
int getArea();
|
||||
|
||||
/**
|
||||
* Update the selector with changes to the region.
|
||||
|
@ -113,8 +113,8 @@ public class TransformRegion extends AbstractRegion {
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getVolume() {
|
||||
return region.getVolume(); // Cannot transform this
|
||||
public int getArea() {
|
||||
return region.getArea(); // Cannot transform this
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -170,8 +170,8 @@ public class ConvexPolyhedralRegionSelector implements RegionSelector, CUIRegion
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getVolume() {
|
||||
return region.getVolume();
|
||||
public int getArea() {
|
||||
return region.getArea();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -250,7 +250,7 @@ public class ConvexPolyhedralRegionSelector implements RegionSelector, CUIRegion
|
||||
int lastVertexId = -1;
|
||||
for (BlockVector3 vertex : vertices) {
|
||||
vertexIds.put(vertex, ++lastVertexId);
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(lastVertexId, vertex, getVolume()));
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(lastVertexId, vertex, getArea()));
|
||||
}
|
||||
|
||||
for (Triangle triangle : triangles) {
|
||||
@ -273,8 +273,8 @@ public class ConvexPolyhedralRegionSelector implements RegionSelector, CUIRegion
|
||||
checkNotNull(session);
|
||||
|
||||
if (isDefined()) {
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(0, region.getMinimumPoint(), getVolume()));
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(1, region.getMaximumPoint(), getVolume()));
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(0, region.getMinimumPoint(), getArea()));
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(1, region.getMaximumPoint(), getArea()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -161,13 +161,13 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion {
|
||||
player.printInfo(TranslatableComponent.of(
|
||||
"worldedit.selection.cuboid.explain.primary-area",
|
||||
TextComponent.of(position1.toString()),
|
||||
TextComponent.of(region.getVolume())
|
||||
TextComponent.of(region.getArea())
|
||||
));
|
||||
} else if (position1 != null) {
|
||||
player.printInfo(TranslatableComponent.of("worldedit.selection.cuboid.explain.primary", TextComponent.of(position1.toString())));
|
||||
}
|
||||
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(0, pos, getVolume()));
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(0, pos, getArea()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -180,13 +180,13 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion {
|
||||
player.printInfo(TranslatableComponent.of(
|
||||
"worldedit.selection.cuboid.explain.secondary-area",
|
||||
TextComponent.of(position2.toString()),
|
||||
TextComponent.of(region.getVolume())
|
||||
TextComponent.of(region.getArea())
|
||||
));
|
||||
} else if (position2 != null) {
|
||||
player.printInfo(TranslatableComponent.of("worldedit.selection.cuboid.explain.secondary", TextComponent.of(position2.toString())));
|
||||
}
|
||||
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(1, pos, getVolume()));
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(1, pos, getArea()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -197,11 +197,11 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion {
|
||||
session.dispatchCUIEvent(player, new SelectionShapeEvent(getTypeID()));
|
||||
|
||||
if (position1 != null) {
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(0, position1, getVolume()));
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(0, position1, getArea()));
|
||||
}
|
||||
|
||||
if (position2 != null) {
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(1, position2, getVolume()));
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(1, position2, getArea()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -268,7 +268,7 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion {
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getVolume() {
|
||||
public int getArea() {
|
||||
if (position1 == null) {
|
||||
return -1;
|
||||
}
|
||||
@ -277,17 +277,17 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return region.getVolume();
|
||||
return region.getArea();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void describeCUI(LocalSession session, Actor player) {
|
||||
if (position1 != null) {
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(0, position1, getVolume()));
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(0, position1, getArea()));
|
||||
}
|
||||
|
||||
if (position2 != null) {
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(1, position2, getVolume()));
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(1, position2, getArea()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -188,7 +188,7 @@ public class CylinderRegionSelector implements RegionSelector, CUIRegion {
|
||||
"worldedit.selection.cylinder.explain.secondary",
|
||||
TextComponent.of(NUMBER_FORMAT.format(region.getRadius().getX())),
|
||||
TextComponent.of(NUMBER_FORMAT.format(region.getRadius().getZ())),
|
||||
TextComponent.of(region.getVolume())
|
||||
TextComponent.of(region.getArea())
|
||||
));
|
||||
} else {
|
||||
player.printError(TranslatableComponent.of("worldedit.selection.cylinder.explain.secondary-missing"));
|
||||
@ -260,8 +260,8 @@ public class CylinderRegionSelector implements RegionSelector, CUIRegion {
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getVolume() {
|
||||
return region.getVolume();
|
||||
public int getArea() {
|
||||
return region.getArea();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -273,8 +273,8 @@ public class CylinderRegionSelector implements RegionSelector, CUIRegion {
|
||||
@Override
|
||||
public void describeLegacyCUI(LocalSession session, Actor player) {
|
||||
if (isDefined()) {
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(0, region.getMinimumPoint(), getVolume()));
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(1, region.getMaximumPoint(), getVolume()));
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(0, region.getMinimumPoint(), getArea()));
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(1, region.getMaximumPoint(), getArea()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,7 +151,7 @@ public class EllipsoidRegionSelector implements RegionSelector, CUIRegion {
|
||||
player.printInfo(TranslatableComponent.of(
|
||||
"worldedit.selection.ellipsoid.explain.primary-area",
|
||||
TextComponent.of(region.getCenter().toString()),
|
||||
TextComponent.of(region.getVolume())
|
||||
TextComponent.of(region.getArea())
|
||||
));
|
||||
} else {
|
||||
player.printInfo(TranslatableComponent.of(
|
||||
@ -169,7 +169,7 @@ public class EllipsoidRegionSelector implements RegionSelector, CUIRegion {
|
||||
player.printInfo(TranslatableComponent.of(
|
||||
"worldedit.selection.ellipsoid.explain.secondary-area",
|
||||
TextComponent.of(region.getRadius().toString()),
|
||||
TextComponent.of(region.getVolume())
|
||||
TextComponent.of(region.getArea())
|
||||
));
|
||||
} else {
|
||||
player.printInfo(TranslatableComponent.of(
|
||||
@ -238,8 +238,8 @@ public class EllipsoidRegionSelector implements RegionSelector, CUIRegion {
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getVolume() {
|
||||
return region.getVolume();
|
||||
public int getArea() {
|
||||
return region.getArea();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -250,8 +250,8 @@ public class EllipsoidRegionSelector implements RegionSelector, CUIRegion {
|
||||
|
||||
@Override
|
||||
public void describeLegacyCUI(LocalSession session, Actor player) {
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(0, region.getMinimumPoint(), getVolume()));
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(1, region.getMaximumPoint(), getVolume()));
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(0, region.getMinimumPoint(), getArea()));
|
||||
session.dispatchCUIEvent(player, new SelectionPointEvent(1, region.getMaximumPoint(), getArea()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -134,7 +134,7 @@ public class ExtendingCuboidRegionSelector extends CuboidRegionSelector {
|
||||
player.printInfo(TranslatableComponent.of(
|
||||
"worldedit.selection.extend.explain.primary",
|
||||
TextComponent.of(pos.toString()),
|
||||
TextComponent.of(region.getVolume())
|
||||
TextComponent.of(region.getArea())
|
||||
));
|
||||
|
||||
explainRegionAdjust(player, session);
|
||||
@ -145,7 +145,7 @@ public class ExtendingCuboidRegionSelector extends CuboidRegionSelector {
|
||||
player.printInfo(TranslatableComponent.of(
|
||||
"worldedit.selection.extend.explain.secondary",
|
||||
TextComponent.of(pos.toString()),
|
||||
TextComponent.of(region.getVolume())
|
||||
TextComponent.of(region.getArea())
|
||||
));
|
||||
|
||||
explainRegionAdjust(player, session);
|
||||
|
@ -174,7 +174,7 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIRegion {
|
||||
player.printInfo(TranslatableComponent.of("worldedit.selection.polygon2d.explain.primary", TextComponent.of(pos.toString())));
|
||||
|
||||
session.dispatchCUIEvent(player, new SelectionShapeEvent(getTypeID()));
|
||||
session.dispatchCUIEvent(player, new SelectionPoint2DEvent(0, pos, getVolume()));
|
||||
session.dispatchCUIEvent(player, new SelectionPoint2DEvent(0, pos, getArea()));
|
||||
session.dispatchCUIEvent(player, new SelectionMinMaxEvent(region.getMinimumY(), region.getMaximumY()));
|
||||
}
|
||||
|
||||
@ -186,7 +186,7 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIRegion {
|
||||
TextComponent.of(pos.toString())
|
||||
));
|
||||
|
||||
session.dispatchCUIEvent(player, new SelectionPoint2DEvent(region.size() - 1, pos, getVolume()));
|
||||
session.dispatchCUIEvent(player, new SelectionPoint2DEvent(region.size() - 1, pos, getArea()));
|
||||
session.dispatchCUIEvent(player, new SelectionMinMaxEvent(region.getMinimumY(), region.getMaximumY()));
|
||||
}
|
||||
|
||||
@ -247,8 +247,8 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIRegion {
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getVolume() {
|
||||
return region.getVolume();
|
||||
public int getArea() {
|
||||
return region.getArea();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -264,7 +264,7 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIRegion {
|
||||
public void describeCUI(LocalSession session, Actor player) {
|
||||
final List<BlockVector2> points = region.getPoints();
|
||||
for (int id = 0; id < points.size(); id++) {
|
||||
session.dispatchCUIEvent(player, new SelectionPoint2DEvent(id, points.get(id), getVolume()));
|
||||
session.dispatchCUIEvent(player, new SelectionPoint2DEvent(id, points.get(id), getArea()));
|
||||
}
|
||||
|
||||
session.dispatchCUIEvent(player, new SelectionMinMaxEvent(region.getMinimumY(), region.getMaximumY()));
|
||||
|
@ -93,7 +93,7 @@ public class SphereRegionSelector extends EllipsoidRegionSelector {
|
||||
player.printInfo(TranslatableComponent.of(
|
||||
"worldedit.selection.sphere.explain.secondary-defined",
|
||||
TextComponent.of(region.getRadius().getX()),
|
||||
TextComponent.of(region.getVolume())
|
||||
TextComponent.of(region.getArea())
|
||||
));
|
||||
} else {
|
||||
player.printInfo(TranslatableComponent.of("worldedit.selection.sphere.explain.secondary", TextComponent.of(region.getRadius().getX())));
|
||||
|
@ -78,8 +78,8 @@ public class RequestSelection implements Region {
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getVolume() {
|
||||
return getRegion().getVolume();
|
||||
public int getArea() {
|
||||
return getRegion().getArea();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
package com.sk89q.worldedit.util.collection;
|
||||
|
||||
import com.google.common.collect.AbstractIterator;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
@ -35,7 +36,6 @@ import java.util.AbstractSet;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiConsumer;
|
||||
@ -43,7 +43,6 @@ import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static com.sk89q.worldedit.math.BitMath.fixSign;
|
||||
import static com.sk89q.worldedit.math.BitMath.mask;
|
||||
|
||||
@ -52,6 +51,12 @@ import static com.sk89q.worldedit.math.BitMath.mask;
|
||||
*/
|
||||
public class BlockMap<V> extends AbstractMap<BlockVector3, V> {
|
||||
|
||||
/* =========================
|
||||
IF YOU MAKE CHANGES TO THIS CLASS
|
||||
Re-run BlockMapTest with the blockmap.fulltesting=true system property.
|
||||
Or just temporarily remove the annotation disabling the related tests.
|
||||
========================= */
|
||||
|
||||
public static <V> BlockMap<V> create() {
|
||||
return create(() -> new Int2ObjectOpenHashMap<>(64, 0.9f));
|
||||
}
|
||||
@ -240,65 +245,26 @@ public class BlockMap<V> extends AbstractMap<BlockVector3, V> {
|
||||
entrySet = es = new AbstractSet<Entry<BlockVector3, V>>() {
|
||||
@Override
|
||||
public Iterator<Entry<BlockVector3, V>> iterator() {
|
||||
return new Iterator<Entry<BlockVector3,V>>() {
|
||||
return new AbstractIterator<Entry<BlockVector3, V>>() {
|
||||
|
||||
private final ObjectIterator<Long2ObjectMap.Entry<Int2ObjectMap<V>>> primaryIterator
|
||||
= Long2ObjectMaps.fastIterator(maps);
|
||||
private Long2ObjectMap.Entry<Int2ObjectMap<V>> currentPrimaryEntry;
|
||||
private long currentGroupKey;
|
||||
private ObjectIterator<Int2ObjectMap.Entry<V>> secondaryIterator;
|
||||
private boolean finished;
|
||||
private LazyEntry next;
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
if (finished) {
|
||||
return false;
|
||||
}
|
||||
if (next == null) {
|
||||
LazyEntry proposedNext = computeNext();
|
||||
if (proposedNext == null) {
|
||||
finished = true;
|
||||
return false;
|
||||
}
|
||||
next = proposedNext;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private LazyEntry computeNext() {
|
||||
protected Entry<BlockVector3, V> computeNext() {
|
||||
if (secondaryIterator == null || !secondaryIterator.hasNext()) {
|
||||
if (!primaryIterator.hasNext()) {
|
||||
return null;
|
||||
return endOfData();
|
||||
}
|
||||
|
||||
currentPrimaryEntry = primaryIterator.next();
|
||||
secondaryIterator = Int2ObjectMaps.fastIterator(currentPrimaryEntry.getValue());
|
||||
// be paranoid
|
||||
checkState(secondaryIterator.hasNext(),
|
||||
"Should not have an empty map entry, it should have been removed!");
|
||||
Long2ObjectMap.Entry<Int2ObjectMap<V>> next = primaryIterator.next();
|
||||
currentGroupKey = next.getLongKey();
|
||||
secondaryIterator = Int2ObjectMaps.fastIterator(next.getValue());
|
||||
}
|
||||
Int2ObjectMap.Entry<V> next = secondaryIterator.next();
|
||||
return new LazyEntry(currentPrimaryEntry.getLongKey(), next.getIntKey(), next.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entry<BlockVector3, V> next() {
|
||||
if (!hasNext()) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
LazyEntry tmp = next;
|
||||
next = null;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
secondaryIterator.remove();
|
||||
// ensure invariants hold
|
||||
if (currentPrimaryEntry.getValue().isEmpty()) {
|
||||
// the remove call cleared this map. call remove on the primary iter
|
||||
primaryIterator.remove();
|
||||
}
|
||||
return new LazyEntry(currentGroupKey, next.getIntKey(), next.getValue());
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -398,14 +364,13 @@ public class BlockMap<V> extends AbstractMap<BlockVector3, V> {
|
||||
@Override
|
||||
public V remove(Object key) {
|
||||
BlockVector3 vec = (BlockVector3) key;
|
||||
long groupKey = toGroupKey(vec);
|
||||
Int2ObjectMap<V> activeMap = maps.get(groupKey);
|
||||
Int2ObjectMap<V> activeMap = maps.get(toGroupKey(vec));
|
||||
if (activeMap == null) {
|
||||
return null;
|
||||
}
|
||||
V removed = activeMap.remove(toInnerKey(vec));
|
||||
if (activeMap.isEmpty()) {
|
||||
maps.remove(groupKey);
|
||||
maps.remove(toGroupKey(vec));
|
||||
}
|
||||
return removed;
|
||||
}
|
||||
@ -464,9 +429,7 @@ public class BlockMap<V> extends AbstractMap<BlockVector3, V> {
|
||||
}
|
||||
if (o instanceof BlockMap) {
|
||||
// optimize by skipping entry translations:
|
||||
@SuppressWarnings("unchecked")
|
||||
BlockMap<V> other = (BlockMap<V>) o;
|
||||
return maps.equals(other.maps);
|
||||
return maps.equals(((BlockMap) o).maps);
|
||||
}
|
||||
return super.equals(o);
|
||||
}
|
||||
|
@ -91,7 +91,6 @@ class Int2BaseBlockMap extends AbstractInt2ObjectMap<BaseBlock> {
|
||||
= Int2IntMaps.fastIterator(commonMap);
|
||||
private final ObjectIterator<Entry<BaseBlock>> uncommonIter
|
||||
= Int2ObjectMaps.fastIterator(uncommonMap);
|
||||
private boolean lastNextFromCommon = false;
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
@ -102,26 +101,15 @@ class Int2BaseBlockMap extends AbstractInt2ObjectMap<BaseBlock> {
|
||||
public Entry<BaseBlock> next() {
|
||||
if (commonIter.hasNext()) {
|
||||
Int2IntMap.Entry e = commonIter.next();
|
||||
lastNextFromCommon = true;
|
||||
return new BasicEntry<>(
|
||||
e.getIntKey(), assumeAsBlock(e.getIntValue())
|
||||
);
|
||||
}
|
||||
if (uncommonIter.hasNext()) {
|
||||
lastNextFromCommon = false;
|
||||
return uncommonIter.next();
|
||||
}
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
if (lastNextFromCommon) {
|
||||
commonIter.remove();
|
||||
} else {
|
||||
uncommonIter.remove();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -30,54 +30,49 @@ import java.util.Iterator;
|
||||
|
||||
class VectorPositionList implements PositionList {
|
||||
|
||||
private final IntList delegateX = new IntArrayList();
|
||||
private final IntList delegateY = new IntArrayList();
|
||||
private final IntList delegateZ = new IntArrayList();
|
||||
private final IntList delegate = new IntArrayList();
|
||||
|
||||
@Override
|
||||
public BlockVector3 get(int index) {
|
||||
int ri = index * 3;
|
||||
return BlockVector3.at(
|
||||
delegateX.getInt(index),
|
||||
delegateY.getInt(index),
|
||||
delegateZ.getInt(index));
|
||||
delegate.getInt(ri),
|
||||
delegate.getInt(ri + 1),
|
||||
delegate.getInt(ri + 2));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(BlockVector3 vector) {
|
||||
delegateX.add(vector.getX());
|
||||
delegateY.add(vector.getY());
|
||||
delegateZ.add(vector.getZ());
|
||||
delegate.add(vector.getX());
|
||||
delegate.add(vector.getY());
|
||||
delegate.add(vector.getZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return delegateX.size();
|
||||
return delegate.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
delegateX.clear();
|
||||
delegateY.clear();
|
||||
delegateZ.clear();
|
||||
delegate.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<BlockVector3> iterator() {
|
||||
return new AbstractIterator<BlockVector3>() {
|
||||
|
||||
private final IntIterator iteratorX = delegateX.iterator();
|
||||
private final IntIterator iteratorY = delegateY.iterator();
|
||||
private final IntIterator iteratorZ = delegateZ.iterator();
|
||||
private final IntIterator iterator = delegate.iterator();
|
||||
|
||||
@Override
|
||||
protected BlockVector3 computeNext() {
|
||||
if (!iteratorX.hasNext()) {
|
||||
if (!iterator.hasNext()) {
|
||||
return endOfData();
|
||||
}
|
||||
return BlockVector3.at(
|
||||
iteratorX.nextInt(),
|
||||
iteratorY.nextInt(),
|
||||
iteratorZ.nextInt());
|
||||
iterator.nextInt(),
|
||||
iterator.nextInt(),
|
||||
iterator.nextInt());
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -86,19 +81,17 @@ class VectorPositionList implements PositionList {
|
||||
public Iterator<BlockVector3> reverseIterator() {
|
||||
return new AbstractIterator<BlockVector3>() {
|
||||
|
||||
private final IntListIterator iteratorX = delegateX.listIterator(delegateX.size());
|
||||
private final IntListIterator iteratorY = delegateY.listIterator(delegateY.size());
|
||||
private final IntListIterator iteratorZ = delegateZ.listIterator(delegateZ.size());
|
||||
private final IntListIterator iterator = delegate.listIterator(delegate.size());
|
||||
|
||||
@Override
|
||||
protected BlockVector3 computeNext() {
|
||||
if (!iteratorX.hasPrevious()) {
|
||||
if (!iterator.hasPrevious()) {
|
||||
return endOfData();
|
||||
}
|
||||
return BlockVector3.at(
|
||||
iteratorX.previousInt(),
|
||||
iteratorY.previousInt(),
|
||||
iteratorZ.previousInt());
|
||||
iterator.previousInt(),
|
||||
iterator.previousInt(),
|
||||
iterator.previousInt());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -31,7 +31,13 @@ public class TaskStateComparator implements Comparator<Task<?>> {
|
||||
public int compare(com.sk89q.worldedit.util.task.Task<?> o1, Task<?> o2) {
|
||||
int ordinal1 = o1.getState().ordinal();
|
||||
int ordinal2 = o2.getState().ordinal();
|
||||
return Integer.compare(ordinal1, ordinal2);
|
||||
if (ordinal1 < ordinal2) {
|
||||
return -1;
|
||||
} else if (ordinal1 > ordinal2) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,36 +0,0 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.math;
|
||||
|
||||
import com.sk89q.worldedit.util.test.VariedVectors;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
@DisplayName("A 3D block vector")
|
||||
public class BlockVector3Test {
|
||||
|
||||
@VariedVectors.Test(capToVanilla = true, divisionsXZ = 50, divisionsY = 50)
|
||||
@DisplayName("survives a round-trip through long-packing")
|
||||
void longPackingRoundTrip(BlockVector3 vec) {
|
||||
assertEquals(vec, BlockVector3.fromLongPackedForm(vec.toLongPackedForm()));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,133 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util;
|
||||
|
||||
import com.google.common.collect.AbstractIterator;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Streams;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.ArgumentsProvider;
|
||||
import org.junit.jupiter.params.provider.ArgumentsSource;
|
||||
import org.junit.jupiter.params.support.AnnotationConsumer;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Argument provider for various vectors.
|
||||
*/
|
||||
public final class VariedVectorsProvider implements ArgumentsProvider, AnnotationConsumer<VariedVectorsProvider.Test> {
|
||||
|
||||
@Target({ ElementType.ANNOTATION_TYPE, ElementType.METHOD })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@ArgumentsSource(VariedVectorsProvider.class)
|
||||
@ParameterizedTest(name = ParameterizedTest.ARGUMENTS_PLACEHOLDER)
|
||||
public @interface Test {
|
||||
|
||||
/**
|
||||
* If {@code true}, provide a non-matching vector from
|
||||
* the existing vectors set as well. This will nearly
|
||||
* square the number of tests executed, since it will
|
||||
* test <em>every</em> non-matching vector.
|
||||
*/
|
||||
boolean provideNonMatching() default false;
|
||||
|
||||
}
|
||||
|
||||
private static final int WORLD_XZ_MINMAX = 30_000_000;
|
||||
private static final long WORLD_Y_MAX = Integer.MAX_VALUE;
|
||||
private static final long WORLD_Y_MIN = Integer.MIN_VALUE;
|
||||
|
||||
// For better coverage assurance, increase these values for a local Gradle run.
|
||||
// Don't do it for IntelliJ, it'll probably run out of memory.
|
||||
private static final int DIVISIONS_XZ = Integer.getInteger("variedvecs.divisions.xz", 5);
|
||||
private static final int DIVISIONS_Y = Integer.getInteger("variedvecs.divisions.y", 5);
|
||||
|
||||
private static final int XZ_STEP = (WORLD_XZ_MINMAX * 2) / DIVISIONS_XZ;
|
||||
private static final long Y_STEP = (WORLD_Y_MAX * 2) / DIVISIONS_Y;
|
||||
|
||||
private static final Set<BlockVector3> ALWAYS_INCLUDE =
|
||||
ImmutableSet.of(BlockVector3.ZERO, BlockVector3.ONE,
|
||||
BlockVector3.at(-WORLD_XZ_MINMAX, 0, -WORLD_XZ_MINMAX),
|
||||
BlockVector3.at(WORLD_XZ_MINMAX, 0, WORLD_XZ_MINMAX),
|
||||
BlockVector3.at(-WORLD_XZ_MINMAX, WORLD_Y_MAX, -WORLD_XZ_MINMAX),
|
||||
BlockVector3.at(WORLD_XZ_MINMAX, WORLD_Y_MAX, WORLD_XZ_MINMAX));
|
||||
|
||||
private boolean provideNonMatching;
|
||||
|
||||
@Override
|
||||
public void accept(Test test) {
|
||||
provideNonMatching = test.provideNonMatching();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
|
||||
if (provideNonMatching) {
|
||||
return makeVectorsStream()
|
||||
.flatMap(vec -> makeVectorsStream().filter(v -> !v.equals(vec))
|
||||
.map(v -> Arguments.of(vec, v)));
|
||||
}
|
||||
return makeVectorsStream().map(Arguments::of);
|
||||
}
|
||||
|
||||
public static Stream<BlockVector3> makeVectorsStream() {
|
||||
return Stream.concat(
|
||||
ALWAYS_INCLUDE.stream(),
|
||||
Streams.stream(generateVectors()).filter(v -> !ALWAYS_INCLUDE.contains(v))
|
||||
);
|
||||
}
|
||||
|
||||
private static Iterator<BlockVector3> generateVectors() {
|
||||
return new AbstractIterator<BlockVector3>() {
|
||||
|
||||
private int x = -WORLD_XZ_MINMAX + 1;
|
||||
private int z = -WORLD_XZ_MINMAX + 1;
|
||||
private long y = WORLD_Y_MAX;
|
||||
|
||||
@Override
|
||||
protected BlockVector3 computeNext() {
|
||||
if (x > WORLD_XZ_MINMAX) {
|
||||
return endOfData();
|
||||
}
|
||||
BlockVector3 newVector = BlockVector3.at(x, (int) y, z);
|
||||
y += Y_STEP;
|
||||
if (y > WORLD_Y_MAX) {
|
||||
y = 0;
|
||||
z += XZ_STEP;
|
||||
if (z > WORLD_XZ_MINMAX) {
|
||||
z = -WORLD_XZ_MINMAX;
|
||||
x += XZ_STEP;
|
||||
}
|
||||
}
|
||||
return newVector;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -27,8 +27,7 @@ import com.sk89q.worldedit.extension.platform.PlatformManager;
|
||||
import com.sk89q.worldedit.extension.platform.Preference;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.registry.Registry;
|
||||
import com.sk89q.worldedit.util.test.VariedVectorGenerator;
|
||||
import com.sk89q.worldedit.util.test.VariedVectors;
|
||||
import com.sk89q.worldedit.util.VariedVectorsProvider;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
@ -46,11 +45,11 @@ import org.mockito.MockitoAnnotations;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.AbstractMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
@ -64,23 +63,24 @@ import static org.junit.jupiter.api.Assumptions.assumeFalse;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@DisplayName("An ordered block map")
|
||||
class BlockMapTest {
|
||||
/*
|
||||
private static final Platform MOCKED_PLATFORM = mock(Platform.class);
|
||||
private static Platform mockedPlatform = mock(Platform.class);
|
||||
|
||||
@BeforeAll
|
||||
static void setupFakePlatform() {
|
||||
when(MOCKED_PLATFORM.getRegistries()).thenReturn(new BundledRegistries() {
|
||||
when(mockedPlatform.getRegistries()).thenReturn(new BundledRegistries() {
|
||||
});
|
||||
when(MOCKED_PLATFORM.getCapabilities()).thenReturn(ImmutableMap.of(
|
||||
when(mockedPlatform.getCapabilities()).thenReturn(ImmutableMap.of(
|
||||
Capability.WORLD_EDITING, Preference.PREFERRED,
|
||||
Capability.GAME_HOOKS, Preference.PREFERRED
|
||||
));
|
||||
PlatformManager platformManager = WorldEdit.getInstance().getPlatformManager();
|
||||
platformManager.register(MOCKED_PLATFORM);
|
||||
platformManager.register(mockedPlatform);
|
||||
|
||||
registerBlock("minecraft:air");
|
||||
registerBlock("minecraft:oak_wood");
|
||||
@ -88,7 +88,7 @@ class BlockMapTest {
|
||||
|
||||
@AfterAll
|
||||
static void tearDownFakePlatform() throws Exception {
|
||||
WorldEdit.getInstance().getPlatformManager().unregister(MOCKED_PLATFORM);
|
||||
WorldEdit.getInstance().getPlatformManager().unregister(mockedPlatform);
|
||||
Field map = Registry.class.getDeclaredField("map");
|
||||
map.setAccessible(true);
|
||||
((Map<?, ?>) map.get(BlockType.REGISTRY)).clear();
|
||||
@ -98,6 +98,8 @@ class BlockMapTest {
|
||||
BlockType.REGISTRY.register(id, new BlockType(id));
|
||||
}
|
||||
|
||||
@Mock
|
||||
private Function<? super BlockVector3, ? extends BaseBlock> function;
|
||||
@Mock
|
||||
private BiFunction<? super BlockVector3, ? super BaseBlock, ? extends BaseBlock> biFunction;
|
||||
@Mock
|
||||
@ -108,7 +110,7 @@ class BlockMapTest {
|
||||
private final BaseBlock air = checkNotNull(BlockTypes.AIR).getDefaultState().toBaseBlock();
|
||||
private final BaseBlock oakWood = checkNotNull(BlockTypes.OAK_WOOD).getDefaultState().toBaseBlock();
|
||||
|
||||
private final BlockMap<BaseBlock> map = BlockMap.createForBaseBlock();
|
||||
private BlockMap<BaseBlock> map = BlockMap.createForBaseBlock();
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
@ -184,14 +186,14 @@ class BlockMapTest {
|
||||
@DisplayName("never calls the forEach action")
|
||||
void neverCallsForEachAction() {
|
||||
map.forEach(biConsumer);
|
||||
verifyNoMoreInteractions(biConsumer);
|
||||
verifyZeroInteractions(biConsumer);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("never calls the replaceAll function")
|
||||
void neverCallsReplaceAllFunction() {
|
||||
map.replaceAll(biFunction);
|
||||
verifyNoMoreInteractions(biFunction);
|
||||
verifyZeroInteractions(biFunction);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -252,62 +254,63 @@ class BlockMapTest {
|
||||
assertEquals(air, map.merge(BlockVector3.ZERO, air, mergeFunction));
|
||||
assertEquals(1, map.size());
|
||||
assertEquals(air, map.get(BlockVector3.ZERO));
|
||||
verifyNoMoreInteractions(mergeFunction);
|
||||
verifyZeroInteractions(mergeFunction);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Nested
|
||||
@DisplayName("after having an entry added")
|
||||
@EnabledIfSystemProperty(named = "blockmap.fulltesting", matches = "true")
|
||||
class AfterEntryAdded {
|
||||
|
||||
// Note: This section of tests would really benefit from
|
||||
// being able to parameterize classes. It's not part of JUnit
|
||||
// yet though: https://github.com/junit-team/junit5/issues/878
|
||||
|
||||
@VariedVectors.Test
|
||||
@VariedVectorsProvider.Test
|
||||
@DisplayName("has a size of one")
|
||||
void hasSizeOne(BlockVector3 vec) {
|
||||
map.put(vec, air);
|
||||
assertEquals(1, map.size());
|
||||
}
|
||||
|
||||
@VariedVectors.Test
|
||||
@VariedVectorsProvider.Test
|
||||
@DisplayName("is equal to another map with the same entry")
|
||||
void isEqualToSimilarMap(BlockVector3 vec) {
|
||||
map.put(vec, air);
|
||||
assertEquals(ImmutableMap.of(vec, air), map);
|
||||
}
|
||||
|
||||
@VariedVectors.Test(provideNonMatching = true)
|
||||
@VariedVectorsProvider.Test(provideNonMatching = true)
|
||||
@DisplayName("is not equal to another map with a different key")
|
||||
void isNotEqualToDifferentKeyMap(BlockVector3 vec, BlockVector3 nonMatch) {
|
||||
map.put(vec, air);
|
||||
assertNotEquals(ImmutableMap.of(nonMatch, air), map);
|
||||
}
|
||||
|
||||
@VariedVectors.Test
|
||||
@VariedVectorsProvider.Test
|
||||
@DisplayName("is not equal to another map with a different value")
|
||||
void isNotEqualToDifferentValueMap(BlockVector3 vec) {
|
||||
map.put(vec, air);
|
||||
assertNotEquals(ImmutableMap.of(vec, oakWood), map);
|
||||
}
|
||||
|
||||
@VariedVectors.Test
|
||||
@VariedVectorsProvider.Test
|
||||
@DisplayName("is not equal to an empty map")
|
||||
void isNotEqualToEmptyMap(BlockVector3 vec) {
|
||||
map.put(vec, air);
|
||||
assertNotEquals(ImmutableMap.of(), map);
|
||||
}
|
||||
|
||||
@VariedVectors.Test
|
||||
@VariedVectorsProvider.Test
|
||||
@DisplayName("has the same hashCode as another map with the same entry")
|
||||
void isHashCodeEqualToSimilarMap(BlockVector3 vec) {
|
||||
map.put(vec, air);
|
||||
assertEquals(ImmutableMap.of(vec, air).hashCode(), map.hashCode());
|
||||
}
|
||||
|
||||
@VariedVectors.Test(provideNonMatching = true)
|
||||
@VariedVectorsProvider.Test(provideNonMatching = true)
|
||||
@DisplayName("has a different hashCode from another map with a different key")
|
||||
void isHashCodeNotEqualToDifferentKeyMap(BlockVector3 vec, BlockVector3 nonMatch) {
|
||||
assumeFalse(vec.hashCode() == nonMatch.hashCode(),
|
||||
@ -316,35 +319,35 @@ class BlockMapTest {
|
||||
assertNotEquals(ImmutableMap.of(nonMatch, air).hashCode(), map.hashCode());
|
||||
}
|
||||
|
||||
@VariedVectors.Test
|
||||
@VariedVectorsProvider.Test
|
||||
@DisplayName("has a different hashCode from another map with a different value")
|
||||
void isHashCodeNotEqualToDifferentValueMap(BlockVector3 vec) {
|
||||
map.put(vec, air);
|
||||
assertNotEquals(ImmutableMap.of(vec, oakWood).hashCode(), map.hashCode());
|
||||
}
|
||||
|
||||
@VariedVectors.Test
|
||||
@VariedVectorsProvider.Test
|
||||
@DisplayName("has a different hashCode from an empty map")
|
||||
void isHashCodeNotEqualToEmptyMap(BlockVector3 vec) {
|
||||
map.put(vec, air);
|
||||
assertNotEquals(ImmutableMap.of().hashCode(), map.hashCode());
|
||||
}
|
||||
|
||||
@VariedVectors.Test
|
||||
@VariedVectorsProvider.Test
|
||||
@DisplayName("returns value from get")
|
||||
void returnsValueFromGet(BlockVector3 vec) {
|
||||
map.put(vec, air);
|
||||
assertEquals(air, map.get(vec));
|
||||
}
|
||||
|
||||
@VariedVectors.Test(provideNonMatching = true)
|
||||
@VariedVectorsProvider.Test(provideNonMatching = true)
|
||||
@DisplayName("returns `null` from get with different key")
|
||||
void returnsValueFromGet(BlockVector3 vec, BlockVector3 nonMatch) {
|
||||
map.put(vec, air);
|
||||
assertNotEquals(air, map.get(nonMatch));
|
||||
}
|
||||
|
||||
@VariedVectors.Test
|
||||
@VariedVectorsProvider.Test
|
||||
@DisplayName("contains the key")
|
||||
void containsTheKey(BlockVector3 vec) {
|
||||
map.put(vec, air);
|
||||
@ -353,7 +356,7 @@ class BlockMapTest {
|
||||
assertTrue(map.containsKey(vec));
|
||||
}
|
||||
|
||||
@VariedVectors.Test
|
||||
@VariedVectorsProvider.Test
|
||||
@DisplayName("contains the value")
|
||||
void containsTheValue(BlockVector3 vec) {
|
||||
map.put(vec, air);
|
||||
@ -362,7 +365,7 @@ class BlockMapTest {
|
||||
assertTrue(map.containsValue(air));
|
||||
}
|
||||
|
||||
@VariedVectors.Test
|
||||
@VariedVectorsProvider.Test
|
||||
@DisplayName("contains the entry")
|
||||
void containsTheEntry(BlockVector3 vec) {
|
||||
map.put(vec, air);
|
||||
@ -370,21 +373,21 @@ class BlockMapTest {
|
||||
assertEquals(new AbstractMap.SimpleImmutableEntry<>(vec, air), map.entrySet().iterator().next());
|
||||
}
|
||||
|
||||
@VariedVectors.Test
|
||||
@VariedVectorsProvider.Test
|
||||
@DisplayName("returns the provided value from getOrDefault")
|
||||
void returnsProvidedFromGetOrDefault(BlockVector3 vec) {
|
||||
map.put(vec, air);
|
||||
assertEquals(air, map.getOrDefault(vec, oakWood));
|
||||
}
|
||||
|
||||
@VariedVectors.Test(provideNonMatching = true)
|
||||
@VariedVectorsProvider.Test(provideNonMatching = true)
|
||||
@DisplayName("returns the default value from getOrDefault with a different key")
|
||||
void returnsDefaultFromGetOrDefaultWrongKey(BlockVector3 vec, BlockVector3 nonMatch) {
|
||||
map.put(vec, air);
|
||||
assertEquals(oakWood, map.getOrDefault(nonMatch, oakWood));
|
||||
}
|
||||
|
||||
@VariedVectors.Test
|
||||
@VariedVectorsProvider.Test
|
||||
@DisplayName("calls the forEach action once")
|
||||
void neverCallsForEachAction(BlockVector3 vec) {
|
||||
map.put(vec, air);
|
||||
@ -393,7 +396,7 @@ class BlockMapTest {
|
||||
verifyNoMoreInteractions(biConsumer);
|
||||
}
|
||||
|
||||
@VariedVectors.Test
|
||||
@VariedVectorsProvider.Test
|
||||
@DisplayName("replaces value using replaceAll")
|
||||
void neverCallsReplaceAllFunction(BlockVector3 vec) {
|
||||
map.put(vec, air);
|
||||
@ -401,7 +404,7 @@ class BlockMapTest {
|
||||
assertEquals(oakWood, map.get(vec));
|
||||
}
|
||||
|
||||
@VariedVectors.Test
|
||||
@VariedVectorsProvider.Test
|
||||
@DisplayName("does not insert on `putIfAbsent`")
|
||||
void noInsertOnPutIfAbsent(BlockVector3 vec) {
|
||||
map.put(vec, air);
|
||||
@ -410,7 +413,7 @@ class BlockMapTest {
|
||||
assertEquals(air, map.get(vec));
|
||||
}
|
||||
|
||||
@VariedVectors.Test(provideNonMatching = true)
|
||||
@VariedVectorsProvider.Test(provideNonMatching = true)
|
||||
@DisplayName("inserts on `putIfAbsent` to a different key")
|
||||
void insertOnPutIfAbsentDifferentKey(BlockVector3 vec, BlockVector3 nonMatch) {
|
||||
map.put(vec, air);
|
||||
@ -420,7 +423,7 @@ class BlockMapTest {
|
||||
assertEquals(oakWood, map.get(nonMatch));
|
||||
}
|
||||
|
||||
@VariedVectors.Test
|
||||
@VariedVectorsProvider.Test
|
||||
@DisplayName("remove(key) returns the old value")
|
||||
void removeKeyReturnsOldValue(BlockVector3 vec) {
|
||||
map.put(vec, air);
|
||||
@ -428,27 +431,7 @@ class BlockMapTest {
|
||||
assertEquals(0, map.size());
|
||||
}
|
||||
|
||||
@VariedVectors.Test
|
||||
@DisplayName("keySet().remove(key) removes the entry from the map")
|
||||
void keySetRemovePassesThrough(BlockVector3 vec) {
|
||||
map.put(vec, air);
|
||||
assertTrue(map.keySet().remove(vec));
|
||||
assertEquals(0, map.size());
|
||||
}
|
||||
|
||||
@VariedVectors.Test
|
||||
@DisplayName("entrySet().iterator().remove() removes the entry from the map")
|
||||
void entrySetIteratorRemovePassesThrough(BlockVector3 vec) {
|
||||
map.put(vec, air);
|
||||
Iterator<Map.Entry<BlockVector3, BaseBlock>> iterator = map.entrySet().iterator();
|
||||
assertTrue(iterator.hasNext());
|
||||
Map.Entry<BlockVector3, BaseBlock> entry = iterator.next();
|
||||
assertEquals(entry.getKey(), vec);
|
||||
iterator.remove();
|
||||
assertEquals(0, map.size());
|
||||
}
|
||||
|
||||
@VariedVectors.Test(provideNonMatching = true)
|
||||
@VariedVectorsProvider.Test(provideNonMatching = true)
|
||||
@DisplayName("remove(nonMatch) returns null")
|
||||
void removeNonMatchingKeyReturnsNull(BlockVector3 vec, BlockVector3 nonMatch) {
|
||||
map.put(vec, air);
|
||||
@ -456,7 +439,7 @@ class BlockMapTest {
|
||||
assertEquals(1, map.size());
|
||||
}
|
||||
|
||||
@VariedVectors.Test
|
||||
@VariedVectorsProvider.Test
|
||||
@DisplayName("remove(key, value) returns true")
|
||||
void removeKeyValueReturnsTrue(BlockVector3 vec) {
|
||||
map.put(vec, air);
|
||||
@ -464,7 +447,7 @@ class BlockMapTest {
|
||||
assertEquals(0, map.size());
|
||||
}
|
||||
|
||||
@VariedVectors.Test
|
||||
@VariedVectorsProvider.Test
|
||||
@DisplayName("remove(key, value) returns false for wrong value")
|
||||
void removeKeyValueReturnsFalseWrongValue(BlockVector3 vec) {
|
||||
map.put(vec, air);
|
||||
@ -472,7 +455,7 @@ class BlockMapTest {
|
||||
assertEquals(1, map.size());
|
||||
}
|
||||
|
||||
@VariedVectors.Test
|
||||
@VariedVectorsProvider.Test
|
||||
@DisplayName("replaces value at key")
|
||||
void replacesValueAtKey(BlockVector3 vec) {
|
||||
map.put(vec, air);
|
||||
@ -486,7 +469,7 @@ class BlockMapTest {
|
||||
assertEquals(air, map.get(vec));
|
||||
}
|
||||
|
||||
@VariedVectors.Test(provideNonMatching = true)
|
||||
@VariedVectorsProvider.Test(provideNonMatching = true)
|
||||
@DisplayName("does not replace value at different key")
|
||||
void doesNotReplaceAtDifferentKey(BlockVector3 vec, BlockVector3 nonMatch) {
|
||||
map.put(vec, air);
|
||||
@ -500,7 +483,7 @@ class BlockMapTest {
|
||||
assertEquals(air, map.get(vec));
|
||||
}
|
||||
|
||||
@VariedVectors.Test
|
||||
@VariedVectorsProvider.Test
|
||||
@DisplayName("does not insert on computeIfAbsent")
|
||||
void doesNotInsertComputeIfAbsent(BlockVector3 vec) {
|
||||
map.put(vec, air);
|
||||
@ -512,7 +495,7 @@ class BlockMapTest {
|
||||
assertEquals(air, map.get(vec));
|
||||
}
|
||||
|
||||
@VariedVectors.Test(provideNonMatching = true)
|
||||
@VariedVectorsProvider.Test(provideNonMatching = true)
|
||||
@DisplayName("inserts on computeIfAbsent with different key")
|
||||
void insertsOnComputeIfAbsentDifferentKey(BlockVector3 vec, BlockVector3 nonMatch) {
|
||||
map.put(vec, air);
|
||||
@ -525,7 +508,7 @@ class BlockMapTest {
|
||||
assertEquals(oakWood, map.get(nonMatch));
|
||||
}
|
||||
|
||||
@VariedVectors.Test
|
||||
@VariedVectorsProvider.Test
|
||||
@DisplayName("replaces on compute")
|
||||
void replaceOnCompute(BlockVector3 vec) {
|
||||
map.put(vec, air);
|
||||
@ -540,7 +523,7 @@ class BlockMapTest {
|
||||
assertEquals(0, map.size());
|
||||
}
|
||||
|
||||
@VariedVectors.Test(provideNonMatching = true)
|
||||
@VariedVectorsProvider.Test(provideNonMatching = true)
|
||||
@DisplayName("inserts on compute with different key")
|
||||
void insertOnComputeDifferentKey(BlockVector3 vec, BlockVector3 nonMatch) {
|
||||
map.put(vec, air);
|
||||
@ -557,7 +540,7 @@ class BlockMapTest {
|
||||
assertEquals(air, map.get(vec));
|
||||
}
|
||||
|
||||
@VariedVectors.Test
|
||||
@VariedVectorsProvider.Test
|
||||
@DisplayName("replaces on computeIfPresent")
|
||||
void replacesOnComputeIfPresent(BlockVector3 vec) {
|
||||
map.put(vec, air);
|
||||
@ -572,7 +555,7 @@ class BlockMapTest {
|
||||
assertEquals(0, map.size());
|
||||
}
|
||||
|
||||
@VariedVectors.Test
|
||||
@VariedVectorsProvider.Test
|
||||
@DisplayName("inserts on merge, with call to merge function")
|
||||
void insertsOnMerge(BlockVector3 vec) {
|
||||
map.put(vec, air);
|
||||
@ -590,9 +573,7 @@ class BlockMapTest {
|
||||
@Test
|
||||
@DisplayName("contains all inserted vectors")
|
||||
void containsAllInsertedVectors() {
|
||||
Set<BlockVector3> allVectors = new VariedVectorGenerator()
|
||||
.makeVectorsStream()
|
||||
.collect(Collectors.toSet());
|
||||
Set<BlockVector3> allVectors = VariedVectorsProvider.makeVectorsStream().collect(Collectors.toSet());
|
||||
for (BlockVector3 vec : allVectors) {
|
||||
map.put(vec, air);
|
||||
}
|
||||
|
@ -1,98 +0,0 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.collection;
|
||||
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.util.test.VariedVectors;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
abstract class PositionListTest {
|
||||
|
||||
static class Long extends PositionListTest {
|
||||
protected Long() {
|
||||
super(new LongPositionList());
|
||||
}
|
||||
}
|
||||
|
||||
static class Vector extends PositionListTest {
|
||||
protected Vector() {
|
||||
super(new VectorPositionList());
|
||||
}
|
||||
}
|
||||
|
||||
private final PositionList positionList;
|
||||
|
||||
protected PositionListTest(PositionList positionList) {
|
||||
this.positionList = positionList;
|
||||
}
|
||||
|
||||
@VariedVectors.Test(capToVanilla = true)
|
||||
@DisplayName("calling add(vec) increases size by 1")
|
||||
void addIncreasesSizeByOne(BlockVector3 vec) {
|
||||
positionList.add(vec);
|
||||
assertEquals(1, positionList.size());
|
||||
}
|
||||
|
||||
@VariedVectors.Test(capToVanilla = true)
|
||||
@DisplayName("calling get(0) after add(vec) returns vec")
|
||||
void canGetVectorAfterAdd(BlockVector3 vec) {
|
||||
positionList.add(vec);
|
||||
assertEquals(vec, positionList.get(0));
|
||||
}
|
||||
|
||||
@VariedVectors.Test(capToVanilla = true)
|
||||
@DisplayName("calling iterator().hasNext() after add(vec) returns true")
|
||||
void hasNextAfterAdd(BlockVector3 vec) {
|
||||
positionList.add(vec);
|
||||
assertTrue(positionList.iterator().hasNext());
|
||||
}
|
||||
|
||||
@VariedVectors.Test(capToVanilla = true)
|
||||
@DisplayName("calling iterator().next() after add(vec) returns vec")
|
||||
void nextAfterAdd(BlockVector3 vec) {
|
||||
positionList.add(vec);
|
||||
assertEquals(vec, positionList.iterator().next());
|
||||
}
|
||||
|
||||
@VariedVectors.Test(capToVanilla = true)
|
||||
@DisplayName("calling reverseIterator().hasNext() after add(vec) returns true")
|
||||
void reverseHasNextAfterAdd(BlockVector3 vec) {
|
||||
positionList.add(vec);
|
||||
assertTrue(positionList.reverseIterator().hasNext());
|
||||
}
|
||||
|
||||
@VariedVectors.Test(capToVanilla = true)
|
||||
@DisplayName("calling reverseIterator().next() after add(vec) returns vec")
|
||||
void reverseNextAfterAdd(BlockVector3 vec) {
|
||||
positionList.add(vec);
|
||||
assertEquals(vec, positionList.reverseIterator().next());
|
||||
}
|
||||
|
||||
@VariedVectors.Test(capToVanilla = true)
|
||||
@DisplayName("calling clear() after add(vec) makes the size() zero")
|
||||
void clearAfterAdd(BlockVector3 vec) {
|
||||
positionList.add(vec);
|
||||
positionList.clear();
|
||||
assertEquals(0, positionList.size());
|
||||
}
|
||||
}
|
@ -1,100 +0,0 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.test;
|
||||
|
||||
import com.google.common.collect.AbstractIterator;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Streams;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class VariedVectorGenerator {
|
||||
|
||||
// For better coverage assurance, increase these values for a local Gradle run.
|
||||
// Don't do it for IntelliJ, it'll probably run out of memory.
|
||||
private static final int DEFAULT_DIVISIONS_XZ =
|
||||
Integer.getInteger("variedvecs.divisions.xz", 5);
|
||||
private static final int DEFAULT_DIVISIONS_Y =
|
||||
Integer.getInteger("variedvecs.divisions.y", 5);
|
||||
|
||||
public final int divisionsXZ;
|
||||
public final int divisionsY;
|
||||
public final int maxXZ;
|
||||
public final long maxY;
|
||||
public final int xzStep;
|
||||
public final long yStep;
|
||||
public final Set<BlockVector3> alwaysInclude;
|
||||
|
||||
public VariedVectorGenerator() {
|
||||
this(false, -1, -1);
|
||||
}
|
||||
|
||||
public VariedVectorGenerator(boolean vanilla, int divisionsXZ, int divisionsY) {
|
||||
this.divisionsXZ = divisionsXZ == -1 ? DEFAULT_DIVISIONS_XZ : divisionsXZ;
|
||||
this.divisionsY = divisionsY == -1 ? DEFAULT_DIVISIONS_Y : divisionsY;
|
||||
maxXZ = 30_000_000;
|
||||
maxY = vanilla ? 255 : Integer.MAX_VALUE;
|
||||
xzStep = (maxXZ * 2) / this.divisionsXZ;
|
||||
yStep = (maxY * 2) / this.divisionsY;
|
||||
alwaysInclude =
|
||||
ImmutableSet.of(BlockVector3.ZERO, BlockVector3.ONE,
|
||||
BlockVector3.at(-maxXZ, 0, -maxXZ),
|
||||
BlockVector3.at(maxXZ, 0, maxXZ),
|
||||
BlockVector3.at(-maxXZ, maxY, -maxXZ),
|
||||
BlockVector3.at(maxXZ, maxY, maxXZ));
|
||||
}
|
||||
|
||||
public Stream<BlockVector3> makeVectorsStream() {
|
||||
return Stream.concat(
|
||||
alwaysInclude.stream(),
|
||||
Streams.stream(generateVectors()).filter(v -> !alwaysInclude.contains(v))
|
||||
);
|
||||
}
|
||||
|
||||
private Iterator<BlockVector3> generateVectors() {
|
||||
return new AbstractIterator<BlockVector3>() {
|
||||
|
||||
private int x = -maxXZ + 1;
|
||||
private int z = -maxXZ + 1;
|
||||
private long y = maxY;
|
||||
|
||||
@Override
|
||||
protected BlockVector3 computeNext() {
|
||||
if (x > maxXZ) {
|
||||
return endOfData();
|
||||
}
|
||||
BlockVector3 newVector = BlockVector3.at(x, (int) y, z);
|
||||
y += yStep;
|
||||
if (y > maxY) {
|
||||
y = 0;
|
||||
z += xzStep;
|
||||
if (z > maxXZ) {
|
||||
z = -maxXZ;
|
||||
x += xzStep;
|
||||
}
|
||||
}
|
||||
return newVector;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -1,87 +0,0 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.test;
|
||||
|
||||
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.ArgumentsProvider;
|
||||
import org.junit.jupiter.params.provider.ArgumentsSource;
|
||||
import org.junit.jupiter.params.support.AnnotationConsumer;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Argument provider for various vectors.
|
||||
*/
|
||||
public final class VariedVectors implements ArgumentsProvider, AnnotationConsumer<VariedVectors.Test> {
|
||||
|
||||
@Target({ ElementType.ANNOTATION_TYPE, ElementType.METHOD })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@ArgumentsSource(VariedVectors.class)
|
||||
@ParameterizedTest(name = ParameterizedTest.ARGUMENTS_PLACEHOLDER)
|
||||
public @interface Test {
|
||||
|
||||
/**
|
||||
* If {@code true}, provide a non-matching vector from
|
||||
* the existing vectors set as well. This will nearly
|
||||
* square the number of tests executed, since it will
|
||||
* test <em>every</em> non-matching vector.
|
||||
*/
|
||||
boolean provideNonMatching() default false;
|
||||
|
||||
/**
|
||||
* If {@code true}, only provide vectors inside the range of Vanilla MC.
|
||||
* This caps the Y value to 255.
|
||||
*/
|
||||
boolean capToVanilla() default false;
|
||||
|
||||
int divisionsXZ() default -1;
|
||||
|
||||
int divisionsY() default -1;
|
||||
|
||||
}
|
||||
|
||||
private boolean provideNonMatching;
|
||||
private VariedVectorGenerator generator;
|
||||
|
||||
@Override
|
||||
public void accept(Test test) {
|
||||
provideNonMatching = test.provideNonMatching();
|
||||
generator = new VariedVectorGenerator(test.capToVanilla(), test.divisionsXZ(), test.divisionsY());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
|
||||
if (provideNonMatching) {
|
||||
return generator.makeVectorsStream()
|
||||
.flatMap(vec -> generator.makeVectorsStream().filter(v -> !v.equals(vec))
|
||||
.map(v -> Arguments.of(vec, v)));
|
||||
}
|
||||
return generator.makeVectorsStream().map(Arguments::of);
|
||||
}
|
||||
|
||||
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren