Jump to content

Recommended Posts

Posted

I am trying to add a custom slot to the player inventory.  I've managed to get the container and GUI working and getting the visual to show up in game.  However, I cannot seem to manage to keep the inventory persistent between sessions.  I've been playing with the code in multiple ways, but I cannot seem to find a working solution.  I might be overlooking something major and just not be noticing it.  Any help is appreciated.

 

Custom Player Inventory Capability:

  Reveal hidden contents

 

Capability Registry

  Reveal hidden contents

 

Custom Player Inventory

  Reveal hidden contents

 

Event Loading

  Reveal hidden contents

 

Container

  Reveal hidden contents
Posted
  On 7/12/2018 at 4:22 AM, ChampionAsh5357 said:

Any help is appreciated

Expand  

You need to attach the capability to the Entity, not to the inventory. Also, read this documentation.

 

It is also recommended when adding something to the players inventory gui/container you do it through tabs(the way creative tabs work, keeps intermod compatibility).

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 7/12/2018 at 4:54 AM, Animefan8888 said:

You need to attach the capability to the Entity, not to the inventory.

Expand  

Ah, that might help.  For some reason I thought that attaching it to the inventory meant that it was going to be attached to the player.  I've fixed that now.  However, now I seem to be getting a NullPointerException when the writeToNBT function is being called.

 

  On 7/12/2018 at 4:54 AM, Animefan8888 said:

Also, read this documentation.

Expand  

I did, and I know I need to sync the server to the client data.  However, I want to get rid of all the errors first so that it at least saves to server before I start implementing the client syncing.

 

  On 7/12/2018 at 4:54 AM, Animefan8888 said:

It is also recommended when adding something to the players inventory gui/container you do it through tabs(the way creative tabs work, keeps intermod compatibility).

Expand  

I was going to do that as soon as I finished getting it working properly.

Posted
  On 7/12/2018 at 12:57 PM, ChampionAsh5357 said:

Ah, that might help.  For some reason I thought that attaching it to the inventory meant that it was going to be attached to the player.  I've fixed that now.  However, now I seem to be getting a NullPointerException when the writeToNBT function is being called. 

Expand  

Post your updated code and your crash report

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

Updated writeToNBT and readToNBT in the InventoryPlayer extended class:

  Reveal hidden contents

 

Event Registering:

  Reveal hidden contents

 

Crash Report:

  Reveal hidden contents

 

The rest of the code remained exactly the same.  The mod crashes when the player saves its NBT data at any time.

Posted
  On 7/12/2018 at 1:19 PM, ChampionAsh5357 said:

nbtTagListIn.appendTag(nbtTagListIn);

Expand  

 

Inserting a list into itself seems like a good plan.

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
  On 7/12/2018 at 1:19 PM, ChampionAsh5357 said:

The rest of the code remained exactly the same.  The mod crashes when the player saves its NBT data at any time. 

Expand  

You did not read and understand the forge documentation.

  Quote

CapabilityManager.INSTANCE.register(capability interface class, storage, default implementation factory);

Expand  
 

Also, you are using the deprecated method of registering, use the factory version.

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 7/12/2018 at 2:29 PM, Animefan8888 said:

You did not read and understand the forge documentation.

Expand  

I did read the forge documentation.  Understanding it, maybe.  From my understanding, I do not see why I can't create the inventory with an implementation of ICapabilitySerializable (which is what I did originally) and then just attach the capability via that to the player.  As far as I know through NBT checking, the player inventory does save on the server side and I can see it.  The problem I actually have is with loading it to the client which is actually what I didn't do when I made this thread.  However, I do not really know what event or tick handler I should notify to sync the data already stored in the NBT to the client.  I tried a couple of ways using EntityJoinWorldEvent and PlayerEvent.StartTracking, but I could not manage to get them to work.  So that would actually be the actual issue I'm having as of this moment.  I will repost my inventory and network handler along with the event class.  If you have any recommendation on how I would do that, I would be interested to hear.

 

Custom Inventory

  Reveal hidden contents

 

Packet Handler

  Reveal hidden contents

 

Event Class

  Reveal hidden contents

 

Apologies for the late reply.

Posted (edited)
  On 7/18/2018 at 2:35 AM, ChampionAsh5357 said:

However, I do not really know what event or tick handler I should notify to sync the data already stored in the NBT to the client.

Expand  

When you open the inventory or the inventory is accessed the contents need to be synced, it is not necessarily an event handler you need to use. Note the container class should automatically sync its contents to the client from Container#detectAndSendChanges

  On 7/18/2018 at 2:35 AM, ChampionAsh5357 said:

I do not see why I can't create the inventory with an implementation of ICapabilitySerializable

Expand  

You very well could, but you shouldn't extend InventoryPlayer or any IInventory, instead just use an IItemHandler implementation.

  On 7/18/2018 at 2:35 AM, ChampionAsh5357 said:

PlayerEvent.StartTracking

Expand  

For future reference please read the javadoc above things before you use them.

  Quote

Fired when an Entity is started to be "tracked" by this player (the player receives updates about this entity, e.g. motion).

Expand  

 

Edited by Animefan8888

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 7/18/2018 at 12:11 PM, Animefan8888 said:

When you open the inventory or the inventory is accessed the contents need to be synced, it is not necessarily an event handler you need to use. Note the container class should automatically sync its contents to the client from Container#detectAndSendChanges

Expand  

Ok. I think I'm going to rewrite everything so that it takes out the IInventory use and just add it on as a tab instead of just putting it off.  That way it should get everything working properly and stick with the conventions. Do I need to create a class extended from ItemStackHandler then, or can I just call IItemHandler?  I think I only need to store the slot I'm adding if the player inventory does it manually.

 

  On 7/18/2018 at 12:11 PM, Animefan8888 said:

