Jump to content

[SOLVED] [1.12.2] player.changeDimension(-1) NullPointerException


Recommended Posts

Posted (edited)

In my mod, I made an item which can teleport you into the nether.

But when I use it, I get a NullPointerException with following stack trace:

java.lang.NullPointerException: Ticking player
	at net.minecraft.world.Teleporter.placeInExistingPortal(Teleporter.java:136)
	at net.minecraft.world.Teleporter.placeInPortal(Teleporter.java:36)
	at net.minecraft.server.management.PlayerList.transferEntityToWorld(PlayerList.java:748)
	at net.minecraft.server.management.PlayerList.transferPlayerToDimension(PlayerList.java:655)
	at net.minecraft.server.management.PlayerList.changePlayerDimension(PlayerList.java:642)
	at net.minecraft.entity.player.EntityPlayerMP.changeDimension(EntityPlayerMP.java:745)
	at com.deerangle.item.ItemChocolateBar.onFoodEaten(ItemChocolateBar.java:197)
	at com.deerangle.item.ItemChocolateBar.onItemUseFinish(ItemChocolateBar.java:117)
	at net.minecraft.item.ItemStack.onItemUseFinish(ItemStack.java:242)
	at net.minecraft.entity.EntityLivingBase.onItemUseFinish(EntityLivingBase.java:3062)
	at net.minecraft.entity.player.EntityPlayerMP.onItemUseFinish(EntityPlayerMP.java:1227)
	at net.minecraft.entity.EntityLivingBase.updateActiveHand(EntityLivingBase.java:2956)
	at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:2311)
	at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:272)
	at net.minecraft.entity.player.EntityPlayerMP.onUpdateEntity(EntityPlayerMP.java:423)
	at net.minecraft.network.NetHandlerPlayServer.update(NetHandlerPlayServer.java:185)
	at net.minecraftforge.fml.common.network.handshake.NetworkDispatcher$1.update(NetworkDispatcher.java:212)
	at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:307)
	at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:196)
	at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:863)
	at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:741)
	at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:192)
	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:590)
	at java.lang.Thread.run(Unknown Source)

 

 

Solution:

instead of 

player.changeDimension(-1);

use 

player.setPortal(player.getPosition());
player.changeDimension(-1);

 

Edited by deerangle
solved
Posted
double d6 = (double)(blockpattern$patternhelper.getFrontTopLeft().getY() + 1) - entityIn.getLastPortalVec().y * (double)blockpattern$patternhelper.getHeight();

this is the line of code in the Teleporter class, that crashes the game.

since the blockpattern$patternhelper object is created 3 lines above, it must be either entityIn or entityIn.getLastPortalVec().

I assume it is actually entityIn.getLastPortalVec(). The variable returned by this function is only set in the Entity#setPortal(BlockPos pos).

Posted
1 minute ago, deerangle said:

double d6 = (double)(blockpattern$patternhelper.getFrontTopLeft().getY() + 1) - entityIn.getLastPortalVec().y * (double)blockpattern$patternhelper.getHeight();

this is the line of code in the Teleporter class, that crashes the game.

since the blockpattern$patternhelper object is created 3 lines above, it must be either entityIn or entityIn.getLastPortalVec().

I assume it is actually entityIn.getLastPortalVec(). The variable returned by this function is only set in the Entity#setPortal(BlockPos pos).

I managed to solve my problem with exactly this. Thank you for the tips, @diesieben07

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.