Skip to content

Commit 8a8a954

Browse files
committed
Added Cactus damage
1 parent 34139c7 commit 8a8a954

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/pocketmine/Player.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2348,6 +2348,9 @@ public function kill(){
23482348
break;
23492349

23502350
case EntityDamageEvent::CAUSE_CONTACT:
2351+
$message = $this->getName() . " was pricked to death";
2352+
break;
2353+
23512354
case EntityDamageEvent::CAUSE_BLOCK_EXPLOSION:
23522355
case EntityDamageEvent::CAUSE_ENTITY_EXPLOSION:
23532356
case EntityDamageEvent::CAUSE_MAGIC:

src/pocketmine/block/Cactus.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
use pocketmine\math\AxisAlignedBB;
2727
use pocketmine\math\Vector3 as Vector3;
2828
use pocketmine\Player;
29+
use pocketmine\entity\Entity;
30+
use pocketmine\event\entity\EntityDamageEvent;
31+
use pocketmine\Server;
2932

3033
class Cactus extends Transparent{
3134
public function __construct($meta = 0){
@@ -45,6 +48,14 @@ public function getBoundingBox(){
4548
);
4649
}
4750

51+
public function onEntityCollide(Entity $entity){
52+
$ev = new EntityDamageEvent($entity, EntityDamageEvent::CAUSE_CONTACT, 1);
53+
Server::getInstance()->getPluginManager()->callEvent($ev);
54+
if(!$ev->isCancelled()){
55+
$entity->attack($ev->getFinalDamage(), $ev);
56+
}
57+
}
58+
4859
public function onUpdate($type){
4960
if($type === Level::BLOCK_UPDATE_NORMAL){
5061
$down = $this->getSide(0);

0 commit comments

Comments
 (0)