mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 01:46:04 +00:00
Merge branch 'next-major' into modern-world-support
This commit is contained in:
@ -38,18 +38,17 @@ class BlockBreakInfo{
|
||||
*/
|
||||
public const INCOMPATIBLE_TOOL_MULTIPLIER = 5.0;
|
||||
|
||||
private float $hardness;
|
||||
private float $blastResistance;
|
||||
private int $toolType;
|
||||
private int $toolHarvestLevel;
|
||||
|
||||
/**
|
||||
* @param float|null $blastResistance default 5x hardness
|
||||
*/
|
||||
public function __construct(float $hardness, int $toolType = BlockToolType::NONE, int $toolHarvestLevel = 0, ?float $blastResistance = null){
|
||||
$this->hardness = $hardness;
|
||||
$this->toolType = $toolType;
|
||||
$this->toolHarvestLevel = $toolHarvestLevel;
|
||||
public function __construct(
|
||||
private float $hardness,
|
||||
private int $toolType = BlockToolType::NONE,
|
||||
private int $toolHarvestLevel = 0,
|
||||
?float $blastResistance = null
|
||||
){
|
||||
$this->blastResistance = $blastResistance ?? $hardness * 5;
|
||||
}
|
||||
|
||||
|
@ -391,6 +391,7 @@ class BlockFactory{
|
||||
$this->registerAllMeta(new Stair(new BID(Ids::STONE_BRICK_STAIRS, 0), "Stone Brick Stairs", $stoneBreakInfo));
|
||||
$this->registerAllMeta(new Stair(new BID(Ids::MOSSY_STONE_BRICK_STAIRS, 0), "Mossy Stone Brick Stairs", $stoneBreakInfo));
|
||||
$this->registerAllMeta(new StoneButton(new BID(Ids::STONE_BUTTON, 0), "Stone Button", new BlockBreakInfo(0.5, BlockToolType::PICKAXE)));
|
||||
$this->registerAllMeta(new Stonecutter(new BID(Ids::STONECUTTER_BLOCK, 0, ItemIds::STONECUTTER_BLOCK), "Stonecutter", new BlockBreakInfo(3.5, BlockToolType::PICKAXE)));
|
||||
$this->registerAllMeta(new StonePressurePlate(new BID(Ids::STONE_PRESSURE_PLATE, 0), "Stone Pressure Plate", new BlockBreakInfo(0.5, BlockToolType::PICKAXE, ToolTier::WOOD()->getHarvestLevel())));
|
||||
|
||||
//TODO: in the future this won't be the same for all the types
|
||||
@ -431,7 +432,7 @@ class BlockFactory{
|
||||
$this->registerSlabWithDoubleHighBitsRemapping($slabType);
|
||||
}
|
||||
|
||||
$this->registerAllMeta(new Opaque(new BID(Ids::STONECUTTER, 0), "Stonecutter", new BlockBreakInfo(3.5, BlockToolType::PICKAXE, ToolTier::WOOD()->getHarvestLevel())));
|
||||
$this->registerAllMeta(new Opaque(new BID(Ids::STONECUTTER, 0), "Legacy Stonecutter", new BlockBreakInfo(3.5, BlockToolType::PICKAXE, ToolTier::WOOD()->getHarvestLevel())));
|
||||
$this->registerAllMeta(new Sugarcane(new BID(Ids::REEDS_BLOCK, 0, ItemIds::REEDS), "Sugarcane", BlockBreakInfo::instant()));
|
||||
$this->registerAllMeta(new SweetBerryBush(new BID(Ids::SWEET_BERRY_BUSH, 0, ItemIds::SWEET_BERRIES), "Sweet Berry Bush", BlockBreakInfo::instant()));
|
||||
$this->registerAllMeta(new TNT(new BID(Ids::TNT, 0), "TNT", BlockBreakInfo::instant()));
|
||||
@ -641,7 +642,6 @@ class BlockFactory{
|
||||
//TODO: minecraft:seagrass
|
||||
//TODO: minecraft:smithing_table
|
||||
//TODO: minecraft:sticky_piston
|
||||
//TODO: minecraft:stonecutter_block
|
||||
//TODO: minecraft:structure_block
|
||||
//TODO: minecraft:turtle_egg
|
||||
//endregion
|
||||
|
@ -27,31 +27,25 @@ use pocketmine\block\tile\Tile;
|
||||
use pocketmine\utils\Utils;
|
||||
|
||||
class BlockIdentifier{
|
||||
|
||||
private int $blockId;
|
||||
private int $variant;
|
||||
private ?int $itemId;
|
||||
/** @phpstan-var class-string<Tile>|null */
|
||||
private ?string $tileClass;
|
||||
|
||||
/**
|
||||
* @phpstan-param class-string<Tile>|null $tileClass
|
||||
*/
|
||||
public function __construct(int $blockId, int $variant, ?int $itemId = null, ?string $tileClass = null){
|
||||
public function __construct(
|
||||
private int $blockId,
|
||||
private int $variant,
|
||||
private ?int $itemId = null,
|
||||
private ?string $tileClass = null
|
||||
){
|
||||
if($blockId < 0){
|
||||
throw new \InvalidArgumentException("Block ID may not be negative");
|
||||
}
|
||||
if($variant < 0){
|
||||
throw new \InvalidArgumentException("Block variant may not be negative");
|
||||
}
|
||||
$this->blockId = $blockId;
|
||||
$this->variant = $variant;
|
||||
$this->itemId = $itemId;
|
||||
|
||||
if($tileClass !== null){
|
||||
Utils::testValidInstance($tileClass, Tile::class);
|
||||
}
|
||||
$this->tileClass = $tileClass;
|
||||
}
|
||||
|
||||
public function getBlockId() : int{
|
||||
|
@ -24,16 +24,15 @@ declare(strict_types=1);
|
||||
namespace pocketmine\block;
|
||||
|
||||
class Element extends Opaque{
|
||||
|
||||
private int $atomicWeight;
|
||||
private int $group;
|
||||
private string $symbol;
|
||||
|
||||
public function __construct(BlockIdentifier $idInfo, string $name, BlockBreakInfo $breakInfo, string $symbol, int $atomicWeight, int $group){
|
||||
public function __construct(
|
||||
BlockIdentifier $idInfo,
|
||||
string $name,
|
||||
BlockBreakInfo $breakInfo,
|
||||
private string $symbol,
|
||||
private int $atomicWeight,
|
||||
private int $group
|
||||
){
|
||||
parent::__construct($idInfo, $name, $breakInfo);
|
||||
$this->atomicWeight = $atomicWeight;
|
||||
$this->group = $group;
|
||||
$this->symbol = $symbol;
|
||||
}
|
||||
|
||||
public function getAtomicWeight() : int{
|
||||
|
@ -138,14 +138,16 @@ class FlowerPot extends Flowable{
|
||||
|
||||
$this->setPlant(null);
|
||||
$this->position->getWorld()->setBlock($this->position, $this);
|
||||
return true;
|
||||
}elseif($this->isValidPlant($plant)){
|
||||
$this->setPlant($plant);
|
||||
$item->pop();
|
||||
$this->position->getWorld()->setBlock($this->position, $this);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->setPlant($plant);
|
||||
$item->pop();
|
||||
$this->position->getWorld()->setBlock($this->position, $this);
|
||||
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getDropsForCompatibleTool(Item $item) : array{
|
||||
|
62
src/block/Stonecutter.php
Normal file
62
src/block/Stonecutter.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?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\StonecutterInventory;
|
||||
use pocketmine\block\utils\BlockDataSerializer;
|
||||
use pocketmine\block\utils\FacesOppositePlacingPlayerTrait;
|
||||
use pocketmine\block\utils\HorizontalFacingTrait;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\math\AxisAlignedBB;
|
||||
use pocketmine\math\Facing;
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\player\Player;
|
||||
|
||||
class Stonecutter extends Transparent{
|
||||
use FacesOppositePlacingPlayerTrait;
|
||||
use HorizontalFacingTrait;
|
||||
|
||||
public function writeStateToMeta() : int{
|
||||
return BlockDataSerializer::writeHorizontalFacing($this->facing);
|
||||
}
|
||||
|
||||
public function readStateFromData(int $id, int $stateMeta) : void{
|
||||
$this->facing = BlockDataSerializer::readHorizontalFacing($stateMeta);
|
||||
}
|
||||
|
||||
public function getStateBitmask() : int{
|
||||
return 0b111;
|
||||
}
|
||||
|
||||
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||
if($player !== null){
|
||||
$player->setCurrentWindow(new StonecutterInventory($this->position));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function recalculateCollisionBoxes() : array{
|
||||
return [AxisAlignedBB::one()->trim(Facing::UP, 7 / 16)];
|
||||
}
|
||||
}
|
@ -529,6 +529,7 @@ use pocketmine\utils\CloningRegistryTrait;
|
||||
* @method static StainedHardenedGlass STAINED_HARDENED_GLASS()
|
||||
* @method static StainedHardenedGlassPane STAINED_HARDENED_GLASS_PANE()
|
||||
* @method static Opaque STONE()
|
||||
* @method static Stonecutter STONECUTTER()
|
||||
* @method static Opaque STONE_BRICKS()
|
||||
* @method static Slab STONE_BRICK_SLAB()
|
||||
* @method static Stair STONE_BRICK_STAIRS()
|
||||
@ -1099,6 +1100,7 @@ final class VanillaBlocks{
|
||||
self::register("stone_pressure_plate", $factory->get(Ids::STONE_PRESSURE_PLATE, 0));
|
||||
self::register("stone_slab", $factory->get(Ids::STONE_SLAB4, 2));
|
||||
self::register("stone_stairs", $factory->get(Ids::NORMAL_STONE_STAIRS, 0));
|
||||
self::register("stonecutter", $factory->get(Ids::STONECUTTER_BLOCK, 2));
|
||||
self::register("stripped_acacia_log", $factory->get(Ids::STRIPPED_ACACIA_LOG, 0));
|
||||
self::register("stripped_acacia_wood", $factory->get(Ids::WOOD, 12));
|
||||
self::register("stripped_birch_log", $factory->get(Ids::STRIPPED_BIRCH_LOG, 0));
|
||||
|
@ -33,12 +33,10 @@ use pocketmine\world\sound\Sound;
|
||||
class DoubleChestInventory extends BaseInventory implements BlockInventory, InventoryHolder{
|
||||
use AnimatedBlockInventoryTrait;
|
||||
|
||||
private ChestInventory $left;
|
||||
private ChestInventory $right;
|
||||
|
||||
public function __construct(ChestInventory $left, ChestInventory $right){
|
||||
$this->left = $left;
|
||||
$this->right = $right;
|
||||
public function __construct(
|
||||
private ChestInventory $left,
|
||||
private ChestInventory $right
|
||||
){
|
||||
$this->holder = $this->left->getHolder();
|
||||
parent::__construct();
|
||||
}
|
||||
|
@ -43,12 +43,12 @@ class EnderChestInventory extends DelegateInventory implements BlockInventory{
|
||||
onClose as animatedBlockInventoryTrait_onClose;
|
||||
}
|
||||
|
||||
private PlayerEnderInventory $inventory;
|
||||
|
||||
public function __construct(Position $holder, PlayerEnderInventory $inventory){
|
||||
public function __construct(
|
||||
Position $holder,
|
||||
private PlayerEnderInventory $inventory
|
||||
){
|
||||
parent::__construct($inventory);
|
||||
$this->holder = $holder;
|
||||
$this->inventory = $inventory;
|
||||
}
|
||||
|
||||
public function getEnderInventory() : PlayerEnderInventory{
|
||||
|
@ -35,11 +35,11 @@ class FurnaceInventory extends SimpleInventory implements BlockInventory{
|
||||
public const SLOT_FUEL = 1;
|
||||
public const SLOT_RESULT = 2;
|
||||
|
||||
private FurnaceType $furnaceType;
|
||||
|
||||
public function __construct(Position $holder, FurnaceType $furnaceType){
|
||||
public function __construct(
|
||||
Position $holder,
|
||||
private FurnaceType $furnaceType
|
||||
){
|
||||
$this->holder = $holder;
|
||||
$this->furnaceType = $furnaceType;
|
||||
parent::__construct(3);
|
||||
}
|
||||
|
||||
|
39
src/block/inventory/StonecutterInventory.php
Normal file
39
src/block/inventory/StonecutterInventory.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?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\inventory\SimpleInventory;
|
||||
use pocketmine\inventory\TemporaryInventory;
|
||||
use pocketmine\world\Position;
|
||||
|
||||
class StonecutterInventory extends SimpleInventory implements BlockInventory, TemporaryInventory{
|
||||
use BlockInventoryTrait;
|
||||
|
||||
public const SLOT_INPUT = 0;
|
||||
|
||||
public function __construct(Position $holder){
|
||||
$this->holder = $holder;
|
||||
parent::__construct(1);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user