Merge branch 'experimental/vanilla-block-registry'

This commit is contained in:
Dylan K. Taylor 2019-07-08 19:38:09 +01:00
commit bda9bd2f2d
58 changed files with 2732 additions and 198 deletions

View File

@ -283,7 +283,7 @@ class Block extends Position implements BlockLegacyIds{
if(($t = $this->world->getTile($this)) !== null){
$t->onBlockDestroyed();
}
return $this->getWorld()->setBlock($this, BlockFactory::get(BlockLegacyIds::AIR));
return $this->getWorld()->setBlock($this, VanillaBlocks::AIR());
}
/**
@ -748,4 +748,16 @@ class Block extends Position implements BlockLegacyIds{
return $currentHit;
}
/**
* @param self $self
*
* @return static
*/
public static function cast(self $self){
if(!($self instanceof static)){
throw new \TypeError("Cannot cast from " . self::class . " to " . static::class);
}
return $self;
}
}

View File

@ -95,7 +95,7 @@ class Cactus extends Transparent{
for($y = 1; $y < 3; ++$y){
$b = $this->getWorld()->getBlockAt($this->x, $this->y + $y, $this->z);
if($b->getId() === BlockLegacyIds::AIR){
$ev = new BlockGrowEvent($b, BlockFactory::get(BlockLegacyIds::CACTUS));
$ev = new BlockGrowEvent($b, VanillaBlocks::CACTUS());
$ev->call();
if($ev->isCancelled()){
break;

View File

@ -73,7 +73,7 @@ class Cake extends Transparent implements FoodSource{
public function onNearbyBlockChange() : void{
if($this->getSide(Facing::DOWN)->getId() === BlockLegacyIds::AIR){ //Replace with common break method
$this->getWorld()->setBlock($this, BlockFactory::get(BlockLegacyIds::AIR));
$this->getWorld()->setBlock($this, VanillaBlocks::AIR());
}
}
@ -113,7 +113,7 @@ class Cake extends Transparent implements FoodSource{
$clone = clone $this;
$clone->bites++;
if($clone->bites > 6){
$clone = BlockFactory::get(BlockLegacyIds::AIR);
$clone = VanillaBlocks::AIR();
}
return $clone;
}

View File

@ -34,7 +34,7 @@ class CoarseDirt extends Dirt{
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if($face === Facing::UP and $item instanceof Hoe){
$item->applyDamage(1);
$this->getWorld()->setBlock($this, BlockFactory::get(BlockLegacyIds::DIRT));
$this->getWorld()->setBlock($this, VanillaBlocks::DIRT());
return true;
}

View File

@ -38,7 +38,7 @@ class Dirt extends Solid{
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if($face === Facing::UP and $item instanceof Hoe){
$item->applyDamage(1);
$this->getWorld()->setBlock($this, BlockFactory::get(BlockLegacyIds::FARMLAND));
$this->getWorld()->setBlock($this, VanillaBlocks::FARMLAND());
return true;
}

View File

@ -77,7 +77,7 @@ class DragonEgg extends Transparent implements Fallable{
$block = $ev->getTo();
}
$this->world->addParticle($this, new DragonEggTeleportParticle($this->x - $block->x, $this->y - $block->y, $this->z - $block->z));
$this->world->setBlock($this, BlockFactory::get(BlockLegacyIds::AIR));
$this->world->setBlock($this, VanillaBlocks::AIR());
$this->world->setBlock($block, $this);
break;
}

View File

@ -56,7 +56,7 @@ class Farmland extends Transparent{
public function onNearbyBlockChange() : void{
if($this->getSide(Facing::UP)->isSolid()){
$this->world->setBlock($this, BlockFactory::get(BlockLegacyIds::DIRT));
$this->world->setBlock($this, VanillaBlocks::DIRT());
}
}
@ -70,7 +70,7 @@ class Farmland extends Transparent{
$this->wetness--;
$this->world->setBlock($this, $this, false);
}else{
$this->world->setBlock($this, BlockFactory::get(BlockLegacyIds::DIRT));
$this->world->setBlock($this, VanillaBlocks::DIRT());
}
}elseif($this->wetness < 7){
$this->wetness = 7;

View File

@ -88,7 +88,7 @@ class Fire extends Flowable{
public function onNearbyBlockChange() : void{
if(!$this->getSide(Facing::DOWN)->isSolid() and !$this->hasAdjacentFlammableBlocks()){
$this->getWorld()->setBlock($this, BlockFactory::get(BlockLegacyIds::AIR));
$this->getWorld()->setBlock($this, VanillaBlocks::AIR());
}else{
$this->world->scheduleDelayedBlockUpdate($this, mt_rand(30, 40));
}
@ -113,12 +113,12 @@ class Fire extends Flowable{
if($this->age === 15){
if(!$down->isFlammable() and mt_rand(0, 3) === 3){ //1/4 chance to extinguish
$canSpread = false;
$result = BlockFactory::get(BlockLegacyIds::AIR);
$result = VanillaBlocks::AIR();
}
}elseif(!$this->hasAdjacentFlammableBlocks()){
$canSpread = false;
if(!$down->isSolid() or $this->age > 3){
$result = BlockFactory::get(BlockLegacyIds::AIR);
$result = VanillaBlocks::AIR();
}
}
}
@ -170,7 +170,7 @@ class Fire extends Flowable{
$fire->age = min(15, $fire->age + (mt_rand(0, 4) >> 2));
$this->world->setBlock($block, $fire);
}else{
$this->world->setBlock($block, BlockFactory::get(BlockLegacyIds::AIR));
$this->world->setBlock($block, VanillaBlocks::AIR());
}
}
}

View File

@ -56,7 +56,7 @@ class Grass extends Solid{
$lightAbove = $this->world->getFullLightAt($this->x, $this->y + 1, $this->z);
if($lightAbove < 4 and $this->world->getBlockAt($this->x, $this->y + 1, $this->z)->getLightFilter() >= 2){
//grass dies
$ev = new BlockSpreadEvent($this, $this, BlockFactory::get(BlockLegacyIds::DIRT));
$ev = new BlockSpreadEvent($this, $this, VanillaBlocks::DIRT());
$ev->call();
if(!$ev->isCancelled()){
$this->world->setBlock($this, $ev->getNewState(), false);
@ -78,7 +78,7 @@ class Grass extends Solid{
continue;
}
$ev = new BlockSpreadEvent($b, $this, BlockFactory::get(BlockLegacyIds::GRASS));
$ev = new BlockSpreadEvent($b, $this, VanillaBlocks::GRASS());
$ev->call();
if(!$ev->isCancelled()){
$this->world->setBlock($b, $ev->getNewState(), false);
@ -98,12 +98,12 @@ class Grass extends Solid{
return true;
}elseif($item instanceof Hoe){
$item->applyDamage(1);
$this->getWorld()->setBlock($this, BlockFactory::get(BlockLegacyIds::FARMLAND));
$this->getWorld()->setBlock($this, VanillaBlocks::FARMLAND());
return true;
}elseif($item instanceof Shovel and $this->getSide(Facing::UP)->getId() === BlockLegacyIds::AIR){
$item->applyDamage(1);
$this->getWorld()->setBlock($this, BlockFactory::get(BlockLegacyIds::GRASS_PATH));
$this->getWorld()->setBlock($this, VanillaBlocks::GRASS_PATH());
return true;
}

View File

@ -40,7 +40,7 @@ class GrassPath extends Transparent{
public function onNearbyBlockChange() : void{
if($this->getSide(Facing::UP)->isSolid()){
$this->world->setBlock($this, BlockFactory::get(BlockLegacyIds::DIRT));
$this->world->setBlock($this, VanillaBlocks::DIRT());
}
}

View File

@ -43,7 +43,7 @@ class Ice extends Transparent{
public function onBreak(Item $item, ?Player $player = null) : bool{
if(($player === null or $player->isSurvival()) and !$item->hasEnchantment(Enchantment::SILK_TOUCH())){
return $this->getWorld()->setBlock($this, BlockFactory::get(BlockLegacyIds::WATER));
return $this->getWorld()->setBlock($this, VanillaBlocks::WATER());
}
return parent::onBreak($item, $player);
}

View File

@ -69,16 +69,16 @@ class Lava extends Liquid{
if($colliding !== null){
if($this->decay === 0){
$this->liquidCollide($colliding, BlockFactory::get(BlockLegacyIds::OBSIDIAN));
$this->liquidCollide($colliding, VanillaBlocks::OBSIDIAN());
}elseif($this->decay <= 4){
$this->liquidCollide($colliding, BlockFactory::get(BlockLegacyIds::COBBLESTONE));
$this->liquidCollide($colliding, VanillaBlocks::COBBLESTONE());
}
}
}
protected function flowIntoBlock(Block $block, int $newFlowDecay, bool $falling) : void{
if($block instanceof Water){
$block->liquidCollide($this, BlockFactory::get(BlockLegacyIds::STONE));
$block->liquidCollide($this, VanillaBlocks::STONE());
}else{
parent::flowIntoBlock($block, $newFlowDecay, $falling);
}

View File

@ -283,7 +283,7 @@ abstract class Liquid extends Transparent{
if($falling !== $this->falling or (!$falling and $newDecay !== $this->decay)){
if(!$falling and $newDecay < 0){
$this->world->setBlock($this, BlockFactory::get(BlockLegacyIds::AIR));
$this->world->setBlock($this, VanillaBlocks::AIR());
return;
}

View File

@ -26,6 +26,6 @@ namespace pocketmine\block;
class MelonStem extends Stem{
protected function getPlant() : Block{
return BlockFactory::get(BlockLegacyIds::MELON_BLOCK);
return VanillaBlocks::MELON();
}
}

View File

@ -53,7 +53,7 @@ class Mycelium extends Solid{
$block = $this->getWorld()->getBlockAt($x, $y, $z);
if($block->getId() === BlockLegacyIds::DIRT){
if($block->getSide(Facing::UP) instanceof Transparent){
$ev = new BlockSpreadEvent($block, $this, BlockFactory::get(BlockLegacyIds::MYCELIUM));
$ev = new BlockSpreadEvent($block, $this, VanillaBlocks::MYCELIUM());
$ev->call();
if(!$ev->isCancelled()){
$this->getWorld()->setBlock($block, $ev->getNewState());

View File

@ -26,6 +26,6 @@ namespace pocketmine\block;
class PumpkinStem extends Stem{
protected function getPlant() : Block{
return BlockFactory::get(BlockLegacyIds::PUMPKIN);
return VanillaBlocks::PUMPKIN();
}
}

View File

@ -89,7 +89,7 @@ class SnowLayer extends Flowable implements Fallable{
public function onRandomTick() : void{
if($this->world->getBlockLightAt($this->x, $this->y, $this->z) >= 12){
$this->getWorld()->setBlock($this, BlockFactory::get(BlockLegacyIds::AIR), false);
$this->getWorld()->setBlock($this, VanillaBlocks::AIR(), false);
}
}

View File

@ -59,7 +59,7 @@ class Sugarcane extends Flowable{
for($y = 1; $y < 3; ++$y){
$b = $this->getWorld()->getBlockAt($this->x, $this->y + $y, $this->z);
if($b->getId() === BlockLegacyIds::AIR){
$ev = new BlockGrowEvent($b, BlockFactory::get(BlockLegacyIds::SUGARCANE_BLOCK));
$ev = new BlockGrowEvent($b, VanillaBlocks::SUGARCANE());
$ev->call();
if($ev->isCancelled()){
break;
@ -98,7 +98,7 @@ class Sugarcane extends Flowable{
for($y = 1; $y < 3; ++$y){
$b = $this->getWorld()->getBlockAt($this->x, $this->y + $y, $this->z);
if($b->getId() === BlockLegacyIds::AIR){
$this->getWorld()->setBlock($b, BlockFactory::get(BlockLegacyIds::SUGARCANE_BLOCK));
$this->getWorld()->setBlock($b, VanillaBlocks::SUGARCANE());
break;
}
}

View File

@ -90,7 +90,7 @@ class TNT extends Solid{
}
public function ignite(int $fuse = 80) : void{
$this->getWorld()->setBlock($this, BlockFactory::get(BlockLegacyIds::AIR));
$this->getWorld()->setBlock($this, VanillaBlocks::AIR());
$mot = (new Random())->nextSignedFloat() * M_PI * 2;
$nbt = EntityFactory::createBaseNBT($this->add(0.5, 0, 0.5), new Vector3(-sin($mot) * 0.02, 0.2, -cos($mot) * 0.02));

File diff suppressed because it is too large Load Diff

View File

@ -23,10 +23,10 @@ declare(strict_types=1);
namespace pocketmine\block\utils;
use pocketmine\block\BlockFactory;
use pocketmine\block\BlockLegacyIds;
use pocketmine\block\Fire;
use pocketmine\block\Liquid;
use pocketmine\block\VanillaBlocks;
use pocketmine\entity\EntityFactory;
use pocketmine\entity\object\FallingBlock;
use pocketmine\math\Facing;
@ -49,7 +49,7 @@ trait FallableTrait{
$pos = $this->asPosition();
$down = $pos->world->getBlock($pos->getSide(Facing::DOWN));
if($down->getId() === BlockLegacyIds::AIR or $down instanceof Liquid or $down instanceof Fire){
$pos->world->setBlock($pos, BlockFactory::get(BlockLegacyIds::AIR));
$pos->world->setBlock($pos, VanillaBlocks::AIR());
$nbt = EntityFactory::createBaseNBT($pos->add(0.5, 0, 0.5));
$nbt->setInt("TileID", $this->getId());

View File

@ -23,8 +23,7 @@ declare(strict_types=1);
namespace pocketmine\entity\object;
use pocketmine\block\BlockFactory;
use pocketmine\block\BlockLegacyIds;
use pocketmine\block\VanillaBlocks;
use pocketmine\entity\Entity;
use pocketmine\event\entity\EntityDamageByEntityEvent;
use pocketmine\item\Item;
@ -109,7 +108,7 @@ class Painting extends Entity{
//non-living entities don't have a way to create drops generically yet
$this->world->dropItem($this, ItemFactory::get(Item::PAINTING));
}
$this->world->addParticle($this->add(0.5, 0.5, 0.5), new DestroyBlockParticle(BlockFactory::get(BlockLegacyIds::PLANKS)));
$this->world->addParticle($this->add(0.5, 0.5, 0.5), new DestroyBlockParticle(VanillaBlocks::OAK_PLANKS()));
}
protected function recalculateBoundingBox() : void{

View File

@ -23,8 +23,8 @@ declare(strict_types=1);
namespace pocketmine\entity\projectile;
use pocketmine\block\BlockFactory;
use pocketmine\block\BlockLegacyIds;
use pocketmine\block\VanillaBlocks;
use pocketmine\entity\effect\EffectInstance;
use pocketmine\entity\effect\InstantEffect;
use pocketmine\entity\Living;
@ -123,11 +123,11 @@ class SplashPotion extends Throwable{
$blockIn = $event->getBlockHit()->getSide($event->getRayTraceResult()->getHitFace());
if($blockIn->getId() === BlockLegacyIds::FIRE){
$this->world->setBlock($blockIn, BlockFactory::get(BlockLegacyIds::AIR));
$this->world->setBlock($blockIn, VanillaBlocks::AIR());
}
foreach($blockIn->getHorizontalSides() as $horizontalSide){
if($horizontalSide->getId() === BlockLegacyIds::FIRE){
$this->world->setBlock($horizontalSide, BlockFactory::get(BlockLegacyIds::AIR));
$this->world->setBlock($horizontalSide, VanillaBlocks::AIR());
}
}
}

View File

@ -25,11 +25,10 @@ namespace pocketmine\item;
use Ds\Deque;
use pocketmine\block\Block;
use pocketmine\block\BlockFactory;
use pocketmine\block\BlockLegacyIds;
use pocketmine\block\tile\Banner as TileBanner;
use pocketmine\block\utils\BannerPattern;
use pocketmine\block\utils\DyeColor;
use pocketmine\block\VanillaBlocks;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\ListTag;
@ -54,7 +53,7 @@ class Banner extends Item{
}
public function getBlock() : Block{
return BlockFactory::get(BlockLegacyIds::STANDING_BANNER);
return VanillaBlocks::BANNER();
}
public function getMaxStackSize() : int{

View File

@ -24,9 +24,8 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\block\Block;
use pocketmine\block\BlockFactory;
use pocketmine\block\BlockLegacyIds;
use pocketmine\block\utils\DyeColor;
use pocketmine\block\VanillaBlocks;
class Bed extends Item{
@ -46,7 +45,7 @@ class Bed extends Item{
}
public function getBlock() : Block{
return BlockFactory::get(BlockLegacyIds::BED_BLOCK);
return VanillaBlocks::BED();
}
public function getMaxStackSize() : int{

View File

@ -24,12 +24,11 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\block\Block;
use pocketmine\block\BlockFactory;
use pocketmine\block\BlockLegacyIds;
use pocketmine\block\VanillaBlocks;
class BeetrootSeeds extends Item{
public function getBlock() : Block{
return BlockFactory::get(BlockLegacyIds::BEETROOT_BLOCK);
return VanillaBlocks::BEETROOTS();
}
}

View File

@ -24,9 +24,8 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\block\Block;
use pocketmine\block\BlockFactory;
use pocketmine\block\BlockLegacyIds;
use pocketmine\block\Liquid;
use pocketmine\block\VanillaBlocks;
use pocketmine\event\player\PlayerBucketFillEvent;
use pocketmine\math\Vector3;
use pocketmine\player\Player;
@ -47,7 +46,7 @@ class Bucket extends Item{
$ev = new PlayerBucketFillEvent($player, $blockReplace, $face, $this, $resultItem);
$ev->call();
if(!$ev->isCancelled()){
$player->getWorld()->setBlock($blockClicked, BlockFactory::get(BlockLegacyIds::AIR));
$player->getWorld()->setBlock($blockClicked, VanillaBlocks::AIR());
$player->getWorld()->addSound($blockClicked->add(0.5, 0.5, 0.5), $blockClicked->getBucketFillSound());
if($player->hasFiniteResources()){
if($stack->getCount() === 0){

View File

@ -24,13 +24,12 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\block\Block;
use pocketmine\block\BlockFactory;
use pocketmine\block\BlockLegacyIds;
use pocketmine\block\VanillaBlocks;
class Carrot extends Food{
public function getBlock() : Block{
return BlockFactory::get(BlockLegacyIds::CARROT_BLOCK);
return VanillaBlocks::CARROTS();
}
public function getFoodRestore() : int{

View File

@ -24,12 +24,11 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\block\Block;
use pocketmine\block\BlockFactory;
use pocketmine\block\BlockLegacyIds;
use pocketmine\block\VanillaBlocks;
class CocoaBeans extends Item{
public function getBlock() : Block{
return BlockFactory::get(BlockLegacyIds::COCOA);
return VanillaBlocks::COCOA_POD();
}
}

View File

@ -24,8 +24,8 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\block\Block;
use pocketmine\block\BlockFactory;
use pocketmine\block\BlockLegacyIds;
use pocketmine\block\VanillaBlocks;
use pocketmine\math\Vector3;
use pocketmine\player\Player;
use pocketmine\world\sound\FlintSteelSound;
@ -37,7 +37,7 @@ class FlintSteel extends Tool{
if($blockReplace->getId() === BlockLegacyIds::AIR){
$world = $player->getWorld();
assert($world !== null);
$world->setBlock($blockReplace, BlockFactory::get(BlockLegacyIds::FIRE));
$world->setBlock($blockReplace, VanillaBlocks::FIRE());
$world->addSound($blockReplace->add(0.5, 0.5, 0.5), new FlintSteelSound());
$this->applyDamage(1);

View File

@ -28,9 +28,8 @@ namespace pocketmine\item;
use pocketmine\block\Block;
use pocketmine\block\BlockBreakInfo;
use pocketmine\block\BlockFactory;
use pocketmine\block\BlockLegacyIds;
use pocketmine\block\BlockToolType;
use pocketmine\block\VanillaBlocks;
use pocketmine\entity\Entity;
use pocketmine\item\enchantment\Enchantment;
use pocketmine\item\enchantment\EnchantmentInstance;
@ -529,7 +528,7 @@ class Item implements ItemIds, \JsonSerializable{
* @return Block
*/
public function getBlock() : Block{
return BlockFactory::get(BlockLegacyIds::AIR);
return VanillaBlocks::AIR();
}
/**

View File

@ -28,6 +28,7 @@ use pocketmine\block\BlockLegacyIds;
use pocketmine\block\utils\DyeColor;
use pocketmine\block\utils\SkullType;
use pocketmine\block\utils\TreeType;
use pocketmine\block\VanillaBlocks;
use pocketmine\entity\EntityFactory;
use pocketmine\entity\Living;
use pocketmine\nbt\tag\CompoundTag;
@ -218,8 +219,8 @@ class ItemFactory{
self::register(new Leggings(Item::LEATHER_LEGGINGS, 0, "Leather Pants", new ArmorTypeInfo(2, 76)));
//TODO: fix metadata for buckets with still liquid in them
//the meta values are intentionally hardcoded because block IDs will change in the future
self::register(new LiquidBucket(Item::BUCKET, 8, "Water Bucket", BlockLegacyIds::FLOWING_WATER));
self::register(new LiquidBucket(Item::BUCKET, 10, "Lava Bucket", BlockLegacyIds::FLOWING_LAVA));
self::register(new LiquidBucket(Item::BUCKET, 8, "Water Bucket", VanillaBlocks::WATER()));
self::register(new LiquidBucket(Item::BUCKET, 10, "Lava Bucket", VanillaBlocks::LAVA()));
self::register(new Melon(Item::MELON, 0, "Melon"));
self::register(new MelonSeeds(Item::MELON_SEEDS, 0, "Melon Seeds"));
self::register(new MilkBucket(Item::BUCKET, 1, "Milk Bucket"));

View File

@ -24,7 +24,6 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\block\Block;
use pocketmine\block\BlockFactory;
use pocketmine\block\Lava;
use pocketmine\block\Liquid;
use pocketmine\event\player\PlayerBucketEmptyEvent;
@ -32,12 +31,13 @@ use pocketmine\math\Vector3;
use pocketmine\player\Player;
class LiquidBucket extends Item{
/** @var int|null */
protected $liquidId;
public function __construct(int $id, int $meta, string $name, int $liquidId){
/** @var Liquid */
private $liquid;
public function __construct(int $id, int $meta, string $name, Liquid $liquid){
parent::__construct($id, $meta, $name);
$this->liquidId = $liquidId;
$this->liquid = $liquid;
}
public function getMaxStackSize() : int{
@ -45,7 +45,7 @@ class LiquidBucket extends Item{
}
public function getFuelTime() : int{
if(BlockFactory::get($this->liquidId) instanceof Lava){
if($this->liquid instanceof Lava){
return 20000;
}
@ -58,23 +58,20 @@ class LiquidBucket extends Item{
}
//TODO: move this to generic placement logic
$resultBlock = BlockFactory::get($this->liquidId);
if($resultBlock instanceof Liquid){ //TODO: this should never be false
$ev = new PlayerBucketEmptyEvent($player, $blockReplace, $face, $this, ItemFactory::get(Item::BUCKET));
$ev->call();
if(!$ev->isCancelled()){
$player->getWorld()->setBlock($blockReplace, $resultBlock->getFlowingForm());
$player->getWorld()->addSound($blockClicked->add(0.5, 0.5, 0.5), $resultBlock->getBucketEmptySound());
$resultBlock = clone $this->liquid;
if($player->hasFiniteResources()){
$player->getInventory()->setItemInHand($ev->getItem());
}
return ItemUseResult::SUCCESS();
$ev = new PlayerBucketEmptyEvent($player, $blockReplace, $face, $this, ItemFactory::get(Item::BUCKET));
$ev->call();
if(!$ev->isCancelled()){
$player->getWorld()->setBlock($blockReplace, $resultBlock->getFlowingForm());
$player->getWorld()->addSound($blockClicked->add(0.5, 0.5, 0.5), $resultBlock->getBucketEmptySound());
if($player->hasFiniteResources()){
$player->getInventory()->setItemInHand($ev->getItem());
}
return ItemUseResult::FAIL();
return ItemUseResult::SUCCESS();
}
return ItemUseResult::NONE();
return ItemUseResult::FAIL();
}
}

View File

@ -24,12 +24,11 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\block\Block;
use pocketmine\block\BlockFactory;
use pocketmine\block\BlockLegacyIds;
use pocketmine\block\VanillaBlocks;
class MelonSeeds extends Item{
public function getBlock() : Block{
return BlockFactory::get(BlockLegacyIds::MELON_STEM);
return VanillaBlocks::MELON_STEM();
}
}

View File

@ -24,13 +24,12 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\block\Block;
use pocketmine\block\BlockFactory;
use pocketmine\block\BlockLegacyIds;
use pocketmine\block\VanillaBlocks;
class Potato extends Food{
public function getBlock() : Block{
return BlockFactory::get(BlockLegacyIds::POTATO_BLOCK);
return VanillaBlocks::POTATOES();
}
public function getFoodRestore() : int{

View File

@ -24,12 +24,11 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\block\Block;
use pocketmine\block\BlockFactory;
use pocketmine\block\BlockLegacyIds;
use pocketmine\block\VanillaBlocks;
class PumpkinSeeds extends Item{
public function getBlock() : Block{
return BlockFactory::get(BlockLegacyIds::PUMPKIN_STEM);
return VanillaBlocks::PUMPKIN_STEM();
}
}

View File

@ -24,12 +24,11 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\block\Block;
use pocketmine\block\BlockFactory;
use pocketmine\block\BlockLegacyIds;
use pocketmine\block\VanillaBlocks;
class Redstone extends Item{
public function getBlock() : Block{
return BlockFactory::get(BlockLegacyIds::REDSTONE_WIRE);
return VanillaBlocks::REDSTONE_WIRE();
}
}

View File

@ -24,9 +24,8 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\block\Block;
use pocketmine\block\BlockFactory;
use pocketmine\block\BlockLegacyIds;
use pocketmine\block\utils\SkullType;
use pocketmine\block\VanillaBlocks;
class Skull extends Item{
@ -39,7 +38,7 @@ class Skull extends Item{
}
public function getBlock() : Block{
return BlockFactory::get(BlockLegacyIds::SKULL_BLOCK);
return VanillaBlocks::MOB_HEAD();
}
public function getSkullType() : SkullType{

View File

@ -24,12 +24,11 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\block\Block;
use pocketmine\block\BlockFactory;
use pocketmine\block\BlockLegacyIds;
use pocketmine\block\VanillaBlocks;
class StringItem extends Item{
public function getBlock() : Block{
return BlockFactory::get(BlockLegacyIds::TRIPWIRE);
return VanillaBlocks::TRIPWIRE();
}
}

View File

@ -24,12 +24,11 @@ declare(strict_types=1);
namespace pocketmine\item;
use pocketmine\block\Block;
use pocketmine\block\BlockFactory;
use pocketmine\block\BlockLegacyIds;
use pocketmine\block\VanillaBlocks;
class WheatSeeds extends Item{
public function getBlock() : Block{
return BlockFactory::get(BlockLegacyIds::WHEAT_BLOCK);
return VanillaBlocks::WHEAT();
}
}

View File

@ -24,9 +24,9 @@ declare(strict_types=1);
namespace pocketmine\player;
use pocketmine\block\Bed;
use pocketmine\block\BlockFactory;
use pocketmine\block\BlockLegacyIds;
use pocketmine\block\UnknownBlock;
use pocketmine\block\VanillaBlocks;
use pocketmine\command\CommandSender;
use pocketmine\crafting\CraftingGrid;
use pocketmine\entity\effect\Effect;
@ -1767,7 +1767,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
$block = $target->getSide($face);
if($block->getId() === BlockLegacyIds::FIRE){
$this->world->setBlock($block, BlockFactory::get(BlockLegacyIds::AIR));
$this->world->setBlock($block, VanillaBlocks::AIR());
return true;
}

View File

@ -25,8 +25,8 @@ namespace pocketmine\world;
use pocketmine\block\Block;
use pocketmine\block\BlockFactory;
use pocketmine\block\BlockLegacyIds;
use pocketmine\block\TNT;
use pocketmine\block\VanillaBlocks;
use pocketmine\entity\Entity;
use pocketmine\event\block\BlockUpdateEvent;
use pocketmine\event\entity\EntityDamageByBlockEvent;
@ -200,7 +200,7 @@ class Explosion{
$air = ItemFactory::air();
$airBlock = BlockFactory::get(BlockLegacyIds::AIR);
$airBlock = VanillaBlocks::AIR();
foreach($this->affectedBlocks as $block){
if($block instanceof TNT){

View File

@ -25,7 +25,7 @@ namespace pocketmine\world;
use pocketmine\block\Block;
use pocketmine\block\BlockFactory;
use pocketmine\block\BlockLegacyIds;
use pocketmine\block\VanillaBlocks;
use pocketmine\world\format\Chunk;
use pocketmine\world\utils\SubChunkIteratorManager;
use const INT32_MAX;
@ -55,7 +55,7 @@ class SimpleChunkManager implements ChunkManager{
if($this->terrainPointer->moveTo($x, $y, $z, false)){
return BlockFactory::fromFullBlock($this->terrainPointer->currentSubChunk->getFullBlock($x & 0xf, $y & 0xf, $z & 0xf));
}
return BlockFactory::get(BlockLegacyIds::AIR);
return VanillaBlocks::AIR();
}
public function setBlockAt(int $x, int $y, int $z, Block $block) : bool{

View File

@ -23,18 +23,17 @@ declare(strict_types=1);
namespace pocketmine\world\biome;
use pocketmine\block\BlockFactory;
use pocketmine\block\BlockLegacyIds;
use pocketmine\block\VanillaBlocks;
abstract class GrassyBiome extends Biome{
public function __construct(){
$this->setGroundCover([
BlockFactory::get(BlockLegacyIds::GRASS),
BlockFactory::get(BlockLegacyIds::DIRT),
BlockFactory::get(BlockLegacyIds::DIRT),
BlockFactory::get(BlockLegacyIds::DIRT),
BlockFactory::get(BlockLegacyIds::DIRT)
VanillaBlocks::GRASS(),
VanillaBlocks::DIRT(),
VanillaBlocks::DIRT(),
VanillaBlocks::DIRT(),
VanillaBlocks::DIRT()
]);
}
}

View File

@ -23,19 +23,18 @@ declare(strict_types=1);
namespace pocketmine\world\biome;
use pocketmine\block\BlockFactory;
use pocketmine\block\BlockLegacyIds;
use pocketmine\block\VanillaBlocks;
use pocketmine\world\generator\populator\TallGrass;
class OceanBiome extends Biome{
public function __construct(){
$this->setGroundCover([
BlockFactory::get(BlockLegacyIds::GRAVEL),
BlockFactory::get(BlockLegacyIds::GRAVEL),
BlockFactory::get(BlockLegacyIds::GRAVEL),
BlockFactory::get(BlockLegacyIds::GRAVEL),
BlockFactory::get(BlockLegacyIds::GRAVEL)
VanillaBlocks::GRAVEL(),
VanillaBlocks::GRAVEL(),
VanillaBlocks::GRAVEL(),
VanillaBlocks::GRAVEL(),
VanillaBlocks::GRAVEL()
]);
$tallGrass = new TallGrass();

View File

@ -23,19 +23,18 @@ declare(strict_types=1);
namespace pocketmine\world\biome;
use pocketmine\block\BlockFactory;
use pocketmine\block\BlockLegacyIds;
use pocketmine\block\VanillaBlocks;
use pocketmine\world\generator\populator\TallGrass;
class RiverBiome extends Biome{
public function __construct(){
$this->setGroundCover([
BlockFactory::get(BlockLegacyIds::DIRT),
BlockFactory::get(BlockLegacyIds::DIRT),
BlockFactory::get(BlockLegacyIds::DIRT),
BlockFactory::get(BlockLegacyIds::DIRT),
BlockFactory::get(BlockLegacyIds::DIRT)
VanillaBlocks::DIRT(),
VanillaBlocks::DIRT(),
VanillaBlocks::DIRT(),
VanillaBlocks::DIRT(),
VanillaBlocks::DIRT()
]);
$tallGrass = new TallGrass();

View File

@ -23,18 +23,17 @@ declare(strict_types=1);
namespace pocketmine\world\biome;
use pocketmine\block\BlockFactory;
use pocketmine\block\BlockLegacyIds;
use pocketmine\block\VanillaBlocks;
abstract class SandyBiome extends Biome{
public function __construct(){
$this->setGroundCover([
BlockFactory::get(BlockLegacyIds::SAND),
BlockFactory::get(BlockLegacyIds::SAND),
BlockFactory::get(BlockLegacyIds::SANDSTONE),
BlockFactory::get(BlockLegacyIds::SANDSTONE),
BlockFactory::get(BlockLegacyIds::SANDSTONE)
VanillaBlocks::SAND(),
VanillaBlocks::SAND(),
VanillaBlocks::SANDSTONE(),
VanillaBlocks::SANDSTONE(),
VanillaBlocks::SANDSTONE()
]);
}
}

View File

@ -23,18 +23,17 @@ declare(strict_types=1);
namespace pocketmine\world\biome;
use pocketmine\block\BlockFactory;
use pocketmine\block\BlockLegacyIds;
use pocketmine\block\VanillaBlocks;
abstract class SnowyBiome extends Biome{
public function __construct(){
$this->setGroundCover([
BlockFactory::get(BlockLegacyIds::SNOW_LAYER),
BlockFactory::get(BlockLegacyIds::GRASS),
BlockFactory::get(BlockLegacyIds::DIRT),
BlockFactory::get(BlockLegacyIds::DIRT),
BlockFactory::get(BlockLegacyIds::DIRT)
VanillaBlocks::SNOW_LAYER(),
VanillaBlocks::GRASS(),
VanillaBlocks::DIRT(),
VanillaBlocks::DIRT(),
VanillaBlocks::DIRT()
]);
}
}

View File

@ -23,8 +23,7 @@ declare(strict_types=1);
namespace pocketmine\world\generator;
use pocketmine\block\BlockFactory;
use pocketmine\block\BlockLegacyIds;
use pocketmine\block\VanillaBlocks;
use pocketmine\item\ItemFactory;
use pocketmine\world\ChunkManager;
use pocketmine\world\format\Chunk;
@ -73,14 +72,14 @@ class Flat extends Generator{
if(isset($this->options["decoration"])){
$ores = new Ore();
$ores->setOreTypes([
new OreType(BlockFactory::get(BlockLegacyIds::COAL_ORE), 20, 16, 0, 128),
new OreType(BlockFactory::get(BlockLegacyIds::IRON_ORE), 20, 8, 0, 64),
new OreType(BlockFactory::get(BlockLegacyIds::REDSTONE_ORE), 8, 7, 0, 16),
new OreType(BlockFactory::get(BlockLegacyIds::LAPIS_ORE), 1, 6, 0, 32),
new OreType(BlockFactory::get(BlockLegacyIds::GOLD_ORE), 2, 8, 0, 32),
new OreType(BlockFactory::get(BlockLegacyIds::DIAMOND_ORE), 1, 7, 0, 16),
new OreType(BlockFactory::get(BlockLegacyIds::DIRT), 20, 32, 0, 128),
new OreType(BlockFactory::get(BlockLegacyIds::GRAVEL), 10, 16, 0, 128)
new OreType(VanillaBlocks::COAL_ORE(), 20, 16, 0, 128),
new OreType(VanillaBlocks::IRON_ORE(), 20, 8, 0, 64),
new OreType(VanillaBlocks::REDSTONE_ORE(), 8, 7, 0, 16),
new OreType(VanillaBlocks::LAPIS_LAZULI_ORE(), 1, 6, 0, 32),
new OreType(VanillaBlocks::GOLD_ORE(), 2, 8, 0, 32),
new OreType(VanillaBlocks::DIAMOND_ORE(), 1, 7, 0, 16),
new OreType(VanillaBlocks::DIRT(), 20, 32, 0, 128),
new OreType(VanillaBlocks::GRAVEL(), 10, 16, 0, 128)
]);
$this->populators[] = $ores;
}

View File

@ -23,8 +23,7 @@ declare(strict_types=1);
namespace pocketmine\world\generator\hell;
use pocketmine\block\BlockFactory;
use pocketmine\block\BlockLegacyIds;
use pocketmine\block\VanillaBlocks;
use pocketmine\world\biome\Biome;
use pocketmine\world\ChunkManager;
use pocketmine\world\generator\Generator;
@ -85,9 +84,9 @@ class Nether extends Generator{
$chunk = $this->world->getChunk($chunkX, $chunkZ);
$bedrock = BlockFactory::get(BlockLegacyIds::BEDROCK)->getFullId();
$netherrack = BlockFactory::get(BlockLegacyIds::NETHERRACK)->getFullId();
$stillLava = BlockFactory::get(BlockLegacyIds::STILL_LAVA)->getFullId();
$bedrock = VanillaBlocks::BEDROCK()->getFullId();
$netherrack = VanillaBlocks::NETHERRACK()->getFullId();
$stillLava = VanillaBlocks::LAVA()->getFullId();
for($x = 0; $x < 16; ++$x){
for($z = 0; $z < 16; ++$z){

View File

@ -23,8 +23,7 @@ declare(strict_types=1);
namespace pocketmine\world\generator\normal;
use pocketmine\block\BlockFactory;
use pocketmine\block\BlockLegacyIds;
use pocketmine\block\VanillaBlocks;
use pocketmine\world\biome\Biome;
use pocketmine\world\ChunkManager;
use pocketmine\world\generator\biome\BiomeSelector;
@ -120,14 +119,14 @@ class Normal extends Generator{
$ores = new Ore();
$ores->setOreTypes([
new OreType(BlockFactory::get(BlockLegacyIds::COAL_ORE), 20, 16, 0, 128),
new OreType(BlockFactory::get(BlockLegacyIds::IRON_ORE), 20, 8, 0, 64),
new OreType(BlockFactory::get(BlockLegacyIds::REDSTONE_ORE), 8, 7, 0, 16),
new OreType(BlockFactory::get(BlockLegacyIds::LAPIS_ORE), 1, 6, 0, 32),
new OreType(BlockFactory::get(BlockLegacyIds::GOLD_ORE), 2, 8, 0, 32),
new OreType(BlockFactory::get(BlockLegacyIds::DIAMOND_ORE), 1, 7, 0, 16),
new OreType(BlockFactory::get(BlockLegacyIds::DIRT), 20, 32, 0, 128),
new OreType(BlockFactory::get(BlockLegacyIds::GRAVEL), 10, 16, 0, 128)
new OreType(VanillaBlocks::COAL_ORE(), 20, 16, 0, 128),
new OreType(VanillaBlocks::IRON_ORE(), 20, 8, 0, 64),
new OreType(VanillaBlocks::REDSTONE_ORE(), 8, 7, 0, 16),
new OreType(VanillaBlocks::LAPIS_LAZULI_ORE(), 1, 6, 0, 32),
new OreType(VanillaBlocks::GOLD_ORE(), 2, 8, 0, 32),
new OreType(VanillaBlocks::DIAMOND_ORE(), 1, 7, 0, 16),
new OreType(VanillaBlocks::DIRT(), 20, 32, 0, 128),
new OreType(VanillaBlocks::GRAVEL(), 10, 16, 0, 128)
]);
$this->populators[] = $ores;
}
@ -173,9 +172,9 @@ class Normal extends Generator{
$biomeCache = [];
$bedrock = BlockFactory::get(BlockLegacyIds::BEDROCK)->getFullId();
$stillWater = BlockFactory::get(BlockLegacyIds::STILL_WATER)->getFullId();
$stone = BlockFactory::get(BlockLegacyIds::STONE)->getFullId();
$bedrock = VanillaBlocks::BEDROCK()->getFullId();
$stillWater = VanillaBlocks::WATER()->getFullId();
$stone = VanillaBlocks::STONE()->getFullId();
for($x = 0; $x < 16; ++$x){
for($z = 0; $z < 16; ++$z){

View File

@ -23,9 +23,7 @@ declare(strict_types=1);
namespace pocketmine\world\generator\object;
use pocketmine\block\BlockFactory;
use pocketmine\block\BlockLegacyIds;
use pocketmine\block\utils\TreeType;
use pocketmine\block\VanillaBlocks;
use pocketmine\utils\Random;
use pocketmine\world\ChunkManager;
@ -34,7 +32,7 @@ class BirchTree extends Tree{
protected $superBirch = false;
public function __construct(bool $superBirch = false){
parent::__construct(BlockFactory::get(BlockLegacyIds::LOG, TreeType::BIRCH()->getMagicNumber()), BlockFactory::get(BlockLegacyIds::LEAVES, TreeType::BIRCH()->getMagicNumber()));
parent::__construct(VanillaBlocks::BIRCH_LOG(), VanillaBlocks::BIRCH_LEAVES());
$this->superBirch = $superBirch;
}

View File

@ -23,13 +23,11 @@ declare(strict_types=1);
namespace pocketmine\world\generator\object;
use pocketmine\block\BlockFactory;
use pocketmine\block\BlockLegacyIds;
use pocketmine\block\utils\TreeType;
use pocketmine\block\VanillaBlocks;
class JungleTree extends Tree{
public function __construct(){
parent::__construct(BlockFactory::get(BlockLegacyIds::LOG, TreeType::JUNGLE()->getMagicNumber()), BlockFactory::get(BlockLegacyIds::LEAVES, TreeType::JUNGLE()->getMagicNumber()), 8);
parent::__construct(VanillaBlocks::JUNGLE_LOG(), VanillaBlocks::JUNGLE_LEAVES(), 8);
}
}

View File

@ -23,16 +23,14 @@ declare(strict_types=1);
namespace pocketmine\world\generator\object;
use pocketmine\block\BlockFactory;
use pocketmine\block\BlockLegacyIds;
use pocketmine\block\utils\TreeType;
use pocketmine\block\VanillaBlocks;
use pocketmine\utils\Random;
use pocketmine\world\ChunkManager;
class OakTree extends Tree{
public function __construct(){
parent::__construct(BlockFactory::get(BlockLegacyIds::LOG, TreeType::OAK()->getMagicNumber()), BlockFactory::get(BlockLegacyIds::LEAVES, TreeType::OAK()->getMagicNumber()));
parent::__construct(VanillaBlocks::OAK_LOG(), VanillaBlocks::OAK_LEAVES());
}
public function placeObject(ChunkManager $world, int $x, int $y, int $z, Random $random) : void{

View File

@ -23,9 +23,7 @@ declare(strict_types=1);
namespace pocketmine\world\generator\object;
use pocketmine\block\BlockFactory;
use pocketmine\block\BlockLegacyIds;
use pocketmine\block\utils\TreeType;
use pocketmine\block\VanillaBlocks;
use pocketmine\utils\Random;
use pocketmine\world\BlockTransaction;
use pocketmine\world\ChunkManager;
@ -34,7 +32,7 @@ use function abs;
class SpruceTree extends Tree{
public function __construct(){
parent::__construct(BlockFactory::get(BlockLegacyIds::LOG, TreeType::SPRUCE()->getMagicNumber()), BlockFactory::get(BlockLegacyIds::LEAVES, TreeType::SPRUCE()->getMagicNumber()), 10);
parent::__construct(VanillaBlocks::SPRUCE_LOG(), VanillaBlocks::SPRUCE_LEAVES(), 10);
}
protected function generateChunkHeight(Random $random) : int{

View File

@ -24,8 +24,8 @@ declare(strict_types=1);
namespace pocketmine\world\generator\object;
use pocketmine\block\Block;
use pocketmine\block\BlockFactory;
use pocketmine\block\BlockLegacyIds;
use pocketmine\block\VanillaBlocks;
use pocketmine\math\Vector3;
use pocketmine\utils\Random;
use pocketmine\world\ChunkManager;
@ -36,9 +36,9 @@ class TallGrass{
public static function growGrass(ChunkManager $world, Vector3 $pos, Random $random, int $count = 15, int $radius = 10) : void{
/** @var Block[] $arr */
$arr = [
BlockFactory::get(BlockLegacyIds::DANDELION),
BlockFactory::get(BlockLegacyIds::POPPY),
$tallGrass = BlockFactory::get(BlockLegacyIds::TALL_GRASS, 1),
VanillaBlocks::DANDELION(),
VanillaBlocks::POPPY(),
$tallGrass = VanillaBlocks::TALL_GRASS(),
$tallGrass,
$tallGrass,
$tallGrass

View File

@ -24,11 +24,10 @@ declare(strict_types=1);
namespace pocketmine\world\generator\object;
use pocketmine\block\Block;
use pocketmine\block\BlockFactory;
use pocketmine\block\BlockLegacyIds;
use pocketmine\block\Leaves;
use pocketmine\block\Sapling;
use pocketmine\block\utils\TreeType;
use pocketmine\block\VanillaBlocks;
use pocketmine\utils\Random;
use pocketmine\world\BlockTransaction;
use pocketmine\world\ChunkManager;
@ -121,7 +120,7 @@ abstract class Tree{
protected function placeTrunk(int $x, int $y, int $z, Random $random, int $trunkHeight, BlockTransaction $transaction) : void{
// The base dirt block
$transaction->addBlockAt($x, $y - 1, $z, BlockFactory::get(BlockLegacyIds::DIRT));
$transaction->addBlockAt($x, $y - 1, $z, VanillaBlocks::DIRT());
for($yy = 0; $yy < $trunkHeight; ++$yy){
if($this->canOverride($transaction->fetchBlockAt($x, $y + $yy, $z))){

View File

@ -23,8 +23,8 @@ declare(strict_types=1);
namespace pocketmine\world\generator\populator;
use pocketmine\block\BlockFactory;
use pocketmine\block\BlockLegacyIds;
use pocketmine\block\VanillaBlocks;
use pocketmine\utils\Random;
use pocketmine\world\ChunkManager;
@ -46,7 +46,7 @@ class TallGrass extends Populator{
$this->world = $world;
$amount = $random->nextRange(0, $this->randomAmount + 1) + $this->baseAmount;
$block = BlockFactory::get(BlockLegacyIds::TALL_GRASS, 1);
$block = VanillaBlocks::TALL_GRASS();
for($i = 0; $i < $amount; ++$i){
$x = $random->nextRange($chunkX * 16, $chunkX * 16 + 15);
$z = $random->nextRange($chunkZ * 16, $chunkZ * 16 + 15);