Major command changes that don't work yet.

This commit is contained in:
MattBDev
2019-07-05 20:46:48 -04:00
parent ffc2092d93
commit 8108d0a936
399 changed files with 13558 additions and 7985 deletions

View File

@ -24,6 +24,7 @@ import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.TileEntityBlock;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.registry.state.Property;
@ -44,7 +45,7 @@ import java.util.Objects;
* snapshot of blocks correctly, so, for example, the NBT data for a block
* may be missing.</p>
*/
public class BaseBlock implements BlockStateHolder<BaseBlock> {
public class BaseBlock implements BlockStateHolder<BaseBlock>, TileEntityBlock {
private BlockState blockState;
@Nullable protected CompoundTag nbtData;
@ -236,22 +237,6 @@ public class BaseBlock implements BlockStateHolder<BaseBlock> {
return this;
}
@Override
public BaseBlock toBaseBlock(CompoundTag compoundTag) {
if (compoundTag == null) {
return this.blockState.toBaseBlock();
} else if (compoundTag == this.nbtData) {
return this;
} else {
return new BaseBlock(this.blockState, compoundTag);
}
}
@Override
public int hashCode() {
return getOrdinal();
}
@Override
public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException {
return extent.setBlock(set, this);
@ -277,18 +262,38 @@ public class BaseBlock implements BlockStateHolder<BaseBlock> {
return toImmutableState().with(property, value).toBaseBlock(getNbtData());
}
@Override
public <V> V getState(PropertyKey property) {
return toImmutableState().getState(property);
}
@Override
public String toString() {
if (getNbtData() != null) {
return getAsString() + " {" + String.valueOf(getNbtData()) + "}";
public BaseBlock toBaseBlock(CompoundTag compoundTag) {
if (compoundTag == null) {
return this.blockState.toBaseBlock();
} else if (compoundTag == this.nbtData) {
return this;
} else {
return getAsString();
return new BaseBlock(this.blockState, compoundTag);
}
}
@Override
public <V> V getState(PropertyKey property) {
return toImmutableState().getState(property);
}
@Override
public int hashCode() {
int ret = toImmutableState().hashCode() << 3;
if (hasNbtData()) {
ret += getNbtData().hashCode();
}
return ret;
}
@Override
public String toString() {
// if (getNbtData() != null) { // TODO Maybe make some JSON serialiser to make this not awful.
// return blockState.getAsString() + " {" + String.valueOf(getNbtData()) + "}";
// } else {
return blockState.getAsString();
// }
}
}

View File

@ -26,17 +26,24 @@ public final class BlockCategories {
public static final BlockCategory ACACIA_LOGS = get("minecraft:acacia_logs");
public static final BlockCategory ANVIL = get("minecraft:anvil");
public static final BlockCategory BAMBOO_PLANTABLE_ON = get("minecraft:bamboo_plantable_on");
public static final BlockCategory BANNERS = get("minecraft:banners");
public static final BlockCategory BEDS = get("minecraft:beds");
public static final BlockCategory BIRCH_LOGS = get("minecraft:birch_logs");
public static final BlockCategory BUTTONS = get("minecraft:buttons");
public static final BlockCategory CARPETS = get("minecraft:carpets");
public static final BlockCategory CORALS = get("minecraft:corals");
public static final BlockCategory CORAL_BLOCKS = get("minecraft:coral_blocks");
public static final BlockCategory CORAL_PLANTS = get("minecraft:coral_plants");
public static final BlockCategory CORALS = get("minecraft:corals");
public static final BlockCategory DARK_OAK_LOGS = get("minecraft:dark_oak_logs");
public static final BlockCategory DIRT_LIKE = get("minecraft:dirt_like");
public static final BlockCategory DOORS = get("minecraft:doors");
public static final BlockCategory DRAGON_IMMUNE = get("minecraft:dragon_immune");
public static final BlockCategory ENDERMAN_HOLDABLE = get("minecraft:enderman_holdable");
public static final BlockCategory FENCES = get("minecraft:fences");
public static final BlockCategory FLOWER_POTS = get("minecraft:flower_pots");
public static final BlockCategory ICE = get("minecraft:ice");
public static final BlockCategory IMPERMEABLE = get("minecraft:impermeable");
public static final BlockCategory JUNGLE_LOGS = get("minecraft:jungle_logs");
public static final BlockCategory LEAVES = get("minecraft:leaves");
public static final BlockCategory LOGS = get("minecraft:logs");
@ -45,16 +52,27 @@ public final class BlockCategories {
public static final BlockCategory RAILS = get("minecraft:rails");
public static final BlockCategory SAND = get("minecraft:sand");
public static final BlockCategory SAPLINGS = get("minecraft:saplings");
public static final BlockCategory SIGNS = get("minecraft:signs");
public static final BlockCategory SLABS = get("minecraft:slabs");
public static final BlockCategory SMALL_FLOWERS = get("minecraft:small_flowers");
public static final BlockCategory SPRUCE_LOGS = get("minecraft:spruce_logs");
public static final BlockCategory STAIRS = get("minecraft:stairs");
public static final BlockCategory STANDING_SIGNS = get("minecraft:standing_signs");
public static final BlockCategory STONE_BRICKS = get("minecraft:stone_bricks");
public static final BlockCategory TRAPDOORS = get("minecraft:trapdoors");
public static final BlockCategory UNDERWATER_BONEMEALS = get("minecraft:underwater_bonemeals");
public static final BlockCategory VALID_SPAWN = get("minecraft:valid_spawn");
public static final BlockCategory WALL_CORALS = get("minecraft:wall_corals");
public static final BlockCategory WALL_SIGNS = get("minecraft:wall_signs");
public static final BlockCategory WALLS = get("minecraft:walls");
public static final BlockCategory WITHER_IMMUNE = get("minecraft:wither_immune");
public static final BlockCategory WOODEN_BUTTONS = get("minecraft:wooden_buttons");
public static final BlockCategory WOODEN_DOORS = get("minecraft:wooden_doors");
public static final BlockCategory WOODEN_FENCES = get("minecraft:wooden_fences");
public static final BlockCategory WOODEN_PRESSURE_PLATES = get("minecraft:wooden_pressure_plates");
public static final BlockCategory WOODEN_SLABS = get("minecraft:wooden_slabs");
public static final BlockCategory WOODEN_STAIRS = get("minecraft:wooden_stairs");
public static final BlockCategory WOODEN_TRAPDOORS = get("minecraft:wooden_trapdoors");
public static final BlockCategory WOOL = get("minecraft:wool");
private BlockCategories() {

View File

@ -22,6 +22,7 @@ package com.sk89q.worldedit.world.block;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.registry.Category;
import com.sk89q.worldedit.registry.Keyed;
import com.sk89q.worldedit.registry.NamespacedRegistry;
import java.util.Set;
@ -30,7 +31,7 @@ import java.util.Set;
* A category of blocks. This is due to the splitting up of
* blocks such as wool into separate ids.
*/
public class BlockCategory extends Category<BlockType> {
public class BlockCategory extends Category<BlockType> implements Keyed {
public static final NamespacedRegistry<BlockCategory> REGISTRY = new NamespacedRegistry<>("block tag");

View File

@ -66,7 +66,7 @@ public class BlockState implements BlockStateHolder<BlockState>, FawePattern {
* @deprecated magic number
* @return BlockState
*/
@Deprecated
public static BlockState getFromInternalId(int combinedId) throws InputParseException {
return BlockTypes.getFromStateId(combinedId).withStateId(combinedId);
@ -208,7 +208,6 @@ public class BlockState implements BlockStateHolder<BlockState>, FawePattern {
return getBlockType().withPropertyId(propertyId);
}
@Override
public BlockType getBlockType() {
return this.blockType;
@ -250,6 +249,16 @@ public class BlockState implements BlockStateHolder<BlockState>, FawePattern {
}
}
@Override
public <V> V getState(final Property<V> property) {
try {
AbstractProperty ap = (AbstractProperty) property;
return (V) ap.getValue(this.getInternalId());
} catch (ClassCastException e) {
throw new IllegalArgumentException("Property not found: " + property);
}
}
@Override
public <V> BlockState with(final PropertyKey property, final V value) {
try {
@ -262,7 +271,7 @@ public class BlockState implements BlockStateHolder<BlockState>, FawePattern {
}
@Override
public final Map<Property<?>, Object> getStates() {
public Map<Property<?>, Object> getStates() {
BlockType type = this.getBlockType();
// Lazily initialize the map
Map<? extends Property, Object> map = Maps.asMap(type.getPropertiesSet(), (Function<Property, Object>) this::getState);
@ -270,13 +279,19 @@ public class BlockState implements BlockStateHolder<BlockState>, FawePattern {
}
@Override
public final <V> V getState(final Property<V> property) {
try {
AbstractProperty ap = (AbstractProperty) property;
return (V) ap.getValue(this.getInternalId());
} catch (ClassCastException e) {
throw new IllegalArgumentException("Property not found: " + property);
public boolean equalsFuzzy(BlockStateHolder<?> o) {
if (null == o) {
return false;
}
if (this == o) {
// Added a reference equality check for speediness
return true;
}
if (o.getClass() == BlockState.class) {
return o.getOrdinal() == this.getOrdinal();
}
return o.equalsFuzzy(this);
}
@Override
@ -291,7 +306,7 @@ public class BlockState implements BlockStateHolder<BlockState>, FawePattern {
@Deprecated
@Override
public final <V> V getState(final PropertyKey key) {
public <V> V getState(PropertyKey key) {
return getState(getBlockType().getProperty(key));
}
@ -303,14 +318,6 @@ public class BlockState implements BlockStateHolder<BlockState>, FawePattern {
return new BaseBlock(this, compoundTag);
}
@Override
public boolean equalsFuzzy(BlockStateHolder<?> o) {
if (o.getClass() == BlockState.class) {
return o.getOrdinal() == this.getOrdinal();
}
return o.equalsFuzzy(this);
}
@Override
public int getInternalId() {
return internalId;

View File

@ -21,30 +21,30 @@ package com.sk89q.worldedit.world.block;
import static com.google.common.base.Preconditions.checkArgument;
import com.boydti.fawe.util.ReflectionUtils;
import com.google.common.collect.ImmutableList;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.SingleBlockTypeMask;
import com.sk89q.worldedit.function.pattern.FawePattern;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.WorldEdit;
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.item.ItemTypes;
import com.sk89q.worldedit.world.registry.BlockMaterial;
import com.sk89q.worldedit.world.registry.LegacyMapper;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.*;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import javax.annotation.Nullable;
public class BlockType implements FawePattern, Keyed {
private final String id;
@ -71,7 +71,7 @@ public class BlockType implements FawePattern, Keyed {
*/
@Override
public String getId() {
return this.id;
return this.id;
}
public String getNamespace() {
@ -104,35 +104,17 @@ public class BlockType implements FawePattern, Keyed {
if (settings.stateOrdinals == null) return settings.defaultState;
return BlockTypes.states[settings.stateOrdinals[propertyId]];
}
@Deprecated
public BlockState withStateId(int internalStateId) { //
return this.withPropertyId(internalStateId >> BlockTypes.BIT_OFFSET);
}
/**
* Properties string in the form property1=foo,prop2=bar
* @param properties
* @return
*/
public BlockState withProperties(String properties) { //
int id = getInternalId();
for (String keyPair : properties.split(",")) {
String[] split = keyPair.split("=");
String name = split[0];
String value = split[1];
AbstractProperty btp = settings.propertiesMap.get(name);
id = btp.modify(id, btp.getValueFor(value));
}
return withStateId(id);
}
/**
* Gets the properties of this BlockType in a key->property mapping.
* Gets the properties of this BlockType in a {@code key->property} mapping.
*
* @return The properties map
*/
@Deprecated
public Map<String, ? extends Property<?>> getPropertyMap() {
return this.settings.propertiesMap;
}
@ -142,9 +124,8 @@ public class BlockType implements FawePattern, Keyed {
*
* @return the properties
*/
@Deprecated
public List<? extends Property<?>> getProperties() {
return this.settings.propertiesList;
return ImmutableList.copyOf(this.getPropertyMap().values());
}
@Deprecated
@ -158,16 +139,19 @@ public class BlockType implements FawePattern, Keyed {
* @param name The name
* @return The property
*/
@Deprecated
public <V> Property<V> getProperty(String name) {
return (Property<V>) this.settings.propertiesMap.get(name);
// Assume it works, CCE later at runtime if not.
@SuppressWarnings("unchecked")
Property<V> property = (Property<V>) getPropertyMap().get(name);
checkArgument(property != null, "%s has no property named %s", this, name);
return property;
}
public boolean hasProperty(PropertyKey key) {
int ordinal = key.ordinal();
return this.settings.propertiesMapArr.length > ordinal ? this.settings.propertiesMapArr[ordinal] != null : false;
}
public <V> Property<V> getProperty(PropertyKey key) {
try {
return (Property<V>) this.settings.propertiesMapArr[key.ordinal()];
@ -185,7 +169,7 @@ public class BlockType implements FawePattern, Keyed {
return this.settings.defaultState;
}
public FuzzyBlockState getFuzzyMatcher() { //
public FuzzyBlockState getFuzzyMatcher() {
return new FuzzyBlockState(this);
}
@ -222,7 +206,6 @@ public class BlockType implements FawePattern, Keyed {
return withStateId(id);
}
/**
* Gets whether this block type has an item representation.
*
@ -262,6 +245,7 @@ public class BlockType implements FawePattern, Keyed {
*
* @return legacy id or 0, if unknown
*/
@Deprecated
public int getLegacyCombinedId() {
Integer combinedId = LegacyMapper.getInstance().getLegacyCombined(this);
return combinedId == null ? 0 : combinedId;
@ -278,21 +262,21 @@ public class BlockType implements FawePattern, Keyed {
return this.settings.internalId;
}
@Override
public String toString() {
return getId();
}
@Override
public int hashCode() {
return settings.internalId;
return this.id.hashCode();
}
@Override
public boolean equals(Object obj) {
return obj == this;
return obj instanceof BlockType && this.id.equals(((BlockType) obj).id);
}
@Override
public String toString() {
return getId();
}
@Override
public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException {
@ -310,7 +294,7 @@ public class BlockType implements FawePattern, Keyed {
@Deprecated
public int getLegacyId() { //
public int getLegacyId() {
Integer id = LegacyMapper.getInstance().getLegacyCombined(this.getDefaultState());
if (id != null) {
return id >> 4;

View File

@ -20,6 +20,7 @@
package com.sk89q.worldedit.world.block;
import static com.google.common.base.Preconditions.checkNotNull;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.registry.state.PropertyKey;
@ -38,11 +39,7 @@ public class FuzzyBlockState extends BlockState {
private final Map<PropertyKey, Object> props;
FuzzyBlockState(BlockType blockType) {
this(blockType.getDefaultState(), null);
}
public FuzzyBlockState(BlockState state) {
this(state, null);
super(blockType);
}
private FuzzyBlockState(BlockState state, Map<Property<?>, Object> values) {