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.
So already I'm not sure how to go about the new slots. As I understand I need to create a new inventory for the container. How would I do that? Then as far as I understand I need to create two new slots that extend Slot. What would I put inside them? And how do I make the slots only contain the dye and rune type items?
So already I'm not sure how to go about the new slots. As I understand I need to create a new inventory for the container. How would I do that? Then as far as I understand I need to create two new slots that extend Slot. What would I put inside them? And how do I make the slots only contain the dye and rune type items?
You need to override isItemValid in your custom Slot class, you don't have to create 2 different classes. Then you need to use the switch statement with slotNumber from the Slot class as the value. The number of the 1st slot is always 0. So you will check for slot number 0, and slot number 1. You need to return an Item in each cases, ", courier, monospace">return stack.getItem() == Items.dye;
Your code should look something like this:
@Override
public boolean isItemValid(ItemStack stack)
{
switch (//call the slotNumber from Slot class)
{
case 0:
return stack.getItem() == Items.dye;
case 1:
return stack.getItem() == YourItems.runeItem;
}
}
You need to override isItemValid in your custom Slot class, you don't have to create 2 different classes. Then you need to use the switch statement with slotNumber from the Slot class as the value. The number of the 1st slot is always 0. So you will check for slot number 0, and slot number 1. You need to return an Item in each cases, return stack.getItem() == Items.dye;
Your code should look something like this:
@Override
public boolean isItemValid(ItemStack stack)
{
switch (//call the slotNumber from Slot class)
{
case 0:
return stack.getItem() == Items.dye;
case 1:
return stack.getItem() == YourItems.runeItem;
}
}
Gotcha, but how does the custom slot class look like generally? I.E. which methods, etc.
And also what about a custom inventory? How would that look like? Or could I keep using the InventoryPlayer?
Gotcha, but how does the custom slot class look like generally? I.E. which methods, etc.
And also what about a custom inventory? How would that look like? Or could I keep using the InventoryPlayer?
I haven't gotten the entire concept between Inventory classes and Container classes but I think you need to create your own Inventory class as it can't be sharing the player inventory, or else, there may (should be, I think) a copy of an item appearing. Double item.
As for your 1st question, the custom slot class generally has the constructor and isItemValid.
As for the methods of an Inventory class, your IDE will override the methods for you when you implement IInventory. Just one question before I tell you what methods you will need, you are using an Item to open the GUI, right?
I haven't gotten the entire concept between Inventory classes and Container classes but I think you need to create your own Inventory class as it can't be sharing the player inventory, or else, there may (should be, I think) a copy of an item appearing. Double item.
As for your 1st question, the custom slot class generally has the constructor and isItemValid.
As for the methods of an Inventory class, your IDE will override the methods for you when you implement IInventory. Just one question before I tell you what methods you will need, you are using an Item to open the GUI, right?
So I need to create an inventory class which extends IInventory and leave it at that without adding anything else in? And then use it as an arg in the container?
And yes, I am opening the GUI with an item, but why does that matter?
Also one more question, what if I want the same to be an input slot (for dyes) and output slot (outputs only runes and you can't place anything in it). Would that work with your switch method?
Also one more question, what if I want the same to be an input slot (for dyes) and output slot (outputs only runes and you can't place anything in it). Would that work with your switch method?
Yes, that is exactly what the switch method is for, it's to check the slot number and specified item.
This is an example of adding a Slot to a Container, a basic Slot class,
Note that your custom Inventory class is to be in the constructor parameters of your Container class.
Now, I'm sorry I can't help you any further with your custom Inventory class as I'm working in 1.8.9 and not 1.7.10, but here's a tutorial that you can follow to setup your custom Inventory class, click here.
The reason why I asked if the GUI would be opened from an Item was because IInventory classes needs to be used instead of TileEntity if you are using Item.
Yes, that is exactly what the switch method is for, it's to check the slot number and specified item.
This is an example of adding a Slot to a Container, a basic Slot class,
Note that your custom Inventory class is to be in the constructor parameters of your Container class.
Now, I'm sorry I can't help you any further with your custom Inventory class as I'm working in 1.8.9 and not 1.7.10, but here's a tutorial that you can follow to setup your custom Inventory class, click here.
The reason why I asked if the GUI would be opened from an Item was because IInventory classes needs to be used instead of TileEntity if you are using Item.
I see thanks for your help
What I meant about the switch part, is how would the code look like to make an output slot (doesn't accept any items in)? Instead of the slot accepting a rune item.
I see thanks for your help
What I meant about the switch part, is how would the code look like to make an output slot (doesn't accept any items in)? Instead of the slot accepting a rune item.
Now, the next part is checking for a certain dye in the input slot and outputting the rune into the output slot. What are the methods to check for a metadata in a slot and output an item? Also, how to clear everything out after the output item was removed?
Your slot class looks good for the input slot. I forgot the method to check the metadata onf the dye. Currently on mobile. Sorry again for my inability to help you any further.
I think you need to create your own Inventory class
You don't need to. Depending on your needs, you can use the pre-made vanilla inventory classes.
Have a look at the vanilla crafting table, or my custom hammer crafting table here. You can see the use there of an InventoryCrafting for the crafting grid and an InventoryCraftResult for the output slot.
You don't need to. Depending on your needs, you can use the pre-made vanilla inventory classes.
Have a look at the vanilla crafting table, or my custom hammer crafting table here. You can see the use there of an InventoryCrafting for the crafting grid and an InventoryCraftResult for the output slot.
I did say I didn't fully grasp the concept between Inventories and Containers.
Can someone explain to me why I get a nullpointerexception at this piece of code on the second condition (the first is fine) if I have no item in the slot. If I do have a dye in the slot everything is ok.
Can someone explain to me why I get a nullpointerexception at this piece of code on the second condition (the first is fine) if I have no item in the slot. If I do have a dye in the slot everything is ok.
It appeared to actually be a stackoverflowerror which was caused by the checkRecipes() and setInventorySlotContents() methods looping infinitely. I fixed it by creating a method identical to setInventorySlotContents(), but without running the checkRecipes() method.
Right, so after hours agony and torture I got most of the things working!
But I have 2 final issues:
1) How to update the client GUI from the server container. In my custom slot I have a method that is supposed to reset the carving grid after taking out the result, but it doesn't affect the client (obviously). I don't know how to do this through packets, because I have no idea how to tell the client that the packet has arrived.
2) When the craft result is added in the container (part with setInventorySlotContents()) the item itself is not displayed in the GUI, even though it's there.
Well, this issue doesn't relate to thread anymore so I'll mark it as solved. I will be posting everything I've done on my repo. Huge thanks to everyone who helped. Deserves credit.
1) How to update the client GUI from the server container. In my custom slot I have a method that is supposed to reset the carving grid after taking out the result, but it doesn't affect the client (obviously). I don't know how to do this through packets, because I have no idea how to tell the client that the packet has arrived.
2) When the craft result is added in the container (part with setInventorySlotContents()) the item itself is not displayed in the GUI, even though it's there.
To update the client from the server, the Container class actually already has methods for it. I've used blocks like the vanilla furnace to create my own block with GUI before. Have a look at the following code: Container My Base Container (The above container extends this) Gui Tile Entity
I've highlighted the code which will be of interest to get this working. I've done something similar to the furnace (I think it was ;P) so you don't need to use the setField stuff. But the main things of interest are the two method in my Container and the one in the Base Container.
Container#detectAndSendChanges you will use to send data from the server to the client Container by checking if it needs to be updated (I'm sending data using the "progress bar". Just using what's already in place, and it works fine). Then the Container#updateProgressBar will set the value to your new value the client has received.
Don't ask about the Container#addListener... vanilla had it so I included it XD I don't completely understand the listeners but I got it working =D
To update the client from the server, the Container class actually already has methods for it. I've used blocks like the vanilla furnace to create my own block with GUI before. Have a look at the following code: Container My Base Container (The above container extends this) Gui Tile Entity
I've highlighted the code which will be of interest to get this working. I've done something similar to the furnace (I think it was ;P) so you don't need to use the setField stuff. But the main things of interest are the two method in my Container and the one in the Base Container.
Container#detectAndSendChanges you will use to send data from the server to the client Container by checking if it needs to be updated (I'm sending data using the "progress bar". Just using what's already in place, and it works fine). Then the Container#updateProgressBar will set the value to your new value the client has received.
Don't ask about the Container#addListener... vanilla had it so I included it XD I don't completely understand the listeners but I got it working =D
But how do I get access to the GUI? I can't really pass it into the container's constructor (or can I?). I can't refer to the vanilla code either because everything there uses a tileentity. What do I do?
Victory!
Now I just need to create a dye and output slot and incorporate that into the recipes. I'll report back if I have any issues.
There was one silly mistake *facepalm*
So already I'm not sure how to go about the new slots. As I understand I need to create a new inventory for the container. How would I do that? Then as far as I understand I need to create two new slots that extend Slot. What would I put inside them? And how do I make the slots only contain the dye and rune type items?
You need to override isItemValid in your custom Slot class, you don't have to create 2 different classes. Then you need to use the switch statement with slotNumber from the Slot class as the value. The number of the 1st slot is always 0. So you will check for slot number 0, and slot number 1. You need to return an Item in each cases, ", courier, monospace">return stack.getItem() == Items.dye;
Your code should look something like this:
Gotcha, but how does the custom slot class look like generally? I.E. which methods, etc.
And also what about a custom inventory? How would that look like? Or could I keep using the InventoryPlayer?
I haven't gotten the entire concept between Inventory classes and Container classes but I think you need to create your own Inventory class as it can't be sharing the player inventory, or else, there may (should be, I think) a copy of an item appearing. Double item.
As for your 1st question, the custom slot class generally has the constructor and isItemValid.
As for the methods of an Inventory class, your IDE will override the methods for you when you implement IInventory. Just one question before I tell you what methods you will need, you are using an Item to open the GUI, right?
So I need to create an inventory class which extends IInventory and leave it at that without adding anything else in? And then use it as an arg in the container?
And yes, I am opening the GUI with an item, but why does that matter?
Also one more question, what if I want the same to be an input slot (for dyes) and output slot (outputs only runes and you can't place anything in it). Would that work with your switch method?
Yes, that is exactly what the switch method is for, it's to check the slot number and specified item.
This is an example of adding a Slot to a Container, a basic Slot class,
Note that your custom Inventory class is to be in the constructor parameters of your Container class.
Now, I'm sorry I can't help you any further with your custom Inventory class as I'm working in 1.8.9 and not 1.7.10, but here's a tutorial that you can follow to setup your custom Inventory class, click here.
The reason why I asked if the GUI would be opened from an Item was because IInventory classes needs to be used instead of TileEntity if you are using Item.
I see thanks for your help
What I meant about the switch part, is how would the code look like to make an output slot (doesn't accept any items in)? Instead of the slot accepting a rune item.
Sorry, I can't help you. It's beyond my ability.
Ah, we're finally getting somewhere!
As I was doing these pretty blindly, I would appreciate if someone would check these
Inventory
http://pastebin.com/sT7VBMMG
Slot
http://pastebin.com/QcPCvLaU
Now, the next part is checking for a certain dye in the input slot and outputting the rune into the output slot. What are the methods to check for a metadata in a slot and output an item? Also, how to clear everything out after the output item was removed?
Your slot class looks good for the input slot. I forgot the method to check the metadata onf the dye. Currently on mobile. Sorry again for my inability to help you any further.
You don't need to. Depending on your needs, you can use the pre-made vanilla inventory classes.
Have a look at the vanilla crafting table, or my custom hammer crafting table here. You can see the use there of an InventoryCrafting for the crafting grid and an InventoryCraftResult for the output slot.
I did say I didn't fully grasp the concept between Inventories and Containers.
Can someone explain to me why I get a nullpointerexception at this piece of code on the second condition (the first is fine) if I have no item in the slot. If I do have a dye in the slot everything is ok.
I'm guessing it's something to do with getStackInSlot().getItem().
That's fine, I was quoting you as reference and providing some extra help
You need to check if inventoryInscription.getStackInSlot(0) is null.
That works thanks!
Another question, how do check if an item is placed in the input slot?
So in the meantime I actually figured stuff out, but now I'm getting a ReportedException: Updating screen events at this line in the container:
Container:
http://pastebin.com/DEDApPJu
Inventory:
http://pastebin.com/dYRxPBF4
EDIT:
Silly me
It appeared to actually be a stackoverflowerror which was caused by the checkRecipes() and setInventorySlotContents() methods looping infinitely. I fixed it by creating a method identical to setInventorySlotContents(), but without running the checkRecipes() method.
Right, so after hours agony and torture I got most of the things working!
But I have 2 final issues:
1) How to update the client GUI from the server container. In my custom slot I have a method that is supposed to reset the carving grid after taking out the result, but it doesn't affect the client (obviously). I don't know how to do this through packets, because I have no idea how to tell the client that the packet has arrived.
2) When the craft result is added in the container (part with setInventorySlotContents()) the item itself is not displayed in the GUI, even though it's there.
GUI:
http://pastebin.com/shbcUHb4
Container:
http://pastebin.com/Tcz1AeYh
Inventory:
http://pastebin.com/R7bdWvug
Slot:
http://pastebin.com/3ZV7VrEJ
EDIT:
Well, this issue doesn't relate to thread anymore so I'll mark it as solved. I will be posting everything I've done on my repo. Huge thanks to everyone who helped. Deserves credit.
To update the client from the server, the Container class actually already has methods for it. I've used blocks like the vanilla furnace to create my own block with GUI before. Have a look at the following code:
Container
My Base Container (The above container extends this)
Gui
Tile Entity
I've highlighted the code which will be of interest to get this working. I've done something similar to the furnace (I think it was ;P) so you don't need to use the setField stuff. But the main things of interest are the two method in my Container and the one in the Base Container.
Container#detectAndSendChanges you will use to send data from the server to the client Container by checking if it needs to be updated (I'm sending data using the "progress bar". Just using what's already in place, and it works fine). Then the Container#updateProgressBar will set the value to your new value the client has received.
Don't ask about the Container#addListener... vanilla had it so I included it XD I don't completely understand the listeners but I got it working =D
But how do I get access to the GUI? I can't really pass it into the container's constructor (or can I?). I can't refer to the vanilla code either because everything there uses a tileentity. What do I do?