mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-20 16:00:20 +00:00
Implemented Light blocks
This commit is contained in:
parent
30149c6ed4
commit
2a0fade893
@ -558,6 +558,7 @@ class BlockFactory{
|
||||
BreakInfo::instant(),
|
||||
));
|
||||
|
||||
$this->registerBlocksR13();
|
||||
$this->registerBlocksR16();
|
||||
$this->registerBlocksR17();
|
||||
|
||||
@ -831,6 +832,10 @@ class BlockFactory{
|
||||
$this->register(new Element(new BID(Ids::ELEMENT_OGANESSON), "Oganesson", $instaBreak, "og", 118, 7));
|
||||
}
|
||||
|
||||
private function registerBlocksR13() : void{
|
||||
$this->register(new Light(new BID(Ids::LIGHT), "Light Block", BreakInfo::indestructible()));
|
||||
}
|
||||
|
||||
private function registerBlocksR16() : void{
|
||||
//for some reason, slabs have weird hardness like the legacy ones
|
||||
$slabBreakInfo = new BreakInfo(2.0, ToolType::PICKAXE, ToolTier::WOOD()->getHarvestLevel());
|
||||
|
@ -585,5 +585,7 @@ final class BlockTypeIds{
|
||||
public const POLISHED_BLACKSTONE_BRICK_STAIRS = 10558;
|
||||
public const POLISHED_BLACKSTONE_BRICK_WALL = 10559;
|
||||
public const CRACKED_POLISHED_BLACKSTONE_BRICKS = 10560;
|
||||
public const FIRST_UNUSED_BLOCK_ID = 10561;
|
||||
public const LIGHT = 10561;
|
||||
|
||||
public const FIRST_UNUSED_BLOCK_ID = 10562;
|
||||
}
|
||||
|
57
src/block/Light.php
Normal file
57
src/block/Light.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?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\data\runtime\block\BlockDataReader;
|
||||
use pocketmine\data\runtime\block\BlockDataWriter;
|
||||
|
||||
final class Light extends Flowable{
|
||||
public const MIN_LIGHT_LEVEL = 0;
|
||||
public const MAX_LIGHT_LEVEL = 15;
|
||||
|
||||
private int $level = self::MAX_LIGHT_LEVEL;
|
||||
|
||||
public function getRequiredTypeDataBits() : int{ return 4; }
|
||||
|
||||
protected function decodeType(BlockDataReader $r) : void{
|
||||
$this->level = $r->readBoundedInt(4, self::MIN_LIGHT_LEVEL, self::MAX_LIGHT_LEVEL);
|
||||
}
|
||||
|
||||
protected function encodeType(BlockDataWriter $w) : void{
|
||||
$w->writeInt(4, $this->level);
|
||||
}
|
||||
|
||||
public function getLightLevel() : int{ return $this->level; }
|
||||
|
||||
/** @return $this */
|
||||
public function setLightLevel(int $level) : self{
|
||||
if($level < self::MIN_LIGHT_LEVEL || $level > self::MAX_LIGHT_LEVEL){
|
||||
throw new \InvalidArgumentException("Light level must be in the range " . self::MIN_LIGHT_LEVEL . " ... " . self::MAX_LIGHT_LEVEL);
|
||||
}
|
||||
$this->level = $level;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function canBeReplaced() : bool{ return true; }
|
||||
}
|
@ -371,6 +371,7 @@ use pocketmine\utils\CloningRegistryTrait;
|
||||
* @method static Lectern LECTERN()
|
||||
* @method static Opaque LEGACY_STONECUTTER()
|
||||
* @method static Lever LEVER()
|
||||
* @method static Light LIGHT()
|
||||
* @method static DoublePlant LILAC()
|
||||
* @method static Flower LILY_OF_THE_VALLEY()
|
||||
* @method static WaterLily LILY_PAD()
|
||||
@ -928,6 +929,7 @@ final class VanillaBlocks{
|
||||
self::register("lectern", $factory->get(Ids::LECTERN, 0));
|
||||
self::register("legacy_stonecutter", $factory->get(Ids::LEGACY_STONECUTTER, 0));
|
||||
self::register("lever", $factory->get(Ids::LEVER, 5));
|
||||
self::register("light", $factory->get(Ids::LIGHT, 15));
|
||||
self::register("lilac", $factory->get(Ids::LILAC, 0));
|
||||
self::register("lily_of_the_valley", $factory->get(Ids::LILY_OF_THE_VALLEY, 0));
|
||||
self::register("lily_pad", $factory->get(Ids::LILY_PAD, 0));
|
||||
|
@ -77,6 +77,7 @@ use pocketmine\block\Lava;
|
||||
use pocketmine\block\Leaves;
|
||||
use pocketmine\block\Lectern;
|
||||
use pocketmine\block\Lever;
|
||||
use pocketmine\block\Light;
|
||||
use pocketmine\block\LitPumpkin;
|
||||
use pocketmine\block\Log;
|
||||
use pocketmine\block\Loom;
|
||||
@ -791,6 +792,10 @@ final class BlockObjectToBlockStateSerializer implements BlockStateSerializer{
|
||||
default => throw new BlockStateSerializeException("Invalid Lever facing " . $block->getFacing()->name()),
|
||||
});
|
||||
});
|
||||
$this->map(Blocks::LIGHT(), function(Light $block) : Writer{
|
||||
return Writer::create(Ids::LIGHT_BLOCK)
|
||||
->writeInt(StateNames::BLOCK_LIGHT_LEVEL, $block->getLightLevel());
|
||||
});
|
||||
$this->map(Blocks::LILAC(), fn(DoublePlant $block) => Helper::encodeDoublePlant($block, StringValues::DOUBLE_PLANT_TYPE_SYRINGA, Writer::create(Ids::DOUBLE_PLANT)));
|
||||
$this->map(Blocks::LILY_OF_THE_VALLEY(), fn() => Helper::encodeRedFlower(StringValues::FLOWER_TYPE_LILY_OF_THE_VALLEY));
|
||||
$this->mapSimple(Blocks::LILY_PAD(), Ids::WATERLILY);
|
||||
|
@ -25,6 +25,7 @@ namespace pocketmine\data\bedrock\block\convert;
|
||||
|
||||
use pocketmine\block\Bamboo;
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\Light;
|
||||
use pocketmine\block\Slab;
|
||||
use pocketmine\block\Stair;
|
||||
use pocketmine\block\SweetBerryBush;
|
||||
@ -640,6 +641,10 @@ final class BlockStateToBlockObjectDeserializer implements BlockStateDeserialize
|
||||
default => throw $in->badValueException(StateNames::LEVER_DIRECTION, $value),
|
||||
});
|
||||
});
|
||||
$this->map(Ids::LIGHT_BLOCK, function(Reader $in) : Block{
|
||||
return Blocks::LIGHT()
|
||||
->setLightLevel($in->readBoundedInt(StateNames::BLOCK_LIGHT_LEVEL, Light::MIN_LIGHT_LEVEL, Light::MAX_LIGHT_LEVEL));
|
||||
});
|
||||
$this->map(Ids::LIGHT_BLUE_GLAZED_TERRACOTTA, fn(Reader $in) => Helper::decodeGlazedTerracotta(DyeColor::LIGHT_BLUE(), $in));
|
||||
$this->map(Ids::LIGHT_WEIGHTED_PRESSURE_PLATE, fn(Reader $in) => Helper::decodeWeightedPressurePlate(Blocks::WEIGHTED_PRESSURE_PLATE_LIGHT(), $in));
|
||||
$this->map(Ids::LIME_GLAZED_TERRACOTTA, fn(Reader $in) => Helper::decodeGlazedTerracotta(DyeColor::LIME(), $in));
|
||||
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
namespace pocketmine\item;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\Light;
|
||||
use pocketmine\block\utils\CoralType;
|
||||
use pocketmine\block\utils\DyeColor;
|
||||
use pocketmine\block\utils\SkullType;
|
||||
@ -70,6 +71,11 @@ final class StringToItemParser extends StringToTParser{
|
||||
//wall and floor coral fans are the same item
|
||||
$result->registerBlock($prefix("coral_fan"), fn() => Blocks::CORAL_FAN()->setCoralType($coralType));
|
||||
}
|
||||
for($i = Light::MIN_LIGHT_LEVEL; $i < Light::MAX_LIGHT_LEVEL; $i++){
|
||||
//helper aliases, since we don't support passing data values in /give
|
||||
$result->registerBlock("light_$i", fn() => Blocks::LIGHT()->setLightLevel($i));
|
||||
$result->registerBlock("light_block_$i", fn() => Blocks::LIGHT()->setLightLevel($i));
|
||||
}
|
||||
|
||||
$result->registerBlock("acacia_button", fn() => Blocks::ACACIA_BUTTON());
|
||||
$result->registerBlock("acacia_door", fn() => Blocks::ACACIA_DOOR());
|
||||
@ -640,6 +646,8 @@ final class StringToItemParser extends StringToTParser{
|
||||
$result->registerBlock("lectern", fn() => Blocks::LECTERN());
|
||||
$result->registerBlock("legacy_stonecutter", fn() => Blocks::LEGACY_STONECUTTER());
|
||||
$result->registerBlock("lever", fn() => Blocks::LEVER());
|
||||
$result->registerBlock("light", fn() => Blocks::LIGHT());
|
||||
$result->registerBlock("light_block", fn() => Blocks::LIGHT());
|
||||
$result->registerBlock("light_weighted_pressure_plate", fn() => Blocks::WEIGHTED_PRESSURE_PLATE_LIGHT());
|
||||
$result->registerBlock("lilac", fn() => Blocks::LILAC());
|
||||
$result->registerBlock("lily_of_the_valley", fn() => Blocks::LILY_OF_THE_VALLEY());
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user