Jump to content

Advice on implementing non-block inventories?


535

Recommended Posts

I'm adapting a mod I wrote for ModLoader 1.3 and SSP to Forge and SMP and have hit a bit of a sticking point.

 

I use an inventory which is particular to the player rather than to a block / tile entity (a la ender chests/pouches or alchemy bags) and am having trouble reading and writing those inventories to disk in an SMP-friendly manner.  I've gotten a lot of mileage out of the forum and wiki here and by following along with existing code (cpw, you're a life-saver), but I haven't been able to dig up any examples of this kind of data storage and I'm apparently not yet familiar enough with Forge and the current state of MC modding to work it out on my own.  :-)

 

Originally, when I was only worried about SSP, I wrote the Inventory class to handle reading and writing (called from the container's constructor and the inventory's closeChest, respectively) to a file located under the integrated server's save directory, and after converting that to use FML's getMinecraftServerInstance, it works just fine under Forge SSP.  Under SMP, predictably, it's an absolute mess.  The client crashes with a NullPointerException trying to find the save folder (no SaveHandler, so no surprise there) and the server never tries to read the inventory at all.

 

So!  Any advice?  I'd be perfectly happy to just scrap my current approach, as it's pretty hacky, but I haven't yet managed to find an addon which hits the trifecta of having blockless inventories, using Forge, and being open-source.  The vanilla Ender Chest is sub-optimal because it stores its inventory within the player and I need something that's "owned" by a single player, but visible to all.

 

(I can post code if any want it, but I'm pretty convinced that the problem is a bad approach, rather than bad code.)

Link to comment
Share on other sites

The server side has a save handler.

 

I realize that; my issue isn't determining where to save the files, but rather the whole approach to communicating an inventory between server and client which isn't based on a tile entity.  My slapped-together approach doesn't work in SMP because the client tries to perform the file reading, but the server the writing.  If I move it all into the server, the client never sees the contents of the inventory at all and presents an empty container.

 

More than anything else, I'm looking for the basics of how to communicate an inventory between client and server when there's no tile entity to do the bridging (as with EE's alchemy bags).

Link to comment
Share on other sites

Take a look at how the player inventory works.

Thats how you should do yours.

 

Hmm.  Player inventory seems to be handled by the entity-spawning packet, which doesn't do me much good, but it led me to NetClientHandler.  I can see a lot of very interesting code there related to map data, which is handled pretty similarly to how I want my inventory to be; I'm going to see what I can do with it.

 

Thanks for the advice!

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