Mod-compatible method of making spawn eggs

Started by TLSCT on

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:
  • MCreator plugins:
  • Comments:
Mod-compatible method of making spawn eggs

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.

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 ^^

Last seen on 03:15, 18. Nov 2023
Joined Mar 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
hello, I just did what you…
Thu, 06/23/2022 - 00:35

hello,

I just did what you said above but it doesn't take the right name it takes the name given with nametag and so if I rename a slime "cow" and capture it I get a cow egg and even if it took the name of the entity I think that any modded mob could not work due to the lack of term (like minecraft:) so can we get the preffix of the mod before the ":" and how to have (in mcreator) the part which allows to take the entity name and not the name given to the entity because I only found: " get (display) name of...."

and if we are not opped does the command work for the give? because the text "in name of -> source entity" makes me say that he makes the order for us so with our order access level

but otherwise in these cases everything works if an entity has a name and I launch it on it, it disappears and gives me its egg (except those who don't have one like the wither boss)

Fair point. I used MCreator…
Thu, 06/23/2022 - 08:40

Fair point. I used MCreator way of doing that, because as far as I used it (until 2021.2), there was no "get entity ID" procedure block, and I know that code explanation is usually seen as more confusing than more complicated, but non-code one.

Unfortunately, this goes with more limitations, bugginess, and it's more sophisticated in this specific case. If you'd prefer to use code, you would be able to get entity ID through such snippets:

entity.getName().getString();

OR

entity.getEntity().toString();

I didn't test it thus far for my projects, so be warned none of those can work - but from my investigation, first one should return string containing ID (so, mod_id:entity_id). As with code in MCR in general, manually putting this inside procedure code can be more bug-safe, but then remember about imports as well.

As for access level, I have no idea how this works for procedure blocks in MCreator, but you can always rephrase the command to have "execute @s ~ ~ ~ [your_command]". From what I read in wiki, "execute" bypasses access of an actor and runs it from OP-permission-level.