Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hey all,

 

I am trying to spawn one of my entities in the world when a player right clicks on a creeper (for now)

 

	@SubscribeEvent
	public void interactEntity(PlayerInteractEvent.EntityInteract event)
	{
		if(event.getTarget().getClass().equals(EntityCreeper.class))
		{
          		Utils.getlogger.info("Creeper clicked");
			event.getWorld().spawnEntity(new EntitySpiritCreeper(event.getWorld()));
		}
	}

 

Note, the message does get logged. So the check up to the point of spawning code does work.

Nothing is spawning. However, I feel like I should be able to enter more parameters, like location and such. Thanks in advance.

Edited by MSpace-Dev

You need to set location and angles of the entity. You can use the setLocationAndAngles method for that, from the Entity class.

        EntityModMob mob = new EntityModMob(event.getWorld());
        mob.setLocationAndAngles(DESIRED POSITION AND ROTATION GOES HERE);
        event.getWorld().spawnEntity(mob);

 

Edited by TheUnnamed

  • Author

Thanks, worked perfectly. However, I used setRotationAndPosition() instead.

For interest sake: What's the difference? They look the same, so I assume it's just a refactor

  • Author

Actually, still having an issue. Since the position of the target only is returned as an int, and not a float. The entity spawns aligned to the grid, rather at the exact location. Also, the rotation of the entity is not applied.

 

EntitySpiritCreeper creeper = new EntitySpiritCreeper(event.getWorld());
creeper.setPositionAndRotation(event.getTarget().getPosition().getX(), event.getTarget().getPosition().getY(), event.getTarget().getPosition().getZ(), event.getTarget().rotationYaw, event.getTarget().rotationPitch);
event.getWorld().spawnEntity(creeper);

Excuse the long line of code. Going to refactor soon.

I tried with both methods btw.

Not 100% sure as I don't have a 1.11.2 workspace set up, but in 1.14.2 the Javadocs tells me that setRotationAndPosition() sets the position and rotation, clamping and wrapping params to valid values. Used by network code.

Whereas setLocationAndAngles() simply sets the location and Yaw/Pitch of the entity in the world.

  • Author

Ah, interesting. Guess I'll use the latter then. Any idea about the above issue? Can't find a method that returns floating point values.

Regarding your problem, use the posX, posY, posZ double variables instead, from the entity class, this I believe will give you the exact position.

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.