Jump to content

onItemRightClick behaving weird [ISSUE UPDATED]


zedlander1000

Recommended Posts

ISSUE FIXED

So i am making an Item in tribute to the Terrarian Magic Mirror that teleports you to either your spawn point or your bed depending if you have slept in the bed else if your bed is missing/obstructed, or just for reasons you cannot spawn at your bed, just spawn at the world's spawn location.

 

I got it working for a while but it would only spawn me to the spawn chunks but now since i have added if(!world.isRemote), it doesnt want to teleport at all.

 

NEW ISSUE

Hello :) i got my old issue fixed but to bring up a new issue now. The inverse is happening now to where if i havnt slept in a bed at all, the item flat out doesnt work but if i sleep in a bed then destroy it, it shall teleport me to spawn like it should.

 

Basically: if i start a new world, use the item, i get an error and it doesnt teleport me to my original spawn. If i sleep, it will teleport me to my bed. If i destroy the bed, It teleports me to spawn.

issue to fix is the item not working if you have not used a bed at all.

 

I updated the code down below for eyes to view.

 

UPDATED CODE:

 

 

@Override
public ItemStack onItemRightClick(ItemStack item, World world, EntityPlayer user)
{	
	if(!world.isRemote)
	{
		System.out.println("\n\n\nWorld: " + world + "\nWorldtoString: " + world.toString() + "\nforce spawnr: " + user.forceSpawn + "\nPlayer: " + user.toString() + "\nBedSpawnLocation: " + user.getBedSpawnLocation(world, user.getBedLocation(0), false) + "\nBed Location: " + user.getBedLocation(0) + "\nSpawn Location: " + world.getSpawnPoint() + "\nSpawn top point: " + world.getTopSolidOrLiquidBlock(world.getSpawnPoint()).getY() + "\n\n\n");

		if(user.getBedSpawnLocation(world, user.getBedLocation(0), false) == null)
		{
			((EntityPlayerMP) user).playerNetServerHandler.setPlayerLocation(world.getSpawnPoint().getX(), 
																			 world.getTopSolidOrLiquidBlock(world.getSpawnPoint()).getY(), 
																			 world.getSpawnPoint().getZ(), 
																			 user.getRotationYawHead(), 
																			 user.getDefaultEyeHeight());
		}
		else
		{
			((EntityPlayerMP) user).playerNetServerHandler.setPlayerLocation(user.getBedSpawnLocation(world, user.getBedLocation(0), false).getX(), 
																			 user.getBedSpawnLocation(world, user.getBedLocation(0), false).getY(), 
																			 user.getBedSpawnLocation(world, user.getBedLocation(0), false).getZ(), 
																			 user.getRotationYawHead(), 
																			 user.getDefaultEyeHeight());
		}
	}

	return item;
}
}

 

 

ERROR:

I get this with the new stated issue above.

 

 

[14:37:26] [server thread/FATAL] [FML]: Exception caught executing FutureTask: java.util.concurrent.ExecutionException: java.lang.NullPointerException
java.util.concurrent.ExecutionException: java.lang.NullPointerException
at java.util.concurrent.FutureTask.report(Unknown Source) ~[?:1.8.0_45]
at java.util.concurrent.FutureTask.get(Unknown Source) ~[?:1.8.0_45]
at net.minecraftforge.fml.common.FMLCommonHandler.callFuture(FMLCommonHandler.java:715) [FMLCommonHandler.class:?]
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:727) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:669) [MinecraftServer.class:?]
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:171) [integratedServer.class:?]
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:540) [MinecraftServer.class:?]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_45]
Caused by: java.lang.NullPointerException
at net.minecraft.world.World.isValid(World.java:260) ~[World.class:?]
at net.minecraft.world.World.getBlockState(World.java:896) ~[World.class:?]
at net.minecraft.entity.player.EntityPlayer.getBedSpawnLocation(EntityPlayer.java:1715) ~[EntityPlayer.class:?]
at zed.ztools.items.MagicMirror.onItemRightClick(MagicMirror.java:40) ~[MagicMirror.class:?]
at net.minecraft.item.ItemStack.useItemRightClick(ItemStack.java:168) ~[itemStack.class:?]
at net.minecraft.server.management.ItemInWorldManager.tryUseItem(ItemInWorldManager.java:378) ~[itemInWorldManager.class:?]
at net.minecraft.network.NetHandlerPlayServer.processPlayerBlockPlacement(NetHandlerPlayServer.java:607) ~[NetHandlerPlayServer.class:?]
at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:67) ~[C08PacketPlayerBlockPlacement.class:?]
at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:114) ~[C08PacketPlayerBlockPlacement.class:?]
at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:24) ~[PacketThreadUtil$1.class:?]
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.8.0_45]
at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0_45]
at net.minecraftforge.fml.common.FMLCommonHandler.callFuture(FMLCommonHandler.java:714) ~[FMLCommonHandler.class:?]
... 5 more

 

 