For future reference please read the javadoc above things before you use them.

Expand  

I was reading the documentation of the deprecated IEntityExtenedProperties to see if that could potentially work with what I had before.

Posted
  On 7/18/2018 at 9:36 PM, ChampionAsh5357 said:

Do I need to create a class extended from ItemStackHandler then, or can I just call IItemHandler?

Expand  

IItemHandler is an interface that ItemStackHandler implements. An instance of ItemStackHandler should work fine for this case.

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 7/18/2018 at 9:50 PM, Animefan8888 said:

IItemHandler is an interface that ItemStackHandler implements. An instance of ItemStackHandler should work fine for this case.

Expand  

So, just to make sure I understand everything correctly.  Use an instance of ItemStackHandler to attach to the player to hold the inventory information.  Then when creating the container and gui use that same instance to store the custom slots added to the player. Then to call that instance from the gui handler I would just use player.getCapability(<? extends ItemStackHandler>, null); for calling it?

Posted
  On 7/18/2018 at 10:06 PM, ChampionAsh5357 said:

So, just to make sure I understand everything correctly.  Use an instance of ItemStackHandler to attach to the player to hold the inventory information.  Then when creating the container and gui use that same instance to store the custom slots added to the player. Then to call that instance from the gui handler I would just use player.getCapability(<? extends ItemStackHandler>, null); for calling it?

Expand  

No, you cannot attach an CapabilityItemHandler.ITEM_HANDLER_CAPABILITY to the player as there is already one, but you can make your own capability that uses IItemHandler as its data(I believe. someone will correct me if I am wrong). And then attach this capability in AttachCapabilityEvent<Entity> to the player. Then reference it by EntityPlayer#getCapability

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 (edited)

I tried using getSlotTexture to create a back image for the slot similar to the offhand slot and it comes up with a null texture even though the texture is defined at the place I set it to.  Also, when I try to give the player an item, it only detects that once the extended inventory has been opened.

 

Extended Inventory Container

  Reveal hidden contents

 

Gui Extended Inventory

  Reveal hidden contents

 

Updated Player Inventory (I know I'm reusing the recipe book texture on the button but its only until I can manage to get it working)

  Reveal hidden contents

 

Extended Inventory Slot

  Reveal hidden contents

 

Edited by ChampionAsh5357
Everything was fixed.
Posted
  On 7/18/2018 at 10:10 PM, Animefan8888 said:

No, you cannot attach an CapabilityItemHandler.ITEM_HANDLER_CAPABILITY to the player as there is already one, but you can make your own capability that uses IItemHandler as its data(I believe. someone will correct me if I am wrong). And then attach this capability in AttachCapabilityEvent<Entity> to the player. Then reference it by EntityPlayer#getCapability

Expand  

Okay, I created everything so that it works properly.  The only problem I have left is that when I first load up the world, the data in the slot does not get loaded until I open up the tab with it.  Since I created a KeyBinding to change the item with what the player has in hand, the data from the slot has to be loaded by the time the entity joins the world.

Posted
  On 7/20/2018 at 4:09 AM, ChampionAsh5357 said:

The only problem I have left is that when I first load up the world, the data in the slot does not get loaded until I open up the tab with it. 

Expand  

Then it is pretty obvious what you have to do if this is an actual problem. Sync it when the player joins the world with a custom packet.

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 7/20/2018 at 4:24 AM, Animefan8888 said:

Then it is pretty obvious what you have to do if this is an actual problem. Sync it when the player joins the world with a custom packet.

Expand  

I realized that after posting it.  So I tried with the EntityJoinWorldEvent and I check if the entity joined is the player.  I got the server information and tried to sync it with the client.  However, it only works one time on login and then the packet throws a NullPointerException somehow when I add the scheduled task.  I also tried with PlayerEvent.PlayerLoggedInEvent with the same issue.

 

Packet

  Reveal hidden contents

 

Event

  Reveal hidden contents

 

Inventory Sync Method

  Reveal hidden contents

 

Posted
  On 7/22/2018 at 7:35 PM, ChampionAsh5357 said:

NullPointerException somehow when I add the scheduled task.

Expand  

Can I see the crash, kinda hard to debug without it.

 

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 7/22/2018 at 8:06 PM, Animefan8888 said:

Can I see the crash, kinda hard to debug without it.

Expand  

It's not a crash, the packet just throws an exception; the game still runs because the only thing it does it try and load the slot.  If it fails then it's just air until I load it via opening the custom inventory.

 

  Reveal hidden contents

 

The line it is referring to, since I didn't post the entire packet class, is the line where I set the ItemStack in the slot.

Posted
  On 7/23/2018 at 2:29 PM, ChampionAsh5357 said:

The line it is referring to, since I didn't post the entire packet class, is the line where I set the ItemStack in the slot.

Expand  

Use the debugger and find out what is null

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 7/23/2018 at 6:51 PM, Animefan8888 said:

Use the debugger and find out what is null

Expand  

The player was returning null because I called it in the beginning of the message.  The player might not have been loaded yet so it couldn't set it. I moved the EntityPlayerSP inside the addScheduledTask and now everything works.  Thank you for taking the time to help me do this.

Posted
  On 7/24/2018 at 4:22 AM, ChampionAsh5357 said:

The player was returning null because I called it in the beginning of the message.  The player might not have been loaded yet so it couldn't set it. I moved the EntityPlayerSP inside the addScheduledTask and now everything works.  Thank you for taking the time to help me do this.

Expand  

No problem, glad you got it working.

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.