Working on server-side inventory
There are a few stability issues with the client that worry me, and I will try to sort that out before I go on the trip to Finland next week, but more important is getting SMP more playable before then.
I’m currently working on server-side inventory, and it’s going relatively well. I’m currently pulling on hard coded
strands of spaghetti code, seeing what moves, then refactoring that out into a better designed code. See, when I
first wrote the inventory, it was just a test to see if it was fun, and I’ve stuck to that code ever since since I
never really had to change it.
I probably would’ve saved myself some time if I had fixed the code immediately
when it was still fresh in my mind.
The worst part about refactoring code is that you spend hours working on something only to have it do the exact same thing when you’re done with it. The best part is that you feel much better about working with that code in the future. It’s very cleansing, in a boring kind of way.
One interesting problem that came up was that of client-side prediction. Since the client is able to accurately predict inventory management 100% (with the exception of crafting, which I’m making controlled by the server, for modding reasons), there’s no reason to synch any state other than to tell the server what happens.
Or so I thought!
For example, another player can throw an item at you while you’re playing around in your inventory. If you split a stack client side, your inventory might end up being full, but the server thought you had room because of lag, and that item ends up getting lost. So instead of having the server assign new items a specific slot, it just goes “here, take this if you can”, and the client says either “ok, I put it in slot #7” or “no” as a reply.
But then what about chests?
I can either make chest only operatable by one player at a time, or I can make them fully synched by the server, meaning they would get noticeably laggy. I don’t want to lock chests to one user, as that’s prone to griefing, nor do I want to do the fully synchronous inventory management in them as it really ruins the smooth feeling. I could do some clever rollback scheme where the client will predict moves until the server says that a certain move was illegal (like if two players try to take the same item at the same time, only the first player should get it), but that might get annoying. You see yourself picking up an item, and you place it in your inventory, but then it vanishes.
[why is tumblr refusing to post some entires?]