GUI limit stack input multiple items

Started by thijs_films on

Topic category: Help with MCreator software

Joined Apr 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
GUI limit stack input multiple items

i have been looking everywhere for a good tutorial on how to do this but i can't find it.
what i'm trying to do is have a GUI slot where you can only put in a select view items, instead of only being able to limit it to just one item.
is there a good way to do this? maybe with tags but idk.

any help would be appreciated alot!

Joined Sep 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Hi! I'm using version 2023.4…
Sun, 09/01/2024 - 05:49

Hi! I'm using version 2023.4 and trying to do this. I think just using or can make it work perfectly.

For example, I first chose the diamond ore for the GUI limit stack input, so I could see a part of the code like this:

this.customSlots.put(0, this.addSlot(new SlotItemHandler(internal, 0, 55, 36) {
			private final int slot = 0;

			@Override
			public boolean mayPlace(ItemStack stack) {
				return Blocks.DIAMOND_ORE.asItem() == stack.getItem();
			}
		}))

Then, just in the editor, I used the hint or found the namespaced identifier to add the code like this:

this.customSlots.put(0, this.addSlot(new SlotItemHandler(internal, 0, 55, 36) {
			private final int slot = 0;

			@Override
			public boolean mayPlace(ItemStack stack) {
				return Blocks.DIAMOND_ORE.asItem() == stack.getItem() || Blocks.GOLD_ORE.asItem() == stack.getItem();
			}
		}));

There was a small issue when I tried to limit the equipment to items like the iron helmet or iron chestplate. The original code looked like this:

@Override
public boolean mayPlace(ItemStack stack) {
    return StackItems.IRON_HELMET == stack.getItem() || StackItems.IRON_CHESTPLATE == stack.getItem();
}

When I used this code and tried to test the mod, MCreator gave me some errors. I wasn't sure if this was the best solution, but I was able to fix the problem by changing StackItems to Items like this:

@Override
			public boolean mayPlace(ItemStack stack) {
				return Items.IRON_HELMET == stack.getItem() || Items.IRON_CHESTPLATE == stack.getItem();
			}

 

There are more items that I haven't tested yet. I only tested the equipment and blocks, so it might be necessary to make some adjustments to the code for other types of items, similar to how I did with the blocks and equipment. However, I think most of it should be the same.

Hope this can help you~