diff --git a/src/pocketmine/block/Block.php b/src/pocketmine/block/Block.php index 5f5df3e8d..13f4f43a2 100644 --- a/src/pocketmine/block/Block.php +++ b/src/pocketmine/block/Block.php @@ -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; + } } diff --git a/src/pocketmine/block/Cactus.php b/src/pocketmine/block/Cactus.php index ae6692517..d4ecc9781 100644 --- a/src/pocketmine/block/Cactus.php +++ b/src/pocketmine/block/Cactus.php @@ -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; diff --git a/src/pocketmine/block/Cake.php b/src/pocketmine/block/Cake.php index 8d1cd4b8a..51ea82f0f 100644 --- a/src/pocketmine/block/Cake.php +++ b/src/pocketmine/block/Cake.php @@ -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; } diff --git a/src/pocketmine/block/CoarseDirt.php b/src/pocketmine/block/CoarseDirt.php index 91026cdc4..e26e1be74 100644 --- a/src/pocketmine/block/CoarseDirt.php +++ b/src/pocketmine/block/CoarseDirt.php @@ -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; } diff --git a/src/pocketmine/block/Dirt.php b/src/pocketmine/block/Dirt.php index 75ecc73ee..5511d9b6d 100644 --- a/src/pocketmine/block/Dirt.php +++ b/src/pocketmine/block/Dirt.php @@ -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; } diff --git a/src/pocketmine/block/DragonEgg.php b/src/pocketmine/block/DragonEgg.php index b2bd03efe..0ede5a6be 100644 --- a/src/pocketmine/block/DragonEgg.php +++ b/src/pocketmine/block/DragonEgg.php @@ -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; } diff --git a/src/pocketmine/block/Farmland.php b/src/pocketmine/block/Farmland.php index 95398761c..2dfc1f8ab 100644 --- a/src/pocketmine/block/Farmland.php +++ b/src/pocketmine/block/Farmland.php @@ -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; diff --git a/src/pocketmine/block/Fire.php b/src/pocketmine/block/Fire.php index 68b96942b..24fd42fe8 100644 --- a/src/pocketmine/block/Fire.php +++ b/src/pocketmine/block/Fire.php @@ -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()); } } } diff --git a/src/pocketmine/block/Grass.php b/src/pocketmine/block/Grass.php index cc0d6588f..fe852a012 100644 --- a/src/pocketmine/block/Grass.php +++ b/src/pocketmine/block/Grass.php @@ -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; } diff --git a/src/pocketmine/block/GrassPath.php b/src/pocketmine/block/GrassPath.php index 640da5daf..e6e003429 100644 --- a/src/pocketmine/block/GrassPath.php +++ b/src/pocketmine/block/GrassPath.php @@ -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()); } } diff --git a/src/pocketmine/block/Ice.php b/src/pocketmine/block/Ice.php index 893a34782..eccf9dee5 100644 --- a/src/pocketmine/block/Ice.php +++ b/src/pocketmine/block/Ice.php @@ -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); } diff --git a/src/pocketmine/block/Lava.php b/src/pocketmine/block/Lava.php index 48899e7ef..e897a606b 100644 --- a/src/pocketmine/block/Lava.php +++ b/src/pocketmine/block/Lava.php @@ -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); } diff --git a/src/pocketmine/block/Liquid.php b/src/pocketmine/block/Liquid.php index b912e5860..c5005148c 100644 --- a/src/pocketmine/block/Liquid.php +++ b/src/pocketmine/block/Liquid.php @@ -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; } diff --git a/src/pocketmine/block/MelonStem.php b/src/pocketmine/block/MelonStem.php index 9486b4df3..0684786c0 100644 --- a/src/pocketmine/block/MelonStem.php +++ b/src/pocketmine/block/MelonStem.php @@ -26,6 +26,6 @@ namespace pocketmine\block; class MelonStem extends Stem{ protected function getPlant() : Block{ - return BlockFactory::get(BlockLegacyIds::MELON_BLOCK); + return VanillaBlocks::MELON(); } } diff --git a/src/pocketmine/block/Mycelium.php b/src/pocketmine/block/Mycelium.php index ef5ac71c3..1fb34909e 100644 --- a/src/pocketmine/block/Mycelium.php +++ b/src/pocketmine/block/Mycelium.php @@ -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()); diff --git a/src/pocketmine/block/PumpkinStem.php b/src/pocketmine/block/PumpkinStem.php index 12ae62c16..fd909a7db 100644 --- a/src/pocketmine/block/PumpkinStem.php +++ b/src/pocketmine/block/PumpkinStem.php @@ -26,6 +26,6 @@ namespace pocketmine\block; class PumpkinStem extends Stem{ protected function getPlant() : Block{ - return BlockFactory::get(BlockLegacyIds::PUMPKIN); + return VanillaBlocks::PUMPKIN(); } } diff --git a/src/pocketmine/block/SnowLayer.php b/src/pocketmine/block/SnowLayer.php index 1960eea1b..7023691da 100644 --- a/src/pocketmine/block/SnowLayer.php +++ b/src/pocketmine/block/SnowLayer.php @@ -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); } } diff --git a/src/pocketmine/block/Sugarcane.php b/src/pocketmine/block/Sugarcane.php index 92488993d..42fba2232 100644 --- a/src/pocketmine/block/Sugarcane.php +++ b/src/pocketmine/block/Sugarcane.php @@ -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; } } diff --git a/src/pocketmine/block/TNT.php b/src/pocketmine/block/TNT.php index 882e1ff9d..4aa5fd250 100644 --- a/src/pocketmine/block/TNT.php +++ b/src/pocketmine/block/TNT.php @@ -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)); diff --git a/src/pocketmine/block/VanillaBlocks.php b/src/pocketmine/block/VanillaBlocks.php new file mode 100644 index 000000000..930fd6c58 --- /dev/null +++ b/src/pocketmine/block/VanillaBlocks.php @@ -0,0 +1,2556 @@ +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()); diff --git a/src/pocketmine/entity/object/Painting.php b/src/pocketmine/entity/object/Painting.php index 3f1b26a3f..9be7bc43d 100644 --- a/src/pocketmine/entity/object/Painting.php +++ b/src/pocketmine/entity/object/Painting.php @@ -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{ diff --git a/src/pocketmine/entity/projectile/SplashPotion.php b/src/pocketmine/entity/projectile/SplashPotion.php index 1b408978c..a930cd37e 100644 --- a/src/pocketmine/entity/projectile/SplashPotion.php +++ b/src/pocketmine/entity/projectile/SplashPotion.php @@ -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()); } } } diff --git a/src/pocketmine/item/Banner.php b/src/pocketmine/item/Banner.php index 55a80ee61..caf0dc8b5 100644 --- a/src/pocketmine/item/Banner.php +++ b/src/pocketmine/item/Banner.php @@ -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{ diff --git a/src/pocketmine/item/Bed.php b/src/pocketmine/item/Bed.php index cf1095ab6..9212b80b0 100644 --- a/src/pocketmine/item/Bed.php +++ b/src/pocketmine/item/Bed.php @@ -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{ diff --git a/src/pocketmine/item/BeetrootSeeds.php b/src/pocketmine/item/BeetrootSeeds.php index 216148a72..2ef2250da 100644 --- a/src/pocketmine/item/BeetrootSeeds.php +++ b/src/pocketmine/item/BeetrootSeeds.php @@ -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(); } } diff --git a/src/pocketmine/item/Bucket.php b/src/pocketmine/item/Bucket.php index 3497b9a4b..d6f880a46 100644 --- a/src/pocketmine/item/Bucket.php +++ b/src/pocketmine/item/Bucket.php @@ -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){ diff --git a/src/pocketmine/item/Carrot.php b/src/pocketmine/item/Carrot.php index 92491c432..ec5d47699 100644 --- a/src/pocketmine/item/Carrot.php +++ b/src/pocketmine/item/Carrot.php @@ -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{ diff --git a/src/pocketmine/item/CocoaBeans.php b/src/pocketmine/item/CocoaBeans.php index d1461e984..bd6ac2d1c 100644 --- a/src/pocketmine/item/CocoaBeans.php +++ b/src/pocketmine/item/CocoaBeans.php @@ -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(); } } diff --git a/src/pocketmine/item/FlintSteel.php b/src/pocketmine/item/FlintSteel.php index 7d8e07119..18772a05f 100644 --- a/src/pocketmine/item/FlintSteel.php +++ b/src/pocketmine/item/FlintSteel.php @@ -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); diff --git a/src/pocketmine/item/Item.php b/src/pocketmine/item/Item.php index 7a4c2aca1..b7bd229ca 100644 --- a/src/pocketmine/item/Item.php +++ b/src/pocketmine/item/Item.php @@ -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(); } /** diff --git a/src/pocketmine/item/ItemFactory.php b/src/pocketmine/item/ItemFactory.php index b6b076f27..b122778c8 100644 --- a/src/pocketmine/item/ItemFactory.php +++ b/src/pocketmine/item/ItemFactory.php @@ -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")); diff --git a/src/pocketmine/item/LiquidBucket.php b/src/pocketmine/item/LiquidBucket.php index 1f2b74e3c..4d2d7d791 100644 --- a/src/pocketmine/item/LiquidBucket.php +++ b/src/pocketmine/item/LiquidBucket.php @@ -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(); } } diff --git a/src/pocketmine/item/MelonSeeds.php b/src/pocketmine/item/MelonSeeds.php index f2d782058..ee397fdba 100644 --- a/src/pocketmine/item/MelonSeeds.php +++ b/src/pocketmine/item/MelonSeeds.php @@ -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(); } } diff --git a/src/pocketmine/item/Potato.php b/src/pocketmine/item/Potato.php index c9fbd32eb..f5bae0227 100644 --- a/src/pocketmine/item/Potato.php +++ b/src/pocketmine/item/Potato.php @@ -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{ diff --git a/src/pocketmine/item/PumpkinSeeds.php b/src/pocketmine/item/PumpkinSeeds.php index 048538090..f192ba90b 100644 --- a/src/pocketmine/item/PumpkinSeeds.php +++ b/src/pocketmine/item/PumpkinSeeds.php @@ -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(); } } diff --git a/src/pocketmine/item/Redstone.php b/src/pocketmine/item/Redstone.php index 6e4e054b5..b4b5d0a97 100644 --- a/src/pocketmine/item/Redstone.php +++ b/src/pocketmine/item/Redstone.php @@ -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(); } } diff --git a/src/pocketmine/item/Skull.php b/src/pocketmine/item/Skull.php index b5baae504..62d008662 100644 --- a/src/pocketmine/item/Skull.php +++ b/src/pocketmine/item/Skull.php @@ -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{ diff --git a/src/pocketmine/item/StringItem.php b/src/pocketmine/item/StringItem.php index 9497e34ab..366adfd12 100644 --- a/src/pocketmine/item/StringItem.php +++ b/src/pocketmine/item/StringItem.php @@ -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(); } } diff --git a/src/pocketmine/item/WheatSeeds.php b/src/pocketmine/item/WheatSeeds.php index d844aeea7..0a2478aef 100644 --- a/src/pocketmine/item/WheatSeeds.php +++ b/src/pocketmine/item/WheatSeeds.php @@ -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(); } } diff --git a/src/pocketmine/player/Player.php b/src/pocketmine/player/Player.php index cd1dd4a9a..7f5b95515 100644 --- a/src/pocketmine/player/Player.php +++ b/src/pocketmine/player/Player.php @@ -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; } diff --git a/src/pocketmine/world/Explosion.php b/src/pocketmine/world/Explosion.php index c70c66bf1..3180b7caa 100644 --- a/src/pocketmine/world/Explosion.php +++ b/src/pocketmine/world/Explosion.php @@ -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){ diff --git a/src/pocketmine/world/SimpleChunkManager.php b/src/pocketmine/world/SimpleChunkManager.php index dd7bce34f..8869f4189 100644 --- a/src/pocketmine/world/SimpleChunkManager.php +++ b/src/pocketmine/world/SimpleChunkManager.php @@ -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{ diff --git a/src/pocketmine/world/biome/GrassyBiome.php b/src/pocketmine/world/biome/GrassyBiome.php index 142b18b81..9520c1a2e 100644 --- a/src/pocketmine/world/biome/GrassyBiome.php +++ b/src/pocketmine/world/biome/GrassyBiome.php @@ -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() ]); } } diff --git a/src/pocketmine/world/biome/OceanBiome.php b/src/pocketmine/world/biome/OceanBiome.php index c3274c90d..e554ca731 100644 --- a/src/pocketmine/world/biome/OceanBiome.php +++ b/src/pocketmine/world/biome/OceanBiome.php @@ -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(); diff --git a/src/pocketmine/world/biome/RiverBiome.php b/src/pocketmine/world/biome/RiverBiome.php index 7752d5da8..534107b8c 100644 --- a/src/pocketmine/world/biome/RiverBiome.php +++ b/src/pocketmine/world/biome/RiverBiome.php @@ -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(); diff --git a/src/pocketmine/world/biome/SandyBiome.php b/src/pocketmine/world/biome/SandyBiome.php index 3e45c709b..e809c6201 100644 --- a/src/pocketmine/world/biome/SandyBiome.php +++ b/src/pocketmine/world/biome/SandyBiome.php @@ -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() ]); } } diff --git a/src/pocketmine/world/biome/SnowyBiome.php b/src/pocketmine/world/biome/SnowyBiome.php index 19d8ca057..ed1061d63 100644 --- a/src/pocketmine/world/biome/SnowyBiome.php +++ b/src/pocketmine/world/biome/SnowyBiome.php @@ -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() ]); } } diff --git a/src/pocketmine/world/generator/Flat.php b/src/pocketmine/world/generator/Flat.php index 1ea1b9b66..85e103b59 100644 --- a/src/pocketmine/world/generator/Flat.php +++ b/src/pocketmine/world/generator/Flat.php @@ -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; } diff --git a/src/pocketmine/world/generator/hell/Nether.php b/src/pocketmine/world/generator/hell/Nether.php index da8bef88a..efb11abed 100644 --- a/src/pocketmine/world/generator/hell/Nether.php +++ b/src/pocketmine/world/generator/hell/Nether.php @@ -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){ diff --git a/src/pocketmine/world/generator/normal/Normal.php b/src/pocketmine/world/generator/normal/Normal.php index dd9627283..4fc7250fd 100644 --- a/src/pocketmine/world/generator/normal/Normal.php +++ b/src/pocketmine/world/generator/normal/Normal.php @@ -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){ diff --git a/src/pocketmine/world/generator/object/BirchTree.php b/src/pocketmine/world/generator/object/BirchTree.php index 65c3365e7..c3fdc8de1 100644 --- a/src/pocketmine/world/generator/object/BirchTree.php +++ b/src/pocketmine/world/generator/object/BirchTree.php @@ -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; } diff --git a/src/pocketmine/world/generator/object/JungleTree.php b/src/pocketmine/world/generator/object/JungleTree.php index 0daeaaa67..de687b920 100644 --- a/src/pocketmine/world/generator/object/JungleTree.php +++ b/src/pocketmine/world/generator/object/JungleTree.php @@ -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); } } diff --git a/src/pocketmine/world/generator/object/OakTree.php b/src/pocketmine/world/generator/object/OakTree.php index 01d06425a..e66b7a0e2 100644 --- a/src/pocketmine/world/generator/object/OakTree.php +++ b/src/pocketmine/world/generator/object/OakTree.php @@ -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{ diff --git a/src/pocketmine/world/generator/object/SpruceTree.php b/src/pocketmine/world/generator/object/SpruceTree.php index 59f74e83d..679b5fcc0 100644 --- a/src/pocketmine/world/generator/object/SpruceTree.php +++ b/src/pocketmine/world/generator/object/SpruceTree.php @@ -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{ diff --git a/src/pocketmine/world/generator/object/TallGrass.php b/src/pocketmine/world/generator/object/TallGrass.php index eb8fc38af..80e75e5a1 100644 --- a/src/pocketmine/world/generator/object/TallGrass.php +++ b/src/pocketmine/world/generator/object/TallGrass.php @@ -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 diff --git a/src/pocketmine/world/generator/object/Tree.php b/src/pocketmine/world/generator/object/Tree.php index c3f2b72aa..be9a2adf6 100644 --- a/src/pocketmine/world/generator/object/Tree.php +++ b/src/pocketmine/world/generator/object/Tree.php @@ -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))){ diff --git a/src/pocketmine/world/generator/populator/TallGrass.php b/src/pocketmine/world/generator/populator/TallGrass.php index d46026744..4833fa6a5 100644 --- a/src/pocketmine/world/generator/populator/TallGrass.php +++ b/src/pocketmine/world/generator/populator/TallGrass.php @@ -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);