Skip to content

Commit

Permalink
Do not always fail hard for null Property values in StateHolder
Browse files Browse the repository at this point in the history
Some mods pass null to methods in this class that would not NPE
on Vanilla, so we need to preserve that behaviour.
  • Loading branch information
Spottedleaf committed Aug 21, 2024
1 parent c9fe98b commit 5788bb6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public <T extends Comparable<T>, V extends T> S setValue(final Property<T> prope
*/
@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);
}
Expand All @@ -114,7 +114,7 @@ public <T extends Comparable<T>, V extends T> S trySetValue(final Property<T> pr
*/
@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));
}

/**
Expand All @@ -137,6 +137,6 @@ public <T extends Comparable<T>> T getValue(final Property<T> property) {
*/
@Overwrite
public <T extends Comparable<T>> boolean hasProperty(final Property<T> property) {
return this.optimisedTable.hasProperty(property);
return property != null && this.optimisedTable.hasProperty(property);
}
}
2 changes: 1 addition & 1 deletion src/main/resources/moonrise.accesswidener
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 5788bb6

Please sign in to comment.