Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

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

Featured Replies

Posted

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

  • Author
private void onFoodEaten(int meta, ItemStack stack, World worldIn, EntityPlayer player) {
	if (!worldIn.isRemote) {
		player.changeDimension(-1);
	}
}

 

  • Author
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).

  • Author
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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.