Merge upstream changes through 88f22f2e

This was not a straightforward merge. A new method was added upstream to:
        worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockType.java

This file has been substantially changed vs upstream worldedit. I merged
things as best I could - added the new method to this interface, and
then implemented it in:
        worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypes.java

Unfortunately there's no easy way to test that it works - so I left a note...

Signed-off-by: Byron Marohn <combustible@live.com>
This commit is contained in:
Byron Marohn
2018-12-23 19:56:33 -08:00
10 changed files with 386 additions and 11 deletions

View File

@ -116,6 +116,11 @@ public class AbstractProperty<T> implements Property<T> {
return this.name;
}
@Override
public String toString() {
return getClass().getSimpleName() + "{name=" + name + "}";
}
@Override
public int hashCode() {
return name.hashCode();

View File

@ -19,6 +19,8 @@
package com.sk89q.worldedit.world.block;
import static com.google.common.base.Preconditions.checkArgument;
import com.google.common.collect.ImmutableList;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEditException;
@ -138,7 +140,9 @@ public interface BlockType extends FawePattern, Comparable<BlockTypes> {
*/
@Deprecated
default <V> Property<V> getProperty(String name) {
return getPropertyMap().get(name);
Property<V> property = getPropertyMap().get(name);
checkArgument(property != null, "%s has no property named %s", this, name);
return property;
}
default boolean hasProperty(PropertyKey key) {
@ -146,7 +150,9 @@ public interface BlockType extends FawePattern, Comparable<BlockTypes> {
}
default <V> Property<V> getProperty(PropertyKey key) {
return getPropertyMap().get(key.getId());
Property<V> property = getPropertyMap().get(key.getId());
checkArgument(property != null, "%s has no property named %s", this, key.getId());
return property;
}
/**
@ -163,6 +169,13 @@ public interface BlockType extends FawePattern, Comparable<BlockTypes> {
*/
List<BlockState> getAllStates();
/**
* Gets a state of this BlockType with the given properties.
*
* @return The state, if it exists
*/
BlockState getState(Map<Property<?>, Object> key);
/**
* Gets whether this block type has an item representation.
*

View File

@ -19,6 +19,8 @@
package com.sk89q.worldedit.world.block;
import static com.google.common.base.Preconditions.checkArgument;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.command.SuggestInputParseException;
import com.boydti.fawe.util.MathMan;
@ -825,6 +827,24 @@ public enum BlockTypes implements BlockType {
return IntStream.of(settings.stateOrdinals).filter(i -> i != -1).mapToObj(i -> states[i]).collect(Collectors.toList());
}
public BlockState getState(Map<Property<?>, Object> key) {
int id = getInternalId();
for (Map.Entry<Property<?>, Object> iter : key.entrySet()) {
Property<?> prop = iter.getKey();
Object value = iter.getValue();
/*
* TODO:
* This is likely wrong. The only place this seems to currently (Dec 23 2018)
* be invoked is via ForgeWorld, and value is a String when invoked there...
*/
AbstractProperty btp = settings.propertiesMap.get(prop.getName());
checkArgument(btp != null, "%s has no property named %s", this, prop.getName());
id = btp.modify(id, btp.getValueFor((String)value));
}
return withStateId(id);
}
@Deprecated
public int getMaxStateId() {
return settings.permutations;