mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-06 20:56:41 +00:00
Further work on BlockState transition
This commit is contained in:
@ -24,6 +24,7 @@ import com.sk89q.jnbt.CompoundTagBuilder;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.blocks.type.BlockStateHolder;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.function.RegionFunction;
|
||||
import com.sk89q.worldedit.internal.helper.MCDirections;
|
||||
@ -68,7 +69,7 @@ public class ExtentBlockCopy implements RegionFunction {
|
||||
|
||||
@Override
|
||||
public boolean apply(Vector position) throws WorldEditException {
|
||||
BaseBlock block = source.getBlock(position);
|
||||
BaseBlock block = source.getFullBlock(position);
|
||||
Vector orig = position.subtract(from);
|
||||
Vector transformed = transform.apply(orig);
|
||||
|
||||
|
@ -23,6 +23,7 @@ import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.blocks.type.BlockStateHolder;
|
||||
import com.sk89q.worldedit.blocks.type.BlockTypes;
|
||||
import com.sk89q.worldedit.function.RegionFunction;
|
||||
import com.sk89q.worldedit.function.pattern.BlockPattern;
|
||||
@ -104,7 +105,7 @@ public class FloraGenerator implements RegionFunction {
|
||||
|
||||
@Override
|
||||
public boolean apply(Vector position) throws WorldEditException {
|
||||
BaseBlock block = editSession.getBlock(position);
|
||||
BlockStateHolder block = editSession.getBlock(position);
|
||||
|
||||
if (block.getBlockType() == BlockTypes.GRASS) {
|
||||
editSession.setBlock(position.add(0, 1, 0), temperatePattern.apply(position));
|
||||
|
@ -23,6 +23,7 @@ import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.blocks.type.BlockStateHolder;
|
||||
import com.sk89q.worldedit.blocks.type.BlockType;
|
||||
import com.sk89q.worldedit.blocks.type.BlockTypes;
|
||||
import com.sk89q.worldedit.function.RegionFunction;
|
||||
@ -50,7 +51,7 @@ public class ForestGenerator implements RegionFunction {
|
||||
|
||||
@Override
|
||||
public boolean apply(Vector position) throws WorldEditException {
|
||||
BaseBlock block = editSession.getBlock(position);
|
||||
BlockStateHolder block = editSession.getBlock(position);
|
||||
BlockType t = block.getBlockType();
|
||||
|
||||
if (t == BlockTypes.GRASS || t == BlockTypes.DIRT) {
|
||||
|
@ -24,6 +24,8 @@ import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.blocks.type.BlockState;
|
||||
import com.sk89q.worldedit.blocks.type.BlockStateHolder;
|
||||
import com.sk89q.worldedit.blocks.type.BlockTypes;
|
||||
import com.sk89q.worldedit.function.RegionFunction;
|
||||
import com.sk89q.worldedit.function.pattern.BlockPattern;
|
||||
@ -86,25 +88,25 @@ public class GardenPatchGenerator implements RegionFunction {
|
||||
*/
|
||||
private void placeVine(Vector basePos, Vector pos) throws MaxChangedBlocksException {
|
||||
if (pos.distance(basePos) > 4) return;
|
||||
if (!editSession.getBlock(pos).isAir()) return;
|
||||
if (editSession.getBlock(pos).getBlockType() != BlockTypes.AIR) return;
|
||||
|
||||
for (int i = -1; i > -3; --i) {
|
||||
Vector testPos = pos.add(0, i, 0);
|
||||
if (editSession.getBlock(testPos).isAir()) {
|
||||
if (editSession.getBlock(testPos).getBlockType() == BlockTypes.AIR) {
|
||||
pos = testPos;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
setBlockIfAir(editSession, pos, new BaseBlock(BlockTypes.OAK_LEAVES));
|
||||
setBlockIfAir(editSession, pos, BlockTypes.OAK_LEAVES.getDefaultState());
|
||||
affected++;
|
||||
|
||||
int t = random.nextInt(4);
|
||||
int h = random.nextInt(3) - 1;
|
||||
Vector p;
|
||||
|
||||
BaseBlock log = new BaseBlock(BlockTypes.OAK_LOG);
|
||||
BlockState log = BlockTypes.OAK_LOG.getDefaultState();
|
||||
|
||||
switch (t) {
|
||||
case 0:
|
||||
@ -159,7 +161,7 @@ public class GardenPatchGenerator implements RegionFunction {
|
||||
|
||||
@Override
|
||||
public boolean apply(Vector position) throws WorldEditException {
|
||||
if (!editSession.getBlock(position).isAir()) {
|
||||
if (editSession.getBlock(position).getBlockType() != BlockTypes.AIR) {
|
||||
position = position.add(0, 1, 0);
|
||||
}
|
||||
|
||||
@ -167,9 +169,9 @@ public class GardenPatchGenerator implements RegionFunction {
|
||||
return false;
|
||||
}
|
||||
|
||||
BaseBlock leavesBlock = new BaseBlock(BlockTypes.OAK_LEAVES);
|
||||
BlockState leavesBlock = BlockTypes.OAK_LEAVES.getDefaultState();
|
||||
|
||||
if (editSession.getBlock(position).isAir()) {
|
||||
if (editSession.getBlock(position).getBlockType() == BlockTypes.AIR) {
|
||||
editSession.setBlock(position, leavesBlock);
|
||||
}
|
||||
|
||||
@ -202,8 +204,8 @@ public class GardenPatchGenerator implements RegionFunction {
|
||||
* @return if block was changed
|
||||
* @throws MaxChangedBlocksException thrown if too many blocks are changed
|
||||
*/
|
||||
private static boolean setBlockIfAir(EditSession session, Vector position, BaseBlock block) throws MaxChangedBlocksException {
|
||||
return session.getBlock(position).isAir() && session.setBlock(position, block);
|
||||
private static boolean setBlockIfAir(EditSession session, Vector position, BlockStateHolder block) throws MaxChangedBlocksException {
|
||||
return session.getBlock(position).getBlockType() == BlockTypes.AIR && session.setBlock(position, block);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -19,6 +19,8 @@
|
||||
|
||||
package com.sk89q.worldedit.function.mask;
|
||||
|
||||
import com.sk89q.worldedit.blocks.type.BlockState;
|
||||
import com.sk89q.worldedit.blocks.type.BlockStateHolder;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
@ -40,7 +42,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||
*/
|
||||
public class BlockMask extends AbstractExtentMask {
|
||||
|
||||
private final Set<BaseBlock> blocks = new HashSet<>();
|
||||
private final Set<BlockStateHolder> blocks = new HashSet<>();
|
||||
|
||||
/**
|
||||
* Create a new block mask.
|
||||
@ -48,7 +50,7 @@ public class BlockMask extends AbstractExtentMask {
|
||||
* @param extent the extent
|
||||
* @param blocks a list of blocks to match
|
||||
*/
|
||||
public BlockMask(Extent extent, Collection<BaseBlock> blocks) {
|
||||
public BlockMask(Extent extent, Collection<BlockStateHolder> blocks) {
|
||||
super(extent);
|
||||
checkNotNull(blocks);
|
||||
this.blocks.addAll(blocks);
|
||||
@ -60,7 +62,7 @@ public class BlockMask extends AbstractExtentMask {
|
||||
* @param extent the extent
|
||||
* @param block an array of blocks to match
|
||||
*/
|
||||
public BlockMask(Extent extent, BaseBlock... block) {
|
||||
public BlockMask(Extent extent, BlockStateHolder... block) {
|
||||
this(extent, Arrays.asList(checkNotNull(block)));
|
||||
}
|
||||
|
||||
@ -69,7 +71,7 @@ public class BlockMask extends AbstractExtentMask {
|
||||
*
|
||||
* @param blocks a list of blocks
|
||||
*/
|
||||
public void add(Collection<BaseBlock> blocks) {
|
||||
public void add(Collection<BlockStateHolder> blocks) {
|
||||
checkNotNull(blocks);
|
||||
this.blocks.addAll(blocks);
|
||||
}
|
||||
@ -79,7 +81,7 @@ public class BlockMask extends AbstractExtentMask {
|
||||
*
|
||||
* @param block an array of blocks
|
||||
*/
|
||||
public void add(BaseBlock... block) {
|
||||
public void add(BlockStateHolder... block) {
|
||||
add(Arrays.asList(checkNotNull(block)));
|
||||
}
|
||||
|
||||
@ -88,14 +90,14 @@ public class BlockMask extends AbstractExtentMask {
|
||||
*
|
||||
* @return a list of blocks
|
||||
*/
|
||||
public Collection<BaseBlock> getBlocks() {
|
||||
public Collection<BlockStateHolder> getBlocks() {
|
||||
return blocks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Vector vector) {
|
||||
BaseBlock block = getExtent().getBlock(vector);
|
||||
return blocks.contains(block) || blocks.contains(new BaseBlock(block.getBlockType()));
|
||||
BlockStateHolder block = getExtent().getBlock(vector);
|
||||
return blocks.contains(block) || blocks.contains(block);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -22,26 +22,25 @@ package com.sk89q.worldedit.function.mask;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.blocks.Blocks;
|
||||
import com.sk89q.worldedit.blocks.type.BlockStateHolder;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class FuzzyBlockMask extends BlockMask {
|
||||
|
||||
public FuzzyBlockMask(Extent extent, Collection<BaseBlock> blocks) {
|
||||
public FuzzyBlockMask(Extent extent, Collection<BlockStateHolder> blocks) {
|
||||
super(extent, blocks);
|
||||
}
|
||||
|
||||
public FuzzyBlockMask(Extent extent, BaseBlock... block) {
|
||||
public FuzzyBlockMask(Extent extent, BlockStateHolder... block) {
|
||||
super(extent, block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(Vector vector) {
|
||||
Extent extent = getExtent();
|
||||
Collection<BaseBlock> blocks = getBlocks();
|
||||
BaseBlock lazyBlock = extent.getLazyBlock(vector);
|
||||
BaseBlock compare = new BaseBlock(lazyBlock.getState());
|
||||
return Blocks.containsFuzzy(blocks, compare);
|
||||
Collection<BlockStateHolder> blocks = getBlocks();
|
||||
return Blocks.containsFuzzy(blocks, extent.getFullBlock(vector));
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ package com.sk89q.worldedit.function.operation;
|
||||
import com.sk89q.worldedit.BlockVector;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.blocks.type.BlockStateHolder;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
|
||||
import java.util.Iterator;
|
||||
@ -37,7 +38,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||
public class BlockMapEntryPlacer implements Operation {
|
||||
|
||||
private final Extent extent;
|
||||
private final Iterator<Map.Entry<BlockVector, BaseBlock>> iterator;
|
||||
private final Iterator<Map.Entry<BlockVector, BlockStateHolder>> iterator;
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
@ -45,7 +46,7 @@ public class BlockMapEntryPlacer implements Operation {
|
||||
* @param extent the extent to set the blocks on
|
||||
* @param iterator the iterator
|
||||
*/
|
||||
public BlockMapEntryPlacer(Extent extent, Iterator<Map.Entry<BlockVector, BaseBlock>> iterator) {
|
||||
public BlockMapEntryPlacer(Extent extent, Iterator<Map.Entry<BlockVector, BlockStateHolder>> iterator) {
|
||||
checkNotNull(extent);
|
||||
checkNotNull(iterator);
|
||||
this.extent = extent;
|
||||
@ -55,7 +56,7 @@ public class BlockMapEntryPlacer implements Operation {
|
||||
@Override
|
||||
public Operation resume(RunContext run) throws WorldEditException {
|
||||
while (iterator.hasNext()) {
|
||||
Map.Entry<BlockVector, BaseBlock> entry = iterator.next();
|
||||
Map.Entry<BlockVector, BlockStateHolder> entry = iterator.next();
|
||||
extent.setBlock(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@ package com.sk89q.worldedit.function.pattern;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.blocks.type.BlockStateHolder;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
@ -29,14 +30,14 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||
*/
|
||||
public class BlockPattern extends AbstractPattern {
|
||||
|
||||
private BaseBlock block;
|
||||
private BlockStateHolder block;
|
||||
|
||||
/**
|
||||
* Create a new pattern with the given block.
|
||||
*
|
||||
* @param block the block
|
||||
*/
|
||||
public BlockPattern(BaseBlock block) {
|
||||
public BlockPattern(BlockStateHolder block) {
|
||||
setBlock(block);
|
||||
}
|
||||
|
||||
@ -45,7 +46,7 @@ public class BlockPattern extends AbstractPattern {
|
||||
*
|
||||
* @return the block that is always returned
|
||||
*/
|
||||
public BaseBlock getBlock() {
|
||||
public BlockStateHolder getBlock() {
|
||||
return block;
|
||||
}
|
||||
|
||||
@ -54,13 +55,13 @@ public class BlockPattern extends AbstractPattern {
|
||||
*
|
||||
* @param block the block
|
||||
*/
|
||||
public void setBlock(BaseBlock block) {
|
||||
public void setBlock(BlockStateHolder block) {
|
||||
checkNotNull(block);
|
||||
this.block = block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBlock apply(Vector position) {
|
||||
public BlockStateHolder apply(Vector position) {
|
||||
return block;
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@ package com.sk89q.worldedit.function.pattern;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.blocks.type.BlockStateHolder;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
@ -45,7 +46,7 @@ public class ClipboardPattern extends AbstractPattern {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBlock apply(Vector position) {
|
||||
public BlockStateHolder apply(Vector position) {
|
||||
int xp = Math.abs(position.getBlockX()) % size.getBlockX();
|
||||
int yp = Math.abs(position.getBlockY()) % size.getBlockY();
|
||||
int zp = Math.abs(position.getBlockZ()) % size.getBlockZ();
|
||||
|
@ -21,18 +21,19 @@ package com.sk89q.worldedit.function.pattern;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.blocks.type.BlockStateHolder;
|
||||
|
||||
/**
|
||||
* Returns a {@link BaseBlock} for a given position.
|
||||
* Returns a {@link BlockStateHolder} for a given position.
|
||||
*/
|
||||
public interface Pattern {
|
||||
|
||||
/**
|
||||
* Return a {@link BaseBlock} for the given position.
|
||||
* Return a {@link BlockStateHolder} for the given position.
|
||||
*
|
||||
* @param position the position
|
||||
* @return a block
|
||||
*/
|
||||
BaseBlock apply(Vector position);
|
||||
BlockStateHolder apply(Vector position);
|
||||
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ package com.sk89q.worldedit.function.pattern;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.blocks.type.BlockStateHolder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -53,7 +54,7 @@ public class RandomPattern extends AbstractPattern {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBlock apply(Vector position) {
|
||||
public BlockStateHolder apply(Vector position) {
|
||||
double r = random.nextDouble();
|
||||
double offset = 0;
|
||||
|
||||
|
@ -21,6 +21,7 @@ package com.sk89q.worldedit.function.pattern;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.blocks.type.BlockStateHolder;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
@ -83,7 +84,7 @@ public class RepeatingExtentPattern extends AbstractPattern {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseBlock apply(Vector position) {
|
||||
public BlockStateHolder apply(Vector position) {
|
||||
Vector base = position.add(offset);
|
||||
Vector size = extent.getMaximumPoint().subtract(extent.getMinimumPoint()).add(1, 1, 1);
|
||||
int x = base.getBlockX() % size.getBlockX();
|
||||
|
Reference in New Issue
Block a user