Posted April 19, 20205 yr I'd like to add a custom player inventory I've written, nearly identical to the default inventory except that it also has a creative mode-like tab with secondary elements and custom item organization. I've implemented the inventory class similar to the default implementation of the creative one, but I don't know how to get it to show up in place of the default survival one. I've got an event handler and packet system for inputs already set up, what do I need to do next? Do I cancel the default inventory when the player first selects their inventory, or when they're created? Edited April 19, 20205 yr by Turtledove
April 19, 20205 yr Well, you could do something like this: @EventBusSubscriber(bus = Bus.FORGE) public class GuiHandler { @SubscribeEvent public static void onRenderGui(GuiScreenEvent.DrawScreenEvent.Pre event) { // Checks if the gui is an exact instance of InventoryScreen if(event.getGui().getClass() == InventoryScreen.class) { // Cancel the event event.setCanceled(true); // Draws "test" Minecraft.getInstance().fontRenderer.drawString("test", 200, 200, 3997696); // Render your own stuff } } } Edited April 19, 20205 yr by Budschie
April 19, 20205 yr Author 24 minutes ago, Budschie said: Well, you could do something like this: @EventBusSubscriber(bus = Bus.FORGE) public class GuiHandler { @SubscribeEvent public static void onRenderGui(GuiScreenEvent.DrawScreenEvent.Pre event) { // Checks if the gui is an exact instance of InventoryScreen if(event.getGui().getClass() == InventoryScreen.class) { // Cancel the event event.setCanceled(true); // Draws "test" Minecraft.getInstance().fontRenderer.drawString("test", 200, 200, 3997696); // Render your own stuff } } } and I don't need to send anything via the packets? I know buttons and such are client-side but assumed things like the inventory were on the server.
April 19, 20205 yr Author 4 minutes ago, diesieben07 said: Inventory synchronization happens through the Container class. You need a custom Container implementation and you need to open it server side (!) using NetworkHooks.openGui. Ah got it, so: 1) Create an inventory class that takes a Container object 2) Cancel the default inventory open event 3) Send a packet to server 4) Open it from that side Correct?
April 19, 20205 yr Author 4 hours ago, diesieben07 said: Eh, no, not really. You need some form of IItemHandler which stores the items. In your case probably attached to the player as a capability. Then you need a Container class which has slots that reference this handler. You also need a ContainerScreen, which shows the actual container. For this you need to register a ContainerType and you need to register a screen factory with ScreenManager. There's no such event. You'd have to use GuiOpenEvent. Yes. Why does the custom IItemHandler need to be attached to the player? Edited April 19, 20205 yr by Turtledove
April 20, 20205 yr Because it's an inventory that belongs to the player. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
April 20, 20205 yr Author 3 minutes ago, Draco18s said: Because it's an inventory that belongs to the player. I guess my confusion is just because I can't seem to figure out how to attach capabilities for a class data type like my custom IItem Handler. I'm trying to call .createKey() and can't figure out how to serialize the data type.
April 20, 20205 yr Author Still can't figure this out, at this point to keep it simple I'm trying to just implement the default inventory via this custom ItemHandler, but still can't attach it.
April 20, 20205 yr IItemHandler is a capability. You attach it to the player. CapabilityItemHandler.ITEM_HANDLER_CAPABILITY Edited April 20, 20205 yr by Draco18s Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
April 20, 20205 yr Author 10 minutes ago, Draco18s said: IItemHandler is a capability. You attach it to the player. CapabilityItemHandler.ITEM_HANDLER_CAPABILITY Again, thanks for the insight as always! Reading through the docs again it makes a ton of sense now. ?
April 20, 20205 yr 4 hours ago, diesieben07 said: That won't work, because the player already exposes that capability. You need your own capability, realized through a custom interface (which should extend IItemHandler). Point. But I think the concept that was not being understood was communicated. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
April 20, 20205 yr Author 8 hours ago, diesieben07 said: That won't work, because the player already exposes that capability. You need your own capability, realized through a custom interface (which should extend IItemHandler). Alright, so I've went ahead and done: 1) Created an interface that extends IItemHandler, and another that implements this interface 3 hours ago, Draco18s said: Point. But I think the concept that was not being understood was communicated. 2) In my GuiDataProvider class went ahead and called: @CapabilityInject(IMyItemHandler.class) static Capability<IMyItemHandler> ITEM_HANDLER_CAPABILITY = null; and implemented the various capability methods. And like you said previously, the only thing left to do is create the various container classes, and to register them. My original confusion was because I was under the impression that something like a Mana capability class wasn't the capability itself, but rather its various parameters, which was a silly thing to think. So I thought I had to add the IMyItemHandler as a capability as a parameter in a similar fashion. Anyhow, now the problem seems to be that I can't call these, return super.hasCapability(capability, facing); return super.getCapability(capability, facing); it complains that it "Cannot resolve method 'getCapability' in 'Object'" Edited April 20, 20205 yr by Turtledove
April 20, 20205 yr Author 2 minutes ago, diesieben07 said: Correct, I assume you just made a class that implements ICapabilityProvider (or ICapabilitySerializable, which extends that) to attach to the player, right? If so, yes of course you can't call super, because there is no super implementation for those methods. There is nothing wrong with that though, I am not sure why you are trying to call super in the first place. Ah alright, everything's crystal clear now, thank you. Just a case of blindly trying to do what the doc is saying without really checking on why its doing it.
April 21, 20205 yr Author 23 hours ago, diesieben07 said: Correct, I assume you just made a class that implements ICapabilityProvider (or ICapabilitySerializable, which extends that) to attach to the player, right? If so, yes of course you can't call super, because there is no super implementation for those methods. There is nothing wrong with that though, I am not sure why you are trying to call super in the first place. Got everything set up and registered, and the packets all work. My only question now is what do I do server-side after I've sent a packet?
April 21, 20205 yr Author 3 hours ago, diesieben07 said: Call NetworkHooks.openGui to open a GUI. Alright it finally works. It's duplicating items for some reason so I may have to tweak my itemhandler but that should be it.
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.