mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-04 03:56:41 +00:00
Upstream, generics, formatting
This commit is contained in:
@ -19,11 +19,11 @@
|
||||
|
||||
package com.sk89q.worldedit.extent;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
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 com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
@ -41,7 +41,7 @@ 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;
|
||||
|
@ -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;
|
||||
|
@ -22,12 +22,10 @@ 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;
|
||||
|
||||
/**
|
||||
|
@ -61,7 +61,7 @@ public interface Clipboard extends Extent {
|
||||
|
||||
/**
|
||||
* 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}
|
||||
* 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.
|
||||
*
|
||||
|
@ -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;
|
||||
|
@ -31,30 +31,19 @@ import com.boydti.fawe.object.clipboard.MemoryOptimizedClipboard;
|
||||
import com.boydti.fawe.object.io.FastByteArrayOutputStream;
|
||||
import com.boydti.fawe.object.io.FastByteArraysInputStream;
|
||||
import com.boydti.fawe.util.IOUtil;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.sk89q.jnbt.ByteArrayTag;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.jnbt.IntArrayTag;
|
||||
import com.sk89q.jnbt.IntTag;
|
||||
import com.sk89q.jnbt.ListTag;
|
||||
import com.sk89q.jnbt.NBTInputStream;
|
||||
import com.sk89q.jnbt.NamedTag;
|
||||
import com.sk89q.jnbt.ShortTag;
|
||||
import com.sk89q.jnbt.StringTag;
|
||||
import com.sk89q.jnbt.Tag;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.world.biome.BiomeTypes;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.legacycompat.NBTCompatibilityHandler;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.world.biome.BiomeTypes;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
import com.sk89q.worldedit.world.entity.EntityType;
|
||||
@ -67,13 +56,11 @@ import org.slf4j.LoggerFactory;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
@ -110,7 +97,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,8 +119,8 @@ public class SpongeSchematicReader extends NBTSchematicReader {
|
||||
return fc = new MemoryOptimizedClipboard(size, 1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
private Clipboard readVersion1(UUID uuid) throws IOException {
|
||||
|
||||
private BlockArrayClipboard readVersion1(UUID uuid) throws IOException {
|
||||
width = height = length = offsetX = offsetY = offsetZ = Integer.MIN_VALUE;
|
||||
|
||||
final BlockArrayClipboard clipboard = new BlockArrayClipboard(new CuboidRegion(BlockVector3.at(0, 0, 0), BlockVector3.at(0, 0, 0)), fc);
|
||||
@ -176,39 +163,33 @@ public class SpongeSchematicReader extends NBTSchematicReader {
|
||||
}
|
||||
}
|
||||
});
|
||||
streamer.addReader("Schematic.TileEntities.#", new BiConsumer<Integer, CompoundTag>() {
|
||||
@Override
|
||||
public void accept(Integer index, CompoundTag value) {
|
||||
if (fc == null) {
|
||||
setupClipboard(0, uuid);
|
||||
}
|
||||
int[] pos = value.getIntArray("Pos");
|
||||
int x = pos[0];
|
||||
int y = pos[1];
|
||||
int z = pos[2];
|
||||
fc.setTile(x, y, z, value);
|
||||
streamer.addReader("Schematic.TileEntities.#", (BiConsumer<Integer, CompoundTag>) (index, value) -> {
|
||||
if (fc == null) {
|
||||
setupClipboard(0, uuid);
|
||||
}
|
||||
int[] pos = value.getIntArray("Pos");
|
||||
int x = pos[0];
|
||||
int y = pos[1];
|
||||
int z = pos[2];
|
||||
fc.setTile(x, y, z, value);
|
||||
});
|
||||
streamer.addReader("Schematic.Entities.#", new BiConsumer<Integer, CompoundTag>() {
|
||||
@Override
|
||||
public void accept(Integer index, CompoundTag compound) {
|
||||
if (fc == null) {
|
||||
setupClipboard(0, uuid);
|
||||
}
|
||||
String id = compound.getString("id");
|
||||
if (id.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
ListTag positionTag = compound.getListTag("Pos");
|
||||
ListTag directionTag = compound.getListTag("Rotation");
|
||||
EntityType type = EntityTypes.parse(id);
|
||||
if (type != null) {
|
||||
compound.getValue().put("Id", new StringTag(type.getId()));
|
||||
BaseEntity state = new BaseEntity(type, compound);
|
||||
fc.createEntity(clipboard, positionTag.asDouble(0), positionTag.asDouble(1), positionTag.asDouble(2), (float) directionTag.asDouble(0), (float) directionTag.asDouble(1), state);
|
||||
} else {
|
||||
Fawe.debug("Invalid entity: " + id);
|
||||
}
|
||||
streamer.addReader("Schematic.Entities.#", (BiConsumer<Integer, CompoundTag>) (index, compound) -> {
|
||||
if (fc == null) {
|
||||
setupClipboard(0, uuid);
|
||||
}
|
||||
String id = compound.getString("id");
|
||||
if (id.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
ListTag positionTag = compound.getListTag("Pos");
|
||||
ListTag directionTag = compound.getListTag("Rotation");
|
||||
EntityType type = EntityTypes.parse(id);
|
||||
if (type != null) {
|
||||
compound.getValue().put("Id", new StringTag(type.getId()));
|
||||
BaseEntity state = new BaseEntity(type, compound);
|
||||
fc.createEntity(clipboard, positionTag.asDouble(0), positionTag.asDouble(1), positionTag.asDouble(2), (float) directionTag.asDouble(0), (float) directionTag.asDouble(1), state);
|
||||
} else {
|
||||
Fawe.debug("Invalid entity: " + id);
|
||||
}
|
||||
});
|
||||
streamer.readFully();
|
||||
@ -235,6 +216,7 @@ public class SpongeSchematicReader extends NBTSchematicReader {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if (biomesOut.getSize() != 0) {
|
||||
try (FaweInputStream fis = new FaweInputStream(new LZ4BlockInputStream(new FastByteArraysInputStream(biomesOut.toByteArrays())))) {
|
||||
@ -249,7 +231,6 @@ public class SpongeSchematicReader extends NBTSchematicReader {
|
||||
return clipboard;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
inputStream.close();
|
||||
|
@ -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,18 @@ 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;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* 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 +46,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,15 +76,9 @@ 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
|
||||
@ -114,19 +96,21 @@ public class BlockBagExtent extends AbstractDelegateExtent {
|
||||
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) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -252,4 +252,4 @@ public class MultiStageReorder extends AbstractDelegateExtent implements Reorder
|
||||
|
||||
return new OperationQueue(operations);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -54,6 +54,10 @@ 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;
|
||||
@ -407,6 +411,11 @@ public class BlockTransformExtent extends ResettableExtent {
|
||||
return super.setExtent(extent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the transform.
|
||||
*
|
||||
* @return the transform
|
||||
*/
|
||||
public Transform getTransform() {
|
||||
return transform;
|
||||
}
|
||||
@ -496,6 +505,36 @@ public class BlockTransformExtent extends ResettableExtent {
|
||||
return super.setBlock(x, y, z, transformInverse(block));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the new value with the transformed direction.
|
||||
*
|
||||
* @param allowedStates the allowed states
|
||||
* @param transform the transform
|
||||
* @param oldDirection the old direction to transform
|
||||
* @return a new state or null if none could be found
|
||||
*/
|
||||
@Nullable
|
||||
private static Vector3 getNewStateValue(List<Direction> allowedStates, Transform transform, Vector3 oldDirection) {
|
||||
Vector3 newDirection = transform.apply(oldDirection).subtract(transform.apply(Vector3.ZERO)).normalize();
|
||||
Vector3 newValue = null;
|
||||
double closest = -2;
|
||||
boolean found = false;
|
||||
|
||||
for (Direction v : allowedStates) {
|
||||
double dot = v.toVector().normalize().dot(newDirection);
|
||||
if (dot >= closest) {
|
||||
closest = dot;
|
||||
newValue = v.toVector();
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (found) {
|
||||
return newValue;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException {
|
||||
|
@ -28,8 +28,6 @@ import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Makes changes to the world as if a player had done so during survival mode.
|
||||
*
|
||||
|
Reference in New Issue
Block a user