cn.nukkit.entity.EntityCreature Maven / Gradle / Ivy
package cn.nukkit.entity;
import cn.nukkit.Player;
import cn.nukkit.api.PowerNukkitDifference;
import cn.nukkit.api.PowerNukkitOnly;
import cn.nukkit.api.PowerNukkitXOnly;
import cn.nukkit.api.Since;
import cn.nukkit.item.Item;
import cn.nukkit.level.format.FullChunk;
import cn.nukkit.math.Vector3;
import cn.nukkit.nbt.tag.CompoundTag;
import javax.annotation.Nonnull;
/**
* @author MagicDroidX (Nukkit Project)
*/
@PowerNukkitDifference(since = "1.4.0.0-PN", info = "Implements EntityNameable only in PowerNukkit")
public abstract class EntityCreature extends EntityLiving implements EntityNameable, EntityAgeable {
public EntityCreature(FullChunk chunk, CompoundTag nbt) {
super(chunk, nbt);
}
// Armor stands, when implemented, should also check this.
@Override
public boolean onInteract(Player player, Item item, Vector3 clickedPos) {
if (item.getId() == Item.NAME_TAG && !player.isAdventure()) {
return applyNameTag(player, item);
}
return false;
}
@PowerNukkitOnly
@Since("1.4.0.0-PN")
@Override
public final boolean playerApplyNameTag(@Nonnull Player player, @Nonnull Item item) {
return applyNameTag(player, item);
}
// Structured like this so I can override nametags in player and dragon classes
// without overriding onInteract.
protected boolean applyNameTag(Player player, Item item) {
if (item.hasCustomName()) {
this.setNameTag(item.getCustomName());
this.setNameTagVisible(true);
if (!player.isCreative()) {
player.getInventory().removeItem(item);
}
// Set entity as persistent.
return true;
}
return false;
}
@Override
public boolean isBaby() {
return this.getDataFlag(DATA_FLAGS, Entity.DATA_FLAG_BABY);
}
@PowerNukkitXOnly
@Since("1.6.0.0-PNX")
public void setBaby(boolean flag) {
this.setDataFlag(DATA_FLAGS, Entity.DATA_FLAG_BABY, flag);
if (flag)
this.setScale(0.5f);
else
this.setScale(1f);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy