Help about Entity

Discussion in 'Разработка плагинов' started by Accasua, 12/11/16.

  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
Dismiss Notice
We welcome you on our site. This site is devoted to the Nukkit project and all that is connected with him. Here you can communicate, download plugins, also many other things get acquainted! Register the account right now :3
  1. Accasua

    Accasua Пользователь

    Messages:
    8
    Likes Received:
    0
    Minecraft:
    Accasia
    How I can make ItemEntity which floats around player?


    I need some help

    Sorry for my bad english. :p
     
  2. FSDC

    FSDC Пользователь

    Messages:
    2
    Likes Received:
    0
    what do you mean by which floats around player
     
  3. Accasua

    Accasua Пользователь

    Messages:
    8
    Likes Received:
    0
    Minecraft:
    Accasia

    https://github.com/Nukkit/Nukkit/blob/master/src/main/java/cn/nukkit/entity/item/EntityItem.java

    just on the head.

    I use this code, is it right?
    if right, how can i set ItemID?
    if wrong, plz help..

    sorry for my bad English :p



    --------------------
    package buff.ItemEntityPet;
    import cn.nukkit.Player;
    import cn.nukkit.entity.Entity;
    import cn.nukkit.level.format.FullChunk;
    import cn.nukkit.nbt.tag.CompoundTag;

    public class EntityPet extends Entity{

    public static final int NETWORK_ID = 64;
    public Player owner = null;

    public EntityPet(FullChunk chunk, CompoundTag nbt, Player owner) {
    super(chunk, nbt);
    this.owner = owner;
    }
    @Override
    public int getNetworkId() {
    return NETWORK_ID;
    }
    @Override
    public float getWidth() {
    return 0.25f;
    }

    @Override
    public float getLength() {
    return 0.25f;
    }
    @Override
    public float getHeight() {
    return 0.25f;
    }

    Code:
    @Override
    public boolean onUpdate(int tick){
    
     double x = this.owner.x;
     double y = this.owner.y;
     double z = this.owner.z;
    
     this.yaw = 0;
     this.pitch = 0;
    
     this.motionX = x;
     this.motionY = y + 2;
     this.motionZ = z;
    
     return true;
    }

    }
    -----------------------
     
    Last edited: 14/11/16
  4. FSDC

    FSDC Пользователь

    Messages:
    2
    Likes Received:
    0
    are you trying to use it off of the official github
     
  5. Accasua

    Accasua Пользователь

    Messages:
    8
    Likes Received:
    0
    Minecraft:
    Accasia
    English is not my first language, So please tell me clearly.
     
  6. Accasua

    Accasua Пользователь

    Messages:
    8
    Likes Received:
    0
    Minecraft:
    Accasia
    i wrote new code, but it doesn't work

    package buff.BaseEntity;
    import buff.BuffCore;
    import cn.nukkit.Player;
    import cn.nukkit.entity.data.ByteEntityData;
    import cn.nukkit.entity.item.EntityItem;
    import cn.nukkit.item.Item;
    import cn.nukkit.level.format.FullChunk;
    import cn.nukkit.nbt.tag.CompoundTag;
    import cn.nukkit.network.protocol.AddEntityPacket;
    public class BuffItem extends EntityItem{

    public Player player;

    public BuffItem(FullChunk chunk, CompoundTag nbt, Player player, Item item) {
    super(chunk, nbt);
    this.item = item;
    this.player = player;
    }

    @Override
    public boolean onUpdate(int tickes){
    this.motionX = player.x;
    this.motionY = player.y + 2;
    this.motionZ = player.z;
    this.level = player.level;
    this.yaw = 0;
    this.pitch = 0;

    int time = BuffCore.getInstance().getListener().time.get(this.player);
    if(time < 1){
    this.kill();
    this.close();
    return false;
    }
    return true;
    }

    @Override
    public void spawnTo(Player player){
    AddEntityPacket pk = new AddEntityPacket();
    pk.entityRuntimeId = this.getId();
    pk.entityUniqueId = this.getId();
    pk.type = this.getNetworkId();
    pk.x = (float) this.x;
    pk.y = (float) this.y;
    pk.z = (float) this.z;
    pk.speedX = pk.speedY = pk.speedZ = 0;
    pk.yaw = (float) this.yaw;
    pk.pitch = (float) this.pitch;
    pk.metadata = this.dataProperties;
    this.setDataProperty(new ByteEntityData(DATA_FLAG_NO_AI, (byte) 1));
    player.dataPacket(pk);
    }
    }





    is it right?
    if right, how can i spawn this?
    if wrong, plz fix it :p
    sorry for my bad english, and thx!
     

Share This Page