Jump to content

[SOLVED] [1.10.2] Custom player inventory doesn't display GUI


Recommended Posts

Posted

I'm creating a custom player inventory. I'm attempting to give the player a 3x3 crafting grid by default, instead of 2x2. However, the vanilla GUI is appearing on the screen instead of mine. It  still shows the highlight slots from my GUI, and I can even put items where the slots should be.

 

I have a few other problems, like the crafting grid not producing a crafting result—do I need a custom crafting manager? Also, the creative player inventory is screwy (armor slots appearing in hot bar).

 

Common Proxy where I register my OpenGuiEvent and my GUI Handler:

 

  Reveal hidden contents

 

 

My GUI Handler:

 

  Reveal hidden contents

 

 

My GUI class:

 

  Reveal hidden contents

 

 

Event for opening GUI and attaching player inventory (no, I'm not using Capabilities for this yet - advice on how to achieve that would be welcome):

 

  Reveal hidden contents

 

 

My player container:

 

  Reveal hidden contents

 

 

My player inventory:

 

  Reveal hidden contents

 

Posted

You are extending the Gui class for the players inventory and then in the draw method you call the super.

 

As for Capability advice you need to create a new Capability (of course) and then you need to add it to the player using AttachCapabilityEvent, all of this you know. In your Capability you will store an IItemHandler instance for storing your ItemStacks.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted

		Gui gui = event.getGui();
	if (gui != null && gui.getClass() == net.minecraft.client.gui.inventory.GuiInventory.class && !(gui instanceof PrimalGuiInventory))
	{
		gui = new PrimalGuiInventory(Minecraft.getMinecraft().player);
	}

 

Congrats, you made a local variable equal your gui. The function returns, the local variable is popped off the stack, and no longer exists.  The event object is unchanged, the vanilla gui is displayed.

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.

Posted

Sigh. Learning to program via Minecraft modding sometimes makes me question my sanity. I have fixed both the problems you pointed out. I now see my GUI. Here's the new code:

 

 

  Reveal hidden contents

 

However, I'm still seeing the slot highlights from the original 2x2 crafting grid--they partially overlap my custom crafting grid slots. Where are they coming from?

 

There's weird crap going on in the creative inventory, too. It seems that maybe the slot IDs are all messed up, with the little armor icons appearing in hot bar slots, and items appearing in two slots at once depending on where they are placed, etc. Possibly because it's using my custom player inventory slot IDs? How do I fix that?

Posted
  On 1/17/2017 at 7:14 AM, Daeruin said:

Sigh. Learning to program via Minecraft modding sometimes makes me question my sanity. I have fixed both the problems you pointed out. I now see my GUI. Here's the new code:

 

 

  Reveal hidden contents

 

However, I'm still seeing the slot highlights from the original 2x2 crafting grid--they partially overlap my custom crafting grid slots. Where are they coming from?

 

There's weird crap going on in the creative inventory, too. It seems that maybe the slot IDs are all messed up, with the little armor icons appearing in hot bar slots, and items appearing in two slots at once depending on where they are placed, etc. Possibly because it's using my custom player inventory slot IDs? How do I fix that?

Are you ever overriding the Container? If not just call player.openGui

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted
  On 1/17/2017 at 7:24 AM, Animefan8888 said:

Are you ever overriding the Container? If not just call player.openGui

Which question are you attempting to answer? Could you be more explicit? Overriding what Container?

 

I am extending the ContainerPlayer class and overriding some of the methods, if that's what you mean. And I'm replacing the regular player.inventoryContainer with my player container during the EntityJoinWorldEvent. But you could have seen that from the code I posted earlier, so maybe you meant something else?

Posted
  On 1/17/2017 at 7:39 AM, Daeruin said:

  Quote

Are you ever overriding the Container? If not just call player.openGui

Which question are you attempting to answer? Could you be more explicit? Overriding what Container?

 

I am extending the ContainerPlayer class and overriding some of the methods, if that's what you mean. And I'm replacing the regular player.inventoryContainer with my player container during the EntityJoinWorldEvent. But you could have seen that from the code I posted earlier, so maybe you meant something else?

Oops, didn't catch that. The problem is that you call super in your Containers constructor so it adds all the slots that vanilla adds. Which is impossible to prevent. So you have to options.

[*]Override the slots by manually setting them in the inventorySlots field using List#set(int, Slot)

[*]Or switch to extending Container and adding the abilities/functions of the Players default container.

Note that overriding the Gui and Container may lead to incompatibility if done wrong.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted

Oh, I feel like such a dummy. I went with option 2. I realized I needed to override two of the methods anyway. Man, transferStackInSlot is nasty.

 

I'm still having the problem with the creative survival inventory tab. I think by adding five new slots to the player container, I have pushed all the slot indexes for that screen down by five. Vanilla does some weird crap in the GuiContainerInventory class to compensate for the missing crafting grid slots, and by adding five slots to the player container, I seem to have thrown that off. Any advice on how to deal with that?

Posted

The creative inventory problem has been there since my very first post, so nothing I've done recently has caused it.

 

Does this screen shot work? https://screencast.com/t/ItbjCtAFi

 

See how the icons for the armor slots have all been pushed down into the regular inventory? I think because the creative inventory lacks a crafting grid, GuiContainerCreative#setCurrentCreativeTab manually adjusts for the missing slots by iterating through the player's inventoryContainer and moving the slots around based on their ID. For example, it sets slot ID 45 (the shield slot) to xPos=35 and yPos=20. Well, since I've added five slots to the player container, slot ID 45 is no longer the shield slot.

 

setCurrentCreativeTab is private, so I can't override it by extending GuiContainerCreative. I suppose I could rearrange what indexes I assign my new player inventory slots to, in order to leave all the vanilla slots in their original index positions. That would be a pain in the butt and make my transferStackInSlot method even more complicated than it already is. Maybe I could use OpenGuiEvent to intercept the creative inventory and replace it with a custom one, but that intimidates me because the creative inventory GUI is such a huge class.

Posted

Alright, I did that and it seems to be working. It wasn't as annoying as I thought it would be, in large part because I had defined my indices with a set of constants with human-readable names. Here's what the finished player container looks like, for anyone who's interested.

 

 

  Reveal hidden contents

 

 

I have one final problem, which is that the items in the player's inventory disappear every time I log out. I need to convert the player container over to Capabilities still, and I'm hoping that will solve the problem.

Posted

I haven't finished converting to Capabilities yet, but in the meantime I have noticed that the player model that displays in the inventory screen doesn't move around as I move the mouse. It's always looking at the top left corner of the screen. Any idea why? I copied that code directly from vanilla's GuiInventory class.

Posted
  On 1/20/2017 at 1:44 AM, Daeruin said:

I haven't finished converting to Capabilities yet, but in the meantime I have noticed that the player model that displays in the inventory screen doesn't move around as I move the mouse. It's always looking at the top left corner of the screen. Any idea why? I copied that code directly from vanilla's GuiInventory class.

Post the code you think does that.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted

I lied, I didn't copy that code. I'm already extending GuiInventory, so I'm just letting that class do the work by calling GuiInventory#drawEntityOnScreen.

 

Here's my container GUI:

 

  Reveal hidden contents

 

 

And here's GuiInventory#drawEntityOnScreen, which is supposed to animate the player model on the inventory screen:

 

  Reveal hidden contents

 

 

For some reason, it isn't doing its job, or I've done something wrong, so the player model is always stuck staring at the top left of the screen and does't follow the mouse's movement.

 

Also, I realized I don't need to use Capabilities just yet. I originally thought I needed to make changes to the player's inventory itself, but in the end I only needed to modify the player container, since the slots I'm adding are all in the crafting grid, and they aren't part of the player's permanent inventory. I can let the vanilla player inventory do all the work of saving and loading the items in the inventory. I have other ideas for adding more slots to the inventory, however, and may be asking for help later. I got a ways into adding the Capability and kept getting confused.

Posted

You're talking about mouseX and mouseY, right? I don't see a problem. I'm not doing anything different from vanilla. drawEntityOnScreen is called from drawGuiContainerBackgroundLayer, which passes in a float parameter based on oldMouseX and oldMouseY and some other values. oldMouseX and oldMouseY get their values from the superclass drawScreen method from the mouseX and mouseY parameters.... all that is pure vanilla.

Posted
  On 1/21/2017 at 1:44 AM, Daeruin said:

You're talking about mouseX and mouseY, right? I don't see a problem. I'm not doing anything different from vanilla. drawEntityOnScreen is called from drawGuiContainerBackgroundLayer, which passes in a float parameter based on oldMouseX and oldMouseY and some other values. oldMouseX and oldMouseY get their values from the superclass drawScreen method from the mouseX and mouseY parameters.... all that is pure vanilla.

You never actually set oldMouseX or oldMouseY to anything after declaring them.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted

I guess I still don't have a full understanding of how subclassing works, but let me see if I understand now. I'm extending GuiInventory, which has two private variables (oldMouseX and oldMouseY) and a method (drawScreen) for setting those variables. I have extended that class, but I had to declare my own versions of the variables, because they were private in the superclass. So now I need my own method to set the variables, too. I'm still unclear if the real reason is because the variables are private, or because the superclass method uses the

[b]this[/b]

notation when setting the variables.

 

But yeah, once I copied drawScreen into my subclass and override it, everything works. Thanks for being patient with all my questions. I really appreciate all your help! I'm really pleased with how this feature of my mod has turned out.  :D

Posted

Right, but I had my own variables in my subclass. Why couldn't the superclass method set their values? Changing my subclass's variables to public didn't make a difference.

Posted
  On 1/21/2017 at 3:18 AM, Daeruin said:

Right, but I had my own variables in my subclass. Why couldn't the superclass method set their values? Changing my subclass's variables to public didn't make a difference.

Because they are accessing their variables not yours.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

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.