Lazy tags + get / set tiles

Lazy tags means tiles/ents are not translated into the nms NBTBase until it is needed. Should be faster in cases where getFullBlock is called, but nbt is not always needed.
Commands like Copy and Paste, where the input/output are both nms worlds, can entirely bypass WorldEdit translating to and from the WorldEdit JNBT classes.
This commit is contained in:
Jesse Boyd
2019-11-20 03:40:52 +00:00
parent 60759934a3
commit 144ea2ef34
40 changed files with 298 additions and 172 deletions

View File

@ -21,6 +21,7 @@ package com.sk89q.worldedit.world.block;
import static com.google.common.base.Preconditions.checkNotNull;
import com.boydti.fawe.beta.ITileInput;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag;
@ -162,11 +163,6 @@ public class BaseBlock implements BlockStateHolder<BaseBlock>, TileEntityBlock {
return this.nbtData;
}
@Override
public void setNbtData(@Nullable CompoundTag nbtData) {
throw new UnsupportedOperationException("This class is immutable.");
}
/**
* Checks whether the type ID and data value are equal.
*/

View File

@ -19,6 +19,7 @@
package com.sk89q.worldedit.world.block;
import com.boydti.fawe.beta.ITileInput;
import com.boydti.fawe.command.SuggestInputParseException;
import com.boydti.fawe.object.string.MutableCharSequence;
import com.boydti.fawe.util.StringMan;
@ -53,7 +54,8 @@ public class BlockState implements BlockStateHolder<BlockState>, FawePattern {
private final char ordinalChar;
private final BlockType blockType;
private BlockMaterial material;
private BaseBlock emptyBaseBlock;
private final BaseBlock emptyBaseBlock;
private CompoundInput compoundInput = CompoundInput.NULL;
protected BlockState(BlockType blockType, int internalId, int ordinal) {
this.blockType = blockType;
@ -196,7 +198,6 @@ public class BlockState implements BlockStateHolder<BlockState>, FawePattern {
case '=': {
charSequence.setSubstring(last, i);
property = (AbstractProperty) type.getPropertyMap().get(charSequence);
if (property == null) System.out.println("No prop " + charSequence + " | " + type.getPropertyMap());
last = i + 1;
break;
}
@ -356,6 +357,9 @@ public class BlockState implements BlockStateHolder<BlockState>, FawePattern {
return this.material = blockType.getMaterial();
}
this.material = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getRegistries().getBlockRegistry().getMaterial(this);
if (this.material.hasContainer()) {
this.compoundInput = CompoundInput.CONTAINER;
}
}
return material;
}
@ -388,4 +392,17 @@ public class BlockState implements BlockStateHolder<BlockState>, FawePattern {
public int hashCode() {
return getOrdinal();
}
public boolean isAir() {
try {
return material.isAir();
} catch (NullPointerException ignore) {
return getMaterial().isAir();
}
}
@Override
public BaseBlock toBaseBlock(ITileInput input, int x, int y, int z) {
return compoundInput.get(this, input, x, y, z);
}
}

View File

@ -19,7 +19,9 @@
package com.sk89q.worldedit.world.block;
import com.boydti.fawe.beta.ITileInput;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.blocks.TileEntityBlock;
import com.sk89q.worldedit.extent.OutputExtent;
@ -203,6 +205,10 @@ public interface BlockStateHolder<B extends BlockStateHolder<B>> extends FawePat
throw new UnsupportedOperationException("State is immutable");
}
default BaseBlock toBaseBlock(ITileInput input, int x, int y, int z) {
throw new UnsupportedOperationException("State is immutable");
}
default String getAsString() {
if (getStates().isEmpty()) {
return this.getBlockType().getId();

View File

@ -0,0 +1,18 @@
package com.sk89q.worldedit.world.block;
import com.boydti.fawe.beta.ITileInput;
public enum CompoundInput {
NULL,
CONTAINER() {
@Override
public BaseBlock get(BlockState state, ITileInput input, int x, int y, int z) {
return state.toBaseBlock(input.getTag(x, y, z));
}
}
;
public BaseBlock get(BlockState state, ITileInput input, int x, int y, int z) {
return state.toBaseBlock();
}
}

View File

@ -1,5 +1,6 @@
package com.sk89q.worldedit.world.block;
import com.boydti.fawe.beta.ITileInput;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extent.Extent;