wip on 1.14

This commit is contained in:
Jesse Boyd
2019-07-09 17:18:51 +10:00
229 changed files with 9489 additions and 3025 deletions

View File

@ -20,17 +20,16 @@
package com.sk89q.worldedit.world;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.function.mask.BlockMask;
import com.sk89q.worldedit.blocks.BaseItem;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.function.mask.BlockTypeMask;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.operation.Operation;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.util.Direction;
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;
@ -63,7 +62,7 @@ public abstract class AbstractWorld implements World {
@Override
public Mask createLiquidMask() {
return new BlockTypeMask(this, BlockTypes.LAVA, BlockTypes.WATER);
return new BlockMask(this).add(BlockTypes.LAVA, BlockTypes.WATER);
}
@Override
@ -90,11 +89,6 @@ public abstract class AbstractWorld implements World {
return false;
}
@Override
public BlockState getLazyBlock(BlockVector3 position) {
return getBlock(position);
}
@Override
public boolean queueBlockBreakEffect(Platform server, BlockVector3 position, BlockType blockType, double priority) {
if (taskId == -1) {

View File

@ -81,12 +81,12 @@ public class NullWorld extends AbstractWorld {
}
@Override
public BiomeType getBiome(BlockVector2 position) {
public BiomeType getBiomeType(int x, int z) {
return BiomeTypes.THE_VOID;
}
@Override
public boolean setBiome(BlockVector2 position, BiomeType biome) {
public boolean setBiome(int x, int y, int z, BiomeType biome) {
return false;
}
@ -132,13 +132,18 @@ public class NullWorld extends AbstractWorld {
}
@Override
public BlockState getBlock(BlockVector3 position) {
public BlockState getBlock(int x, int y, int z) {
return BlockTypes.AIR.getDefaultState();
}
@Override
public BlockState getLazyBlock(BlockVector3 position) {
return getBlock(position);
public BaseBlock getFullBlock(int x, int y, int z) {
return BlockTypes.AIR.getDefaultState().toBaseBlock();
}
@Override
public <T extends BlockStateHolder<T>> boolean setBlock(int x, int y, int z, T block) throws WorldEditException {
return false;
}
@Override

View File

@ -61,7 +61,7 @@ public interface SimpleWorld extends World {
@Override
default BaseBlock getFullBlock(BlockVector3 position) {
return getLazyBlock(position).toBaseBlock();
return getBlock(position).toBaseBlock();
}
@Override
@ -74,7 +74,7 @@ public interface SimpleWorld extends World {
@Override
default Mask createLiquidMask() {
return new BlockTypeMask(this, BlockTypes.LAVA, BlockTypes.WATER);
return new BlockMask(this).add(BlockTypes.LAVA, BlockTypes.WATER);
}
@Override

View File

@ -94,7 +94,9 @@ 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)
*/
<B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block, boolean notifyAndLight) throws WorldEditException;
default <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block, boolean notifyAndLight) throws WorldEditException {
return setBlock(position, block);
}
/**
* Notifies the simulation that the block at the given location has

View File

@ -45,9 +45,8 @@ import java.util.Objects;
* may be missing.</p>
*/
public class BaseBlock implements BlockStateHolder<BaseBlock> {
private BlockState blockState;
@Nullable protected CompoundTag nbtData;
private final BlockState blockState;
private final CompoundTag nbtData;
@Deprecated
public BaseBlock() {
@ -70,6 +69,7 @@ public class BaseBlock implements BlockStateHolder<BaseBlock> {
*/
public BaseBlock(BlockState blockState) {
this.blockState = blockState;
nbtData = null;
}
/**
@ -180,7 +180,7 @@ public class BaseBlock implements BlockStateHolder<BaseBlock> {
@Override
public void setNbtData(@Nullable CompoundTag nbtData) {
this.nbtData = nbtData;
throw new UnsupportedOperationException("Immutable");
}
/**
@ -232,7 +232,12 @@ public class BaseBlock implements BlockStateHolder<BaseBlock> {
}
@Override
public BaseBlock toBaseBlock() {
public final char getOrdinalChar() {
return blockState.getOrdinalChar();
}
@Override
public final BaseBlock toBaseBlock() {
return this;
}
@ -247,6 +252,10 @@ public class BaseBlock implements BlockStateHolder<BaseBlock> {
}
}
public BlockState toBlockState() {
return blockState;
}
@Override
public int hashCode() {
return getOrdinal();
@ -254,7 +263,8 @@ public class BaseBlock implements BlockStateHolder<BaseBlock> {
@Override
public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException {
return extent.setBlock(set, this);
set.setFullBlock(extent, this);
return true;
}
@Override

View File

@ -19,6 +19,7 @@
package com.sk89q.worldedit.world.block;
import com.boydti.fawe.beta.FilterBlock;
import com.boydti.fawe.command.SuggestInputParseException;
import com.boydti.fawe.object.string.MutableCharSequence;
import com.boydti.fawe.util.StringMan;
@ -49,6 +50,7 @@ import java.util.stream.Stream;
public class BlockState implements BlockStateHolder<BlockState>, FawePattern {
private final int internalId;
private final int ordinal;
private final char ordinalChar;
private final BlockType blockType;
private BlockMaterial material;
private BaseBlock emptyBaseBlock;
@ -57,7 +59,8 @@ public class BlockState implements BlockStateHolder<BlockState>, FawePattern {
this.blockType = blockType;
this.internalId = internalId;
this.ordinal = ordinal;
this.emptyBaseBlock = new BaseBlock(this);
this.ordinalChar = (char) ordinal;
this.emptyBaseBlock = new ImmutableBaseBlock(this);
}
/**
@ -215,7 +218,7 @@ public class BlockState implements BlockStateHolder<BlockState>, FawePattern {
}
@Override
public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException {
return extent.setBlock(set, this);
return set.setBlock(extent, this);
}
@Override
@ -261,6 +264,24 @@ public class BlockState implements BlockStateHolder<BlockState>, FawePattern {
}
}
public <V> BlockState withProperties(final BlockState other) {
BlockType ot = other.getBlockType();
if (ot == blockType) {
return other;
}
if (ot.getProperties().isEmpty() || blockType.getProperties().isEmpty()) {
return this;
}
BlockState newState = this;
for (Property<?> prop: ot.getProperties()) {
PropertyKey key = prop.getKey();
if (blockType.hasProperty(key)) {
newState = newState.with(key, other.getState(key));
}
}
return this;
}
@Override
public final Map<Property<?>, Object> getStates() {
BlockType type = this.getBlockType();
@ -327,10 +348,15 @@ public class BlockState implements BlockStateHolder<BlockState>, FawePattern {
return material;
}
@Override
public int getOrdinal() {
return this.ordinal;
}
@Override
public final int getOrdinal() {
return this.ordinal;
}
@Override
public final char getOrdinalChar() {
return this.ordinalChar;
}
@Override
public String toString() {

View File

@ -64,6 +64,9 @@ public interface BlockStateHolder<B extends BlockStateHolder<B>> extends FawePat
@Deprecated
int getOrdinal();
@Deprecated
char getOrdinalChar();
BlockMaterial getMaterial();
/**
* Get type id (legacy uses)

View File

@ -21,7 +21,6 @@ package com.sk89q.worldedit.world.block;
import static com.google.common.base.Preconditions.checkArgument;
import com.boydti.fawe.util.ReflectionUtils;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.mask.Mask;
@ -33,14 +32,12 @@ import com.sk89q.worldedit.registry.Keyed;
import com.sk89q.worldedit.world.item.ItemTypes;
import com.sk89q.worldedit.world.registry.BlockMaterial;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.registry.NamespacedRegistry;
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.item.ItemType;
import com.sk89q.worldedit.world.registry.LegacyMapper;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.*;
import java.util.stream.Collectors;
@ -181,10 +178,15 @@ public class BlockType implements FawePattern, Keyed {
*
* @return The default state
*/
public BlockState getDefaultState() {
public final BlockState getDefaultState() {
return this.settings.defaultState;
}
/**
* @Deprecated use a Mask instead
* @return
*/
@Deprecated
public FuzzyBlockState getFuzzyMatcher() { //
return new FuzzyBlockState(this);
}
@ -296,7 +298,7 @@ public class BlockType implements FawePattern, Keyed {
@Override
public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException {
return extent.setBlock(set, this.getDefaultState());
return set.setBlock(extent, getDefaultState());
}
@Override

View File

@ -52,6 +52,10 @@ import java.util.stream.Stream;
public final class BlockTypes {
// Doesn't really matter what the hardcoded values are, as FAWE will update it on load
@Nullable public static final BlockType __RESERVED__ = null;
@Nullable public static final BlockType AIR = null;
@Nullable public static final BlockType CAVE_AIR = null;
@Nullable public static final BlockType VOID_AIR = null;
@Nullable public static final BlockType ACACIA_BUTTON = null;
@Nullable public static final BlockType ACACIA_DOOR = null;
@Nullable public static final BlockType ACACIA_FENCE = null;
@ -66,7 +70,6 @@ public final class BlockTypes {
@Nullable public static final BlockType ACACIA_TRAPDOOR = null;
@Nullable public static final BlockType ACACIA_WOOD = null;
@Nullable public static final BlockType ACTIVATOR_RAIL = null;
@Nullable public static final BlockType AIR = null;
@Nullable public static final BlockType ALLIUM = null;
@Nullable public static final BlockType ANDESITE = null;
@Nullable public static final BlockType ANVIL = null;
@ -150,7 +153,6 @@ public final class BlockTypes {
@Nullable public static final BlockType CARROTS = null;
@Nullable public static final BlockType CARVED_PUMPKIN = null;
@Nullable public static final BlockType CAULDRON = null;
@Nullable public static final BlockType CAVE_AIR = null;
@Nullable public static final BlockType CHAIN_COMMAND_BLOCK = null;
@Nullable public static final BlockType CHEST = null;
@Nullable public static final BlockType CHIPPED_ANVIL = null;
@ -615,7 +617,6 @@ public final class BlockTypes {
@Nullable public static final BlockType TUBE_CORAL_WALL_FAN = null;
@Nullable public static final BlockType TURTLE_EGG = null;
@Nullable public static final BlockType VINE = null;
@Nullable public static final BlockType VOID_AIR = null;
@Nullable public static final BlockType WALL_SIGN = null;
@Nullable public static final BlockType WALL_TORCH = null;
@Nullable public static final BlockType WATER = null;

View File

@ -0,0 +1,50 @@
package com.sk89q.worldedit.world.block;
import com.boydti.fawe.beta.FilterBlock;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extent.Extent;
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);
}
@Nullable
@Override
public CompoundTag getNbtData() {
return null;
}
@Override
public boolean hasNbtData() {
return false;
}
@Override
public String getNbtId() {
return "";
}
@Override
public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException {
return set.setBlock(extent, toBlockState());
}
@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;
}
}