diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index ecbe50be3..4245037c2 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -69,6 +69,7 @@ use pocketmine\inventory\InventoryHolder; use pocketmine\inventory\PlayerInventory; use pocketmine\inventory\SimpleTransactionGroup; use pocketmine\inventory\StonecutterShapelessRecipe; +use pocketmine\item\Armor; use pocketmine\item\Item; use pocketmine\level\format\FullChunk; use pocketmine\level\format\LevelProvider; @@ -217,6 +218,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ public function setBanned($value){ if($value === true){ $this->server->getNameBans()->addBan($this->getName(), null, null, null); + $this->kick("You have been banned"); }else{ $this->server->getNameBans()->remove($this->getName()); } @@ -1250,7 +1252,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $this->entityBaseTick(1); - if(!$this->forceMovement and $this->speed and $this->isSurvival()){ + if($this->forceMovement === null and $this->speed and $this->isSurvival()){ $speed = sqrt($this->speed->x ** 2 + $this->speed->z ** 2); if($speed > 0.45){ $this->highSpeedTicks += $speed > 3 ? 2 : 1; @@ -1280,10 +1282,8 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ if(!$this->hasEffect(Effect::JUMP) and $diff > 0.6 and $expectedVelocity < $this->speed->y and !$this->server->getAllowFlight()){ if($this->inAirTicks < 100){ $this->setMotion(new Vector3(0, $expectedVelocity, 0)); - }else{ - if($this->kick("Flying is not enabled on this server")){ - return false; - } + }elseif($this->kick("Flying is not enabled on this server")){ + return false; } } } @@ -1975,6 +1975,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ EntityDamageEvent::MODIFIER_BASE => isset($damageTable[$item->getId()]) ? $damageTable[$item->getId()] : 1, ]; + $points = 0; if($this->distance($target) > 8){ $cancelled = true; }elseif($target instanceof Player){ @@ -1984,34 +1985,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $cancelled = true; } - $armorValues = [ - Item::LEATHER_CAP => 1, - Item::LEATHER_TUNIC => 3, - Item::LEATHER_PANTS => 2, - Item::LEATHER_BOOTS => 1, - Item::CHAIN_HELMET => 1, - Item::CHAIN_CHESTPLATE => 5, - Item::CHAIN_LEGGINGS => 4, - Item::CHAIN_BOOTS => 1, - Item::GOLD_HELMET => 1, - Item::GOLD_CHESTPLATE => 5, - Item::GOLD_LEGGINGS => 3, - Item::GOLD_BOOTS => 1, - Item::IRON_HELMET => 2, - Item::IRON_CHESTPLATE => 6, - Item::IRON_LEGGINGS => 5, - Item::IRON_BOOTS => 2, - Item::DIAMOND_HELMET => 3, - Item::DIAMOND_CHESTPLATE => 8, - Item::DIAMOND_LEGGINGS => 6, - Item::DIAMOND_BOOTS => 3, - ]; - $points = 0; - foreach($target->getInventory()->getArmorContents() as $index => $i){ - if(isset($armorValues[$i->getId()])){ - $points += $armorValues[$i->getId()]; - } - } + $points = $target->getInventory()->getArmorPoints(); $damage[EntityDamageEvent::MODIFIER_ARMOR] = -floor($damage[EntityDamageEvent::MODIFIER_BASE] * $points * 0.04); } @@ -2039,7 +2013,6 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ } } - break; case ProtocolInfo::ANIMATE_PACKET: if($this->spawned === false or $this->dead === true){ @@ -2633,6 +2606,10 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ if($ev->getDeathMessage() != ""){ $this->server->broadcast($ev->getDeathMessage(), Server::BROADCAST_CHANNEL_USERS); } + + if($this->server->isHardcore()){ + $this->setBanned(true); + } } public function setHealth($amount){ @@ -2671,8 +2648,24 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ parent::attack($damage, $source); - if($source instanceof EntityDamageEvent and $source->isCancelled()){ - return; + if($source instanceof EntityDamageEvent){ + if($source->isCancelled()){ + return; + } + if($source->getDamage(EntityDamageEvent::MODIFIER_ARMOR) > 0){ + for($i = 0; $i < 4; $i++){ + $piece = $this->getInventory()->getArmorItem($i); + if($piece instanceof Armor){ + $damage = $piece->getDamage(); + if($damage >= $piece->getMaxDurability()){ + $this->getInventory()->setArmorItem($i, Item::get(Item::AIR)); + }else{ + $piece->setDamage($damage + 1); + $this->getInventory()->setArmorItem($i, $piece); + } + } + } + } } if($this->getLastDamageCause() === $source){ @@ -2681,6 +2674,8 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $pk->event = 2; $this->dataPacket($pk); } + + } public function teleport(Vector3 $pos, $yaw = null, $pitch = null){ diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index abc1301bf..2c98e21f8 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -1142,10 +1142,11 @@ class Server{ $seed = $seed === null ? Binary::readInt(@Utils::getRandomBytes(4, false)) : (int) $seed; - if($generator !== null and class_exists($generator) and is_subclass_of($generator, Generator::class)){ - $generator = new $generator($options); - }else{ + if(!isset($options["presey"])){ $options["preset"] = $this->getConfigString("generator-settings", ""); + } + + if(!($generator !== null and class_exists($generator, true) and is_subclass_of($generator, Generator::class))){ $generator = Generator::getGenerator($this->getLevelType()); } diff --git a/src/pocketmine/block/Cactus.php b/src/pocketmine/block/Cactus.php index 54dec6193..2f8426eda 100644 --- a/src/pocketmine/block/Cactus.php +++ b/src/pocketmine/block/Cactus.php @@ -2,11 +2,11 @@ /* * - * ____ _ _ __ __ _ __ __ ____ - * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ + * ____ _ _ __ __ _ __ __ ____ + * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) | - * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ - * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| + * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ + * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| * * 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 @@ -15,7 +15,7 @@ * * @author PocketMine Team * @link http://www.pocketmine.net/ - * + * * */ @@ -25,6 +25,8 @@ use pocketmine\entity\Entity; use pocketmine\event\block\BlockGrowEvent; use pocketmine\event\entity\EntityDamageByBlockEvent; use pocketmine\event\entity\EntityDamageEvent; +use pocketmine\inventory\InventoryHolder; +use pocketmine\inventory\PlayerInventory; use pocketmine\item\Item; use pocketmine\level\Level; use pocketmine\math\AxisAlignedBB; @@ -65,7 +67,14 @@ class Cactus extends Transparent{ } public function onEntityCollide(Entity $entity){ - $ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_CONTACT, 1); + $damage = [EntityDamageEvent::MODIFIER_BASE => 1]; + if($entity instanceof InventoryHolder){ + $inventory = $entity->getInventory(); + if($inventory instanceof PlayerInventory){ + $damage[EntityDamageEvent::MODIFIER_ARMOR] = $inventory->getArmorPoints(); + } + } + $ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_CONTACT, $damage); $entity->attack($ev->getFinalDamage(), $ev); } @@ -128,4 +137,4 @@ class Cactus extends Transparent{ [$this->id, 0, 1], ]; } -} \ No newline at end of file +} diff --git a/src/pocketmine/block/Fire.php b/src/pocketmine/block/Fire.php index 28eb20635..89767345c 100644 --- a/src/pocketmine/block/Fire.php +++ b/src/pocketmine/block/Fire.php @@ -2,11 +2,11 @@ /* * - * ____ _ _ __ __ _ __ __ ____ - * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ + * ____ _ _ __ __ _ __ __ ____ + * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) | - * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ - * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| + * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ + * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| * * 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 @@ -15,7 +15,7 @@ * * @author PocketMine Team * @link http://www.pocketmine.net/ - * + * * */ @@ -25,6 +25,8 @@ use pocketmine\entity\Entity; use pocketmine\event\entity\EntityCombustByBlockEvent; use pocketmine\event\entity\EntityDamageByBlockEvent; use pocketmine\event\entity\EntityDamageEvent; +use pocketmine\inventory\InventoryHolder; +use pocketmine\inventory\PlayerInventory; use pocketmine\item\Item; use pocketmine\level\Level; use pocketmine\Server; @@ -58,7 +60,14 @@ class Fire extends Flowable{ } public function onEntityCollide(Entity $entity){ - $ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_FIRE, 1); + $damage = [EntityDamageEvent::MODIFIER_BASE => 1]; + if($entity instanceof InventoryHolder){ + $inventory = $entity->getInventory(); + if($inventory instanceof PlayerInventory){ + $damage[EntityDamageEvent::MODIFIER_ARMOR] = $inventory->getArmorPoints(); + } + } + $ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_FIRE, $damage); $entity->attack($ev->getFinalDamage(), $ev); $ev = new EntityCombustByBlockEvent($this, $entity, 8); @@ -94,4 +103,4 @@ class Fire extends Flowable{ return false; } -} \ No newline at end of file +} diff --git a/src/pocketmine/block/IronBars.php b/src/pocketmine/block/IronBars.php index ad75b5d3a..7458ed582 100644 --- a/src/pocketmine/block/IronBars.php +++ b/src/pocketmine/block/IronBars.php @@ -21,6 +21,7 @@ namespace pocketmine\block; +use pocketmine\item\Item; class IronBars extends Thin{ @@ -33,5 +34,36 @@ class IronBars extends Thin{ public function getName(){ return "Iron Bars"; } + public function getHardness(){ + return 5; + } + + public function getBreakTime(Item $item){ + switch($item->isPickaxe()){ + case 5: + return 0.95; + case 4: + return 1.25; + case 3: + return 1.9; + case 2: + return 0.65; + case 1: + return 3.75; + default: + return 5; + } + } + + public function getDrops(Item $item){ + if($item->isPickaxe() >= 1){ + return [ + [Item::IRON_BARS, 0, 1], + ]; + }else{ + return []; + } + } + +} -} \ No newline at end of file diff --git a/src/pocketmine/block/Lava.php b/src/pocketmine/block/Lava.php index 37faaa1fa..3ca20e864 100644 --- a/src/pocketmine/block/Lava.php +++ b/src/pocketmine/block/Lava.php @@ -2,11 +2,11 @@ /* * - * ____ _ _ __ __ _ __ __ ____ - * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ + * ____ _ _ __ __ _ __ __ ____ + * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) | - * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ - * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| + * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ + * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| * * 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 @@ -15,7 +15,7 @@ * * @author PocketMine Team * @link http://www.pocketmine.net/ - * + * * */ @@ -25,6 +25,8 @@ use pocketmine\entity\Entity; use pocketmine\event\entity\EntityCombustByBlockEvent; use pocketmine\event\entity\EntityDamageByBlockEvent; use pocketmine\event\entity\EntityDamageEvent; +use pocketmine\inventory\InventoryHolder; +use pocketmine\inventory\PlayerInventory; use pocketmine\item\Item; use pocketmine\Player; use pocketmine\Server; @@ -51,8 +53,15 @@ class Lava extends Liquid{ public function onEntityCollide(Entity $entity){ $entity->fallDistance *= 0.5; + $damage = [EntityDamageEvent::MODIFIER_BASE => 1]; + if($entity instanceof InventoryHolder){ + $inventory = $entity->getInventory(); + if($inventory instanceof PlayerInventory){ + $damage[EntityDamageEvent::MODIFIER_ARMOR] = $inventory->getArmorPoints(); + } + } if(!$entity->hasEffect(Effect::FIRE_RESISTANCE)){ - $ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_LAVA, 4); + $ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_LAVA, $damage); $entity->attack($ev->getFinalDamage(), $ev); } diff --git a/src/pocketmine/block/Stonecutter.php b/src/pocketmine/block/Stonecutter.php index 6a8d7985d..fa9f28fde 100644 --- a/src/pocketmine/block/Stonecutter.php +++ b/src/pocketmine/block/Stonecutter.php @@ -50,8 +50,12 @@ class Stonecutter extends Solid{ } public function getDrops(Item $item){ - return [ - [$this->id, 0, 1], - ]; + if($item->isPickaxe() >= 1){ + return [ + [Item::STONECUTTER, 0, 1], + ]; + }else{ + return []; + } } } \ No newline at end of file diff --git a/src/pocketmine/block/TallGrass.php b/src/pocketmine/block/TallGrass.php index faa483f80..bce7fef36 100644 --- a/src/pocketmine/block/TallGrass.php +++ b/src/pocketmine/block/TallGrass.php @@ -23,6 +23,7 @@ namespace pocketmine\block; use pocketmine\item\Item; use pocketmine\level\Level; +use pocketmine\Player; class TallGrass extends Flowable{ @@ -45,6 +46,17 @@ class TallGrass extends Flowable{ ]; return $names[$this->meta & 0x03]; } + + public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ + $down = $this->getSide(0); + if($down->getId() === self::GRASS){ + $this->getLevel()->setBlock($block, $this, true); + + return true; + } + + return false; + } public function onUpdate($type){ @@ -67,4 +79,4 @@ class TallGrass extends Flowable{ return []; } -} \ No newline at end of file +} diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 7734a870e..5d83423b4 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -2,11 +2,11 @@ /* * - * ____ _ _ __ __ _ __ __ ____ - * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ + * ____ _ _ __ __ _ __ __ ____ + * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) | - * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ - * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| + * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ + * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| * * 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 @@ -15,7 +15,7 @@ * * @author PocketMine Team * @link http://www.pocketmine.net/ - * + * * */ @@ -33,6 +33,8 @@ use pocketmine\event\entity\EntityRegainHealthEvent; use pocketmine\event\entity\EntitySpawnEvent; use pocketmine\event\entity\EntityTeleportEvent; use pocketmine\event\Timings; +use pocketmine\inventory\InventoryHolder; +use pocketmine\inventory\PlayerInventory; use pocketmine\level\format\Chunk; use pocketmine\level\format\FullChunk; use pocketmine\level\Level; @@ -867,6 +869,13 @@ abstract class Entity extends Location implements Metadatable{ public function fall($fallDistance){ $damage = floor($fallDistance - 3); if($damage > 0){ + $damage = [EntityDamageEvent::MODIFIER_BASE => $damage]; + if($this instanceof InventoryHolder){ + $inventory = $this->getInventory(); + if($inventory instanceof PlayerInventory){ + $damage[EntityDamageEvent::MODIFIER_ARMOR] = $inventory->getArmorPoints(); + } + } $ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_FALL, $damage); $this->attack($ev->getFinalDamage(), $ev); } diff --git a/src/pocketmine/entity/Living.php b/src/pocketmine/entity/Living.php index ac2413372..a876b4dc1 100644 --- a/src/pocketmine/entity/Living.php +++ b/src/pocketmine/entity/Living.php @@ -2,11 +2,11 @@ /* * - * ____ _ _ __ __ _ __ __ ____ - * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ + * ____ _ _ __ __ _ __ __ ____ + * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) | - * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ - * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| + * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ + * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| * * 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 @@ -15,7 +15,7 @@ * * @author PocketMine Team * @link http://www.pocketmine.net/ - * + * * */ @@ -28,6 +28,8 @@ use pocketmine\event\entity\EntityDamageEvent; use pocketmine\event\entity\EntityDeathEvent; use pocketmine\event\entity\EntityRegainHealthEvent; use pocketmine\event\Timings; +use pocketmine\inventory\InventoryHolder; +use pocketmine\inventory\PlayerInventory; use pocketmine\item\Item as ItemItem; use pocketmine\math\Vector3; use pocketmine\nbt\tag\Short; @@ -176,7 +178,14 @@ abstract class Living extends Entity implements Damageable{ if($this->dead !== true and $this->isInsideOfSolid()){ $hasUpdate = true; - $ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_SUFFOCATION, 1); + $damage = [EntityDamageEvent::MODIFIER_BASE => 1]; + if($this instanceof InventoryHolder){ + $inventory = $this->getInventory(); + if($inventory instanceof PlayerInventory){ + $damage[EntityDamageEvent::MODIFIER_ARMOR] = $inventory; + } + } + $ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_SUFFOCATION, $damage); $this->attack($ev->getFinalDamage(), $ev); } @@ -186,7 +195,14 @@ abstract class Living extends Entity implements Damageable{ if($airTicks <= -20){ $airTicks = 0; - $ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_DROWNING, 2); + $damage = [EntityDamageEvent::MODIFIER_BASE => 2]; + if($this instanceof InventoryHolder){ + $inventory = $this->getInventory(); + if($inventory instanceof PlayerInventory){ + $damage[EntityDamageEvent::MODIFIER_ARMOR] = $inventory->getArmorPoints(); + } + } + $ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_DROWNING, $damage); $this->attack($ev->getFinalDamage(), $ev); } $this->setDataProperty(self::DATA_AIR, self::DATA_TYPE_SHORT, $airTicks); diff --git a/src/pocketmine/entity/Projectile.php b/src/pocketmine/entity/Projectile.php index 7c7547767..926f7dc6a 100644 --- a/src/pocketmine/entity/Projectile.php +++ b/src/pocketmine/entity/Projectile.php @@ -2,11 +2,11 @@ /* * - * ____ _ _ __ __ _ __ __ ____ - * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ + * ____ _ _ __ __ _ __ __ ____ + * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) | - * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ - * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| + * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ + * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| * * 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 @@ -15,7 +15,7 @@ * * @author PocketMine Team * @link http://www.pocketmine.net/ - * + * * */ @@ -24,10 +24,11 @@ namespace pocketmine\entity; use pocketmine\event\entity\EntityCombustByEntityEvent; use pocketmine\event\entity\EntityDamageByChildEntityEvent; -use pocketmine\event\entity\EntityDamageByEntityEvent; use pocketmine\event\entity\EntityDamageEvent; use pocketmine\event\entity\EntityRegainHealthEvent; use pocketmine\event\entity\ProjectileHitEvent; +use pocketmine\inventory\InventoryHolder; +use pocketmine\inventory\PlayerInventory; use pocketmine\level\MovingObjectPosition; use pocketmine\math\Vector3; use pocketmine\nbt\tag\Short; @@ -127,15 +128,22 @@ abstract class Projectile extends Entity{ $this->server->getPluginManager()->callEvent(new ProjectileHitEvent($this)); $motion = sqrt($this->motionX ** 2 + $this->motionY ** 2 + $this->motionZ ** 2); - $damage = ceil($motion * $this->damage); - - if($this->shootingEntity === null){ - $ev = new EntityDamageByEntityEvent($this, $movingObjectPosition->entityHit, EntityDamageEvent::CAUSE_PROJECTILE, $damage); - }else{ - $ev = new EntityDamageByChildEntityEvent($this->shootingEntity, $this, $movingObjectPosition->entityHit, EntityDamageEvent::CAUSE_PROJECTILE, $damage); + $damage = [EntityDamageEvent::MODIFIER_BASE => ceil($motion * $this->damage)]; + $hit = $movingObjectPosition->entityHit; + if($hit instanceof InventoryHolder){ + $inventory = $hit->getInventory(); + if($inventory instanceof PlayerInventory){ + $damage[EntityDamageEvent::MODIFIER_ARMOR] = $inventory->getArmorPoints(); + } } - $movingObjectPosition->entityHit->attack($ev->getFinalDamage(), $ev); + if($this->shootingEntity === null){ + $ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_PROJECTILE, $damage); + }else{ + $ev = new EntityDamageByChildEntityEvent($this->shootingEntity, $this, $hit, EntityDamageEvent::CAUSE_PROJECTILE, $damage); + } + + $hit->attack($ev->getFinalDamage(), $ev); if($this->fireTicks > 0){ @@ -179,4 +187,4 @@ abstract class Projectile extends Entity{ return $hasUpdate; } -} \ No newline at end of file +} diff --git a/src/pocketmine/event/entity/EntityDamageByBlockEvent.php b/src/pocketmine/event/entity/EntityDamageByBlockEvent.php index bb4075d76..acb3c3175 100644 --- a/src/pocketmine/event/entity/EntityDamageByBlockEvent.php +++ b/src/pocketmine/event/entity/EntityDamageByBlockEvent.php @@ -49,4 +49,4 @@ class EntityDamageByBlockEvent extends EntityDamageEvent{ } -} \ No newline at end of file +} diff --git a/src/pocketmine/inventory/BaseInventory.php b/src/pocketmine/inventory/BaseInventory.php index 5025fd5b7..b0df84533 100644 --- a/src/pocketmine/inventory/BaseInventory.php +++ b/src/pocketmine/inventory/BaseInventory.php @@ -115,7 +115,9 @@ abstract class BaseInventory implements Inventory{ $this->clear($i); } }else{ - $this->setItem($i, $items[$i]); + if (!$this->setItem($i, $items[$i])){ + $this->clear($i); + } } } } diff --git a/src/pocketmine/inventory/DoubleChestInventory.php b/src/pocketmine/inventory/DoubleChestInventory.php index 5d6bef991..2c87ca503 100644 --- a/src/pocketmine/inventory/DoubleChestInventory.php +++ b/src/pocketmine/inventory/DoubleChestInventory.php @@ -37,7 +37,8 @@ class DoubleChestInventory extends ChestInventory implements InventoryHolder{ public function __construct(Chest $left, Chest $right){ $this->left = $left->getRealInventory(); $this->right = $right->getRealInventory(); - BaseInventory::__construct($this, InventoryType::get(InventoryType::DOUBLE_CHEST)); + $items = array_merge($this->left->getContents(), $this->right->getContents()); + BaseInventory::__construct($this, InventoryType::get(InventoryType::DOUBLE_CHEST), $items); } public function getInventory(){ @@ -77,13 +78,19 @@ class DoubleChestInventory extends ChestInventory implements InventoryHolder{ $items = array_slice($items, 0, $this->size, true); } - parent::setContents($items); - $leftItems = array_slice($items, 0, $this->left->getSize(), true); - $this->left->setContents($leftItems); - if(count($items) > $this->left->getSize()){ - $rightItems = array_slice($items, $this->left->getSize() - 1, $this->right->getSize(), true); - $this->right->setContents($rightItems); + for($i = 0; $i < $this->size; ++$i){ + if(!isset($items[$i])){ + if ($i < $this->left->size){ + if(isset($this->left->slots[$i])){ + $this->clear($i); + } + }elseif(isset($this->right->slots[$i - $this->left->size])){ + $this->clear($i); + } + }elseif(!$this->setItem($i, $items[$i])){ + $this->clear($i); + } } } diff --git a/src/pocketmine/inventory/PlayerInventory.php b/src/pocketmine/inventory/PlayerInventory.php index 913ff2fd6..4524853e2 100644 --- a/src/pocketmine/inventory/PlayerInventory.php +++ b/src/pocketmine/inventory/PlayerInventory.php @@ -25,6 +25,7 @@ use pocketmine\entity\Human; use pocketmine\event\entity\EntityArmorChangeEvent; use pocketmine\event\entity\EntityInventoryChangeEvent; use pocketmine\event\player\PlayerItemHeldEvent; +use pocketmine\item\Armor; use pocketmine\item\Item; use pocketmine\network\protocol\ContainerSetContentPacket; use pocketmine\network\protocol\ContainerSetSlotPacket; @@ -297,6 +298,15 @@ class PlayerInventory extends BaseInventory{ return $armor; } + public function getArmorPoints(){ + $points = 0; + foreach($this->getArmorContents() as $i){ + if($i instanceof Armor){ + $points += $i->getArmorPoints(); + } + } + return $points; + } public function clearAll(){ $limit = $this->getSize() + 4; for($index = 0; $index < $limit; ++$index){ diff --git a/src/pocketmine/item/Armor.php b/src/pocketmine/item/Armor.php index af5264fbf..e11fbe219 100644 --- a/src/pocketmine/item/Armor.php +++ b/src/pocketmine/item/Armor.php @@ -27,4 +27,8 @@ abstract class Armor extends Item{ public function getMaxStackSize(){ return 1; } -} \ No newline at end of file + /** + * @return int + */ + public abstract function getArmorPoints(); +} diff --git a/src/pocketmine/item/ChainBoots.php b/src/pocketmine/item/ChainBoots.php index bd5cc6a2b..eca96ca5d 100644 --- a/src/pocketmine/item/ChainBoots.php +++ b/src/pocketmine/item/ChainBoots.php @@ -2,11 +2,11 @@ /* * - * ____ _ _ __ __ _ __ __ ____ - * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ + * ____ _ _ __ __ _ __ __ ____ + * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) | - * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ - * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| + * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ + * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| * * 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 @@ -15,7 +15,7 @@ * * @author PocketMine Team * @link http://www.pocketmine.net/ - * + * * */ @@ -26,4 +26,10 @@ class ChainBoots extends Armor{ public function __construct($meta = 0, $count = 1){ parent::__construct(self::CHAIN_BOOTS, $meta, $count, "Chainmail Boots"); } -} \ No newline at end of file + public function getArmorPoints(){ + return 1; + } + public function getMaxDurability(){ + return 196; + } +} diff --git a/src/pocketmine/item/ChainChestplate.php b/src/pocketmine/item/ChainChestplate.php index 6037ef957..20668e180 100644 --- a/src/pocketmine/item/ChainChestplate.php +++ b/src/pocketmine/item/ChainChestplate.php @@ -2,11 +2,11 @@ /* * - * ____ _ _ __ __ _ __ __ ____ - * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ + * ____ _ _ __ __ _ __ __ ____ + * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) | - * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ - * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| + * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ + * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| * * 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 @@ -15,7 +15,7 @@ * * @author PocketMine Team * @link http://www.pocketmine.net/ - * + * * */ @@ -26,4 +26,10 @@ class ChainChestplate extends Armor{ public function __construct($meta = 0, $count = 1){ parent::__construct(self::CHAIN_CHESTPLATE, $meta, $count, "Chain Chestplate"); } -} \ No newline at end of file + public function getArmorPoints(){ + return 5; + } + public function getMaxDurability(){ + return 241; + } +} diff --git a/src/pocketmine/item/ChainHelmet.php b/src/pocketmine/item/ChainHelmet.php index 3455ab088..36f8898a4 100644 --- a/src/pocketmine/item/ChainHelmet.php +++ b/src/pocketmine/item/ChainHelmet.php @@ -2,11 +2,11 @@ /* * - * ____ _ _ __ __ _ __ __ ____ - * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ + * ____ _ _ __ __ _ __ __ ____ + * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) | - * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ - * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| + * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ + * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| * * 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 @@ -15,7 +15,7 @@ * * @author PocketMine Team * @link http://www.pocketmine.net/ - * + * * */ @@ -26,4 +26,10 @@ class ChainHelmet extends Armor{ public function __construct($meta = 0, $count = 1){ parent::__construct(self::CHAIN_HELMET, $meta, $count, "Chainmail Helmet"); } -} \ No newline at end of file + public function getArmorPoints(){ + return 2; + } + public function getMaxDurability(){ + return 166; + } +} diff --git a/src/pocketmine/item/ChainLeggings.php b/src/pocketmine/item/ChainLeggings.php index b005c7aff..53e98addf 100644 --- a/src/pocketmine/item/ChainLeggings.php +++ b/src/pocketmine/item/ChainLeggings.php @@ -2,11 +2,11 @@ /* * - * ____ _ _ __ __ _ __ __ ____ - * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ + * ____ _ _ __ __ _ __ __ ____ + * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) | - * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ - * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| + * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ + * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| * * 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 @@ -15,7 +15,7 @@ * * @author PocketMine Team * @link http://www.pocketmine.net/ - * + * * */ @@ -26,4 +26,10 @@ class ChainLeggings extends Armor{ public function __construct($meta = 0, $count = 1){ parent::__construct(self::CHAIN_LEGGINGS, $meta, $count, "Chain Leggings"); } -} \ No newline at end of file + public function getArmorPoints(){ + return 3; + } + public function getMaxDurability(){ + return 226; + } +} diff --git a/src/pocketmine/item/DiamondBoots.php b/src/pocketmine/item/DiamondBoots.php index cabd1d6a7..3b2f031da 100644 --- a/src/pocketmine/item/DiamondBoots.php +++ b/src/pocketmine/item/DiamondBoots.php @@ -2,11 +2,11 @@ /* * - * ____ _ _ __ __ _ __ __ ____ - * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ + * ____ _ _ __ __ _ __ __ ____ + * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) | - * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ - * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| + * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ + * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| * * 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 @@ -15,7 +15,7 @@ * * @author PocketMine Team * @link http://www.pocketmine.net/ - * + * * */ @@ -26,4 +26,10 @@ class DiamondBoots extends Armor{ public function __construct($meta = 0, $count = 1){ parent::__construct(self::DIAMOND_BOOTS, $meta, $count, "Diamond Boots"); } -} \ No newline at end of file + public function getArmorPoints(){ + return 3; + } + public function getMaxDurability(){ + return 430; + } +} diff --git a/src/pocketmine/item/DiamondChestplate.php b/src/pocketmine/item/DiamondChestplate.php index 61e3e1659..080f9d6da 100644 --- a/src/pocketmine/item/DiamondChestplate.php +++ b/src/pocketmine/item/DiamondChestplate.php @@ -2,11 +2,11 @@ /* * - * ____ _ _ __ __ _ __ __ ____ - * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ + * ____ _ _ __ __ _ __ __ ____ + * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) | - * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ - * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| + * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ + * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| * * 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 @@ -15,7 +15,7 @@ * * @author PocketMine Team * @link http://www.pocketmine.net/ - * + * * */ @@ -26,4 +26,10 @@ class DiamondChestplate extends Armor{ public function __construct($meta = 0, $count = 1){ parent::__construct(self::DIAMOND_CHESTPLATE, $meta, $count, "Diamond Chestplate"); } -} \ No newline at end of file + public function getArmorPoints(){ + return 8; + } + public function getMaxDurability(){ + return 529; + } +} diff --git a/src/pocketmine/item/DiamondHelmet.php b/src/pocketmine/item/DiamondHelmet.php index d884b2ae9..cd42dd712 100644 --- a/src/pocketmine/item/DiamondHelmet.php +++ b/src/pocketmine/item/DiamondHelmet.php @@ -2,11 +2,11 @@ /* * - * ____ _ _ __ __ _ __ __ ____ - * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ + * ____ _ _ __ __ _ __ __ ____ + * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) | - * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ - * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| + * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ + * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| * * 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 @@ -15,7 +15,7 @@ * * @author PocketMine Team * @link http://www.pocketmine.net/ - * + * * */ @@ -26,4 +26,10 @@ class DiamondHelmet extends Armor{ public function __construct($meta = 0, $count = 1){ parent::__construct(self::DIAMOND_HELMET, $meta, $count, "Diamond Helmet"); } -} \ No newline at end of file + public function getArmorPoints(){ + return 3; + } + public function getMaxDurability(){ + return 364; + } +} diff --git a/src/pocketmine/item/DiamondLeggings.php b/src/pocketmine/item/DiamondLeggings.php index abb772376..5aab5e97b 100644 --- a/src/pocketmine/item/DiamondLeggings.php +++ b/src/pocketmine/item/DiamondLeggings.php @@ -2,11 +2,11 @@ /* * - * ____ _ _ __ __ _ __ __ ____ - * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ + * ____ _ _ __ __ _ __ __ ____ + * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) | - * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ - * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| + * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ + * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| * * 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 @@ -15,7 +15,7 @@ * * @author PocketMine Team * @link http://www.pocketmine.net/ - * + * * */ @@ -26,4 +26,10 @@ class DiamondLeggings extends Armor{ public function __construct($meta = 0, $count = 1){ parent::__construct(self::DIAMOND_LEGGINGS, $meta, $count, "Diamond Leggings"); } -} \ No newline at end of file + public function getArmorPoints(){ + return 6; + } + public function getMaxDurability(){ + return 496; + } +} diff --git a/src/pocketmine/item/GoldBoots.php b/src/pocketmine/item/GoldBoots.php index 7f10dd509..17677ff5b 100644 --- a/src/pocketmine/item/GoldBoots.php +++ b/src/pocketmine/item/GoldBoots.php @@ -2,11 +2,11 @@ /* * - * ____ _ _ __ __ _ __ __ ____ - * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ + * ____ _ _ __ __ _ __ __ ____ + * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) | - * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ - * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| + * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ + * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| * * 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 @@ -15,7 +15,7 @@ * * @author PocketMine Team * @link http://www.pocketmine.net/ - * + * * */ @@ -26,4 +26,10 @@ class GoldBoots extends Armor{ public function __construct($meta = 0, $count = 1){ parent::__construct(self::GOLD_BOOTS, $meta, $count, "Gold Boots"); } -} \ No newline at end of file + public function getArmorPoints(){ + return 1; + } + public function getMaxDurability(){ + return 92; + } +} diff --git a/src/pocketmine/item/GoldChestplate.php b/src/pocketmine/item/GoldChestplate.php index 262994965..d6051d74e 100644 --- a/src/pocketmine/item/GoldChestplate.php +++ b/src/pocketmine/item/GoldChestplate.php @@ -2,11 +2,11 @@ /* * - * ____ _ _ __ __ _ __ __ ____ - * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ + * ____ _ _ __ __ _ __ __ ____ + * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) | - * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ - * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| + * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ + * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| * * 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 @@ -15,7 +15,7 @@ * * @author PocketMine Team * @link http://www.pocketmine.net/ - * + * * */ @@ -26,4 +26,10 @@ class GoldChestplate extends Armor{ public function __construct($meta = 0, $count = 1){ parent::__construct(self::GOLD_CHESTPLATE, $meta, $count, "Gold Chestplate"); } -} \ No newline at end of file + public function getArmorPoints(){ + return 5; + } + public function getMaxDurability(){ + return 113; + } +} diff --git a/src/pocketmine/item/GoldHelmet.php b/src/pocketmine/item/GoldHelmet.php index e54d1b44a..9255a886e 100644 --- a/src/pocketmine/item/GoldHelmet.php +++ b/src/pocketmine/item/GoldHelmet.php @@ -2,11 +2,11 @@ /* * - * ____ _ _ __ __ _ __ __ ____ - * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ + * ____ _ _ __ __ _ __ __ ____ + * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) | - * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ - * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| + * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ + * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| * * 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 @@ -15,7 +15,7 @@ * * @author PocketMine Team * @link http://www.pocketmine.net/ - * + * * */ @@ -26,4 +26,10 @@ class GoldHelmet extends Armor{ public function __construct($meta = 0, $count = 1){ parent::__construct(self::GOLD_HELMET, $meta, $count, "Gold Helmet"); } -} \ No newline at end of file + public function getArmorPoints(){ + return 2; + } + public function getMaxDurability(){ + return 78; + } +} diff --git a/src/pocketmine/item/GoldLeggings.php b/src/pocketmine/item/GoldLeggings.php index f7eabe43e..439c62635 100644 --- a/src/pocketmine/item/GoldLeggings.php +++ b/src/pocketmine/item/GoldLeggings.php @@ -2,11 +2,11 @@ /* * - * ____ _ _ __ __ _ __ __ ____ - * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ + * ____ _ _ __ __ _ __ __ ____ + * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) | - * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ - * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| + * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ + * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| * * 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 @@ -15,7 +15,7 @@ * * @author PocketMine Team * @link http://www.pocketmine.net/ - * + * * */ @@ -26,4 +26,10 @@ class GoldLeggings extends Armor{ public function __construct($meta = 0, $count = 1){ parent::__construct(self::GOLD_LEGGINGS, $meta, $count, "Gold Leggings"); } -} \ No newline at end of file + public function getArmorPoints(){ + return 3; + } + public function getMaxDurability(){ + return 106; + } +} diff --git a/src/pocketmine/item/IronBoots.php b/src/pocketmine/item/IronBoots.php index 370bd635e..2bcb03090 100644 --- a/src/pocketmine/item/IronBoots.php +++ b/src/pocketmine/item/IronBoots.php @@ -2,11 +2,11 @@ /* * - * ____ _ _ __ __ _ __ __ ____ - * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ + * ____ _ _ __ __ _ __ __ ____ + * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) | - * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ - * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| + * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ + * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| * * 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 @@ -15,7 +15,7 @@ * * @author PocketMine Team * @link http://www.pocketmine.net/ - * + * * */ @@ -26,4 +26,10 @@ class IronBoots extends Armor{ public function __construct($meta = 0, $count = 1){ parent::__construct(self::IRON_BOOTS, $meta, $count, "Iron Boots"); } -} \ No newline at end of file + public function getArmorPoints(){ + return 2; + } + public function getMaxDurability(){ + return 196; + } +} diff --git a/src/pocketmine/item/IronChestplate.php b/src/pocketmine/item/IronChestplate.php index 1a485229a..55e13a3b7 100644 --- a/src/pocketmine/item/IronChestplate.php +++ b/src/pocketmine/item/IronChestplate.php @@ -2,11 +2,11 @@ /* * - * ____ _ _ __ __ _ __ __ ____ - * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ + * ____ _ _ __ __ _ __ __ ____ + * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) | - * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ - * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| + * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ + * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| * * 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 @@ -15,7 +15,7 @@ * * @author PocketMine Team * @link http://www.pocketmine.net/ - * + * * */ @@ -26,4 +26,10 @@ class IronChestplate extends Armor{ public function __construct($meta = 0, $count = 1){ parent::__construct(self::IRON_CHESTPLATE, $meta, $count, "Iron Chestplate"); } -} \ No newline at end of file + public function getArmorPoints(){ + return 6; + } + public function getMaxDurability(){ + return 241; + } +} diff --git a/src/pocketmine/item/IronHelmet.php b/src/pocketmine/item/IronHelmet.php index eb1fbbd0f..3848f5ce4 100644 --- a/src/pocketmine/item/IronHelmet.php +++ b/src/pocketmine/item/IronHelmet.php @@ -2,11 +2,11 @@ /* * - * ____ _ _ __ __ _ __ __ ____ - * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ + * ____ _ _ __ __ _ __ __ ____ + * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) | - * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ - * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| + * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ + * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| * * 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 @@ -15,7 +15,7 @@ * * @author PocketMine Team * @link http://www.pocketmine.net/ - * + * * */ @@ -26,4 +26,10 @@ class IronHelmet extends Armor{ public function __construct($meta = 0, $count = 1){ parent::__construct(self::IRON_HELMET, $meta, $count, "Iron Helmet"); } -} \ No newline at end of file + public function getArmorPoints(){ + return 2; + } + public function getMaxDurability(){ + return 166; + } +} diff --git a/src/pocketmine/item/IronLeggings.php b/src/pocketmine/item/IronLeggings.php index 5d99d1d20..211a27697 100644 --- a/src/pocketmine/item/IronLeggings.php +++ b/src/pocketmine/item/IronLeggings.php @@ -2,11 +2,11 @@ /* * - * ____ _ _ __ __ _ __ __ ____ - * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ + * ____ _ _ __ __ _ __ __ ____ + * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) | - * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ - * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| + * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ + * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| * * 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 @@ -15,7 +15,7 @@ * * @author PocketMine Team * @link http://www.pocketmine.net/ - * + * * */ @@ -26,4 +26,10 @@ class IronLeggings extends Armor{ public function __construct($meta = 0, $count = 1){ parent::__construct(self::IRON_LEGGINGS, $meta, $count, "Iron Leggings"); } -} \ No newline at end of file + public function getArmorPoints(){ + return 5; + } + public function getMaxDurability(){ + return 226; + } +} diff --git a/src/pocketmine/item/LeatherBoots.php b/src/pocketmine/item/LeatherBoots.php index 2a7b1816c..a72656c28 100644 --- a/src/pocketmine/item/LeatherBoots.php +++ b/src/pocketmine/item/LeatherBoots.php @@ -2,11 +2,11 @@ /* * - * ____ _ _ __ __ _ __ __ ____ - * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ + * ____ _ _ __ __ _ __ __ ____ + * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) | - * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ - * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| + * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ + * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| * * 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 @@ -15,7 +15,7 @@ * * @author PocketMine Team * @link http://www.pocketmine.net/ - * + * * */ @@ -26,4 +26,10 @@ class LeatherBoots extends Armor{ public function __construct($meta = 0, $count = 1){ parent::__construct(self::LEATHER_BOOTS, $meta, $count, "Leather Boots"); } -} \ No newline at end of file + public function getArmorPoints(){ + return 1; + } + public function getMaxDurability(){ + return 66; + } +} diff --git a/src/pocketmine/item/LeatherCap.php b/src/pocketmine/item/LeatherCap.php index 4179b7725..c3ff7392a 100644 --- a/src/pocketmine/item/LeatherCap.php +++ b/src/pocketmine/item/LeatherCap.php @@ -2,11 +2,11 @@ /* * - * ____ _ _ __ __ _ __ __ ____ - * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ + * ____ _ _ __ __ _ __ __ ____ + * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) | - * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ - * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| + * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ + * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| * * 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 @@ -15,7 +15,7 @@ * * @author PocketMine Team * @link http://www.pocketmine.net/ - * + * * */ @@ -26,4 +26,10 @@ class LeatherCap extends Armor{ public function __construct($meta = 0, $count = 1){ parent::__construct(self::LEATHER_CAP, $meta, $count, "Leather Cap"); } -} \ No newline at end of file + public function getArmorPoints(){ + return 1; + } + public function getMaxDurability(){ + return 56; + } +} diff --git a/src/pocketmine/item/LeatherPants.php b/src/pocketmine/item/LeatherPants.php index 98e65c09e..3c300c3e0 100644 --- a/src/pocketmine/item/LeatherPants.php +++ b/src/pocketmine/item/LeatherPants.php @@ -2,11 +2,11 @@ /* * - * ____ _ _ __ __ _ __ __ ____ - * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ + * ____ _ _ __ __ _ __ __ ____ + * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) | - * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ - * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| + * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ + * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| * * 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 @@ -15,7 +15,7 @@ * * @author PocketMine Team * @link http://www.pocketmine.net/ - * + * * */ @@ -26,4 +26,10 @@ class LeatherPants extends Armor{ public function __construct($meta = 0, $count = 1){ parent::__construct(self::LEATHER_PANTS, $meta, $count, "Leather Pants"); } -} \ No newline at end of file + public function getArmorPoints(){ + return 2; + } + public function getMaxDurability(){ + return 76; + } +} diff --git a/src/pocketmine/item/LeatherTunic.php b/src/pocketmine/item/LeatherTunic.php index af4d18259..4c9d47c69 100644 --- a/src/pocketmine/item/LeatherTunic.php +++ b/src/pocketmine/item/LeatherTunic.php @@ -2,11 +2,11 @@ /* * - * ____ _ _ __ __ _ __ __ ____ - * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ + * ____ _ _ __ __ _ __ __ ____ + * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) | - * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ - * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| + * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ + * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| * * 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 @@ -15,7 +15,7 @@ * * @author PocketMine Team * @link http://www.pocketmine.net/ - * + * * */ @@ -26,4 +26,10 @@ class LeatherTunic extends Armor{ public function __construct($meta = 0, $count = 1){ parent::__construct(self::LEATHER_TUNIC, $meta, $count, "Leather Tunic"); } -} \ No newline at end of file + public function getArmorPoints(){ + return 3; + } + public function getMaxDurability(){ + return 81; + } +} diff --git a/src/pocketmine/level/Explosion.php b/src/pocketmine/level/Explosion.php index c2c4603ad..a3608dda2 100644 --- a/src/pocketmine/level/Explosion.php +++ b/src/pocketmine/level/Explosion.php @@ -2,11 +2,11 @@ /* * - * ____ _ _ __ __ _ __ __ ____ - * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ + * ____ _ _ __ __ _ __ __ ____ + * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) | - * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ - * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| + * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ + * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| * * 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 @@ -15,7 +15,7 @@ * * @author PocketMine Team * @link http://www.pocketmine.net/ - * + * * */ @@ -27,6 +27,8 @@ use pocketmine\event\entity\EntityDamageByBlockEvent; use pocketmine\event\entity\EntityDamageByEntityEvent; use pocketmine\event\entity\EntityDamageEvent; use pocketmine\event\entity\EntityExplodeEvent; +use pocketmine\inventory\InventoryHolder; +use pocketmine\inventory\PlayerInventory; use pocketmine\item\Item; use pocketmine\math\AxisAlignedBB; use pocketmine\math\Math; @@ -161,7 +163,13 @@ class Explosion{ $impact = (1 - $distance) * ($exposure = 1); - $damage = (int) ((($impact * $impact + $impact) / 2) * 8 * $explosionSize + 1); + $damage = [EntityDamageEvent::MODIFIER_BASE => (int) ((($impact * $impact + $impact) / 2) * 8 * $explosionSize + 1)]; + if($entity instanceof InventoryHolder){ + $inventory = $entity->getInventory(); + if($inventory instanceof PlayerInventory){ + $damage[EntityDamageEvent::MODIFIER_ARMOR] = $inventory->getArmorPoints(); + } + } if($this->what instanceof Entity){ $ev = new EntityDamageByEntityEvent($this->what, $entity, EntityDamageEvent::CAUSE_ENTITY_EXPLOSION, $damage); diff --git a/src/pocketmine/math/Vector3.php b/src/pocketmine/math/Vector3.php index f4b49905c..2d62334ac 100644 --- a/src/pocketmine/math/Vector3.php +++ b/src/pocketmine/math/Vector3.php @@ -128,9 +128,8 @@ class Vector3{ public function floor(){ $x = (int) $this->x; - $y = (int) $this->y; $z = (int) $this->z; - return new Vector3($this->x >= $x ? $x : $x - 1, $this->y >= $y ? $y : $y - 1, $this->z >= $z ? $z : $z - 1); + return new Vector3($this->x >= $x ? $x : $x - 1, round($this->y), $this->z >= $z ? $z : $z - 1); } public function round(){