-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Work around Carpet crash when remove_spawn_chunks is enabled
Related: #390
- Loading branch information
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
...va/org/embeddedt/modernfix/common/mixin/perf/remove_spawn_chunks/SortedArraySetMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<T> { | ||
/** | ||
* @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<T> instance, T object, Operation<Integer> original) { | ||
if(object == null) { | ||
ModernFix.LOGGER.error("Attempted to insert a null key into SortedArraySet, ignoring"); | ||
return 0; | ||
} | ||
return original.call(instance, object); | ||
} | ||
} |