mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-20 16:00:20 +00:00
Added Fire, Lava damage
This commit is contained in:
parent
e608acbd1c
commit
e9a2f88847
@ -24,6 +24,7 @@
|
||||
*/
|
||||
namespace pocketmine\block;
|
||||
|
||||
use pocketmine\entity\Entity;
|
||||
use pocketmine\entity\Villager;
|
||||
use pocketmine\entity\Zombie;
|
||||
use pocketmine\item\Item;
|
||||
@ -832,6 +833,13 @@ abstract class Block extends Position implements Metadatable{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Entity $entity
|
||||
*/
|
||||
public function onEntityCollide(Entity $entity){
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return AxisAlignedBB
|
||||
*/
|
||||
|
@ -42,7 +42,7 @@ class FenceGate extends Transparent{
|
||||
if(($this->getDamage() & 0x04) > 0){
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
$i = ($this->getDamage() & 0x03);
|
||||
if($i === 2 and $i === 0){
|
||||
return new AxisAlignedBB(
|
||||
|
@ -22,7 +22,10 @@
|
||||
namespace pocketmine\block;
|
||||
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\entity\Entity;
|
||||
use pocketmine\level\Level;
|
||||
use pocketmine\event\entity\EntityDamageEvent;
|
||||
use pocketmine\Server;
|
||||
|
||||
class Fire extends Flowable{
|
||||
public function __construct($meta = 0){
|
||||
@ -37,6 +40,14 @@ class Fire extends Flowable{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function onEntityCollide(Entity $entity){
|
||||
$entity->setOnFire(8);
|
||||
$ev = new EntityDamageEvent($entity, EntityDamageEvent::CAUSE_FIRE, 1);
|
||||
Server::getInstance()->getPluginManager()->callEvent($ev);
|
||||
if(!$ev->isCancelled()){
|
||||
$entity->attack($ev->getFinalDamage(), $ev);
|
||||
}
|
||||
}
|
||||
|
||||
public function getDrops(Item $item){
|
||||
return [];
|
||||
|
@ -22,10 +22,12 @@
|
||||
namespace pocketmine\block;
|
||||
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\entity\Entity;
|
||||
use pocketmine\level\Level;
|
||||
use pocketmine\level\Position;
|
||||
use pocketmine\Player;
|
||||
use pocketmine\Server;
|
||||
use pocketmine\event\entity\EntityDamageEvent;
|
||||
|
||||
class Lava extends Liquid{
|
||||
public function __construct($meta = 0){
|
||||
@ -37,6 +39,15 @@ class Lava extends Liquid{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function onEntityCollide(Entity $entity){
|
||||
$entity->setOnFire(15);
|
||||
$ev = new EntityDamageEvent($entity, EntityDamageEvent::CAUSE_LAVA, 4);
|
||||
Server::getInstance()->getPluginManager()->callEvent($ev);
|
||||
if(!$ev->isCancelled()){
|
||||
$entity->attack($ev->getFinalDamage(), $ev);
|
||||
}
|
||||
$entity->attack(4, EntityDamageEvent::CAUSE_LAVA);
|
||||
}
|
||||
|
||||
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||
$ret = $this->getLevel()->setBlock($this, $this, true);
|
||||
|
@ -21,6 +21,9 @@
|
||||
|
||||
namespace pocketmine\block;
|
||||
|
||||
use pocketmine\event\entity\EntityDamageEvent;
|
||||
use pocketmine\Server;
|
||||
use pocketmine\entity\Entity;
|
||||
|
||||
class StillLava extends Liquid{
|
||||
public function __construct($meta = 0){
|
||||
@ -28,4 +31,18 @@ class StillLava extends Liquid{
|
||||
$this->hardness = 500;
|
||||
}
|
||||
|
||||
public function getBoundingBox(){
|
||||
return null;
|
||||
}
|
||||
|
||||
public function onEntityCollide(Entity $entity){
|
||||
$entity->setOnFire(15);
|
||||
$ev = new EntityDamageEvent($entity, EntityDamageEvent::CAUSE_LAVA, 4);
|
||||
Server::getInstance()->getPluginManager()->callEvent($ev);
|
||||
if(!$ev->isCancelled()){
|
||||
$entity->attack($ev->getFinalDamage(), $ev);
|
||||
}
|
||||
$entity->attack(4, EntityDamageEvent::CAUSE_LAVA);
|
||||
}
|
||||
|
||||
}
|
@ -460,6 +460,8 @@ abstract class Entity extends Position implements Metadatable{
|
||||
$hasUpdate = false;
|
||||
$this->updateMovement();
|
||||
|
||||
$this->checkBlockCollision();
|
||||
|
||||
if($this->handleWaterMovement()){
|
||||
$this->fallDistance = 0;
|
||||
$this->inWater = true;
|
||||
@ -483,7 +485,11 @@ abstract class Entity extends Position implements Metadatable{
|
||||
}
|
||||
}else{
|
||||
if(($this->fireTicks % 20) === 0){
|
||||
$this->attack(1, EntityDamageEvent::CAUSE_FIRE_TICK);
|
||||
$ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_FIRE_TICK, 1);
|
||||
$this->server->getPluginManager()->callEvent($ev);
|
||||
if(!$ev->isCancelled()){
|
||||
$this->attack($ev->getFinalDamage(), $ev);
|
||||
}
|
||||
}
|
||||
--$this->fireTicks;
|
||||
}
|
||||
@ -491,8 +497,8 @@ abstract class Entity extends Position implements Metadatable{
|
||||
}
|
||||
|
||||
if($this->handleLavaMovement()){
|
||||
$this->attack(4, EntityDamageEvent::CAUSE_LAVA);
|
||||
$this->setOnFire(15);
|
||||
//$this->attack(4, EntityDamageEvent::CAUSE_LAVA);
|
||||
//$this->setOnFire(15);
|
||||
$hasUpdate = true;
|
||||
$this->fallDistance *= 0.5;
|
||||
}
|
||||
@ -712,8 +718,7 @@ abstract class Entity extends Position implements Metadatable{
|
||||
}
|
||||
|
||||
public function move($dx, $dy, $dz){
|
||||
//$collision = [];
|
||||
//$this->checkBlockCollision($collision);
|
||||
|
||||
if($dx == 0 and $dz == 0 and $dy == 0){
|
||||
return true;
|
||||
}
|
||||
@ -932,12 +937,7 @@ abstract class Entity extends Position implements Metadatable{
|
||||
//}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Block[] $list
|
||||
*
|
||||
* @return Block[]
|
||||
*/
|
||||
protected function checkBlockCollision(&$list = []){
|
||||
protected function checkBlockCollision(){
|
||||
$minX = floor($this->boundingBox->minX + 0.001);
|
||||
$minY = floor($this->boundingBox->minY + 0.001);
|
||||
$minZ = floor($this->boundingBox->minZ + 0.001);
|
||||
@ -948,12 +948,13 @@ abstract class Entity extends Position implements Metadatable{
|
||||
for($z = $minZ; $z <= $maxZ; ++$z){
|
||||
for($x = $minX; $x <= $maxX; ++$x){
|
||||
for($y = $minY; $y <= $maxY; ++$y){
|
||||
$this->getLevel()->getBlock(new Vector3($x, $y, $z))->collidesWithBB($this->boundingBox, $list);
|
||||
$block = $this->getLevel()->getBlock(new Vector3($x, $y, $z));
|
||||
if($block !== null and $block->getID() > 0){
|
||||
$block->onEntityCollide($this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function setPositionAndRotation(Vector3 $pos, $yaw, $pitch, $force = false){
|
||||
|
Loading…
x
Reference in New Issue
Block a user