Do not always fail hard for null Property values in StateHolder

Some mods pass null to methods in this class that would not NPE
on Vanilla, so we need to preserve that behaviour.
This commit is contained in:
Spottedleaf
2024-08-20 19:46:20 -07:00
parent c9fe98b213
commit 5788bb64aa
2 changed files with 4 additions and 4 deletions

View File

@@ -101,7 +101,7 @@ abstract class StateHolderMixin<O, S> implements PropertyAccessStateHolder {
*/
@Overwrite
public <T extends Comparable<T>, V extends T> S trySetValue(final Property<T> property, final V value) {
final S ret = this.optimisedTable.trySet(this.tableIndex, property, value, (S)(StateHolder<O, S>)(Object)this);
final S ret = property == null ? (S)(StateHolder<O, S>)(Object)this : this.optimisedTable.trySet(this.tableIndex, property, value, (S)(StateHolder<O, S>)(Object)this);
if (ret == null) {
throw new IllegalArgumentException("Cannot set property " + property + " to " + value + " on " + this.owner);
}
@@ -114,7 +114,7 @@ abstract class StateHolderMixin<O, S> implements PropertyAccessStateHolder {
*/
@Overwrite
public <T extends Comparable<T>> Optional<T> getOptionalValue(final Property<T> property) {
return Optional.ofNullable(this.optimisedTable.get(this.tableIndex, property));
return property == null ? Optional.empty() : Optional.ofNullable(this.optimisedTable.get(this.tableIndex, property));
}
/**
@@ -137,6 +137,6 @@ abstract class StateHolderMixin<O, S> implements PropertyAccessStateHolder {
*/
@Overwrite
public <T extends Comparable<T>> boolean hasProperty(final Property<T> property) {
return this.optimisedTable.hasProperty(property);
return property != null && this.optimisedTable.hasProperty(property);
}
}

View File

@@ -286,4 +286,4 @@ accessible method net/minecraft/world/level/chunk/storage/RegionFile write (Lnet
# RegionFile$ChunkBuffer
accessible class net/minecraft/world/level/chunk/storage/RegionFile$ChunkBuffer
accessible class net/minecraft/world/level/chunk/storage/RegionFile$ChunkBuffer