I see. But how would I code the matches() method then?
Have a look at my recipe I linked above. The code is a little messy... but basically the logic is in my checkMatch method.
The matches method gives the inventory for the GUI Container, and the method will simply check the inventory for all of the required items in the right places against the recipe has stored.
I realise now this wouldn't work for your 2D boolean array as it's not contained in the inventory...
Okay, in that case I guess you'll want something more custom (sorry, I figure things out as I go XD)
I suggest you either check the recipe in your crafting manager (since there's no template or limitations to this class) OR you can ditch the IRecipe (don't see the point now if the matches method can't be used) and code your own specific method there.
Either way, when you check for recipe matches in your Container, you should call a method in your Crafting Manager to check the GUI input against your registered recipes (I have a method for the same thing for a custom crafting table here).
Have a look at my recipe I linked above. The code is a little messy... but basically the logic is in my checkMatch method.
The matches method gives the inventory for the GUI Container, and the method will simply check the inventory for all of the required items in the right places against the recipe has stored.
I realise now this wouldn't work for your 2D boolean array as it's not contained in the inventory...
Okay, in that case I guess you'll want something more custom (sorry, I figure things out as I go XD)
I suggest you either check the recipe in your crafting manager (since there's no template or limitations to this class) OR you can ditch the IRecipe (don't see the point now if the matches method can't be used) and code your own specific method there.
Either way, when you check for recipe matches in your Container, you should call a method in your Crafting Manager to check the GUI input against your registered recipes (I have a method for the same thing for a custom crafting table here).
I'll explain what I'm trying to do. So I want to make a packet for GUI -> Container for the carving grid. Once the packet arrives from the GUI to the container the grid is updated and a method that checks if a match is found is ran from the crafting manager. Now the point where I'm having trouble at is adding and storing these recipes inside the crafting manager. I followed what you said about IRecipe, but now that doesn't work and I'm not sure what to do. One idea is that I could make a class similar to ShapedRecipes, but without the IRecipe methods. Would that work?
I'll explain what I'm trying to do. So I want to make a packet for GUI -> Container for the carving grid. Once the packet arrives from the GUI to the container the grid is updated and a method that checks if a match is found is ran from the crafting manager.
If you want to update the Container, you'll want to update client and server. Create a method in the Container to do the updating, and call that from the GUI to update the client side (you can get the Container from the GUI using this.inventorySlots). To update the server side, you'd need to send a packet which sends the necessary data to the server, get the player, and then you can get the player's currently open Container using EntityPlayer#openContainer from which you can cast to your Container (make sure to null check and check it's an instance of your Container first!) and call your update method.
Sorry it took a while to get back to you, I've been busy lately.
If you want to update the Container, you'll want to update client and server. Create a method in the Container to do the updating, and call that from the GUI to update the client side (you can get the Container from the GUI using this.inventorySlots). To update the server side, you'd need to send a packet which sends the necessary data to the server, get the player, and then you can get the player's currently open Container using EntityPlayer#openContainer from which you can cast to your Container (make sure to null check and check it's an instance of your Container first!) and call your update method.
Sorry it took a while to get back to you, I've been busy lately.
Alright, I'll keep that in mind. But as I previously mentioned: how do I check for matching recipes. The only way I can come up with is just shoving everything into an if() statement, but that would be very time consuming as I would have to check each boolean from the array.
The only way I can come up with is just shoving everything into an if() statement, but that would be very time consuming as I would have to check each boolean from the array.
And that's the only way I can think of. To know that the recipe is valid, you need to check every part of the carving, which means iterating through them all and checking against the stored recipes. As far as I know, that's the best way to do it.
For comparing two Arrays I'd suggest to use the Arrays.equals() method. It's only working for 1D Arrays so you have to loop through the outer Array and then compare each of the inner ones using this method.
For comparing two Arrays I'd suggest to use the Arrays.equals() method. It's only working for 1D Arrays so you have to loop through the outer Array and then compare each of the inner ones using this method.
I believe so! Give it a go and let us know what happens. Try add some log prints to see if the method actually gets called on the client and server.
Getting a packet related error log (not crash) when pressing one of the carving buttons.
Also note that I remade the packet to send a single boolean instead of the whole array.
Also I added all of the recipes into the container itself.
Have a look at my recipe I linked above. The code is a little messy... but basically the logic is in my checkMatch method.
The matches method gives the inventory for the GUI Container, and the method will simply check the inventory for all of the required items in the right places against the recipe has stored.
I realise now this wouldn't work for your 2D boolean array as it's not contained in the inventory...
Okay, in that case I guess you'll want something more custom (sorry, I figure things out as I go XD)
I suggest you either check the recipe in your crafting manager (since there's no template or limitations to this class) OR you can ditch the IRecipe (don't see the point now if the matches method can't be used) and code your own specific method there.
Either way, when you check for recipe matches in your Container, you should call a method in your Crafting Manager to check the GUI input against your registered recipes (I have a method for the same thing for a custom crafting table here).
I'll explain what I'm trying to do. So I want to make a packet for GUI -> Container for the carving grid. Once the packet arrives from the GUI to the container the grid is updated and a method that checks if a match is found is ran from the crafting manager. Now the point where I'm having trouble at is adding and storing these recipes inside the crafting manager. I followed what you said about IRecipe, but now that doesn't work and I'm not sure what to do. One idea is that I could make a class similar to ShapedRecipes, but without the IRecipe methods. Would that work?
bump
If you want to update the Container, you'll want to update client and server. Create a method in the Container to do the updating, and call that from the GUI to update the client side (you can get the Container from the GUI using this.inventorySlots). To update the server side, you'd need to send a packet which sends the necessary data to the server, get the player, and then you can get the player's currently open Container using EntityPlayer#openContainer from which you can cast to your Container (make sure to null check and check it's an instance of your Container first!) and call your update method.
Sorry it took a while to get back to you, I've been busy lately.
Alright, I'll keep that in mind. But as I previously mentioned: how do I check for matching recipes. The only way I can come up with is just shoving everything into an if() statement, but that would be very time consuming as I would have to check each boolean from the array.
And that's the only way I can think of. To know that the recipe is valid, you need to check every part of the carving, which means iterating through them all and checking against the stored recipes. As far as I know, that's the best way to do it.
For comparing two Arrays I'd suggest to use the Arrays.equals() method. It's only working for 1D Arrays so you have to loop through the outer Array and then compare each of the inner ones using this method.
I've created a little helper method here
Nice Greetings
TechMage66
Right, so I got a packet going, but I can't seem to understand how to update the container's boolean array with the one from the packet.
GUI
http://pastebin.com/B3QGBdwQ
Container
http://pastebin.com/YVF07bvV
Packet
http://pastebin.com/74zg4BQw
Handler (!)
http://pastebin.com/sNiQ929W
In your packet handler you're just creating a new container and updating the grid in that. What's that going to do? I can tell you - nothing.
You need to get the player from the message context and get the player's currently open GUI like I said before.
How do I get the player? I have a method in the proxy, but it only returns the client player.
So I will end up with this?
No, get the currently open GUI / Container from the player. I think it's a variable in EntityPlayer.
Like this?
I believe so! Give it a go and let us know what happens. Try add some log prints to see if the method actually gets called on the client and server.
Getting a packet related error log (not crash) when pressing one of the carving buttons.
Also note that I remade the packet to send a single boolean instead of the whole array.
Also I added all of the recipes into the container itself.
GUI
http://pastebin.com/ZrRgyYbV
Container
http://pastebin.com/ic6z2Nkn
Packet
http://pastebin.com/VpRShQVt
Handler
http://pastebin.com/fN78vzrw
Error log
http://pastebin.com/Zn95g3iC
You have your reading and writing of the data the wrong way round!
fromBytes is reading the data. toBytes is writing the data
Silly me
Still, though, I am getting a fatal error now.
http://pastebin.com/G8weDLLR
Ah I thought you'd need this, but wasn't sure if it was necessary back in 1.7.10.
Your packet class needs an empty constructor with no parameters as well as the one you have.