mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-12 15:38:35 +00:00
Remove all raw usages of BSH, improve API generics
This commit is contained in:
@ -25,7 +25,6 @@ import com.sk89q.worldedit.function.RegionFunction;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.util.Countable;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@ -36,27 +35,27 @@ import java.util.Map;
|
||||
public class BlockDistributionCounter implements RegionFunction {
|
||||
|
||||
private Extent extent;
|
||||
private boolean fuzzy;
|
||||
private boolean separateStates;
|
||||
|
||||
private List<Countable<BlockStateHolder>> distribution = new ArrayList<>();
|
||||
private Map<BlockStateHolder, Countable<BlockStateHolder>> map = new HashMap<>();
|
||||
private List<Countable<BlockState>> distribution = new ArrayList<>();
|
||||
private Map<BlockState, Countable<BlockState>> map = new HashMap<>();
|
||||
|
||||
public BlockDistributionCounter(Extent extent, boolean fuzzy) {
|
||||
public BlockDistributionCounter(Extent extent, boolean separateStates) {
|
||||
this.extent = extent;
|
||||
this.fuzzy = fuzzy;
|
||||
this.separateStates = separateStates;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(BlockVector3 position) throws WorldEditException {
|
||||
BlockStateHolder blk = extent.getBlock(position);
|
||||
if (fuzzy) {
|
||||
blk = ((BlockState) blk).toFuzzy();
|
||||
BlockState blk = extent.getBlock(position);
|
||||
if (!separateStates) {
|
||||
blk = blk.getBlockType().getDefaultState();
|
||||
}
|
||||
|
||||
if (map.containsKey(blk)) {
|
||||
map.get(blk).increment();
|
||||
} else {
|
||||
Countable<BlockStateHolder> c = new Countable<>(blk, 1);
|
||||
Countable<BlockState> c = new Countable<>(blk, 1);
|
||||
map.put(blk, c);
|
||||
distribution.add(c);
|
||||
}
|
||||
@ -69,7 +68,7 @@ public class BlockDistributionCounter implements RegionFunction {
|
||||
*
|
||||
* @return The distribution
|
||||
*/
|
||||
public List<Countable<BlockStateHolder>> getDistribution() {
|
||||
public List<Countable<BlockState>> getDistribution() {
|
||||
Collections.sort(distribution);
|
||||
Collections.reverse(distribution);
|
||||
return this.distribution;
|
||||
|
@ -26,7 +26,7 @@ import com.sk89q.worldedit.function.pattern.BlockPattern;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.function.pattern.RandomPattern;
|
||||
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;
|
||||
|
||||
/**
|
||||
@ -104,7 +104,7 @@ public class FloraGenerator implements RegionFunction {
|
||||
|
||||
@Override
|
||||
public boolean apply(BlockVector3 position) throws WorldEditException {
|
||||
BlockStateHolder block = editSession.getBlock(position);
|
||||
BlockState block = editSession.getBlock(position);
|
||||
|
||||
if (block.getBlockType() == BlockTypes.GRASS_BLOCK) {
|
||||
editSession.setBlock(position.add(0, 1, 0), temperatePattern.apply(position));
|
||||
|
@ -24,7 +24,7 @@ import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.function.RegionFunction;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.util.TreeGenerator;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
@ -50,7 +50,7 @@ public class ForestGenerator implements RegionFunction {
|
||||
|
||||
@Override
|
||||
public boolean apply(BlockVector3 position) throws WorldEditException {
|
||||
BlockStateHolder block = editSession.getBlock(position);
|
||||
BlockState block = editSession.getBlock(position);
|
||||
BlockType t = block.getBlockType();
|
||||
|
||||
if (t == BlockTypes.GRASS_BLOCK || t == BlockTypes.DIRT) {
|
||||
|
@ -198,7 +198,7 @@ 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, BlockVector3 position, BlockStateHolder block) throws MaxChangedBlocksException {
|
||||
private static <B extends BlockStateHolder<B>> boolean setBlockIfAir(EditSession session, BlockVector3 position, B block) throws MaxChangedBlocksException {
|
||||
return session.getBlock(position).getBlockType().getMaterial().isAir() && session.setBlock(position, block);
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,8 @@ 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.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@ -41,7 +42,7 @@ import javax.annotation.Nullable;
|
||||
*/
|
||||
public class BlockMask extends AbstractExtentMask {
|
||||
|
||||
private final Set<BlockStateHolder> blocks = new HashSet<>();
|
||||
private final Set<BaseBlock> blocks = new HashSet<>();
|
||||
|
||||
/**
|
||||
* Create a new block mask.
|
||||
@ -49,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<BlockStateHolder> blocks) {
|
||||
public BlockMask(Extent extent, Collection<BaseBlock> blocks) {
|
||||
super(extent);
|
||||
checkNotNull(blocks);
|
||||
this.blocks.addAll(blocks);
|
||||
@ -61,7 +62,7 @@ public class BlockMask extends AbstractExtentMask {
|
||||
* @param extent the extent
|
||||
* @param block an array of blocks to match
|
||||
*/
|
||||
public BlockMask(Extent extent, BlockStateHolder... block) {
|
||||
public BlockMask(Extent extent, BaseBlock... block) {
|
||||
this(extent, Arrays.asList(checkNotNull(block)));
|
||||
}
|
||||
|
||||
@ -70,7 +71,7 @@ public class BlockMask extends AbstractExtentMask {
|
||||
*
|
||||
* @param blocks a list of blocks
|
||||
*/
|
||||
public void add(Collection<BlockStateHolder> blocks) {
|
||||
public void add(Collection<BaseBlock> blocks) {
|
||||
checkNotNull(blocks);
|
||||
this.blocks.addAll(blocks);
|
||||
}
|
||||
@ -80,7 +81,7 @@ public class BlockMask extends AbstractExtentMask {
|
||||
*
|
||||
* @param block an array of blocks
|
||||
*/
|
||||
public void add(BlockStateHolder... block) {
|
||||
public void add(BaseBlock... block) {
|
||||
add(Arrays.asList(checkNotNull(block)));
|
||||
}
|
||||
|
||||
@ -89,14 +90,14 @@ public class BlockMask extends AbstractExtentMask {
|
||||
*
|
||||
* @return a list of blocks
|
||||
*/
|
||||
public Collection<BlockStateHolder> getBlocks() {
|
||||
public Collection<BaseBlock> getBlocks() {
|
||||
return blocks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BlockVector3 vector) {
|
||||
BlockStateHolder block = getExtent().getBlock(vector);
|
||||
for (BlockStateHolder testBlock : blocks) {
|
||||
BlockState block = getExtent().getBlock(vector);
|
||||
for (BaseBlock testBlock : blocks) {
|
||||
if (testBlock.equalsFuzzy(block)) {
|
||||
return true;
|
||||
}
|
||||
|
@ -30,14 +30,14 @@ import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
*/
|
||||
public class BlockPattern extends AbstractPattern {
|
||||
|
||||
private BlockStateHolder block;
|
||||
private BaseBlock block;
|
||||
|
||||
/**
|
||||
* Create a new pattern with the given block.
|
||||
*
|
||||
* @param block the block
|
||||
*/
|
||||
public BlockPattern(BlockStateHolder block) {
|
||||
public BlockPattern(BlockStateHolder<?> block) {
|
||||
setBlock(block);
|
||||
}
|
||||
|
||||
@ -46,7 +46,7 @@ public class BlockPattern extends AbstractPattern {
|
||||
*
|
||||
* @return the block that is always returned
|
||||
*/
|
||||
public BlockStateHolder getBlock() {
|
||||
public BaseBlock getBlock() {
|
||||
return block;
|
||||
}
|
||||
|
||||
@ -55,13 +55,13 @@ public class BlockPattern extends AbstractPattern {
|
||||
*
|
||||
* @param block the block
|
||||
*/
|
||||
public void setBlock(BlockStateHolder block) {
|
||||
public void setBlock(BlockStateHolder<?> block) {
|
||||
checkNotNull(block);
|
||||
this.block = block;
|
||||
this.block = block.toBaseBlock();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockStateHolder apply(BlockVector3 position) {
|
||||
public BaseBlock apply(BlockVector3 position) {
|
||||
return block;
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
|
||||
/**
|
||||
* A pattern that reads from {@link Clipboard}.
|
||||
@ -45,7 +45,7 @@ public class ClipboardPattern extends AbstractPattern {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockStateHolder apply(BlockVector3 position) {
|
||||
public BaseBlock apply(BlockVector3 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();
|
||||
|
@ -20,6 +20,7 @@
|
||||
package com.sk89q.worldedit.function.pattern;
|
||||
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
|
||||
/**
|
||||
@ -33,6 +34,6 @@ public interface Pattern {
|
||||
* @param position the position
|
||||
* @return a block
|
||||
*/
|
||||
BlockStateHolder apply(BlockVector3 position);
|
||||
BaseBlock apply(BlockVector3 position);
|
||||
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ package com.sk89q.worldedit.function.pattern;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -53,7 +53,7 @@ public class RandomPattern extends AbstractPattern {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockStateHolder apply(BlockVector3 position) {
|
||||
public BaseBlock apply(BlockVector3 position) {
|
||||
double r = random.nextDouble();
|
||||
double offset = 0;
|
||||
|
||||
|
@ -23,7 +23,7 @@ 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.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
|
||||
/**
|
||||
* Returns the blocks from {@link Extent}, repeating when out of bounds.
|
||||
@ -83,7 +83,7 @@ public class RepeatingExtentPattern extends AbstractPattern {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockStateHolder apply(BlockVector3 position) {
|
||||
public BaseBlock apply(BlockVector3 position) {
|
||||
BlockVector3 base = position.add(offset);
|
||||
BlockVector3 size = extent.getMaximumPoint().subtract(extent.getMinimumPoint()).add(1, 1, 1);
|
||||
int x = base.getBlockX() % size.getBlockX();
|
||||
|
Reference in New Issue
Block a user