Hey man great tutorial! I got everything working perfectly One thing though, I want to make slot 1 in my inventory a specific item all the time. what should I do? i cant figure out the setInventorySlotContents part.
Hey man great tutorial! I got everything working perfectly One thing though, I want to make slot 1 in my inventory a specific item all the time. what should I do? i cant figure out the setInventorySlotContents part.
Do you mean you want that slot to permanently contain that item, or just that the slot can only hold that specific item? If it's the former, then you don't really want an inventory at all, at least not in the usual sense; for the latter, just make a custom Slot and override isValidForSlot.
Okay, then in your Gui class (which should extend GuiContainer), override mouseClickMove to do absolutely nothing. This will prevent players from interacting with your inventory, but they will still be able to see the items that it contains and hover over items to view tooltips. Another option is to return null from your Container#slotClick method - the player will never be able to move an item within your inventory.
If you only want it to affect one slot, then overriding Container#slotClick in your Container class is the easiest, since it gives you the slot index that was clicked.
Okay, then in your Gui class (which should extend GuiContainer), override mouseClickMove to do absolutely nothing. This will prevent players from interacting with your inventory, but they will still be able to see the items that it contains and hover over items to view tooltips. Another option is to return null from your Container#slotClick method - the player will never be able to move an item within your inventory.
If you only want it to affect one slot, then overriding Container#slotClick in your Container class is the easiest, since it gives you the slot index that was clicked.
This seems to only occur when Inventory Tweaks is installed but I don't think it's their fault. It happens pretty randomly although some people think the problem is after you shift click.
@SuperSonic If a bug only happens with another mod installed (e.g. InventoryTweaks), then you need to look at that other mod's code and see how it affects what your mod is trying to do. Since at least one of your classes is extending from a vanilla class, if the other mod does any sort of base edits to the class you rely on, then that is 99.9% likely to be the source of your problem.
That's all the help I can offer you on this thread, as your issue is not really related to my tutorial. I suggest you contact the author of the potentially offending mod and see if they have ever seen anything like that before, or you could try posting a topic in the Modification Development section here, or make a post on MinecraftForge.net.
I managed to get it working until the part where I use a Key to open the gui. The slots are in place, but I can't interact with any of the slots on the container, when I click an item it just goes back to the slot. Any idea on what I'm doing wrong?
I managed to get it working until the part where I use a Key to open the gui. The slots are in place, but I can't interact with any of the slots on the container, when I click an item it just goes back to the slot. Any idea on what I'm doing wrong?
Make sure you open the inventory on the SERVER, so if you are doing it from a keybinding, you have to send a packet. If you are already doing that, make sure you return a valid element both from the server (this would be your Container) and the client (your GUI).
Make sure you open the inventory on the SERVER, so if you are doing it from a keybinding, you have to send a packet. If you are already doing that, make sure you return a valid element both from the server (this would be your Container) and the client (your GUI).
All of those details seems fine, in fact, if I remove my custom slots it all works fine as a normal inventory screen .. I was peeking at Azanor's Baubles and he's using packets to sync the container with the GUI, could this be the issue? I tried finding something wrong with my slot, but it also seems to be properly setup.
All of those details seems fine, in fact, if I remove my custom slots it all works fine as a normal inventory screen .. I was peeking at Azanor's Baubles and he's using packets to sync the container with the GUI, could this be the issue? I tried finding something wrong with my slot, but it also seems to be properly setup.
If you have a Container, you should never need any packets to sync the inventory - that's the entire point of the Container.
Since you can narrow the issue down to your custom slots, then you very likely have incorrectly implemented that class. Show your custom slot(s) code.
There you go, sorry for posting it directly as text, but since it's not that huge I didn't think it would be worth it to use git. I'm gonna try to add just a normal slot and see how it goes (this would be a simple and useful test if I haven't deleted the container to start over )
(Thanks a lot for the tutorial and for the help BTW.)
There you go, sorry for posting it directly as text, but since it's not that huge I didn't think it would be worth it to use git. I'm gonna try to add just a normal slot and see how it goes (this would be a simple and useful test if I haven't deleted the container to start over )
(Thanks a lot for the tutorial and for the help BTW.)
That's sort of a funky implementation, but I don't see how it would cause the issue you described.
Slot#slotNumber already stores the index of the slot, so you don't need to store that yourself.
Your Slot#isItemValid implementation shouldn't need to call the Inventory's method, as that method usually calls the Slot's method, so you may have ended up in an infinite loop. The whole point of the Slot is that the Slot's implementation should be the final arbiter of what can be put in there, and each Slot that has special requirements is its own class rather than having a 'switch (slotIndex)' in your Inventory class, which is what it looks like you may have.
So if you have several slots all with different requirements, you should have several slot classes, and their #isItemValid implementations would look like this:
@Override
public boolean isItemValid(ItemStack stack) {
return stack == null || stack.getItem() instanceof ItemTool; // to allow any kind of tool, for example
Hey I've followed your Tutorials and have created a working Inventory.
Now I've come upon a sticky situation that I would appreciate someone to help me with, OK here it goes:
I have a working Inventory, Container and Slots, now I want to find a way to detect when my
inventory slots have a specific item in them. Kinda the way Armour slots work I want to give
the player an effect (for example potion effect) when ever this item is in my slot.
If anyone has an Idea please post it, I'm really stuck with this and I would love to have it fixed.
Thanks again,
iEquinox Soldier.
Hi,
I keep meaning to add that as part of the tutorial. It's very simple:
1. Add a PlayerTickEvent handler
2. Choose either Phase.END or Phase.START
3. During the chosen phase, iterate through all of the slots in your custom inventory and call Item#onUpdate and, if it's an ItemArmor, Item#onArmorTick
4. Then implement whatever effects you want directly in your item classes, as you would normally
Hi thanks for this, although is there any way you could post the placeholder text for me?
I'm good at coding but I need to see how the code is used and layed out.
Thank You
You have an opportunity here to improve your coding skills even further by translating step-by-step instructions in English into code - I wouldn't want to ruin that opportunity for you.
Hey man great tutorial! I got everything working perfectly One thing though, I want to make slot 1 in my inventory a specific item all the time. what should I do? i cant figure out the setInventorySlotContents part.
Do you mean you want that slot to permanently contain that item, or just that the slot can only hold that specific item? If it's the former, then you don't really want an inventory at all, at least not in the usual sense; for the latter, just make a custom Slot and override isValidForSlot.
ya i want the slot to permanently[/i] contain an item
Okay, then in your Gui class (which should extend GuiContainer), override mouseClickMove to do absolutely nothing. This will prevent players from interacting with your inventory, but they will still be able to see the items that it contains and hover over items to view tooltips. Another option is to return null from your Container#slotClick method - the player will never be able to move an item within your inventory.
If you only want it to affect one slot, then overriding Container#slotClick in your Container class is the easiest, since it gives you the slot index that was clicked.
Thank you! I got it
.
Hey,
I'm still having trouble with mine
This seems to only occur when Inventory Tweaks is installed but I don't think it's their fault. It happens pretty randomly although some people think the problem is after you shift click.
Container class.
https://github.com/SonarSonic/Calculator/blob/master/sonar/calculator/mod/common/containers/ContainerCalculator.java
Stored Crafting
https://github.com/SonarSonic/Sonar-Core/blob/master/sonar/core/client/gui/InventoryStoredCrafting.java
https://github.com/SonarSonic/Sonar-Core/blob/master/sonar/core/client/gui/InventoryStoredResult.java
Any help would be appreciated sooo much, since this bug has been in my mod since the beginning and I get loads of people complaining about it.
Flux Networks - CurseForge - Source Code
Practical Logistics 2 - CurseForge - Source Code
Calculator - CurseForge - Source Code
Bagelsmore - CurseForge - Source Code
@SuperSonic If a bug only happens with another mod installed (e.g. InventoryTweaks), then you need to look at that other mod's code and see how it affects what your mod is trying to do. Since at least one of your classes is extending from a vanilla class, if the other mod does any sort of base edits to the class you rely on, then that is 99.9% likely to be the source of your problem.
That's all the help I can offer you on this thread, as your issue is not really related to my tutorial. I suggest you contact the author of the potentially offending mod and see if they have ever seen anything like that before, or you could try posting a topic in the Modification Development section here, or make a post on MinecraftForge.net.
I managed to get it working until the part where I use a Key to open the gui. The slots are in place, but I can't interact with any of the slots on the container, when I click an item it just goes back to the slot. Any idea on what I'm doing wrong?
Make sure you open the inventory on the SERVER, so if you are doing it from a keybinding, you have to send a packet. If you are already doing that, make sure you return a valid element both from the server (this would be your Container) and the client (your GUI).
All of those details seems fine, in fact, if I remove my custom slots it all works fine as a normal inventory screen .. I was peeking at Azanor's Baubles and he's using packets to sync the container with the GUI, could this be the issue? I tried finding something wrong with my slot, but it also seems to be properly setup.
If you have a Container, you should never need any packets to sync the inventory - that's the entire point of the Container.
Since you can narrow the issue down to your custom slots, then you very likely have incorrectly implemented that class. Show your custom slot(s) code.
public class ExampleModSlot extends Slot
{
private byte index;
public ExampleModSlot(IInventory iInventory, int index, int x, int y)
{
super(iInventory, index, x, y);
this.index = (byte)index;
}
@Override
public boolean isItemValid(ItemStack itemStack)
{
if(inventory instanceof CustomPlayerInventory)
{
return inventory.isItemValidForSlot(index, itemStack);
}
return super.isItemValid(itemStack);
}
}
There you go, sorry for posting it directly as text, but since it's not that huge I didn't think it would be worth it to use git. I'm gonna try to add just a normal slot and see how it goes (this would be a simple and useful test if I haven't deleted the container to start over )
(Thanks a lot for the tutorial and for the help BTW.)
That's sort of a funky implementation, but I don't see how it would cause the issue you described.
Slot#slotNumber already stores the index of the slot, so you don't need to store that yourself.
Your Slot#isItemValid implementation shouldn't need to call the Inventory's method, as that method usually calls the Slot's method, so you may have ended up in an infinite loop. The whole point of the Slot is that the Slot's implementation should be the final arbiter of what can be put in there, and each Slot that has special requirements is its own class rather than having a 'switch (slotIndex)' in your Inventory class, which is what it looks like you may have.
So if you have several slots all with different requirements, you should have several slot classes, and their #isItemValid implementations would look like this:
@Override
public boolean isItemValid(ItemStack stack) {
return stack == null || stack.getItem() instanceof ItemTool; // to allow any kind of tool, for example
}
Hey I've followed your Tutorials and have created a working Inventory.
Now I've come upon a sticky situation that I would appreciate someone to help me with, OK here it goes:
I have a working Inventory, Container and Slots, now I want to find a way to detect when my
inventory slots have a specific item in them. Kinda the way Armour slots work I want to give
the player an effect (for example potion effect) when ever this item is in my slot.
If anyone has an Idea please post it, I'm really stuck with this and I would love to have it fixed.
Thanks again,
iEquinox Soldier.
Hi,
I keep meaning to add that as part of the tutorial. It's very simple:
1. Add a PlayerTickEvent handler
2. Choose either Phase.END or Phase.START
3. During the chosen phase, iterate through all of the slots in your custom inventory and call Item#onUpdate and, if it's an ItemArmor, Item#onArmorTick
4. Then implement whatever effects you want directly in your item classes, as you would normally
Hi thanks for this, although is there any way you could post the placeholder text for me?
I'm good at coding but I need to see how the code is used and layed out.
Thank You
You have an opportunity here to improve your coding skills even further by translating step-by-step instructions in English into code - I wouldn't want to ruin that opportunity for you.
Ok, I accept that challenge.
I was just trying to remember how to iterate a list like inventory contents.
Excellent In that case, Google is your friend, as are the JavaDocs from Oracle.