From f0b4f82f1f6aca089a6e24d6033a39cb095cdaba Mon Sep 17 00:00:00 2001 From: IzzelAliz Date: Sun, 24 Jan 2021 01:22:21 +0800 Subject: [PATCH] Workaround for MinecraftForge#7519 --- .../mixin/forge/ForgeInternalHandlerMixin.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/forge/ForgeInternalHandlerMixin.java b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/forge/ForgeInternalHandlerMixin.java index 1f254794..7db440eb 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mixin/forge/ForgeInternalHandlerMixin.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mixin/forge/ForgeInternalHandlerMixin.java @@ -2,7 +2,12 @@ package io.izzel.arclight.common.mixin.forge; import io.izzel.arclight.common.mod.util.ArclightCaptures; import net.minecraft.entity.Entity; +import net.minecraft.util.concurrent.TickDelayedTask; +import net.minecraft.util.math.MathHelper; import net.minecraft.world.World; +import net.minecraft.world.chunk.Chunk; +import net.minecraft.world.chunk.ChunkStatus; +import net.minecraft.world.chunk.IChunk; import net.minecraft.world.server.ServerWorld; import net.minecraftforge.common.ForgeInternalHandler; import org.spongepowered.asm.mixin.Mixin; @@ -15,8 +20,15 @@ public class ForgeInternalHandlerMixin { // Workaround for MinecraftForge#7519 @Redirect(method = "*", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;addEntity(Lnet/minecraft/entity/Entity;)Z")) private boolean arclight$addDuringWorldGen(World world, Entity entityIn) { - return world instanceof ServerWorld && ArclightCaptures.isWorldGenAdd() - ? ((ServerWorld) world).addEntityIfNotDuplicate(entityIn) - : world.addEntity(entityIn); + if (world instanceof ServerWorld && ArclightCaptures.isWorldGenAdd()) { + world.getServer().enqueue(new TickDelayedTask(world.getServer().getTickCounter(), () -> { + IChunk ichunk = world.getChunk(MathHelper.floor(entityIn.getPosX() / 16.0D), MathHelper.floor(entityIn.getPosZ() / 16.0D), ChunkStatus.FULL, entityIn.forceSpawn); + if (ichunk instanceof Chunk) { + ichunk.addEntity(entityIn); + } + })); + return ((ServerWorld) world).addEntityIfNotDuplicate(entityIn); + } + return world.addEntity(entityIn); } }