Posted May 2, 20205 yr For every loaded chunk in the Overworld, I want to load the chunk which corresponds with it in my dimension (same x and z). I currently have: @SubscribeEvent public static void chunkLoad(final ChunkEvent.Load event) { if (event.getWorld() != null) if (!event.getWorld().isRemote()) { ServerWorld world = (ServerWorld) event.getWorld(); if (world.dimension.getType() == DBMDimensions.realm_of_the_ancients) { // Force Loads Corresponding Chunks in the Overworld DBMChunkManager.getLoadedChunks(world).forEach((a, b) -> world.getServer().getWorld(DimensionType.OVERWORLD).forceChunk(b.getPosition().x, b.getPosition().z, true)); } else if (world.dimension.getType() == DimensionType.OVERWORLD && DBMDimensions.realm_of_the_ancients != null) { // Force Loads Corresponding Chunks in the Realm of the Ancients DBMChunkManager.getLoadedChunks(world).forEach((a, b) -> world.getServer().getWorld(DBMDimensions.realm_of_the_ancients).forceChunk(b.getPosition().x, b.getPosition().z, true)); } } } @SubscribeEvent public static void chunkUnload(final ChunkEvent.Unload event) { if (event.getWorld() != null) if (!event.getWorld().isRemote()) { ServerWorld world = (ServerWorld) event.getWorld(); if (world.dimension.getType() == DBMDimensions.realm_of_the_ancients) { // Force Unloads Corresponding Chunks in the Overworld world.getServer().getWorld(DimensionType.OVERWORLD).forceChunk(event.getChunk().getPos().x, event.getChunk().getPos().z, false); } else if (world.dimension.getType() == DimensionType.OVERWORLD && DBMDimensions.realm_of_the_ancients != null) { // Force Unloads Corresponding Chunks in the Realm of the Ancients world.getServer().getWorld(DBMDimensions.realm_of_the_ancients).forceChunk(event.getChunk().getPos().x, event.getChunk().getPos().z, false); } } } And here is the class I made to get the loaded chunks: public class DBMChunkManager { private static final Field LOADED_CHUNKS_FIELD = ObfuscationReflectionHelper.findField(ChunkManager.class, "immutableLoadedChunks"); static { LOADED_CHUNKS_FIELD.setAccessible(true); } @SuppressWarnings("unchecked") @Nullable public static Long2ObjectLinkedOpenHashMap<ChunkHolder> getLoadedChunks(ServerWorld world) { try { return (Long2ObjectLinkedOpenHashMap<ChunkHolder>) LOADED_CHUNKS_FIELD.get(world.getChunkProvider().chunkManager); } catch (Exception e) { e.printStackTrace(); } return null; } } However, any time I try to create a new world, the game gets stuck at 0%. The last console message to show up is: [01May2020 23:18:46.645] [Server thread/INFO] [net.minecraftforge.common.DimensionManager/DIMS]: Registered dimension daboismod:the_realm_of_the_ancients of type daboismod:the_realm_of_the_ancients and id 3 The game doesn't crash or suspend, it just does not do anything from this point onward. Any help is greatly appreciated.
May 2, 20205 yr Author 8 hours ago, diesieben07 said: You have a deadlock, because while a chunk is being loaded the loaded chunk map is being blocked. How would I go about fixing the deadlock? I removed the DBMChunkManager class as I realized I didn't need it. Here is the new code: @SubscribeEvent public static void chunkLoad(final ChunkEvent.Load event) { if (event.getWorld() != null) if (event.getWorld().chunkExists(event.getChunk().getPos().x, event.getChunk().getPos().z)) if (!event.getWorld().isRemote()) { ServerWorld world = (ServerWorld) event.getWorld(); if (world.dimension.getType() == DBMDimensions.realm_of_the_ancients) { // Force Loads Corresponding Chunks in the Overworld world.getServer().getWorld(DimensionType.OVERWORLD).forceChunk(event.getChunk().getPos().x, event.getChunk().getPos().z, true); } else if (world.dimension.getType() == DimensionType.OVERWORLD && DBMDimensions.realm_of_the_ancients != null) { // Force Loads Corresponding Chunks in the Realm of the Ancients world.getServer().getWorld(DBMDimensions.realm_of_the_ancients).forceChunk(event.getChunk().getPos().x, event.getChunk().getPos().z, true); } } } @SubscribeEvent public static void chunkUnload(final ChunkEvent.Unload event) { if (event.getWorld() != null) if (event.getWorld().chunkExists(event.getChunk().getPos().x, event.getChunk().getPos().z)) if (!event.getWorld().isRemote()) { ServerWorld world = (ServerWorld) event.getWorld(); if (world.dimension.getType() == DBMDimensions.realm_of_the_ancients) { // Force Unloads Corresponding Chunks in the Overworld world.getServer().getWorld(DimensionType.OVERWORLD).forceChunk(event.getChunk().getPos().x, event.getChunk().getPos().z, false); } else if (world.dimension.getType() == DimensionType.OVERWORLD && DBMDimensions.realm_of_the_ancients != null) { // Force Unloads Corresponding Chunks in the Realm of the Ancients world.getServer().getWorld(DBMDimensions.realm_of_the_ancients).forceChunk(event.getChunk().getPos().x, event.getChunk().getPos().z, false); } } } Still gets stuck at 0%. Edited May 2, 20205 yr by kaydogz fixed wrong thing at the bottom
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.