Added Loom blocks

these don't support doing patterns yet, but their inventories work.
This commit is contained in:
Dylan K. Taylor
2021-04-29 19:51:09 +01:00
parent b33bf1f433
commit 593a8ac529
8 changed files with 115 additions and 2 deletions

View File

@ -222,6 +222,7 @@ class BlockFactory{
$this->register(new LapisOre(new BID(Ids::LAPIS_ORE, 0), "Lapis Lazuli Ore"));
$this->register(new Lava(new BIDFlattened(Ids::FLOWING_LAVA, Ids::STILL_LAVA, 0), "Lava"));
$this->register(new Lever(new BID(Ids::LEVER, 0), "Lever"));
$this->register(new Loom(new BID(Ids::LOOM, 0), "Loom", new BlockBreakInfo(2.5, BlockToolType::AXE)));
$this->register(new Magma(new BID(Ids::MAGMA, 0), "Magma Block"));
$this->register(new Melon(new BID(Ids::MELON_BLOCK, 0), "Melon Block"));
$this->register(new MelonStem(new BID(Ids::MELON_STEM, 0, ItemIds::MELON_SEEDS), "Melon Stem"));

57
src/block/Loom.php Normal file
View 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\block\inventory\LoomInventory;
use pocketmine\block\utils\BlockDataSerializer;
use pocketmine\block\utils\FacesOppositePlacingPlayerTrait;
use pocketmine\block\utils\HorizontalFacingTrait;
use pocketmine\item\Item;
use pocketmine\math\Vector3;
use pocketmine\player\Player;
final class Loom extends Opaque{
use FacesOppositePlacingPlayerTrait;
use HorizontalFacingTrait;
public function readStateFromData(int $id, int $stateMeta) : void{
$this->facing = BlockDataSerializer::readLegacyHorizontalFacing($stateMeta & 0x3);
}
protected function writeStateToMeta() : int{
return BlockDataSerializer::writeLegacyHorizontalFacing($this->facing);
}
public function getStateBitmask() : int{
return 0b11;
}
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if($player !== null){
$player->setCurrentWindow(new LoomInventory($this->pos));
return true;
}
return false;
}
}

View File

@ -438,6 +438,7 @@ use function assert;
* @method static Glass LIME_STAINED_GLASS()
* @method static GlassPane LIME_STAINED_GLASS_PANE()
* @method static LitPumpkin LIT_PUMPKIN()
* @method static Loom LOOM()
* @method static GlazedTerracotta MAGENTA_GLAZED_TERRACOTTA()
* @method static HardenedClay MAGENTA_STAINED_CLAY()
* @method static Glass MAGENTA_STAINED_GLASS()
@ -1078,6 +1079,7 @@ final class VanillaBlocks{
self::register("lime_stained_glass", $factory->get(241, 5));
self::register("lime_stained_glass_pane", $factory->get(160, 5));
self::register("lit_pumpkin", $factory->get(91, 0));
self::register("loom", $factory->get(459, 0));
self::register("magenta_glazed_terracotta", $factory->get(222, 2));
self::register("magenta_stained_clay", $factory->get(159, 2));
self::register("magenta_stained_glass", $factory->get(241, 2));

View File

@ -0,0 +1,46 @@
<?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\inventory;
use pocketmine\player\Player;
use pocketmine\world\Position;
final class LoomInventory extends BlockInventory{
public const SLOT_BANNER = 0;
public const SLOT_DYE = 1;
public const SLOT_PATTERN = 2;
public function __construct(Position $holder, int $size = 3){
parent::__construct($holder, $size);
}
public function onClose(Player $who) : void{
parent::onClose($who);
foreach($this->getContents() as $item){
$who->dropItem($item);
}
$this->clearAll();
}
}