Skip to content

Commit f977660

Browse files
committed
Prevent sculk events in addPassenger from deadlocking the game during worldgen
This seems to be a vanilla bug when spawning entities that ride other entities Related: #510
1 parent 6aae0f9 commit f977660

File tree

1 file changed

+31
-0
lines changed
  • common/src/main/java/org/embeddedt/modernfix/common/mixin/bugfix/chunk_deadlock

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.embeddedt.modernfix.common.mixin.bugfix.chunk_deadlock;
2+
3+
import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;
4+
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
5+
import net.minecraft.server.level.ServerLevel;
6+
import net.minecraft.world.entity.Entity;
7+
import net.minecraft.world.level.gameevent.GameEvent;
8+
import org.embeddedt.modernfix.ModernFix;
9+
import org.spongepowered.asm.mixin.Mixin;
10+
import org.spongepowered.asm.mixin.injection.At;
11+
12+
@Mixin(Entity.class)
13+
public class EntityMixin {
14+
/**
15+
* @author embeddedt
16+
* @reason When an entity is added to the world via the worldgen load path (ChunkMap#postLoadProtoChunk calling
17+
* ServerLevel#addWorldGenChunkEntities), attempts to add a passenger result in a deadlock when the sculk event
18+
* tries to raytrace blocks. To fix this, we skip firing the sculk event if the chunk the entity is within is not
19+
* loaded.
20+
*/
21+
@WrapWithCondition(method = "addPassenger", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/Entity;gameEvent(Lnet/minecraft/world/level/gameevent/GameEvent;Lnet/minecraft/world/entity/Entity;)V"))
22+
private boolean onlyAddIfSelfChunkLoaded(Entity instance, GameEvent event, Entity entity) {
23+
var chunkPos = instance.chunkPosition();
24+
if (instance.level() instanceof ServerLevel serverLevel && serverLevel.getChunkSource().getChunkNow(chunkPos.x, chunkPos.z) == null) {
25+
ModernFix.LOGGER.warn("Skipped emitting ENTITY_MOUNT game event for entity {} as it would cause deadlock", instance.toString());
26+
return false;
27+
} else {
28+
return true;
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)