Jump to content

Teleportation To anther age crashes game


Frost Dragon Empire

Recommended Posts

 public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
    {
		if (!playerIn.capabilities.isCreativeMode)
        {
			playerIn.dropItem(false);
        }
		playerIn.getCooldownTracker().setCooldown(this, 20);
		
		ItemStack itemstack = playerIn.getHeldItem(handIn);
		NBTTagCompound nbt = itemstack.getTagCompound();
		
		int x = nbt.getInteger("x");
		int y = nbt.getInteger("y");
		int z = nbt.getInteger("z");
		int dim = nbt.getInteger("dim");
		
		if(dim != playerIn.dimension)
		{
			playerIn.getServer().getPlayerList().changePlayerDimension((EntityPlayerMP)playerIn, dim);
;		}
		playerIn.setLocationAndAngles(x, y, z, playerIn.rotationYaw, playerIn.rotationPitch);
        return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn));
    }
	
	@Override
	public void onCreated(ItemStack stack, World worldIn, EntityPlayer playerIn)
    {
		NBTTagCompound nbt = new NBTTagCompound();
		nbt.setInteger("x", (int)playerIn.posX);
		nbt.setInteger("y", (int)playerIn.posY);
		nbt.setInteger("z", (int)playerIn.posZ);
		nbt.setInteger("dim", playerIn.dimension);
		stack.setTagCompound(nbt);
    }

When I right click the item in anther dimension the game crashes, and when I reload I have teleported. So what is causing the crash? Crash log says something about null pointer. What I am I doing wrong here? Do I need to create my own teleporter and use the other method and if so how? I have been reading the code on the teleporter and it doesn't seem to do much.

Link to comment
Share on other sites

Null pointers are easy to resolve...

 

If you know where they are.

 

You did not post the crash error itself, therefore I cannot help you.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

---- Minecraft Crash Report ----
// Surprise! Haha. Well, this is awkward.

Time: 12/2/17 10:41 PM
Description: Unexpected error

java.lang.NullPointerException: Unexpected error
	at items.ItemLinkingBook.onItemRightClick(ItemLinkingBook.java:50)
	at net.minecraft.item.ItemStack.useItemRightClick(ItemStack.java:234)
	at net.minecraft.client.multiplayer.PlayerControllerMP.processRightClick(PlayerControllerMP.java:543)
	at net.minecraft.client.Minecraft.rightClickMouse(Minecraft.java:1710)
	at net.minecraft.client.Minecraft.processKeyBinds(Minecraft.java:2379)
	at net.minecraft.client.Minecraft.runTickKeyboard(Minecraft.java:2145)
	at net.minecraft.client.Minecraft.runTick(Minecraft.java:1933)
	at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1186)
	at net.minecraft.client.Minecraft.run(Minecraft.java:441)
	at net.minecraft.client.main.Main.main(Main.java:118)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
	at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
	at GradleStart.main(GradleStart.java:26)


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Thread: Client thread
Stacktrace:
	at items.ItemLinkingBook.onItemRightClick(ItemLinkingBook.java:50)
	at net.minecraft.item.ItemStack.useItemRightClick(ItemStack.java:234)
	at net.minecraft.client.multiplayer.PlayerControllerMP.processRightClick(PlayerControllerMP.java:543)
	at net.minecraft.client.Minecraft.rightClickMouse(Minecraft.java:1710)
	at net.minecraft.client.Minecraft.processKeyBinds(Minecraft.java:2379)
	at net.minecraft.client.Minecraft.runTickKeyboard(Minecraft.java:2145)

-- Affected level --
Details:
	Level name: MpServer
	All players: 1 total; [EntityPlayerSP['Player65'/290, l='MpServer', x=-52.76, y=69.00, z=271.44]]
	Chunk stats: MultiplayerChunkCache: 547, 547
	Level seed: 0
	Level generator: ID 00 - default, ver 1. Features enabled: false
	Level generator options: 
	Level spawn location: World: (-64,64,256), Chunk: (at 0,4,0 in -4,16; contains blocks -64,0,256 to -49,255,271), Region: (-1,0; contains chunks -32,0 to -1,31, blocks -512,0,0 to -1,255,511)
	Level time: 9478 game time, 4576 day time
	Level dimension: 0
	Level storage version: 0x00000 - Unknown?
	Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false)
	Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: false
	Forced entities: 113 total;
    
    ...
    
    Retry entities: 0 total; []
	Server brand: fml,forge
	Server type: Integrated singleplayer server
