MSpace-Dev Posted June 30, 2019 Posted June 30, 2019 (edited) 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 June 30, 2019 by MSpace-Dev Quote
TheUnnamed Posted June 30, 2019 Posted June 30, 2019 (edited) 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 June 30, 2019 by TheUnnamed Quote
MSpace-Dev Posted June 30, 2019 Author Posted June 30, 2019 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 Quote
MSpace-Dev Posted June 30, 2019 Author Posted June 30, 2019 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. Quote
TheUnnamed Posted June 30, 2019 Posted June 30, 2019 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. Quote
MSpace-Dev Posted June 30, 2019 Author Posted June 30, 2019 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. Quote
TheUnnamed Posted June 30, 2019 Posted June 30, 2019 Regarding your problem, use the posX, posY, posZ double variables instead, from the entity class, this I believe will give you the exact position. 1 Quote
MSpace-Dev Posted June 30, 2019 Author Posted June 30, 2019 Ah, found it. Thanks for all the help Quote
Recommended Posts
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.