Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-11-07 12:00:07 +01:00
Upstream
Dieser Commit ist enthalten in:
Ursprung
a1c15e1c39
Commit
a69b239848
@ -1,18 +1,6 @@
|
||||
package com.sk89q.worldedit.bukkit;
|
||||
|
||||
import com.sk89q.worldedit.world.registry.BundledItemRegistry;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
public class BukkitItemRegistry extends BundledItemRegistry {
|
||||
@Override
|
||||
public Collection<String> registerItems() {
|
||||
ArrayList<String> items = new ArrayList<>();
|
||||
for (Material m : Material.values()) {
|
||||
if (!m.isLegacy() && m.isItem()) items.add(m.getKey().getNamespace() + ":" + m.getKey().getKey());
|
||||
}
|
||||
return items;
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ package com.sk89q.worldedit.bukkit;
|
||||
|
||||
import com.boydti.fawe.object.RunnableVal;
|
||||
import com.boydti.fawe.util.TaskManager;
|
||||
|
||||
import com.sk89q.util.StringUtil;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
@ -41,7 +42,6 @@ import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
import com.sk89q.worldedit.world.gamemode.GameMode;
|
||||
import com.sk89q.worldedit.world.gamemode.GameModes;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -51,12 +51,11 @@ import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class BukkitPlayer extends AbstractPlayerActor {
|
||||
|
||||
private Player player;
|
||||
@ -168,13 +167,10 @@ public class BukkitPlayer extends AbstractPlayerActor {
|
||||
Extent extent = loc.getExtent();
|
||||
if (extent instanceof World) {
|
||||
org.bukkit.World world = Bukkit.getWorld(((World) extent).getName());
|
||||
// System.out.println("Teleport to world " + world);
|
||||
player.teleport(new Location(world, pos.getX(), pos.getY(),
|
||||
pos.getZ(), yaw, pitch));
|
||||
player.teleport(new Location(world, pos.getX(), pos.getY(), pos.getZ(), yaw, pitch));
|
||||
}
|
||||
}
|
||||
player.teleport(new Location(player.getWorld(), pos.getX(), pos.getY(),
|
||||
pos.getZ(), yaw, pitch));
|
||||
player.teleport(new Location(player.getWorld(), pos.getX(), pos.getY(), pos.getZ(), yaw, pitch));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -10,6 +10,7 @@ import com.boydti.fawe.object.clipboard.FaweClipboard;
|
||||
import com.boydti.fawe.object.clipboard.MemoryOptimizedClipboard;
|
||||
import com.boydti.fawe.object.io.FastByteArrayOutputStream;
|
||||
import com.boydti.fawe.object.io.FastByteArraysInputStream;
|
||||
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.jnbt.ListTag;
|
||||
import com.sk89q.jnbt.NBTInputStream;
|
||||
@ -18,15 +19,17 @@ import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.registry.state.PropertyKey;
|
||||
import com.sk89q.worldedit.util.Direction;
|
||||
import com.sk89q.worldedit.world.biome.BiomeTypes;
|
||||
import com.sk89q.worldedit.world.block.*;
|
||||
import com.sk89q.worldedit.world.block.BlockID;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.block.BlockTypeSwitch;
|
||||
import com.sk89q.worldedit.world.block.BlockTypeSwitchBuilder;
|
||||
import com.sk89q.worldedit.world.entity.EntityType;
|
||||
import com.sk89q.worldedit.world.entity.EntityTypes;
|
||||
import com.sk89q.worldedit.world.item.ItemTypes;
|
||||
import com.sk89q.worldedit.world.registry.BlockMaterial;
|
||||
import com.sk89q.worldedit.world.registry.LegacyMapper;
|
||||
import net.jpountz.lz4.LZ4BlockInputStream;
|
||||
|
@ -4,6 +4,7 @@ import com.boydti.fawe.FaweCache;
|
||||
import com.boydti.fawe.object.FaweChunk;
|
||||
import com.boydti.fawe.object.io.FastByteArrayOutputStream;
|
||||
import com.boydti.fawe.util.MathMan;
|
||||
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.jnbt.ListTag;
|
||||
import com.sk89q.jnbt.NBTConstants;
|
||||
@ -91,7 +92,6 @@ public class WritableMCAChunk extends FaweChunk<Void> {
|
||||
nbtOut.writeNamedTagName("", NBTConstants.TYPE_COMPOUND);
|
||||
nbtOut.writeNamedTag("DataVersion", 1631);
|
||||
nbtOut.writeLazyCompoundTag("Level", out -> {
|
||||
// out.writeNamedTag("V", (byte) 1);
|
||||
out.writeNamedTag("Status", "decorated");
|
||||
out.writeNamedTag("xPos", getX());
|
||||
out.writeNamedTag("zPos", getZ());
|
||||
@ -104,21 +104,25 @@ public class WritableMCAChunk extends FaweChunk<Void> {
|
||||
out.writeNamedEmptyList("TileEntities");
|
||||
} else {
|
||||
out.writeNamedTag("TileEntities", new ListTag(CompoundTag.class,
|
||||
new ArrayList<>(tiles.values())));
|
||||
new ArrayList<>(tiles.values())));
|
||||
}
|
||||
out.writeNamedTag("InhabitedTime", inhabitedTime);
|
||||
out.writeNamedTag("LastUpdate", lastUpdate);
|
||||
out.writeNamedTag("Biomes", biomes);
|
||||
int len = 0;
|
||||
for (boolean hasSection : hasSections) {
|
||||
if (hasSection) len++;
|
||||
if (hasSection) {
|
||||
len++;
|
||||
}
|
||||
}
|
||||
out.writeNamedTagName("Sections", NBTConstants.TYPE_LIST);
|
||||
nbtOut.writeByte(NBTConstants.TYPE_COMPOUND);
|
||||
nbtOut.writeInt(len);
|
||||
|
||||
for (int layer = 0; layer < hasSections.length; layer++) {
|
||||
if (!hasSections[layer]) continue;
|
||||
if (!hasSections[layer]) {
|
||||
continue;
|
||||
}
|
||||
out.writeNamedTag("Y", (byte) layer);
|
||||
|
||||
int blockIndexStart = layer << 12;
|
||||
@ -186,7 +190,9 @@ public class WritableMCAChunk extends FaweChunk<Void> {
|
||||
|
||||
out.writeNamedTagName("BlockStates", NBTConstants.TYPE_LONG_ARRAY);
|
||||
out.writeInt(blockBitArrayEnd);
|
||||
for (int i = 0; i < blockBitArrayEnd; i++) out.writeLong(blockstates[i]);
|
||||
for (int i = 0; i < blockBitArrayEnd; i++) {
|
||||
out.writeLong(blockstates[i]);
|
||||
}
|
||||
|
||||
|
||||
out.writeNamedTagName("BlockLight", NBTConstants.TYPE_BYTE_ARRAY);
|
||||
@ -337,12 +343,16 @@ public class WritableMCAChunk extends FaweChunk<Void> {
|
||||
}
|
||||
|
||||
public int getSkyLight(int x, int y, int z) {
|
||||
if (!hasSections[y >> 4]) return 0;
|
||||
if (!hasSections[y >> 4]) {
|
||||
return 0;
|
||||
}
|
||||
return getNibble(getIndex(x, y, z), skyLight);
|
||||
}
|
||||
|
||||
public int getBlockLight(int x, int y, int z) {
|
||||
if (!hasSections[y >> 4]) return 0;
|
||||
if (!hasSections[y >> 4]) {
|
||||
return 0;
|
||||
}
|
||||
return getNibble(getIndex(x, y, z), blockLight);
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,11 @@
|
||||
package com.boydti.fawe.object.clipboard;
|
||||
|
||||
import com.boydti.fawe.object.schematic.StructureFormat;
|
||||
import com.google.common.io.ByteSource;
|
||||
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.ClipboardReader;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.SchematicReader;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.util.UUID;
|
||||
|
@ -3,6 +3,7 @@ package com.boydti.fawe.object.collection;
|
||||
import com.boydti.fawe.util.MathMan;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.MutableBlockVector3;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
@ -115,14 +116,13 @@ public class LocalBlockVectorSet implements Set<BlockVector3> {
|
||||
int b3 = ((byte) (index >> 15)) & 0xFF;
|
||||
int b4 = ((byte) (index >> 23)) & 0xFF;
|
||||
int x = offsetX + (((b3 + ((MathMan.unpair8x(b2)) << 8)) << 21) >> 21);
|
||||
int y = b1;
|
||||
int z = offsetZ + (((b4 + ((MathMan.unpair8y(b2)) << 8)) << 21) >> 21);
|
||||
return MutableBlockVector3.get(x, y, z);
|
||||
return MutableBlockVector3.get(x, b1, z);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull @Override
|
||||
public Iterator<BlockVector3> iterator() {
|
||||
return new Iterator<BlockVector3>() {
|
||||
int index = set.nextSetBit(0);
|
||||
@ -158,12 +158,12 @@ public class LocalBlockVectorSet implements Set<BlockVector3> {
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull @Override
|
||||
public Object[] toArray() {
|
||||
return toArray(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull @Override
|
||||
public <T> T[] toArray(T[] array) {
|
||||
int size = size();
|
||||
if (array == null || array.length < size) {
|
||||
@ -177,9 +177,8 @@ public class LocalBlockVectorSet implements Set<BlockVector3> {
|
||||
int b3 = ((byte) (index >> 15)) & 0xFF;
|
||||
int b4 = ((byte) (index >> 23)) & 0xFF;
|
||||
int x = offsetX + (((b3 + ((MathMan.unpair8x(b2)) << 8)) << 21) >> 21);
|
||||
int y = b1;
|
||||
int z = offsetZ + (((b4 + ((MathMan.unpair8y(b2)) << 8)) << 21) >> 21);
|
||||
array[i] = (T) BlockVector3.at(x, y, z);
|
||||
array[i] = (T) BlockVector3.at(x, b1, z);
|
||||
index++;
|
||||
}
|
||||
return array;
|
||||
@ -258,25 +257,16 @@ public class LocalBlockVectorSet implements Set<BlockVector3> {
|
||||
|
||||
@Override
|
||||
public boolean containsAll(Collection<?> c) {
|
||||
for (Object o : c) {
|
||||
if (!contains(o)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return c.stream().allMatch(this::contains);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(Collection<? extends BlockVector3> c) {
|
||||
boolean result = false;
|
||||
for (BlockVector3 v : c) {
|
||||
result |= add(v);
|
||||
}
|
||||
return result;
|
||||
return c.stream().map(this::add).reduce(false, (a, b) -> a || b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean retainAll(Collection<?> c) {
|
||||
public boolean retainAll(@NotNull Collection<?> c) {
|
||||
boolean result = false;
|
||||
int size = size();
|
||||
int index = -1;
|
||||
@ -300,11 +290,7 @@ public class LocalBlockVectorSet implements Set<BlockVector3> {
|
||||
|
||||
@Override
|
||||
public boolean removeAll(Collection<?> c) {
|
||||
boolean result = false;
|
||||
for (Object o : c) {
|
||||
result |= remove(o);
|
||||
}
|
||||
return result;
|
||||
return c.stream().map(this::remove).reduce(false, (a, b) -> a || b);
|
||||
}
|
||||
|
||||
public void forEach(BlockVectorSetVisitor visitor) {
|
||||
@ -318,9 +304,8 @@ public class LocalBlockVectorSet implements Set<BlockVector3> {
|
||||
int b3 = ((byte) (index >> 15)) & 0xFF;
|
||||
int b4 = ((byte) (index >> 23)) & 0xFF;
|
||||
int x = offsetX + (((b3 + ((MathMan.unpair8x(b2)) << 8)) << 21) >> 21);
|
||||
int y = b1;
|
||||
int z = offsetZ + (((b4 + ((MathMan.unpair8y(b2)) << 8)) << 21) >> 21);
|
||||
visitor.run(x, y, z, index);
|
||||
visitor.run(x, b1, z, index);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -41,11 +41,6 @@ public class FuzzyRegionSelector extends AbstractDelegateExtent implements Regio
|
||||
new MaskTraverser(mask).reset(getExtent());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BlockVector3> getVerticies() {
|
||||
return positions;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public World getWorld() {
|
||||
|
@ -63,11 +63,6 @@ public class PolyhedralRegionSelector implements RegionSelector, CUIRegion {
|
||||
region = new PolyhedralRegion(world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BlockVector3> getVerticies() {
|
||||
return new ArrayList<>(region.getVertices());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public World getWorld() {
|
||||
|
@ -41,15 +41,6 @@ public class CompoundTag extends Tag {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getRaw() {
|
||||
HashMap<String, Object> raw = new HashMap<>();
|
||||
for (Map.Entry<String, Tag> entry : value.entrySet()) {
|
||||
raw.put(entry.getKey(), entry.getValue().getRaw());
|
||||
}
|
||||
return raw;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this compound tag contains the given key.
|
||||
*
|
||||
|
@ -34,7 +34,7 @@ public class CompoundTagBuilder {
|
||||
/**
|
||||
* Create a new instance.
|
||||
*/
|
||||
public CompoundTagBuilder() {
|
||||
CompoundTagBuilder() {
|
||||
this.entries = new HashMap<>();
|
||||
}
|
||||
|
||||
@ -43,7 +43,7 @@ public class CompoundTagBuilder {
|
||||
*
|
||||
* @param value the value
|
||||
*/
|
||||
public CompoundTagBuilder(Map<String, Tag> value) {
|
||||
CompoundTagBuilder(Map<String, Tag> value) {
|
||||
checkNotNull(value);
|
||||
this.entries = value;
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ public final class ListTag extends Tag {
|
||||
|
||||
/**
|
||||
* Get the tag if it exists at the given index.
|
||||
*
|
||||
*
|
||||
* @param index the index
|
||||
* @return the tag or null
|
||||
*/
|
||||
@ -82,7 +82,7 @@ public final class ListTag extends Tag {
|
||||
if (index >= value.size()) {
|
||||
return null;
|
||||
}
|
||||
return value.get(index);
|
||||
return value.get(index);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -20,16 +20,12 @@
|
||||
package com.sk89q.jnbt;
|
||||
|
||||
import com.boydti.fawe.jnbt.NBTStreamer;
|
||||
import com.boydti.fawe.object.RunnableVal2;
|
||||
import com.boydti.fawe.util.StringMan;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -40,7 +36,7 @@ import java.util.function.Function;
|
||||
* This class reads <strong>NBT</strong>, or <strong>Named Binary Tag</strong>
|
||||
* streams, and produces an object graph of subclasses of the {@code Tag}
|
||||
* object.
|
||||
*
|
||||
*
|
||||
* <p>The NBT format was created by Markus Persson, and the specification may be
|
||||
* found at <a href="http://www.minecraft.net/docs/NBT.txt">
|
||||
* http://www.minecraft.net/docs/NBT.txt</a>.</p>
|
||||
@ -52,7 +48,7 @@ public final class NBTInputStream implements Closeable {
|
||||
/**
|
||||
* Creates a new {@code NBTInputStream}, which will source its data
|
||||
* from the specified input stream.
|
||||
*
|
||||
*
|
||||
* @param is the input stream
|
||||
* @throws IOException if an I/O error occurs
|
||||
*/
|
||||
@ -64,13 +60,9 @@ public final class NBTInputStream implements Closeable {
|
||||
this.is = dis;
|
||||
}
|
||||
|
||||
public DataInputStream getInputStream() {
|
||||
return is;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an NBT tag from the stream.
|
||||
*
|
||||
*
|
||||
* @return The tag that was read.
|
||||
* @throws IOException if an I/O error occurs.
|
||||
*/
|
||||
@ -78,19 +70,9 @@ public final class NBTInputStream implements Closeable {
|
||||
return readNamedTag(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an NBT map from the stream.
|
||||
*
|
||||
* @return The map that was read.
|
||||
* @throws IOException if an I/O error occurs.
|
||||
*/
|
||||
public NamedData readNamedData() throws IOException {
|
||||
return readNamedData(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an NBT from the stream.
|
||||
*
|
||||
*
|
||||
* @param depth the depth of this tag
|
||||
* @return The tag that was read.
|
||||
* @throws IOException if an I/O error occurs.
|
||||
@ -100,21 +82,11 @@ public final class NBTInputStream implements Closeable {
|
||||
return new NamedTag(readNamedTagName(type), readTagPayload(type, depth));
|
||||
}
|
||||
|
||||
private NamedData readNamedData(int depth) throws IOException {
|
||||
int type = is.readByte();
|
||||
return new NamedData(readNamedTagName(type), readDataPayload(type, depth));
|
||||
}
|
||||
|
||||
public Tag readTag() throws IOException {
|
||||
int type = is.readByte();
|
||||
return readTagPayload(type, 0);
|
||||
}
|
||||
|
||||
public Object readData() throws IOException {
|
||||
int type = is.readByte();
|
||||
return readDataPayload(type, 0);
|
||||
}
|
||||
|
||||
public void readNamedTagLazy(Function<String, BiConsumer> getReader) throws IOException {
|
||||
int type = is.readByte();
|
||||
String name = readNamedTagName(type);
|
||||
@ -522,13 +494,13 @@ public final class NBTInputStream implements Closeable {
|
||||
|
||||
/**
|
||||
* Reads the payload of a tag given the type.
|
||||
*
|
||||
*
|
||||
* @param type the type
|
||||
* @param depth the depth
|
||||
* @return the tag
|
||||
* @throws IOException if an I/O error occurs.
|
||||
*/
|
||||
public Tag readTagPayload(int type, int depth) throws IOException {
|
||||
private Tag readTagPayload(int type, int depth) throws IOException {
|
||||
switch (type) {
|
||||
case NBTConstants.TYPE_END:
|
||||
if (depth == 0) {
|
||||
@ -598,11 +570,11 @@ public final class NBTInputStream implements Closeable {
|
||||
}
|
||||
case NBTConstants.TYPE_LONG_ARRAY: {
|
||||
length = is.readInt();
|
||||
long[] data = new long[length];
|
||||
long[] longData = new long[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
data[i] = is.readLong();
|
||||
longData[i] = is.readLong();
|
||||
}
|
||||
return new LongArrayTag(data);
|
||||
return new LongArrayTag(longData);
|
||||
}
|
||||
default:
|
||||
throw new IOException("Invalid tag type: " + type + ".");
|
||||
|
@ -21,7 +21,6 @@ package com.sk89q.jnbt;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.boydti.fawe.object.io.LittleEndianOutputStream;
|
||||
import java.io.Closeable;
|
||||
import java.io.DataOutput;
|
||||
import java.io.DataOutputStream;
|
||||
@ -34,7 +33,7 @@ import java.util.Map;
|
||||
/**
|
||||
* This class writes <strong>NBT</strong>, or <strong>Named Binary Tag</strong>
|
||||
* {@code Tag} objects to an underlying {@code OutputStream}.
|
||||
*
|
||||
*
|
||||
* <p>The NBT format was created by Markus Persson, and the specification may be
|
||||
* found at <a href="http://www.minecraft.net/docs/NBT.txt">
|
||||
* http://www.minecraft.net/docs/NBT.txt</a>.</p>
|
||||
@ -49,7 +48,7 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da
|
||||
/**
|
||||
* Creates a new {@code NBTOutputStream}, which will write data to the
|
||||
* specified underlying output stream.
|
||||
*
|
||||
*
|
||||
* @param os
|
||||
* The output stream.
|
||||
* @throws IOException
|
||||
@ -67,15 +66,9 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da
|
||||
return os;
|
||||
}
|
||||
|
||||
public void setLittleEndian() {
|
||||
if (!(os instanceof LittleEndianOutputStream)) {
|
||||
this.os = new LittleEndianOutputStream((OutputStream) os);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a tag.
|
||||
*
|
||||
*
|
||||
* @param tag
|
||||
* The tag to write.
|
||||
* @throws IOException
|
||||
@ -86,10 +79,16 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da
|
||||
checkNotNull(tag);
|
||||
|
||||
int type = NBTUtils.getTypeCode(tag.getClass());
|
||||
writeNamedTagName(name, type);
|
||||
byte[] nameBytes = name.getBytes(NBTConstants.CHARSET);
|
||||
|
||||
os.writeByte(type);
|
||||
os.writeShort(nameBytes.length);
|
||||
os.write(nameBytes);
|
||||
|
||||
if (type == NBTConstants.TYPE_END) {
|
||||
throw new IOException("Named TAG_End not permitted.");
|
||||
}
|
||||
|
||||
writeTagPayload(tag);
|
||||
}
|
||||
|
||||
@ -149,16 +148,6 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da
|
||||
}
|
||||
}
|
||||
|
||||
public void writeNamedTag(String name, long[] data) throws IOException {
|
||||
checkNotNull(name);
|
||||
int type = NBTConstants.TYPE_LONG_ARRAY;
|
||||
writeNamedTagName(name, type);
|
||||
os.writeInt(data.length);
|
||||
for (long aData : data) {
|
||||
os.writeLong(aData);
|
||||
}
|
||||
}
|
||||
|
||||
public void writeNamedEmptyList(String name) throws IOException {
|
||||
writeNamedEmptyList(name, NBTConstants.TYPE_COMPOUND);
|
||||
}
|
||||
@ -171,6 +160,7 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da
|
||||
|
||||
public void writeNamedTagName(String name, int type) throws IOException {
|
||||
byte[] nameBytes = name.getBytes(NBTConstants.CHARSET);
|
||||
|
||||
os.writeByte(type);
|
||||
os.writeShort(nameBytes.length);
|
||||
os.write(nameBytes);
|
||||
@ -201,7 +191,7 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da
|
||||
|
||||
/**
|
||||
* Writes tag payload.
|
||||
*
|
||||
*
|
||||
* @param tag
|
||||
* The tag.
|
||||
* @throws IOException
|
||||
@ -256,7 +246,7 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da
|
||||
|
||||
/**
|
||||
* Writes a {@code TAG_Byte} tag.
|
||||
*
|
||||
*
|
||||
* @param tag
|
||||
* The tag.
|
||||
* @throws IOException
|
||||
@ -268,7 +258,7 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da
|
||||
|
||||
/**
|
||||
* Writes a {@code TAG_Byte_Array} tag.
|
||||
*
|
||||
*
|
||||
* @param tag
|
||||
* The tag.
|
||||
* @throws IOException
|
||||
@ -282,7 +272,7 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da
|
||||
|
||||
/**
|
||||
* Writes a {@code TAG_Compound} tag.
|
||||
*
|
||||
*
|
||||
* @param tag
|
||||
* The tag.
|
||||
* @throws IOException
|
||||
@ -292,12 +282,12 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da
|
||||
for (Map.Entry<String, Tag> entry : tag.getValue().entrySet()) {
|
||||
writeNamedTag(entry.getKey(), entry.getValue());
|
||||
}
|
||||
os.writeByte(NBTConstants.TYPE_END); // end tag - better way?
|
||||
os.writeByte((byte) 0); // end tag - better way?
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a {@code TAG_List} tag.
|
||||
*
|
||||
*
|
||||
* @param tag
|
||||
* The tag.
|
||||
* @throws IOException
|
||||
@ -324,7 +314,7 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da
|
||||
|
||||
/**
|
||||
* Writes a {@code TAG_String} tag.
|
||||
*
|
||||
*
|
||||
* @param tag
|
||||
* The tag.
|
||||
* @throws IOException
|
||||
@ -338,7 +328,7 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da
|
||||
|
||||
/**
|
||||
* Writes a {@code TAG_Double} tag.
|
||||
*
|
||||
*
|
||||
* @param tag
|
||||
* The tag.
|
||||
* @throws IOException
|
||||
@ -350,7 +340,7 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da
|
||||
|
||||
/**
|
||||
* Writes a {@code TAG_Float} tag.
|
||||
*
|
||||
*
|
||||
* @param tag
|
||||
* The tag.
|
||||
* @throws IOException
|
||||
@ -362,7 +352,7 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da
|
||||
|
||||
/**
|
||||
* Writes a {@code TAG_Long} tag.
|
||||
*
|
||||
*
|
||||
* @param tag
|
||||
* The tag.
|
||||
* @throws IOException
|
||||
@ -374,7 +364,7 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da
|
||||
|
||||
/**
|
||||
* Writes a {@code TAG_Int} tag.
|
||||
*
|
||||
*
|
||||
* @param tag
|
||||
* The tag.
|
||||
* @throws IOException
|
||||
@ -386,7 +376,7 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da
|
||||
|
||||
/**
|
||||
* Writes a {@code TAG_Short} tag.
|
||||
*
|
||||
*
|
||||
* @param tag
|
||||
* The tag.
|
||||
* @throws IOException
|
||||
@ -398,19 +388,19 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da
|
||||
|
||||
/**
|
||||
* Writes a {@code TAG_Empty} tag.
|
||||
*
|
||||
*
|
||||
* @param tag the tag
|
||||
*/
|
||||
private void writeEndTagPayload(EndTag tag) {
|
||||
/* empty */
|
||||
}
|
||||
|
||||
|
||||
private void writeIntArrayTagPayload(IntArrayTag tag) throws IOException {
|
||||
int[] data = tag.getValue();
|
||||
os.writeInt(data.length);
|
||||
for (int aData : data) {
|
||||
os.writeInt(aData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void writeLongArrayTagPayload(LongArrayTag tag) throws IOException {
|
||||
@ -505,4 +495,4 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da
|
||||
public void flush() throws IOException {
|
||||
if (os instanceof Flushable) ((Flushable) os).flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,12 +26,9 @@ public abstract class Tag {
|
||||
|
||||
/**
|
||||
* Gets the value of this tag.
|
||||
*
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public abstract Object getValue();
|
||||
|
||||
public Object getRaw() {
|
||||
return getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,21 +0,0 @@
|
||||
package com.sk89q.minecraft.util.commands;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface SuggestedRange {
|
||||
/**
|
||||
* The minimum value that the number can be at, inclusive.
|
||||
*
|
||||
* @return the minimum value
|
||||
*/
|
||||
double min() default Double.MIN_VALUE;
|
||||
|
||||
/**
|
||||
* The maximum value that the number can be at, inclusive.
|
||||
*
|
||||
* @return the maximum value
|
||||
*/
|
||||
double max() default Double.MAX_VALUE;
|
||||
}
|
@ -26,6 +26,7 @@ public final class ReflectionUtil {
|
||||
private ReflectionUtil() {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T getField(Object from, String name) {
|
||||
if (from instanceof Class)
|
||||
return getField((Class) from, null, name);
|
||||
@ -34,12 +35,12 @@ public final class ReflectionUtil {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T getField(Class checkClass, Object obj, String name) {
|
||||
public static <T> T getField(Class checkClass, Object from, String name) {
|
||||
do {
|
||||
try {
|
||||
Field field = checkClass.getDeclaredField(name);
|
||||
field.setAccessible(true);
|
||||
return (T) field.get(obj);
|
||||
return (T) field.get(from);
|
||||
} catch (NoSuchFieldException | IllegalAccessException ignored) {
|
||||
}
|
||||
} while (checkClass.getSuperclass() != Object.class && ((checkClass = checkClass.getSuperclass()) != null));
|
||||
|
@ -1,477 +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;
|
||||
|
||||
import com.boydti.fawe.object.schematic.Schematic;
|
||||
import com.sk89q.worldedit.command.ClipboardCommands;
|
||||
import com.sk89q.worldedit.command.FlattenedClipboardTransform;
|
||||
import com.sk89q.worldedit.command.SchematicCommands;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.BuiltInClipboardFormat;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
|
||||
import com.sk89q.worldedit.function.operation.ForwardExtentCopy;
|
||||
import com.sk89q.worldedit.function.operation.Operations;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.transform.AffineTransform;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.util.Countable;
|
||||
import com.sk89q.worldedit.util.Direction;
|
||||
import com.sk89q.worldedit.world.DataException;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
import com.sk89q.worldedit.world.registry.LegacyMapper;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* The clipboard remembers the state of a cuboid region.
|
||||
*
|
||||
* @deprecated This is slowly being replaced with {@link Clipboard}, which is
|
||||
* far more versatile. Transforms are supported using affine
|
||||
* transformations and full entity support is provided because
|
||||
* the clipboard properly implements {@link Extent}. However,
|
||||
* the new clipboard class is only available in WorldEdit 6.x and
|
||||
* beyond. We intend on keeping this deprecated class in WorldEdit
|
||||
* for an extended amount of time so there is no rush to
|
||||
* switch (but new features will not be supported). To copy between
|
||||
* a clipboard and a world (or between any two {@code Extent}s),
|
||||
* one can use {@link ForwardExtentCopy}. See
|
||||
* {@link ClipboardCommands} and {@link SchematicCommands} for
|
||||
* more information.
|
||||
*/
|
||||
@Deprecated
|
||||
public class CuboidClipboard {
|
||||
|
||||
/**
|
||||
* An enum of possible flip directions.
|
||||
*/
|
||||
public enum FlipDirection {
|
||||
NORTH_SOUTH(Direction.NORTH),
|
||||
WEST_EAST(Direction.WEST),
|
||||
UP_DOWN(Direction.UP),
|
||||
;
|
||||
private final Direction direction;
|
||||
FlipDirection(Direction direction) {
|
||||
this.direction = direction;
|
||||
}
|
||||
}
|
||||
|
||||
private BlockArrayClipboard clipboard;
|
||||
private AffineTransform transform;
|
||||
public BlockVector3 size;
|
||||
|
||||
/**
|
||||
* Constructs the clipboard.
|
||||
*
|
||||
* @param size the dimensions of the clipboard (should be at least 1 on every dimension)
|
||||
*/
|
||||
public CuboidClipboard(BlockVector3 size) {
|
||||
checkNotNull(size);
|
||||
this.size = size;
|
||||
this.clipboard = this.init(BlockVector3.ZERO, BlockVector3.ZERO);
|
||||
}
|
||||
|
||||
public CuboidClipboard(BlockArrayClipboard clipboard) {
|
||||
this.clipboard = clipboard;
|
||||
this.size = clipboard.getDimensions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs the clipboard.
|
||||
*
|
||||
* @param size the dimensions of the clipboard (should be at least 1 on every dimension)
|
||||
* @param origin the origin point where the copy was made, which must be the
|
||||
* {@link CuboidRegion#getMinimumPoint()} relative to the copy
|
||||
*/
|
||||
public CuboidClipboard(BlockVector3 size, BlockVector3 origin) {
|
||||
checkNotNull(size);
|
||||
checkNotNull(origin);
|
||||
this.size = size;
|
||||
this.clipboard = init(BlockVector3.ZERO, origin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs the clipboard.
|
||||
*
|
||||
* @param size the dimensions of the clipboard (should be at least 1 on every dimension)
|
||||
* @param origin the origin point where the copy was made, which must be the
|
||||
* {@link CuboidRegion#getMinimumPoint()} relative to the copy
|
||||
* @param offset the offset from the minimum point of the copy where the user was
|
||||
*/
|
||||
public CuboidClipboard(BlockVector3 size, BlockVector3 origin, BlockVector3 offset) {
|
||||
checkNotNull(size);
|
||||
checkNotNull(origin);
|
||||
checkNotNull(offset);
|
||||
this.size = size;
|
||||
this.clipboard = this.init(offset, origin);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------- */
|
||||
|
||||
private BlockArrayClipboard init(BlockVector3 offset, BlockVector3 min) {
|
||||
BlockVector3 origin = min.subtract(offset);
|
||||
CuboidRegion region = new CuboidRegion(min, min.add(size).subtract(BlockVector3.ONE));
|
||||
BlockArrayClipboard clipboard = new BlockArrayClipboard(region);
|
||||
clipboard.setOrigin(origin);
|
||||
return clipboard;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------- */
|
||||
|
||||
public BaseBlock getBlock(BlockVector3 position) {
|
||||
return getBlock(position.getBlockX(), position.getBlockY(), position.getBlockZ());
|
||||
}
|
||||
|
||||
|
||||
public BaseBlock getBlock(int x, int y, int z) {
|
||||
// return adapt(clipboard.IMP.getBlock(x, y, z));
|
||||
return clipboard.IMP.getBlock(x, y, z);
|
||||
}
|
||||
|
||||
public BaseBlock getLazyBlock(BlockVector3 position) {
|
||||
return getBlock(position);
|
||||
}
|
||||
|
||||
public void setBlock(BlockVector3 location, BaseBlock block) {
|
||||
setBlock(location.getBlockX(), location.getBlockY(), location.getBlockZ(), block);
|
||||
}
|
||||
|
||||
public boolean setBlock(int x, int y, int z, BaseBlock block) {
|
||||
return setBlock(x, y, z, block);
|
||||
}
|
||||
|
||||
public boolean setBlock(int x, int y, int z, BlockState block) {
|
||||
return clipboard.IMP.setBlock(x, y, z, block);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the width (X-direction) of the clipboard.
|
||||
*
|
||||
* @return width
|
||||
*/
|
||||
public int getWidth() {
|
||||
return size.getBlockX();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the length (Z-direction) of the clipboard.
|
||||
*
|
||||
* @return length
|
||||
*/
|
||||
public int getLength() {
|
||||
return size.getBlockZ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the height (Y-direction) of the clipboard.
|
||||
*
|
||||
* @return height
|
||||
*/
|
||||
public int getHeight() {
|
||||
return size.getBlockY();
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotate the clipboard in 2D. It can only rotate by angles divisible by 90.
|
||||
*
|
||||
* @param angle in degrees
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public void rotate2D(int angle) {
|
||||
AffineTransform newTransform = new AffineTransform().rotateY(-angle);
|
||||
this.transform = transform == null ? newTransform : newTransform.combine(transform);
|
||||
}
|
||||
|
||||
/**
|
||||
* Flip the clipboard.
|
||||
*
|
||||
* @param dir direction to flip
|
||||
*/
|
||||
public void flip(FlipDirection dir) {
|
||||
flip(dir, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Flip the clipboard.
|
||||
*
|
||||
* @param dir direction to flip
|
||||
* @param aroundPlayer flip the offset around the player
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public void flip(FlipDirection dir, boolean aroundPlayer) {
|
||||
checkNotNull(dir);
|
||||
Direction direction = dir.direction;
|
||||
AffineTransform newTransform = new AffineTransform().scale(direction.toVector().abs().multiply(-2).add(1, 1, 1));
|
||||
this.transform = transform == null ? newTransform : newTransform.combine(transform);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies blocks to the clipboard.
|
||||
*
|
||||
* @param editSession the EditSession from which to take the blocks
|
||||
*/
|
||||
public void copy(EditSession editSession) {
|
||||
for (int x = 0; x < size.getBlockX(); ++x) {
|
||||
for (int y = 0; y < size.getBlockY(); ++y) {
|
||||
for (int z = 0; z < size.getBlockZ(); ++z) {
|
||||
setBlock(x, y, z, editSession.getBlock(BlockVector3.at(x, y, z).add(getOrigin())));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies blocks to the clipboard.
|
||||
*
|
||||
* @param editSession The EditSession from which to take the blocks
|
||||
* @param region A region that further constrains which blocks to take.
|
||||
*/
|
||||
public void copy(EditSession editSession, Region region) {
|
||||
for (int x = 0; x < size.getBlockX(); ++x) {
|
||||
for (int y = 0; y < size.getBlockY(); ++y) {
|
||||
for (int z = 0; z < size.getBlockZ(); ++z) {
|
||||
final BlockVector3 pt = BlockVector3.at(x, y, z).add(getOrigin());
|
||||
if (region.contains(pt)) {
|
||||
setBlock(x, y, z, editSession.getBlock(pt));
|
||||
} else {
|
||||
setBlock(x, y, z, (BlockState)null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Paste the clipboard at the given location using the given {@code EditSession}.
|
||||
* <p>
|
||||
* <p>This method blocks the server/game until the entire clipboard is
|
||||
* pasted. In the future, {@link ForwardExtentCopy} will be recommended,
|
||||
* which, if combined with the proposed operation scheduler framework,
|
||||
* will not freeze the game/server.</p>
|
||||
*
|
||||
* @param editSession the EditSession to which blocks are to be copied to
|
||||
* @param newOrigin the new origin point (must correspond to the minimum point of the cuboid)
|
||||
* @param noAir true to not copy air blocks in the source
|
||||
* @throws MaxChangedBlocksException thrown if too many blocks were changed
|
||||
*/
|
||||
public void paste(EditSession editSession, BlockVector3 newOrigin, boolean noAir) throws MaxChangedBlocksException {
|
||||
paste(editSession, newOrigin, noAir, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Paste the clipboard at the given location using the given {@code EditSession}.
|
||||
* <p>
|
||||
* <p>This method blocks the server/game until the entire clipboard is
|
||||
* pasted. In the future, {@link ForwardExtentCopy} will be recommended,
|
||||
* which, if combined with the proposed operation scheduler framework,
|
||||
* will not freeze the game/server.</p>
|
||||
*
|
||||
* @param editSession the EditSession to which blocks are to be copied to
|
||||
* @param newOrigin the new origin point (must correspond to the minimum point of the cuboid)
|
||||
* @param noAir true to not copy air blocks in the source
|
||||
* @param entities true to copy entities
|
||||
* @throws MaxChangedBlocksException thrown if too many blocks were changed
|
||||
*/
|
||||
public void paste(EditSession editSession, BlockVector3 newOrigin, boolean noAir, boolean entities) throws MaxChangedBlocksException {
|
||||
new Schematic(clipboard).paste(editSession, newOrigin, false, !noAir, entities, transform);
|
||||
editSession.flushQueue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Paste the clipboard at the given location using the given {@code EditSession}.
|
||||
* <p>
|
||||
* <p>This method blocks the server/game until the entire clipboard is
|
||||
* pasted. In the future, {@link ForwardExtentCopy} will be recommended,
|
||||
* which, if combined with the proposed operation scheduler framework,
|
||||
* will not freeze the game/server.</p>
|
||||
*
|
||||
* @param editSession the EditSession to which blocks are to be copied to
|
||||
* @param newOrigin the new origin point (must correspond to the minimum point of the cuboid)
|
||||
* @param noAir true to not copy air blocks in the source
|
||||
* @throws MaxChangedBlocksException thrown if too many blocks were changed
|
||||
*/
|
||||
public void place(EditSession editSession, BlockVector3 newOrigin, boolean noAir) throws MaxChangedBlocksException {
|
||||
paste(editSession, newOrigin, noAir, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the block at the given position.
|
||||
* <p>
|
||||
* <p>If the position is out of bounds, air will be returned.</p>
|
||||
*
|
||||
* @param position the point, relative to the origin of the copy (0, 0, 0) and not to the actual copy origin
|
||||
* @return air, if this block was outside the (non-cuboid) selection while copying
|
||||
* @throws ArrayIndexOutOfBoundsException if the position is outside the bounds of the CuboidClipboard
|
||||
* @deprecated use {@link #getBlock(Vector)} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public BaseBlock getPoint(BlockVector3 position) throws ArrayIndexOutOfBoundsException {
|
||||
final BaseBlock block = getBlock(position);
|
||||
if (block == null) {
|
||||
return BlockTypes.AIR.getDefaultState().toBaseBlock();
|
||||
}
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the origin point, which corresponds to where the copy was
|
||||
* originally copied from. The origin is the lowest possible X, Y, and
|
||||
* Z components of the cuboid region that was copied.
|
||||
*
|
||||
* @return the origin
|
||||
*/
|
||||
public BlockVector3 getOrigin() {
|
||||
return clipboard.getMinimumPoint();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the origin point, which corresponds to where the copy was
|
||||
* originally copied from. The origin is the lowest possible X, Y, and
|
||||
* Z components of the cuboid region that was copied.
|
||||
*
|
||||
* @param origin the origin to set
|
||||
*/
|
||||
public void setOrigin(BlockVector3 origin) {
|
||||
checkNotNull(origin);
|
||||
setOriginAndOffset(getOffset(), origin);
|
||||
}
|
||||
|
||||
public void setOriginAndOffset(BlockVector3 offset, BlockVector3 min) {
|
||||
BlockVector3 origin = min.subtract(offset);
|
||||
CuboidRegion region = new CuboidRegion(min, min.add(size).subtract(BlockVector3.ONE));
|
||||
clipboard.setRegion(region);
|
||||
clipboard.setOrigin(origin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the offset of the player to the clipboard's minimum point
|
||||
* (minimum X, Y, Z coordinates).
|
||||
* <p>
|
||||
* <p>The offset is inverse (multiplied by -1).</p>
|
||||
*
|
||||
* @return the offset the offset
|
||||
*/
|
||||
public BlockVector3 getOffset() {
|
||||
BlockVector3 min = clipboard.getMinimumPoint();
|
||||
BlockVector3 origin = clipboard.getOrigin();
|
||||
BlockVector3 offset = min.subtract(origin);
|
||||
return offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the offset of the player to the clipboard's minimum point
|
||||
* (minimum X, Y, Z coordinates).
|
||||
* <p>
|
||||
* <p>The offset is inverse (multiplied by -1).</p>
|
||||
*
|
||||
* @param offset the new offset
|
||||
*/
|
||||
public void setOffset(BlockVector3 offset) {
|
||||
checkNotNull(offset);
|
||||
setOriginAndOffset(offset, getOrigin());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the dimensions of the clipboard.
|
||||
*
|
||||
* @return the dimensions, where (1, 1, 1) is 1 wide, 1 across, 1 deep
|
||||
*/
|
||||
public BlockVector3 getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the clipboard data to a .schematic-format file.
|
||||
*
|
||||
* @param path the path to the file to save
|
||||
* @throws IOException thrown on I/O error
|
||||
* @throws DataException thrown on error writing the data for other reasons
|
||||
* @deprecated use {@link ClipboardFormat#SCHEMATIC}
|
||||
*/
|
||||
@Deprecated
|
||||
public void saveSchematic(File path) throws IOException, DataException {
|
||||
checkNotNull(path);
|
||||
if (transform != null && !transform.isIdentity()) {
|
||||
final FlattenedClipboardTransform result = FlattenedClipboardTransform.transform(clipboard, transform);
|
||||
BlockArrayClipboard target = new BlockArrayClipboard(result.getTransformedRegion(), UUID.randomUUID());
|
||||
target.setOrigin(clipboard.getOrigin());
|
||||
Operations.completeLegacy(result.copyTo(target));
|
||||
this.clipboard = target;
|
||||
}
|
||||
new Schematic(clipboard).save(path, BuiltInClipboardFormat.SPONGE_SCHEMATIC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a .schematic file into a clipboard.
|
||||
*
|
||||
* @param path the path to the file to load
|
||||
* @return a clipboard
|
||||
* @throws IOException thrown on I/O error
|
||||
* @throws DataException thrown on error writing the data for other reasons
|
||||
* @deprecated use {@link ClipboardFormat#SCHEMATIC}
|
||||
*/
|
||||
@Deprecated
|
||||
public static CuboidClipboard loadSchematic(File path) throws DataException, IOException {
|
||||
checkNotNull(path);
|
||||
return new CuboidClipboard((BlockVector3) BuiltInClipboardFormat.MCEDIT_SCHEMATIC.load(path).getClipboard());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the block distribution inside a clipboard.
|
||||
*
|
||||
* @return a block distribution
|
||||
*/
|
||||
public List<Countable<Integer>> getBlockDistribution() {
|
||||
List<Countable<Integer>> distribution = new ArrayList<>();
|
||||
List<Countable<BlockState>> distr = clipboard.getBlockDistributionWithData(clipboard.getRegion());
|
||||
for (Countable<BlockState> item : distr) {
|
||||
BlockStateHolder state = item.getID();
|
||||
int[] legacyId = LegacyMapper.getInstance().getLegacyFromBlock(state.toImmutableState());
|
||||
if (legacyId[0] != 0) distribution.add(new Countable<>(legacyId[0], item.getAmount()));
|
||||
}
|
||||
return distribution;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the block distribution inside a clipboard with data values.
|
||||
*
|
||||
* @return a block distribution
|
||||
*/
|
||||
public List<Countable<BaseBlock>> getBlockDistributionWithData() {
|
||||
List<Countable<BaseBlock>> distribution = new ArrayList<>();
|
||||
List<Countable<BlockState>> distr = clipboard.getBlockDistributionWithData(clipboard.getRegion());
|
||||
for (Countable<BlockState> item : distr) {
|
||||
distribution.add(new Countable<>(item.getID().toBaseBlock(), item.getAmount()));
|
||||
}
|
||||
return distribution;
|
||||
}
|
||||
}
|
@ -21,14 +21,11 @@ package com.sk89q.worldedit.blocks;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.sk89q.worldedit.registry.state.Property;
|
||||
import com.sk89q.worldedit.world.block.BlockCategories;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Block-related utility methods.
|
||||
|
@ -23,10 +23,12 @@ import com.boydti.fawe.config.BBC;
|
||||
import com.boydti.fawe.config.Commands;
|
||||
import com.boydti.fawe.object.visitor.Fast2DIterator;
|
||||
import com.boydti.fawe.util.chat.Message;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
||||
import com.sk89q.minecraft.util.commands.Logging;
|
||||
import static com.sk89q.minecraft.util.commands.Logging.LogMode.REGION;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
@ -62,8 +64,6 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static com.sk89q.minecraft.util.commands.Logging.LogMode.REGION;
|
||||
|
||||
/**
|
||||
* Implements biome-related commands such as "/biomelist".
|
||||
*/
|
||||
@ -84,10 +84,10 @@ public class BiomeCommands extends MethodCommands {
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"biomelist", "biomels"},
|
||||
usage = "[page]",
|
||||
desc = "Gets all biomes available.",
|
||||
max = 1
|
||||
aliases = { "biomelist", "biomels" },
|
||||
usage = "[page]",
|
||||
desc = "Gets all biomes available.",
|
||||
max = 1
|
||||
)
|
||||
@CommandPermissions("worldedit.biome.list")
|
||||
public void biomeList(Player player, CommandContext args) throws WorldEditException {
|
||||
@ -127,15 +127,15 @@ public class BiomeCommands extends MethodCommands {
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"biomeinfo"},
|
||||
flags = "pt",
|
||||
desc = "Get the biome of the targeted block.",
|
||||
help =
|
||||
"Get the biome of the block.\n" +
|
||||
"By default use all the blocks contained in your selection.\n" +
|
||||
"-t use the block you are looking at.\n" +
|
||||
"-p use the block you are currently in",
|
||||
max = 0
|
||||
aliases = { "biomeinfo" },
|
||||
flags = "pt",
|
||||
desc = "Get the biome of the targeted block.",
|
||||
help =
|
||||
"Get the biome of the block.\n" +
|
||||
"By default use all the blocks contained in your selection.\n" +
|
||||
"-t use the block you are looking at.\n" +
|
||||
"-p use the block you are currently in",
|
||||
max = 0
|
||||
)
|
||||
@CommandPermissions("worldedit.biome.info")
|
||||
public void biomeInfo(Player player, LocalSession session, final EditSession editSession, CommandContext args) throws WorldEditException {
|
||||
@ -192,24 +192,33 @@ public class BiomeCommands extends MethodCommands {
|
||||
Collections.sort(distribution);
|
||||
for (Countable<BiomeType> c : distribution) {
|
||||
BiomeData data = biomeRegistry.getData(c.getID());
|
||||
String str = String.format("%-7s (%.3f%%) %s #%d",
|
||||
String.valueOf(c.getAmount()),
|
||||
c.getAmount() / (double) size * 100,
|
||||
data == null ? "Unknown" : data.getName(),
|
||||
c.getID().getInternalId());
|
||||
String str;
|
||||
if (data == null) {
|
||||
str = String.format("%-7s (%.3f%%) %s #%d",
|
||||
String.valueOf(c.getAmount()),
|
||||
c.getAmount() / (double) size * 100,
|
||||
"Unknown",
|
||||
c.getID().getInternalId());
|
||||
} else {
|
||||
str = String.format("%-7s (%.3f%%) %s #%d",
|
||||
String.valueOf(c.getAmount()),
|
||||
c.getAmount() / (double) size * 100,
|
||||
data.getName(),
|
||||
c.getID().getInternalId());
|
||||
}
|
||||
player.print(str);
|
||||
}
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = {"/setbiome"},
|
||||
aliases = { "/setbiome" },
|
||||
usage = "<biome>",
|
||||
flags = "p",
|
||||
desc = "Sets the biome of the player's current block or region.",
|
||||
help =
|
||||
"Set the biome of the region.\n" +
|
||||
"By default use all the blocks contained in your selection.\n" +
|
||||
"-p use the block you are currently in"
|
||||
"By default use all the blocks contained in your selection.\n" +
|
||||
"-p use the block you are currently in"
|
||||
)
|
||||
@Logging(REGION)
|
||||
@CommandPermissions("worldedit.biome.set")
|
||||
@ -220,7 +229,7 @@ public class BiomeCommands extends MethodCommands {
|
||||
Mask2D mask2d = mask != null ? mask.toMask2D() : null;
|
||||
|
||||
if (atPosition) {
|
||||
region = new CuboidRegion(player.getLocation().toBlockPoint(), player.getLocation().toBlockPoint());
|
||||
region = new CuboidRegion(player.getLocation().toVector().toBlockPoint(), player.getLocation().toVector().toBlockPoint());
|
||||
} else {
|
||||
region = session.getSelection(world);
|
||||
}
|
||||
@ -236,4 +245,5 @@ public class BiomeCommands extends MethodCommands {
|
||||
if (!player.hasPermission("fawe.tips"))
|
||||
BBC.TIP_BIOME_PATTERN.or(BBC.TIP_BIOME_MASK).send(player);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -183,6 +183,4 @@ public class SelectionCommand extends SimpleCommand<Operation> {
|
||||
return locals.get(Actor.class).hasPermission(permission);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -19,8 +19,6 @@
|
||||
|
||||
package com.sk89q.worldedit.command.composition;
|
||||
|
||||
import com.boydti.fawe.config.BBC;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
|
@ -1,15 +1,32 @@
|
||||
/*
|
||||
* 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.command.tool;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.LocalConfiguration;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.extension.platform.Platform;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
@ -30,11 +47,11 @@ public class AreaPickaxe implements BlockTool {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked) {
|
||||
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, com.sk89q.worldedit.util.Location clicked) {
|
||||
int ox = clicked.getBlockX();
|
||||
int oy = clicked.getBlockY();
|
||||
int oz = clicked.getBlockZ();
|
||||
BlockType initialType = clicked.getExtent().getBlock(clicked.toBlockPoint()).getBlockType();
|
||||
BlockType initialType = clicked.getExtent().getBlock(clicked.toVector().toBlockPoint()).getBlockType();
|
||||
|
||||
if (initialType.getMaterial().isAir()) {
|
||||
return true;
|
||||
@ -45,23 +62,29 @@ public class AreaPickaxe implements BlockTool {
|
||||
}
|
||||
|
||||
try (EditSession editSession = session.createEditSession(player)) {
|
||||
editSession.getSurvivalExtent().setToolUse(config.superPickaxeManyDrop);
|
||||
|
||||
try {
|
||||
editSession.getSurvivalExtent().setToolUse(config.superPickaxeManyDrop);
|
||||
for (int x = ox - range; x <= ox + range; ++x) {
|
||||
for (int z = oz - range; z <= oz + range; ++z) {
|
||||
for (int y = oy + range; y >= oy - range; --y) {
|
||||
if (initialType.equals(editSession.getLazyBlock(x, y, z))) {
|
||||
BlockVector3 pos = BlockVector3.at(x, y, z);
|
||||
if (editSession.getLazyBlock(pos).getBlockType() != initialType) {
|
||||
continue;
|
||||
}
|
||||
editSession.setBlock(x, y, z, BlockTypes.AIR.getDefaultState());
|
||||
editSession.setBlock(pos, BlockTypes.AIR.getDefaultState());
|
||||
}
|
||||
}
|
||||
}
|
||||
editSession.flushQueue();
|
||||
} catch (MaxChangedBlocksException e) {
|
||||
player.printError("Max blocks change limit reached.");
|
||||
} finally {
|
||||
session.remember(editSession);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -56,8 +56,7 @@ public class BlockDataCyler implements DoubleActionBlockTool {
|
||||
|
||||
World world = (World) clicked.getExtent();
|
||||
|
||||
// BlockStateHolder block = world.getBlock(clicked);
|
||||
BlockVector3 blockPoint = clicked.toBlockPoint();
|
||||
BlockVector3 blockPoint = clicked.toVector().toBlockPoint();
|
||||
BlockState block = world.getBlock(blockPoint);
|
||||
|
||||
if (!config.allowedDataCycleBlocks.isEmpty()
|
||||
@ -68,42 +67,43 @@ public class BlockDataCyler implements DoubleActionBlockTool {
|
||||
}
|
||||
|
||||
if (block.getStates().keySet().isEmpty()) {
|
||||
BBC.BLOCK_CYCLER_CANNOT_CYCLE.send(player);
|
||||
BBC.BLOCK_CYCLER_CANNOT_CYCLE.send(player);
|
||||
} else {
|
||||
Property<?> currentProperty = selectedProperties.get(player.getUniqueId());
|
||||
Property<?> currentProperty = selectedProperties.get(player.getUniqueId());
|
||||
|
||||
if (currentProperty == null || (forward && block.getState(currentProperty) == null)) {
|
||||
currentProperty = block.getStates().keySet().stream().findFirst().get();
|
||||
selectedProperties.put(player.getUniqueId(), currentProperty);
|
||||
}
|
||||
if (currentProperty == null || (forward && block.getState(currentProperty) == null)) {
|
||||
currentProperty = block.getStates().keySet().stream().findFirst().get();
|
||||
selectedProperties.put(player.getUniqueId(), currentProperty);
|
||||
}
|
||||
|
||||
if (forward) {
|
||||
block.getState(currentProperty);
|
||||
int index = currentProperty.getValues().indexOf(block.getState(currentProperty));
|
||||
index = (index + 1) % currentProperty.getValues().size();
|
||||
@SuppressWarnings("unchecked")
|
||||
Property<Object> objProp = (Property<Object>) currentProperty;
|
||||
BlockState newBlock = block.with(objProp, currentProperty.getValues().get(index));
|
||||
if (forward) {
|
||||
block.getState(currentProperty);
|
||||
int index = currentProperty.getValues().indexOf(block.getState(currentProperty));
|
||||
index = (index + 1) % currentProperty.getValues().size();
|
||||
@SuppressWarnings("unchecked")
|
||||
Property<Object> objProp = (Property<Object>) currentProperty;
|
||||
BlockState newBlock = block.with(objProp, currentProperty.getValues().get(index));
|
||||
|
||||
try {
|
||||
EditSession editSession = session.createEditSession(player);
|
||||
try {
|
||||
editSession.setBlock(blockPoint, newBlock);
|
||||
player.print("Value of " + currentProperty.getName() + " is now " + currentProperty.getValues().get(index).toString());
|
||||
} catch (MaxChangedBlocksException e) {
|
||||
BBC.BLOCK_CYCLER_LIMIT.send(player);
|
||||
} finally {
|
||||
session.remember(editSession);
|
||||
}
|
||||
}catch (Exception e) {}
|
||||
} else {
|
||||
List<Property<?>> properties = Lists.newArrayList(block.getStates().keySet());
|
||||
int index = properties.indexOf(currentProperty);
|
||||
index = (index + 1) % properties.size();
|
||||
currentProperty = properties.get(index);
|
||||
selectedProperties.put(player.getUniqueId(), currentProperty);
|
||||
player.print("Now cycling " + currentProperty.getName());
|
||||
}
|
||||
try (EditSession editSession = session.createEditSession(player)) {
|
||||
editSession.disableBuffering();
|
||||
|
||||
try {
|
||||
editSession.setBlock(blockPoint, newBlock);
|
||||
player.print("Value of " + currentProperty.getName() + " is now " + currentProperty.getValues().get(index).toString());
|
||||
} catch (MaxChangedBlocksException e) {
|
||||
BBC.BLOCK_CYCLER_LIMIT.send(player);
|
||||
} finally {
|
||||
session.remember(editSession);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
List<Property<?>> properties = Lists.newArrayList(block.getStates().keySet());
|
||||
int index = properties.indexOf(currentProperty);
|
||||
index = (index + 1) % properties.size();
|
||||
currentProperty = properties.get(index);
|
||||
selectedProperties.put(player.getUniqueId(), currentProperty);
|
||||
player.print("Now cycling " + currentProperty.getName());
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -19,7 +19,6 @@
|
||||
|
||||
package com.sk89q.worldedit.command.tool;
|
||||
|
||||
import com.boydti.fawe.config.BBC;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.LocalConfiguration;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
@ -32,10 +31,9 @@ import com.sk89q.worldedit.function.pattern.BlockPattern;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
|
||||
/**
|
||||
* A mode that replaces one block.
|
||||
*/
|
||||
public class BlockReplacer implements DoubleActionBlockTool {
|
||||
|
||||
@ -75,12 +73,11 @@ public class BlockReplacer implements DoubleActionBlockTool {
|
||||
@Override
|
||||
public boolean actSecondary(Platform server, LocalConfiguration config, Player player, LocalSession session, com.sk89q.worldedit.util.Location clicked) {
|
||||
EditSession editSession = session.createEditSession(player);
|
||||
BlockStateHolder targetBlock = (editSession).getBlock(clicked.toBlockPoint());
|
||||
BlockType type = targetBlock.getBlockType();
|
||||
BlockState targetBlock = editSession.getBlock(clicked.toVector().toBlockPoint());
|
||||
|
||||
if (type != null) {
|
||||
this.pattern = targetBlock;
|
||||
player.print("Replacer tool switched to: " + type.getName());
|
||||
if (targetBlock != null) {
|
||||
pattern = new BlockPattern(targetBlock);
|
||||
player.print("Replacer tool switched to: " + targetBlock.getBlockType().getName());
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -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.command.tool;
|
||||
|
||||
import com.boydti.fawe.Fawe;
|
||||
@ -16,15 +35,21 @@ import com.boydti.fawe.object.brush.visualization.VisualMode;
|
||||
import com.boydti.fawe.object.extent.ResettableExtent;
|
||||
import com.boydti.fawe.object.mask.MaskedTargetBlock;
|
||||
import com.boydti.fawe.object.pattern.PatternTraverser;
|
||||
import com.boydti.fawe.util.*;
|
||||
import com.boydti.fawe.util.BrushCache;
|
||||
import com.boydti.fawe.util.EditSessionBuilder;
|
||||
import com.boydti.fawe.util.MaskTraverser;
|
||||
import com.boydti.fawe.util.StringMan;
|
||||
import com.boydti.fawe.util.TaskManager;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.worldedit.*;
|
||||
|
||||
import com.sk89q.worldedit.internal.expression.Expression;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.LocalConfiguration;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.blocks.BaseItem;
|
||||
import com.sk89q.worldedit.command.tool.brush.Brush;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
@ -36,10 +61,14 @@ import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.mask.MaskIntersection;
|
||||
import com.sk89q.worldedit.function.mask.SolidBlockMask;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.internal.expression.Expression;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
import com.sk89q.worldedit.session.request.Request;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Type;
|
||||
@ -47,11 +76,10 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Builds a shape at the place being looked at.
|
||||
*/
|
||||
public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool, ResettableTool, Serializable {
|
||||
// TODO:
|
||||
// Serialize methods
|
||||
@ -79,7 +107,13 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool
|
||||
|
||||
private transient BaseItem holder;
|
||||
|
||||
/**
|
||||
* Construct the tool.
|
||||
*
|
||||
* @param permission the permission to check before use is allowed
|
||||
*/
|
||||
public BrushTool(String permission) {
|
||||
checkNotNull(permission);
|
||||
getContext().addPermission(permission);
|
||||
}
|
||||
|
||||
@ -285,10 +319,9 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool
|
||||
/**
|
||||
* Set the brush.
|
||||
*
|
||||
* @param brush tbe brush
|
||||
* @param brush tbe brush
|
||||
* @param permission the permission
|
||||
*/
|
||||
@Deprecated
|
||||
public void setBrush(Brush brush, String permission) {
|
||||
setBrush(brush, permission, null);
|
||||
update();
|
||||
@ -388,7 +421,6 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool
|
||||
pitch = 23 - (pitch / 4);
|
||||
d += (int) (Math.sin(Math.toRadians(pitch)) * 50);
|
||||
final Vector3 vector = loc.getDirection().withY(0).normalize().multiply(d).add(loc.getX(), loc.getY(), loc.getZ());
|
||||
// vector = vector.add(loc.getX(), loc.getY(), loc.getZ());
|
||||
return offset(vector, loc).toBlockPoint();
|
||||
}
|
||||
case TARGET_POINT_HEIGHT: {
|
||||
|
@ -51,7 +51,7 @@ public class DistanceWand extends BrushTool implements DoubleActionTraceTool {
|
||||
if (target == null) return true;
|
||||
|
||||
RegionSelector selector = session.getRegionSelector(player.getWorld());
|
||||
BlockVector3 blockPoint = target.toBlockPoint();
|
||||
BlockVector3 blockPoint = target.toVector().toBlockPoint();
|
||||
if (selector.selectPrimary(blockPoint, ActorSelectorLimits.forActor(player))) {
|
||||
selector.explainPrimarySelection(player, session, blockPoint);
|
||||
}
|
||||
@ -69,7 +69,7 @@ public class DistanceWand extends BrushTool implements DoubleActionTraceTool {
|
||||
if (target == null) return true;
|
||||
|
||||
RegionSelector selector = session.getRegionSelector(player.getWorld());
|
||||
BlockVector3 blockPoint = target.toBlockPoint();
|
||||
BlockVector3 blockPoint = target.toVector().toBlockPoint();
|
||||
if (selector.selectSecondary(blockPoint, ActorSelectorLimits.forActor(player))) {
|
||||
selector.explainSecondarySelection(player, session, blockPoint);
|
||||
}
|
||||
|
@ -19,9 +19,9 @@
|
||||
|
||||
package com.sk89q.worldedit.command.tool;
|
||||
|
||||
import com.boydti.fawe.object.collection.BlockVectorSet;
|
||||
import com.boydti.fawe.config.BBC;
|
||||
import com.boydti.fawe.object.collection.LocalBlockVectorSet;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.LocalConfiguration;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
@ -38,9 +38,7 @@ import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@ -70,7 +68,7 @@ public class FloatingTreeRemover implements BlockTool {
|
||||
|
||||
@Override
|
||||
public boolean actPrimary(Platform server, LocalConfiguration config,
|
||||
Player player, LocalSession session, Location clicked) {
|
||||
Player player, LocalSession session, Location clicked) {
|
||||
|
||||
final World world = (World) clicked.getExtent();
|
||||
final BlockState state = world.getBlock(clicked.toVector().toBlockPoint());
|
||||
@ -161,4 +159,4 @@ public class FloatingTreeRemover implements BlockTool {
|
||||
|
||||
return visited;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,6 @@
|
||||
|
||||
package com.sk89q.worldedit.command.tool;
|
||||
|
||||
import com.boydti.fawe.object.mask.IdMask;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.LocalConfiguration;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
@ -28,7 +27,6 @@ import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.extension.platform.Platform;
|
||||
import com.sk89q.worldedit.function.block.BlockReplace;
|
||||
import com.sk89q.worldedit.function.mask.BlockTypeMask;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.operation.Operations;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
@ -39,7 +37,6 @@ import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@ -64,7 +61,7 @@ public class FloodFillTool implements BlockTool {
|
||||
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked) {
|
||||
World world = (World) clicked.getExtent();
|
||||
|
||||
BlockVector3 origin = clicked.toBlockPoint();
|
||||
BlockVector3 origin = clicked.toVector().toBlockPoint();
|
||||
BlockType initialType = world.getBlock(origin).getBlockType();
|
||||
|
||||
if (initialType.getMaterial().isAir()) {
|
||||
@ -88,6 +85,7 @@ public class FloodFillTool implements BlockTool {
|
||||
session.remember(editSession);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -120,5 +118,4 @@ public class FloodFillTool implements BlockTool {
|
||||
origin, size, initialType, visited);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -61,25 +61,27 @@ public class LongRangeBuildTool extends BrushTool implements DoubleActionTraceTo
|
||||
if (applied.getBlockType().getMaterial().isAir()) {
|
||||
eS.setBlock(blockPoint, secondary);
|
||||
} else {
|
||||
eS.setBlock(pos.subtract(pos.getDirection()).toBlockPoint(), secondary);
|
||||
eS.setBlock(pos.toVector().subtract(pos.getDirection()).toBlockPoint(), secondary);
|
||||
}
|
||||
return true;
|
||||
} catch (MaxChangedBlocksException e) {
|
||||
// one block? eat it
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session) {
|
||||
Location pos = getTargetFace(player);
|
||||
if (pos == null) return false;
|
||||
try (EditSession eS = session.createEditSession(player)) {
|
||||
BlockVector3 blockPoint = pos.toBlockPoint();
|
||||
BlockVector3 blockPoint = pos.toVector().toBlockPoint();
|
||||
BaseBlock applied = primary.apply(blockPoint);
|
||||
if (applied.getBlockType().getMaterial().isAir()) {
|
||||
eS.setBlock(blockPoint, primary);
|
||||
} else {
|
||||
eS.setBlock(pos.subtract(pos.getDirection()).toBlockPoint(), primary);
|
||||
eS.setBlock(pos.toVector().subtract(pos.getDirection()).toBlockPoint(), primary);
|
||||
}
|
||||
return true;
|
||||
} catch (MaxChangedBlocksException e) {
|
||||
@ -99,4 +101,4 @@ public class LongRangeBuildTool extends BrushTool implements DoubleActionTraceTo
|
||||
return target;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -45,10 +45,10 @@ public class QueryTool implements BlockTool {
|
||||
|
||||
World world = (World) clicked.getExtent();
|
||||
EditSession editSession = session.createEditSession(player);
|
||||
BlockVector3 blockPoint = clicked.toBlockPoint();
|
||||
BlockVector3 blockPoint = clicked.toVector().toBlockPoint();
|
||||
BaseBlock block = editSession.getFullBlock(blockPoint);
|
||||
|
||||
player.print("\u00A79@" + blockPoint + ": " + "\u00A7e"
|
||||
player.print("\u00A79@" + clicked.toVector() + ": " + "\u00A7e"
|
||||
+ block.getBlockType().getName() + "\u00A77" + " ("
|
||||
+ block.toString() + ") "
|
||||
+ "\u00A7f"
|
||||
|
@ -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.command.tool;
|
||||
|
||||
import com.boydti.fawe.object.mask.IdMask;
|
||||
@ -22,6 +41,7 @@ import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
* an initial block and of the same type.
|
||||
*/
|
||||
public class RecursivePickaxe implements BlockTool {
|
||||
|
||||
private double range;
|
||||
|
||||
public RecursivePickaxe(double range) {
|
||||
@ -39,7 +59,7 @@ public class RecursivePickaxe implements BlockTool {
|
||||
final BlockVector3 pos = clicked.toBlockPoint();
|
||||
|
||||
EditSession editSession = session.createEditSession(player);
|
||||
BlockVector3 origin = clicked.toBlockPoint();
|
||||
BlockVector3 origin = clicked.toVector().toBlockPoint();
|
||||
BlockType initialType = world.getBlock(origin).getBlockType();
|
||||
|
||||
BlockStateHolder block = editSession.getBlock(pos);
|
||||
|
@ -21,11 +21,9 @@ package com.sk89q.worldedit.command.tool.brush;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.mask.Masks;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
public class GravityBrush implements Brush {
|
||||
@ -37,24 +35,21 @@ public class GravityBrush implements Brush {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double sizeDouble) throws MaxChangedBlocksException {
|
||||
Mask mask = editSession.getMask();
|
||||
if (mask == Masks.alwaysTrue() || mask == Masks.alwaysTrue2D()) {
|
||||
mask = null;
|
||||
}
|
||||
int size = (int) sizeDouble;
|
||||
int endY = position.getBlockY() + size;
|
||||
int startPerformY = Math.max(0, position.getBlockY() - size);
|
||||
int startCheckY = fullHeight ? 0 : startPerformY;
|
||||
for (int x = position.getBlockX() + size; x > position.getBlockX() - size; --x) {
|
||||
for (int z = position.getBlockZ() + size; z > position.getBlockZ() - size; --z) {
|
||||
int freeSpot = startCheckY;
|
||||
for (int y = startCheckY; y <= endY; y++) {
|
||||
BlockStateHolder block = editSession.getLazyBlock(x, y, z);
|
||||
public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException {
|
||||
double endY = position.getBlockY() + size;
|
||||
double startPerformY = Math.max(0, position.getBlockY() - size);
|
||||
double startCheckY = fullHeight ? 0 : startPerformY;
|
||||
for (double x = position.getBlockX() + size; x > position.getBlockX() - size; --x) {
|
||||
for (double z = position.getBlockZ() + size; z > position.getBlockZ() - size; --z) {
|
||||
double freeSpot = startCheckY;
|
||||
for (double y = startCheckY; y <= endY; ++y) {
|
||||
final BlockVector3 pt = BlockVector3.at(x, y, z);
|
||||
final BlockState block = editSession.getLazyBlock(pt);
|
||||
if (!block.getBlockType().getMaterial().isAir()) {
|
||||
if (y != freeSpot) {
|
||||
editSession.setBlock(x, y, z, BlockTypes.AIR.getDefaultState());
|
||||
editSession.setBlock(x, freeSpot, z, block);
|
||||
editSession.setBlock(pt, BlockTypes.AIR.getDefaultState());
|
||||
final BlockVector3 pt2 = BlockVector3.at(x, freeSpot, z);
|
||||
editSession.setBlock(pt2, block);
|
||||
}
|
||||
freeSpot = y + 1;
|
||||
}
|
||||
@ -63,6 +58,4 @@ public class GravityBrush implements Brush {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ public class HollowCylinderBrush implements Brush {
|
||||
@Override
|
||||
public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException {
|
||||
if (pattern == null) {
|
||||
pattern = (BlockTypes.COBBLESTONE.getDefaultState());
|
||||
pattern = new BlockPattern(BlockTypes.COBBLESTONE.getDefaultState());
|
||||
}
|
||||
editSession.makeCylinder(position, pattern, size, size, height, false);
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ public class HollowSphereBrush implements Brush {
|
||||
@Override
|
||||
public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException {
|
||||
if (pattern == null) {
|
||||
pattern = (BlockTypes.COBBLESTONE.getDefaultState());
|
||||
pattern = new BlockPattern(BlockTypes.COBBLESTONE.getDefaultState());
|
||||
}
|
||||
editSession.makeSphere(position, pattern, size, size, size, false);
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ public class SmoothBrush implements Brush {
|
||||
Vector3 posDouble = position.toVector3();
|
||||
Location min = new Location(editSession.getWorld(), posDouble.subtract(size, size, size));
|
||||
BlockVector3 max = posDouble.add(size, size + 10, size).toBlockPoint();
|
||||
Region region = new CuboidRegion(editSession.getWorld(), min.toBlockPoint(), max);
|
||||
Region region = new CuboidRegion(editSession.getWorld(), min.toVector().toBlockPoint(), max);
|
||||
HeightMap heightMap = new HeightMap(editSession, region, mask);
|
||||
HeightMapFilter filter = new HeightMapFilter(new GaussianKernel(5, 1.0));
|
||||
heightMap.applyFilter(filter, iterations);
|
||||
|
@ -31,7 +31,7 @@ public class SphereBrush implements Brush {
|
||||
@Override
|
||||
public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException {
|
||||
if (pattern == null) {
|
||||
pattern = (BlockTypes.COBBLESTONE.getDefaultState());
|
||||
pattern = new BlockPattern(BlockTypes.COBBLESTONE.getDefaultState());
|
||||
}
|
||||
editSession.makeSphere(position, pattern, size, size, size, true);
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
package com.sk89q.worldedit.extension.factory.parser;
|
||||
|
||||
import com.boydti.fawe.Fawe;
|
||||
import com.boydti.fawe.config.BBC;
|
||||
import com.boydti.fawe.jnbt.JSON2NBT;
|
||||
import com.boydti.fawe.jnbt.NBTException;
|
||||
@ -229,7 +230,13 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
|
||||
throw new NoMatchException("Does not match a valid block type: '" + input + "'");
|
||||
}
|
||||
}
|
||||
nbt = state.getNbtData();
|
||||
if (state != null) {
|
||||
nbt = state.getNbtData();
|
||||
} else {
|
||||
Fawe.debug("State was null.");
|
||||
Fawe.debug("Input was: " + input);
|
||||
Fawe.debug("typestring was: " + typeString);
|
||||
}
|
||||
|
||||
if (stateString != null) {
|
||||
state = BlockState.get(state.getBlockType(), "[" + stateString + "]", state);
|
||||
|
@ -22,8 +22,8 @@ package com.sk89q.worldedit.extent;
|
||||
import com.boydti.fawe.jnbt.anvil.generator.GenBase;
|
||||
import com.boydti.fawe.jnbt.anvil.generator.Resource;
|
||||
import com.boydti.fawe.object.extent.LightingExtent;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
@ -41,10 +41,9 @@ import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.registry.BundledBlockData;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A base class for {@link Extent}s that merely passes extents onto another.
|
||||
|
@ -19,9 +19,6 @@
|
||||
|
||||
package com.sk89q.worldedit.extent;
|
||||
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
@ -40,11 +37,10 @@ import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Stores changes to a {@link ChangeSet}.
|
||||
*/
|
||||
|
@ -19,12 +19,15 @@
|
||||
|
||||
package com.sk89q.worldedit.extent;
|
||||
|
||||
import com.boydti.fawe.jnbt.anvil.generator.*;
|
||||
import com.boydti.fawe.object.clipboard.WorldCopyClipboard;
|
||||
import com.boydti.fawe.jnbt.anvil.generator.CavesGen;
|
||||
import com.boydti.fawe.jnbt.anvil.generator.GenBase;
|
||||
import com.boydti.fawe.jnbt.anvil.generator.OreGen;
|
||||
import com.boydti.fawe.jnbt.anvil.generator.Resource;
|
||||
import com.boydti.fawe.jnbt.anvil.generator.SchemGen;
|
||||
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.operation.Operation;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
@ -173,13 +176,13 @@ public interface Extent extends InputExtent, OutputExtent {
|
||||
for (int d = 0; d <= clearance; d++) {
|
||||
int y1 = y + d;
|
||||
block = getLazyBlock(x, y1, z);
|
||||
if (!block.getBlockType().getMaterial().isMovementBlocker() != state) {
|
||||
if (block.getBlockType().getMaterial().isMovementBlocker() == state) {
|
||||
return ((y1 - offset) << 4) - (15 - (state ? PropertyGroup.LEVEL.get(block) : data1));
|
||||
}
|
||||
data1 = PropertyGroup.LEVEL.get(block);
|
||||
int y2 = y - d;
|
||||
block = getLazyBlock(x, y2, z);
|
||||
if (!block.getBlockType().getMaterial().isMovementBlocker() != state) {
|
||||
if (block.getBlockType().getMaterial().isMovementBlocker() == state) {
|
||||
return ((y2 + offset) << 4) - (15 - (state ? PropertyGroup.LEVEL.get(block) : data2));
|
||||
}
|
||||
data2 = PropertyGroup.LEVEL.get(block);
|
||||
@ -188,16 +191,15 @@ public interface Extent extends InputExtent, OutputExtent {
|
||||
if (clearanceAbove < clearanceBelow) {
|
||||
for (int layer = y - clearance - 1; layer >= minY; layer--) {
|
||||
block = getLazyBlock(x, layer, z);
|
||||
if (!block.getBlockType().getMaterial().isMovementBlocker() != state) {
|
||||
int data = (state ? PropertyGroup.LEVEL.get(block) : data1);
|
||||
return ((layer + offset) << 4) + 0;
|
||||
if (block.getBlockType().getMaterial().isMovementBlocker() == state) {
|
||||
return layer + offset << 4;
|
||||
}
|
||||
data1 = PropertyGroup.LEVEL.get(block);
|
||||
}
|
||||
} else {
|
||||
for (int layer = y + clearance + 1; layer <= maxY; layer++) {
|
||||
block = getLazyBlock(x, layer, z);
|
||||
if (!block.getBlockType().getMaterial().isMovementBlocker() != state) {
|
||||
if (block.getBlockType().getMaterial().isMovementBlocker() == state) {
|
||||
return ((layer - offset) << 4) - (15 - (state ? PropertyGroup.LEVEL.get(block) : data2));
|
||||
}
|
||||
data2 = PropertyGroup.LEVEL.get(block);
|
||||
@ -243,8 +245,7 @@ public interface Extent extends InputExtent, OutputExtent {
|
||||
}
|
||||
}
|
||||
}
|
||||
int result = state ? failedMin : failedMax;
|
||||
return result;
|
||||
return state ? failedMin : failedMax;
|
||||
}
|
||||
|
||||
default int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY, int failedMin, int failedMax, boolean ignoreAir) {
|
||||
@ -258,21 +259,21 @@ public interface Extent extends InputExtent, OutputExtent {
|
||||
for (int d = 0; d <= clearance; d++) {
|
||||
int y1 = y + d;
|
||||
block = getLazyBlock(x, y1, z);
|
||||
if (!block.getMaterial().isMovementBlocker() != state && block.getBlockType() != BlockTypes.__RESERVED__) return y1 - offset;
|
||||
if (block.getMaterial().isMovementBlocker() == state && block.getBlockType() != BlockTypes.__RESERVED__) return y1 - offset;
|
||||
int y2 = y - d;
|
||||
block = getLazyBlock(x, y2, z);
|
||||
if (!block.getMaterial().isMovementBlocker() != state && block.getBlockType() != BlockTypes.__RESERVED__) return y2 + offset;
|
||||
if (block.getMaterial().isMovementBlocker() == state && block.getBlockType() != BlockTypes.__RESERVED__) return y2 + offset;
|
||||
}
|
||||
if (clearanceAbove != clearanceBelow) {
|
||||
if (clearanceAbove < clearanceBelow) {
|
||||
for (int layer = y - clearance - 1; layer >= minY; layer--) {
|
||||
block = getLazyBlock(x, layer, z);
|
||||
if (!block.getMaterial().isMovementBlocker() != state && block.getBlockType() != BlockTypes.__RESERVED__) return layer + offset;
|
||||
if (block.getMaterial().isMovementBlocker() == state && block.getBlockType() != BlockTypes.__RESERVED__) return layer + offset;
|
||||
}
|
||||
} else {
|
||||
for (int layer = y + clearance + 1; layer <= maxY; layer++) {
|
||||
block = getLazyBlock(x, layer, z);
|
||||
if (!block.getMaterial().isMovementBlocker() != state && block.getBlockType() != BlockTypes.__RESERVED__) return layer - offset;
|
||||
if (block.getMaterial().isMovementBlocker() == state && block.getBlockType() != BlockTypes.__RESERVED__) return layer - offset;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -294,7 +295,7 @@ public interface Extent extends InputExtent, OutputExtent {
|
||||
}
|
||||
}
|
||||
|
||||
default public void addSchems(Region region, Mask mask, List<ClipboardHolder> clipboards, int rarity, boolean rotate) throws WorldEditException {
|
||||
default void addSchems(Region region, Mask mask, List<ClipboardHolder> clipboards, int rarity, boolean rotate) throws WorldEditException {
|
||||
spawnResource(region, new SchemGen(mask, this, clipboards, rotate), rarity, 1);
|
||||
}
|
||||
|
||||
@ -318,11 +319,11 @@ public interface Extent extends InputExtent, OutputExtent {
|
||||
return (pt.containedWithin(min, max));
|
||||
}
|
||||
|
||||
default public void addOre(Region region, Mask mask, Pattern material, int size, int frequency, int rarity, int minY, int maxY) throws WorldEditException {
|
||||
default void addOre(Region region, Mask mask, Pattern material, int size, int frequency, int rarity, int minY, int maxY) throws WorldEditException {
|
||||
spawnResource(region, new OreGen(this, mask, material, size, minY, maxY), rarity, frequency);
|
||||
}
|
||||
|
||||
default public void addOres(Region region, Mask mask) throws WorldEditException {
|
||||
default void addOres(Region region, Mask mask) throws WorldEditException {
|
||||
addOre(region, mask, BlockTypes.DIRT.getDefaultState(), 33, 10, 100, 0, 255);
|
||||
addOre(region, mask, BlockTypes.GRAVEL.getDefaultState(), 33, 8, 100, 0, 255);
|
||||
addOre(region, mask, BlockTypes.ANDESITE.getDefaultState(), 33, 10, 100, 0, 79);
|
||||
@ -398,19 +399,6 @@ public interface Extent extends InputExtent, OutputExtent {
|
||||
return distribution;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lazily copy a region
|
||||
*
|
||||
* @param region
|
||||
* @return
|
||||
*/
|
||||
default BlockArrayClipboard lazyCopy(Region region) {
|
||||
WorldCopyClipboard faweClipboard = new WorldCopyClipboard(this, region);
|
||||
BlockArrayClipboard weClipboard = new BlockArrayClipboard(region, faweClipboard);
|
||||
weClipboard.setOrigin(region.getMinimumPoint());
|
||||
return weClipboard;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
default Operation commit() {
|
||||
|
@ -20,14 +20,11 @@
|
||||
package com.sk89q.worldedit.extent;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
|
||||
/**
|
||||
|
@ -58,9 +58,9 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
|
||||
|
||||
private Region region;
|
||||
private BlockVector3 origin;
|
||||
private BlockStateHolder[][][] blocks;
|
||||
public FaweClipboard IMP;
|
||||
private BlockVector3 size;
|
||||
private BlockStateHolder[][][] blocks;
|
||||
private final List<ClipboardEntity> entities = new ArrayList<>();
|
||||
|
||||
public BlockArrayClipboard(Region region) {
|
||||
|
@ -20,7 +20,6 @@
|
||||
package com.sk89q.worldedit.extent.clipboard;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
|
||||
@ -59,15 +58,4 @@ public interface Clipboard extends Extent {
|
||||
*/
|
||||
void setOrigin(BlockVector3 origin);
|
||||
|
||||
/**
|
||||
* Returns true if the clipboard has biome data. This can be checked since {@link Extent#getBiome(BlockVector2)}
|
||||
* strongly suggests returning {@link com.sk89q.worldedit.world.biome.BiomeTypes.OCEAN} instead of {@code null}
|
||||
* if biomes aren't present. However, it might not be desired to set areas to ocean if the clipboard is defaulting
|
||||
* to ocean, instead of having biomes explicitly set.
|
||||
*
|
||||
* @return true if the clipboard has biome data set
|
||||
*/
|
||||
default boolean hasBiomes() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,21 @@
|
||||
|
||||
package com.sk89q.worldedit.extent.clipboard.io;
|
||||
|
||||
import com.boydti.fawe.config.Settings;
|
||||
import com.boydti.fawe.object.RunnableVal;
|
||||
import com.boydti.fawe.object.clipboard.URIClipboardHolder;
|
||||
import com.boydti.fawe.object.io.PGZIPOutputStream;
|
||||
import com.boydti.fawe.object.schematic.Schematic;
|
||||
import com.boydti.fawe.util.MainUtil;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import com.google.gson.Gson;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
@ -29,23 +44,6 @@ import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
|
||||
import com.boydti.fawe.config.Settings;
|
||||
import com.boydti.fawe.object.RunnableVal;
|
||||
import com.boydti.fawe.object.clipboard.URIClipboardHolder;
|
||||
import com.boydti.fawe.object.io.PGZIPOutputStream;
|
||||
import com.boydti.fawe.object.schematic.Schematic;
|
||||
import com.boydti.fawe.util.MainUtil;
|
||||
import com.google.gson.Gson;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.session.ClipboardHolder;
|
||||
|
||||
/**
|
||||
* A collection of supported clipboard formats.
|
||||
*/
|
||||
@ -105,16 +103,15 @@ public interface ClipboardFormat {
|
||||
* @return The file extensions this format might be known by
|
||||
*/
|
||||
Set<String> getFileExtensions();
|
||||
|
||||
|
||||
/**
|
||||
* Set the player's clipboard
|
||||
* @param player
|
||||
* @param uri
|
||||
* @param in
|
||||
* @return the held clipboard
|
||||
* @throws IOException
|
||||
*/
|
||||
default ClipboardHolder hold(Player player, URI uri, InputStream in) throws IOException {
|
||||
default void hold(Player player, URI uri, InputStream in) throws IOException {
|
||||
checkNotNull(player);
|
||||
checkNotNull(uri);
|
||||
checkNotNull(in);
|
||||
@ -128,9 +125,8 @@ public interface ClipboardFormat {
|
||||
clipboard = reader.read(player.getUniqueId());
|
||||
URIClipboardHolder holder = new URIClipboardHolder(uri, clipboard);
|
||||
session.setClipboard(holder);
|
||||
return holder;
|
||||
}
|
||||
|
||||
|
||||
default Schematic load(File file) throws IOException {
|
||||
return load(new FileInputStream(file));
|
||||
}
|
||||
@ -138,8 +134,8 @@ public interface ClipboardFormat {
|
||||
default Schematic load(InputStream stream) throws IOException {
|
||||
return new Schematic(getReader(stream).read());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
default URL uploadPublic(final Clipboard clipboard, String category, String user) {
|
||||
// summary
|
||||
// blocks
|
||||
@ -158,7 +154,7 @@ public interface ClipboardFormat {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
default URL uploadAnonymous(final Clipboard clipboard) {
|
||||
return MainUtil.upload(null, null, getPrimaryFileExtension(), new RunnableVal<OutputStream>() {
|
||||
@Override
|
||||
@ -167,7 +163,7 @@ public interface ClipboardFormat {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
default void write(OutputStream value, Clipboard clipboard) {
|
||||
try {
|
||||
try (PGZIPOutputStream gzip = new PGZIPOutputStream(value)) {
|
||||
|
@ -284,7 +284,6 @@ public class ClipboardFormats {
|
||||
byte[] buffer = new byte[8192];
|
||||
while ((entry = zip.getNextEntry()) != null) {
|
||||
String filename = entry.getName();
|
||||
String extension = filename.substring(filename.lastIndexOf('.') + 1, filename.length());
|
||||
ClipboardFormat format = findByExtension(filename);
|
||||
if (format != null) {
|
||||
FastByteArrayOutputStream out = new FastByteArrayOutputStream();
|
||||
|
@ -43,4 +43,4 @@ public interface ClipboardReader extends Closeable {
|
||||
default Clipboard read(UUID uuid) throws IOException {
|
||||
return read();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,6 @@ import com.sk89q.jnbt.ShortTag;
|
||||
import com.sk89q.jnbt.StringTag;
|
||||
import com.sk89q.jnbt.Tag;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
|
@ -22,21 +22,14 @@ package com.sk89q.worldedit.extent.clipboard.io;
|
||||
import com.boydti.fawe.Fawe;
|
||||
import com.boydti.fawe.jnbt.CorruptSchematicStreamer;
|
||||
import com.boydti.fawe.jnbt.SchematicStreamer;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import com.sk89q.jnbt.NBTInputStream;
|
||||
import com.sk89q.jnbt.Tag;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Reads schematic files based that are compatible with MCEdit and other editors.
|
||||
@ -75,36 +68,6 @@ public class SchematicReader implements ClipboardReader {
|
||||
}
|
||||
}
|
||||
|
||||
private static <T extends Tag> T requireTag(Map<String, Tag> items, String key, Class<T> expected) throws IOException {
|
||||
if (!items.containsKey(key)) {
|
||||
throw new IOException("Schematic file is missing a \"" + key + "\" tag");
|
||||
}
|
||||
|
||||
Tag tag = items.get(key);
|
||||
if (!expected.isInstance(tag)) {
|
||||
throw new IOException(key + " tag is not of tag type " + expected.getName());
|
||||
}
|
||||
|
||||
return expected.cast(tag);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static <T extends Tag> T getTag(CompoundTag tag, Class<T> expected, String key) {
|
||||
Map<String, Tag> items = tag.getValue();
|
||||
|
||||
if (!items.containsKey(key)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Tag test = items.get(key);
|
||||
if (!expected.isInstance(test)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return expected.cast(test);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
|
@ -110,7 +110,7 @@ public class SpongeSchematicReader extends NBTSchematicReader {
|
||||
public Clipboard read(UUID uuid) throws IOException {
|
||||
return readVersion1(uuid);
|
||||
}
|
||||
|
||||
|
||||
private int width, height, length;
|
||||
private int offsetX, offsetY, offsetZ;
|
||||
private char[] palette;
|
||||
@ -132,7 +132,7 @@ public class SpongeSchematicReader extends NBTSchematicReader {
|
||||
return fc = new MemoryOptimizedClipboard(size, 1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Clipboard readVersion1(UUID uuid) throws IOException {
|
||||
width = height = length = offsetX = offsetY = offsetZ = Integer.MIN_VALUE;
|
||||
|
||||
@ -249,7 +249,6 @@ public class SpongeSchematicReader extends NBTSchematicReader {
|
||||
return clipboard;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
inputStream.close();
|
||||
|
@ -21,6 +21,8 @@ package com.sk89q.worldedit.extent.clipboard.io;
|
||||
|
||||
import com.boydti.fawe.object.clipboard.FaweClipboard;
|
||||
import com.boydti.fawe.util.IOUtil;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.jnbt.DoubleTag;
|
||||
import com.sk89q.jnbt.FloatTag;
|
||||
@ -33,12 +35,12 @@ import com.sk89q.jnbt.Tag;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
@ -55,9 +57,6 @@ import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Vector;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Writes schematic files using the Sponge schematic format.
|
||||
@ -82,8 +81,13 @@ public class SpongeSchematicWriter implements ClipboardWriter {
|
||||
write1(clipboard);
|
||||
}
|
||||
|
||||
public void write1(Clipboard clipboard) throws IOException {
|
||||
// metadata
|
||||
/**
|
||||
* Writes a version 1 schematic file.
|
||||
*
|
||||
* @param clipboard The clipboard
|
||||
* @throws IOException If an error occurs
|
||||
*/
|
||||
private void write1(Clipboard clipboard) throws IOException {
|
||||
Region region = clipboard.getRegion();
|
||||
BlockVector3 origin = clipboard.getOrigin();
|
||||
BlockVector3 min = region.getMinimumPoint();
|
||||
@ -91,6 +95,7 @@ public class SpongeSchematicWriter implements ClipboardWriter {
|
||||
int width = region.getWidth();
|
||||
int height = region.getHeight();
|
||||
int length = region.getLength();
|
||||
|
||||
if (width > MAX_SIZE) {
|
||||
throw new IllegalArgumentException("Width of region too large for a .schematic");
|
||||
}
|
||||
@ -100,13 +105,15 @@ public class SpongeSchematicWriter implements ClipboardWriter {
|
||||
if (length > MAX_SIZE) {
|
||||
throw new IllegalArgumentException("Length of region too large for a .schematic");
|
||||
}
|
||||
// output
|
||||
|
||||
final DataOutput rawStream = outputStream.getOutputStream();
|
||||
outputStream.writeLazyCompoundTag("Schematic", out -> {
|
||||
out.writeNamedTag("Version", 1);
|
||||
out.writeNamedTag("Width", (short) width);
|
||||
out.writeNamedTag("Height", (short) height);
|
||||
out.writeNamedTag("Length", (short) length);
|
||||
|
||||
// The Sponge format Offset refers to the 'min' points location in the world. That's our 'Origin'
|
||||
out.writeNamedTag("Offset", new int[]{
|
||||
min.getBlockX(),
|
||||
min.getBlockY(),
|
||||
@ -124,7 +131,6 @@ public class SpongeSchematicWriter implements ClipboardWriter {
|
||||
|
||||
ByteArrayOutputStream tilesCompressed = new ByteArrayOutputStream();
|
||||
NBTOutputStream tilesOut = new NBTOutputStream(new LZ4BlockOutputStream(tilesCompressed));
|
||||
int[] numTiles = {0};
|
||||
|
||||
List<Integer> paletteList = new ArrayList<>();
|
||||
char[] palette = new char[BlockTypes.states.length];
|
||||
@ -132,27 +138,34 @@ public class SpongeSchematicWriter implements ClipboardWriter {
|
||||
int[] paletteMax = {0};
|
||||
|
||||
|
||||
int[] numTiles = {0};
|
||||
FaweClipboard.BlockReader reader = new FaweClipboard.BlockReader() {
|
||||
@Override
|
||||
public <B extends BlockStateHolder<B>> void run(int x, int y, int z, B block) {
|
||||
try {
|
||||
boolean hasNbt = block instanceof BaseBlock && ((BaseBlock)block).hasNbtData();
|
||||
boolean hasNbt = block instanceof BaseBlock && block.hasNbtData();
|
||||
if (hasNbt) {
|
||||
BaseBlock localBlock = (BaseBlock)block;
|
||||
Map<String, Tag> values = localBlock.getNbtData().getValue();
|
||||
values.remove("id"); // Remove 'id' if it exists. We want 'Id'
|
||||
// Positions are kept in NBT, we don't want that.
|
||||
values.remove("x");
|
||||
values.remove("y");
|
||||
values.remove("z");
|
||||
if (!values.containsKey("Id")) values.put("Id", new StringTag(localBlock.getNbtId()));
|
||||
values.put("Pos", new IntArrayTag(new int[]{
|
||||
x,
|
||||
y,
|
||||
z
|
||||
}));
|
||||
numTiles[0]++;
|
||||
tilesOut.writeTagPayload(localBlock.getNbtData());
|
||||
if (block.getNbtData() != null) {
|
||||
BaseBlock localBlock = (BaseBlock) block;
|
||||
Map<String, Tag> values = localBlock.getNbtData().getValue();
|
||||
|
||||
values.remove("id"); // Remove 'id' if it exists. We want 'Id'
|
||||
|
||||
// Positions are kept in NBT, we don't want that.
|
||||
values.remove("x");
|
||||
values.remove("y");
|
||||
values.remove("z");
|
||||
if (!values.containsKey("Id")) {
|
||||
values.put("Id", new StringTag(block.getNbtId()));
|
||||
}
|
||||
values.put("Pos", new IntArrayTag(new int[]{
|
||||
x,
|
||||
y,
|
||||
z
|
||||
}));
|
||||
numTiles[0]++;
|
||||
tilesOut.writeTagPayload(localBlock.getNbtData());
|
||||
}
|
||||
}
|
||||
int ordinal = block.getOrdinal();
|
||||
char value = palette[ordinal];
|
||||
@ -185,9 +198,9 @@ public class SpongeSchematicWriter implements ClipboardWriter {
|
||||
// close
|
||||
tilesOut.close();
|
||||
blocksOut.close();
|
||||
// palette max
|
||||
|
||||
out.writeNamedTag("PaletteMax", paletteMax[0]);
|
||||
// palette
|
||||
|
||||
out.writeLazyCompoundTag("Palette", out12 -> {
|
||||
for (int i = 0; i < paletteList.size(); i++) {
|
||||
int stateOrdinal = paletteList.get(i);
|
||||
@ -195,13 +208,13 @@ public class SpongeSchematicWriter implements ClipboardWriter {
|
||||
out12.writeNamedTag(state.getAsString(), i);
|
||||
}
|
||||
});
|
||||
// Block data
|
||||
|
||||
out.writeNamedTagName("BlockData", NBTConstants.TYPE_BYTE_ARRAY);
|
||||
rawStream.writeInt(blocksOut.size());
|
||||
try (LZ4BlockInputStream in = new LZ4BlockInputStream(new ByteArrayInputStream(blocksCompressed.toByteArray()))) {
|
||||
IOUtil.copy(in, rawStream);
|
||||
}
|
||||
// tiles
|
||||
|
||||
if (numTiles[0] != 0) {
|
||||
out.writeNamedTagName("TileEntities", NBTConstants.TYPE_LIST);
|
||||
rawStream.write(NBTConstants.TYPE_COMPOUND);
|
||||
@ -213,14 +226,12 @@ public class SpongeSchematicWriter implements ClipboardWriter {
|
||||
out.writeNamedEmptyList("TileEntities");
|
||||
}
|
||||
|
||||
|
||||
// Entities
|
||||
List<Tag> entities = new ArrayList<Tag>();
|
||||
List<Tag> entities = new ArrayList<>();
|
||||
for (Entity entity : clipboard.getEntities()) {
|
||||
BaseEntity state = entity.getState();
|
||||
|
||||
if (state != null) {
|
||||
Map<String, Tag> values = new HashMap<String, Tag>();
|
||||
Map<String, Tag> values = new HashMap<>();
|
||||
|
||||
// Put NBT provided data
|
||||
CompoundTag rawTag = state.getNbtData();
|
||||
@ -246,7 +257,7 @@ public class SpongeSchematicWriter implements ClipboardWriter {
|
||||
}
|
||||
|
||||
private static Tag writeVector(Vector3 vector, String name) {
|
||||
List<DoubleTag> list = new ArrayList<DoubleTag>();
|
||||
List<DoubleTag> list = new ArrayList<>();
|
||||
list.add(new DoubleTag(vector.getX()));
|
||||
list.add(new DoubleTag(vector.getY()));
|
||||
list.add(new DoubleTag(vector.getZ()));
|
||||
@ -254,7 +265,7 @@ public class SpongeSchematicWriter implements ClipboardWriter {
|
||||
}
|
||||
|
||||
private static Tag writeRotation(Location location, String name) {
|
||||
List<FloatTag> list = new ArrayList<FloatTag>();
|
||||
List<FloatTag> list = new ArrayList<>();
|
||||
list.add(new FloatTag(location.getYaw()));
|
||||
list.add(new FloatTag(location.getPitch()));
|
||||
return new ListTag(FloatTag.class, list);
|
||||
@ -264,4 +275,4 @@ public class SpongeSchematicWriter implements ClipboardWriter {
|
||||
public void close() throws IOException {
|
||||
outputStream.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,557 +0,0 @@
|
||||
package com.sk89q.worldedit.extent.clipboard.io;
|
||||
|
||||
import com.boydti.fawe.Fawe;
|
||||
import com.boydti.fawe.object.collection.SoftHashMap;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
public class WavefrontReader implements ClipboardReader {
|
||||
private final InputStream inputStream;
|
||||
private final File root;
|
||||
|
||||
private final Map<String, BufferedImage> textures = new SoftHashMap<>();
|
||||
private final Map<String, Map<String, Material>> materialFiles = new HashMap<>();
|
||||
private final Map<String, Material> materials = new HashMap<>();
|
||||
|
||||
public WavefrontReader(File file) throws FileNotFoundException {
|
||||
this.inputStream = new BufferedInputStream(new FileInputStream(file));
|
||||
File parent = file.getParentFile();
|
||||
this.root = parent == null ? new File(".") : parent;
|
||||
}
|
||||
|
||||
private final static double parse(String s) {
|
||||
int len = s.length();
|
||||
int index;
|
||||
int numIndex = 1;
|
||||
|
||||
double neg;
|
||||
|
||||
if (s.charAt(0) == '-') {
|
||||
neg = -1;
|
||||
index = 1;
|
||||
} else {
|
||||
index = 0;
|
||||
neg = 1;
|
||||
}
|
||||
double val = 0;
|
||||
outer:
|
||||
for (; index < len; index++) {
|
||||
char c = s.charAt(index);
|
||||
switch (c) {
|
||||
case ' ': break outer;
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
val = val * 10 + (c - 48);
|
||||
continue;
|
||||
case '.': {
|
||||
double factor = 0.1;
|
||||
for (; index < len; index++) {
|
||||
c = s.charAt(index);
|
||||
switch (c) {
|
||||
case ' ': break outer;
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
val += ((c - 48) * factor);
|
||||
factor *= 0.1;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return val * neg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Clipboard read() throws IOException {
|
||||
try (InputStream finalStream = inputStream) {
|
||||
load(finalStream);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private final BufferedImage getTexture(String file) throws IOException {
|
||||
BufferedImage texture = textures.get(file);
|
||||
if (texture == null) {
|
||||
texture = ImageIO.read(new File(root, file));
|
||||
textures.put(file, texture);
|
||||
}
|
||||
return texture;
|
||||
}
|
||||
|
||||
private void readLines(InputStream stream, Consumer<String> onEachLine, boolean nullTerminate) throws IOException {
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(stream))) {
|
||||
for (String line = reader.readLine(); line != null; line = reader.readLine()) {
|
||||
if (line.isEmpty() || line.charAt(0) == '#') continue;
|
||||
onEachLine.accept(line);
|
||||
}
|
||||
if (nullTerminate) onEachLine.accept(null);
|
||||
}
|
||||
}
|
||||
|
||||
private final int toIntColor(float color) {
|
||||
return (int) (color * 256 + 0.5);
|
||||
}
|
||||
|
||||
private String getFileName(String arg) {
|
||||
String[] pathSplit = arg.split("[/|\\\\]");
|
||||
return pathSplit[pathSplit.length - 1];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
|
||||
}
|
||||
|
||||
private class Material {
|
||||
private double dissolve = 1;
|
||||
private int color = Integer.MIN_VALUE;
|
||||
private String texture;
|
||||
}
|
||||
|
||||
private final void loadMaterials(String fileName) throws IOException {
|
||||
File file = new File(root, fileName);
|
||||
if (!file.exists()) {
|
||||
Fawe.debug(".mtl not found: " + fileName);
|
||||
return;
|
||||
}
|
||||
Map<String, Material> mtl = materialFiles.get(fileName);
|
||||
if (mtl == null) {
|
||||
final Map<String, Material> tmp = mtl = new HashMap<>();
|
||||
materialFiles.put(fileName, tmp);
|
||||
readLines(new FileInputStream(file), new Consumer<String>() {
|
||||
|
||||
private String name;
|
||||
private Material material;
|
||||
private int index;
|
||||
|
||||
private void add() {
|
||||
if (material != null) {
|
||||
if (material.color == Integer.MIN_VALUE) {
|
||||
material.color = -1;
|
||||
}
|
||||
tmp.put(name, material);
|
||||
material = null;
|
||||
name = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(String s) {
|
||||
if (s == null) {
|
||||
add();
|
||||
return;
|
||||
}
|
||||
String[] args = s.split("[ ]+");
|
||||
switch (args[0]) {
|
||||
// Name
|
||||
case "newmtl": {
|
||||
add();
|
||||
material = new Material();
|
||||
name = args[1];
|
||||
break;
|
||||
}
|
||||
// Color
|
||||
case "Ka":
|
||||
if (material.color != Integer.MIN_VALUE) break;
|
||||
case "Kd": {
|
||||
float r = Float.parseFloat(args[1]);
|
||||
float g = Float.parseFloat(args[2]);
|
||||
float b = Float.parseFloat(args[3]);
|
||||
material.color = (toIntColor(r) << 16) + (toIntColor(g) << 8) + toIntColor(b);
|
||||
break;
|
||||
}
|
||||
// Density
|
||||
case "d": {
|
||||
material.dissolve = Double.parseDouble(args[1]);
|
||||
break;
|
||||
}
|
||||
case "Tr": {
|
||||
material.dissolve = 1.0 - Double.parseDouble(args[1]);
|
||||
break;
|
||||
}
|
||||
case "map_Ka":
|
||||
if (material.texture != null) break;
|
||||
case "map_Kd": {
|
||||
material.texture = getFileName(args[1]);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}, true);
|
||||
}
|
||||
materials.putAll(mtl);
|
||||
}
|
||||
|
||||
private final Material getMaterial(String name) {
|
||||
Material mtl = materials.get(name);
|
||||
return mtl != null ? mtl : new Material();
|
||||
}
|
||||
|
||||
private void load(InputStream in) throws IOException {
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(in))) {
|
||||
for (String line = reader.readLine(); line != null; line = reader.readLine()) {
|
||||
if (line.isEmpty()) continue;
|
||||
char char0 = line.charAt(0);
|
||||
switch (char0) {
|
||||
case '#': continue;
|
||||
case 'v':
|
||||
switch (line.charAt(1)) {
|
||||
case ' ':
|
||||
case 'n': {
|
||||
Double.parseDouble("");
|
||||
break;
|
||||
}
|
||||
case 't': {
|
||||
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'f': {
|
||||
|
||||
break;
|
||||
}
|
||||
case 'l':
|
||||
case 's':
|
||||
case 'o':
|
||||
case 'g':
|
||||
// Ignore
|
||||
break;
|
||||
default:
|
||||
String[] args = line.split(" ");
|
||||
switch (args[0]) {
|
||||
case "mtllib": {
|
||||
String[] pathSplit = args[1].split("[/|\\\\]");
|
||||
String fileName = pathSplit[pathSplit.length - 1];
|
||||
loadMaterials(fileName);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// final File directory = file.getParentFile();
|
||||
// final Map<String, SimpleMaterial> materials = new HashMap<String, SimpleMaterial>();
|
||||
// final Map<Face, BufferedImage> textures = new HashMap<Face, BufferedImage>();
|
||||
// final Map<Face, Color> colors = new HashMap<Face, Color>();
|
||||
// final List<Vertex> v = new LinkedList<Vertex>();
|
||||
// final List<VertexTexture> vt = new LinkedList<VertexTexture>();
|
||||
// final List<Vertex> vn = new LinkedList<Vertex>();
|
||||
// final List<Face> f = new LinkedList<Face>();
|
||||
// final List<String[]> obj = new LinkedList<String[]>();
|
||||
// for (final String[] entry : obj) {
|
||||
// if (entry[0].equals("v") || entry[0].equals("vn")) {
|
||||
// if (entry.length == 1) {
|
||||
// VLogger.log("[ERROR] Invalid vertex or vertex normal entry found (no data)");
|
||||
// return null;
|
||||
// }
|
||||
// double x;
|
||||
// double y;
|
||||
// double z;
|
||||
// try {
|
||||
// x = Double.parseDouble(entry[1]);
|
||||
// y = Double.parseDouble(entry[2]);
|
||||
// z = Double.parseDouble(entry[3]);
|
||||
// }
|
||||
// catch (NumberFormatException | ArrayIndexOutOfBoundsException ex8) {
|
||||
// final RuntimeException ex5;
|
||||
// final RuntimeException ex = ex5;
|
||||
// VLogger.log("[ERROR] Invalid vertex or vertex normal entry found (not parseable data)");
|
||||
// return null;
|
||||
// }
|
||||
// if (entry[0].equals("v")) {
|
||||
// if (entry.length >= 6) {
|
||||
// try {
|
||||
// final float r = Float.parseFloat(entry[4]);
|
||||
// final float g = Float.parseFloat(entry[5]);
|
||||
// final float b = Float.parseFloat(entry[6]);
|
||||
// final Color c = new Color(r, g, b);
|
||||
// v.add(new Vertex(x, y, z, v.size() + 1, c));
|
||||
// continue;
|
||||
// }
|
||||
// catch (NumberFormatException | ArrayIndexOutOfBoundsException ex9) {
|
||||
// final RuntimeException ex6;
|
||||
// final RuntimeException ex = ex6;
|
||||
// VLogger.log("[ERROR] Invalid vertex color (not parseable data)");
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
// v.add(new Vertex(x, y, z, v.size() + 1));
|
||||
// }
|
||||
// else {
|
||||
// vn.add(new Vertex(x, y, z, vn.size() + 1));
|
||||
// }
|
||||
// }
|
||||
// else {
|
||||
// if (!entry[0].equals("vt")) {
|
||||
// continue;
|
||||
// }
|
||||
// if (entry.length == 1) {
|
||||
// VLogger.log("[ERROR] Invalid vertex texture entry found (no data)");
|
||||
// return null;
|
||||
// }
|
||||
// double vt_u;
|
||||
// double vt_v;
|
||||
// try {
|
||||
// vt_u = Double.parseDouble(entry[1]);
|
||||
// vt_v = Double.parseDouble(entry[2]);
|
||||
// if (vt_u < 0.0 || vt_v < 0.0 || vt_u > 1.0 || vt_v > 1.0) {
|
||||
// VLogger.log("[ERROR] UV of vertex texture out of bounds");
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
// catch (NumberFormatException | ArrayIndexOutOfBoundsException ex10) {
|
||||
// final RuntimeException ex7;
|
||||
// final RuntimeException ex2 = ex7;
|
||||
// VLogger.log("[ERROR] Invalid vertex texture entry found (not parseable data)");
|
||||
// return null;
|
||||
// }
|
||||
// vt.add(new VertexTexture(vt_u, vt_v, vn.size() + 1));
|
||||
// }
|
||||
// }
|
||||
// VLogger.log("[IMPORT] Loaded " + v.size() + " vertexes");
|
||||
// VLogger.log("[IMPORT] Loaded " + vt.size() + " vertex textures");
|
||||
// VLogger.log("[IMPORT] Loaded " + vn.size() + " vertex normals");
|
||||
// BufferedImage usemtl_texture = null;
|
||||
// Color usemtl_color = null;
|
||||
// for (final String[] entry2 : obj) {
|
||||
// if (entry2[0].equals("usemtl")) {
|
||||
// if (entry2.length == 1) {
|
||||
// VLogger.log("[ERROR] Invalid usemtl entry");
|
||||
// return null;
|
||||
// }
|
||||
// SimpleMaterial material = (SimpleMaterial)materials.get(entry2[1]);
|
||||
// if (material == null) {
|
||||
// VLogger.log("[WARN] Material '" + entry2[1] + "' does not exist");
|
||||
// material = getFallbackMaterial();
|
||||
// VLogger.log("[WARN] Replacing with fallback material");
|
||||
// }
|
||||
// usemtl_texture = material.texture;
|
||||
// usemtl_color = material.color;
|
||||
// VLogger.log("[IMPORT] Now using material '" + entry2[1] + "'");
|
||||
// }
|
||||
// else {
|
||||
// if (!entry2[0].equals("f")) {
|
||||
// continue;
|
||||
// }
|
||||
// if (entry2.length == 1) {
|
||||
// VLogger.log("[ERROR] Invalid face entry (no arguments)");
|
||||
// return null;
|
||||
// }
|
||||
// if (usemtl_texture == null && usemtl_color == null) {
|
||||
// VLogger.log("[WARN] Current Material has neither a texture nor a color");
|
||||
// usemtl_color = Colors.getGray(1.0f);
|
||||
// VLogger.log("[WARN] Using fallback color");
|
||||
// }
|
||||
// final Collection<FacePoint> points = new LinkedList<FacePoint>();
|
||||
// for (int i = 1; i < entry2.length; ++i) {
|
||||
// final String[] comp = entry2[i].split("/");
|
||||
// Integer comp_v;
|
||||
// Integer comp_vt;
|
||||
// Integer comp_vn;
|
||||
// try {
|
||||
// comp_v = Integer.parseInt(comp[0]);
|
||||
// comp_vt = ((comp.length <= 1 || comp[1].isEmpty()) ? null : Integer.parseInt(comp[1]));
|
||||
// comp_vn = ((comp.length <= 2 || comp[2].isEmpty()) ? null : Integer.parseInt(comp[2]));
|
||||
// }
|
||||
// catch (NumberFormatException ex3) {
|
||||
// final StringBuilder debug = new StringBuilder();
|
||||
// String[] array;
|
||||
// for (int length = (array = comp).length, j = 0; j < length; ++j) {
|
||||
// final String segment = array[j];
|
||||
// debug.append(segment);
|
||||
// debug.append("/");
|
||||
// }
|
||||
// VLogger.log("[ERROR] Face point failed to load (" + (Object)debug + ")");
|
||||
// return null;
|
||||
// }
|
||||
// try {
|
||||
// final FacePoint point = new FacePoint();
|
||||
// point.v = v.get((int)comp_v - 1);
|
||||
// point.vt = ((comp_vt == null) ? null : ((VertexTexture)vt.get((int)comp_vt - 1)));
|
||||
// point.vn = ((comp_vn == null) ? null : ((Vertex)vn.get((int)comp_vn - 1)));
|
||||
// points.add(point);
|
||||
// }
|
||||
// catch (IndexOutOfBoundsException ex4) {
|
||||
// VLogger.log("[ERROR] Face point reference to missing vertex");
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
// final Face face = new Face(points);
|
||||
// f.add(face);
|
||||
// if (usemtl_texture != null) {
|
||||
// textures.put(face, usemtl_texture);
|
||||
// }
|
||||
// if (usemtl_color == null) {
|
||||
// continue;
|
||||
// }
|
||||
// colors.put(face, usemtl_color);
|
||||
// }
|
||||
// }
|
||||
// double minX = Double.MAX_VALUE;
|
||||
// double minY = Double.MAX_VALUE;
|
||||
// double minZ = Double.MAX_VALUE;
|
||||
// double maxX = -1.7976931348623157E308;
|
||||
// double maxY = -1.7976931348623157E308;
|
||||
// double maxZ = -1.7976931348623157E308;
|
||||
// for (final Face face2 : f) {
|
||||
// for (final FacePoint point2 : face2.points) {
|
||||
// final double x2 = point2.v.getX();
|
||||
// final double y2 = point2.v.getY();
|
||||
// final double z2 = point2.v.getZ();
|
||||
// if (x2 < minX) {
|
||||
// minX = x2;
|
||||
// }
|
||||
// else if (x2 > maxX) {
|
||||
// maxX = x2;
|
||||
// }
|
||||
// if (y2 < minY) {
|
||||
// minY = y2;
|
||||
// }
|
||||
// else if (y2 > maxY) {
|
||||
// maxY = y2;
|
||||
// }
|
||||
// if (z2 < minZ) {
|
||||
// minZ = z2;
|
||||
// }
|
||||
// else {
|
||||
// if (z2 <= maxZ) {
|
||||
// continue;
|
||||
// }
|
||||
// maxZ = z2;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// final double size = Math.max(maxX - minX, Math.max(maxY - minY, maxZ - minZ));
|
||||
// final double scale = size / (resolution - 1.0);
|
||||
// final List<Face> polygons = new LinkedList<Face>();
|
||||
// for (final Face face3 : f) {
|
||||
// polygons.addAll(shatterFace(face3, colors, textures));
|
||||
// }
|
||||
// VLogger.log("[IMPORT] " + f.size() + " faces -> " + polygons.size() + " polygons");
|
||||
// final Map<Position3D, Color> colormap = new HashMap<Position3D, Color>();
|
||||
// for (final Face poly : polygons) {
|
||||
// final FacePoint a = (FacePoint)poly.points.get(0);
|
||||
// final FacePoint b2 = (FacePoint)poly.points.get(1);
|
||||
// final FacePoint c2 = (FacePoint)poly.points.get(2);
|
||||
// final Vector3D vAB = new Vector3D((Point3D)a.v, (Point3D)b2.v);
|
||||
// final Vector3D vAC = new Vector3D((Point3D)a.v, (Point3D)c2.v);
|
||||
// final float lAB = (float)vAB.length();
|
||||
// final float lAC = (float)vAC.length();
|
||||
// double[] array3;
|
||||
// if (a.vt == null || b2.vt == null) {
|
||||
// final double[] array2 = array3 = new double[2];
|
||||
// array2[1] = (array2[0] = 0.0);
|
||||
// }
|
||||
// else {
|
||||
// final double[] array4 = array3 = new double[2];
|
||||
// array4[0] = b2.vt.u - a.vt.u;
|
||||
// array4[1] = b2.vt.v - a.vt.v;
|
||||
// }
|
||||
// final double[] uvAB = array3;
|
||||
// double[] array6;
|
||||
// if (a.vt == null || c2.vt == null) {
|
||||
// final double[] array5 = array6 = new double[2];
|
||||
// array5[1] = (array5[0] = 0.0);
|
||||
// }
|
||||
// else {
|
||||
// final double[] array7 = array6 = new double[2];
|
||||
// array7[0] = c2.vt.u - a.vt.u;
|
||||
// array7[1] = c2.vt.v - a.vt.v;
|
||||
// }
|
||||
// final double[] uvAC = array6;
|
||||
// double[] array9;
|
||||
// if (a.vt == null) {
|
||||
// final double[] array8 = array9 = new double[2];
|
||||
// array8[1] = (array8[0] = 0.0);
|
||||
// }
|
||||
// else {
|
||||
// final double[] array10 = array9 = new double[2];
|
||||
// array10[0] = a.vt.u;
|
||||
// array10[1] = a.vt.v;
|
||||
// }
|
||||
// final double[] uvA = array9;
|
||||
// final Vector3D i2 = vAB.clone();
|
||||
// i2.normalize();
|
||||
// i2.multiply(scale);
|
||||
// final Vector3D i3 = vAC.clone();
|
||||
// i3.normalize();
|
||||
// i3.multiply(scale);
|
||||
// final BufferedImage texture = (BufferedImage)textures.get(poly);
|
||||
// final Color poly_color = (Color)colors.get(poly);
|
||||
// final int maxW = (texture == null) ? 0 : (texture.getWidth() - 1);
|
||||
// final int maxH = (texture == null) ? 0 : (texture.getHeight() - 1);
|
||||
// final double l = scale / 2.0;
|
||||
// for (float aloop = 0.0f; aloop < lAB; aloop += l) {
|
||||
// for (float bloop = 0.0f; bloop < lAC; bloop += l) {
|
||||
// final float ratio1 = aloop / lAB;
|
||||
// final float ratio2 = bloop / lAC;
|
||||
// if (ratio1 + ratio2 > 1.0f) {
|
||||
// break;
|
||||
// }
|
||||
// final Point3D point3 = a.v.clone();
|
||||
// point3.add(vAB.clone().multiply((double)ratio1));
|
||||
// point3.add(vAC.clone().multiply((double)ratio2));
|
||||
// final double colorU = uvA[0] + uvAB[0] * ratio1 + uvAC[0] * ratio2;
|
||||
// final double colorV = uvA[1] + uvAB[1] * ratio1 + uvAC[1] * ratio2;
|
||||
// Color pointcolor = null;
|
||||
// if (texture == null) {
|
||||
// if (poly.hasVertexColors()) {
|
||||
// final WeightedColor cA = new WeightedColor(a.v.getColor().getRGB(), 1.0f - ratio1 - ratio2);
|
||||
// final WeightedColor cB = new WeightedColor(b2.v.getColor().getRGB(), ratio1);
|
||||
// final WeightedColor cC = new WeightedColor(c2.v.getColor().getRGB(), ratio2);
|
||||
// pointcolor = Colors.blendColors(new WeightedColor[] { cA, cB, cC });
|
||||
// }
|
||||
// else {
|
||||
// pointcolor = poly_color;
|
||||
// }
|
||||
// }
|
||||
// else {
|
||||
// pointcolor = new Color(texture.getRGB((int)Math.floor((double)maxW * colorU), (int)Math.floor((double)maxH - maxH * colorV)), true);
|
||||
// }
|
||||
// if (pointcolor.getAlpha() != 0) {
|
||||
// point3.divide(scale);
|
||||
// colormap.put(point3.toPositionRound(), pointcolor);
|
||||
// colormap.put(point3.toPositionFloor(), pointcolor);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// VLogger.log("[IMPORT] Import complete, loaded " + f.size() + " faces");
|
||||
// VLogger.log("[IMPORT] Import complete, created " + colormap.size() + " voxels");
|
||||
// return new VoxelBox(colormap);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -20,7 +20,6 @@
|
||||
package com.sk89q.worldedit.extent.clipboard.io.legacycompat;
|
||||
|
||||
import com.sk89q.jnbt.Tag;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
|
||||
import java.util.Map;
|
||||
|
@ -26,8 +26,6 @@ import com.google.gson.JsonPrimitive;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import com.sk89q.jnbt.StringTag;
|
||||
import com.sk89q.jnbt.Tag;
|
||||
import com.sk89q.worldedit.world.block.BlockID;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
@ -37,13 +35,7 @@ public class SignCompatibilityHandler implements NBTCompatibilityHandler {
|
||||
|
||||
@Override
|
||||
public <B extends BlockStateHolder<B>> boolean isAffectedBlock(B block) {
|
||||
switch (block.getBlockType().getInternalId()) {
|
||||
case BlockID.SIGN:
|
||||
case BlockID.WALL_SIGN:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return block.getBlockType() == BlockTypes.SIGN || block.getBlockType() == BlockTypes.WALL_SIGN;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -19,7 +19,6 @@
|
||||
|
||||
package com.sk89q.worldedit.extent.inventory;
|
||||
|
||||
import com.boydti.fawe.object.exception.FaweException;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.extent.AbstractDelegateExtent;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
@ -27,23 +26,17 @@ import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Applies a {@link BlockBag} to operations.
|
||||
*/
|
||||
public class BlockBagExtent extends AbstractDelegateExtent {
|
||||
|
||||
private final boolean mine;
|
||||
private int[] missingBlocks = new int[BlockTypes.size()];
|
||||
private Map<BlockType, Integer> missingBlocks = new HashMap<>();
|
||||
private BlockBag blockBag;
|
||||
|
||||
/**
|
||||
@ -52,15 +45,9 @@ public class BlockBagExtent extends AbstractDelegateExtent {
|
||||
* @param extent the extent
|
||||
* @param blockBag the block bag
|
||||
*/
|
||||
public BlockBagExtent(Extent extent, @Nonnull BlockBag blockBag) {
|
||||
this(extent, blockBag, false);
|
||||
}
|
||||
|
||||
public BlockBagExtent(Extent extent, @Nonnull BlockBag blockBag, boolean mine) {
|
||||
public BlockBagExtent(Extent extent, @Nullable BlockBag blockBag) {
|
||||
super(extent);
|
||||
checkNotNull(blockBag);
|
||||
this.blockBag = blockBag;
|
||||
this.mine = mine;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -88,50 +75,46 @@ public class BlockBagExtent extends AbstractDelegateExtent {
|
||||
* @return a map of missing blocks
|
||||
*/
|
||||
public Map<BlockType, Integer> popMissing() {
|
||||
HashMap<BlockType, Integer> map = new HashMap<>();
|
||||
for (int i = 0; i < missingBlocks.length; i++) {
|
||||
int count = missingBlocks[i];
|
||||
if (count > 0) {
|
||||
map.put(BlockTypes.get(i), count);
|
||||
}
|
||||
}
|
||||
Arrays.fill(missingBlocks, 0);
|
||||
return map;
|
||||
Map<BlockType, Integer> missingBlocks = this.missingBlocks;
|
||||
this.missingBlocks = new HashMap<>();
|
||||
return missingBlocks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 pos, B block) throws WorldEditException {
|
||||
return setBlock(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ(), block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block) throws WorldEditException {
|
||||
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block) throws WorldEditException {
|
||||
if (blockBag != null) {
|
||||
BlockState existing = getExtent().getBlock(BlockVector3.at(x,y,z));
|
||||
BlockState existing = getExtent().getBlock(position);
|
||||
|
||||
if (!block.getBlockType().equals(existing.getBlockType())) {
|
||||
if (!block.getBlockType().getMaterial().isAir()) {
|
||||
try {
|
||||
blockBag.fetchPlacedBlock(block.toImmutableState());
|
||||
} catch (UnplaceableBlockException e) {
|
||||
throw new FaweException.FaweBlockBagException();
|
||||
return false;
|
||||
} catch (BlockBagException e) {
|
||||
missingBlocks[block.getBlockType().getInternalId()]++;
|
||||
throw new FaweException.FaweBlockBagException();
|
||||
if (!missingBlocks.containsKey(block.getBlockType())) {
|
||||
missingBlocks.put(block.getBlockType(), 1);
|
||||
} else {
|
||||
missingBlocks.put(block.getBlockType(), missingBlocks.get(block.getBlockType()) + 1);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (mine) {
|
||||
|
||||
if (!existing.getBlockType().getMaterial().isAir()) {
|
||||
try {
|
||||
blockBag.storeDroppedBlock(existing);
|
||||
} catch (BlockBagException ignored) {
|
||||
}
|
||||
if (!existing.getBlockType().getMaterial().isAir()) {
|
||||
try {
|
||||
blockBag.storeDroppedBlock(existing);
|
||||
} catch (BlockBagException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return super.setBlock(x, y, z, block);
|
||||
return super.setBlock(position, block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block) throws WorldEditException {
|
||||
return setBlock(BlockVector3.at(x,y,z),block);
|
||||
}
|
||||
}
|
||||
|
@ -1,58 +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.extent.logging;
|
||||
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
|
||||
import com.sk89q.worldedit.extent.AbstractDelegateExtent;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
|
||||
/**
|
||||
* An abstract class to implement block loggers and so on with.
|
||||
*/
|
||||
public abstract class AbstractLoggingExtent extends AbstractDelegateExtent {
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
*
|
||||
* @param extent the extent
|
||||
*/
|
||||
public AbstractLoggingExtent(Extent extent) {
|
||||
super(extent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a block is being changed.
|
||||
*
|
||||
* @param position the position
|
||||
* @param newBlock the new block to replace the old one
|
||||
*/
|
||||
protected void onBlockChange(BlockVector3 position, BlockStateHolder newBlock) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block) throws WorldEditException {
|
||||
onBlockChange(position, block);
|
||||
return super.setBlock(position, block);
|
||||
}
|
||||
}
|
@ -252,4 +252,4 @@ public class MultiStageReorder extends AbstractDelegateExtent implements Reorder
|
||||
|
||||
return new OperationQueue(operations);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,8 @@ package com.sk89q.worldedit.extent.transform;
|
||||
|
||||
import com.boydti.fawe.object.extent.ResettableExtent;
|
||||
import com.boydti.fawe.util.ReflectionUtils;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import com.sk89q.jnbt.ByteTag;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.jnbt.Tag;
|
||||
@ -37,6 +39,7 @@ import com.sk89q.worldedit.registry.state.DirectionalProperty;
|
||||
import com.sk89q.worldedit.registry.state.Property;
|
||||
import com.sk89q.worldedit.registry.state.PropertyKey;
|
||||
import com.sk89q.worldedit.util.Direction;
|
||||
import static com.sk89q.worldedit.util.Direction.*;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
@ -51,9 +54,10 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.sk89q.worldedit.util.Direction.*;
|
||||
|
||||
/**
|
||||
* Transforms blocks themselves (but not their position) according to a
|
||||
* given transform.
|
||||
*/
|
||||
public class BlockTransformExtent extends ResettableExtent {
|
||||
private Transform transform;
|
||||
private Transform transformInverse;
|
||||
@ -81,27 +85,17 @@ public class BlockTransformExtent extends ResettableExtent {
|
||||
|
||||
|
||||
private static long combine(Direction... directions) {
|
||||
long mask = 0;
|
||||
for (Direction dir : directions) {
|
||||
mask = mask | (1L << dir.ordinal());
|
||||
}
|
||||
return mask;
|
||||
return Arrays.stream(directions).mapToLong(dir -> (1L << dir.ordinal())).reduce(0, (a, b) -> a | b);
|
||||
}
|
||||
|
||||
private static long[] adapt(Direction... dirs) {
|
||||
long[] arr = new long[dirs.length];
|
||||
for (int i = 0; i < arr.length; i++) {
|
||||
arr[i] = 1L << dirs[i].ordinal();
|
||||
}
|
||||
Arrays.setAll(arr, i -> 1L << dirs[i].ordinal());
|
||||
return arr;
|
||||
}
|
||||
|
||||
private static long[] adapt(Long... dirs) {
|
||||
long[] arr = new long[dirs.length];
|
||||
for (int i = 0; i < arr.length; i++) {
|
||||
arr[i] = dirs[i];
|
||||
}
|
||||
return arr;
|
||||
return Arrays.stream(dirs).mapToLong(dir -> dir).toArray();
|
||||
}
|
||||
|
||||
private static long[] getDirections(AbstractProperty property) {
|
||||
@ -215,9 +209,7 @@ public class BlockTransformExtent extends ResettableExtent {
|
||||
}
|
||||
|
||||
private static long notIndex(long mask, int... indexes) {
|
||||
for (int index : indexes) {
|
||||
mask = mask | (1L << (index + values().length));
|
||||
}
|
||||
mask |= Arrays.stream(indexes).mapToLong(index -> (1L << (index + values().length))).reduce(0, (a, b) -> a | b);
|
||||
return mask;
|
||||
}
|
||||
|
||||
@ -271,7 +263,7 @@ public class BlockTransformExtent extends ResettableExtent {
|
||||
}
|
||||
if (newIndex != null) return newIndex;
|
||||
}
|
||||
return newIndex != null ? newIndex : null;
|
||||
return newIndex;
|
||||
}
|
||||
|
||||
private static boolean isDirectional(Property property) {
|
||||
@ -361,24 +353,6 @@ public class BlockTransformExtent extends ResettableExtent {
|
||||
return newMaskedId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Slow - does not cache results
|
||||
* @param block
|
||||
* @param transform
|
||||
* @param <B>
|
||||
* @return
|
||||
*/
|
||||
@Deprecated
|
||||
public static <B extends BlockStateHolder<B>> B transform(B block, Transform transform) {
|
||||
BlockState state = block.toImmutableState();
|
||||
|
||||
int transformedId = transformState(state, transform);
|
||||
BlockState transformed = BlockState.getFromInternalId(transformedId);
|
||||
if (block.hasNbtData()) {
|
||||
return (B) transformBaseBlockNBT(transformed, block.getNbtData(), transform);
|
||||
}
|
||||
return (B) (block instanceof BaseBlock ? transformed.toBaseBlock() : transformed);
|
||||
}
|
||||
|
||||
private void cache() {
|
||||
BLOCK_ROTATION_BITMASK = new int[BlockTypes.size()];
|
||||
@ -407,16 +381,58 @@ public class BlockTransformExtent extends ResettableExtent {
|
||||
return super.setExtent(extent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the transform.
|
||||
*
|
||||
* @return the transform
|
||||
*/
|
||||
public Transform getTransform() {
|
||||
return transform;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getBlock(BlockVector3 position) {
|
||||
return transform(super.getBlock(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBlock getFullBlock(BlockVector3 position) {
|
||||
return transform(super.getFullBlock(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 location, B block) throws WorldEditException {
|
||||
return super.setBlock(location, transformInverse(block));
|
||||
}
|
||||
|
||||
public void setTransform(Transform affine) {
|
||||
this.transform = affine;
|
||||
this.transformInverse = this.transform.inverse();
|
||||
cache();
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform the given block using the given transform.
|
||||
*
|
||||
* <p>The provided block is <em>not</em> modified.</p>
|
||||
*
|
||||
* @param block the block
|
||||
* @param transform the transform
|
||||
* @return the same block
|
||||
*/
|
||||
public static <B extends BlockStateHolder<B>> B transform(B block, Transform transform) {
|
||||
checkNotNull(block);
|
||||
checkNotNull(transform);
|
||||
BlockState state = block.toImmutableState();
|
||||
|
||||
int transformedId = transformState(state, transform);
|
||||
BlockState transformed = BlockState.getFromInternalId(transformedId);
|
||||
if (block.hasNbtData()) {
|
||||
return (B) transformBaseBlockNBT(transformed, block.getNbtData(), transform);
|
||||
}
|
||||
return (B) (block instanceof BaseBlock ? transformed.toBaseBlock() : transformed);
|
||||
}
|
||||
|
||||
private BlockState transform(BlockState state, int[][] transformArray, Transform transform) {
|
||||
int typeId = state.getInternalBlockTypeId();
|
||||
int[] arr = transformArray[typeId];
|
||||
@ -450,7 +466,7 @@ public class BlockTransformExtent extends ResettableExtent {
|
||||
return transformed.toBaseBlock();
|
||||
}
|
||||
|
||||
public final BlockStateHolder transformInverse(BlockStateHolder block) {
|
||||
protected final BlockStateHolder transformInverse(BlockStateHolder block) {
|
||||
BlockState transformed = transformInverse(block.toImmutableState());
|
||||
if (block.hasNbtData()) {
|
||||
return transformBaseBlockNBT(transformed, block.getNbtData(), transformInverse);
|
||||
@ -462,7 +478,7 @@ public class BlockTransformExtent extends ResettableExtent {
|
||||
return transform(block, BLOCK_TRANSFORM, transform);
|
||||
}
|
||||
|
||||
public final BlockState transformInverse(BlockState block) {
|
||||
private BlockState transformInverse(BlockState block) {
|
||||
return transform(block, BLOCK_TRANSFORM_INVERSE, transformInverse);
|
||||
}
|
||||
|
||||
@ -471,21 +487,11 @@ public class BlockTransformExtent extends ResettableExtent {
|
||||
return transform(super.getLazyBlock(x, y, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBlock getFullBlock(BlockVector3 position) {
|
||||
return transform(super.getFullBlock(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getLazyBlock(BlockVector3 position) {
|
||||
return transform(super.getLazyBlock(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getBlock(BlockVector3 position) {
|
||||
return transform(super.getBlock(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeType getBiome(BlockVector2 position) {
|
||||
return super.getBiome(position);
|
||||
@ -497,10 +503,5 @@ public class BlockTransformExtent extends ResettableExtent {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException {
|
||||
return super.setBlock(location, transformInverse(block));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -60,7 +60,6 @@ public class BlockMask extends AbstractExtentMask {
|
||||
* @param extent the extent
|
||||
* @param blocks a list of blocks to match
|
||||
*/
|
||||
@Deprecated
|
||||
public BlockMask(Extent extent, Collection<BaseBlock> blocks) {
|
||||
super(extent);
|
||||
checkNotNull(blocks);
|
||||
@ -73,7 +72,6 @@ public class BlockMask extends AbstractExtentMask {
|
||||
* @param extent the extent
|
||||
* @param block an array of blocks to match
|
||||
*/
|
||||
@Deprecated
|
||||
public BlockMask(Extent extent, BaseBlock... block) {
|
||||
super(extent);
|
||||
checkNotNull(block);
|
||||
|
@ -20,6 +20,7 @@
|
||||
package com.sk89q.worldedit.function.mask;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
@ -39,19 +40,9 @@ import java.util.Set;
|
||||
* use {@link BlockMask}.</p>
|
||||
*/
|
||||
public class BlockTypeMask extends AbstractExtentMask {
|
||||
|
||||
private final boolean[] types;
|
||||
|
||||
protected BlockTypeMask(Extent extent, boolean[] types) {
|
||||
super(extent);
|
||||
this.types = types;
|
||||
}
|
||||
|
||||
public BlockTypeMask(Extent extent, BlockType... types) {
|
||||
super(extent);
|
||||
this.types = new boolean[BlockTypes.size()];
|
||||
for (BlockType type : types) this.types[type.getInternalId()] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new block mask.
|
||||
*
|
||||
@ -59,7 +50,24 @@ public class BlockTypeMask extends AbstractExtentMask {
|
||||
* @param blocks a list of blocks to match
|
||||
*/
|
||||
public BlockTypeMask(Extent extent, Collection<BlockType> blocks) {
|
||||
this(extent, blocks.toArray(new BlockType[blocks.size()]));
|
||||
this(extent, blocks.toArray(new BlockType[0]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new block mask.
|
||||
*
|
||||
* @param extent the extent
|
||||
* @param block an array of blocks to match
|
||||
*/
|
||||
public BlockTypeMask(Extent extent, BlockType... block) {
|
||||
super(extent);
|
||||
this.types = new boolean[BlockTypes.size()];
|
||||
for (BlockType type : block) this.types[type.getInternalId()] = true;
|
||||
}
|
||||
|
||||
protected BlockTypeMask(Extent extent, boolean[] types) {
|
||||
super(extent);
|
||||
this.types = types;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -25,9 +25,6 @@ import com.sk89q.worldedit.math.BlockVector3;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.sk89q.worldedit.function.mask.Masks.negate;
|
||||
|
||||
/**
|
||||
* Tests whether a given vector meets a criteria.
|
||||
*/
|
||||
|
@ -104,7 +104,8 @@ public class MaskIntersection extends AbstractMask {
|
||||
Set<Mask> optimized = new HashSet<>();
|
||||
Set<Map.Entry<Mask, Mask>> failedCombines = new HashSet<>();
|
||||
// Combine the masks
|
||||
while (combine(pairingFunction(), failedCombines));
|
||||
while (combine(pairingFunction(), failedCombines)) {
|
||||
}
|
||||
// Optimize / combine
|
||||
do optimizeMasks(optimized);
|
||||
while (combine(pairingFunction(), failedCombines));
|
||||
@ -122,7 +123,7 @@ public class MaskIntersection extends AbstractMask {
|
||||
outer:
|
||||
for (Mask mask : masks) {
|
||||
for (Mask other : masks) {
|
||||
AbstractMap.SimpleEntry pair = new AbstractMap.SimpleEntry(mask, other);
|
||||
AbstractMap.SimpleEntry<Mask, Mask> pair = new AbstractMap.SimpleEntry<>(mask, other);
|
||||
if (failedCombines.contains(pair)) continue;
|
||||
Mask combined = pairing.apply(pair);
|
||||
if (combined != null) {
|
||||
|
@ -16,6 +16,7 @@
|
||||
* 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.function.mask;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
@ -2,7 +2,6 @@ package com.sk89q.worldedit.function.mask;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
|
||||
public class SingleBlockStateMask extends AbstractExtentMask {
|
||||
|
@ -2,7 +2,6 @@ package com.sk89q.worldedit.function.mask;
|
||||
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
|
@ -1,29 +1,25 @@
|
||||
package com.sk89q.worldedit.function.operation;
|
||||
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.function.RegionFunction;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
import com.sk89q.worldedit.math.transform.Transform;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class BackwardsExtentBlockCopy implements Operation {
|
||||
private final Region region;
|
||||
private final Transform transform;
|
||||
private final Extent destination;
|
||||
private final Extent source;
|
||||
private final RegionFunction function;
|
||||
private final BlockVector3 origin;
|
||||
|
||||
// private Vector mutable = new MutableBlockVector3();
|
||||
|
||||
public BackwardsExtentBlockCopy(Extent source, Region region, Extent destination, BlockVector3 origin, Transform transform, RegionFunction function) {
|
||||
this.source = source;
|
||||
BackwardsExtentBlockCopy(Region region, BlockVector3 origin, Transform transform, RegionFunction function) {
|
||||
this.region = region;
|
||||
this.destination = destination;
|
||||
this.transform = transform;
|
||||
this.function = function;
|
||||
this.origin = origin;
|
||||
|
@ -299,7 +299,7 @@ public class ForwardExtentCopy implements Operation {
|
||||
if (copyBiomes && (!(source instanceof BlockArrayClipboard) || ((BlockArrayClipboard) source).IMP.hasBiomes())) {
|
||||
copy = CombinedRegionFunction.combine(copy, new BiomeCopy(source, finalDest));
|
||||
}
|
||||
blockCopy = new BackwardsExtentBlockCopy(transExt, region, finalDest, from, transform, copy);
|
||||
blockCopy = new BackwardsExtentBlockCopy(region, from, transform, copy);
|
||||
} else {
|
||||
transExt = new PositionTransformExtent(finalDest, currentTransform);
|
||||
transExt.setOrigin(from);
|
||||
|
@ -4,11 +4,9 @@ import com.sk89q.minecraft.util.commands.Link;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.command.UtilityCommands;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.extent.NullExtent;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
|
||||
/**
|
||||
* Returns a {@link BlockStateHolder} for a given position.
|
||||
@ -29,4 +27,4 @@ public interface FawePattern extends Pattern {
|
||||
*/
|
||||
@Override
|
||||
boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException;
|
||||
}
|
||||
}
|
||||
|
@ -20,8 +20,7 @@
|
||||
package com.sk89q.worldedit.function.visitor;
|
||||
|
||||
import com.boydti.fawe.object.HasFaweQueue;
|
||||
import com.sk89q.worldedit.function.RegionFunction;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.function.RegionFunction;
|
||||
|
@ -19,14 +19,14 @@
|
||||
|
||||
package com.sk89q.worldedit.history.change;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
import com.sk89q.worldedit.history.UndoContext;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Logs the creation of an entity and removes the entity upon undo.
|
||||
*/
|
||||
|
@ -19,14 +19,14 @@
|
||||
|
||||
package com.sk89q.worldedit.history.change;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
import com.sk89q.worldedit.history.UndoContext;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Tracks the removal of an entity.
|
||||
*/
|
||||
|
@ -70,4 +70,4 @@ public class ArrayListHistory implements ChangeSet {
|
||||
return changes.size();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -77,4 +77,4 @@ public interface ChangeSet {
|
||||
*/
|
||||
int size();
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ public class CommandLoggingHandler extends AbstractInvokeListener implements Inv
|
||||
Logging loggingAnnotation = method.getAnnotation(Logging.class);
|
||||
Logging.LogMode logMode;
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
|
||||
if (loggingAnnotation == null) {
|
||||
logMode = null;
|
||||
} else {
|
||||
@ -96,15 +96,15 @@ public class CommandLoggingHandler extends AbstractInvokeListener implements Inv
|
||||
}
|
||||
|
||||
builder.append(": ").append(context.getCommand());
|
||||
|
||||
|
||||
if (context.argsLength() > 0) {
|
||||
builder.append(" ").append(context.getJoinedStrings(0));
|
||||
}
|
||||
|
||||
|
||||
if (logMode != null && sender.isPlayer()) {
|
||||
Vector3 position = player.getLocation();
|
||||
Vector3 position = player.getLocation().toVector();
|
||||
LocalSession session = worldEdit.getSessionManager().get(player);
|
||||
|
||||
|
||||
switch (logMode) {
|
||||
case PLACEMENT:
|
||||
try {
|
||||
|
@ -20,6 +20,7 @@
|
||||
package com.sk89q.worldedit.internal.command;
|
||||
|
||||
import com.boydti.fawe.util.MathMan;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
@ -36,14 +37,12 @@ import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.internal.annotation.Direction;
|
||||
import com.sk89q.worldedit.internal.annotation.Selection;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.util.TreeGenerator;
|
||||
import com.sk89q.worldedit.util.TreeGenerator.TreeType;
|
||||
import com.sk89q.worldedit.util.command.parametric.ArgumentStack;
|
||||
import com.sk89q.worldedit.util.command.parametric.BindingBehavior;
|
||||
import com.sk89q.worldedit.util.command.parametric.BindingHelper;
|
||||
import com.sk89q.worldedit.util.command.parametric.BindingMatch;
|
||||
import com.sk89q.worldedit.util.command.parametric.ParameterException;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
@ -99,7 +98,7 @@ public class WorldEditBinding {
|
||||
* @throws ParameterException on other error
|
||||
*/
|
||||
@BindingMatch(type = EditSession.class,
|
||||
behavior = BindingBehavior.PROVIDES)
|
||||
behavior = BindingBehavior.PROVIDES)
|
||||
public EditSession getEditSession(ArgumentStack context) throws ParameterException {
|
||||
Player sender = getPlayer(context);
|
||||
LocalSession session = worldEdit.getSessionManager().get(sender);
|
||||
@ -118,7 +117,7 @@ public class WorldEditBinding {
|
||||
* @throws ParameterException on error
|
||||
*/
|
||||
@BindingMatch(type = LocalSession.class,
|
||||
behavior = BindingBehavior.PROVIDES)
|
||||
behavior = BindingBehavior.PROVIDES)
|
||||
public LocalSession getLocalSession(ArgumentStack context) throws ParameterException {
|
||||
Player sender = getPlayer(context);
|
||||
return worldEdit.getSessionManager().get(sender);
|
||||
@ -150,7 +149,7 @@ public class WorldEditBinding {
|
||||
* @throws ParameterException on error
|
||||
*/
|
||||
@BindingMatch(type = Player.class,
|
||||
behavior = BindingBehavior.PROVIDES)
|
||||
behavior = BindingBehavior.PROVIDES)
|
||||
public Player getPlayer(ArgumentStack context) throws ParameterException {
|
||||
Actor sender = context.getContext().getLocals().get(Actor.class);
|
||||
if (sender == null) {
|
||||
@ -166,7 +165,7 @@ public class WorldEditBinding {
|
||||
* Gets an {@link BaseBlock} from a {@link ArgumentStack}.
|
||||
*
|
||||
* @param context the context
|
||||
* @return a block state
|
||||
* @return a pattern
|
||||
* @throws ParameterException on error
|
||||
* @throws WorldEditException on error
|
||||
*/
|
||||
@ -200,8 +199,8 @@ public class WorldEditBinding {
|
||||
}
|
||||
|
||||
@BindingMatch(type = {BaseBlock.class, BlockState.class, BlockStateHolder.class},
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1)
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1)
|
||||
public BaseBlock getBaseBlock(ArgumentStack context) throws ParameterException, WorldEditException {
|
||||
return getBlockState(context).toBaseBlock();
|
||||
}
|
||||
@ -244,8 +243,8 @@ public class WorldEditBinding {
|
||||
* @throws WorldEditException on error
|
||||
*/
|
||||
@BindingMatch(type = Pattern.class,
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1)
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1)
|
||||
public Pattern getPattern(ArgumentStack context) throws ParameterException, WorldEditException {
|
||||
Actor actor = context.getContext().getLocals().get(Actor.class);
|
||||
ParserContext parserContext = new ParserContext();
|
||||
@ -273,8 +272,8 @@ public class WorldEditBinding {
|
||||
* @throws WorldEditException on error
|
||||
*/
|
||||
@BindingMatch(type = Mask.class,
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1)
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1)
|
||||
public Mask getMask(ArgumentStack context) throws ParameterException, WorldEditException {
|
||||
Actor actor = context.getContext().getLocals().get(Actor.class);
|
||||
ParserContext parserContext = new ParserContext();
|
||||
@ -377,6 +376,4 @@ public class WorldEditBinding {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -45,22 +45,22 @@ import java.util.concurrent.TimeoutException;
|
||||
|
||||
/**
|
||||
* Compiles and evaluates expressions.
|
||||
* <p>
|
||||
*
|
||||
* <p>Supported operators:</p>
|
||||
* <p>
|
||||
*
|
||||
* <ul>
|
||||
* <li>Logical: &&, ||, ! (unary)</li>
|
||||
* <li>Bitwise: ~ (unary), >>, <<</li>
|
||||
* <li>Arithmetic: +, -, *, /, % (modulo), ^ (power), - (unary), --, ++ (prefix only)</li>
|
||||
* <li>Comparison: <=, >=, >, <, ==, !=, ~= (near)</li>
|
||||
* <li>Logical: &&, ||, ! (unary)</li>
|
||||
* <li>Bitwise: ~ (unary), >>, <<</li>
|
||||
* <li>Arithmetic: +, -, *, /, % (modulo), ^ (power), - (unary), --, ++ (prefix only)</li>
|
||||
* <li>Comparison: <=, >=, >, <, ==, !=, ~= (near)</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
*
|
||||
* <p>Supported functions: abs, acos, asin, atan, atan2, cbrt, ceil, cos, cosh,
|
||||
* exp, floor, ln, log, log10, max, max, min, min, rint, round, sin, sinh,
|
||||
* sqrt, tan, tanh and more. (See the Functions class or the wiki)</p>
|
||||
* <p>
|
||||
*
|
||||
* <p>Constants: e, pi</p>
|
||||
* <p>
|
||||
*
|
||||
* <p>To compile an equation, run
|
||||
* {@code Expression.compile("expression here", "var1", "var2"...)}.
|
||||
* If you wish to run the equation multiple times, you can then optimize it,
|
||||
@ -70,7 +70,7 @@ import java.util.concurrent.TimeoutException;
|
||||
* To query variables after evaluation, you can use
|
||||
* {@link #getVariable(String, boolean)}. To get a value out of these, use
|
||||
* {@link Variable#getValue()}.</p>
|
||||
* <p>
|
||||
*
|
||||
* <p>Variables are also supported and can be set either by passing values
|
||||
* to {@link #evaluate(double...)}.</p>
|
||||
*/
|
||||
@ -146,6 +146,7 @@ public class Expression {
|
||||
|
||||
((Variable) invokable).value = values[i];
|
||||
}
|
||||
|
||||
try {
|
||||
if (timeout < 0) {
|
||||
return evaluateRoot();
|
||||
@ -236,6 +237,4 @@ public class Expression {
|
||||
this.environment = environment;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,9 +1,32 @@
|
||||
/*
|
||||
* 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.internal.expression.runtime;
|
||||
|
||||
import com.sk89q.worldedit.internal.expression.Expression;
|
||||
import com.sk89q.worldedit.internal.expression.parser.ParserException;
|
||||
|
||||
/**
|
||||
* A Java/C-style for loop.
|
||||
*/
|
||||
public class For extends Node {
|
||||
|
||||
RValue init;
|
||||
RValue condition;
|
||||
RValue increment;
|
||||
@ -11,34 +34,35 @@ public class For extends Node {
|
||||
|
||||
public For(int position, RValue init, RValue condition, RValue increment, RValue body) {
|
||||
super(position);
|
||||
|
||||
this.init = init;
|
||||
this.condition = condition;
|
||||
this.increment = increment;
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getValue() throws EvaluationException {
|
||||
|
||||
int iterations = 0;
|
||||
double ret = 0.0D;
|
||||
this.init.getValue();
|
||||
double ret = 0.0;
|
||||
|
||||
for(; this.condition.getValue() > 0.0D; this.increment.getValue()) {
|
||||
|
||||
if(iterations > 256) {
|
||||
throw new EvaluationException(this.getPosition(), "Loop exceeded 256 iterations.");
|
||||
for (init.getValue(); condition.getValue() > 0; increment.getValue()) {
|
||||
if (iterations > 256) {
|
||||
throw new EvaluationException(getPosition(), "Loop exceeded 256 iterations.");
|
||||
}
|
||||
|
||||
if(Thread.interrupted()){
|
||||
throw new EvaluationException(this.getPosition(), "Thread has been interrupted.");
|
||||
if (Thread.interrupted()) {
|
||||
throw new EvaluationException(getPosition(), "Calculations exceeded time limit.");
|
||||
}
|
||||
++iterations;
|
||||
|
||||
try {
|
||||
ret = this.body.getValue();
|
||||
} catch (BreakException var5) {
|
||||
if(!var5.doContinue) {
|
||||
return ret;
|
||||
ret = body.getValue();
|
||||
} catch (BreakException e) {
|
||||
if (e.doContinue) {
|
||||
//noinspection UnnecessaryContinue
|
||||
continue;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -46,30 +70,38 @@ public class For extends Node {
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public char id() {
|
||||
return 'F';
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "for (" + this.init + "; " + this.condition + "; " + this.increment + ") { " + this.body + " }";
|
||||
return "for (" + init + "; " + condition + "; " + increment + ") { " + body + " }";
|
||||
}
|
||||
|
||||
@Override
|
||||
public RValue optimize() throws EvaluationException {
|
||||
final RValue newCondition = condition.optimize();
|
||||
|
||||
if (newCondition instanceof Constant && newCondition.getValue() <= 0) {
|
||||
// If the condition is always false, the loop can be flattened.
|
||||
// So we run the init part and then return 0.0.
|
||||
return new Sequence(getPosition(), init, new Constant(getPosition(), 0.0)).optimize();
|
||||
}
|
||||
|
||||
//return new Sequence(getPosition(), init.optimize(), new While(getPosition(), condition, new Sequence(getPosition(), body, increment), false)).optimize();
|
||||
return new For(getPosition(), init.optimize(), newCondition, increment.optimize(), body.optimize());
|
||||
}
|
||||
|
||||
@Override
|
||||
public RValue bindVariables(Expression expression, boolean preferLValue) throws ParserException {
|
||||
this.init = this.init.bindVariables(expression, false);
|
||||
this.condition = this.condition.bindVariables(expression, false);
|
||||
this.increment = this.increment.bindVariables(expression, false);
|
||||
this.body = this.body.bindVariables(expression, false);
|
||||
init = init.bindVariables(expression, false);
|
||||
condition = condition.bindVariables(expression, false);
|
||||
increment = increment.bindVariables(expression, false);
|
||||
body = body.bindVariables(expression, false);
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ package com.sk89q.worldedit.internal.expression.runtime;
|
||||
|
||||
import com.sk89q.worldedit.internal.expression.Expression;
|
||||
import com.sk89q.worldedit.internal.expression.parser.ParserException;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@ -36,8 +37,7 @@ public class Function extends Node {
|
||||
* for the same inputs and on functions with side-effects.
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Dynamic {
|
||||
}
|
||||
public @interface Dynamic { }
|
||||
|
||||
public final Method method;
|
||||
public final RValue[] args;
|
||||
@ -121,5 +121,4 @@ public class Function extends Node {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -19,14 +19,13 @@
|
||||
|
||||
package com.sk89q.worldedit.internal.expression.runtime;
|
||||
|
||||
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.internal.expression.Expression;
|
||||
import com.sk89q.worldedit.internal.expression.runtime.Function.Dynamic;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
import com.sk89q.worldedit.math.noise.PerlinNoise;
|
||||
import com.sk89q.worldedit.math.noise.RidgedMultiFractalNoise;
|
||||
import com.sk89q.worldedit.math.noise.VoronoiNoise;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@ -125,13 +124,11 @@ public final class Functions {
|
||||
}
|
||||
|
||||
private static final Map<String, List<Overload>> functions = new HashMap<>();
|
||||
|
||||
static {
|
||||
for (Method method : Functions.class.getMethods()) {
|
||||
try {
|
||||
addFunction(method);
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
}
|
||||
} catch (IllegalArgumentException ignored) { }
|
||||
}
|
||||
}
|
||||
|
||||
@ -141,10 +138,7 @@ public final class Functions {
|
||||
|
||||
Overload overload = new Overload(method);
|
||||
|
||||
List<Overload> overloads = functions.get(methodName);
|
||||
if (overloads == null) {
|
||||
functions.put(methodName, overloads = new ArrayList<>());
|
||||
}
|
||||
List<Overload> overloads = functions.computeIfAbsent(methodName, k -> new ArrayList<>());
|
||||
|
||||
overloads.add(overload);
|
||||
}
|
||||
@ -256,6 +250,7 @@ public final class Functions {
|
||||
return Math.log10(x.getValue());
|
||||
}
|
||||
|
||||
|
||||
public static double rotate(LValue x, LValue y, RValue angle) throws EvaluationException {
|
||||
final double f = angle.getValue();
|
||||
|
||||
@ -327,26 +322,26 @@ public final class Functions {
|
||||
@Dynamic
|
||||
public static double closest(RValue x, RValue y, RValue z, RValue index, RValue count, RValue stride) throws EvaluationException {
|
||||
return findClosest(
|
||||
Expression.getInstance().getFunctions().megabuf,
|
||||
x.getValue(),
|
||||
y.getValue(),
|
||||
z.getValue(),
|
||||
(int) index.getValue(),
|
||||
(int) count.getValue(),
|
||||
(int) stride.getValue()
|
||||
Expression.getInstance().getFunctions().megabuf,
|
||||
x.getValue(),
|
||||
y.getValue(),
|
||||
z.getValue(),
|
||||
(int) index.getValue(),
|
||||
(int) count.getValue(),
|
||||
(int) stride.getValue()
|
||||
);
|
||||
}
|
||||
|
||||
@Dynamic
|
||||
public static double gclosest(RValue x, RValue y, RValue z, RValue index, RValue count, RValue stride) throws EvaluationException {
|
||||
return findClosest(
|
||||
gmegabuf,
|
||||
x.getValue(),
|
||||
y.getValue(),
|
||||
z.getValue(),
|
||||
(int) index.getValue(),
|
||||
(int) count.getValue(),
|
||||
(int) stride.getValue()
|
||||
gmegabuf,
|
||||
x.getValue(),
|
||||
y.getValue(),
|
||||
z.getValue(),
|
||||
(int) index.getValue(),
|
||||
(int) count.getValue(),
|
||||
(int) stride.getValue()
|
||||
);
|
||||
}
|
||||
|
||||
@ -355,11 +350,11 @@ public final class Functions {
|
||||
double minDistanceSquared = Double.MAX_VALUE;
|
||||
|
||||
for (int i = 0; i < count; ++i) {
|
||||
double currentX = getBufferItem(megabuf, index + 0) - x;
|
||||
double currentY = getBufferItem(megabuf, index + 1) - y;
|
||||
double currentZ = getBufferItem(megabuf, index + 2) - z;
|
||||
double currentX = getBufferItem(megabuf, index+0) - x;
|
||||
double currentY = getBufferItem(megabuf, index+1) - y;
|
||||
double currentZ = getBufferItem(megabuf, index+2) - z;
|
||||
|
||||
double currentDistanceSquared = currentX * currentX + currentY * currentY + currentZ * currentZ;
|
||||
double currentDistanceSquared = currentX*currentX + currentY*currentY + currentZ*currentZ;
|
||||
|
||||
if (currentDistanceSquared < minDistanceSquared) {
|
||||
minDistanceSquared = currentDistanceSquared;
|
||||
@ -489,5 +484,4 @@ public final class Functions {
|
||||
return queryInternal(type, data, typeId, dataValue);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -19,7 +19,6 @@
|
||||
|
||||
package com.sk89q.worldedit.internal.registry;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
|
@ -117,34 +117,4 @@ public final class MathUtils {
|
||||
public static double roundHalfUp(double value) {
|
||||
return Math.signum(value) * Math.round(Math.abs(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the midpoint Vector3 of the two given Vector3's.
|
||||
*
|
||||
* @param first Vector3
|
||||
* @param second Vector3
|
||||
* @return midpoint Vector3
|
||||
*/
|
||||
public static Vector3 midpoint(Vector3 v1, Vector3 v2) {
|
||||
return Vector3.at(
|
||||
(v1.getX() + v2.getX()) / 2,
|
||||
(v1.getY() + v2.getY()) / 2,
|
||||
(v1.getZ() + v2.getZ()) / 2
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the midpoint BlockVector3 of the two given BlockVector3's.
|
||||
*
|
||||
* @param first BlockVector3
|
||||
* @param second BlockVector3
|
||||
* @return midpoint BlockVector3
|
||||
*/
|
||||
public static BlockVector3 midpoint(BlockVector3 v1, BlockVector3 v2) {
|
||||
return BlockVector3.at(
|
||||
(v1.getBlockX() + v2.getBlockX()) / 2,
|
||||
(v1.getBlockY() + v2.getBlockY()) / 2,
|
||||
(v1.getBlockZ() + v2.getBlockZ()) / 2
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,12 +2,7 @@ package com.sk89q.worldedit.math;
|
||||
|
||||
public class MutableBlockVector2 extends BlockVector2 {
|
||||
|
||||
private static ThreadLocal<MutableBlockVector2> MUTABLE_CACHE = new ThreadLocal<MutableBlockVector2>() {
|
||||
@Override
|
||||
protected MutableBlockVector2 initialValue() {
|
||||
return new MutableBlockVector2();
|
||||
}
|
||||
};
|
||||
private static ThreadLocal<MutableBlockVector2> MUTABLE_CACHE = ThreadLocal.withInitial(() -> new MutableBlockVector2());
|
||||
|
||||
public static MutableBlockVector2 get(int x, int z) {
|
||||
return MUTABLE_CACHE.get().setComponents(x, z);
|
||||
|
@ -2,12 +2,7 @@ package com.sk89q.worldedit.math;
|
||||
|
||||
public class MutableBlockVector3 extends BlockVector3 {
|
||||
|
||||
private static ThreadLocal<MutableBlockVector3> MUTABLE_CACHE = new ThreadLocal<MutableBlockVector3>() {
|
||||
@Override
|
||||
protected MutableBlockVector3 initialValue() {
|
||||
return new MutableBlockVector3();
|
||||
}
|
||||
};
|
||||
private static ThreadLocal<MutableBlockVector3> MUTABLE_CACHE = ThreadLocal.withInitial(() -> new MutableBlockVector3());
|
||||
|
||||
public static MutableBlockVector3 get(int x, int y, int z) {
|
||||
return MUTABLE_CACHE.get().setComponents(x, y, z);
|
||||
|
@ -1,7 +1,5 @@
|
||||
package com.sk89q.worldedit.math;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class MutableVector3 extends Vector3 {
|
||||
|
||||
public MutableVector3() {}
|
||||
|
@ -20,6 +20,8 @@
|
||||
package com.sk89q.worldedit.math.convolution;
|
||||
|
||||
import com.boydti.fawe.object.visitor.Fast2DIterator;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
@ -34,8 +36,6 @@ import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Allows applications of Kernels onto the region's height map.
|
||||
*
|
||||
@ -167,7 +167,6 @@ public class HeightMap {
|
||||
|
||||
BlockVector3 minY = region.getMinimumPoint();
|
||||
int originX = minY.getBlockX();
|
||||
int originY = minY.getBlockY();
|
||||
int originZ = minY.getBlockZ();
|
||||
|
||||
int maxY = region.getMaximumPoint().getBlockY();
|
||||
@ -177,10 +176,10 @@ public class HeightMap {
|
||||
|
||||
BlockStateHolder tmpBlock = BlockTypes.AIR.getDefaultState();
|
||||
|
||||
// Apply heightmap
|
||||
int maxY4 = maxY << 4;
|
||||
int index = 0;
|
||||
|
||||
// Apply heightmap
|
||||
for (int z = 0; z < height; ++z) {
|
||||
int zr = z + originZ;
|
||||
for (int x = 0; x < width; ++x) {
|
||||
|
@ -22,21 +22,17 @@
|
||||
package com.sk89q.worldedit.math.interpolation;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.math.MutableBlockVector3;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* A Kochanek-Bartels interpolation; continuous in the 2nd derivative.
|
||||
* <p>
|
||||
* <p>Supports {@link Node#tension tension}, {@link Node#bias bias} and
|
||||
* {@link Node#continuity continuity} parameters per {@link Node}.</p>
|
||||
*
|
||||
* <p>Supports Node#tension tension, Node#bias bias and
|
||||
* Node#continuity continuity parameters per {@link Node}.</p>
|
||||
*/
|
||||
public class KochanekBartelsInterpolation implements Interpolation {
|
||||
|
||||
@ -48,7 +44,7 @@ public class KochanekBartelsInterpolation implements Interpolation {
|
||||
private double scaling;
|
||||
|
||||
public KochanekBartelsInterpolation() {
|
||||
setNodes(Collections.<Node>emptyList());
|
||||
setNodes(Collections.emptyList());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -86,14 +82,14 @@ public class KochanekBartelsInterpolation implements Interpolation {
|
||||
}
|
||||
|
||||
// Kochanek-Bartels tangent coefficients
|
||||
final double ta = (1 - tensionA) * (1 + biasA) * (1 + continuityA) / 2; // Factor for lhs of d[i]
|
||||
final double tb = (1 - tensionA) * (1 - biasA) * (1 - continuityA) / 2; // Factor for rhs of d[i]
|
||||
final double tc = (1 - tensionB) * (1 + biasB) * (1 - continuityB) / 2; // Factor for lhs of d[i+1]
|
||||
final double td = (1 - tensionB) * (1 - biasB) * (1 + continuityB) / 2; // Factor for rhs of d[i+1]
|
||||
final double ta = (1-tensionA)*(1+biasA)*(1+continuityA)/2; // Factor for lhs of d[i]
|
||||
final double tb = (1-tensionA)*(1-biasA)*(1-continuityA)/2; // Factor for rhs of d[i]
|
||||
final double tc = (1-tensionB)*(1+biasB)*(1-continuityB)/2; // Factor for lhs of d[i+1]
|
||||
final double td = (1-tensionB)*(1-biasB)*(1+continuityB)/2; // Factor for rhs of d[i+1]
|
||||
|
||||
coeffA[i] = linearCombination(i, -ta, ta - tb - tc + 2, tb + tc - td - 2, td);
|
||||
coeffB[i] = linearCombination(i, 2 * ta, -2 * ta + 2 * tb + tc - 3, -2 * tb - tc + td + 3, -td);
|
||||
coeffC[i] = linearCombination(i, -ta, ta - tb, tb, 0);
|
||||
coeffA[i] = linearCombination(i, -ta, ta- tb-tc+2, tb+tc-td-2, td);
|
||||
coeffB[i] = linearCombination(i, 2*ta, -2*ta+2*tb+tc-3, -2*tb-tc+td+3, -td);
|
||||
coeffC[i] = linearCombination(i, -ta, ta- tb , tb , 0);
|
||||
//coeffD[i] = linearCombination(i, 0, 1, 0, 0);
|
||||
coeffD[i] = retrieve(i); // this is an optimization
|
||||
}
|
||||
@ -105,10 +101,10 @@ public class KochanekBartelsInterpolation implements Interpolation {
|
||||
* Returns the linear combination of the given coefficients with the nodes adjacent to baseIndex.
|
||||
*
|
||||
* @param baseIndex node index
|
||||
* @param f1 coefficient for baseIndex-1
|
||||
* @param f2 coefficient for baseIndex
|
||||
* @param f3 coefficient for baseIndex+1
|
||||
* @param f4 coefficient for baseIndex+2
|
||||
* @param f1 coefficient for baseIndex-1
|
||||
* @param f2 coefficient for baseIndex
|
||||
* @param f3 coefficient for baseIndex+1
|
||||
* @param f4 coefficient for baseIndex+2
|
||||
* @return linear combination of nodes[n-1..n+2] with f1..4
|
||||
*/
|
||||
private Vector3 linearCombination(int baseIndex, double f1, double f2, double f3, double f4) {
|
||||
@ -116,6 +112,7 @@ public class KochanekBartelsInterpolation implements Interpolation {
|
||||
final Vector3 r2 = retrieve(baseIndex ).multiply(f2);
|
||||
final Vector3 r3 = retrieve(baseIndex + 1).multiply(f3);
|
||||
final Vector3 r4 = retrieve(baseIndex + 2).multiply(f4);
|
||||
|
||||
return r1.add(r2).add(r3).add(r4);
|
||||
}
|
||||
|
||||
@ -130,7 +127,7 @@ public class KochanekBartelsInterpolation implements Interpolation {
|
||||
return fastRetrieve(0);
|
||||
|
||||
if (index >= nodes.size())
|
||||
return fastRetrieve(nodes.size() - 1);
|
||||
return fastRetrieve(nodes.size()-1);
|
||||
|
||||
return fastRetrieve(index);
|
||||
}
|
||||
@ -184,7 +181,7 @@ public class KochanekBartelsInterpolation implements Interpolation {
|
||||
final Vector3 b = coeffB[index];
|
||||
final Vector3 c = coeffC[index];
|
||||
|
||||
return a.multiply(1.5 * position - 3.0 * index).add(b).multiply(2.0 * position).add(a.multiply(1.5 * index).subtract(b).multiply(2.0 * index)).add(c).multiply(scaling);
|
||||
return a.multiply(1.5*position - 3.0*index).add(b).multiply(2.0*position).add(a.multiply(1.5*index).subtract(b).multiply(2.0*index)).add(c).multiply(scaling);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -212,19 +209,19 @@ public class KochanekBartelsInterpolation implements Interpolation {
|
||||
*/
|
||||
private double arcLengthRecursive(int indexLeft, double remainderLeft, int indexRight, double remainderRight) {
|
||||
switch (indexRight - indexLeft) {
|
||||
case 0:
|
||||
return arcLengthRecursive(indexLeft, remainderLeft, remainderRight);
|
||||
case 0:
|
||||
return arcLengthRecursive(indexLeft, remainderLeft, remainderRight);
|
||||
|
||||
case 1:
|
||||
// This case is merely a speed-up for a very common case
|
||||
return
|
||||
arcLengthRecursive(indexLeft, remainderLeft, 1.0) +
|
||||
arcLengthRecursive(indexRight, 0.0, remainderRight);
|
||||
case 1:
|
||||
// This case is merely a speed-up for a very common case
|
||||
return
|
||||
arcLengthRecursive(indexLeft, remainderLeft, 1.0) +
|
||||
arcLengthRecursive(indexRight, 0.0, remainderRight);
|
||||
|
||||
default:
|
||||
return
|
||||
arcLengthRecursive(indexLeft, remainderLeft, indexRight - 1, 1.0) +
|
||||
arcLengthRecursive(indexRight, 0.0, remainderRight);
|
||||
default:
|
||||
return
|
||||
arcLengthRecursive(indexLeft, remainderLeft, indexRight - 1, 1.0) +
|
||||
arcLengthRecursive(indexRight, 0.0, remainderRight);
|
||||
}
|
||||
}
|
||||
|
||||
@ -236,9 +233,9 @@ public class KochanekBartelsInterpolation implements Interpolation {
|
||||
final int nPoints = 8;
|
||||
|
||||
double accum = a.multiply(remainderLeft).add(b).multiply(remainderLeft).add(c).length() / 2.0;
|
||||
for (int i = 1; i < nPoints - 1; ++i) {
|
||||
for (int i = 1; i < nPoints-1; ++i) {
|
||||
double t = ((double) i) / nPoints;
|
||||
t = (remainderRight - remainderLeft) * t + remainderLeft;
|
||||
t = (remainderRight-remainderLeft)*t + remainderLeft;
|
||||
accum += a.multiply(t).add(b).multiply(t).add(c).length();
|
||||
}
|
||||
|
||||
@ -259,5 +256,4 @@ public class KochanekBartelsInterpolation implements Interpolation {
|
||||
return (int) Math.floor(position);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ public class Node {
|
||||
private double continuity;
|
||||
|
||||
public Node() {
|
||||
this(Vector3.at(0, 0, 0));
|
||||
this(Vector3.ZERO);
|
||||
}
|
||||
|
||||
public Node(Node other) {
|
||||
|
@ -1,17 +1,34 @@
|
||||
/*
|
||||
* 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.transform;
|
||||
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.MathUtils;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.sk89q.worldedit.math.MutableBlockVector3;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.MathUtils;
|
||||
import com.sk89q.worldedit.math.MutableVector3;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
|
||||
/**
|
||||
* An affine transform.
|
||||
* <p>
|
||||
*
|
||||
* <p>This class is from the
|
||||
* <a href="http://geom-java.sourceforge.net/index.html">JavaGeom project</a>,
|
||||
* which is licensed under LGPL v2.1.</p>
|
||||
@ -153,7 +170,7 @@ public class AffineTransform implements Transform, Serializable {
|
||||
*
|
||||
* @return the determinant of the transform.
|
||||
*/
|
||||
public double determinant() {
|
||||
private double determinant() {
|
||||
return m00 * (m11 * m22 - m12 * m21) - m01 * (m10 * m22 - m20 * m12)
|
||||
+ m02 * (m10 * m21 - m20 * m11);
|
||||
}
|
||||
@ -336,4 +353,4 @@ public class AffineTransform implements Transform, Serializable {
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,9 @@
|
||||
package com.sk89q.worldedit.math.transform;
|
||||
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
|
||||
public class RoundedTransform implements Transform{
|
||||
private final Transform transform;
|
||||
// private MutableBlockVector3 mutable = new MutableBlockVector3();
|
||||
|
||||
public RoundedTransform(Transform transform) {
|
||||
this.transform = transform;
|
||||
@ -19,9 +17,6 @@ public class RoundedTransform implements Transform{
|
||||
@Override
|
||||
public Vector3 apply(Vector3 input) {
|
||||
Vector3 val = transform.apply(input);
|
||||
// mutable.mutX((int) Math.floor(val.getX() + 0.5));
|
||||
// mutable.mutY((int) Math.floor(val.getY() + 0.5));
|
||||
// mutable.mutZ((int) Math.floor(val.getZ() + 0.5));
|
||||
return Vector3.at(Math.floor(val.getX() + 0.5), Math.floor(val.getY() + 0.5), Math.floor(val.getY() + 0.5));
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@ public final class Transforms {
|
||||
public static Location transform(Location location, Transform transform) {
|
||||
checkNotNull(location);
|
||||
checkNotNull(transform);
|
||||
return new Location(location.getExtent(), transform.apply(location), location.getDirection());
|
||||
return new Location(location.getExtent(), transform.apply(location.toVector()), location.getDirection());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -166,7 +166,7 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
|
||||
hasY = true;
|
||||
maxY = y;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BlockVector3 getMinimumPoint() {
|
||||
return center.toVector2().subtract(getRadius()).toVector3(minY).toBlockPoint();
|
||||
@ -381,4 +381,5 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion {
|
||||
int maxY = extent.getMaximumPoint().getBlockY();
|
||||
return new CylinderRegion(center, radiusVec, minY, maxY);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -24,7 +24,11 @@ import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* A region that contains no points.
|
||||
|
@ -54,7 +54,7 @@ public interface RegionSelector {
|
||||
|
||||
/**
|
||||
* Called when the first point is selected.
|
||||
*
|
||||
*
|
||||
* @param position the position
|
||||
* @return true if something changed
|
||||
*/
|
||||
@ -62,7 +62,7 @@ public interface RegionSelector {
|
||||
|
||||
/**
|
||||
* Called when the second point is selected.
|
||||
*
|
||||
*
|
||||
* @param position the position
|
||||
* @return true if something changed
|
||||
*/
|
||||
@ -70,7 +70,7 @@ public interface RegionSelector {
|
||||
|
||||
/**
|
||||
* Tell the player information about his/her primary selection.
|
||||
*
|
||||
*
|
||||
* @param actor the actor
|
||||
* @param session the session
|
||||
* @param position position
|
||||
@ -97,7 +97,7 @@ public interface RegionSelector {
|
||||
|
||||
/**
|
||||
* Get the primary position.
|
||||
*
|
||||
*
|
||||
* @return the primary position
|
||||
* @throws IncompleteRegionException thrown if a region has not been fully defined
|
||||
*/
|
||||
@ -105,7 +105,7 @@ public interface RegionSelector {
|
||||
|
||||
/**
|
||||
* Get the selection.
|
||||
*
|
||||
*
|
||||
* @return the created region
|
||||
* @throws IncompleteRegionException thrown if a region has not been fully defined
|
||||
*/
|
||||
@ -113,21 +113,21 @@ public interface RegionSelector {
|
||||
|
||||
/**
|
||||
* Get the region even if it's not fully defined.
|
||||
*
|
||||
*
|
||||
* @return an incomplete region object that is incomplete
|
||||
*/
|
||||
Region getIncompleteRegion();
|
||||
|
||||
/**
|
||||
* Returns whether the region has been fully defined.
|
||||
*
|
||||
*
|
||||
* @return true if a selection is available
|
||||
*/
|
||||
boolean isDefined();
|
||||
|
||||
/**
|
||||
* Get the number of blocks inside the region.
|
||||
*
|
||||
*
|
||||
* @return number of blocks, or -1 if undefined
|
||||
*/
|
||||
int getArea();
|
||||
@ -144,25 +144,16 @@ public interface RegionSelector {
|
||||
|
||||
/**
|
||||
* Get a lowercase name of this region selector type.
|
||||
*
|
||||
*
|
||||
* @return a lower case name of the type
|
||||
*/
|
||||
String getTypeName();
|
||||
|
||||
/**
|
||||
* Get lines of information about the selection.
|
||||
*
|
||||
*
|
||||
* @return a list of lines describing the region
|
||||
*/
|
||||
List<String> getInformationLines();
|
||||
|
||||
/**
|
||||
* Get the verticies
|
||||
* @return
|
||||
* @throws IncompleteRegionException
|
||||
*/
|
||||
default List<BlockVector3> getVerticies() throws IncompleteRegionException {
|
||||
return Collections.singletonList(getPrimaryPosition());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -20,8 +20,8 @@
|
||||
package com.sk89q.worldedit.regions.selector;
|
||||
|
||||
import com.boydti.fawe.config.BBC;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
@ -37,11 +37,13 @@ import com.sk89q.worldedit.regions.polyhedron.Triangle;
|
||||
import com.sk89q.worldedit.regions.selector.limit.SelectorLimits;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
import java.util.*;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Creates a {@code ConvexPolyhedralRegion} from a user's selections.
|
||||
@ -108,11 +110,6 @@ public class ConvexPolyhedralRegionSelector implements RegionSelector, CUIRegion
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BlockVector3> getVerticies() {
|
||||
return new ArrayList<>(region.getVertices());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public World getWorld() {
|
||||
@ -279,5 +276,4 @@ public class ConvexPolyhedralRegionSelector implements RegionSelector, CUIRegion
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -22,14 +22,12 @@ package com.sk89q.worldedit.regions.selector;
|
||||
import com.boydti.fawe.config.BBC;
|
||||
import com.boydti.fawe.config.Commands;
|
||||
import com.boydti.fawe.util.chat.Message;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.command.SelectionCommands;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.internal.cui.CUIRegion;
|
||||
import com.sk89q.worldedit.internal.cui.SelectionPointEvent;
|
||||
@ -39,13 +37,10 @@ import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.regions.RegionSelector;
|
||||
import com.sk89q.worldedit.regions.selector.limit.SelectorLimits;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Creates a {@code CuboidRegion} from a user's selections.
|
||||
@ -96,6 +91,7 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion {
|
||||
position1 = oldRegion.getMinimumPoint();
|
||||
position2 = oldRegion.getMaximumPoint();
|
||||
}
|
||||
|
||||
region.setPos1(position1);
|
||||
region.setPos2(position2);
|
||||
}
|
||||
@ -103,7 +99,7 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion {
|
||||
/**
|
||||
* Create a new region selector with the given two positions.
|
||||
*
|
||||
* @param world the world
|
||||
* @param world the world
|
||||
* @param position1 position 1
|
||||
* @param position2 position 2
|
||||
*/
|
||||
@ -117,11 +113,6 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion {
|
||||
region.setPos2(position2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BlockVector3> getVerticies() {
|
||||
return Arrays.asList(position1, position2);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public World getWorld() {
|
||||
@ -317,5 +308,4 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion {
|
||||
return "cuboid";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -20,8 +20,8 @@
|
||||
package com.sk89q.worldedit.regions.selector;
|
||||
|
||||
import com.boydti.fawe.config.BBC;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
@ -38,13 +38,11 @@ import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.regions.RegionSelector;
|
||||
import com.sk89q.worldedit.regions.selector.limit.SelectorLimits;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Creates a {@code CylinderRegionSelector} from a user's selections.
|
||||
|
@ -20,8 +20,8 @@
|
||||
package com.sk89q.worldedit.regions.selector;
|
||||
|
||||
import com.boydti.fawe.config.BBC;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
@ -35,12 +35,10 @@ import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.regions.RegionSelector;
|
||||
import com.sk89q.worldedit.regions.selector.limit.SelectorLimits;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Creates a {@code EllipsoidRegionSelector} from a user's selections.
|
||||
@ -251,5 +249,4 @@ public class EllipsoidRegionSelector implements RegionSelector, CUIRegion {
|
||||
return region.getCenter().toBlockPoint();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -142,5 +142,4 @@ public class ExtendingCuboidRegionSelector extends CuboidRegionSelector {
|
||||
explainRegionAdjust(player, session);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -20,8 +20,8 @@
|
||||
package com.sk89q.worldedit.regions.selector;
|
||||
|
||||
import com.boydti.fawe.config.BBC;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
@ -36,13 +36,11 @@ import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.regions.RegionSelector;
|
||||
import com.sk89q.worldedit.regions.selector.limit.SelectorLimits;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Creates a {@code Polygonal2DRegion} from a user's selections.
|
||||
@ -114,7 +112,7 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIRegion {
|
||||
*/
|
||||
public Polygonal2DRegionSelector(@Nullable World world, List<BlockVector2> points, int minY, int maxY) {
|
||||
checkNotNull(points);
|
||||
|
||||
|
||||
final BlockVector2 pos2D = points.get(0);
|
||||
pos1 = BlockVector3.at(pos2D.getX(), minY, pos2D.getZ());
|
||||
region = new Polygonal2DRegion(world, points, minY, maxY);
|
||||
|
@ -79,17 +79,17 @@ public abstract class ArbitraryBiomeShape {
|
||||
*
|
||||
* @param x X coordinate to be queried
|
||||
* @param z Z coordinate to be queried
|
||||
* @param defaultBiomeType The default biome for the current column.
|
||||
* @param defaultBaseBiome The default biome for the current column.
|
||||
* @return material to place or null to not place anything.
|
||||
*/
|
||||
protected abstract BiomeType getBiome(int x, int z, BiomeType defaultBiomeType);
|
||||
protected abstract BiomeType getBiome(int x, int z, BiomeType defaultBaseBiome);
|
||||
|
||||
private BiomeType getBiomeCached(int x, int z, BiomeType biomeType) {
|
||||
private BiomeType getBiomeCached(int x, int z, BiomeType baseBiome) {
|
||||
final int index = (z - cacheOffsetZ) + (x - cacheOffsetX) * cacheSizeZ;
|
||||
|
||||
final BiomeType cacheEntry = cache[index];
|
||||
if (cacheEntry == null) {// unknown, fetch material
|
||||
final BiomeType material = getBiome(x, z, biomeType);
|
||||
final BiomeType material = getBiome(x, z, baseBiome);
|
||||
if (material == null) {
|
||||
// outside
|
||||
cache[index] = BiomeTypes.THE_VOID;
|
||||
@ -108,13 +108,13 @@ public abstract class ArbitraryBiomeShape {
|
||||
return cacheEntry;
|
||||
}
|
||||
|
||||
private boolean isInsideCached(int x, int z, BiomeType biomeType) {
|
||||
private boolean isInsideCached(int x, int z, BiomeType baseBiome) {
|
||||
final int index = (z - cacheOffsetZ) + (x - cacheOffsetX) * cacheSizeZ;
|
||||
|
||||
final BiomeType cacheEntry = cache[index];
|
||||
if (cacheEntry == null) {
|
||||
// unknown block, meaning they must be outside the extent at this stage, but might still be inside the shape
|
||||
return getBiomeCached(x, z, biomeType) != null;
|
||||
return getBiomeCached(x, z, baseBiome) != null;
|
||||
}
|
||||
|
||||
return cacheEntry != BiomeTypes.THE_VOID;
|
||||
@ -124,11 +124,11 @@ public abstract class ArbitraryBiomeShape {
|
||||
* Generates the shape.
|
||||
*
|
||||
* @param editSession The EditSession to use.
|
||||
* @param biomeType The default biome type.
|
||||
* @param baseBiome The default biome type.
|
||||
* @param hollow Specifies whether to generate a hollow shape.
|
||||
* @return number of affected blocks.
|
||||
*/
|
||||
public int generate(EditSession editSession, BiomeType biomeType, boolean hollow) {
|
||||
public int generate(EditSession editSession, BiomeType baseBiome, boolean hollow) {
|
||||
int affected = 0;
|
||||
|
||||
for (BlockVector2 position : getExtent()) {
|
||||
@ -136,7 +136,7 @@ public abstract class ArbitraryBiomeShape {
|
||||
int z = position.getBlockZ();
|
||||
|
||||
if (!hollow) {
|
||||
final BiomeType material = getBiome(x, z, biomeType);
|
||||
final BiomeType material = getBiome(x, z, baseBiome);
|
||||
if (material != null && material != BiomeTypes.THE_VOID) {
|
||||
editSession.getWorld().setBiome(position, material);
|
||||
++affected;
|
||||
@ -145,26 +145,26 @@ public abstract class ArbitraryBiomeShape {
|
||||
continue;
|
||||
}
|
||||
|
||||
final BiomeType material = getBiomeCached(x, z, biomeType);
|
||||
final BiomeType material = getBiomeCached(x, z, baseBiome);
|
||||
if (material == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean draw = false;
|
||||
do {
|
||||
if (!isInsideCached(x + 1, z, biomeType)) {
|
||||
if (!isInsideCached(x + 1, z, baseBiome)) {
|
||||
draw = true;
|
||||
break;
|
||||
}
|
||||
if (!isInsideCached(x - 1, z, biomeType)) {
|
||||
if (!isInsideCached(x - 1, z, baseBiome)) {
|
||||
draw = true;
|
||||
break;
|
||||
}
|
||||
if (!isInsideCached(x, z + 1, biomeType)) {
|
||||
if (!isInsideCached(x, z + 1, baseBiome)) {
|
||||
draw = true;
|
||||
break;
|
||||
}
|
||||
if (!isInsideCached(x, z - 1, biomeType)) {
|
||||
if (!isInsideCached(x, z - 1, baseBiome)) {
|
||||
draw = true;
|
||||
break;
|
||||
}
|
||||
|
@ -27,10 +27,10 @@ import com.sk89q.worldedit.math.MutableVector3;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
|
||||
public class WorldEditExpressionEnvironment implements ExpressionEnvironment {
|
||||
|
||||
private final Vector3 unit;
|
||||
private final Vector3 zero2;
|
||||
private Vector3 current = new MutableVector3(Vector3.ZERO);
|
||||
private EditSession editSession;
|
||||
private Extent extent;
|
||||
|
||||
public WorldEditExpressionEnvironment(EditSession editSession, Vector3 unit, Vector3 zero) {
|
||||
@ -90,5 +90,4 @@ public class WorldEditExpressionEnvironment implements ExpressionEnvironment {
|
||||
this.current = current;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Einige Dateien werden nicht angezeigt, da zu viele Dateien in diesem Diff geändert wurden Mehr anzeigen
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren