Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.14.4] Opening GUI for item with inventory


TehStoneMan
 Share

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

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.

 

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.

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

8 minutes ago, TehStoneMan said:

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

Okay. So. Which part do you have a problem with? What have you tried?

 

8 minutes ago, TehStoneMan said:

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

The interface is stupidly simple. It has two methods, one produces the Container that should be opened, the other produces it's name. What do you not understand about this? What have you tried?

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

49 minutes ago, TehStoneMan said:

OK, I think I managed to figure out DefferedWorkQueue.

Yes, looks correct.

 

49 minutes ago, TehStoneMan said:

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

Anything that you do in the generic setup events (FMLCommonSetupEvent, FMLClientSetupEvent) is run on a separate background thread. If you call into Minecraft code (register things or whatever) you must do this via DeferredWorkQueue. This is not a recommendation, it is a requirement for correct operation as almost all of Minecraft's code is not thread-safe and must only be interacted with from the main thread. This doesn't apply to events that are specifically for registering a specific thing (e.g. RegistryEvent.Register or ColorHandlerEvent).

 

52 minutes ago, TehStoneMan said:

INamedContainerProvider // <-- Is this the right place?

You can do that, sure. It doesn't matter where or how you implement it, that is the point of an interface. All you need to do is provide a container and a name for it.

Link to comment
Share on other sites

3 minutes ago, TehStoneMan said:

That's a static like to the object holder, probably not what is supposed to be there, but not sure what I should be using for this item.

That parameter is the INamedContainerProvider instance that provides the container to open and it's name. It is not an item.
Once again: You can implement this interface however you like. You can use a standalone class, you can use an anonymous inner class, whatever you want.

