From 32b0216b1943ef5635cff94cbad7daa51d50a5aa Mon Sep 17 00:00:00 2001 From: embeddedt <42941056+embeddedt@users.noreply.github.com> Date: Tue, 9 Apr 2024 19:13:12 -0400 Subject: [PATCH] Work around Carpet crash when remove_spawn_chunks is enabled Related: #390 --- .../SortedArraySetMixin.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/remove_spawn_chunks/SortedArraySetMixin.java diff --git a/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/remove_spawn_chunks/SortedArraySetMixin.java b/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/remove_spawn_chunks/SortedArraySetMixin.java new file mode 100644 index 00000000..814b2ca9 --- /dev/null +++ b/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/remove_spawn_chunks/SortedArraySetMixin.java @@ -0,0 +1,25 @@ +package org.embeddedt.modernfix.common.mixin.perf.remove_spawn_chunks; + +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import net.minecraft.util.SortedArraySet; +import org.embeddedt.modernfix.ModernFix; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +@Mixin(SortedArraySet.class) +public class SortedArraySetMixin { + /** + * @author embeddedt + * @reason Make add() not crash with a null key, since some mods (Carpet) assume there will always be a spawn ticket, + * and then assume the reference they have is non-null (it can be null with this option enabled). + */ + @WrapOperation(method = "add", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/SortedArraySet;findIndex(Ljava/lang/Object;)I"), require = 0) + private int checkStatus(SortedArraySet instance, T object, Operation original) { + if(object == null) { + ModernFix.LOGGER.error("Attempted to insert a null key into SortedArraySet, ignoring"); + return 0; + } + return original.call(instance, object); + } +}