diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java index 8ea15818c..a79b86538 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java @@ -54,9 +54,7 @@ public class BaseBlock implements BlockStateHolder, TileEntityBlock { private final BlockState blockState; @Nullable - //FAWE start - LR instead of CompoundTat private final LazyReference nbtData; - //FAWE end //FAWE start @@ -167,16 +165,13 @@ public class BaseBlock implements BlockStateHolder, TileEntityBlock { @Override public String getNbtId() { - //FAWE start - LR > CompoundTag LazyReference nbtData = this.nbtData; if (nbtData == null) { return ""; } return nbtData.getValue().getString("id"); - //FAWE end } - //FAWE start @Nullable @Override public LazyReference getNbtReference() { @@ -187,7 +182,6 @@ public class BaseBlock implements BlockStateHolder, TileEntityBlock { public void setNbtReference(@Nullable LazyReference nbtData) { throw new UnsupportedOperationException("This class is immutable."); } - //FAWE end /** * Checks whether the type ID and data value are equal. @@ -249,6 +243,17 @@ public class BaseBlock implements BlockStateHolder, TileEntityBlock { return this; } + @Override + public BaseBlock toBaseBlock(LazyReference compoundTag) { + if (compoundTag == null) { + return this.blockState.toBaseBlock(); + } else if (compoundTag == this.nbtData) { + return this; + } else { + return new BaseBlock(this.blockState, compoundTag); + } + } + //FAWE start @Override public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException { @@ -284,22 +289,15 @@ public class BaseBlock implements BlockStateHolder, TileEntityBlock { return toImmutableState().with(property, value).toBaseBlock(getNbtData()); } - @Override - public BaseBlock toBaseBlock(LazyReference compoundTag) { - if (compoundTag == null) { - return this.blockState.toBaseBlock(); - } else if (compoundTag == this.nbtData) { - return this; - } else { - return new BaseBlock(this.blockState, compoundTag); - } - } - @Override public V getState(PropertyKey property) { return toImmutableState().getState(property); } + public BlockState toBlockState() { + return blockState; + } + @Override public int hashCode() { return getOrdinal(); @@ -309,7 +307,6 @@ public class BaseBlock implements BlockStateHolder, TileEntityBlock { @Override public String toString() { String nbtString = ""; - //FAWE start - use CBT CompoundBinaryTag nbtData = getNbt(); if (nbtData != null) { try { @@ -321,9 +318,4 @@ public class BaseBlock implements BlockStateHolder, TileEntityBlock { return blockState.getAsString() + nbtString; } - - public BlockState toBlockState() { - return blockState; - } - //FAWE end } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java index 19341d084..4511b7b38 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java @@ -250,11 +250,6 @@ public class BlockState implements BlockStateHolder, Pattern { return getBlockType().withPropertyId(propertyId); } - @Override - public BlockType getBlockType() { - return this.blockType; - } - @Override public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException { return set.setBlock(extent, this); @@ -338,15 +333,22 @@ public class BlockState implements BlockStateHolder, Pattern { } return newState; } + //FAWE end @Override public Map, Object> getStates() { + //FAWE end BlockType type = this.getBlockType(); // Lazily initialize the map Map map = Maps.asMap(type.getPropertiesSet(), (Function) this::getState); - return Collections.unmodifiableMap((Map, Object>) map); + return Collections.unmodifiableMap(map); + //FAWE end + } + + @Override + public BlockType getBlockType() { + return this.blockType; } - //FAWE end @Override public boolean equalsFuzzy(BlockStateHolder o) { @@ -357,10 +359,12 @@ public class BlockState implements BlockStateHolder, Pattern { // Added a reference equality check for speediness return true; } + //FAWE start if (o.getClass() == BlockState.class) { return o.getOrdinal() == this.getOrdinal(); } return o.equalsFuzzy(this); + //FAWE end } @Override @@ -431,20 +435,6 @@ public class BlockState implements BlockStateHolder, Pattern { return this.ordinalChar; } - @Override - public String toString() { - return getAsString(); - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof BlockState)) { - return false; - } - - return equalsFuzzy((BlockState) obj); - } - @Override public int hashCode() { return getOrdinal(); @@ -459,4 +449,18 @@ public class BlockState implements BlockStateHolder, Pattern { return compoundInput.get(this, input, x, y, z); } //FAWE end + + @Override + public String toString() { + return getAsString(); + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof BlockState)) { + return false; + } + + return equalsFuzzy((BlockState) obj); + } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockStateHolder.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockStateHolder.java index 9c914228c..e6c451743 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockStateHolder.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockStateHolder.java @@ -92,6 +92,15 @@ public interface BlockStateHolder> extends TileEnt */ B with(final Property property, final V value); + /** + * Gets the value for the given state. + * + * @param property The state + * @return The value + */ + V getState(Property property); + + //FAWE start /** * Returns a BlockStateHolder with the given state and value applied. * @@ -101,14 +110,6 @@ public interface BlockStateHolder> extends TileEnt */ B with(final PropertyKey property, final V value); - /** - * Gets the value for the given state. - * - * @param property The state - * @return The value - */ - V getState(Property property); - /** * Gets the value for the given state. * @@ -116,6 +117,7 @@ public interface BlockStateHolder> extends TileEnt * @return The value */ V getState(final PropertyKey property); + //FAWE end /** * Gets an immutable collection of the states. @@ -146,8 +148,6 @@ public interface BlockStateHolder> extends TileEnt */ BaseBlock toBaseBlock(); - //FAWE start - /** * Gets a {@link BaseBlock} from this BlockStateHolder. * @@ -193,6 +193,7 @@ public interface BlockStateHolder> extends TileEnt return toBaseBlock(); } + //FAWE start void applyTileEntity(OutputExtent output, int x, int y, int z); default BaseBlock toBaseBlock(ITileInput input, int x, int y, int z) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java index 5ed34c83e..043a89bf5 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java @@ -60,17 +60,15 @@ public class BlockType implements Keyed, Pattern { private static final Logger LOGGER = LogManagerCompat.getLogger(); private final String id; - private final BlockTypesCache.Settings settings; private final LazyReference emptyFuzzy = LazyReference.from(() -> new FuzzyBlockState(this)); + //FAWE start + private final BlockTypesCache.Settings settings; @Deprecated private final LazyReference name = LazyReference.from(() -> WorldEdit.getInstance().getPlatformManager() .queryCapability(Capability.GAME_HOOKS).getRegistries().getBlockRegistry().getName(this)); //FAWE start - private final LazyReference legacyId = LazyReference.from(() -> computeLegacy(0)); - private final LazyReference legacyData = LazyReference.from(() -> computeLegacy(1)); - private Integer legacyCombinedId; private boolean initItemType; private ItemType itemType; @@ -382,6 +380,11 @@ public class BlockType implements Keyed, Pattern { //FAWE end } + @Override + public String toString() { + return getId(); + } + //FAWE start /** @@ -397,11 +400,6 @@ public class BlockType implements Keyed, Pattern { return this.settings.internalId; } - @Override - public String toString() { - return getId(); - } - @Override public int hashCode() { return settings.internalId; // stop changing this to WEs bad hashcode diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypesCache.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypesCache.java index 59ed85560..1a4bba755 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypesCache.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypesCache.java @@ -37,16 +37,16 @@ public class BlockTypesCache { */ protected static final class Settings { - protected final int internalId; - protected final BlockState defaultState; - protected final AbstractProperty[] propertiesMapArr; - protected final AbstractProperty[] propertiesArr; - protected final List> propertiesList; - protected final Map> propertiesMap; - protected final Set> propertiesSet; - protected final BlockMaterial blockMaterial; - protected final int permutations; - protected int[] stateOrdinals; + final int internalId; + final BlockState defaultState; + final AbstractProperty[] propertiesMapArr; + final AbstractProperty[] propertiesArr; + final List> propertiesList; + final Map> propertiesMap; + final Set> propertiesSet; + final BlockMaterial blockMaterial; + final int permutations; + int[] stateOrdinals; Settings(BlockType type, String id, int internalId, List states) { this.internalId = internalId; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/FuzzyBlockState.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/FuzzyBlockState.java index c5e73147d..9a20f9386 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/FuzzyBlockState.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/FuzzyBlockState.java @@ -52,8 +52,8 @@ public class FuzzyBlockState extends BlockState { } //FAWE end - //FAWE start - use internal ids private FuzzyBlockState(BlockState state, Map, Object> values) { + //FAWE start - use internal ids super(state.getBlockType(), state.getInternalId(), state.getOrdinal()); if (values == null || values.isEmpty()) { props = Collections.emptyMap(); @@ -65,9 +65,8 @@ public class FuzzyBlockState extends BlockState { } this.values = new HashMap<>(values); } - + //FAWE end } - //FAWE end /** * Gets a full BlockState from this fuzzy one, filling in @@ -85,6 +84,11 @@ public class FuzzyBlockState extends BlockState { return state; } + @Override + public BlockState toImmutableState() { + return getFullState(); + } + //FAWE start @Override public boolean equalsFuzzy(BlockStateHolder o) { @@ -113,15 +117,16 @@ public class FuzzyBlockState extends BlockState { return new BaseBlock(state); } - @Override - public BlockState toImmutableState() { - return getFullState(); - } - @Override public Map, Object> getStates() { return values; } + + @Deprecated + @Override + public CompoundTag getNbtData() { + return getBlockType().getMaterial().isTile() ? getBlockType().getMaterial().getDefaultTile() : null; + } //FAWE end /** @@ -133,14 +138,6 @@ public class FuzzyBlockState extends BlockState { return new Builder(); } - //FAWE start - @Deprecated - @Override - public CompoundTag getNbtData() { - return getBlockType().getMaterial().isTile() ? getBlockType().getMaterial().getDefaultTile() : null; - } - //FAWE end - /** * Builder for FuzzyBlockState */