public function equals(Enchantment $ent) { if ($ent->getId() == $this->getId() and $ent->getLevel() == $this->getLevel() and $ent->getActivationType() == $this->getActivationType() and $ent->getRarity() == $this->getRarity()) { return true; } return false; }
/** * @param Enchantment $ench */ public function addEnchantment(Enchantment $ench) { if (!$this->hasCompoundTag()) { $tag = new Compound("", []); } else { $tag = $this->getNamedTag(); } if (!isset($tag->ench)) { $tag->ench = new Enum("ench", []); $tag->ench->setTagType(NBT::TAG_Compound); } $found = false; foreach ($tag->ench as $k => $entry) { if ($entry["id"] === $ench->getId()) { $tag->ench->{$k} = new Compound("", ["id" => new Short("id", $ench->getId()), "lvl" => new Short("lvl", $ench->getLevel())]); $found = true; break; } } if (!$found) { $tag->ench->{count($tag->ench) + 1} = new Compound("", ["id" => new Short("id", $ench->getId()), "lvl" => new Short("lvl", $ench->getLevel())]); } $this->setNamedTag($tag); }
/** * @param Enchantment $enchantment * @param Enchantment[] $enchantments * @return Enchantment[] */ public function removeConflictEnchantment(Enchantment $enchantment, array $enchantments) { foreach ($enchantments as $e) { $id = $e->getId(); if ($id == $enchantment->getId()) { unset($enchantments[$id]); continue; } if ($id >= 0 and $id <= 4 and $enchantment->getId() >= 0 and $enchantment->getId() <= 4) { //Protection unset($enchantments[$id]); continue; } if ($id >= 9 and $id <= 14 and $enchantment->getId() >= 9 and $enchantment->getId() <= 14) { //Weapon unset($enchantments[$id]); continue; } if ($id == Enchantment::TYPE_MINING_SILK_TOUCH and $enchantment->getId() == Enchantment::TYPE_MINING_FORTUNE or $id == Enchantment::TYPE_MINING_FORTUNE and $enchantment->getId() == Enchantment::TYPE_MINING_SILK_TOUCH) { //Protection unset($enchantments[$id]); continue; } } $result = []; foreach ($enchantments as $enchantment) { $result[] = $enchantment; } return $result; }