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.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 {
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;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy