Jump to content

[SOLVED] [1.12] Server Crash when removing dimension (NullPointerException)


Rurido

Recommended Posts

I try to remove dimensions (custom, not -1/0/1). After it was successfully removed, the server crashes. I think I forgot one thing but I can't figure out what.
 

This is the remove-code:

/*some imports*/
import net.minecraftforge.common.DimensionManager;
import /*my package*/.util.LogHelper;

public class Dimensions {

/*some stuff*/

public static boolean removeDimension(int id) { if(!DimensionManager.isDimensionRegistered(id)) return false;
    try { LogHelper.info("Unloading dimension " + id);
        DimensionManager.unloadWorld(id);
    }catch (Exception ex){ LogHelper.warn(ex.getMessage());
    } try { LogHelper.info("Unregistering dimension " + id);
        DimensionManager.unregisterDimension(id);
    }catch (Exception ex){ LogHelper.error(ex.getMessage());
        return false;
    } LogHelper.info("Removing dimension " + id + " from data storage");
    if( !DimensionDataStorage.removeDimension(id) ){ //<---DimensionDataStorage extends WorldSavedData LogHelper.warn("Could not delete data from DimensionDataStorage. This occurs if no data was found.");
        return false;
    } LogHelper.info("Dimension " + id + " successfully removed");
    return true;
}

 

Crash Log after calling removeDimension(id[=3]):

Spoiler

...nothing special above...
[22:47:43] [Server thread/INFO] [RR55's Server+]: Unloading dimension 3
[22:47:43] [Server thread/INFO] [RR55's Server+]: Unregistering dimension 3
[22:47:43] [Server thread/INFO] [RR55's Server+]: Removing dimension 3 from data storage
[22:47:43] [Server thread/INFO] [RR55's Server+]: Dimension 3 successfully removed
[22:47:43] [Server thread/ERROR]: Encountered an unexpected exception
java.lang.NullPointerException: null
	at net.minecraftforge.common.DimensionManager$Dimension.access$200(DimensionManager.java:60) ~[DimensionManager$Dimension.class:?]
	at net.minecraftforge.common.DimensionManager.unloadWorlds(DimensionManager.java:332) ~[DimensionManager.class:?]
	at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:857) ~[MinecraftServer.class:?]
	at net.minecraft.server.dedicated.DedicatedServer.updateTimeLightAndEntities(DedicatedServer.java:409) ~[DedicatedServer.class:?]
	at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:740) ~[MinecraftServer.class:?]
	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:589) [MinecraftServer.class:?]
	at java.lang.Thread.run(Thread.java:745) [?:1.8.0_121]
[22:47:43] [Server thread/ERROR]: This crash report has been saved to: [I don't think you need this ^^]
[22:47:43] [Server thread/INFO]: Stopping server
[22:47:43] [Server thread/INFO]: Saving players
[22:47:43] [Server thread/INFO]: Saving worlds
[22:47:43] [Server thread/INFO]: Saving chunks for level 'world'/overworld
[22:47:43] [Server thread/INFO]: Saving chunks for level 'world'/the_nether
[22:47:44] [Server thread/INFO]: Saving chunks for level 'world'/the_end
[22:47:44] [Server thread/INFO]: Saving chunks for level 'NewWorld'/custom
[22:47:45] [Server thread/INFO] [FML]: Unloading dimension 0
[22:47:45] [Server thread/INFO] [FML]: Unloading dimension -1
[22:47:45] [Server thread/INFO] [FML]: Unloading dimension 1
[22:47:45] [Server thread/INFO] [FML]: Unloading dimension 3
[22:47:45] [Server thread/INFO] [FML]: Applying holder lookups
[22:47:45] [Server thread/INFO] [FML]: Holder lookups applied
[22:47:45] [Server thread/INFO] [FML]: The state engine was in incorrect state SERVER_STOPPING and forced into state SERVER_STOPPED. Errors may have been discarded.

 

It looks like the dimension still exists after removing it; but when I restart the server it is gone exept that if I create a new dimension it's id is the id of the removed dimension +1, that's why the id is 3 and not 2 . Also the DIM[ID] folder is not beeing deleted.

 

Any Idea what I forgot to add [or rather remove ^^]?

Edited by Rurido

If my answer helped you out, you may give that answer a like. ^-^
Funny but true JavaScript statements: 

null != 0  null !<0  null !> 0    null <= 0  null >= 0  Number(null) == 0

Link to comment
Share on other sites

Adding them works just fine, no errors, nothing.

 

My approach:

Spoiler

public class Dimensions {
	public static DimensionType dimensionType;

	public static void init() {
		dimensionType = DimensionType.register("custom", "_custom", 5, CustomWorldProvider.class, false);
		for (Integer id : DimensionDataStorage.instance().getDimensions()) {
			LogHelper.info("Loading Dimension " + id);
			if (!DimensionManager.isDimensionRegistered(id)) {
				DimensionManager.registerDimension(id, dimensionType);
			}
		}
	}
	
	public static void createDimension(String name, long randomSeed, boolean mapFeaturesEnabled, WorldType terrainType, String generatorOptions){
		int id = DimensionManager.getNextFreeDimId();
		CustomWorldInfo info = new CustomWorldInfo(DimensionManager.getWorld(0).getWorldInfo(), name, randomSeed, mapFeaturesEnabled, terrainType, generatorOptions);
		DimensionDataStorage.instance().setDimensionData(id, info.cloneNBTCompound(null));
		DimensionManager.registerDimension(id, dimensionType);
		DimensionManager.initDimension(id);
		WorldServer world = DimensionManager.getWorld(id);
		world.initialize(new WorldSettings(info));
	}

	public static boolean removeDimension(int id) {
		/*see above*/
	}
}

@Mod(modid = Main.MODID, version = Main.VERSION)
public class Main {
	/*some stuff*/	
	@EventHandler
	private void serverStarting(FMLServerStartingEvent event) {
		CommandManager.instance().initCommands(event);
		DimensionDataStorage.init(event.getServer().worlds[0]);
		Dimensions.init();

		/*some other stuff*/
	}
}

public class CommandWorld extends CommandBase{
	/*some stuff*/
	@Override
	public void execute(...) throws CommandException {
		/*some argument stuff*/
		Dimensions.createDimension(args[1], seed, mapFeaturesEnabled, WorldType.DEFAULT, generatorSettings);
	}
}

 

 

So i thought removing them would be also that easy.

Well if it CAN NOT be done, the server crash is "not a bug" but "a feature"...

If my answer helped you out, you may give that answer a like. ^-^
Funny but true JavaScript statements: 

null != 0  null !<0  null !> 0    null <= 0  null >= 0  Number(null) == 0

Link to comment
Share on other sites

If you call this a terrible hack, okay...
And there is not "another terrible hack" to remove them?

If my answer helped you out, you may give that answer a like. ^-^
Funny but true JavaScript statements: 

null != 0  null !<0  null !> 0    null <= 0  null >= 0  Number(null) == 0

Link to comment
Share on other sites

20 minutes ago, diesieben07 said:
28 minutes ago, Rurido said:

If you call this a terrible hack, okay...

Please clarify what you mean by "this". I am talking about EnumHelper. And you?

You said:

1 hour ago, diesieben07 said:

Since dimensions are an enum now (DimensionType) you cannot reasonably remove them. Even adding them requires a giant, terrible hack.

 

Well, i never use the EnumHelper directly. It is used by DimensionType.register(...) but I don't want to remove (or add) DimensionTypes - I only do this once for all my custom dimensions which use all the same type:

My code:

public static DimensionType dimensionType; //<--- I could make it final, because it is only initialized once at FMLServerStartingEvent
/*...*/
dimensionType = DimensionType.register("custom", "_custom", 5, CustomWorldProvider.class, false);

Minecraft's source: net.minecraft.world.DimensionType:

public static DimensionType register(String name, String suffix, int id, Class<? extends WorldProvider> provider, boolean keepLoaded){
	String enum_name = name.replace(" ", "_").toLowerCase();
	DimensionType ret = net.minecraftforge.common.util.EnumHelper.addEnum(DimensionType.class, enum_name, ENUM_ARGS, id, name, suffix, provider);
	return ret.setLoadSpawn(keepLoaded);
}

 

So as I said, i don't want to remove the entire type, I just want to remove some dimensions (all of my custom type tho).

 

I really think we talk past each other :/

Edited by Rurido

If my answer helped you out, you may give that answer a like. ^-^
Funny but true JavaScript statements: 

null != 0  null !<0  null !> 0    null <= 0  null >= 0  Number(null) == 0

Link to comment
Share on other sites

I don't know if my way creating dimensions is right, but I do use one DimensionType for multiple dimensions  and all of them work fine:
Screenshot: https://rurido.de/temp/mc_dim_list.png (Post was too long)

[19:39:12] [Server thread/INFO] [RR55's Server+]: WorldInfo set on dimension 2
[19:39:12] [Server thread/INFO] [FML]: Loading dimension 2 (Test1) (net.minecraft.server.dedicated.DedicatedServer@2f011051)
[19:39:15] [Server thread/INFO] [RR55's Server+]: WorldInfo set on dimension 3
[19:39:15] [Server thread/INFO] [FML]: Loading dimension 3 (Test2) (net.minecraft.server.dedicated.DedicatedServer@2f011051)
[19:39:18] [Server thread/INFO] [RR55's Server+]: WorldInfo set on dimension 4
[19:39:18] [Server thread/INFO] [FML]: Loading dimension 4 (Test3) (net.minecraft.server.dedicated.DedicatedServer@2f011051)
[19:39:20] [Server thread/INFO] [RR55's Server+]: WorldInfo set on dimension 5
[19:39:20] [Server thread/INFO] [FML]: Loading dimension 5 (Test4) (net.minecraft.server.dedicated.DedicatedServer@2f011051)

 

So I would say that a DimensionType can be used for ore than one Dimension, because as I understand it, DimensionTypes don't say "what dimension are you?" but "what kind of dimension are you?". But I can also be wrong ;)

 

If my answer helped you out, you may give that answer a like. ^-^
Funny but true JavaScript statements: 

null != 0  null !<0  null !> 0    null <= 0  null >= 0  Number(null) == 0

Link to comment
Share on other sites

17 minutes ago, diesieben07 said:

But I might be wrong here, and type IDs and dimension IDs are separate.

If the comment above the function is right, then you are wrong, idk...

I give a DimensionType (which can also be identified by its id), and get a list of dimension ids...

package net.minecraftforge.common;

public class DimensionManager{
  	/*...*/
  
	/**
	 * Returns a list of dimensions associated with this DimensionType.
	 */
	public static int[] getDimensions(DimensionType type){
		int[] ret = new int[dimensions.size()];
		int x = 0;
		for (Map.Entry<Integer, Dimension> ent : dimensions.entrySet()){
			if (ent.getValue().type == type){
				ret[x++] = ent.getKey();
			}
		}

		return Arrays.copyOf(ret, x);
	}
  	/*...*/
}

 

 

Edited by Rurido

If my answer helped you out, you may give that answer a like. ^-^
Funny but true JavaScript statements: 

null != 0  null !<0  null !> 0    null <= 0  null >= 0  Number(null) == 0

Link to comment
Share on other sites

I never wanted to remove a DimensionType. I want to remove a Dimension (by its id)!

21 hours ago, Rurido said:

So as I said, i don't want to remove the entire type, I just want to remove some dimensions (all of my custom type tho).

 

23 hours ago, Rurido said:

I try to remove dimensions (custom, not -1/0/1).

 

If my answer helped you out, you may give that answer a like. ^-^
Funny but true JavaScript statements: 

null != 0  null !<0  null !> 0    null <= 0  null >= 0  Number(null) == 0

Link to comment
Share on other sites

Do I have to use the event (I found WorldEvent.Unload) or can i force te dimension to unload immediately?

If my answer helped you out, you may give that answer a like. ^-^
Funny but true JavaScript statements: 

null != 0  null !<0  null !> 0    null <= 0  null >= 0  Number(null) == 0

Link to comment
Share on other sites

I see...

if(w == null || !ForgeChunkManager.getPersistentChunksFor(w).isEmpty() || !w.playerEntities.isEmpty() || dimension.type.shouldLoadSpawn()){
	FMLLog.log.debug("Aborting unload for dimension {} as status changed", id);
	continue;	
}

Well, i can teleport all players out of this dimension so that this list would be empty.

I also found ForgeChunkManager.unloadWorld(World world) which removes its  persistent chunks (forcedChunks.remove(world);) so that

public static ImmutableSetMultimap<ChunkPos, Ticket> getPersistentChunksFor(World world){
	return forcedChunks.containsKey(world) ? forcedChunks.get(world) : ImmutableSetMultimap.<ChunkPos,Ticket>of();
}

would  return an empty set.

The spawn is not marked as "keep loaded" by my DimensionType.

 

At last i would steal some code from DimensionManager.unloadWorlds(...); to get

WorldServer w = worlds.get(id);
MinecraftForge.EVENT_BUS.post(new WorldEvent.Unload(w));
w.flush();
setWorld(id, null, w.getMinecraftServer());

which should unload it immediately  if i got things right.


But isn't there a more elegant way or do I have to to all steps by myself?

 

If my answer helped you out, you may give that answer a like. ^-^
Funny but true JavaScript statements: 

null != 0  null !<0  null !> 0    null <= 0  null >= 0  Number(null) == 0

Link to comment
Share on other sites

Is there a way to check if a dimension is already unloaded? (if the dimension should be deleted before it was loaded e.g. when no player joined the world yet)

 

EDIT:

nvm, I found a way:
 

for(Integer i : DimensionManager.getIDs()){
	if(id == i){ //Dimension is loaded.
		return false;  //queued
	}
}
//Dimension is not loaded
//continue

 

Edited by Rurido

If my answer helped you out, you may give that answer a like. ^-^
Funny but true JavaScript statements: 

null != 0  null !<0  null !> 0    null <= 0  null >= 0  Number(null) == 0

Link to comment
Share on other sites

Thx.

Quote

can't see the wood for the trees....

Edited by Rurido

If my answer helped you out, you may give that answer a like. ^-^
Funny but true JavaScript statements: 

null != 0  null !<0  null !> 0    null <= 0  null >= 0  Number(null) == 0

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.