The point of an interface is that you decide how you implement it.

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

 Share



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • This a problem with the Theabyss (The Abyss?) mod. Make sure you have the latest version then contact the author.
    • This is an issue with JEI make sure you have latest version for 1.16.5 then contact the author.
    • I checked my list of mod and immersive portal wasn't even installed.    
    • Look at your image. You are showing  /Applications/Minecraft/Contents/mods Your mods folder is Take a screenshot of the contents of second one. Although we can guess, you have been downloading your mods into the first folder when you should be putting them in the second one.  
    • I play the world yesterday and it was fine, upon loading it today it crashed ╥_╥. Pls help.  [main/ERROR]: Exception caught during firing event: null     Index: 6     Listeners:         0: HIGH         1: ASM: class me.shedaniel.architectury.event.forge.EventHandlerImplClient event(Lnet/minecraftforge/client/event/RecipesUpdatedEvent;)V         2: NORMAL         3: ASM: class owmii.lib.client.wiki.Wiki collect(Lnet/minecraftforge/client/event/RecipesUpdatedEvent;)V         4: ASM: class com.blamejared.crafttweaker.impl.events.CTStateEventHandler onRecipesUpdated(Lnet/minecraftforge/client/event/RecipesUpdatedEvent;)V         5: ASM: mekanism.client.ClientTickHandler@43d9842f recipesUpdated(Lnet/minecraftforge/client/event/RecipesUpdatedEvent;)V         6: net.minecraftforge.eventbus.EventBus$$Lambda$2959/736640638@6d07c39b java.util.ConcurrentModificationException     at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:901)     at java.util.ArrayList$Itr.next(ArrayList.java:851)     at mezz.jei.load.PluginCaller.callOnPlugins(PluginCaller.java:21)     at mezz.jei.load.PluginLoader.<init>(PluginLoader.java:109)     at mezz.jei.startup.JeiStarter.start(JeiStarter.java:69)     at mezz.jei.startup.ClientLifecycleHandler.startJEI(ClientLifecycleHandler.java:147)     at mezz.jei.startup.ClientLifecycleHandler.setupJEI(ClientLifecycleHandler.java:140)     at mezz.jei.startup.ClientLifecycleHandler.lambda$new$3(ClientLifecycleHandler.java:106)     at mezz.jei.startup.ClientLifecycleHandler$$Lambda$29176/1547335276.accept(Unknown Source)     at net.minecraftforge.eventbus.EventBus.doCastFilter(EventBus.java:247)     at net.minecraftforge.eventbus.EventBus.lambda$addListener$11(EventBus.java:239)     at net.minecraftforge.eventbus.EventBus$$Lambda$2959/736640638.invoke(Unknown Source)     at net.minecraftforge.eventbus.EventBus$$Lambda$3273/1859299978.invoke(Unknown Source)     at net.minecraftforge.eventbus.EventBus.post(EventBus.java:302)     at net.minecraftforge.eventbus.EventBus.post(EventBus.java:283)     at net.minecraftforge.client.ForgeHooksClient.onRecipesUpdated(ForgeHooksClient.java:772)     at net.minecraft.client.network.play.ClientPlayNetHandler.func_199525_a(ClientPlayNetHandler.java:1314)     at net.minecraft.network.play.server.SUpdateRecipesPacket.func_148833_a(SourceFile:27)     at net.minecraft.network.play.server.SUpdateRecipesPacket.func_148833_a(SourceFile:15)     at net.minecraft.network.PacketThreadUtil.func_225383_a(SourceFile:21)     at net.minecraft.network.PacketThreadUtil$$Lambda$34638/1869809823.run(Unknown Source)     at net.minecraft.util.concurrent.ThreadTaskExecutor.func_213166_h(SourceFile:144)     at net.minecraft.util.concurrent.RecursiveEventLoop.func_213166_h(SourceFile:23)     at net.minecraft.util.concurrent.ThreadTaskExecutor.func_213168_p(SourceFile:118)     at net.minecraft.util.concurrent.ThreadTaskExecutor.func_213160_bf(SourceFile:103)     at net.minecraft.client.Minecraft.func_195542_b(Minecraft.java:948)     at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:607)     at net.minecraft.client.main.Main.main(Main.java:184)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     at java.lang.reflect.Method.invoke(Method.java:497)     at net.minecraftforge.fml.loading.FMLClientLaunchProvider.lambda$launchService$0(FMLClientLaunchProvider.java:37)     at net.minecraftforge.fml.loading.FMLClientLaunchProvider$$Lambda$502/1391735333.call(Unknown Source)     at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37)     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:54)     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:72)     at cpw.mods.modlauncher.Launcher.run(Launcher.java:82)     at cpw.mods.modlauncher.Launcher.main(Launcher.java:66)  [main/FATAL]: Error executing task on Client java.util.ConcurrentModificationException: null     at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:901) ~[?:1.8.0_51]     at java.util.ArrayList$Itr.next(ArrayList.java:851) ~[?:1.8.0_51]     at mezz.jei.load.PluginCaller.callOnPlugins(PluginCaller.java:21) ~[?:7.7.1.152]     at mezz.jei.load.PluginLoader.<init>(PluginLoader.java:109) ~[?:7.7.1.152]     at mezz.jei.startup.JeiStarter.start(JeiStarter.java:69) ~[?:7.7.1.152]     at mezz.jei.startup.ClientLifecycleHandler.startJEI(ClientLifecycleHandler.java:147) ~[?:7.7.1.152]     at mezz.jei.startup.ClientLifecycleHandler.setupJEI(ClientLifecycleHandler.java:140) ~[?:7.7.1.152]     at mezz.jei.startup.ClientLifecycleHandler.lambda$new$3(ClientLifecycleHandler.java:106) ~[?:7.7.1.152]     at mezz.jei.startup.ClientLifecycleHandler$$Lambda$29176/1547335276.accept(Unknown Source) ~[?:?]     at net.minecraftforge.eventbus.EventBus.doCastFilter(EventBus.java:247) ~[eventbus-4.0.0.jar:?]     at net.minecraftforge.eventbus.EventBus.lambda$addListener$11(EventBus.java:239) ~[eventbus-4.0.0.jar:?]     at net.minecraftforge.eventbus.EventBus$$Lambda$2959/736640638.invoke(Unknown Source) ~[?:?]     at net.minecraftforge.eventbus.EventBus$$Lambda$3273/1859299978.invoke(Unknown Source) ~[?:?]     at net.minecraftforge.eventbus.EventBus.post(EventBus.java:302) ~[eventbus-4.0.0.jar:?]     at net.minecraftforge.eventbus.EventBus.post(EventBus.java:283) ~[eventbus-4.0.0.jar:?]     at net.minecraftforge.client.ForgeHooksClient.onRecipesUpdated(ForgeHooksClient.java:772) ~[?:?]     at net.minecraft.client.network.play.ClientPlayNetHandler.func_199525_a(ClientPlayNetHandler.java:1314) ~[?:?]     at net.minecraft.network.play.server.SUpdateRecipesPacket.func_148833_a(SourceFile:27) ~[?:?]     at net.minecraft.network.play.server.SUpdateRecipesPacket.func_148833_a(SourceFile:15) ~[?:?]     at net.minecraft.network.PacketThreadUtil.func_225383_a(SourceFile:21) ~[?:?]     at net.minecraft.network.PacketThreadUtil$$Lambda$34638/1869809823.run(Unknown Source) ~[?:?]     at net.minecraft.util.concurrent.ThreadTaskExecutor.func_213166_h(SourceFile:144) [?:?]     at net.minecraft.util.concurrent.RecursiveEventLoop.func_213166_h(SourceFile:23) [?:?]     at net.minecraft.util.concurrent.ThreadTaskExecutor.func_213168_p(SourceFile:118) [?:?]     at net.minecraft.util.concurrent.ThreadTaskExecutor.func_213160_bf(SourceFile:103) [?:?]     at net.minecraft.client.Minecraft.func_195542_b(Minecraft.java:948) [?:?]     at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:607) [?:?]     at net.minecraft.client.main.Main.main(Main.java:184) [?:?]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_51]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_51]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_51]     at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_51]     at net.minecraftforge.fml.loading.FMLClientLaunchProvider.lambda$launchService$0(FMLClientLaunchProvider.java:37) [forge-1.16.5-36.2.35.jar:36.2]     at net.minecraftforge.fml.loading.FMLClientLaunchProvider$$Lambda$502/1391735333.call(Unknown Source) [forge-1.16.5-36.2.35.jar:36.2]     at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-8.1.3.jar:?]     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:54) [modlauncher-8.1.3.jar:?]     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:72) [modlauncher-8.1.3.jar:?]     at cpw.mods.modlauncher.Launcher.run(Launcher.java:82) [modlauncher-8.1.3.jar:?]     at cpw.mods.modlauncher.Launcher.main(Launcher.java:66) [modlauncher-8.1.3.jar:?]
  • Topics

×
×
  • Create New...

Important Information

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