Solved Convert from Player to EntityLiving

Discussion in 'Plugin Development' started by HeroWorkbrine, Oct 26, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    HeroWorkbrine

    SOLVED
     
  2. Offline

    Rocoty

    Are you sure you know what you want to achieve? This question made almost no sense.
     
  3. Offline

    HeroWorkbrine

    For a method i need an EntityLiving, but when i cast player to EntityLiving it gives me an error
     
  4. Offline

    Rocoty

    I suppose you mean LivingEntity.....and if a method requires you to pass a LivingEntity there is not need to cast, as any Player already is a LivingEntity
     
  5. Offline

    HeroWorkbrine

    I need to convert
    org.bukkit.entity.Player
    To
    net.minecraft.server.v1_6_R3.EntityLiving
     
  6. Offline

    NathanWolf

    Ah - you can't, not in a bukkit-supported way, anyway.
     
  7. Offline

    Rocoty

    What are you trying to do, though? There might be another way to do it....or there might not....
     
  8. Offline

    HeroWorkbrine

    I want to make a new kind of arrow

    My class:
    Code:java
    1. package me.HeroWorkbrine.MMORPG.spell;
    2.  
    3. import net.minecraft.server.v1_6_R3.EntityArrow;
    4. import net.minecraft.server.v1_6_R3.EntityLiving;
    5.  
    6. import org.bukkit.craftbukkit.v1_6_R3.CraftWorld;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.event.block.Action;
    9.  
    10. public class Spell extends EntityArrow {
    11.  
    12. public Action[] clicks = new Action[3];
    13. public int level;
    14. public Player player;
    15.  
    16. public Spell(int level, Action a0, Action a1, Action a2, Player player) {
    17. super(((CraftWorld) player.getWorld()).getHandle(), (EntityLiving) player, 10F);
    18. this.player = player;
    19. this.level = level;
    20. clicks[0] = a0;
    21. clicks[1] = a1;
    22. clicks[2] = a2;
    23. }
    24.  
    25. public void cast() {
    26.  
    27. }
    28.  
    29. }
    30.  

    Line 17:
    super(((CraftWorld) player.getWorld()).getHandle(), (EntityLiving) player, 10F);
     
  9. Offline

    sheigutn

    I think you want ((EntityLiving) ((CraftPlayer) player).getHandle()) .
     
  10. Offline

    HeroWorkbrine

    It is the second argument, not the first
     
  11. Offline

    nisovin

    Are you sure this is really the way you want to go about this? There's probably a better way that doesn't involve extending an nms class. Maybe if you described what you're trying to do, someone would be able to give you an idea of how to do it.
     
  12. Offline

    HeroWorkbrine

    I only thought this was the way to do it, how should I do it then?
     
  13. Offline

    HeroWorkbrine

  14. Offline

    CubieX

    First of all, explain in detail what you are trying to do.
    "making a new arrow" is not really detailed.

    What characteristics should this new arrow have compared to a normal arrow?
     
  15. Offline

    HeroWorkbrine

    Solved it myself!
    Code:
    Code:java
    1. package me.HeroWorkbrine.MMORPG.spell.shooting;
    2.  
    3. import me.HeroWorkbrine.MMORPG.spell.Spell;
    4. import net.minecraft.server.v1_6_R3.EntityArrow;
    5. import net.minecraft.server.v1_6_R3.MathHelper;
    6.  
    7. import org.bukkit.Location;
    8. import org.bukkit.craftbukkit.v1_6_R3.CraftWorld;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
    11.  
    12. public abstract class ShootSpell extends EntityArrow implements Spell {
    13.  
    14. protected Player player;
    15.  
    16. public ShootSpell(Player player, float speed) {
    17. super(((CraftWorld) player.getWorld()).getHandle());
    18. Location loc = player.getLocation();
    19. setPositionRotation(loc.getX(), loc.getY() + player.getEyeHeight(), loc.getZ(), loc.getYaw(), loc.getPitch());
    20. locX -= (double) (MathHelper.cos(yaw / 180.0F * 3.1415927F) * 0.16F);
    21. locY -= 0.10000000149011612D;
    22. locZ -= (double) (MathHelper.sin(yaw / 180.0F * 3.1415927F) * 0.16F);
    23. setPosition(locX, locY, locZ);
    24. height = 0.0F;
    25. motX = (double) (-MathHelper.sin(yaw / 180.0F * 3.1415927F) * MathHelper.cos(pitch / 180.0F * 3.1415927F));
    26. motZ = (double) (MathHelper.cos(yaw / 180.0F * 3.1415927F) * MathHelper.cos(pitch / 180.0F * 3.1415927F));
    27. motY = (double) (-MathHelper.sin(pitch / 180.0F * 3.1415927F));
    28. shoot(motX, motY, motZ, speed, 1.0F);
    29. this.player = player;
    30. ((CraftWorld) player.getWorld()).getHandle().addEntity(this, SpawnReason.SPAWNER);
    31. cast();
    32. }
    33.  
    34. public abstract void cast();
    35.  
    36. public void a(boolean flag) {
    37. super.a(flag);
    38. lands();
    39. }
    40.  
    41. public abstract void lands();
    42.  
    43. public Player getPlayer() {
    44. return player;
    45. }
    46.  
    47. public void setPlayer(Player player) {
    48. this.player = player;
    49. }
    50.  
    51. }
    52.  
     
Thread Status:
Not open for further replies.

Share This Page