My System.out statement doesn't seem to output so i am quite worried where the code is actually messing up.

Possible solution would be to use a try catch statement for null pointers in my if statement checking for bed spawn point for null.

 

will that work?

 

Any other suggestions?

 

OLD OUTPUT

with an output of:

World: net.minecraft.world.WorldServer@74fababf

WorldtoString: net.minecraft.world.WorldServer@74fababf

EntityPlayer: EntityPlayerMP['Player61'/164, l='New World', x=-133.69, y=66.00, z=-52.32]

Player: EntityPlayerMP['Player61'/164, l='New World', x=-133.69, y=66.00, z=-52.32]

Bed Location: null

Spawn Location: BlockPos{x=-124, y=64, z=-45}

Spawn top point: 64

Link to comment
Share on other sites

Which version?

Because this works for me in 1.8

teleporter.playerNetServerHandler.setPlayerLocation
			(player.posX, player.posY, player.posZ, player.rotationYaw, player.rotationPitch);

 

Where teleporter is the player to get teleported, and player is the player that he gets teleported to

Link to comment
Share on other sites

yes? well i am coding in 1.8 forge-1.8-11.14.3.1446

should i use

teleporter.playerNetServerHandler.setPlayerLocation
			(player.posX, player.posY, player.posZ, player.rotationYaw, player.rotationPitch);

 

like... what is the difference from what i am doing to teleport the user?

?

 

EDIT:

 

bvyVOio.png

i get this :( and i checked it's declaration but it doesnt seem to be declared anywhere.

Link to comment
Share on other sites

so like this:

0vuJ6KB.png

i found the declaration for this but why can it still not be resolved? so far this is what i believe you have done right? or i could be entirely misinterpreting you.

 

removing the NetHandlerPlayServer makes setPlayerLocation an error saying it needs a different cast

 

EDIT:

((EntityPlayerMP) user).playerNetServerHandler.setPlayerLocation(world.getSpawnPoint().getX(), 
				world.getTopSolidOrLiquidBlock(world.getSpawnPoint()).getY(), 
				world.getSpawnPoint().getZ(), 
				user.getRotationYawHead(), 
				user.getDefaultEyeHeight());

seems to have no errors. ima try this out and see if it works

Link to comment
Share on other sites

not really. since you are triing to teleport the player calling methods from the player, and I am using methods from the NetHandlerPlayServer, holded by the player (I forgot to mention that I casted the player to EntityPlayerMP)

 

Welp :) i got that situation sorted. thanks that worked. only problem now is that i need to update my if statement to check if the bed is missing soo.... i should be able to do that my self but i will report to this post if i have any more trouble.

Link to comment
Share on other sites

  • 2 weeks later...

ISSUE UPDATED

 

NEW ISSUE

Hello :) i got my old issue fixed but to bring up a new issue now. The inverse is happening now to where if i havnt slept in a bed at all, the item flat out doesnt work but if i sleep in a bed then destroy it, it shall teleport me to spawn like it should.

 

Basically: if i start a new world, use the item, i get an error and it doesnt teleport me to my original spawn. If i sleep, it will teleport me to my bed. If i destroy the bed, It teleports me to spawn.

issue to fix is the item not working if you have not used a bed at all.

 

I updated the code down below for eyes to view.

 

