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
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
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();
}
}

View File

@ -29,6 +29,7 @@ use pocketmine\block\inventory\BrewingStandInventory;
use pocketmine\block\inventory\EnchantInventory;
use pocketmine\block\inventory\FurnaceInventory;
use pocketmine\block\inventory\HopperInventory;
use pocketmine\block\inventory\LoomInventory;
use pocketmine\inventory\CreativeInventory;
use pocketmine\inventory\Inventory;
use pocketmine\inventory\transaction\action\SlotChangeAction;
@ -161,6 +162,8 @@ class InventoryManager{
//if the class isn't final, not to mention being inflexible.
if($inv instanceof BlockInventory){
switch(true){
case $inv instanceof LoomInventory:
return [ContainerOpenPacket::blockInvVec3($id, WindowTypes::LOOM, $inv->getHolder())];
case $inv instanceof FurnaceInventory:
//TODO: specialized furnace types
return [ContainerOpenPacket::blockInvVec3($id, WindowTypes::FURNACE, $inv->getHolder())];

View File

@ -25,6 +25,7 @@ namespace pocketmine\network\mcpe\convert;
use pocketmine\block\BlockLegacyIds;
use pocketmine\block\inventory\AnvilInventory;
use pocketmine\block\inventory\EnchantInventory;
use pocketmine\block\inventory\LoomInventory;
use pocketmine\crafting\CraftingGrid;
use pocketmine\inventory\Inventory;
use pocketmine\inventory\transaction\action\CreateItemAction;
@ -266,7 +267,9 @@ class TypeConverter{
$this->mapUIInventory($pSlot, UIInventorySlotOffset::ANVIL, $current,
function(Inventory $i) : bool{ return $i instanceof AnvilInventory; }) ??
$this->mapUIInventory($pSlot, UIInventorySlotOffset::ENCHANTING_TABLE, $current,
function(Inventory $i) : bool{ return $i instanceof EnchantInventory; });
function(Inventory $i) : bool{ return $i instanceof EnchantInventory; }) ??
$this->mapUIInventory($pSlot, UIInventorySlotOffset::LOOM, $current,
fn(Inventory $i) => $i instanceof LoomInventory);
}
if($mapped === null){
throw new \UnexpectedValueException("Unmatched UI inventory slot offset $pSlot");

View File

@ -277,6 +277,7 @@ class InGamePacketHandler extends PacketHandler{
if($isCraftingPart){
if($this->craftingTransaction === null){
//TODO: this might not be crafting if there is a special inventory open (anvil, enchanting, loom etc)
$this->craftingTransaction = new CraftingTransaction($this->player, $this->player->getServer()->getCraftingManager(), $actions);
}else{
foreach($actions as $action){

File diff suppressed because one or more lines are too long