Skip to content

Commit

Permalink
Make property changes more robust (#2962)
Browse files Browse the repository at this point in the history
  • Loading branch information
SirYwell authored Nov 4, 2024
1 parent bd94632 commit 7281fa3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,9 @@ public int compareTo(@Nonnull PropertyKey o) {
return Integer.compare(this.id, o.id);
}

@Override
public String toString() {
return "PropertyKey[" + getName() + "]";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ public <V> BlockState withProperties(final BlockState other) {
BlockState newState = this;
for (Property<?> prop : ot.getProperties()) {
PropertyKey key = prop.getKey();
if (blockType.hasProperty(key)) {
if (blockType.hasPropertyOfType(key, prop.getClass())) {
newState = newState.with(key, other.getState(key));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,21 @@ public boolean hasProperty(PropertyKey key) {
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) {
try {
return (Property<V>) this.settings.propertiesMapArr[key.getId()];
Expand Down

0 comments on commit 7281fa3

Please sign in to comment.