UPDATED CODE:

 

 

@Override
public ItemStack onItemRightClick(ItemStack item, World world, EntityPlayer user)
{	
	if(!world.isRemote)
	{
		System.out.println("\n\n\nWorld: " + world + "\nWorldtoString: " + world.toString() + "\nforce spawnr: " + user.forceSpawn + "\nPlayer: " + user.toString() + "\nBedSpawnLocation: " + user.getBedSpawnLocation(world, user.getBedLocation(0), false) + "\nBed Location: " + user.getBedLocation(0) + "\nSpawn Location: " + world.getSpawnPoint() + "\nSpawn top point: " + world.getTopSolidOrLiquidBlock(world.getSpawnPoint()).getY() + "\n\n\n");

		if(user.getBedSpawnLocation(world, user.getBedLocation(0), false) == null)
		{
			((EntityPlayerMP) user).playerNetServerHandler.setPlayerLocation(world.getSpawnPoint().getX(), 
																			 world.getTopSolidOrLiquidBlock(world.getSpawnPoint()).getY(), 
																			 world.getSpawnPoint().getZ(), 
																			 user.getRotationYawHead(), 
																			 user.getDefaultEyeHeight());
		}
		else
		{
			((EntityPlayerMP) user).playerNetServerHandler.setPlayerLocation(user.getBedSpawnLocation(world, user.getBedLocation(0), false).getX(), 
																			 user.getBedSpawnLocation(world, user.getBedLocation(0), false).getY(), 
																			 user.getBedSpawnLocation(world, user.getBedLocation(0), false).getZ(), 
																			 user.getRotationYawHead(), 
																			 user.getDefaultEyeHeight());
		}
	}

	return item;
}
}

 

 

ERROR:

I get this with the new stated issue above.

 

 

[14:37:26] [server thread/FATAL] [FML]: Exception caught executing FutureTask: java.util.concurrent.ExecutionException: java.lang.NullPointerException
java.util.concurrent.ExecutionException: java.lang.NullPointerException
at java.util.concurrent.FutureTask.report(Unknown Source) ~[?:1.8.0_45]
at java.util.concurrent.FutureTask.get(Unknown Source) ~[?:1.8.0_45]
at net.minecraftforge.fml.common.FMLCommonHandler.callFuture(FMLCommonHandler.java:715) [FMLCommonHandler.class:?]
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:727) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:669) [MinecraftServer.class:?]
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:171) [integratedServer.class:?]
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:540) [MinecraftServer.class:?]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_45]
Caused by: java.lang.NullPointerException
at net.minecraft.world.World.isValid(World.java:260) ~[World.class:?]
at net.minecraft.world.World.getBlockState(World.java:896) ~[World.class:?]
at net.minecraft.entity.player.EntityPlayer.getBedSpawnLocation(EntityPlayer.java:1715) ~[EntityPlayer.class:?]
at zed.ztools.items.MagicMirror.onItemRightClick(MagicMirror.java:40) ~[MagicMirror.class:?]
at net.minecraft.item.ItemStack.useItemRightClick(ItemStack.java:168) ~[itemStack.class:?]
at net.minecraft.server.management.ItemInWorldManager.tryUseItem(ItemInWorldManager.java:378) ~[itemInWorldManager.class:?]
at net.minecraft.network.NetHandlerPlayServer.processPlayerBlockPlacement(NetHandlerPlayServer.java:607) ~[NetHandlerPlayServer.class:?]
at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:67) ~[C08PacketPlayerBlockPlacement.class:?]
at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:114) ~[C08PacketPlayerBlockPlacement.class:?]
at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:24) ~[PacketThreadUtil$1.class:?]
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.8.0_45]
at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0_45]
at net.minecraftforge.fml.common.FMLCommonHandler.callFuture(FMLCommonHandler.java:714) ~[FMLCommonHandler.class:?]
... 5 more

 

 

My System.out statement doesn't seem to output so i am quite worried where the code is actually messing up.

Possible solution would be to use a try catch statement for null pointers in my if statement checking for bed spawn point for null.

 

will that work?

 

Any other suggestions?

 

 

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.