From 5788bb64aa9ca5186294441784705bd64c765fb3 Mon Sep 17 00:00:00 2001 From: Spottedleaf Date: Tue, 20 Aug 2024 19:46:20 -0700 Subject: [PATCH] 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. --- .../mixin/blockstate_propertyaccess/StateHolderMixin.java | 6 +++--- src/main/resources/moonrise.accesswidener | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/ca/spottedleaf/moonrise/mixin/blockstate_propertyaccess/StateHolderMixin.java b/src/main/java/ca/spottedleaf/moonrise/mixin/blockstate_propertyaccess/StateHolderMixin.java index c8377b84..d2f58f14 100644 --- a/src/main/java/ca/spottedleaf/moonrise/mixin/blockstate_propertyaccess/StateHolderMixin.java +++ b/src/main/java/ca/spottedleaf/moonrise/mixin/blockstate_propertyaccess/StateHolderMixin.java @@ -101,7 +101,7 @@ public , V extends T> S setValue(final Property prope */ @Overwrite public , V extends T> S trySetValue(final Property property, final V value) { - final S ret = this.optimisedTable.trySet(this.tableIndex, property, value, (S)(StateHolder)(Object)this); + final S ret = property == null ? (S)(StateHolder)(Object)this : this.optimisedTable.trySet(this.tableIndex, property, value, (S)(StateHolder)(Object)this); if (ret == null) { throw new IllegalArgumentException("Cannot set property " + property + " to " + value + " on " + this.owner); } @@ -114,7 +114,7 @@ public , V extends T> S trySetValue(final Property pr */ @Overwrite public > Optional getOptionalValue(final Property 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 @@ public > T getValue(final Property property) { */ @Overwrite public > boolean hasProperty(final Property property) { - return this.optimisedTable.hasProperty(property); + return property != null && this.optimisedTable.hasProperty(property); } } diff --git a/src/main/resources/moonrise.accesswidener b/src/main/resources/moonrise.accesswidener index b4f53fba..949deaf2 100644 --- a/src/main/resources/moonrise.accesswidener +++ b/src/main/resources/moonrise.accesswidener @@ -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 \ No newline at end of file +accessible class net/minecraft/world/level/chunk/storage/RegionFile$ChunkBuffer