Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-12-25 18:40:05 +01:00
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)
Dieser Commit ist enthalten in:
Ursprung
e11a2d7f6d
Commit
717a1b5db4
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren