Topic category: Troubleshooting, bugs, and solutions
If you are reading this, you probably have been to "custom crafting" hell.
The main issue isn't even about the fact that you need to hardcode recipes, if you're not willing to write your own java code for that (personally, I try to avoid this as much as I can.), it's that all solutions which are provided on the internet don't tell you that they only work in single player,
or on a local server.
Once you use their method on a server, you will get weird UI glitches, like Items dissappearing or in some of my
cases uncrafting themselves.
Disclaimer: This post has been written for MCreator version 2024.4, exporting for forge 1.20.1
The Issue:
All of your UI code, especially the code blocks inside of "Slot&GUI procedures" don't properly sync with the server.
This means that you as the player see your client side version, once you craft, you get to experience the server side version.
That's why you shouldn't use "clear slot <num> of the currently open GUI of <Event/Target>" or "set <ammount> <item> in slot <num> of of the currently open GUI of <Event/Target>"
to manage your crafting grids. Those will only work for single player, or for locally hosted servers.
Solution:
Instead of accessing the UI, you should access the block inventory, since that is apparently properly synced with the server and the client.
The procedures you should use for slot handling are under "Block procedures/Actions" ,
one example is "clear slot <num> of block at X Y Z if it has inventory".
You might notice that you need the exact block which currently holds the items. Be carefull here, if you call your item check procedures inside of "OnOpenGUITick"
the X,Y,Z coords will be the coordinates of the player, not the block. This usually leads to your recepies not being recognized, because the block inventory won't be found.
To get the block coordinates you will have to open the UI manually inside your block triggers, in my case OnBlockRightClicked.
(by the not manual way I mean making an extra "open ui" procedure. The default way would be to just tick "Open bound GUI on right click"),
This will give you the block coordinates inside of the procedure which you put there.
One important note here: If you still check your items on every GUI tick, you will have to store the current block coordinates inside of global variables.
Else X,Y,Z will be overridden by the player coordinates.
This approach is quite tedious, but it worked for me. My mod runs fine on external and internal servers.
Hope that I could help you. And good luck making your crafting work.
If there is a better way to do what I'm doing, please tell me. I'd love to make this easier.