Remove all raw usages of BSH, improve API generics

This commit is contained in:
Kenzie Togami
2018-12-26 16:39:10 -08:00
parent a88f6b8430
commit 3fefcbf971
83 changed files with 242 additions and 259 deletions

View File

@ -52,7 +52,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);
}
@ -138,6 +138,7 @@ public abstract class AbstractWorld implements World {
this.priority = priority;
}
@SuppressWarnings("deprecation")
public void play() {
playEffect(position, 2001, blockType.getLegacyId());
}

View File

@ -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;
}

View File

@ -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

View File

@ -135,7 +135,7 @@ public class BaseBlock implements BlockStateHolder<BaseBlock>, TileEntityBlock {
public boolean equals(Object o) {
if (!(o instanceof BaseBlock)) {
if (!hasNbtData() && o instanceof BlockStateHolder) {
return Objects.equals(toImmutableState(), ((BlockStateHolder) o).toImmutableState());
return Objects.equals(toImmutableState(), ((BlockStateHolder<?>) o).toImmutableState());
}
return false;
}
@ -152,7 +152,7 @@ public class BaseBlock implements BlockStateHolder<BaseBlock>, TileEntityBlock {
* @return true if equal
*/
@Override
public boolean equalsFuzzy(BlockStateHolder o) {
public boolean equalsFuzzy(BlockStateHolder<?> o) {
return this.toImmutableState().equalsFuzzy(o);
}

View File

@ -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());
}
}

View File

@ -74,11 +74,11 @@ public class BlockState implements BlockStateHolder<BlockState> {
static Map<Map<Property<?>, Object>, BlockState> generateStateMap(BlockType blockType) {
Map<Map<Property<?>, Object>, BlockState> stateMap = new LinkedHashMap<>();
List<? extends Property> properties = blockType.getProperties();
List<? extends Property<?>> properties = blockType.getProperties();
if (!properties.isEmpty()) {
List<List<Object>> separatedValues = Lists.newArrayList();
for (Property prop : properties) {
for (Property<?> prop : properties) {
List<Object> vals = Lists.newArrayList();
vals.addAll(prop.getValues());
separatedValues.add(vals);
@ -113,7 +113,7 @@ public class BlockState implements BlockStateHolder<BlockState> {
final Table<Property<?>, Object, BlockState> states = HashBasedTable.create();
for(final Map.Entry<Property<?>, Object> entry : this.values.entrySet()) {
final Property property = entry.getKey();
final Property<Object> property = (Property<Object>) entry.getKey();
property.getValues().forEach(value -> {
if(value != entry.getValue()) {
@ -167,7 +167,7 @@ public class BlockState implements BlockStateHolder<BlockState> {
}
@Override
public boolean equalsFuzzy(BlockStateHolder o) {
public boolean equalsFuzzy(BlockStateHolder<?> o) {
if (this == o) {
// Added a reference equality check for
return true;
@ -176,19 +176,19 @@ public class BlockState implements BlockStateHolder<BlockState> {
return false;
}
Set<Property> differingProperties = new HashSet<>();
Set<Property<?>> differingProperties = new HashSet<>();
for (Object state : o.getStates().keySet()) {
if (getState((Property) state) == null) {
differingProperties.add((Property) state);
if (getState((Property<?>) state) == null) {
differingProperties.add((Property<?>) state);
}
}
for (Property property : getStates().keySet()) {
for (Property<?> property : getStates().keySet()) {
if (o.getState(property) == null) {
differingProperties.add(property);
}
}
for (Property property : getStates().keySet()) {
for (Property<?> property : getStates().keySet()) {
if (differingProperties.contains(property)) {
continue;
}

View File

@ -25,7 +25,7 @@ import com.sk89q.worldedit.registry.state.Property;
import java.util.Map;
import java.util.stream.Collectors;
public interface BlockStateHolder<T extends BlockStateHolder> {
public interface BlockStateHolder<B extends BlockStateHolder<B>> {
/**
* Get the block type
@ -41,7 +41,7 @@ public interface BlockStateHolder<T extends BlockStateHolder> {
* @param value The value
* @return The modified state, or same if could not be applied
*/
<V> T with(final Property<V> property, final V value);
<V> B with(final Property<V> property, final V value);
/**
* Gets the value at the given state
@ -64,7 +64,7 @@ public interface BlockStateHolder<T extends BlockStateHolder> {
* @param o other block
* @return true if equal
*/
boolean equalsFuzzy(BlockStateHolder o);
boolean equalsFuzzy(BlockStateHolder<?> o);
/**
* Returns an immutable {@link BlockState} from this BlockStateHolder.

View File

@ -30,7 +30,6 @@ import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.item.ItemTypes;
import com.sk89q.worldedit.world.registry.BlockMaterial;
import com.sk89q.worldedit.world.registry.BundledBlockData;
import com.sk89q.worldedit.world.registry.LegacyMapper;
import java.util.ArrayList;
@ -49,7 +48,7 @@ public class BlockType {
private final String id;
private final Function<BlockState, BlockState> values;
private final AtomicReference<BlockState> defaultState = new AtomicReference<>();
private final AtomicReference<Map<String, ? extends Property>> properties = new AtomicReference<>();
private final AtomicReference<Map<String, ? extends Property<?>>> properties = new AtomicReference<>();
private final AtomicReference<BlockMaterial> blockMaterial = new AtomicReference<>();
private final AtomicReference<Map<Map<Property<?>, Object>, BlockState>> blockStatesMap = new AtomicReference<>();
@ -114,7 +113,7 @@ public class BlockType {
*
* @return The properties map
*/
public Map<String, ? extends Property> getPropertyMap() {
public Map<String, ? extends Property<?>> getPropertyMap() {
return updateField(properties, () -> ImmutableMap.copyOf(WorldEdit.getInstance().getPlatformManager()
.queryCapability(Capability.GAME_HOOKS).getRegistries().getBlockRegistry().getProperties(this)));
}
@ -124,7 +123,7 @@ public class BlockType {
*
* @return the properties
*/
public List<? extends Property> getProperties() {
public List<? extends Property<?>> getProperties() {
return ImmutableList.copyOf(this.getPropertyMap().values());
}
@ -135,7 +134,9 @@ public class BlockType {
* @return The property
*/
public <V> Property<V> getProperty(String name) {
Property<V> property = getPropertyMap().get(name);
// Assume it works, CCE later at runtime if not.
@SuppressWarnings("unchecked")
Property<V> property = (Property<V>) getPropertyMap().get(name);
checkArgument(property != null, "%s has no property named %s", this, name);
return property;
}

View File

@ -30,8 +30,8 @@ import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.math.BlockVector3;
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;
@ -253,14 +253,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();
}
CompoundTag tileEntity = getBlockTileEntity(position);
@ -268,7 +268,7 @@ public class AnvilChunk implements Chunk {
return state.toBaseBlock(tileEntity);
}
return state;
return state.toBaseBlock();
}
}

View File

@ -29,8 +29,8 @@ import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.math.BlockVector3;
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;
@ -229,7 +229,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;
@ -250,7 +250,7 @@ public class AnvilChunk13 implements Chunk {
return state.toBaseBlock(tileEntity);
}
return state;
return state.toBaseBlock();
}
}

View File

@ -21,13 +21,13 @@ package com.sk89q.worldedit.world.chunk;
import com.sk89q.worldedit.math.BlockVector3;
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;
*
@ -35,6 +35,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;
}

View File

@ -29,8 +29,8 @@ import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.math.BlockVector3;
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;
@ -153,7 +153,7 @@ public class OldChunk implements Chunk {
}
@Override
public BlockStateHolder getBlock(BlockVector3 position) throws DataException {
public BaseBlock getBlock(BlockVector3 position) throws DataException {
if(position.getY() >= 128) return BlockTypes.VOID_AIR.getDefaultState().toBaseBlock();
int id, dataVal;
@ -183,7 +183,7 @@ 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();
}
CompoundTag tileEntity = getBlockTileEntity(position);
@ -192,7 +192,7 @@ public class OldChunk implements Chunk {
return state.toBaseBlock(tileEntity);
}
return state;
return state.toBaseBlock();
}
}

View File

@ -55,6 +55,6 @@ public interface BlockRegistry {
* @param blockType the block
* @return a map of states where the key is the state's ID
*/
Map<String, ? extends Property> getProperties(BlockType blockType);
Map<String, ? extends Property<?>> getProperties(BlockType blockType);
}

View File

@ -48,7 +48,7 @@ public class BundledBlockRegistry implements BlockRegistry {
@Nullable
@Override
public Map<String, ? extends Property> getProperties(BlockType blockType) {
public Map<String, ? extends Property<?>> getProperties(BlockType blockType) {
return Collections.emptyMap(); // Oof
}

View File

@ -155,7 +155,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;