geforkt von Mirrors/FastAsyncWorldEdit
Dieser Commit ist enthalten in:
Ursprung
f1e98da01f
Commit
58c6b6278f
@ -257,12 +257,21 @@ public class LocalBlockVectorSet implements Set<BlockVector3> {
|
||||
|
||||
@Override
|
||||
public boolean containsAll(Collection<?> c) {
|
||||
return c.stream().allMatch(this::contains);
|
||||
for (Object o : c) {
|
||||
if (!contains(o)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(Collection<? extends BlockVector3> c) {
|
||||
return c.stream().map(this::add).reduce(false, (a, b) -> a || b);
|
||||
boolean result = false;
|
||||
for (BlockVector3 v : c) {
|
||||
result |= add(v);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -290,7 +299,11 @@ public class LocalBlockVectorSet implements Set<BlockVector3> {
|
||||
|
||||
@Override
|
||||
public boolean removeAll(Collection<?> c) {
|
||||
return c.stream().map(this::remove).reduce(false, (a, b) -> a || b);
|
||||
boolean result = false;
|
||||
for (Object o : c) {
|
||||
result |= remove(o);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void forEach(BlockVectorSetVisitor visitor) {
|
||||
|
@ -19,6 +19,8 @@
|
||||
|
||||
package com.sk89q.jnbt;
|
||||
|
||||
import com.boydti.fawe.object.io.LittleEndianOutputStream;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.io.Closeable;
|
||||
@ -66,6 +68,15 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da
|
||||
return os;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use a little endian output stream
|
||||
*/
|
||||
public void setLittleEndian() {
|
||||
if (!(os instanceof LittleEndianOutputStream)) {
|
||||
this.os = new LittleEndianOutputStream((OutputStream) os);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a tag.
|
||||
*
|
||||
@ -79,11 +90,7 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da
|
||||
checkNotNull(tag);
|
||||
|
||||
int type = NBTUtils.getTypeCode(tag.getClass());
|
||||
byte[] nameBytes = name.getBytes(NBTConstants.CHARSET);
|
||||
|
||||
os.writeByte(type);
|
||||
os.writeShort(nameBytes.length);
|
||||
os.write(nameBytes);
|
||||
writeNamedTagName(name, type);
|
||||
|
||||
if (type == NBTConstants.TYPE_END) {
|
||||
throw new IOException("Named TAG_End not permitted.");
|
||||
|
@ -192,20 +192,11 @@ public class BiomeCommands extends MethodCommands {
|
||||
Collections.sort(distribution);
|
||||
for (Countable<BiomeType> c : distribution) {
|
||||
BiomeData data = biomeRegistry.getData(c.getID());
|
||||
String str;
|
||||
if (data == null) {
|
||||
str = String.format("%-7s (%.3f%%) %s #%d",
|
||||
String str = String.format("%-7s (%.3f%%) %s #%d",
|
||||
String.valueOf(c.getAmount()),
|
||||
c.getAmount() / (double) size * 100,
|
||||
"Unknown",
|
||||
data == null ? "Unknown" : data.getName(),
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -68,11 +68,10 @@ public class AreaPickaxe implements BlockTool {
|
||||
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) {
|
||||
BlockVector3 pos = BlockVector3.at(x, y, z);
|
||||
if (editSession.getLazyBlock(pos).getBlockType() != initialType) {
|
||||
if (editSession.getLazyBlock(x, y, z).getBlockType() != initialType) {
|
||||
continue;
|
||||
}
|
||||
editSession.setBlock(pos, BlockTypes.AIR.getDefaultState());
|
||||
editSession.setBlock(x, y, z, BlockTypes.AIR.getDefaultState());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,9 +25,11 @@ 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.boydti.fawe.object.clipboard.WorldCopyClipboard;
|
||||
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;
|
||||
@ -408,4 +410,17 @@ public interface Extent extends InputExtent, OutputExtent {
|
||||
default int getMaxY() {
|
||||
return 255;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ 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;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
@ -111,7 +112,7 @@ public interface ClipboardFormat {
|
||||
* @param in
|
||||
* @throws IOException
|
||||
*/
|
||||
default void hold(Player player, URI uri, InputStream in) throws IOException {
|
||||
default URIClipboardHolder hold(Player player, URI uri, InputStream in) throws IOException {
|
||||
checkNotNull(player);
|
||||
checkNotNull(uri);
|
||||
checkNotNull(in);
|
||||
@ -125,6 +126,7 @@ 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 {
|
||||
|
@ -143,11 +143,10 @@ public class SpongeSchematicWriter implements ClipboardWriter {
|
||||
@Override
|
||||
public <B extends BlockStateHolder<B>> void run(int x, int y, int z, B block) {
|
||||
try {
|
||||
boolean hasNbt = block instanceof BaseBlock && block.hasNbtData();
|
||||
if (hasNbt) {
|
||||
if (block.getNbtData() != null) {
|
||||
BaseBlock localBlock = (BaseBlock) block;
|
||||
Map<String, Tag> values = localBlock.getNbtData().getValue();
|
||||
if (block.hasNbtData()) {
|
||||
CompoundTag nbt = block.getNbtData();
|
||||
if (nbt != null) {
|
||||
Map<String, Tag> values = nbt.getValue();
|
||||
|
||||
values.remove("id"); // Remove 'id' if it exists. We want 'Id'
|
||||
|
||||
@ -164,7 +163,7 @@ public class SpongeSchematicWriter implements ClipboardWriter {
|
||||
z
|
||||
}));
|
||||
numTiles[0]++;
|
||||
tilesOut.writeTagPayload(localBlock.getNbtData());
|
||||
tilesOut.writeTagPayload(block.getNbtData());
|
||||
}
|
||||
}
|
||||
int ordinal = block.getOrdinal();
|
||||
|
@ -26,6 +26,7 @@ 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.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
@ -35,7 +36,13 @@ public class SignCompatibilityHandler implements NBTCompatibilityHandler {
|
||||
|
||||
@Override
|
||||
public <B extends BlockStateHolder<B>> boolean isAffectedBlock(B block) {
|
||||
return block.getBlockType() == BlockTypes.SIGN || block.getBlockType() == BlockTypes.WALL_SIGN;
|
||||
switch (block.getBlockType().getInternalId()) {
|
||||
case BlockID.SIGN:
|
||||
case BlockID.WALL_SIGN:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
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;
|
||||
@ -26,17 +27,23 @@ 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 Map<BlockType, Integer> missingBlocks = new HashMap<>();
|
||||
private final boolean mine;
|
||||
private int[] missingBlocks = new int[BlockTypes.size()];
|
||||
private BlockBag blockBag;
|
||||
|
||||
/**
|
||||
@ -45,9 +52,15 @@ public class BlockBagExtent extends AbstractDelegateExtent {
|
||||
* @param extent the extent
|
||||
* @param blockBag the block bag
|
||||
*/
|
||||
public BlockBagExtent(Extent extent, @Nullable BlockBag blockBag) {
|
||||
public BlockBagExtent(Extent extent, @Nonnull BlockBag blockBag) {
|
||||
this(extent, blockBag, false);
|
||||
}
|
||||
|
||||
public BlockBagExtent(Extent extent, @Nonnull BlockBag blockBag, boolean mine) {
|
||||
super(extent);
|
||||
checkNotNull(blockBag);
|
||||
this.blockBag = blockBag;
|
||||
this.mine = mine;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -75,9 +88,15 @@ public class BlockBagExtent extends AbstractDelegateExtent {
|
||||
* @return a map of missing blocks
|
||||
*/
|
||||
public Map<BlockType, Integer> popMissing() {
|
||||
Map<BlockType, Integer> missingBlocks = this.missingBlocks;
|
||||
this.missingBlocks = new HashMap<>();
|
||||
return missingBlocks;
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -95,17 +114,13 @@ public class BlockBagExtent extends AbstractDelegateExtent {
|
||||
try {
|
||||
blockBag.fetchPlacedBlock(block.toImmutableState());
|
||||
} catch (UnplaceableBlockException e) {
|
||||
return false;
|
||||
throw new FaweException.FaweBlockBagException();
|
||||
} catch (BlockBagException e) {
|
||||
if (!missingBlocks.containsKey(block.getBlockType())) {
|
||||
missingBlocks.put(block.getBlockType(), 1);
|
||||
} else {
|
||||
missingBlocks.put(block.getBlockType(), missingBlocks.get(block.getBlockType()) + 1);
|
||||
}
|
||||
return false;
|
||||
missingBlocks[block.getBlockType().getInternalId()]++;
|
||||
throw new FaweException.FaweBlockBagException();
|
||||
}
|
||||
}
|
||||
|
||||
if (mine) {
|
||||
if (!existing.getBlockType().getMaterial().isAir()) {
|
||||
try {
|
||||
blockBag.storeDroppedBlock(existing);
|
||||
@ -114,6 +129,7 @@ public class BlockBagExtent extends AbstractDelegateExtent {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return super.setBlock(x, y, z, block);
|
||||
}
|
||||
|
@ -85,17 +85,27 @@ public class BlockTransformExtent extends ResettableExtent {
|
||||
|
||||
|
||||
private static long combine(Direction... directions) {
|
||||
return Arrays.stream(directions).mapToLong(dir -> (1L << dir.ordinal())).reduce(0, (a, b) -> a | b);
|
||||
long mask = 0;
|
||||
for (Direction dir : directions) {
|
||||
mask = mask | (1L << dir.ordinal());
|
||||
}
|
||||
return mask;
|
||||
}
|
||||
|
||||
private static long[] adapt(Direction... dirs) {
|
||||
long[] arr = new long[dirs.length];
|
||||
Arrays.setAll(arr, i -> 1L << dirs[i].ordinal());
|
||||
for (int i = 0; i < arr.length; i++) {
|
||||
arr[i] = 1L << dirs[i].ordinal();
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
private static long[] adapt(Long... dirs) {
|
||||
return Arrays.stream(dirs).mapToLong(dir -> dir).toArray();
|
||||
long[] arr = new long[dirs.length];
|
||||
for (int i = 0; i < arr.length; i++) {
|
||||
arr[i] = dirs[i];
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
private static long[] getDirections(AbstractProperty property) {
|
||||
@ -209,7 +219,9 @@ public class BlockTransformExtent extends ResettableExtent {
|
||||
}
|
||||
|
||||
private static long notIndex(long mask, int... indexes) {
|
||||
mask |= Arrays.stream(indexes).mapToLong(index -> (1L << (index + values().length))).reduce(0, (a, b) -> a | b);
|
||||
for (int index : indexes) {
|
||||
mask = mask | (1L << (index + values().length));
|
||||
}
|
||||
return mask;
|
||||
}
|
||||
|
||||
@ -421,8 +433,7 @@ public class BlockTransformExtent extends ResettableExtent {
|
||||
* @return the same block
|
||||
*/
|
||||
public static <B extends BlockStateHolder<B>> B transform(B block, Transform transform) {
|
||||
checkNotNull(block);
|
||||
checkNotNull(transform);
|
||||
// performance critical
|
||||
BlockState state = block.toImmutableState();
|
||||
|
||||
int transformedId = transformState(state, transform);
|
||||
|
@ -260,11 +260,7 @@ public class BaseBlock implements BlockStateHolder<BaseBlock> {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int ret = toImmutableState().hashCode() << 3;
|
||||
if (hasNbtData()) {
|
||||
ret += getNbtData().hashCode();
|
||||
}
|
||||
return ret;
|
||||
return getOrdinal();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -849,4 +849,8 @@ public final class ItemTypes {
|
||||
public static int size() {
|
||||
return ItemType.REGISTRY.size();
|
||||
}
|
||||
|
||||
public static Collection<ItemType> values() {
|
||||
return ItemType.REGISTRY.values();
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren