Mod-compatible method of making spawn eggs

Started by TLSCT on Tue, 09/21/2021 - 21:44

Topic category: Help with MCreator software

Last seen on 04:46, 6. Oct 2021
Joined Aug 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Mod-compatible method of making spawn eggs
Tue, 09/21/2021 - 21:44

I would like to know how to code an item that, when thrown at a mob, checks to see if it has a spawn egg and create the egg in question if one is located. I know nothing about standard mod programming and have been using MCreator off and on for years, so I figured I would ask here.

How I specifically want it to work:

  1. Craft a throwable item. We'll call it a mob catcher for now.
  2. Throw the mob catcher at a mob like it's a throwable item, such as an egg or a snowball.
  3. If it hits the mob, either check the game's item list or an internal whitelist to see if that mob has an associated spawn egg.
  4. If a spawn egg for the mob is found, remove the mob from the world with no item drops and spawn the egg into the world for a player to pick up.
  5. If no spawn egg is found, or if the player misses entirely, say either in chat or on screen that no egg was found, and drop the mob catcher wherever it landed to be picked back up.

I wouldn't know the first thing about making this possible, either with a whitelist or the full item list, so I figured I would ask for help. Hopefully I put this in the right section; please let me know where it needs to be moved to if I didn't.

Last seen on 13:51, 18. Oct 2021
Joined Dec 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
No idea about correct…
Tue, 09/21/2021 - 22:40

No idea about correct section of the forum (I guess it's more modding issue than MCreator-related), but yeah, I'm pretty sure it is possible to do 1-4. Lately I had quite similar thing that I needed to create (cross-mod compatibile bullet system for my guns), so I will use the same method. As for 5, I will need to think a bit more

1. Create your craftable ranged item. It is recommended to be that way, since it has "when hits entity" trigger.
2. Make procedure "when hits entity" for this item. Now we will work only on it.

3. Add some local variable, like "entity_name" or sth
4. Make set "entity_name" local variable to "get entity display name". It will store name of entity.
5. In the meantime, you can kill the entity whatever method you want. Despawn should make items disappear, but in case it doesn't/you want to kill it brutally, use step 6.
6. If your mob drops item, run command killing also items around the entity; it should go like that:

  • kill @e[type=item,distance=..1]

7. Let's come back to our local variable. You now have name of entity, but in case it has more than one word in it, make another set "entity_name" local variable. But now use "replace [ ] with [_] on [get entity_name local variable]" in second part. Yes, exactly that - space in "replace" part, and "_" within with. It should make entities like "Red Dragon" look like "Red_Dragon".
8. Now, you need to make another command [let's call it command 2] which will spawn the egg for this specific player - use "run command by source entity", so it will be bound to the player who thrown that catcher. Unfortunately I have no idea how to make it appear in the world ;-;
9. In place where you have "command" text, replace it again with our favourite "replace [] with [] on []". This time I will write bracket stuff in parts:

  • on [] should contain command itself. It will be "give @s XYZ_spawn_egg 1". You can do whatever you want on XYZ part, I used XYZ since it makes no sense
  • replace [] should contain this exact XYZ or whatever you wrote instead
  • with [] should contain your "entity_name" local variable

10. This way, whenever entity gets hit by your catcher, it should run procedure being - for Red Dragon - like that:

  • give @s Red_Dragon_spawn_egg 1

It should work, even if there are capital letters, since (as far as I remember) it's not case sensitive. Also, it won't work if spawn egg is written in different way or it's differently named than mob itself. But that's all I could imagine being done without any line of code - maybe there are some neat workarounds allowing you for more, tho, so don't feel like it is everything you can do. I found a lot of nice solutions thanks to searching for them myself ^^