I would like my projectile to teleport the player when the projectile hit any block in a 10 block radius but if the projectile hits an entity(in the 10 block radius), the projectile will harm the entity instead of teleporting the player. How can this be done?
When you want to know how to implement something, look for similar features in vanilla or open source mods.
In this case, the Ender Pearl projectile does almost exactly what you want; though it will still teleport the thrower if it hits an entity and it doesn't have a maximum range.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
The EnderTeleportEvent just fires a Forge Event for other Mods to listen to. (Maybe someone made a mod to prevent Teleporting or to heal you instead of damaging, and those mdos would lsiten to that event.
If you want other mods' or vanilla's mechanics to be able to modify your teleportation, leave it there. If not, just remove everything that mentions events or the Forge event bus (but keep the teleportation code, of course).
For the teleport position coordinates, just set them to the entity's coordinates (the EnderTeleportEvent's target coordinates are copied from the entity).
The radius is determined by checking if the Entity is within 10 Blocks of the player:
I would like my projectile to teleport the player when the projectile hit any block in a 10 block radius but if the projectile hits an entity(in the 10 block radius), the projectile will harm the entity instead of teleporting the player. How can this be done?
When you want to know how to implement something, look for similar features in vanilla or open source mods.
In this case, the Ender Pearl projectile does almost exactly what you want; though it will still teleport the thrower if it hits an entity and it doesn't have a maximum range.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
I don't know where exactly is the teleporting portion of the code. EntityEnderPearl
Take a look at the onImapct () method. That's where the player gets teleported.
Nice Greetings
TechMage66
This code seems to be the teleporting code. Did I get it right? If so, how can I place it into my entity class?
Yes. this is the right piece of code. Modify it to your needs and put it in the Entity#onImpact method (1.8.9, don't know if the name was changed).
Okay, but which part of the code does the teleporting?
EntityLivingBase#setPositionAndUpdate
It's not 'real' teleporting, just telling the entity that it is located at that specific position instead of the old one.
I managed to teleport, next, how do I set a 10 block radius? Code
Edit 1:Is the EnderTeleportEvents required? If not, is there a way around it?
The EnderTeleportEvent just fires a Forge Event for other Mods to listen to. (Maybe someone made a mod to prevent Teleporting or to heal you instead of damaging, and those mdos would lsiten to that event.
If you want other mods' or vanilla's mechanics to be able to modify your teleportation, leave it there. If not, just remove everything that mentions events or the Forge event bus (but keep the teleportation code, of course).
For the teleport position coordinates, just set them to the entity's coordinates (the EnderTeleportEvent's target coordinates are copied from the entity).
The radius is determined by checking if the Entity is within 10 Blocks of the player:
Thanks it worked!
~ Deleted ~