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.

Featured Replies

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;
}

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.

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.

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.

  • Author

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.

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.

  • Author

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

  • Author

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

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.