Jump to content

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


Recommended Posts

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.

Posted

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.

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.