I'm attempting some modding once again, and have run into a problem. I want to add a custom entity gui that opens when you shift-click a mob, but I have no idea how to even begin doing this o.o I've never worked with GUIs before. I did find this tutorial, which helps some:
However, it is for Tile Entities, and the method used to retrieve the tile entity being accessed relies on the tile entity's position (in the GUI handler section-- about 2:50 in). Mobs don't quite run on the same logic, and so my major problem here is me not knowing how to access the entity I need. Otherwise I heavily suspect the rest of this will be applicable.
I'll post code if you guys need that, but does anyone know a "quick fix" in the form of a method I could use to identify a specific entity whose inventory I'm trying to access?
I can't tell you right now, but I'm sure there's an event/function for entity interaction. You can take a look at all existing events here. You can also take a look at how the villager gui is opened. As I said, I can't tell you the exact functions right now, but I probably will later if you won't be able to find anything.
Okay, so the GUI functions now! But I do have one question, regarding the method set out in the container tutorial:
Is there a way to restrict what items are "allowed" to go in each slot? I have 3 "restricted" slots-- one for a collar, one for armor, and one for an amulet, and I don't want just any old item being able to go in there...
Well, that solved my restricted armor slot problem, but a new one has emerged. Whenever I call initGui() in my Gui class (even if there's no code within it), it moves the Gui out of the center and to the top corner of the screen. Although I can re-center it manually, it also messes up the positions of the inventory slots, which are much harder to reset since they need to scale to the screen (and don't have access to the GUI variables that help the GUI do so as far as I know). As far as I can tell, I need initGui() to place a text box on the screen. Is there a way to re-center the gui and container and keep initGui()?
Well, I'm stumped again! I managed to implement a tab system for my GUI, but now I need to tell it to only show the inventory slots on the first tab. The others shouldn't have the inventory slots. The texture and stuff is switching just fine-- I think I'm really close to having this nailed down, but I'm still a little ways out XD
Ah, well I couldn't find that isEnabled method, but moving the Y coordinate works beautifully! Yet again, you've saved the day! Thanks!
Although, on that note, I'm having a bit of trouble with a render layer not showing up on reload. It might be because the slots aren't initializing properly (it's supposed to check if my wolf is wearing a collar. Upon reloading, the collar layer does not render, but it updates properly when I access the gui).
It seems the problem is due to the itemSlot not initializing properly on reload-- when printed, it shows as alternating between air and the collar item, when it should be solid collar item. Once the GUI is opened, everything goes back to normal and the wolf's collar begins to display. Weird!
Edit: I still have not found a solution though... rip
Are you synchronising your capability with the client? The collar rendering relies on the capability being present, but by default capabilitiy data isn't sent to the client so you'll need to handle that yourself using packets.
That's the thing-- the rendering itself isn't the problem. My collar render class grabs the item from the itemstack from the wolf's entity class, and the collar actually renders fine. It's the data in the entity class that's changing. I wrote a println to grab the item from the slot and print it out in the onLivingUpdate method. The first time I spawned one of my wolves and changed its collar, it basically printed:
But when I closed the world and reloaded it, it started printing:
Until I opened the GUI again, which seemed to reset it. Somehow the itemstack doesn't seem to be fully initializing in the slot. And that's why the collar disappears-- because the code in the render class is looking for my collar item, not air.
I bet that when you put a check for world.isRemote at the same point as your current println, you'll find that when it's collaritem isRemote will return false, and when it's air isRemote will be true. This is because the item in the itemstack in your item handler capability only exists on the server.
Ohhh man, that's it! That explains a lot tbh...
So, how exactly do I go about saving that info to the server? I'm afraid I haven't really dealt with packets before...
I can only advise you based on what I can see from your code. The entity code you've posted doesn't contain a data parameter for collar id, and your layer renderer code is referencing your item handler capability.
You should check your readEntityFromNBT / writeEntityToNBT methods if your data isn't saving, and check that you've set up your data parameter correctly using the others that are already there as an example of how to do it. We're well past getting your GUI working now though, so you should probably create a new thread explaining the other problems you're having with your entity and post fresh code.
Alright, I'll play around with it a little more, but if I still can't get it working I'll make a new thread. And I realized my dataparameter is in the class this one extends, not actually this one, oops. I'll post all of that if I can't get it working... thanks!