mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-07 12:18:46 +00:00
Implemented Punch enchantment
This commit is contained in:
parent
85a3c0e7dc
commit
97c267c70c
@ -31,6 +31,7 @@ use pocketmine\item\Item;
|
||||
use pocketmine\item\ItemFactory;
|
||||
use pocketmine\level\Level;
|
||||
use pocketmine\math\RayTraceResult;
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\nbt\tag\CompoundTag;
|
||||
use pocketmine\network\mcpe\protocol\EntityEventPacket;
|
||||
use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
|
||||
@ -58,6 +59,9 @@ class Arrow extends Projectile{
|
||||
/** @var int */
|
||||
protected $pickupMode = self::PICKUP_ANY;
|
||||
|
||||
/** @var float */
|
||||
protected $punchKnockback = 0.0;
|
||||
|
||||
public function __construct(Level $level, CompoundTag $nbt, ?Entity $shootingEntity = null, bool $critical = false){
|
||||
parent::__construct($level, $nbt, $shootingEntity);
|
||||
$this->setCritical($critical);
|
||||
@ -92,6 +96,20 @@ class Arrow extends Projectile{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function getPunchKnockback() : float{
|
||||
return $this->punchKnockback;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $punchKnockback
|
||||
*/
|
||||
public function setPunchKnockback(float $punchKnockback) : void{
|
||||
$this->punchKnockback = $punchKnockback;
|
||||
}
|
||||
|
||||
public function entityBaseTick(int $tickDiff = 1) : bool{
|
||||
if($this->closed){
|
||||
return false;
|
||||
@ -117,6 +135,16 @@ class Arrow extends Projectile{
|
||||
$this->broadcastEntityEvent(EntityEventPacket::ARROW_SHAKE, 7); //7 ticks
|
||||
}
|
||||
|
||||
protected function onHitEntity(Entity $entityHit, RayTraceResult $hitResult) : void{
|
||||
parent::onHitEntity($entityHit, $hitResult);
|
||||
if($this->punchKnockback > 0){
|
||||
$mot = $entityHit->getMotion();
|
||||
$multiplier = $this->punchKnockback * 0.6 / $mot->length();
|
||||
|
||||
$entityHit->setMotion($mot->add($mot->x * $multiplier, 0.1, $mot->z * $multiplier));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
|
@ -67,9 +67,14 @@ class Bow extends Tool{
|
||||
$entity = Entity::createEntity("Arrow", $player->getLevel(), $nbt, $player, $force == 2);
|
||||
if($entity instanceof Projectile){
|
||||
$infinity = $this->hasEnchantment(Enchantment::INFINITY);
|
||||
if($infinity and $entity instanceof ArrowEntity){
|
||||
if($entity instanceof ArrowEntity){
|
||||
if($infinity){
|
||||
$entity->setPickupMode(ArrowEntity::PICKUP_CREATIVE);
|
||||
}
|
||||
if(($punchLevel = $this->getEnchantmentLevel(Enchantment::PUNCH)) > 0){
|
||||
$entity->setPunchKnockback($punchLevel);
|
||||
}
|
||||
}
|
||||
if(($powerLevel = $this->getEnchantmentLevel(Enchantment::POWER)) > 0){
|
||||
$entity->setBaseDamage($entity->getBaseDamage() + (($powerLevel + 1) / 2));
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ class Enchantment{
|
||||
self::registerEnchantment(new Enchantment(self::UNBREAKING, "%enchantment.durability", self::RARITY_UNCOMMON, self::SLOT_DIG | self::SLOT_ARMOR | self::SLOT_FISHING_ROD | self::SLOT_BOW, self::SLOT_TOOL | self::SLOT_CARROT_STICK | self::SLOT_ELYTRA, 3));
|
||||
|
||||
self::registerEnchantment(new Enchantment(self::POWER, "%enchantment.arrowDamage", self::RARITY_COMMON, self::SLOT_BOW, self::SLOT_NONE, 5));
|
||||
|
||||
self::registerEnchantment(new Enchantment(self::PUNCH, "%enchantment.arrowKnockback", self::RARITY_RARE, self::SLOT_BOW, self::SLOT_NONE, 2));
|
||||
self::registerEnchantment(new Enchantment(self::FLAME, "%enchantment.arrowFire", self::RARITY_RARE, self::SLOT_BOW, self::SLOT_NONE, 1));
|
||||
self::registerEnchantment(new Enchantment(self::INFINITY, "%enchantment.arrowInfinite", self::RARITY_MYTHIC, self::SLOT_BOW, self::SLOT_NONE, 1));
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user