Creating a block that generates resources and deposits them into an inventory, like a chest positioned above it.

Started by velw on

Topic category: Help with modding (Java Edition)

Last seen on 10:33, 30. Sep 2023
Joined Sep 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Creating a block that generates resources and deposits them into an inventory, like a chest positioned above it.

I've been working on a setup with six slots, each capable of holding different items like diamonds, and it verifies the contents of each slot. If it identifies a diamond, it proceeds to generate a matching item in the chest above. Conversely, if it finds a gold ingot in a slot, it spawns an additional gold ingot or with that i assinged it with. 

Hopefully i wrote it so you guys can follow, thank you!!

Last seen on 18:06, 24. Jul 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
You should just be able to…
Wed, 09/27/2023 - 15:37

You should just be able to make a procedure that checks each slot, then checks for a storage block above, and, if it finds one, places the correct item inside. Unlike the player's inventory, you can't just say 'put something in a chest' and have it find the first available slot; you'll also have to make a procedure that runs through each slot of the chest, checks if it's empty, and if it already has something in it, moves on to the next slot instead. 

Last seen on 10:33, 30. Sep 2023
Joined Sep 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Sorry i am new to this, do…
Sat, 09/30/2023 - 10:33

Sorry i am new to this, do you have an solution for it, i try to learn from examples. 

Thank you for the help so far tho!!!

Im trying to make it count.

Last seen on 18:06, 24. Jul 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Something like this should…
Sat, 09/30/2023 - 15:23

Something like this should do it, worked when I tested it. (You'd have to make a separate case for golden bars.) It will also eat up your diamonds if the chest directly above is full, so you might want to check for that to.

This code checks if the block above is a chest. If it is, it repeats six times, checking each of the six inventory slots. (It refers to a local variable 'slotnumber,' which increases by one each time the function repeats.) It removes one item from the currently selected slotnumber, then repeats 27 times, checking each slot of the chest until it finds an available slot that's either empty or has an incomplete stack of diamonds. (Once it's found an available slot, it changes the local variable 'found' to true, which stops the repeat from running.) Once it has an available slot, it either puts diamonds inside if the slot is empty, or increases the number of items in the slot if it already has diamonds in it. The same method is used here, where a local variable 'chestslotnumber' increases by one every time the function repeats so that it keeps targeting a new slot.