Jump to content

Spawning entities with forge 1.18.2


Duck478

Recommended Posts

I want to spawn a wither for one of my mods but I don't know how.

 

@SubscribeEvent

public void WitherMake(BreakEvent event) {

   if(!event.getPlayer().level.isClientSide) {

   WitherBoss wither = new WitherBoss(null, event.getPlayer().level);

   event.getPlayer().level.gameEvent(wither, GameEvent.ENTITY_PLACE, event.getPos());

   }

}

 

This is what im trying now but it dose not work. How would I spawn a wither i this placeholder method?

I looked at the spawn egg code but it is really confusing

Link to comment
Share on other sites

12 hours ago, Duck478 said:

I tried this too and it also doesn't work

maybe it does? or it doesn't? why did you expect to see result without specifying the location of the new entity?

addFreshEntity should work. alternatively, entityType.spawn() will work too.

Link to comment
Share on other sites

On 6/20/2023 at 7:04 AM, MFMods said:

why did you expect to see result without specifying the location of the new entity?

I don't know how to do that, how do I specify the location?

Can you give me an example of code to create any entity in minecraft and I can follow that

 

Link to comment
Share on other sites

entityType.spawn() has a BlockPos parameter. you can't miss it.

if you want to go with addFreshEntity, set the location (x,y,z) of the entity (there are set methods for it, i think i was setPosRaw). then, after that, call addFreshEntity.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.