Skip to content

Commit

Permalink
Handle already unloaded dimensions, fix ACGaming#403
Browse files Browse the repository at this point in the history
  • Loading branch information
ACGaming committed Jun 19, 2024
1 parent 356e46c commit f036934
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package mod.acgaming.universaltweaks.tweaks.world.loading;

import mod.acgaming.universaltweaks.UniversalTweaks;
import mod.acgaming.universaltweaks.config.UTConfigGeneral;
import mod.acgaming.universaltweaks.config.UTConfigTweaks;
import net.minecraft.world.DimensionType;
import net.minecraft.world.MinecraftException;
import net.minecraft.world.WorldServer;
Expand All @@ -12,10 +15,6 @@
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;

import mod.acgaming.universaltweaks.UniversalTweaks;
import mod.acgaming.universaltweaks.config.UTConfigGeneral;
import mod.acgaming.universaltweaks.config.UTConfigTweaks;

// Courtesy of Unnoen & tie
@Mod.EventBusSubscriber(modid = UniversalTweaks.MODID)
public class UTUnloader
Expand All @@ -37,8 +36,8 @@ public static void utUnloader(TickEvent.ServerTickEvent event)
@SuppressWarnings("ConstantConditions")
public static void utHandleDimUnload(Integer id)
{
WorldServer worldServer = DimensionManager.getWorld(id);
ChunkProviderServer chunkProviderServer = worldServer.getChunkProvider();
if (!DimensionManager.isDimensionRegistered(id)) return;

DimensionType dimensionType = DimensionManager.getProviderType(id);
String dimensionName = "";

Expand All @@ -49,6 +48,9 @@ public static void utHandleDimUnload(Integer id)
if (dimensionName.matches(dimConfig) || Integer.toString(id).matches(dimConfig)) return;
}

WorldServer worldServer = DimensionManager.getWorld(id);
ChunkProviderServer chunkProviderServer = worldServer.getChunkProvider();

if (!worldServer.provider.getDimensionType().shouldLoadSpawn()
&& ForgeChunkManager.getPersistentChunksFor(worldServer).isEmpty()
&& chunkProviderServer.getLoadedChunkCount() == 0
Expand Down

0 comments on commit f036934

Please sign in to comment.