All types of coral now have fully dynamic types

This commit is contained in:
Dylan K. Taylor 2021-05-19 22:49:44 +01:00
parent 69fa8e8db7
commit af678f985d
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
11 changed files with 161 additions and 96 deletions

View File

@ -31,13 +31,19 @@ abstract class BaseCoral extends Transparent{
protected CoralType $coralType;
protected bool $dead = false;
public function __construct(BlockIdentifier $idInfo, string $name, BlockBreakInfo $breakInfo, CoralType $coralType){
public function __construct(BlockIdentifier $idInfo, string $name, BlockBreakInfo $breakInfo){
parent::__construct($idInfo, $name, $breakInfo);
$this->coralType = $coralType;
$this->coralType = CoralType::TUBE();
}
public function getCoralType() : CoralType{ return $this->coralType; }
/** @return $this */
public function setCoralType(CoralType $coralType) : self{
$this->coralType = $coralType;
return $this;
}
public function isDead() : bool{ return $this->dead; }
/** @return $this */

View File

@ -45,11 +45,9 @@ use pocketmine\block\tile\Jukebox as TileJukebox;
use pocketmine\block\tile\MonsterSpawner as TileMonsterSpawner;
use pocketmine\block\tile\Note as TileNote;
use pocketmine\block\tile\Skull as TileSkull;
use pocketmine\block\utils\CoralType;
use pocketmine\block\utils\DyeColor;
use pocketmine\block\utils\InvalidBlockStateException;
use pocketmine\block\utils\TreeType;
use pocketmine\data\bedrock\CoralTypeIdMap;
use pocketmine\item\Item;
use pocketmine\item\ItemIds;
use pocketmine\item\ToolTier;
@ -144,7 +142,7 @@ class BlockFactory{
$this->register(new CocoaBlock(new BID(Ids::COCOA, 0), "Cocoa Block"));
$this->register(new CoralBlock(new BID(Ids::CORAL_BLOCK, 0), "Coral Block", new BlockBreakInfo(7.0, BlockToolType::PICKAXE, ToolTier::WOOD()->getHarvestLevel())));
$this->register(new CraftingTable(new BID(Ids::CRAFTING_TABLE, 0), "Crafting Table"));
$this->register(new DaylightSensor(new BIDFlattened(Ids::DAYLIGHT_DETECTOR, Ids::DAYLIGHT_DETECTOR_INVERTED, 0, null, TileDaylightSensor::class), "Daylight Sensor"));
$this->register(new DaylightSensor(new BIDFlattened(Ids::DAYLIGHT_DETECTOR, [Ids::DAYLIGHT_DETECTOR_INVERTED], 0, null, TileDaylightSensor::class), "Daylight Sensor"));
$this->register(new DeadBush(new BID(Ids::DEADBUSH, 0), "Dead Bush"));
$this->register(new DetectorRail(new BID(Ids::DETECTOR_RAIL, 0), "Detector Rail"));
@ -187,7 +185,7 @@ class BlockFactory{
$this->register(new Flower(new BID(Ids::RED_FLOWER, Meta::FLOWER_WHITE_TULIP), "White Tulip"));
$this->register(new FlowerPot(new BID(Ids::FLOWER_POT_BLOCK, 0, ItemIds::FLOWER_POT, TileFlowerPot::class), "Flower Pot"));
$this->register(new FrostedIce(new BID(Ids::FROSTED_ICE, 0), "Frosted Ice"));
$this->register(new Furnace(new BIDFlattened(Ids::FURNACE, Ids::LIT_FURNACE, 0, null, TileFurnace::class), "Furnace"));
$this->register(new Furnace(new BIDFlattened(Ids::FURNACE, [Ids::LIT_FURNACE], 0, null, TileFurnace::class), "Furnace"));
$this->register(new Glass(new BID(Ids::GLASS, 0), "Glass"));
$this->register(new GlassPane(new BID(Ids::GLASS_PANE, 0), "Glass Pane"));
$this->register(new GlowingObsidian(new BID(Ids::GLOWINGOBSIDIAN, 0), "Glowing Obsidian"));
@ -219,7 +217,7 @@ class BlockFactory{
$this->register(new Lantern(new BID(Ids::LANTERN, 0), "Lantern", new BlockBreakInfo(5.0, BlockToolType::PICKAXE, ToolTier::WOOD()->getHarvestLevel())));
$this->register(new Opaque(new BID(Ids::LAPIS_BLOCK, 0), "Lapis Lazuli Block", new BlockBreakInfo(3.0, BlockToolType::PICKAXE, ToolTier::STONE()->getHarvestLevel())));
$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 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"));
@ -281,11 +279,11 @@ class BlockFactory{
$this->register(new Rail(new BID(Ids::RAIL, 0), "Rail"));
$this->register(new RedMushroom(new BID(Ids::RED_MUSHROOM, 0), "Red Mushroom"));
$this->register(new Redstone(new BID(Ids::REDSTONE_BLOCK, 0), "Redstone Block"));
$this->register(new RedstoneComparator(new BIDFlattened(Ids::UNPOWERED_COMPARATOR, Ids::POWERED_COMPARATOR, 0, ItemIds::COMPARATOR, TileComparator::class), "Redstone Comparator"));
$this->register(new RedstoneLamp(new BIDFlattened(Ids::REDSTONE_LAMP, Ids::LIT_REDSTONE_LAMP, 0), "Redstone Lamp"));
$this->register(new RedstoneOre(new BIDFlattened(Ids::REDSTONE_ORE, Ids::LIT_REDSTONE_ORE, 0), "Redstone Ore"));
$this->register(new RedstoneRepeater(new BIDFlattened(Ids::UNPOWERED_REPEATER, Ids::POWERED_REPEATER, 0, ItemIds::REPEATER), "Redstone Repeater"));
$this->register(new RedstoneTorch(new BIDFlattened(Ids::REDSTONE_TORCH, Ids::UNLIT_REDSTONE_TORCH, 0), "Redstone Torch"));
$this->register(new RedstoneComparator(new BIDFlattened(Ids::UNPOWERED_COMPARATOR, [Ids::POWERED_COMPARATOR], 0, ItemIds::COMPARATOR, TileComparator::class), "Redstone Comparator"));
$this->register(new RedstoneLamp(new BIDFlattened(Ids::REDSTONE_LAMP, [Ids::LIT_REDSTONE_LAMP], 0), "Redstone Lamp"));
$this->register(new RedstoneOre(new BIDFlattened(Ids::REDSTONE_ORE, [Ids::LIT_REDSTONE_ORE], 0), "Redstone Ore"));
$this->register(new RedstoneRepeater(new BIDFlattened(Ids::UNPOWERED_REPEATER, [Ids::POWERED_REPEATER], 0, ItemIds::REPEATER), "Redstone Repeater"));
$this->register(new RedstoneTorch(new BIDFlattened(Ids::REDSTONE_TORCH, [Ids::UNLIT_REDSTONE_TORCH], 0), "Redstone Torch"));
$this->register(new RedstoneWire(new BID(Ids::REDSTONE_WIRE, 0, ItemIds::REDSTONE), "Redstone"));
$this->register(new Reserved6(new BID(Ids::RESERVED6, 0), "reserved6"));
$this->register(new Sand(new BID(Ids::SAND, 0), "Sand"));
@ -387,7 +385,7 @@ class BlockFactory{
$this->register(new TripwireHook(new BID(Ids::TRIPWIRE_HOOK, 0), "Tripwire Hook"));
$this->register(new UnderwaterTorch(new BID(Ids::UNDERWATER_TORCH, 0), "Underwater Torch"));
$this->register(new Vine(new BID(Ids::VINE, 0), "Vines"));
$this->register(new Water(new BIDFlattened(Ids::FLOWING_WATER, Ids::STILL_WATER, 0), "Water"));
$this->register(new Water(new BIDFlattened(Ids::FLOWING_WATER, [Ids::STILL_WATER], 0), "Water"));
$this->register(new WaterLily(new BID(Ids::LILY_PAD, 0), "Lily Pad"));
$this->register(new WeightedPressurePlateHeavy(new BID(Ids::HEAVY_WEIGHTED_PRESSURE_PLATE, 0), "Weighted Pressure Plate Heavy"));
$this->register(new WeightedPressurePlateLight(new BID(Ids::LIGHT_WEIGHTED_PRESSURE_PLATE, 0), "Weighted Pressure Plate Light"));
@ -399,7 +397,7 @@ class BlockFactory{
$this->register(new Planks(new BID(Ids::PLANKS, $magicNumber), $name . " Planks"));
$this->register(new Sapling(new BID(Ids::SAPLING, $magicNumber), $name . " Sapling", $treeType));
$this->register(new WoodenFence(new BID(Ids::FENCE, $magicNumber), $name . " Fence"));
$this->register(new WoodenSlab(new BIDFlattened(Ids::WOODEN_SLAB, Ids::DOUBLE_WOODEN_SLAB, $treeType->getMagicNumber()), $treeType->getDisplayName()));
$this->register(new WoodenSlab(new BIDFlattened(Ids::WOODEN_SLAB, [Ids::DOUBLE_WOODEN_SLAB], $treeType->getMagicNumber()), $treeType->getDisplayName()));
//TODO: find a better way to deal with this split
$this->register(new Leaves(new BID($magicNumber >= 4 ? Ids::LEAVES2 : Ids::LEAVES, $magicNumber & 0x03), $name . " Leaves", $treeType));
@ -481,28 +479,21 @@ class BlockFactory{
$this->registerMushroomBlocks();
foreach(CoralType::getAll() as $coralType){
$coralTypeId = CoralTypeIdMap::getInstance()->toId($coralType);
$coralTypeName = $coralType->getDisplayName();
$this->register(new Coral(
new BID(Ids::CORAL, $coralTypeId),
"$coralTypeName Coral",
BlockBreakInfo::instant(),
$coralType
));
$this->register(new FloorCoralFan(
new BlockIdentifierFlattened(Ids::CORAL_FAN, Ids::CORAL_FAN_DEAD, $coralTypeId, ItemIds::CORAL_FAN),
"$coralTypeName Coral Fan",
BlockBreakInfo::instant(),
$coralType
));
$this->register(new WallCoralFan(
BlockLegacyIdHelper::getWallCoralFanIdentifier($coralType),
"$coralTypeName Wall Coral Fan",
BlockBreakInfo::instant(),
$coralType
));
}
$this->register(new Coral(
new BID(Ids::CORAL, 0),
"Coral",
BlockBreakInfo::instant(),
));
$this->register(new FloorCoralFan(
new BlockIdentifierFlattened(Ids::CORAL_FAN, [Ids::CORAL_FAN_DEAD], 0, ItemIds::CORAL_FAN),
"Coral Fan",
BlockBreakInfo::instant(),
));
$this->register(new WallCoralFan(
new BlockIdentifierFlattened(Ids::CORAL_FAN_HANG, [Ids::CORAL_FAN_HANG2, Ids::CORAL_FAN_HANG3], 0, ItemIds::CORAL_FAN),
"Wall Coral Fan",
BlockBreakInfo::instant(),
));
//region --- auto-generated TODOs for bedrock-1.11.0 ---
//TODO: minecraft:bell

View File

@ -23,21 +23,37 @@ declare(strict_types=1);
namespace pocketmine\block;
use function count;
class BlockIdentifierFlattened extends BlockIdentifier{
/** @var int */
private $secondId;
/** @var int[] */
private array $additionalIds;
public function __construct(int $blockId, int $secondId, int $variant, ?int $itemId = null, ?string $tileClass = null){
/**
* @param int[] $additionalIds
*/
public function __construct(int $blockId, array $additionalIds, int $variant, ?int $itemId = null, ?string $tileClass = null){
if(count($additionalIds) === 0){
throw new \InvalidArgumentException("Expected at least 1 additional ID");
}
parent::__construct($blockId, $variant, $itemId, $tileClass);
$this->secondId = $secondId;
$this->additionalIds = $additionalIds;
}
public function getAdditionalId(int $index) : int{
if(!isset($this->additionalIds[$index])){
throw new \InvalidArgumentException("No such ID at index $index");
}
return $this->additionalIds[$index];
}
public function getSecondId() : int{
return $this->secondId;
return $this->getAdditionalId(0);
}
public function getAllBlockIds() : array{
return [$this->getBlockId(), $this->getSecondId()];
return [$this->getBlockId(), ...$this->additionalIds];
}
}

View File

@ -26,7 +26,6 @@ namespace pocketmine\block;
use pocketmine\block\BlockIdentifier as BID;
use pocketmine\block\BlockLegacyIds as Ids;
use pocketmine\block\tile\Sign as TileSign;
use pocketmine\block\utils\CoralType;
use pocketmine\block\utils\DyeColor;
use pocketmine\block\utils\TreeType;
use pocketmine\item\ItemIds;
@ -244,17 +243,6 @@ final class BlockLegacyIdHelper{
if($id === null){
throw new \InvalidArgumentException("Stone slab type should be 1, 2, 3 or 4");
}
return new BlockIdentifierFlattened($id[0], $id[1], $meta);
}
public static function getWallCoralFanIdentifier(CoralType $type) : BlockIdentifier{
switch($type->id()){
case CoralType::TUBE()->id(): return new BID(Ids::CORAL_FAN_HANG, 0, ItemIds::CORAL_FAN);
case CoralType::BRAIN()->id(): return new BID(Ids::CORAL_FAN_HANG, 1, ItemIds::CORAL_FAN);
case CoralType::BUBBLE()->id(): return new BID(Ids::CORAL_FAN_HANG2, 0, ItemIds::CORAL_FAN);
case CoralType::FIRE()->id(): return new BID(Ids::CORAL_FAN_HANG2, 1, ItemIds::CORAL_FAN);
case CoralType::HORN()->id(): return new BID(Ids::CORAL_FAN_HANG3, 0, ItemIds::CORAL_FAN);
}
throw new AssumptionFailedError("Switch should cover all coral types");
return new BlockIdentifierFlattened($id[0], [$id[1]], $meta);
}
}

View File

@ -69,6 +69,7 @@ final class BlockLegacyMetadata{
public const CORAL_FAN_EAST_WEST = 0;
public const CORAL_FAN_NORTH_SOUTH = 1;
public const CORAL_FAN_TYPE_MASK = 0x7;
public const CORAL_FAN_HANG_FLAG_DEAD = 0x2;
@ -77,6 +78,7 @@ final class BlockLegacyMetadata{
public const CORAL_FAN_HANG2_BUBBLE = 0;
public const CORAL_FAN_HANG2_FIRE = 1;
public const CORAL_FAN_HANG3_HORN = 0;
public const CORAL_FAN_HANG_TYPE_MASK = 0x1;
public const CORAL_VARIANT_TUBE = 0;
public const CORAL_VARIANT_BRAIN = 1;

View File

@ -23,6 +23,8 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\block\utils\InvalidBlockStateException;
use pocketmine\data\bedrock\CoralTypeIdMap;
use pocketmine\item\Item;
use pocketmine\math\Vector3;
use pocketmine\player\Player;
@ -30,6 +32,26 @@ use pocketmine\world\BlockTransaction;
final class Coral extends BaseCoral{
public function readStateFromData(int $id, int $stateMeta) : void{
$coralType = CoralTypeIdMap::getInstance()->fromId($stateMeta);
if($coralType === null){
throw new InvalidBlockStateException("No such coral type");
}
$this->coralType = $coralType;
}
public function writeStateToMeta() : int{
return CoralTypeIdMap::getInstance()->toId($this->coralType);
}
public function getStateBitmask() : int{
return 0b0111;
}
public function getNonPersistentStateBitmask() : int{
return 0b0000;
}
public function readStateFromWorld() : void{
//TODO: this hack ensures correct state of coral plants, because they don't retain their dead flag in metadata
$world = $this->pos->getWorld();

View File

@ -23,7 +23,7 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\block\utils\CoralType;
use pocketmine\block\utils\InvalidBlockStateException;
use pocketmine\data\bedrock\CoralTypeIdMap;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
@ -41,13 +41,18 @@ final class FloorCoralFan extends BaseCoral{
private int $axis = Axis::X;
public function __construct(BlockIdentifierFlattened $idInfo, string $name, BlockBreakInfo $breakInfo, CoralType $coralType){
parent::__construct($idInfo, $name, $breakInfo, $coralType);
public function __construct(BlockIdentifierFlattened $idInfo, string $name, BlockBreakInfo $breakInfo){
parent::__construct($idInfo, $name, $breakInfo);
}
public function readStateFromData(int $id, int $stateMeta) : void{
$this->dead = $id === $this->idInfo->getSecondId();
$this->axis = ($stateMeta >> 3) === BlockLegacyMetadata::CORAL_FAN_EAST_WEST ? Axis::X : Axis::Z;
$coralType = CoralTypeIdMap::getInstance()->fromId($stateMeta & BlockLegacyMetadata::CORAL_FAN_TYPE_MASK);
if($coralType === null){
throw new InvalidBlockStateException("No such coral type");
}
$this->coralType = $coralType;
}
public function getId() : int{
@ -63,10 +68,15 @@ final class FloorCoralFan extends BaseCoral{
}
protected function writeStateToMeta() : int{
return ($this->axis === Axis::X ? BlockLegacyMetadata::CORAL_FAN_EAST_WEST : BlockLegacyMetadata::CORAL_FAN_NORTH_SOUTH) << 3;
return (($this->axis === Axis::X ? BlockLegacyMetadata::CORAL_FAN_EAST_WEST : BlockLegacyMetadata::CORAL_FAN_NORTH_SOUTH) << 3) |
CoralTypeIdMap::getInstance()->toId($this->coralType);
}
public function getStateBitmask() : int{
return 0b1111;
}
public function getNonPersistentStateBitmask() : int{
return 0b1000;
}

View File

@ -87,9 +87,6 @@ use function assert;
* @method static Torch BLUE_TORCH()
* @method static BoneBlock BONE_BLOCK()
* @method static Bookshelf BOOKSHELF()
* @method static Coral BRAIN_CORAL()
* @method static FloorCoralFan BRAIN_CORAL_FAN()
* @method static WallCoralFan BRAIN_WALL_CORAL_FAN()
* @method static BrewingStand BREWING_STAND()
* @method static Opaque BRICKS()
* @method static Slab BRICK_SLAB()
@ -98,9 +95,6 @@ use function assert;
* @method static GlazedTerracotta BROWN_GLAZED_TERRACOTTA()
* @method static BrownMushroom BROWN_MUSHROOM()
* @method static BrownMushroomBlock BROWN_MUSHROOM_BLOCK()
* @method static Coral BUBBLE_CORAL()
* @method static FloorCoralFan BUBBLE_CORAL_FAN()
* @method static WallCoralFan BUBBLE_WALL_CORAL_FAN()
* @method static Cactus CACTUS()
* @method static Cake CAKE()
* @method static Carpet CARPET()
@ -125,7 +119,9 @@ use function assert;
* @method static ChemistryTable COMPOUND_CREATOR()
* @method static Concrete CONCRETE()
* @method static ConcretePowder CONCRETE_POWDER()
* @method static Coral CORAL()
* @method static CoralBlock CORAL_BLOCK()
* @method static FloorCoralFan CORAL_FAN()
* @method static Flower CORNFLOWER()
* @method static Opaque CRACKED_STONE_BRICKS()
* @method static CraftingTable CRAFTING_TABLE()
@ -301,9 +297,6 @@ use function assert;
* @method static Farmland FARMLAND()
* @method static TallGrass FERN()
* @method static Fire FIRE()
* @method static Coral FIRE_CORAL()
* @method static FloorCoralFan FIRE_CORAL_FAN()
* @method static WallCoralFan FIRE_WALL_CORAL_FAN()
* @method static FlowerPot FLOWER_POT()
* @method static FrostedIce FROSTED_ICE()
* @method static Furnace FURNACE()
@ -328,9 +321,6 @@ use function assert;
* @method static HardenedGlassPane HARDENED_GLASS_PANE()
* @method static HayBale HAY_BALE()
* @method static Hopper HOPPER()
* @method static Coral HORN_CORAL()
* @method static FloorCoralFan HORN_CORAL_FAN()
* @method static WallCoralFan HORN_WALL_CORAL_FAN()
* @method static Ice ICE()
* @method static InfestedStone INFESTED_CHISELED_STONE_BRICK()
* @method static InfestedStone INFESTED_COBBLESTONE()
@ -553,12 +543,10 @@ use function assert;
* @method static TrappedChest TRAPPED_CHEST()
* @method static Tripwire TRIPWIRE()
* @method static TripwireHook TRIPWIRE_HOOK()
* @method static Coral TUBE_CORAL()
* @method static FloorCoralFan TUBE_CORAL_FAN()
* @method static WallCoralFan TUBE_WALL_CORAL_FAN()
* @method static UnderwaterTorch UNDERWATER_TORCH()
* @method static Vine VINES()
* @method static WallBanner WALL_BANNER()
* @method static WallCoralFan WALL_CORAL_FAN()
* @method static Water WATER()
* @method static WeightedPressurePlateHeavy WEIGHTED_PRESSURE_PLATE_HEAVY()
* @method static WeightedPressurePlateLight WEIGHTED_PRESSURE_PLATE_LIGHT()
@ -653,9 +641,6 @@ final class VanillaBlocks{
self::register("blue_torch", $factory->get(204, 5));
self::register("bone_block", $factory->get(216, 0));
self::register("bookshelf", $factory->get(47, 0));
self::register("brain_coral", $factory->get(386, 1));
self::register("brain_coral_fan", $factory->get(388, 1));
self::register("brain_wall_coral_fan", $factory->get(390, 1));
self::register("brewing_stand", $factory->get(117, 0));
self::register("brick_slab", $factory->get(44, 4));
self::register("brick_stairs", $factory->get(108, 0));
@ -664,9 +649,6 @@ final class VanillaBlocks{
self::register("brown_glazed_terracotta", $factory->get(232, 2));
self::register("brown_mushroom", $factory->get(39, 0));
self::register("brown_mushroom_block", $factory->get(99, 0));
self::register("bubble_coral", $factory->get(386, 2));
self::register("bubble_coral_fan", $factory->get(388, 2));
self::register("bubble_wall_coral_fan", $factory->get(391, 0));
self::register("cactus", $factory->get(81, 0));
self::register("cake", $factory->get(92, 0));
self::register("carpet", $factory->get(171, 0));
@ -691,7 +673,9 @@ final class VanillaBlocks{
self::register("compound_creator", $factory->get(238, 0));
self::register("concrete", $factory->get(236, 0));
self::register("concrete_powder", $factory->get(237, 0));
self::register("coral", $factory->get(386, 0));
self::register("coral_block", $factory->get(387, 0));
self::register("coral_fan", $factory->get(388, 0));
self::register("cornflower", $factory->get(38, 9));
self::register("cracked_stone_bricks", $factory->get(98, 2));
self::register("crafting_table", $factory->get(58, 0));
@ -867,9 +851,6 @@ final class VanillaBlocks{
self::register("farmland", $factory->get(60, 0));
self::register("fern", $factory->get(31, 2));
self::register("fire", $factory->get(51, 0));
self::register("fire_coral", $factory->get(386, 3));
self::register("fire_coral_fan", $factory->get(388, 3));
self::register("fire_wall_coral_fan", $factory->get(391, 1));
self::register("flower_pot", $factory->get(140, 0));
self::register("frosted_ice", $factory->get(207, 0));
self::register("furnace", $factory->get(61, 2));
@ -894,9 +875,6 @@ final class VanillaBlocks{
self::register("hardened_glass_pane", $factory->get(190, 0));
self::register("hay_bale", $factory->get(170, 0));
self::register("hopper", $factory->get(154, 0));
self::register("horn_coral", $factory->get(386, 4));
self::register("horn_coral_fan", $factory->get(388, 4));
self::register("horn_wall_coral_fan", $factory->get(392, 0));
self::register("ice", $factory->get(79, 0));
self::register("infested_chiseled_stone_brick", $factory->get(97, 5));
self::register("infested_cobblestone", $factory->get(97, 1));
@ -1119,12 +1097,10 @@ final class VanillaBlocks{
self::register("trapped_chest", $factory->get(146, 2));
self::register("tripwire", $factory->get(132, 0));
self::register("tripwire_hook", $factory->get(131, 0));
self::register("tube_coral", $factory->get(386, 0));
self::register("tube_coral_fan", $factory->get(388, 0));
self::register("tube_wall_coral_fan", $factory->get(390, 0));
self::register("underwater_torch", $factory->get(239, 5));
self::register("vines", $factory->get(106, 0));
self::register("wall_banner", $factory->get(177, 2));
self::register("wall_coral_fan", $factory->get(390, 0));
self::register("water", $factory->get(8, 0));
self::register("weighted_pressure_plate_heavy", $factory->get(148, 0));
self::register("weighted_pressure_plate_light", $factory->get(147, 0));

View File

@ -24,7 +24,9 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\block\utils\BlockDataSerializer;
use pocketmine\block\utils\CoralType;
use pocketmine\block\utils\HorizontalFacingTrait;
use pocketmine\block\utils\InvalidBlockStateException;
use pocketmine\data\bedrock\CoralTypeIdMap;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
@ -33,21 +35,72 @@ use pocketmine\math\Axis;
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\player\Player;
use pocketmine\utils\AssumptionFailedError;
use pocketmine\world\BlockTransaction;
final class WallCoralFan extends BaseCoral{
use HorizontalFacingTrait;
/** @var BlockIdentifierFlattened */
protected $idInfo;
public function __construct(BlockIdentifierFlattened $idInfo, string $name, BlockBreakInfo $breakInfo){
parent::__construct($idInfo, $name, $breakInfo);
}
public function readStateFromData(int $id, int $stateMeta) : void{
$this->facing = BlockDataSerializer::readCoralFacing($stateMeta >> 2);
$this->dead = ($stateMeta & BlockLegacyMetadata::CORAL_FAN_HANG_FLAG_DEAD) !== 0;
$coralTypeFlag = $stateMeta & BlockLegacyMetadata::CORAL_FAN_HANG_TYPE_MASK;
switch($id){
case $this->idInfo->getBlockId():
$this->coralType = $coralTypeFlag === BlockLegacyMetadata::CORAL_FAN_HANG_TUBE ? CoralType::TUBE() : CoralType::BRAIN();
break;
case $this->idInfo->getAdditionalId(0):
$this->coralType = $coralTypeFlag === BlockLegacyMetadata::CORAL_FAN_HANG2_BUBBLE ? CoralType::BUBBLE() : CoralType::FIRE();
break;
case $this->idInfo->getAdditionalId(1):
if($coralTypeFlag !== BlockLegacyMetadata::CORAL_FAN_HANG3_HORN){
throw new InvalidBlockStateException("Invalid CORAL_FAN_HANG3 type");
}
$this->coralType = CoralType::HORN();
break;
default:
throw new \LogicException("ID/meta doesn't match any CORAL_FAN_HANG type");
}
}
public function getId() : int{
if($this->coralType->equals(CoralType::TUBE()) || $this->coralType->equals(CoralType::BRAIN())){
return $this->idInfo->getBlockId();
}elseif($this->coralType->equals(CoralType::BUBBLE()) || $this->coralType->equals(CoralType::FIRE())){
return $this->idInfo->getAdditionalId(0);
}elseif($this->coralType->equals(CoralType::HORN())){
return $this->idInfo->getAdditionalId(1);
}
throw new AssumptionFailedError("All types of coral should be covered");
}
public function writeStateToMeta() : int{
return (BlockDataSerializer::writeCoralFacing($this->facing) << 2) | ($this->dead ? BlockLegacyMetadata::CORAL_FAN_HANG_FLAG_DEAD : 0);
$coralTypeFlag = (function() : int{
switch($this->coralType->id()){
case CoralType::TUBE()->id(): return BlockLegacyMetadata::CORAL_FAN_HANG_TUBE;
case CoralType::BRAIN()->id(): return BlockLegacyMetadata::CORAL_FAN_HANG_BRAIN;
case CoralType::BUBBLE()->id(): return BlockLegacyMetadata::CORAL_FAN_HANG2_BUBBLE;
case CoralType::FIRE()->id(): return BlockLegacyMetadata::CORAL_FAN_HANG2_FIRE;
case CoralType::HORN()->id(): return BlockLegacyMetadata::CORAL_FAN_HANG3_HORN;
default: throw new AssumptionFailedError("All types of coral should be covered");
}
})();
return (BlockDataSerializer::writeCoralFacing($this->facing) << 2) | ($this->dead ? BlockLegacyMetadata::CORAL_FAN_HANG_FLAG_DEAD : 0) | $coralTypeFlag;
}
public function getStateBitmask() : int{
return 0b1111;
}
public function getNonPersistentStateBitmask() : int{
return 0b1110;
}

View File

@ -25,6 +25,7 @@ namespace pocketmine\item;
use pocketmine\block\Block;
use pocketmine\block\BlockFactory;
use pocketmine\block\utils\CoralType;
use pocketmine\block\utils\DyeColor;
use pocketmine\block\utils\RecordType;
use pocketmine\block\utils\SkullType;
@ -77,11 +78,11 @@ class ItemFactory{
$this->register(new Clock(new ItemIdentifier(ItemIds::CLOCK, 0), "Clock"));
$this->register(new Clownfish(new ItemIdentifier(ItemIds::CLOWNFISH, 0), "Clownfish"));
$this->register(new Coal(new ItemIdentifier(ItemIds::COAL, 0), "Coal"));
$this->register(new ItemBlockWallOrFloor(new ItemIdentifier(ItemIds::CORAL_FAN, 0), VanillaBlocks::TUBE_CORAL_FAN(), VanillaBlocks::TUBE_WALL_CORAL_FAN()), true);
$this->register(new ItemBlockWallOrFloor(new ItemIdentifier(ItemIds::CORAL_FAN, 1), VanillaBlocks::BRAIN_CORAL_FAN(), VanillaBlocks::BRAIN_WALL_CORAL_FAN()), true);
$this->register(new ItemBlockWallOrFloor(new ItemIdentifier(ItemIds::CORAL_FAN, 2), VanillaBlocks::BUBBLE_CORAL_FAN(), VanillaBlocks::BUBBLE_WALL_CORAL_FAN()), true);
$this->register(new ItemBlockWallOrFloor(new ItemIdentifier(ItemIds::CORAL_FAN, 3), VanillaBlocks::FIRE_CORAL_FAN(), VanillaBlocks::FIRE_WALL_CORAL_FAN()), true);
$this->register(new ItemBlockWallOrFloor(new ItemIdentifier(ItemIds::CORAL_FAN, 4), VanillaBlocks::HORN_CORAL_FAN(), VanillaBlocks::HORN_WALL_CORAL_FAN()), true);
$this->register(new ItemBlockWallOrFloor(new ItemIdentifier(ItemIds::CORAL_FAN, 0), VanillaBlocks::CORAL_FAN()->setCoralType(CoralType::TUBE()), VanillaBlocks::WALL_CORAL_FAN()->setCoralType(CoralType::TUBE())), true);
$this->register(new ItemBlockWallOrFloor(new ItemIdentifier(ItemIds::CORAL_FAN, 1), VanillaBlocks::CORAL_FAN()->setCoralType(CoralType::BRAIN()), VanillaBlocks::WALL_CORAL_FAN()->setCoralType(CoralType::BRAIN())), true);
$this->register(new ItemBlockWallOrFloor(new ItemIdentifier(ItemIds::CORAL_FAN, 2), VanillaBlocks::CORAL_FAN()->setCoralType(CoralType::BUBBLE()), VanillaBlocks::WALL_CORAL_FAN()->setCoralType(CoralType::BUBBLE())), true);
$this->register(new ItemBlockWallOrFloor(new ItemIdentifier(ItemIds::CORAL_FAN, 3), VanillaBlocks::CORAL_FAN()->setCoralType(CoralType::FIRE()), VanillaBlocks::WALL_CORAL_FAN()->setCoralType(CoralType::FIRE())), true);
$this->register(new ItemBlockWallOrFloor(new ItemIdentifier(ItemIds::CORAL_FAN, 4), VanillaBlocks::CORAL_FAN()->setCoralType(CoralType::HORN()), VanillaBlocks::WALL_CORAL_FAN()->setCoralType(CoralType::HORN())), true);
$this->register(new Coal(new ItemIdentifier(ItemIds::COAL, 1), "Charcoal"));
$this->register(new CocoaBeans(new ItemIdentifier(ItemIds::DYE, 3), "Cocoa Beans"));
$this->register(new Compass(new ItemIdentifier(ItemIds::COMPASS, 0), "Compass"));

File diff suppressed because one or more lines are too long