Skip to content

Commit 32b0216

Browse files
committed
Work around Carpet crash when remove_spawn_chunks is enabled
Related: #390
1 parent 9f521ed commit 32b0216

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package org.embeddedt.modernfix.common.mixin.perf.remove_spawn_chunks;
2+
3+
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
4+
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
5+
import net.minecraft.util.SortedArraySet;
6+
import org.embeddedt.modernfix.ModernFix;
7+
import org.spongepowered.asm.mixin.Mixin;
8+
import org.spongepowered.asm.mixin.injection.At;
9+
10+
@Mixin(SortedArraySet.class)
11+
public class SortedArraySetMixin<T> {
12+
/**
13+
* @author embeddedt
14+
* @reason Make add() not crash with a null key, since some mods (Carpet) assume there will always be a spawn ticket,
15+
* and then assume the reference they have is non-null (it can be null with this option enabled).
16+
*/
17+
@WrapOperation(method = "add", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/SortedArraySet;findIndex(Ljava/lang/Object;)I"), require = 0)
18+
private int checkStatus(SortedArraySet<T> instance, T object, Operation<Integer> original) {
19+
if(object == null) {
20+
ModernFix.LOGGER.error("Attempted to insert a null key into SortedArraySet, ignoring");
21+
return 0;
22+
}
23+
return original.call(instance, object);
24+
}
25+
}

0 commit comments

Comments
 (0)