Make property changes more robust (#2962)
This commit is contained in:
@ -137,4 +137,9 @@ public class PropertyKey implements Comparable<PropertyKey> {
|
|||||||
return Integer.compare(this.id, o.id);
|
return Integer.compare(this.id, o.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "PropertyKey[" + getName() + "]";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -351,7 +351,7 @@ public class BlockState implements BlockStateHolder<BlockState>, Pattern {
|
|||||||
BlockState newState = this;
|
BlockState newState = this;
|
||||||
for (Property<?> prop : ot.getProperties()) {
|
for (Property<?> prop : ot.getProperties()) {
|
||||||
PropertyKey key = prop.getKey();
|
PropertyKey key = prop.getKey();
|
||||||
if (blockType.hasProperty(key)) {
|
if (blockType.hasPropertyOfType(key, prop.getClass())) {
|
||||||
newState = newState.with(key, other.getState(key));
|
newState = newState.with(key, other.getState(key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -247,6 +247,21 @@ public class BlockType implements Keyed, Pattern {
|
|||||||
return this.settings.propertiesMapArr.length > ordinal && this.settings.propertiesMapArr[ordinal] != null;
|
return this.settings.propertiesMapArr.length > ordinal && this.settings.propertiesMapArr[ordinal] != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@return whether this block type has a property with given key of the given type}
|
||||||
|
*
|
||||||
|
* @param key the key identifying the property
|
||||||
|
* @param propertyType the expected type of the property
|
||||||
|
* @since TODO
|
||||||
|
*/
|
||||||
|
public boolean hasPropertyOfType(PropertyKey key, Class<?> propertyType) {
|
||||||
|
int ordinal = key.getId();
|
||||||
|
Property<?> property;
|
||||||
|
return this.settings.propertiesMapArr.length > ordinal
|
||||||
|
&& (property = this.settings.propertiesMapArr[ordinal]) != null
|
||||||
|
&& property.getClass() == propertyType;
|
||||||
|
}
|
||||||
|
|
||||||
public <V> Property<V> getProperty(PropertyKey key) {
|
public <V> Property<V> getProperty(PropertyKey key) {
|
||||||
try {
|
try {
|
||||||
return (Property<V>) this.settings.propertiesMapArr[key.getId()];
|
return (Property<V>) this.settings.propertiesMapArr[key.getId()];
|
||||||
|
|||||||
Reference in New Issue
Block a user