How to get an entire range of numbers

Started by davemurdock55 on

Topic category: Help with modding (Java Edition)

Last seen on 02:28, 27. Apr 2022
Joined Oct 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How to get an entire range of numbers

Hey guys, sorry I'm a bit new to all of this, but I have been searching and searching everything I can find to figure out a way to do this.

I want to check/replace every single slot in a chest and then replace a specific item, if found, with another item. To do this, I have a some code laid out to check if it is raining (one of the dependencies I need for this) and if the item is in slot 0-36 of a "chest" block. Being able to create a range would make it so I don't have to repeat the same block of code 36 times in a row, changing only one number.

 

I don't know how to insert an image, but here's what I've done so far:

Event trigger

if [[is raining in the provided world]AND[[get item from slot 0 of currently open GUI of [event target entity]] = [certain item]]]

do [clear slot 0 of block at x y z if it has inventory]

     [set 1 [certain other item] in slot 0 of block at x y z if it has inventory]

 

And after writing that out, I realized I don't want the GUI to have to be open in order for this change to take place

 

ANY HELP WOULD BE VERY VERY APPRECIATED!!! I've been searching for DAYS on end!

Last seen on 12:10, 12. Jan 2021
Joined Apr 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
You could try something like…
Tue, 12/22/2020 - 13:18

You could try something like this:

while ("chestSlotCounter" is smaller or equal to 36)

     do set "itemInSlot" to get item from slot "chestslotCounter" of the currently open GUI of event/target entity

     if "itemInSlot" = "Your specific item"

     do set "slotOfItem" to "chestSlotCounter"

     else set "chestSlotCounter" to "chestSlotCounter" + 1

set 1 "The item you want to replace with" in slot "slotOfItem" of the currently open GUI of event/target entity

 

To explain, this procedure searches all slots of the opened GUI and saves the slot, in which the item was found to a variable. You could instead save that as a nbt tag. But this procedure can only save one slot, that means if you find the item more often than in one slot, the procedure only saves the last slot, in which the item was found. The variable "chestSlotCounter" counts up by one until it reaches 36. This variable stands for the 0-36 slots. The variable "itemInSlot" is the item that is in e.g the slot 0. this item gets checked if it your desired item. If it is then the slot of the item is saved to "slotOfItem". Else the counter is raised by 1 and the loop checkes the next slot. When the loop is over and has checked all slots you can can replace the item in that slot.

I hope you can do something with this.