mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-10 04:28:35 +00:00
Remove all raw usages of BSH, improve API generics
This commit is contained in:
committed by
IronApollo
parent
1d87642b52
commit
590b7e23a9
@ -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;
|
||||
|
@ -27,6 +27,8 @@ 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.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
|
||||
/**
|
||||
@ -104,7 +106,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.math.BlockVector3;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.function.RegionFunction;
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -11,11 +11,14 @@ import com.sk89q.worldedit.registry.state.AbstractProperty;
|
||||
import com.sk89q.worldedit.registry.state.Property;
|
||||
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.BlockType;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
|
@ -12,10 +12,15 @@ import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
@Deprecated
|
||||
public class BlockPattern implements Pattern {
|
||||
|
||||
private BlockStateHolder block;
|
||||
private BaseBlock block;
|
||||
|
||||
public BlockPattern(BlockStateHolder block) {
|
||||
this.block = block;
|
||||
/**
|
||||
* Create a new pattern with the given block.
|
||||
*
|
||||
* @param block the block
|
||||
*/
|
||||
public BlockPattern(BlockStateHolder<?> block) {
|
||||
setBlock(block);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -23,7 +28,7 @@ public class BlockPattern implements Pattern {
|
||||
*
|
||||
* @return the block that is always returned
|
||||
*/
|
||||
public BlockStateHolder getBlock() {
|
||||
public BaseBlock getBlock() {
|
||||
return block;
|
||||
}
|
||||
|
||||
@ -32,13 +37,13 @@ public class BlockPattern implements Pattern {
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,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;
|
||||
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
@ -37,23 +37,14 @@ public class ClipboardPattern extends AbstractPattern {
|
||||
}
|
||||
|
||||
@Override
|
||||
//<<<<<<< HEAD
|
||||
public BlockStateHolder apply(BlockVector3 position) {
|
||||
public BaseBlock apply(BlockVector3 position) {
|
||||
int xp = position.getBlockX() % sx;
|
||||
int yp = position.getBlockY() % sy;
|
||||
int zp = position.getBlockZ() % sz;
|
||||
if (xp < 0) xp += sx;
|
||||
if (yp < 0) yp += sy;
|
||||
if (zp < 0) zp += sz;
|
||||
return clipboard.getBlock(BlockVector3.at(min.getX() + xp, min.getY() + yp, min.getZ() + zp));
|
||||
//=======
|
||||
// public BlockStateHolder 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();
|
||||
//
|
||||
// return clipboard.getFullBlock(clipboard.getMinimumPoint().add(xp, yp, zp));
|
||||
//>>>>>>> 399e0ad5... Refactor vector system to be cleaner
|
||||
return clipboard.getFullBlock(BlockVector3.at(min.getX() + xp, min.getY() + yp, min.getZ() + zp));
|
||||
}
|
||||
|
||||
|
||||
|
@ -7,6 +7,7 @@ import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.extent.NullExtent;
|
||||
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;
|
||||
|
||||
/**
|
||||
@ -17,7 +18,7 @@ import com.sk89q.worldedit.world.block.BlockState;
|
||||
public interface FawePattern extends Pattern {
|
||||
|
||||
@Deprecated
|
||||
default BlockStateHolder apply(BlockVector3 position) {
|
||||
default BaseBlock apply(BlockVector3 position) {
|
||||
throw new UnsupportedOperationException("Please use apply(extent, get, set)");
|
||||
}
|
||||
|
||||
|
@ -28,6 +28,7 @@ import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.extent.NullExtent;
|
||||
import com.sk89q.worldedit.internal.expression.runtime.Return;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
|
||||
@ -55,7 +56,7 @@ public interface Pattern{
|
||||
* @param position the position
|
||||
* @return a block
|
||||
*/
|
||||
BlockStateHolder apply(BlockVector3 position);
|
||||
BaseBlock apply(BlockVector3 position);
|
||||
|
||||
default boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException {
|
||||
return extent.setBlock(set, apply(get));
|
||||
|
@ -10,7 +10,7 @@ import com.sk89q.worldedit.extent.Extent;
|
||||
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.HashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
@ -56,24 +56,8 @@ public class RandomPattern extends AbstractPattern {
|
||||
this.patterns.add(pattern);
|
||||
}
|
||||
|
||||
//<<<<<<< HEAD
|
||||
public Set<Pattern> getPatterns() {
|
||||
return patterns;
|
||||
//=======
|
||||
// @Override
|
||||
// public BlockStateHolder apply(BlockVector3 position) {
|
||||
// double r = random.nextDouble();
|
||||
// double offset = 0;
|
||||
//
|
||||
// for (Chance chance : patterns) {
|
||||
// if (r <= (offset + chance.getChance()) / max) {
|
||||
// return chance.getPattern().apply(position);
|
||||
// }
|
||||
// offset += chance.getChance();
|
||||
// }
|
||||
//
|
||||
// throw new RuntimeException("ProportionalFillPattern");
|
||||
//>>>>>>> 399e0ad5... Refactor vector system to be cleaner
|
||||
}
|
||||
|
||||
public RandomCollection<Pattern> getCollection() {
|
||||
@ -81,7 +65,7 @@ public class RandomPattern extends AbstractPattern {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockStateHolder apply(BlockVector3 get) {
|
||||
public BaseBlock apply(BlockVector3 get) {
|
||||
return collection.next(get.getBlockX(), get.getBlockY(), get.getBlockZ()).apply(get);
|
||||
}
|
||||
|
||||
|
@ -23,11 +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.BlockState;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
|
||||
/**
|
||||
* Returns the blocks from {@link Extent}, repeating when out of bounds.
|
||||
@ -87,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