Help about Entity

Accasua

Пользователь
How I can make ItemEntity which floats around player?

I need some help

Sorry for my bad english. :p
 

Accasua

Пользователь
what do you mean by which floats around player
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;
}

@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:

FSDC

Пользователь
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;
}

@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;
}
}
-----------------------
are you trying to use it off of the official github
 

Accasua

Пользователь
are you trying to use it off of the official github
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!
 
Top