diff --git a/src/main/java/com/lovetropics/minigames/LoveTropics.java b/src/main/java/com/lovetropics/minigames/LoveTropics.java index fe4341632..64356af58 100644 --- a/src/main/java/com/lovetropics/minigames/LoveTropics.java +++ b/src/main/java/com/lovetropics/minigames/LoveTropics.java @@ -63,6 +63,7 @@ import com.lovetropics.minigames.common.core.item.MinigameDataComponents; import com.lovetropics.minigames.common.core.item.MinigameItems; import com.lovetropics.minigames.common.core.map.VoidChunkGenerator; +import com.lovetropics.minigames.common.core.map.workspace.MapWorkspaceManager; import com.lovetropics.minigames.common.role.StreamHosts; import com.lovetropics.minigames.common.util.registry.LoveTropicsRegistrate; import com.mojang.brigadier.CommandDispatcher; @@ -75,6 +76,7 @@ import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.MinecraftServer; +import net.minecraft.world.entity.MobSpawnType; import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.phys.Vec3; import net.neoforged.api.distmarker.Dist; @@ -90,10 +92,12 @@ import net.neoforged.neoforge.client.event.RegisterGuiLayersEvent; import net.neoforged.neoforge.common.NeoForge; import net.neoforged.neoforge.event.RegisterCommandsEvent; +import net.neoforged.neoforge.event.entity.living.MobSpawnEvent; import net.neoforged.neoforge.event.server.ServerAboutToStartEvent; import net.neoforged.neoforge.event.server.ServerStoppingEvent; import org.slf4j.Logger; +import java.util.Objects; import java.util.function.BiConsumer; import java.util.function.Supplier; import java.util.regex.Pattern; @@ -113,6 +117,7 @@ public LoveTropics(IEventBus modBus, ModContainer modContainer) { NeoForge.EVENT_BUS.addListener(this::onServerAboutToStart); NeoForge.EVENT_BUS.addListener(this::onServerStopping); NeoForge.EVENT_BUS.addListener(this::registerCommands); + NeoForge.EVENT_BUS.addListener(this::onAttemptSpawn); modBus.addListener(ConfigLT::onLoad); modBus.addListener(ConfigLT::onFileChange); @@ -227,6 +232,15 @@ private void onServerStopping(final ServerStoppingEvent event) { BackendIntegrations.get().sendClose(); } + private void onAttemptSpawn(final MobSpawnEvent.PositionCheck event) { + if (event.getSpawnType() == MobSpawnType.SPAWNER) { + var workspace = MapWorkspaceManager.get(event.getLevel().getServer()); + if (workspace.getWorkspace(event.getLevel().getLevel().dimension()) != null) { + event.setResult(MobSpawnEvent.PositionCheck.Result.FAIL); + } + } + } + public static void onServerStoppingUnsafely(MinecraftServer server) { RuntimeDimensions.onServerStoppingUnsafely(server); }