Jump to content

[1.14.4] Opening GUI for item with inventory


TehStoneMan

Recommended Posts

I am trying to make an item that has an inventory, but I need help with opening the GUI. I already have the inventory handler and right-click action in place, but just don't know how the send the right open GUI message.

Link to comment
Share on other sites

31 minutes ago, diesieben07 said:
9 hours ago, TehStoneMan said:

How do you use DeferredWorkQueue? I have not encountered that before.

It has javadocs. Did you read them? You give it a Runnable or Supplier and it will run it on the main game thread and provide you with a CompletableFuture for when it's done.

If I understood the javadocs, I wouldn't be asking for help.

 

32 minutes ago, diesieben07 said:
9 hours ago, TehStoneMan said:

I already know how to use openGui in blocks/tile entities, but don't how to use INamedContainerProvider in an item.

It's an interface. You implement it.

If I knew how to implement it with an item, I wouldn't be asking for help.

Link to comment
Share on other sites

OK, I think I managed to figure out DefferedWorkQueue. Minecraft even seemed to launch faster. Am I correct with this?

DeferredWorkQueue.runLater( () ->
{
	ScreenManager.registerFactory( BetterStorageContainerTypes.LOCKER, GuiBetterStorage::new );
	ScreenManager.registerFactory( BetterStorageContainerTypes.CRATE, GuiCrate::new );
	ScreenManager.registerFactory( BetterStorageContainerTypes.REINFORCED_CHEST, GuiReinforcedChest::new );
	ScreenManager.registerFactory( BetterStorageContainerTypes.REINFORCED_LOCKER, GuiReinforcedLocker::new );
	ScreenManager.registerFactory( BetterStorageContainerTypes.KEYRING, GuiKeyring::new );
} );

What other startup calls would this be recommended to use this with?

 

As for the item, this is my current guess based on how my tile entities are implemented:

public class ItemKeyring extends ItemBetterStorage implements IKey, INamedContainerProvider // <-- Is this the right place?
{
	public ItemKeyring()
	{
		super( "keyring", new Item.Properties().group( BetterStorage.ITEM_GROUP ) );
		addPropertyOverride( new ResourceLocation( "full" ), ( itemStack, world, entityPlayer ) ->
		{
			return 0.0F;
		} );
	}

	@Override
	public ActionResult< ItemStack > onItemRightClick( World world, PlayerEntity player, Hand hand )
	{
		final ItemStack stack = player.getHeldItem( hand );

		if( !player.isSneaking() )
			return new ActionResult( ActionResultType.PASS, stack );

		if( !world.isRemote)
		{
			NetworkHooks.openGui( (ServerPlayerEntity)player, BetterStorageItems.KEYRING ); // <-- Don't know what to put here
		}
		return new ActionResult( ActionResultType.SUCCESS, stack );
	}

	....

}

 

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.