Replace ImmutableBaseBlock with BlanketBaseBlock

- ImmutableBaseBlock is no longer needed as NBT was made immutable previously
 - BlanketBaseBlock represents to masks that the block has NBT, but does not need to match a specific state
 - Allow FuzzyBlockState to create BaseBlocks without NBT data (fixed tab completion issues)
This commit is contained in:
dordsor21 2021-06-10 19:47:34 +01:00
parent e11a2d7f6d
commit 717a1b5db4
No known key found for this signature in database
GPG Key ID: 1E53E88969FFCF0B
6 changed files with 50 additions and 64 deletions

View File

@ -57,6 +57,7 @@ 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.block.FuzzyBlockState;
import com.sk89q.worldedit.world.block.BlanketBaseBlock;
import com.sk89q.worldedit.world.entity.EntityType;
import com.sk89q.worldedit.world.entity.EntityTypes;
import com.sk89q.worldedit.world.registry.LegacyMapper;
@ -417,7 +418,8 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
}
if (nbt != null) {
return validate(context, state.toBaseBlock(nbt));
BaseBlock result = blockStates.size() > 0 ? state.toBaseBlock(nbt) : new BlanketBaseBlock(state, nbt);
return validate(context, result);
}
if (blockType == BlockTypes.SIGN || blockType == BlockTypes.WALL_SIGN

View File

@ -27,7 +27,7 @@ import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.block.BlockTypesCache;
import com.sk89q.worldedit.world.block.ImmutableBaseBlock;
import com.sk89q.worldedit.world.block.BlanketBaseBlock;
import javax.annotation.Nullable;
import java.util.Arrays;
@ -155,7 +155,7 @@ public class BlockMask extends ABlockMask {
public void add(Collection<BaseBlock> blocks) {
checkNotNull(blocks);
for (BaseBlock block : blocks) {
if (block instanceof ImmutableBaseBlock) {
if (block instanceof BlanketBaseBlock) {
for (BlockState state : block.getBlockType().getAllStates()) {
ordinals[state.getOrdinal()] = true;
}

View File

@ -0,0 +1,33 @@
package com.sk89q.worldedit.world.block;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.extent.OutputExtent;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.registry.state.Property;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nullable;
/**
* BaseBlock that when parsed to masks represents all BlockStates of a BlockType, whilst allowing for NBT storage
*/
public final class BlanketBaseBlock extends BaseBlock {
public BlanketBaseBlock(BlockState blockState) {
super(blockState);
}
public BlanketBaseBlock(BlockState blockState, @NotNull CompoundTag tile) {
super(blockState, tile);
}
@Override
public BaseBlock toBaseBlock(CompoundTag compoundTag) {
if (compoundTag != null) {
return new BaseBlock(this.toImmutableState(), compoundTag);
}
return this;
}
}

View File

@ -41,6 +41,7 @@ import com.sk89q.worldedit.registry.state.AbstractProperty;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.registry.state.PropertyKey;
import com.sk89q.worldedit.world.registry.BlockMaterial;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.List;
@ -62,12 +63,20 @@ public class BlockState implements BlockStateHolder<BlockState>, Pattern {
private final BaseBlock emptyBaseBlock;
private CompoundInput compoundInput = CompoundInput.NULL;
protected BlockState(BlockType blockType, int internalId, int ordinal, CompoundTag tile) {
protected BlockState(BlockType blockType, int internalId, int ordinal) {
this.blockType = blockType;
this.internalId = internalId;
this.ordinal = ordinal;
this.ordinalChar = (char) ordinal;
this.emptyBaseBlock = new ImmutableBaseBlock(this, tile);
this.emptyBaseBlock = new BlanketBaseBlock(this);
}
protected BlockState(BlockType blockType, int internalId, int ordinal, @NotNull CompoundTag tile) {
this.blockType = blockType;
this.internalId = internalId;
this.ordinal = ordinal;
this.ordinalChar = (char) ordinal;
this.emptyBaseBlock = new BlanketBaseBlock(this, tile);
}
/**

View File

@ -48,7 +48,7 @@ public class FuzzyBlockState extends BlockState {
}
private FuzzyBlockState(BlockState state, Map<Property<?>, Object> values) {
super(state.getBlockType(), state.getInternalId(), state.getOrdinal(), null);
super(state.getBlockType(), state.getInternalId(), state.getOrdinal());
if (values == null || values.isEmpty()) {
props = Collections.emptyMap();
this.values = Collections.emptyMap();

View File

@ -1,58 +0,0 @@
package com.sk89q.worldedit.world.block;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.extent.OutputExtent;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.registry.state.Property;
import javax.annotation.Nullable;
public final class ImmutableBaseBlock extends BaseBlock {
public ImmutableBaseBlock(BlockState blockState) {
super(blockState);
}
public ImmutableBaseBlock(BlockState blockState, CompoundTag tile) {
super(blockState, tile);
}
@Nullable
@Override
public CompoundTag getNbtData() {
return getBlockType().getMaterial().isTile() ? getBlockType().getMaterial().getDefaultTile() : null;
}
@Override
public boolean hasNbtData() {
return getBlockType().getMaterial().isTile();
}
@Override
public String getNbtId() {
return "";
}
@Override
public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException {
return set.setBlock(extent, toBlockState());
}
@Override
public void applyTileEntity(OutputExtent output, int x, int y, int z) {
}
@Override
public <V> BaseBlock with(Property<V> property, V value) {
return toImmutableState().with(property, value).toBaseBlock();
}
@Override
public BaseBlock toBaseBlock(CompoundTag compoundTag) {
if (compoundTag != null) {
return new BaseBlock(this.toImmutableState(), compoundTag);
}
return this;
}
}