mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-06 20:56:41 +00:00
Remove all raw usages of BSH, improve API generics
This commit is contained in:
committed by
IronApollo
parent
1d87642b52
commit
590b7e23a9
@ -53,7 +53,7 @@ public abstract class AbstractWorld implements World {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean setBlock(BlockVector3 pt, BlockStateHolder block) throws WorldEditException {
|
||||
public final <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 pt, B block) throws WorldEditException {
|
||||
return setBlock(pt, block, true);
|
||||
}
|
||||
|
||||
@ -144,6 +144,7 @@ public abstract class AbstractWorld implements World {
|
||||
this.priority = priority;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public void play() {
|
||||
playEffect(position, 2001, blockType.getLegacyCombinedId() >> 4);
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ public class NullWorld extends AbstractWorld {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBlock(BlockVector3 position, BlockStateHolder block, boolean notifyAndLight) throws WorldEditException {
|
||||
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block, boolean notifyAndLight) throws WorldEditException {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -54,7 +54,7 @@ public interface SimpleWorld extends World {
|
||||
}
|
||||
|
||||
@Override
|
||||
default boolean setBlock(BlockVector3 position, BlockStateHolder block, boolean notifyAndLight) throws WorldEditException {
|
||||
default <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block, boolean notifyAndLight) throws WorldEditException {
|
||||
return setBlock(position, block);
|
||||
}
|
||||
|
||||
@ -64,7 +64,7 @@ public interface SimpleWorld extends World {
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean setBlock(BlockVector3 pt, BlockStateHolder block) throws WorldEditException;
|
||||
<B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 pt, B block) throws WorldEditException;
|
||||
|
||||
@Override
|
||||
default int getMaxY() {
|
||||
|
@ -38,8 +38,6 @@ import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.weather.WeatherType;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
* Represents a world (dimension).
|
||||
*/
|
||||
@ -96,7 +94,7 @@ public interface World extends Extent {
|
||||
* @param notifyAndLight true to to notify and light
|
||||
* @return true if the block was successfully set (return value may not be accurate)
|
||||
*/
|
||||
boolean setBlock(BlockVector3 position, BlockStateHolder block, boolean notifyAndLight) throws WorldEditException;
|
||||
<B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block, boolean notifyAndLight) throws WorldEditException;
|
||||
|
||||
/**
|
||||
* Notifies the simulation that the block at the given location has
|
||||
|
@ -191,7 +191,7 @@ public class BaseBlock implements BlockStateHolder<BaseBlock>, TileEntityBlock {
|
||||
public final BlockState toImmutableState() {
|
||||
return blockState;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getInternalId() {
|
||||
return blockState.getInternalId();
|
||||
|
@ -52,7 +52,7 @@ public class BlockCategory extends Category<BlockType> {
|
||||
* @param blockStateHolder The blockstateholder
|
||||
* @return If it's a part of this category
|
||||
*/
|
||||
public boolean contains(BlockStateHolder blockStateHolder) {
|
||||
public <B extends BlockStateHolder<B>> boolean contains(B blockStateHolder) {
|
||||
return this.getAll().contains(blockStateHolder.getBlockType());
|
||||
}
|
||||
}
|
||||
|
@ -63,6 +63,18 @@ public class BlockState implements BlockStateHolder<BlockState> {
|
||||
this.emptyBaseBlock = baseBlock;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a fuzzy BlockState. This can be used for partial matching.
|
||||
*
|
||||
* @param blockType The block type
|
||||
* @param values The block state values
|
||||
*/
|
||||
private BlockState(BlockType blockType, Map<Property<?>, Object> values) {
|
||||
this.blockType = blockType;
|
||||
// this.values = values;
|
||||
// this.fuzzy = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a temporary BlockState for a given internal id
|
||||
* @param combinedId
|
||||
@ -224,8 +236,8 @@ public class BlockState implements BlockStateHolder<BlockState> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState apply(BlockVector3 position) {
|
||||
return this;
|
||||
public BaseBlock apply(BlockVector3 position) {
|
||||
return this.toBaseBlock();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -330,15 +342,6 @@ public class BlockState implements BlockStateHolder<BlockState> {
|
||||
return this.blockType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated, use masks - not try to this fuzzy/non fuzzy state nonsense
|
||||
* @return
|
||||
*/
|
||||
@Deprecated
|
||||
public BlockState toFuzzy() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getOrdinal();
|
||||
@ -349,10 +352,42 @@ public class BlockState implements BlockStateHolder<BlockState> {
|
||||
return this == obj;
|
||||
}
|
||||
|
||||
public BlockState toFuzzy() {
|
||||
return new BlockState(this.getBlockType(), new HashMap<>());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean equalsFuzzy(BlockStateHolder o) {
|
||||
return o.getOrdinal() == this.getOrdinal();
|
||||
public boolean equalsFuzzy(BlockStateHolder<?> o) {
|
||||
if (this == o) {
|
||||
// Added a reference equality check for
|
||||
return true;
|
||||
}
|
||||
if (!getBlockType().equals(o.getBlockType())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Set<Property<?>> differingProperties = new HashSet<>();
|
||||
for (Object state : o.getStates().keySet()) {
|
||||
if (getState((Property<?>) state) == null) {
|
||||
differingProperties.add((Property<?>) state);
|
||||
}
|
||||
}
|
||||
for (Property<?> property : getStates().keySet()) {
|
||||
if (o.getState(property) == null) {
|
||||
differingProperties.add(property);
|
||||
}
|
||||
}
|
||||
|
||||
for (Property<?> property : getStates().keySet()) {
|
||||
if (differingProperties.contains(property)) {
|
||||
continue;
|
||||
}
|
||||
if (!Objects.equals(getState(property), o.getState(property))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -31,7 +31,7 @@ import com.sk89q.worldedit.world.registry.BlockMaterial;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public interface BlockStateHolder<T extends BlockStateHolder> extends FawePattern, TileEntityBlock {
|
||||
public interface BlockStateHolder<T extends BlockStateHolder<T>> extends FawePattern, TileEntityBlock {
|
||||
|
||||
/**
|
||||
* Get the block type
|
||||
@ -121,8 +121,7 @@ public interface BlockStateHolder<T extends BlockStateHolder> extends FawePatter
|
||||
* @param o other block
|
||||
* @return true if equal
|
||||
*/
|
||||
@Deprecated
|
||||
boolean equalsFuzzy(BlockStateHolder o);
|
||||
boolean equalsFuzzy(BlockStateHolder<?> o);
|
||||
|
||||
/**
|
||||
* Returns an immutable {@link BlockState} from this BlockStateHolder.
|
||||
|
@ -326,8 +326,8 @@ public class BlockType implements FawePattern {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockStateHolder apply(BlockVector3 position) {
|
||||
return this.getDefaultState();
|
||||
public BaseBlock apply(BlockVector3 position) {
|
||||
return this.getDefaultState().toBaseBlock();
|
||||
}
|
||||
|
||||
public Mask toMask(Extent extent) {
|
||||
|
@ -32,8 +32,8 @@ import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.DataException;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
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 com.sk89q.worldedit.world.registry.LegacyMapper;
|
||||
import com.sk89q.worldedit.world.storage.InvalidFormatException;
|
||||
@ -254,14 +254,14 @@ public class AnvilChunk implements Chunk {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockStateHolder getBlock(BlockVector3 position) throws DataException {
|
||||
public BaseBlock getBlock(BlockVector3 position) throws DataException {
|
||||
int id = getBlockID(position);
|
||||
int data = getBlockData(position);
|
||||
|
||||
BlockState state = LegacyMapper.getInstance().getBlockFromLegacy(id, data);
|
||||
if (state == null) {
|
||||
WorldEdit.logger.warning("Unknown legacy block " + id + ":" + data + " found when loading legacy anvil chunk.");
|
||||
return BlockTypes.AIR.getDefaultState();
|
||||
return BlockTypes.AIR.getDefaultState().toBaseBlock();
|
||||
}
|
||||
if (state.getMaterial().hasContainer()) {
|
||||
CompoundTag tileEntity = getBlockTileEntity(position);
|
||||
@ -269,6 +269,8 @@ public class AnvilChunk implements Chunk {
|
||||
return new BaseBlock(state, tileEntity);
|
||||
}
|
||||
}
|
||||
return state; }
|
||||
|
||||
return state.toBaseBlock();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -32,7 +32,6 @@ import com.sk89q.worldedit.registry.state.Property;
|
||||
import com.sk89q.worldedit.world.DataException;
|
||||
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.block.BlockTypes;
|
||||
import com.sk89q.worldedit.world.storage.InvalidFormatException;
|
||||
@ -231,7 +230,7 @@ public class AnvilChunk13 implements Chunk {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockStateHolder getBlock(BlockVector3 position) throws DataException {
|
||||
public BaseBlock getBlock(BlockVector3 position) throws DataException {
|
||||
int x = position.getX() - rootX * 16;
|
||||
int y = position.getY();
|
||||
int z = position.getZ() - rootZ * 16;
|
||||
@ -249,7 +248,8 @@ public class AnvilChunk13 implements Chunk {
|
||||
CompoundTag tileEntity = getBlockTileEntity(position);
|
||||
if (tileEntity != null) return new BaseBlock(state, tileEntity);
|
||||
}
|
||||
return state;
|
||||
|
||||
return state.toBaseBlock();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -22,13 +22,13 @@ package com.sk89q.worldedit.world.chunk;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.DataException;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
|
||||
/**
|
||||
* A 16 by 16 block chunk.
|
||||
*/
|
||||
public interface Chunk {
|
||||
|
||||
|
||||
/**
|
||||
* Get a block;
|
||||
*
|
||||
@ -36,6 +36,6 @@ public interface Chunk {
|
||||
* @return block the block
|
||||
* @throws DataException thrown on data error
|
||||
*/
|
||||
BlockStateHolder getBlock(BlockVector3 position) throws DataException;
|
||||
BaseBlock getBlock(BlockVector3 position) throws DataException;
|
||||
|
||||
}
|
||||
|
@ -30,8 +30,8 @@ import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.DataException;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
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 com.sk89q.worldedit.world.registry.LegacyMapper;
|
||||
import com.sk89q.worldedit.world.storage.InvalidFormatException;
|
||||
@ -154,13 +154,9 @@ public class OldChunk implements Chunk {
|
||||
}
|
||||
|
||||
@Override
|
||||
//<<<<<<< HEAD
|
||||
public BlockStateHolder getBlock(BlockVector3 position) throws DataException {
|
||||
if(position.getBlockY() >= 128) return BlockTypes.VOID_AIR.getDefaultState();
|
||||
//=======
|
||||
// public BlockStateHolder getBlock(BlockVector3 position) throws DataException {
|
||||
// if(position.getY() >= 128) return BlockTypes.VOID_AIR.getDefaultState().toBaseBlock();
|
||||
//>>>>>>> 399e0ad5... Refactor vector system to be cleaner
|
||||
|
||||
public BaseBlock getBlock(BlockVector3 position) throws DataException {
|
||||
if(position.getY() >= 128) return BlockTypes.VOID_AIR.getDefaultState().toBaseBlock();
|
||||
int id, dataVal;
|
||||
|
||||
int x = position.getX() - rootX * 16;
|
||||
@ -189,13 +185,13 @@ public class OldChunk implements Chunk {
|
||||
BlockState state = LegacyMapper.getInstance().getBlockFromLegacy(id, dataVal);
|
||||
if (state == null) {
|
||||
WorldEdit.logger.warning("Unknown legacy block " + id + ":" + dataVal + " found when loading legacy anvil chunk.");
|
||||
return BlockTypes.AIR.getDefaultState();
|
||||
return BlockTypes.AIR.getDefaultState().toBaseBlock();
|
||||
}
|
||||
if (state.getBlockType().getMaterial().hasContainer()) {
|
||||
CompoundTag tileEntity = getBlockTileEntity(position);
|
||||
if (tileEntity != null) return new BaseBlock(state, tileEntity);
|
||||
}
|
||||
return state;
|
||||
return state.toBaseBlock();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -66,7 +66,6 @@ public interface BlockRegistry {
|
||||
*/
|
||||
Map<String, ? extends Property<?>> getProperties(BlockType blockType);
|
||||
|
||||
|
||||
/**
|
||||
* Register all blocks
|
||||
*/
|
||||
|
@ -230,7 +230,7 @@ public class LegacyMapper {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
@SuppressWarnings({"MismatchedQueryAndUpdateOfCollection", "unused"})
|
||||
@SuppressWarnings({"MismatchedQueryAndUpdateOfCollection"})
|
||||
private static class LegacyDataFile {
|
||||
private Map<String, String> blocks;
|
||||
private Map<String, String> items;
|
||||
|
Reference in New Issue
Block a user