mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-12 00:39:45 +00:00
Merge branch 'release/3.1'
This commit is contained in:
commit
fc8dc8a497
@ -77,6 +77,8 @@ use pocketmine\inventory\transaction\InventoryTransaction;
|
|||||||
use pocketmine\inventory\transaction\TransactionValidationException;
|
use pocketmine\inventory\transaction\TransactionValidationException;
|
||||||
use pocketmine\item\Consumable;
|
use pocketmine\item\Consumable;
|
||||||
use pocketmine\item\Durable;
|
use pocketmine\item\Durable;
|
||||||
|
use pocketmine\item\enchantment\EnchantmentInstance;
|
||||||
|
use pocketmine\item\enchantment\MeleeWeaponEnchantment;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\item\WritableBook;
|
use pocketmine\item\WritableBook;
|
||||||
use pocketmine\item\WrittenBook;
|
use pocketmine\item\WrittenBook;
|
||||||
@ -2502,6 +2504,19 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
|||||||
}
|
}
|
||||||
|
|
||||||
$ev = new EntityDamageByEntityEvent($this, $target, EntityDamageEvent::CAUSE_ENTITY_ATTACK, $heldItem->getAttackPoints());
|
$ev = new EntityDamageByEntityEvent($this, $target, EntityDamageEvent::CAUSE_ENTITY_ATTACK, $heldItem->getAttackPoints());
|
||||||
|
|
||||||
|
$meleeEnchantmentDamage = 0;
|
||||||
|
/** @var EnchantmentInstance[] $meleeEnchantments */
|
||||||
|
$meleeEnchantments = [];
|
||||||
|
foreach($heldItem->getEnchantments() as $enchantment){
|
||||||
|
$type = $enchantment->getType();
|
||||||
|
if($type instanceof MeleeWeaponEnchantment and $type->isApplicableTo($target)){
|
||||||
|
$meleeEnchantmentDamage += $type->getDamageBonus($enchantment->getLevel());
|
||||||
|
$meleeEnchantments[] = $enchantment;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$ev->setModifier($meleeEnchantmentDamage, EntityDamageEvent::MODIFIER_WEAPON_ENCHANTMENTS);
|
||||||
|
|
||||||
if($cancelled){
|
if($cancelled){
|
||||||
$ev->setCancelled();
|
$ev->setCancelled();
|
||||||
}
|
}
|
||||||
@ -2529,6 +2544,12 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach($meleeEnchantments as $enchantment){
|
||||||
|
$type = $enchantment->getType();
|
||||||
|
assert($type instanceof MeleeWeaponEnchantment);
|
||||||
|
$type->onPostAttack($this, $target, $enchantment->getLevel());
|
||||||
|
}
|
||||||
|
|
||||||
if($this->isAlive()){
|
if($this->isAlive()){
|
||||||
//reactive damage like thorns might cause us to be killed by attacking another mob, which
|
//reactive damage like thorns might cause us to be killed by attacking another mob, which
|
||||||
//would mean we'd already have dropped the inventory by the time we reached here
|
//would mean we'd already have dropped the inventory by the time we reached here
|
||||||
|
@ -138,10 +138,11 @@ class Arrow extends Projectile{
|
|||||||
protected function onHitEntity(Entity $entityHit, RayTraceResult $hitResult) : void{
|
protected function onHitEntity(Entity $entityHit, RayTraceResult $hitResult) : void{
|
||||||
parent::onHitEntity($entityHit, $hitResult);
|
parent::onHitEntity($entityHit, $hitResult);
|
||||||
if($this->punchKnockback > 0){
|
if($this->punchKnockback > 0){
|
||||||
$mot = $entityHit->getMotion();
|
$horizontalSpeed = sqrt($this->motion->x ** 2 + $this->motion->z ** 2);
|
||||||
$multiplier = $this->punchKnockback * 0.6 / $mot->length();
|
if($horizontalSpeed > 0){
|
||||||
|
$multiplier = $this->punchKnockback * 0.6 / $horizontalSpeed;
|
||||||
$entityHit->setMotion($mot->add($mot->x * $multiplier, 0.1, $mot->z * $multiplier));
|
$entityHit->setMotion($entityHit->getMotion()->add($this->motion->x * $multiplier, 0.1, $this->motion->z * $multiplier));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,6 +38,7 @@ class EntityDamageEvent extends EntityEvent implements Cancellable{
|
|||||||
public const MODIFIER_ARMOR_ENCHANTMENTS = 6;
|
public const MODIFIER_ARMOR_ENCHANTMENTS = 6;
|
||||||
public const MODIFIER_CRITICAL = 7;
|
public const MODIFIER_CRITICAL = 7;
|
||||||
public const MODIFIER_TOTEM = 8;
|
public const MODIFIER_TOTEM = 8;
|
||||||
|
public const MODIFIER_WEAPON_ENCHANTMENTS = 9;
|
||||||
|
|
||||||
public const CAUSE_CONTACT = 0;
|
public const CAUSE_CONTACT = 0;
|
||||||
public const CAUSE_ENTITY_ATTACK = 1;
|
public const CAUSE_ENTITY_ATTACK = 1;
|
||||||
|
@ -117,6 +117,12 @@ class Enchantment{
|
|||||||
self::registerEnchantment(new Enchantment(self::THORNS, "%enchantment.thorns", self::RARITY_MYTHIC, self::SLOT_TORSO, self::SLOT_HEAD | self::SLOT_LEGS | self::SLOT_FEET, 3));
|
self::registerEnchantment(new Enchantment(self::THORNS, "%enchantment.thorns", self::RARITY_MYTHIC, self::SLOT_TORSO, self::SLOT_HEAD | self::SLOT_LEGS | self::SLOT_FEET, 3));
|
||||||
self::registerEnchantment(new Enchantment(self::RESPIRATION, "%enchantment.oxygen", self::RARITY_RARE, self::SLOT_HEAD, self::SLOT_NONE, 3));
|
self::registerEnchantment(new Enchantment(self::RESPIRATION, "%enchantment.oxygen", self::RARITY_RARE, self::SLOT_HEAD, self::SLOT_NONE, 3));
|
||||||
|
|
||||||
|
self::registerEnchantment(new SharpnessEnchantment(self::SHARPNESS, "%enchantment.damage.all", self::RARITY_COMMON, self::SLOT_SWORD, self::SLOT_AXE, 5));
|
||||||
|
//TODO: smite, bane of arthropods (these don't make sense now because their applicable mobs don't exist yet)
|
||||||
|
|
||||||
|
self::registerEnchantment(new KnockbackEnchantment(self::KNOCKBACK, "%enchantment.knockback", self::RARITY_UNCOMMON, self::SLOT_SWORD, self::SLOT_NONE, 2));
|
||||||
|
self::registerEnchantment(new FireAspectEnchantment(self::FIRE_ASPECT, "%enchantment.fire", self::RARITY_RARE, self::SLOT_SWORD, self::SLOT_NONE, 2));
|
||||||
|
|
||||||
self::registerEnchantment(new Enchantment(self::EFFICIENCY, "%enchantment.digging", self::RARITY_COMMON, self::SLOT_DIG, self::SLOT_SHEARS, 5));
|
self::registerEnchantment(new Enchantment(self::EFFICIENCY, "%enchantment.digging", self::RARITY_COMMON, self::SLOT_DIG, self::SLOT_SHEARS, 5));
|
||||||
self::registerEnchantment(new Enchantment(self::SILK_TOUCH, "%enchantment.untouching", self::RARITY_MYTHIC, self::SLOT_DIG, self::SLOT_SHEARS, 1));
|
self::registerEnchantment(new Enchantment(self::SILK_TOUCH, "%enchantment.untouching", self::RARITY_MYTHIC, self::SLOT_DIG, self::SLOT_SHEARS, 1));
|
||||||
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::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));
|
||||||
|
41
src/pocketmine/item/enchantment/FireAspectEnchantment.php
Normal file
41
src/pocketmine/item/enchantment/FireAspectEnchantment.php
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace pocketmine\item\enchantment;
|
||||||
|
|
||||||
|
use pocketmine\entity\Entity;
|
||||||
|
|
||||||
|
class FireAspectEnchantment extends MeleeWeaponEnchantment{
|
||||||
|
|
||||||
|
public function isApplicableTo(Entity $victim) : bool{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDamageBonus(int $enchantmentLevel) : float{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onPostAttack(Entity $attacker, Entity $victim, int $enchantmentLevel) : void{
|
||||||
|
$victim->setOnFire($enchantmentLevel * 4);
|
||||||
|
}
|
||||||
|
}
|
44
src/pocketmine/item/enchantment/KnockbackEnchantment.php
Normal file
44
src/pocketmine/item/enchantment/KnockbackEnchantment.php
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace pocketmine\item\enchantment;
|
||||||
|
|
||||||
|
use pocketmine\entity\Entity;
|
||||||
|
use pocketmine\entity\Living;
|
||||||
|
|
||||||
|
class KnockbackEnchantment extends MeleeWeaponEnchantment{
|
||||||
|
|
||||||
|
public function isApplicableTo(Entity $victim) : bool{
|
||||||
|
return $victim instanceof Living;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDamageBonus(int $enchantmentLevel) : float{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onPostAttack(Entity $attacker, Entity $victim, int $enchantmentLevel) : void{
|
||||||
|
if($victim instanceof Living){
|
||||||
|
$victim->knockBack($attacker, 0, $victim->x - $attacker->x, $victim->z - $attacker->z, $enchantmentLevel * 0.5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
63
src/pocketmine/item/enchantment/MeleeWeaponEnchantment.php
Normal file
63
src/pocketmine/item/enchantment/MeleeWeaponEnchantment.php
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace pocketmine\item\enchantment;
|
||||||
|
|
||||||
|
use pocketmine\entity\Entity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Classes extending this class can be applied to weapons and activate when used by a mob to attack another mob in melee
|
||||||
|
* combat.
|
||||||
|
*/
|
||||||
|
abstract class MeleeWeaponEnchantment extends Enchantment{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether this melee enchantment has an effect on the target entity. For example, Smite only applies to
|
||||||
|
* undead mobs.
|
||||||
|
*
|
||||||
|
* @param Entity $victim
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
abstract public function isApplicableTo(Entity $victim) : bool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the amount of additional damage caused by this enchantment to applicable targets.
|
||||||
|
*
|
||||||
|
* @param int $enchantmentLevel
|
||||||
|
*
|
||||||
|
* @return float
|
||||||
|
*/
|
||||||
|
abstract public function getDamageBonus(int $enchantmentLevel) : float;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called after damaging the entity to apply any post damage effects to the target.
|
||||||
|
*
|
||||||
|
* @param Entity $attacker
|
||||||
|
* @param Entity $victim
|
||||||
|
* @param int $enchantmentLevel
|
||||||
|
*/
|
||||||
|
public function onPostAttack(Entity $attacker, Entity $victim, int $enchantmentLevel) : void{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
37
src/pocketmine/item/enchantment/SharpnessEnchantment.php
Normal file
37
src/pocketmine/item/enchantment/SharpnessEnchantment.php
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace pocketmine\item\enchantment;
|
||||||
|
|
||||||
|
use pocketmine\entity\Entity;
|
||||||
|
|
||||||
|
class SharpnessEnchantment extends MeleeWeaponEnchantment{
|
||||||
|
|
||||||
|
public function isApplicableTo(Entity $victim) : bool{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDamageBonus(int $enchantmentLevel) : float{
|
||||||
|
return 0.5 * ($enchantmentLevel + 1);
|
||||||
|
}
|
||||||
|
}
|
@ -84,6 +84,9 @@ class RCONInstance extends Thread{
|
|||||||
if($this->stop){
|
if($this->stop){
|
||||||
return false;
|
return false;
|
||||||
}elseif($d === false){
|
}elseif($d === false){
|
||||||
|
if(socket_last_error($client) === SOCKET_ECONNRESET){ //client crashed, terminate connection
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}elseif($d === "" or strlen($d) < 4){
|
}elseif($d === "" or strlen($d) < 4){
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user