Stacktrace:
	at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:461)
	at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2897)
	at net.minecraft.client.Minecraft.run(Minecraft.java:470)
	at net.minecraft.client.main.Main.main(Main.java:118)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
	at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
	at GradleStart.main(GradleStart.java:26)

Here is my last crash log. I looked through all my crash logs and every time I crashed it was reported as dimension: 0, but the entity list was different. Overworld entities going from the overworld, and nether entities going to the overworld.

Edited by Frost Dragon Empire
Link to comment
Share on other sites

6 hours ago, diesieben07 said:

Do not rely on onCreated. onCreated is misleading, it should be called onCrafted. It will not be called for stacks taken from e.g. the creative menu. Therefor your NBT might not exist (i.e. it's null).

While true, it is surprisingly not the problem.

playerIn.getServer()

Returns null on the client. Unsurprisingly.

ItemLinkingBook

Are you working on a Myst mod? Because that exists and is probably way better than anything you could accomplish.

Edited by Draco18s

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

11 minutes ago, diesieben07 said:

Or that. We can't know, because we don't know what line 50 is.

(I actually copied his code into my IDE to test it last night, so yes, actually I do know that it's that, but don't tell him--also, it matches the behavior of "the game crashes and when I log back in I've been teleported," but you're right, we can't actually tell from what he's posted what line 50 is.)

Edited by Draco18s

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

3 hours ago, Draco18s said:

While true, it is surprisingly not the problem.


playerIn.getServer()

Returns null on the client. Unsurprisingly.


ItemLinkingBook

Are you working on a Myst mod? Because that exists and is probably way better than anything you could accomplish.

There was, yes. I have not seen an update quite awhile, but even if there is I am doing something different.

Link to comment
Share on other sites

14 minutes ago, Frost Dragon Empire said:

How are other mods doing this type of teleportation?

Why don't you look at their source code? Why are you asking us to look up something that you can find out yourself? Just find a mod that has similar teleportation and see if they have public source, like on github or otherwise published.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

1 hour ago, Frost Dragon Empire said:

There was, yes. I have not seen an update quite awhile, but even if there is I am doing something different.

True, it hasn't been. XCompWiz has been busy with his actual job.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

1 hour ago, jabelar said:

Why don't you look at their source code? Why are you asking us to look up something that you can find out yourself? Just find a mod that has similar teleportation and see if they have public source, like on github or otherwise published.

I wasn't asking other people to look anything up. I am asking what other people know. I'll happily go look at other's code, it's the best way to learn.

Edited by Frost Dragon Empire
Link to comment
Share on other sites

The thing is that coding is very precise so when people are answering the questions here they usually do research to confirm what they are saying. Even if I have written a mod before that does exactly what you're asking, I would make sure I'm referring to the proper method name and such, so it means loading up the code and checking it, or whatever.

 

For example if you look at Draco's answer above, he actually took the time to copy your code into his IDE and try to explore it and maybe run it. So basically answering questions takes work and usually isn't from the top of the head.

 

It is much preferable to say "I looked up these couple mods in GitHub and this what they're doing but when I try it I still have this issue." Then we know you've put in the homework and we'll happily work to get you through the tough part.

 

(It's kinda like when your kids ask you where something is when they haven't even looked for it...)

Edited by jabelar

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Mostly solved, changed if(dim != playerIn.dimension) to if(dim != playerIn.dimension && !worldIn.isRemote), and it no longer crashes. It doesn't seem to be teleporting me to the right location, but when I right click a second time it does. So maybe I need a delay or something on the coord change? Not really important at the moment, I'll solve that down the road after I add the ui, because it will probably work totally different then.

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.