Added soul fire

This commit is contained in:
Dylan K. Taylor 2022-07-04 22:31:59 +01:00
parent 4909c0f257
commit d9544b5d0e
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
10 changed files with 128 additions and 41 deletions

61
src/block/BaseFire.php Normal file
View File

@ -0,0 +1,61 @@
<?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\block;
use pocketmine\entity\Entity;
use pocketmine\entity\projectile\Arrow;
use pocketmine\event\entity\EntityCombustByBlockEvent;
use pocketmine\event\entity\EntityDamageByBlockEvent;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\item\Item;
abstract class BaseFire extends Flowable{
public function hasEntityCollision() : bool{
return true;
}
public function canBeReplaced() : bool{
return true;
}
public function onEntityInside(Entity $entity) : bool{
$ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_FIRE, 1);
$entity->attack($ev);
$ev = new EntityCombustByBlockEvent($this, $entity, 8);
if($entity instanceof Arrow){
$ev->cancel();
}
$ev->call();
if(!$ev->isCancelled()){
$entity->setOnFire($ev->getDuration());
}
return true;
}
public function getDropsForCompatibleTool(Item $item) : array{
return [];
}
}

View File

@ -744,6 +744,8 @@ class BlockFactory{
$this->register(new Stair(new BID(Ids::POLISHED_BLACKSTONE_BRICK_STAIRS), $prefix("Stairs"), $blackstoneBreakInfo));
$this->register(new Wall(new BID(Ids::POLISHED_BLACKSTONE_BRICK_WALL), $prefix("Wall"), $blackstoneBreakInfo));
$this->register(new Opaque(new BID(Ids::CRACKED_POLISHED_BLACKSTONE_BRICKS), "Cracked Polished Blackstone Bricks", $blackstoneBreakInfo));
$this->register(new SoulFire(new BID(Ids::SOUL_FIRE), "Soul Fire", BreakInfo::instant()));
}
private function registerBlocksR17() : void{

View File

@ -614,6 +614,9 @@ final class BlockTypeIds{
public const CHISELED_NETHER_BRICKS = 10587;
public const CRACKED_NETHER_BRICKS = 10588;
public const SOUL_SOIL = 10592;
public const SOUL_FIRE = 10593;
public const MANGROVE_PLANKS = 10595;
public const CRIMSON_PLANKS = 10596;
public const WARPED_PLANKS = 10597;

View File

@ -25,14 +25,8 @@ namespace pocketmine\block;
use pocketmine\data\runtime\block\BlockDataReader;
use pocketmine\data\runtime\block\BlockDataWriter;
use pocketmine\entity\Entity;
use pocketmine\entity\projectile\Arrow;
use pocketmine\event\block\BlockBurnEvent;
use pocketmine\event\block\BlockSpreadEvent;
use pocketmine\event\entity\EntityCombustByBlockEvent;
use pocketmine\event\entity\EntityDamageByBlockEvent;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\item\Item;
use pocketmine\math\Facing;
use pocketmine\world\format\Chunk;
use pocketmine\world\World;
@ -41,7 +35,7 @@ use function max;
use function min;
use function mt_rand;
class Fire extends Flowable{
class Fire extends BaseFire{
public const MAX_AGE = 15;
protected int $age = 0;
@ -67,39 +61,11 @@ class Fire extends Flowable{
return $this;
}
public function hasEntityCollision() : bool{
return true;
}
public function getLightLevel() : int{
return 15;
}
public function canBeReplaced() : bool{
return true;
}
public function onEntityInside(Entity $entity) : bool{
$ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_FIRE, 1);
$entity->attack($ev);
$ev = new EntityCombustByBlockEvent($this, $entity, 8);
if($entity instanceof Arrow){
$ev->cancel();
}
$ev->call();
if(!$ev->isCancelled()){
$entity->setOnFire($ev->getDuration());
}
return true;
}
public function getDropsForCompatibleTool(Item $item) : array{
return [];
}
public function onNearbyBlockChange() : void{
if($this->getSide(Facing::DOWN)->isTransparent() && !$this->hasAdjacentFlammableBlocks()){
$down = $this->getSide(Facing::DOWN);
if(SoulFire::canBeSupportedBy($down)){
$this->position->getWorld()->setBlock($this->position, VanillaBlocks::SOUL_FIRE());
}elseif($down->isTransparent() && !$this->hasAdjacentFlammableBlocks()){
$this->position->getWorld()->setBlock($this->position, VanillaBlocks::AIR());
}else{
$this->position->getWorld()->scheduleDelayedBlockUpdate($this->position, mt_rand(30, 40));

45
src/block/SoulFire.php Normal file
View File

@ -0,0 +1,45 @@
<?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\block;
use pocketmine\math\Facing;
final class SoulFire extends BaseFire{
public function getLightLevel() : int{
return 10;
}
public static function canBeSupportedBy(Block $block) : bool{
//TODO: this really ought to use some kind of tag system
$id = $block->getTypeId();
return $id === BlockTypeIds::SOUL_SAND || $id === BlockTypeIds::SOUL_SOIL;
}
public function onNearbyBlockChange() : void{
if(!self::canBeSupportedBy($this->getSide(Facing::DOWN))){
$this->position->getWorld()->setBlock($this->position, VanillaBlocks::AIR());
}
}
}

View File

@ -564,6 +564,7 @@ use pocketmine\utils\CloningRegistryTrait;
* @method static Slab SMOOTH_STONE_SLAB()
* @method static Snow SNOW()
* @method static SnowLayer SNOW_LAYER()
* @method static SoulFire SOUL_FIRE()
* @method static SoulSand SOUL_SAND()
* @method static Sponge SPONGE()
* @method static WoodenButton SPRUCE_BUTTON()
@ -1182,6 +1183,7 @@ final class VanillaBlocks{
self::register("smooth_stone_slab", $factory->get(Ids::SMOOTH_STONE_SLAB, 0));
self::register("snow", $factory->get(Ids::SNOW, 0));
self::register("snow_layer", $factory->get(Ids::SNOW_LAYER, 0));
self::register("soul_fire", $factory->get(Ids::SOUL_FIRE, 0));
self::register("soul_sand", $factory->get(Ids::SOUL_SAND, 0));
self::register("sponge", $factory->get(Ids::SPONGE, 0));
self::register("spruce_button", $factory->get(Ids::SPRUCE_BUTTON, 0));

View File

@ -1070,6 +1070,10 @@ final class BlockObjectToBlockStateSerializer implements BlockStateSerializer{
->writeBool(StateNames::COVERED_BIT, false)
->writeInt(StateNames::HEIGHT, $block->getLayers() - 1);
});
$this->map(Blocks::SOUL_FIRE(), function() : Writer{
return Writer::create(Ids::SOUL_FIRE)
->writeInt(StateNames::AGE, 0); //useless for soul fire, we don't track it
});
$this->mapSimple(Blocks::SOUL_SAND(), Ids::SOUL_SAND);
$this->map(Blocks::SPONGE(), function(Sponge $block) : Writer{
return Writer::create(Ids::SPONGE)

View File

@ -992,6 +992,10 @@ final class BlockStateToBlockObjectDeserializer implements BlockStateDeserialize
$in->ignored(StateNames::COVERED_BIT); //seems to be useless
return Blocks::SNOW_LAYER()->setLayers($in->readBoundedInt(StateNames::HEIGHT, 0, 7) + 1);
});
$this->map(Ids::SOUL_FIRE, function(Reader $in) : Block{
$in->ignored(StateNames::AGE); //this is useless for soul fire, since it doesn't have the logic associated
return Blocks::SOUL_FIRE();
});
$this->map(Ids::SOUL_SAND, fn() => Blocks::SOUL_SAND());
$this->map(Ids::SPONGE, function(Reader $in) : Block{
return Blocks::SPONGE()->setWet(match($type = $in->readString(StateNames::SPONGE_TYPE)){

View File

@ -1613,7 +1613,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
}
$block = $target->getSide($face);
if($block->getTypeId() === BlockTypeIds::FIRE){
if($block->getTypeId() === BlockTypeIds::FIRE || $block->getTypeId() === BlockTypeIds::SOUL_FIRE){
$this->getWorld()->setBlock($block->getPosition(), VanillaBlocks::AIR());
$this->getWorld()->addSound($block->getPosition()->add(0.5, 0.5, 0.5), new FireExtinguishSound());
return true;

File diff suppressed because one or more lines are too long