Selective upstream merge

Signed-off-by: MattBDev <4009945+MattBDev@users.noreply.github.com>
This commit is contained in:
MattBDev
2019-06-04 11:48:30 -04:00
parent c73fc28847
commit 6c94cca15e
75 changed files with 1039 additions and 1182 deletions

View File

@ -43,8 +43,12 @@ 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;
/**
* A base class for {@link Extent}s that merely passes extents onto another.
*/
public class AbstractDelegateExtent implements LightingExtent {
private transient final Extent extent;
protected MutableBlockVector3 mutable = new MutableBlockVector3(0, 0, 0);
@ -264,8 +268,7 @@ public class AbstractDelegateExtent implements LightingExtent {
}
@Override
public @Nullable
Operation commit() {
public @Nullable Operation commit() {
Operation ours = commitBefore();
Operation other = null;
if (extent != this) other = extent.commit();

View File

@ -40,11 +40,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 static com.google.common.base.Preconditions.checkNotNull;
import javax.annotation.Nullable;
/**
* Stores changes to a {@link ChangeSet}.

View File

@ -30,22 +30,18 @@ import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Requires that all mutating methods pass a given {@link Mask}.
*/
public class MaskingExtent extends AbstractDelegateExtent {
private Mask mask;
// private MutableBlockVector3 mutable = new MutableBlockVector3();
/**
* Create a new instance.
*
* @param extent the extent
* @param mask the mask
* @param mask the mask
*/
public MaskingExtent(Extent extent, Mask mask) {
super(extent);

View File

@ -34,10 +34,11 @@ import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockTypes;
import javax.annotation.Nullable;
import java.util.Collections;
import java.util.List;
import javax.annotation.Nullable;
/**
* An extent that returns air blocks for all blocks and does not
* pass on any changes.

View File

@ -28,12 +28,6 @@ import com.boydti.fawe.object.extent.LightingExtent;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockState;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.function.operation.Operation;
@ -41,15 +35,18 @@ import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.biome.BiomeType;
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 javax.annotation.Nullable;
import java.io.Closeable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import javax.annotation.Nullable;
import static com.google.common.base.Preconditions.checkNotNull;
@ -63,27 +60,21 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
private BlockVector3 origin;
public FaweClipboard IMP;
private BlockVector3 size;
private int mx;
private int my;
private int mz;
private BlockStateHolder[][][] blocks;
private final List<ClipboardEntity> entities = new ArrayList<>();
public BlockArrayClipboard(Region region) {
checkNotNull(region);
this.region = region.clone();
this.size = getDimensions();
this.IMP = Settings.IMP.CLIPBOARD.USE_DISK ? new DiskOptimizedClipboard(size.getBlockX(), size.getBlockY(), size.getBlockZ()) : new MemoryOptimizedClipboard(size.getBlockX(), size.getBlockY(), size.getBlockZ());
this.origin = region.getMinimumPoint();
this.mx = origin.getBlockX();
this.my = origin.getBlockY();
this.mz = origin.getBlockZ();
this.blocks = new BlockStateHolder[size.getBlockX()][size.getBlockY()][size.getBlockZ()];
}
/**
* Create a new instance.
* <p>
*
* <p>The origin will be placed at the region's lowest minimum point.</p>
*
* @param region the bounding region
@ -94,9 +85,6 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
this.size = getDimensions();
this.IMP = Settings.IMP.CLIPBOARD.USE_DISK ? new DiskOptimizedClipboard(size.getBlockX(), size.getBlockY(), size.getBlockZ(), clipboardId) : new MemoryOptimizedClipboard(size.getBlockX(), size.getBlockY(), size.getBlockZ());
this.origin = region.getMinimumPoint();
this.mx = origin.getBlockX();
this.my = origin.getBlockY();
this.mz = origin.getBlockZ();
this.blocks = new BlockStateHolder[size.getBlockX()][size.getBlockY()][size.getBlockZ()];
}
@ -105,9 +93,6 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
this.region = region.clone();
this.size = getDimensions();
this.origin = region.getMinimumPoint();
this.mx = origin.getBlockX();
this.my = origin.getBlockY();
this.mz = origin.getBlockZ();
this.IMP = clipboard;
this.blocks = new BlockStateHolder[size.getBlockX()][size.getBlockY()][size.getBlockZ()];
}
@ -119,9 +104,6 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
this.size = getDimensions();
this.IMP = fc;
this.origin = region.getMinimumPoint();
this.mx = origin.getBlockX();
this.my = origin.getBlockY();
this.mz = origin.getBlockZ();
this.blocks = new BlockStateHolder[size.getBlockX()][size.getBlockY()][size.getBlockZ()];
}
@ -196,12 +178,11 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
@Override
public BlockState getBlock(BlockVector3 position) {
if (region.contains(position)) {
int x = position.getBlockX() - mx;
int y = position.getBlockY() - my;
int z = position.getBlockZ() - mz;
return IMP.getBlock(x, y, z).toImmutableState();
BlockVector3 v = position.subtract(region.getMinimumPoint());
return IMP.getBlock(v.getX(),v.getY(),v.getZ()).toImmutableState();
}
return EditSession.nullBlock;
return BlockTypes.AIR.getDefaultState();
}
public BlockState getBlockAbs(int x, int y, int z) {
@ -215,13 +196,12 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
@Override
public BaseBlock getFullBlock(BlockVector3 position) {
if(region.contains(position)) {
int x = position.getBlockX() - mx;
int y = position.getBlockY() - my;
int z = position.getBlockZ() - mz;
return IMP.getBlock(x, y, z);
if (region.contains(position)) {
BlockVector3 v = position.subtract(region.getMinimumPoint());
return IMP.getBlock(v.getX(),v.getY(),v.getZ());
}
return EditSession.nullBlock.toBaseBlock();
return BlockTypes.AIR.getDefaultState().toBaseBlock();
}
@Override
@ -235,33 +215,28 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
return false;
}
public boolean setTile(int x, int y, int z, CompoundTag tag) {
x -= mx;
y -= my;
z -= mz;
return IMP.setTile(x, y, z, tag);
public boolean setTile(BlockVector3 position, CompoundTag tag) {
BlockVector3 v = position.subtract(region.getMinimumPoint());
return IMP.setTile(v.getX(), v.getY(), v.getZ(), tag);
}
@Override
public <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block) throws WorldEditException {
x -= mx;
y -= my;
z -= mz;
return IMP.setBlock(x, y, z, block);
BlockVector3 position = BlockVector3.at(x, y, z);
BlockVector3 v = position.subtract(region.getMinimumPoint());
return IMP.setBlock(v.getX(), v.getY(), v.getZ(), block);
}
@Override
public BiomeType getBiome(BlockVector2 position) {
int x = position.getBlockX() - mx;
int z = position.getBlockZ() - mz;
return IMP.getBiome(x, z);
BlockVector2 v = position.subtract(region.getMinimumPoint().toBlockVector2());
return IMP.getBiome(v.getX(), v.getZ());
}
@Override
public boolean setBiome(BlockVector2 position, BiomeType biome) {
int x = position.getBlockX() - mx;
int z = position.getBlockZ() - mz;
IMP.setBiome(x, z, biome);
BlockVector2 v = position.subtract(region.getMinimumPoint().toBlockVector2());
IMP.setBiome(v.getX(), v.getZ(), biome);
return true;
}
@ -297,4 +272,4 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable
public int getBrightness(int x, int y, int z) {
return getBlock(BlockVector3.at(x, y, z)).getBlockType().getMaterial().getLightValue();
}
}
}

View File

@ -20,6 +20,7 @@
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;
@ -58,4 +59,15 @@ 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;
}
}

View File

@ -1,12 +1,28 @@
/*
* 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.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;
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;
@ -33,7 +49,7 @@ public class BlockBagExtent extends AbstractDelegateExtent {
/**
* Create a new instance.
*
* @param extent the extent
* @param extent the extent
* @param blockBag the block bag
*/
public BlockBagExtent(Extent extent, @Nonnull BlockBag blockBag) {
@ -52,9 +68,7 @@ public class BlockBagExtent extends AbstractDelegateExtent {
*
* @return a block bag, which may be null if none is used
*/
public
@Nullable
BlockBag getBlockBag() {
public @Nullable BlockBag getBlockBag() {
return blockBag;
}
@ -92,34 +106,32 @@ public class BlockBagExtent extends AbstractDelegateExtent {
@Override
public <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block) throws WorldEditException {
if(blockBag != null) {
BlockStateHolder lazyBlock = getExtent().getLazyBlock(x, y, z);
BlockType fromType = lazyBlock.getBlockType();
if(!block.getBlockType().equals(fromType)) {
BlockType type = block.getBlockType();
if (!type.getMaterial().isAir()) {
try {
blockBag.fetchPlacedBlock(block.toImmutableState());
} catch (UnplaceableBlockException e) {
throw new FaweException.FaweBlockBagException();
} catch (BlockBagException e) {
missingBlocks[type.getInternalId()]++;
throw new FaweException.FaweBlockBagException();
}
}
if (mine) {
if (!fromType.getMaterial().isAir()) {
try {
blockBag.storeDroppedBlock(fromType.getDefaultState());
} catch (BlockBagException ignored) {
}
}
}
}
if (blockBag != null) {
BlockState existing = getExtent().getBlock(BlockVector3.at(x,y,z));
if (!block.getBlockType().equals(existing.getBlockType())) {
if (!block.getBlockType().getMaterial().isAir()) {
try {
blockBag.fetchPlacedBlock(block.toImmutableState());
} catch (UnplaceableBlockException e) {
throw new FaweException.FaweBlockBagException();
} catch (BlockBagException e) {
missingBlocks[block.getBlockType().getInternalId()]++;
throw new FaweException.FaweBlockBagException();
}
}
if (mine) {
if (!existing.getBlockType().getMaterial().isAir()) {
try {
blockBag.storeDroppedBlock(existing);
} catch (BlockBagException ignored) {
}
}
}
}
}
return getExtent().setBlock(x, y, z, block);
return super.setBlock(x, y, z, block);
}
}
}

View File

@ -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.extent.transform;
import com.boydti.fawe.object.extent.ResettableExtent;
@ -32,6 +51,7 @@ 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.*;
public class BlockTransformExtent extends ResettableExtent {
@ -46,8 +66,14 @@ public class BlockTransformExtent extends ResettableExtent {
this(parent, new AffineTransform());
}
public BlockTransformExtent(Extent parent, Transform transform) {
super(parent);
/**
* Create a new instance.
*
* @param extent the extent
*/
public BlockTransformExtent(Extent extent, Transform transform) {
super(extent);
checkNotNull(transform);
this.transform = transform;
this.transformInverse = this.transform.inverse();
cache();
@ -134,7 +160,7 @@ public class BlockTransformExtent extends ResettableExtent {
continue;
default:
System.out.println("Unknown direction " + value);
result.add(0l);
result.add(0L);
}
}
return adapt(result.toArray(new Long[0]));
@ -174,7 +200,7 @@ public class BlockTransformExtent extends ResettableExtent {
break;
default:
System.out.println("Unknown direction " + value);
directions.add(0l);
directions.add(0L);
}
}
return adapt(directions.toArray(new Long[0]));
@ -268,7 +294,7 @@ public class BlockTransformExtent extends ResettableExtent {
}
}
private static final BaseBlock transformBaseBlockNBT(BlockState transformed, CompoundTag tag, Transform transform) {
private static BaseBlock transformBaseBlockNBT(BlockState transformed, CompoundTag tag, Transform transform) {
if (tag != null) {
if (tag.containsKey("Rot")) {
int rot = tag.asInt("Rot");
@ -321,7 +347,7 @@ public class BlockTransformExtent extends ResettableExtent {
newMaskedId = tmp.getInternalId();
}
for (AbstractProperty property : (Collection<AbstractProperty>) (Collection) type.getProperties()) {
for (AbstractProperty property : (List<AbstractProperty<?>>) type.getProperties()) {
if (isDirectional(property)) {
long[] directions = getDirections(property);
if (directions != null) {
@ -358,7 +384,6 @@ public class BlockTransformExtent extends ResettableExtent {
BLOCK_ROTATION_BITMASK = new int[BlockTypes.size()];
BLOCK_TRANSFORM = new int[BlockTypes.size()][];
BLOCK_TRANSFORM_INVERSE = new int[BlockTypes.size()][];
outer:
for (int i = 0; i < BLOCK_TRANSFORM.length; i++) {
BLOCK_TRANSFORM[i] = ALL;
BLOCK_TRANSFORM_INVERSE[i] = ALL;
@ -392,7 +417,7 @@ public class BlockTransformExtent extends ResettableExtent {
cache();
}
private final BlockState transform(BlockState state, int[][] transformArray, Transform transform) {
private BlockState transform(BlockState state, int[][] transformArray, Transform transform) {
int typeId = state.getInternalBlockTypeId();
int[] arr = transformArray[typeId];
if (arr == ALL) {
@ -478,4 +503,4 @@ public class BlockTransformExtent extends ResettableExtent {
}
}
}