Implemented chain (#5454)

This commit is contained in:
ipad54 2022-12-22 18:22:04 +03:00 committed by GitHub
parent 044d35956e
commit b3473960b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 65 additions and 2 deletions

View File

@ -706,8 +706,9 @@ final class BlockTypeIds{
public const FROGLIGHT = 10679;
public const TWISTING_VINES = 10680;
public const WEEPING_VINES = 10681;
public const CHAIN = 10682;
public const FIRST_UNUSED_BLOCK_ID = 10682;
public const FIRST_UNUSED_BLOCK_ID = 10683;
private static int $nextDynamicId = self::FIRST_UNUSED_BLOCK_ID;

48
src/block/Chain.php Normal file
View File

@ -0,0 +1,48 @@
<?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\block\utils\PillarRotationTrait;
use pocketmine\block\utils\SupportType;
use pocketmine\math\Axis;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing;
final class Chain extends Transparent{
use PillarRotationTrait;
public function getSupportType(int $facing) : SupportType{
return $this->axis === Axis::Y && Facing::axis($facing) === Axis::Y ? SupportType::CENTER() : SupportType::NONE();
}
protected function recalculateCollisionBoxes() : array{
$bb = AxisAlignedBB::one();
foreach([Axis::Y, Axis::Z, Axis::X] as $axis){
if($axis !== $this->axis){
$bb->squash($axis, 13 / 32);
}
}
return [$bb];
}
}

View File

@ -153,6 +153,7 @@ use function mb_strtolower;
* @method static CartographyTable CARTOGRAPHY_TABLE()
* @method static CarvedPumpkin CARVED_PUMPKIN()
* @method static Cauldron CAULDRON()
* @method static Chain CHAIN()
* @method static ChemicalHeat CHEMICAL_HEAT()
* @method static Chest CHEST()
* @method static Opaque CHISELED_DEEPSLATE()
@ -1473,6 +1474,8 @@ final class VanillaBlocks{
self::register("twisting_vines", new NetherVines(new BID(Ids::TWISTING_VINES), "Twisting Vines", new Info(BreakInfo::instant()), Facing::UP));
self::register("weeping_vines", new NetherVines(new BID(Ids::WEEPING_VINES), "Weeping Vines", new Info(BreakInfo::instant()), Facing::DOWN));
self::register("chain", new Chain(new BID(Ids::CHAIN), "Chain", new Info(BreakInfo::pickaxe(5.0, ToolTier::WOOD()))));
}
private static function registerBlocksR17() : void{

View File

@ -45,6 +45,7 @@ use pocketmine\block\Candle;
use pocketmine\block\Carpet;
use pocketmine\block\Carrot;
use pocketmine\block\CarvedPumpkin;
use pocketmine\block\Chain;
use pocketmine\block\ChemistryTable;
use pocketmine\block\Chest;
use pocketmine\block\ChorusFlower;
@ -712,6 +713,10 @@ final class BlockObjectToStateSerializer implements BlockStateSerializer{
return Writer::create(Ids::CARVED_PUMPKIN)
->writeLegacyHorizontalFacing($block->getFacing());
});
$this->map(Blocks::CHAIN(), function(Chain $block) : Writer{
return Writer::create(Ids::CHAIN)
->writePillarAxis($block->getAxis());
});
$this->map(Blocks::CHEST(), function(Chest $block) : Writer{
return Writer::create(Ids::CHEST)
->writeHorizontalFacing($block->getFacing());

View File

@ -549,6 +549,10 @@ final class BlockStateToObjectDeserializer implements BlockStateDeserializer{
return Blocks::CARVED_PUMPKIN()
->setFacing($in->readLegacyHorizontalFacing());
});
$this->map(Ids::CHAIN, function(Reader $in) : Block{
return Blocks::CHAIN()
->setAxis($in->readPillarAxis());
});
$this->map(Ids::CHEMISTRY_TABLE, function(Reader $in) : Block{
return (match($type = $in->readString(StateNames::CHEMISTRY_TABLE_TYPE)){
StringValues::CHEMISTRY_TABLE_TYPE_COMPOUND_CREATOR => Blocks::COMPOUND_CREATOR(),

View File

@ -134,6 +134,7 @@ final class ItemSerializerDeserializerRegistrar{
$this->map1to1Block(Ids::BREWING_STAND, Blocks::BREWING_STAND());
$this->map1to1Block(Ids::CAKE, Blocks::CAKE());
$this->map1to1Block(Ids::CAULDRON, Blocks::CAULDRON());
$this->map1to1Block(Ids::CHAIN, Blocks::CHAIN());
$this->map1to1Block(Ids::COMPARATOR, Blocks::REDSTONE_COMPARATOR());
$this->map1to1Block(Ids::CRIMSON_DOOR, Blocks::CRIMSON_DOOR());
$this->map1to1Block(Ids::DARK_OAK_DOOR, Blocks::DARK_OAK_DOOR());

View File

@ -205,6 +205,7 @@ final class StringToItemParser extends StringToTParser{
$result->registerBlock("carrots", fn() => Blocks::CARROTS());
$result->registerBlock("carved_pumpkin", fn() => Blocks::CARVED_PUMPKIN());
$result->registerBlock("cauldron", fn() => Blocks::CAULDRON());
$result->registerBlock("chain", fn() => Blocks::CHAIN());
$result->registerBlock("chemical_heat", fn() => Blocks::CHEMICAL_HEAT());
$result->registerBlock("chemistry_table", fn() => Blocks::COMPOUND_CREATOR());
$result->registerBlock("chest", fn() => Blocks::CHEST());

File diff suppressed because one or more lines are too long