Jump to content

[SOLVED][1.7.10] Can't Teleport to Overworld


Recommended Posts

Posted

I have an item that will let you travel to the last location you set on it. I can use the item to travel within any dimension, and from any dimension to any other except the overworld. When I travel from the end or nether to the overworld the world doesn't load, my Y position slowly decreases and then fluctuates up and down by a couple points where the ground should be but I cant move or use the item again. When I log out and back in again everything is like it worked fine.

 

Any ideas on what I'm missing?

 

@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
{
	NBTTagCompound nbtTagCompound = stack.getTagCompound();
	if (nbtTagCompound == null) 
	{
		nbtTagCompound = new NBTTagCompound();
		stack.setTagCompound(nbtTagCompound);
	}

	if (player.isSneaking())
	{
		if (!world.isRemote)
		{
			NameHeldStackGUI nameGui = new NameHeldStackGUI();
			Minecraft.getMinecraft().displayGuiScreen(nameGui);
		}			
		nbtTagCompound.setBoolean("bound", true);
		nbtTagCompound.setInteger("dimension", player.dimension);
		nbtTagCompound.setDouble("x", player.posX);
		nbtTagCompound.setDouble("y", player.posY);
		nbtTagCompound.setDouble("z", player.posZ);
	}
	else if ((!world.isRemote) && (nbtTagCompound.hasKey("bound")) && (nbtTagCompound.getBoolean("bound")))
	{
		double x = nbtTagCompound.getDouble("x");
		double y = nbtTagCompound.getDouble("y");
		double z = nbtTagCompound.getDouble("z");
		int dimension = nbtTagCompound.getInteger("dimension");

		[b]if (player.dimension != dimension)player.travelToDimension(dimension);[/b]	
		player.setPositionAndUpdate(x, y, z);

		world.playSoundEffect(x, y, z, "mob.endermen.portal", 1.0F, 1.0F);
		if (player.isBurning()) player.extinguish();
		player.heal(1.0f);
		stack.damageItem(1, player);
	}
	return stack;
}

Posted

You're checking for client-side at

else if ((!world.isRemote) && (nbtTagCompound.hasKey("bound")) && (nbtTagCompound.getBoolean("bound")))

, but changing dimension is server-side. Remove the !world.isRemote. That should fix it  :)

If you read this, I'm hot.

Posted

You're checking for client-side at

else if ((!world.isRemote) && (nbtTagCompound.hasKey("bound")) && (nbtTagCompound.getBoolean("bound")))

, but changing dimension is server-side. Remove the !world.isRemote. That should fix it  :)

 

World#isRemote

is

false

on the server and

true

on the client.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

You're checking for client-side at

else if ((!world.isRemote) && (nbtTagCompound.hasKey("bound")) && (nbtTagCompound.getBoolean("bound")))

, but changing dimension is server-side. Remove the !world.isRemote. That should fix it  :)

 

World#isRemote

is

false

on the server and

true

on the client.

Oh lol. Said it backwards :). But getting rid of !world.isRemote, should fix it.

If you read this, I'm hot.

Posted

You're checking for client-side at

else if ((!world.isRemote) && (nbtTagCompound.hasKey("bound")) && (nbtTagCompound.getBoolean("bound")))

, but changing dimension is server-side. Remove the !world.isRemote. That should fix it  :)

 

World#isRemote

is

false

on the server and

true

on the client.

Oh lol. Said it backwards :). But getting rid of !world.isRemote, should fix it.

 

If only it was that easy:( I removed "(!world.isRemote) && " and there was no change.

Posted

You've got some weird stuff going on:

if (!world.isRemote) { // this means you are on the server side
NameHeldStackGUI nameGui = new NameHeldStackGUI(); // GUI classes are typically CLIENT-side only
Minecraft.getMinecraft().displayGuiScreen(nameGui); // Minecraft is DEFINITELY client-side only
}	

Furthermore, if you are relying on that GUI to do something, such as set data in the ItemStack's NBT, well that won't work without sending packets. NBT data should only be set on the server side.

 

Just FYI, most of the NBTTagCompound methods return the equivalent of false if the tag does not exist, so:

if (nbtTagCompound.getBoolean("bound"))

will only return true if the tag has the boolean key "bound" and that key is true, meaning you often don't need to check  `if (tag.hasKey("bound"))` - it is implicit in the getter.

Posted

To reiterate

Everything works except teleporting from the nether or end to overworld.

Meaning I can set and retrieve the NBT data.

Maybe I did the GUI wrong, it works in game though, all it does is use packets to give the item stack a display name.

 

It actually does teleport me to the overworld but no blocks or chunks load, Steve just floats there falling slowly then jumping back up

Posted

I've got it working

I followed everyone's suggestions and there was no noticeable change.

I added a "if (dimension == 0) player.travelToDimension(dimension);" to double travel to dimension 0/overworld

My code works and I don't know why...

@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
{
	NBTTagCompound nbtTagCompound = stack.getTagCompound();
	if (nbtTagCompound == null) 
	{
		nbtTagCompound = new NBTTagCompound();
		stack.setTagCompound(nbtTagCompound);
	}

	if (player.isSneaking())
	{
		if (world.isRemote)
		{
			NameHeldStackGUI nameGui = new NameHeldStackGUI();
			Minecraft.getMinecraft().displayGuiScreen(nameGui);
		}			
		nbtTagCompound.setBoolean("bound", true);
		nbtTagCompound.setInteger("dimension", player.dimension);
		nbtTagCompound.setDouble("x", player.posX);
		nbtTagCompound.setDouble("y", player.posY);
		nbtTagCompound.setDouble("z", player.posZ);
	}
	else if (nbtTagCompound.getBoolean("bound"))
	{
		double x = nbtTagCompound.getDouble("x");
		double y = nbtTagCompound.getDouble("y");
		double z = nbtTagCompound.getDouble("z");
		int dimension = nbtTagCompound.getInteger("dimension");

		if (player.dimension != dimension)player.travelToDimension(dimension);
		if (dimension == 0) player.travelToDimension(dimension);
		player.setPositionAndUpdate(x, y, z);

		world.playSoundEffect(x, y, z, "mob.endermen.portal", 1.0F, 1.0F);
		if (player.isBurning()) player.extinguish();
		player.heal(1.0f);
		stack.damageItem(1, player);
	}
	return stack;
}

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.

×
×
  • Create New...

Important Information

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