[SOLVED]How can you use a procedure to convert a registry name to a loot table name?

Started by Catnip on

Topic category: Help with modding (Java Edition)

Last seen on 21:57, 15. Oct 2024
Joined Apr 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
[SOLVED]How can you use a procedure to convert a registry name to a loot table name?
Mon, 02/12/2024 - 22:24 (edited)

I am wanting to create a procedure that will get the loot table of a certain entity that is determined by location, so it could be almost any entity from vanilla or modded Minecraft. I have found a procedure block to get the entity's registry name which should contain entity name and mod namespace, but I don't know how I can insert entity/ in the middle of it to convert it to a valid loot table name.  If anyone knows how to do this, a guide would be much appreciated.

Edited by Catnip on Mon, 02/12/2024 - 22:24
Last seen on 21:57, 15. Oct 2024
Joined Apr 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
After quite a bit of trial…
Mon, 02/12/2024 - 21:33

After quite a bit of trial and error, I figured it out.

You first need to create two local string variables, one that I am calling entity, and one that I am calling mod, then create the following procedure:

    (set local:[entity] to ("{entity namespace}"))

    (set local:[mod] to ("{}"))

    (While) (does text (get local:[entity]) contain ("{:}")

    (Do) (Set local:[mod] to: (create text with (get local:[mod])(substring:(get local:[entity]) from position: ({0}) to position: ({1}))))

             (Set local:[entity] to: (substring:(get local:[entity]) from position: ({1}) to position: (length of)(get local:[entity])))

After you have all of that set up, setting the 'entity' string variable to the entity's registry name, setting the 'mod' string variable to nothing, then transferring one letter at a time from 'entity' to 'mod' until 'mod' contains the colon, and therefore the mod registry name of the entity, you can use a 'create text with' procedure block to put together 'mod', a text component 'entities/' and 'entity' to get the loot table for that entity.

I hope this helps anyone who is looking to do something similar, I know it's very complicated, but everything has a purpose here.