implemented lantern

This commit is contained in:
Dylan K. Taylor 2019-07-20 17:48:09 +01:00
parent 08a654760c
commit e388ac9c8b
4 changed files with 85 additions and 1 deletions

View File

@ -224,6 +224,7 @@ class BlockFactory{
self::register(new Trapdoor(new BID(Ids::IRON_TRAPDOOR), "Iron Trapdoor", new BlockBreakInfo(5.0, BlockToolType::PICKAXE, ToolTier::WOOD()->getHarvestLevel(), 25.0)));
self::register(new ItemFrame(new BID(Ids::FRAME_BLOCK, 0, ItemIds::FRAME, TileItemFrame::class), "Item Frame"));
self::register(new Ladder(new BID(Ids::LADDER), "Ladder"));
self::register(new Lantern(new BID(Ids::LANTERN), "Lantern", new BlockBreakInfo(5.0, BlockToolType::PICKAXE, ToolTier::WOOD()->getHarvestLevel())));
self::register(new Solid(new BID(Ids::LAPIS_BLOCK), "Lapis Lazuli Block", new BlockBreakInfo(3.0, BlockToolType::PICKAXE, ToolTier::STONE()->getHarvestLevel())));
self::register(new LapisOre(new BID(Ids::LAPIS_ORE), "Lapis Lazuli Ore"));
self::register(new Lava(new BIDFlattened(Ids::FLOWING_LAVA, Ids::STILL_LAVA), "Lava"));
@ -599,7 +600,6 @@ class BlockFactory{
//TODO: minecraft:jigsaw
//TODO: minecraft:jukebox
//TODO: minecraft:kelp
//TODO: minecraft:lantern
//TODO: minecraft:lava_cauldron
//TODO: minecraft:lectern
//TODO: minecraft:lit_blast_furnace

View File

@ -95,6 +95,8 @@ interface BlockLegacyMetadata{
public const ITEM_FRAME_FLAG_HAS_MAP = 0x04;
public const LANTERN_FLAG_HANGING = 0x01;
public const LEAVES_FLAG_NO_DECAY = 0x04;
public const LEAVES_FLAG_CHECK_DECAY = 0x08;

View File

@ -0,0 +1,80 @@
<?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\item\Item;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\player\Player;
use pocketmine\world\BlockTransaction;
class Lantern extends Transparent{
/** @var bool */
protected $hanging = false;
public function readStateFromData(int $id, int $stateMeta) : void{
$this->hanging = ($stateMeta & BlockLegacyMetadata::LANTERN_FLAG_HANGING) !== 0;
}
protected function writeStateToMeta() : int{
return $this->hanging ? BlockLegacyMetadata::LANTERN_FLAG_HANGING : 0;
}
public function getStateBitmask() : int{
return 0b1;
}
public function getLightLevel() : int{
return 15;
}
protected function recalculateBoundingBox() : ?AxisAlignedBB{
return AxisAlignedBB::one()
->trim(Facing::UP, $this->hanging ? 6 / 16 : 8 / 16)
->trim(Facing::DOWN, $this->hanging ? 2 / 16 : 0)
->squash(Facing::AXIS_X, 5 / 16)
->squash(Facing::AXIS_Z, 5 / 16);
}
protected function canAttachTo(Block $b) : bool{
return !$b->isTransparent();
}
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if(!$this->canAttachTo($this->world->getBlock($blockReplace->up())) and !$this->canAttachTo($this->world->getBlock($blockReplace->down()))){
return false;
}
$this->hanging = ($face === Facing::DOWN or !$this->canAttachTo($this->world->getBlock($blockReplace->down())));
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
}
public function onNearbyBlockChange() : void{
if(!$this->canAttachTo($this->world->getBlock($this->hanging ? $this->up() : $this->down()))){
$this->world->useBreakOn($this);
}
}
}

View File

@ -410,6 +410,7 @@ use function assert;
* @method static WoodenTrapdoor JUNGLE_TRAPDOOR()
* @method static Wood JUNGLE_WOOD()
* @method static Ladder LADDER()
* @method static Lantern LANTERN()
* @method static Solid LAPIS_LAZULI()
* @method static LapisOre LAPIS_LAZULI_ORE()
* @method static DoubleTallGrass LARGE_FERN()
@ -1071,6 +1072,7 @@ final class VanillaBlocks{
self::register("jungle_trapdoor", BlockFactory::get(403));
self::register("jungle_wood", BlockFactory::get(467, 3));
self::register("ladder", BlockFactory::get(65, 2));
self::register("lantern", BlockFactory::get(463));
self::register("lapis_lazuli", BlockFactory::get(22));
self::register("lapis_lazuli_ore", BlockFactory::get(21));
self::register("large_fern", BlockFactory::get(175, 3));