Skip to content
This repository has been archived by the owner on Feb 9, 2021. It is now read-only.

Commit

Permalink
Merge pull request #2785 from PocketMine/revert-2776-armor-fix
Browse files Browse the repository at this point in the history
Revert "Implemented proportional armor modifier, applied armor in other ...
  • Loading branch information
shoghicp committed Mar 18, 2015
2 parents 7c0bd45 + d34499e commit 6bf30c1
Show file tree
Hide file tree
Showing 31 changed files with 203 additions and 397 deletions.
54 changes: 31 additions & 23 deletions src/pocketmine/Player.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
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;
Expand Down Expand Up @@ -1983,7 +1982,6 @@ public function handleDataPacket(DataPacket $packet){
EntityDamageEvent::MODIFIER_BASE => isset($damageTable[$item->getId()]) ? $damageTable[$item->getId()] : 1,
];

$points = 0;
if($this->distance($target) > 8){
$cancelled = true;
}elseif($target instanceof Player){
Expand All @@ -1993,7 +1991,34 @@ public function handleDataPacket(DataPacket $packet){
$cancelled = true;
}

$points = $target->getInventory()->getArmorPoints();
$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()];
}
}

$damage[EntityDamageEvent::MODIFIER_ARMOR] = -floor($damage[EntityDamageEvent::MODIFIER_BASE] * $points * 0.04);
}
Expand Down Expand Up @@ -2021,6 +2046,7 @@ public function handleDataPacket(DataPacket $packet){
}
}


break;
case ProtocolInfo::ANIMATE_PACKET:
if($this->spawned === false or $this->dead === true){
Expand Down Expand Up @@ -2662,24 +2688,8 @@ public function attack($damage, $source = EntityDamageEvent::CAUSE_MAGIC){

parent::attack($damage, $source);

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($source instanceof EntityDamageEvent and $source->isCancelled()){
return;
}

if($this->getLastDamageCause() === $source){
Expand All @@ -2688,8 +2698,6 @@ public function attack($damage, $source = EntityDamageEvent::CAUSE_MAGIC){
$pk->event = 2;
$this->dataPacket($pk);
}


}

public function getData(){ //TODO
Expand Down
23 changes: 7 additions & 16 deletions src/pocketmine/block/Cactus.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -15,7 +15,7 @@
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*
*/

Expand All @@ -25,8 +25,6 @@
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;
Expand Down Expand Up @@ -67,14 +65,7 @@ protected function recalculateBoundingBox(){
}

public function onEntityCollide(Entity $entity){
$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);
$ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_CONTACT, 1);
$entity->attack($ev->getFinalDamage(), $ev);
}

Expand Down Expand Up @@ -137,4 +128,4 @@ public function getDrops(Item $item){
[$this->id, 0, 1],
];
}
}
}
23 changes: 7 additions & 16 deletions src/pocketmine/block/Fire.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -15,7 +15,7 @@
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*
*/

Expand All @@ -25,8 +25,6 @@
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;
Expand Down Expand Up @@ -60,14 +58,7 @@ public function canBeReplaced(){
}

public function onEntityCollide(Entity $entity){
$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);
$ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_FIRE, 1);
$entity->attack($ev->getFinalDamage(), $ev);

$ev = new EntityCombustByBlockEvent($this, $entity, 8);
Expand Down Expand Up @@ -103,4 +94,4 @@ public function onUpdate($type){
return false;
}

}
}
21 changes: 6 additions & 15 deletions src/pocketmine/block/Lava.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -15,7 +15,7 @@
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*
*/

Expand All @@ -25,8 +25,6 @@
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;
Expand All @@ -53,14 +51,7 @@ public function getHardness(){

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();
}
}
$ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_LAVA, $damage);
$ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_LAVA, 4);
$entity->attack($ev->getFinalDamage(), $ev);

$ev = new EntityCombustByBlockEvent($this, $entity, 15);
Expand Down
19 changes: 5 additions & 14 deletions src/pocketmine/entity/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -15,7 +15,7 @@
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*
*/

Expand All @@ -33,8 +33,6 @@
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;
Expand Down Expand Up @@ -737,13 +735,6 @@ public function getBoundingBox(){
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);
}
Expand Down
30 changes: 7 additions & 23 deletions src/pocketmine/entity/Living.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -15,7 +15,7 @@
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*
*/

Expand All @@ -28,8 +28,6 @@
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;
Expand Down Expand Up @@ -170,14 +168,7 @@ public function entityBaseTick($tickDiff = 1){

if($this->dead !== true and $this->isInsideOfSolid()){
$hasUpdate = true;
$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);
$ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_SUFFOCATION, 1);
$this->attack($ev->getFinalDamage(), $ev);
}

Expand All @@ -187,14 +178,7 @@ public function entityBaseTick($tickDiff = 1){
if($this->airTicks <= -20){
$this->airTicks = 0;

$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);
$ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_DROWNING, 2);
$this->attack($ev->getFinalDamage(), $ev);
}
}else{
Expand Down
Loading

0 comments on commit 6bf30c1

Please sign in to comment.