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.

[1.6.4][Semi-Solved]Open a block, chest, furnace, etc... from anywhere?

Featured Replies

Posted

I've been trying to get it so I can open a GUI from anywhere.  I attach my itemstack to a chest or furnace or whatever and then have it go through blockList and do the onBlockActivated action.  This should in theory open the GUI or do whatever is intended for the block to do but it doesn't.  The only blocks that work are ones that do not open GUIs.  So levers, switches, repeaters, etc...  How would I go about opening the GUI of a block from any distance away?

Some code from my Item:

@Override
public boolean onItemUse(ItemStack itemstack, EntityPlayer player, World world, int x, int y, int z, int par7, float par8, float par9, float par10)
    {
	if(itemstack.getTagCompound() == null)
	{
		itemstack.setTagCompound(new NBTTagCompound());
		return true;
	}
	else
	if(itemstack.getTagCompound().getBoolean("hasSet") == false)
	{
		itemstack.getTagCompound().setInteger("BlockX", x);
		itemstack.getTagCompound().setInteger("BlockY", y);
		itemstack.getTagCompound().setInteger("BlockZ", z);
		itemstack.getTagCompound().setBoolean("hasSet", true);
		itemstack.getTagCompound().setString("BlockName", Block.blocksList[world.getBlockId(x, y, z)].getLocalizedName());
		return true;
	}
	else
	{
		if(Block.blocksList[world.getBlockId(itemstack.getTagCompound().getInteger("BlockX"), itemstack.getTagCompound().getInteger("BlockY"), itemstack.getTagCompound().getInteger("BlockZ"))] != null)
		{
			if(world.getBlockTileEntity(itemstack.getTagCompound().getInteger("BlockX"), itemstack.getTagCompound().getInteger("BlockY"), itemstack.getTagCompound().getInteger("BlockZ")) != null && world.getBlockTileEntity(itemstack.getTagCompound().getInteger("BlockX"), itemstack.getTagCompound().getInteger("BlockY"), itemstack.getTagCompound().getInteger("BlockZ")) instanceof ISidedInventory)
			{
				((ISidedInventory)world.getBlockTileEntity(itemstack.getTagCompound().getInteger("BlockX"), itemstack.getTagCompound().getInteger("BlockY"), itemstack.getTagCompound().getInteger("BlockZ"))).openChest();
			}
			if(Block.blocksList[world.getBlockId(itemstack.getTagCompound().getInteger("BlockX"), itemstack.getTagCompound().getInteger("BlockY"), itemstack.getTagCompound().getInteger("BlockZ"))].onBlockActivated(world, itemstack.getTagCompound().getInteger("BlockX"), itemstack.getTagCompound().getInteger("BlockY"), itemstack.getTagCompound().getInteger("BlockZ"), player, par7, par8, par9, par10) == false)
			{
				itemstack.getTagCompound().setBoolean("hasSet", false);
				itemstack.getTagCompound().setInteger("BlockX", 0);
				itemstack.getTagCompound().setInteger("BlockY", 0);
				itemstack.getTagCompound().setInteger("BlockZ", 0);
				itemstack.getTagCompound().setString("BlockName", "");
				return false;
			}
		}
		else
			itemstack.getTagCompound().setBoolean("hasSet", false);
		return true;
	}
    }

public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer player)
    {
	if(itemstack.getTagCompound() != null)
	{
		if(Block.blocksList[world.getBlockId(itemstack.getTagCompound().getInteger("BlockX"), itemstack.getTagCompound().getInteger("BlockY"), itemstack.getTagCompound().getInteger("BlockZ"))] != null)
		{
			if(Block.blocksList[world.getBlockId(itemstack.getTagCompound().getInteger("BlockX"), itemstack.getTagCompound().getInteger("BlockY"), itemstack.getTagCompound().getInteger("BlockZ"))].onBlockActivated(world, itemstack.getTagCompound().getInteger("BlockX"), itemstack.getTagCompound().getInteger("BlockY"), itemstack.getTagCompound().getInteger("BlockZ"), player, 0, 0.0F, 0.0F, 0.0F) == false)
			{
				itemstack.getTagCompound().setBoolean("hasSet", false);
			}
		}
		else
			itemstack.getTagCompound().setBoolean("hasSet", false);
	}
        return itemstack;
    }

width=320 height=64http://www.slothygaming.com/img/ota.png[/img]

If your grammar is shit and you blatantly don't know what you're doing, I will not help you.

Vanilla blocks have a maximum distance for interaction, usually defined in the TileEntity#isUseableByPlayer(EntityPlayer), by a 64 distance squared.

You would have to either patch this with a coremod, or use a FakePlayer placed accordingly and pass the block information to the real player entity.

 

Also, it is recommended to cache the block information locally, instead of fetching the world data on every line of code.

  • Author

Alright, I'll cache the block information.  If on the TileEntity it detects this, then how come workbenches and anvils still won't let me use it?  They do not have TileEntities attached.

width=320 height=64http://www.slothygaming.com/img/ota.png[/img]

If your grammar is shit and you blatantly don't know what you're doing, I will not help you.

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.