cn.nukkit.item.ItemArmor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of powernukkit Show documentation
Show all versions of powernukkit Show documentation
A Minecraft Bedrock Edition server software implementation made in Java from scratch which supports all new features.
package cn.nukkit.item;
import cn.nukkit.Player;
import cn.nukkit.api.DeprecationDetails;
import cn.nukkit.api.PowerNukkitDifference;
import cn.nukkit.api.Since;
import cn.nukkit.level.Sound;
import cn.nukkit.math.Vector3;
import cn.nukkit.nbt.tag.ByteTag;
import cn.nukkit.nbt.tag.Tag;
/**
* @author MagicDroidX (Nukkit Project)
*/
abstract public class ItemArmor extends Item implements ItemDurable {
public static final int TIER_LEATHER = 1;
public static final int TIER_IRON = 2;
public static final int TIER_CHAIN = 3;
public static final int TIER_GOLD = 4;
public static final int TIER_DIAMOND = 5;
@Since("1.3.2.0-PN") public static final int TIER_NETHERITE = 6;
@Deprecated
@DeprecationDetails(since = "1.3.2.0-PN",
reason = "The value of this 'constant' is unstable, it may change if new tiers gets added. Refrain from using it. " +
"Changes in this value will not be considered as an API breaking change and will not affect code that " +
"is already compiled."
)
public static final int TIER_OTHER = 7;
public ItemArmor(int id) {
super(id);
}
public ItemArmor(int id, Integer meta) {
super(id, meta);
}
public ItemArmor(int id, Integer meta, int count) {
super(id, meta, count);
}
public ItemArmor(int id, Integer meta, int count, String name) {
super(id, meta, count, name);
}
@Override
public int getMaxStackSize() {
return 1;
}
@Override
public boolean isArmor() {
return true;
}
@PowerNukkitDifference(info = "Using new method to play sounds", since = "1.4.0.0-PN")
@Override
public boolean onClickAir(Player player, Vector3 directionVector) {
boolean equip = false;
if (this.isHelmet() && player.getInventory().getHelmet().isNull()) {
if (player.getInventory().setHelmet(this)) {
equip = true;
}
} else if (this.isChestplate() && player.getInventory().getChestplate().isNull()) {
if (player.getInventory().setChestplate(this)) {
equip = true;
}
} else if (this.isLeggings() && player.getInventory().getLeggings().isNull()) {
if (player.getInventory().setLeggings(this)) {
equip = true;
}
} else if (this.isBoots() && player.getInventory().getBoots().isNull()) {
if (player.getInventory().setBoots(this)) {
equip = true;
}
}
if (equip) {
player.getInventory().clear(player.getInventory().getHeldItemIndex());
switch (this.getTier()) {
case TIER_CHAIN:
player.getLevel().addSound(player, Sound.ARMOR_EQUIP_CHAIN);
break;
case TIER_DIAMOND:
player.getLevel().addSound(player, Sound.ARMOR_EQUIP_DIAMOND);
break;
case TIER_GOLD:
player.getLevel().addSound(player, Sound.ARMOR_EQUIP_GOLD);
break;
case TIER_IRON:
player.getLevel().addSound(player, Sound.ARMOR_EQUIP_IRON);
break;
case TIER_LEATHER:
player.getLevel().addSound(player, Sound.ARMOR_EQUIP_LEATHER);
break;
case TIER_NETHERITE:
player.getLevel().addSound(player, Sound.ARMOR_EQUIP_NETHERITE);
break;
case TIER_OTHER:
default:
player.getLevel().addSound(player, Sound.ARMOR_EQUIP_GENERIC);
}
}
return this.getCount() == 0;
}
@Override
public int getEnchantAbility() {
switch (this.getTier()) {
case TIER_CHAIN:
return 12;
case TIER_LEATHER:
case TIER_NETHERITE:
return 15;
case TIER_DIAMOND:
return 10;
case TIER_GOLD:
return 25;
case TIER_IRON:
return 9;
}
return 0;
}
@Override
public boolean isUnbreakable() {
Tag tag = this.getNamedTagEntry("Unbreakable");
return tag instanceof ByteTag && ((ByteTag) tag).data > 0;
}
}