Reflxction Posted August 24, 2018 Share Posted August 24, 2018 (edited) Hello. In the process of making a mod I have come across some weird behavior of the game. Anytime I attempt to call Minecraft.getMinecraft().player#getUUID() in singleplayer the game crashes with a NPE. The same thing happened with #getPersistentID(). Is there any reliable way to check if an entity is the player without causing crashes or something. I'm afraid comparing names may not 100% work, and since retrieving the UUID crashed the game, is there any better way to do so? Edited August 24, 2018 by Reflxction Quote Link to comment Share on other sites More sharing options...
Animefan8888 Posted August 24, 2018 Share Posted August 24, 2018 1 hour ago, Reflxction said: Hello. In the process of making a mod I have come across some weird behavior of the game. Anytime I attempt to call Minecraft.getMinecraft().player#getUUID() in singleplayer the game crashes with a NPE. The same thing happened with #getPersistentID(). Is there any reliable way to check if an entity is the player without causing crashes or something. I'm afraid comparing names may not 100% work, and since retrieving the UUID crashed the game, is there any better way to do so? Two things Minecraft is a client only class. And either Minecraft.getMinecraft is returning null and which means you are calling this too soon or Minecraft#player is null and which would also mean you are calling this too soon. Quote VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator. Link to comment Share on other sites More sharing options...
Reflxction Posted August 24, 2018 Author Share Posted August 24, 2018 1 hour ago, Animefan8888 said: Two things Minecraft is a client only class. And either Minecraft.getMinecraft is returning null and which means you are calling this too soon or Minecraft#player is null and which would also mean you are calling this too soon. I was calling it in EntityJoinWorldEvent, where I assume the player wouldn't be null. Anyway, I did a few more googling and found out that what I was looking for is Minecraft.getSession().getProfile()#getId(), as this is what worked for me Quote Link to comment Share on other sites More sharing options...
Animefan8888 Posted August 24, 2018 Share Posted August 24, 2018 6 minutes ago, Reflxction said: I was calling it in EntityJoinWorldEvent, where I assume the player wouldn't be null. Anyway, I did a few more googling and found out that what I was looking for is Minecraft.getSession().getProfile()#getId(), as this is what worked for me Did you test it on the dedicated server? Quote VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator. Link to comment Share on other sites More sharing options...
Recommended Posts
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.