Spawn Item after Animal breeding (BabyEntitySpawnEvent?)

Started by Dashin on

Topic category: Help with Minecraft modding (Java Edition)

Joined Nov 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Spawn Item after Animal breeding (BabyEntitySpawnEvent?)

Hi! I'm making a mod for minecraft 1.19.2 and everything was fine but now I'm stuck.

I want an item to be spawned / dropped after breeding 2 animals (any kind of animal actually), I didn't find a "clean way" to do it with procedures (maybe is there a way checking entity spawn or entity enters the world and checking if it's child?, but in this case I'm afraid that if baby chicken spawn from egg will also be executed for example).

I'm currently a Java programmer so I work like 8 hours day programming, If i have to code is no problem (Though I like MCreator because it's more visual and "relax me more" after I got home haha). I was looking for forge APIs (which I think is what I have to use to code my own procedure) and find that BabyEntitySpawnEvent it's the event I'm looking for, but I cant find the event I have to Subscribe to (somewhere I found onBabyBorn, but I think it's not right). I don't know If maybe the best solution is to learn more about forge and create this subscriptions manually or maybe it's not the best way to go. If integrating custom code / procedures is the right thing to do, some help / advice?

 

Thank you in advance!

Joined Nov 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I think integrating custom…
Tue, 11/22/2022 - 23:25

I think integrating custom code would be good

 

Joined Nov 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Ok thank you!  Then I guess…
Wed, 11/23/2022 - 00:06

Ok thank you! 

Then I guess the question is, where do I find the Events that I have to subscribe? (Tryng to post more info but I got 1 error has been found on reply)

Thank you again!

Joined Nov 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
 I don't know if there's a…
Wed, 11/23/2022 - 00:10

 I don't know if there's a layer in between for MCreator or that I'm just missing something (I'm newbie making mods after all >.<) and so I cant Find the event I have to subscribe for BabyEntitySpawnEvent (maybe it comes from Animal?). The docs for this event I'm looking for are here https://nekoyue.github.io/ForgeJavaDocs-NG/javadoc/1.19.2/net/minecraftforge/event/entity/living/BabyEntitySpawnEvent.html

Joined Nov 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
My current code is something…
Wed, 11/23/2022 - 00:21

My current code is something like this

 

@Mod.EventBusSubscriber

public class EssenceFromBreedingProcedure {
@SubscribeEvent
public static void onBabyBorn(BabyEntitySpawnEvent event) {
execute(event, event.getChild().level, event.getChild().getX(), event.getChild().getY(), event.getChild().getZ());
}

public static void execute(LevelAccessor world, double x, double y, double z) {
execute(null, world, x, y, z);
}

private static void execute(@Nullable Event event, LevelAccessor world, double x, double y, double z) {
if (Mth.nextInt(RandomSource.create(), 1, 100) >= 1) {
if (world instanceof Level _level && !_level.isClientSide()) {
ItemEntity entityToSpawn = new ItemEntity(_level, x, y, z, new ItemStack(AfterworldModItems.ESSENCE_OF_LOVE_ITEM.get()));
entityToSpawn.setPickUpDelay(10);
_level.addFreshEntity(entityToSpawn);
}
}
}
}
 
Joined Nov 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Sorry, done. Everything was…
Wed, 11/23/2022 - 02:06

Sorry, done.

Everything was working since the beggining, I was using getChild that I suppose was null at the time of the event and my item position relies on it.

Thank you very much. Stupid mistake!