mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 00:33:59 +00:00
Persistent block metadata may now have mutable parts
Not allowing this makes stuff like anvil damage, colour, wood type, live/dead bit, wet/dry etc all too much hassle to deal with. Naturally I want to get rid of this shit altogether, but first it's necessary to construct a new system that we can shift into before all this bullshit can be addressed fully, so for now we have to work within the bounds of the old system. This change will permit dynamic colours for concrete/concrete powder etc, dynamic wood types where the wood type isn't embedded in the legacy ID, and so forth. Allowing full flexibility requires either more old system hacks or completing the migration to a new system which doesn't have these limitations. I prefer to do the latter, but this change will make it somewhat easier to do.
This commit is contained in:
parent
9191e75392
commit
388a19ef5d
@ -40,19 +40,27 @@ class Anvil extends Transparent implements Fallable{
|
||||
use FallableTrait;
|
||||
use HorizontalFacingTrait;
|
||||
|
||||
/** @var int */
|
||||
private $damage = 0;
|
||||
|
||||
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
|
||||
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(5.0, BlockToolType::PICKAXE, ToolTier::WOOD()->getHarvestLevel(), 6000.0));
|
||||
}
|
||||
|
||||
protected function writeStateToMeta() : int{
|
||||
return BlockDataSerializer::writeLegacyHorizontalFacing($this->facing);
|
||||
return BlockDataSerializer::writeLegacyHorizontalFacing($this->facing) | ($this->damage << 2);
|
||||
}
|
||||
|
||||
public function readStateFromData(int $id, int $stateMeta) : void{
|
||||
$this->facing = BlockDataSerializer::readLegacyHorizontalFacing($stateMeta);
|
||||
$this->facing = BlockDataSerializer::readLegacyHorizontalFacing($stateMeta & 0x3);
|
||||
$this->damage = BlockDataSerializer::readBoundedInt("damage", $stateMeta >> 2, 0, 2);
|
||||
}
|
||||
|
||||
public function getStateBitmask() : int{
|
||||
return 0b1111;
|
||||
}
|
||||
|
||||
public function getNonPersistentStateBitmask() : int{
|
||||
return 0b11;
|
||||
}
|
||||
|
||||
|
@ -101,7 +101,10 @@ class Block{
|
||||
}
|
||||
|
||||
public function asItem() : Item{
|
||||
return ItemFactory::getInstance()->get($this->idInfo->getItemId(), $this->idInfo->getVariant());
|
||||
return ItemFactory::getInstance()->get(
|
||||
$this->idInfo->getItemId(),
|
||||
$this->idInfo->getVariant() | ($this->writeStateToMeta() & ~$this->getNonPersistentStateBitmask())
|
||||
);
|
||||
}
|
||||
|
||||
public function getMeta() : int{
|
||||
@ -117,6 +120,10 @@ class Block{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getNonPersistentStateBitmask() : int{
|
||||
return $this->getStateBitmask();
|
||||
}
|
||||
|
||||
protected function writeStateToMeta() : int{
|
||||
return 0;
|
||||
}
|
||||
|
@ -101,9 +101,7 @@ class BlockFactory{
|
||||
|
||||
$this->register(new ActivatorRail(new BID(Ids::ACTIVATOR_RAIL), "Activator Rail"));
|
||||
$this->register(new Air(new BID(Ids::AIR), "Air"));
|
||||
$this->register(new Anvil(new BID(Ids::ANVIL, Meta::ANVIL_NORMAL), "Anvil"));
|
||||
$this->register(new Anvil(new BID(Ids::ANVIL, Meta::ANVIL_SLIGHTLY_DAMAGED), "Slightly Damaged Anvil"));
|
||||
$this->register(new Anvil(new BID(Ids::ANVIL, Meta::ANVIL_VERY_DAMAGED), "Very Damaged Anvil"));
|
||||
$this->register(new Anvil(new BID(Ids::ANVIL), "Anvil"));
|
||||
$this->register(new Bamboo(new BID(Ids::BAMBOO), "Bamboo", new BlockBreakInfo(2.0 /* 1.0 in PC */, BlockToolType::AXE)));
|
||||
$this->register(new BambooSapling(new BID(Ids::BAMBOO_SAPLING), "Bamboo Sapling", BlockBreakInfo::instant()));
|
||||
$this->register(new Banner(new BIDFlattened(Ids::STANDING_BANNER, Ids::WALL_BANNER, 0, ItemIds::BANNER, TileBanner::class), "Banner"));
|
||||
@ -833,7 +831,7 @@ class BlockFactory{
|
||||
|
||||
$v = clone $block;
|
||||
try{
|
||||
$v->readStateFromData($id, $m & $stateMask);
|
||||
$v->readStateFromData($id, $m);
|
||||
if($v->getMeta() !== $m){
|
||||
throw new InvalidBlockStateException("Corrupted meta"); //don't register anything that isn't the same when we read it back again
|
||||
}
|
||||
|
@ -44,7 +44,8 @@ class Torch extends Flowable{
|
||||
}
|
||||
|
||||
public function readStateFromData(int $id, int $stateMeta) : void{
|
||||
$this->facing = $stateMeta === 5 ? Facing::UP : BlockDataSerializer::readHorizontalFacing(6 - $stateMeta);
|
||||
$facingMeta = $stateMeta & 0x7;
|
||||
$this->facing = $facingMeta === 5 ? Facing::UP : BlockDataSerializer::readHorizontalFacing(6 - $facingMeta);
|
||||
}
|
||||
|
||||
public function getStateBitmask() : int{
|
||||
|
@ -600,7 +600,6 @@ use function assert;
|
||||
* @method static Wall SANDSTONE_WALL()
|
||||
* @method static SeaLantern SEA_LANTERN()
|
||||
* @method static SeaPickle SEA_PICKLE()
|
||||
* @method static Anvil SLIGHTLY_DAMAGED_ANVIL()
|
||||
* @method static Opaque SMOOTH_QUARTZ()
|
||||
* @method static Slab SMOOTH_QUARTZ_SLAB()
|
||||
* @method static Stair SMOOTH_QUARTZ_STAIRS()
|
||||
@ -648,7 +647,6 @@ use function assert;
|
||||
* @method static Tripwire TRIPWIRE()
|
||||
* @method static TripwireHook TRIPWIRE_HOOK()
|
||||
* @method static UnderwaterTorch UNDERWATER_TORCH()
|
||||
* @method static Anvil VERY_DAMAGED_ANVIL()
|
||||
* @method static Vine VINES()
|
||||
* @method static Water WATER()
|
||||
* @method static WeightedPressurePlateHeavy WEIGHTED_PRESSURE_PLATE_HEAVY()
|
||||
@ -1270,7 +1268,6 @@ final class VanillaBlocks{
|
||||
self::register("sandstone_wall", $factory->get(139, 5));
|
||||
self::register("sea_lantern", $factory->get(169));
|
||||
self::register("sea_pickle", $factory->get(411));
|
||||
self::register("slightly_damaged_anvil", $factory->get(145, 4));
|
||||
self::register("smooth_quartz", $factory->get(155, 3));
|
||||
self::register("smooth_quartz_slab", $factory->get(421, 1));
|
||||
self::register("smooth_quartz_stairs", $factory->get(440));
|
||||
@ -1318,7 +1315,6 @@ final class VanillaBlocks{
|
||||
self::register("tripwire", $factory->get(132));
|
||||
self::register("tripwire_hook", $factory->get(131));
|
||||
self::register("underwater_torch", $factory->get(239, 5));
|
||||
self::register("very_damaged_anvil", $factory->get(145, 8));
|
||||
self::register("vines", $factory->get(106));
|
||||
self::register("water", $factory->get(8));
|
||||
self::register("weighted_pressure_plate_heavy", $factory->get(148));
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user