Added glowing item frames

This commit is contained in:
Dylan K. Taylor 2022-07-14 16:24:20 +01:00
parent 0c7370e564
commit 323d31005f
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
8 changed files with 44 additions and 15 deletions

View File

@ -41,12 +41,24 @@ class ItemFrame extends Flowable{
public const ROTATIONS = 8;
protected bool $glowing = false;
protected bool $hasMap = false; //makes frame appear large if set
protected ?Item $framedItem = null;
protected int $itemRotation = 0;
protected float $itemDropChance = 1.0;
public function getRequiredTypeDataBits() : int{ return 1; }
protected function decodeType(RuntimeDataReader $r) : void{
$this->glowing = $r->readBool();
}
protected function encodeType(RuntimeDataWriter $w) : void{
$w->writeBool($this->glowing);
}
public function getRequiredStateDataBits() : int{ return 4; }
protected function decodeState(RuntimeDataReader $r) : void{
@ -133,6 +145,14 @@ class ItemFrame extends Flowable{
return $this;
}
public function isGlowing() : bool{ return $this->glowing; }
/** @return $this */
public function setGlowing(bool $glowing) : self{
$this->glowing = $glowing;
return $this;
}
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if($this->framedItem !== null){
$this->itemRotation = ($this->itemRotation + 1) % self::ROTATIONS;

View File

@ -908,7 +908,7 @@ final class BlockObjectToBlockStateSerializer implements BlockStateSerializer{
$this->mapSimple(Blocks::IRON_ORE(), Ids::IRON_ORE);
$this->map(Blocks::IRON_TRAPDOOR(), fn(Trapdoor $block) => Helper::encodeTrapdoor($block, new Writer(Ids::IRON_TRAPDOOR)));
$this->map(Blocks::ITEM_FRAME(), function(ItemFrame $block) : Writer{
return Writer::create(Ids::FRAME)
return Writer::create($block->isGlowing() ? Ids::GLOW_FRAME : Ids::FRAME)
->writeBool(StateNames::ITEM_FRAME_MAP_BIT, $block->hasMap())
->writeBool(StateNames::ITEM_FRAME_PHOTO_BIT, false)
->writeFacingDirection($block->getFacing());

View File

@ -36,6 +36,7 @@ use pocketmine\block\FenceGate;
use pocketmine\block\FloorCoralFan;
use pocketmine\block\FloorSign;
use pocketmine\block\GlazedTerracotta;
use pocketmine\block\ItemFrame;
use pocketmine\block\Liquid;
use pocketmine\block\RedMushroomBlock;
use pocketmine\block\RedstoneComparator;
@ -48,6 +49,7 @@ use pocketmine\block\Trapdoor;
use pocketmine\block\utils\CopperOxidation;
use pocketmine\block\utils\DyeColor;
use pocketmine\block\VanillaBlocks;
use pocketmine\block\VanillaBlocks as Blocks;
use pocketmine\block\Wall;
use pocketmine\block\WallCoralFan;
use pocketmine\block\WallSign;
@ -170,6 +172,14 @@ final class BlockStateDeserializerHelper{
->setFacing($in->readHorizontalFacing());
}
public static function decodeItemFrame(BlockStateReader $in, bool $glowing) : ItemFrame{
$in->todo(StateNames::ITEM_FRAME_PHOTO_BIT); //TODO: not sure what the point of this is
return Blocks::ITEM_FRAME()
->setFacing($in->readFacingDirection())
->setHasMap($in->readBool(StateNames::ITEM_FRAME_MAP_BIT))
->setGlowing($glowing);
}
/** @throws BlockStateDeserializeException */
public static function decodeLiquid(Liquid $block, BlockStateReader $in, bool $still) : Liquid{
$fluidHeightState = $in->readBoundedInt(BlockStateNames::LIQUID_DEPTH, 0, 15);

View File

@ -614,12 +614,7 @@ final class BlockStateToBlockObjectDeserializer implements BlockStateDeserialize
});
$this->map(Ids::FLOWING_LAVA, fn(Reader $in) => Helper::decodeFlowingLiquid(Blocks::LAVA(), $in));
$this->map(Ids::FLOWING_WATER, fn(Reader $in) => Helper::decodeFlowingLiquid(Blocks::WATER(), $in));
$this->map(Ids::FRAME, function(Reader $in) : Block{
$in->todo(StateNames::ITEM_FRAME_PHOTO_BIT); //TODO: not sure what the point of this is
return Blocks::ITEM_FRAME()
->setFacing($in->readFacingDirection())
->setHasMap($in->readBool(StateNames::ITEM_FRAME_MAP_BIT));
});
$this->map(Ids::FRAME, fn(Reader $in) => Helper::decodeItemFrame($in, false));
$this->map(Ids::FROSTED_ICE, function(Reader $in) : Block{
return Blocks::FROSTED_ICE()
->setAge($in->readBoundedInt(StateNames::AGE, 0, 3));
@ -632,6 +627,7 @@ final class BlockStateToBlockObjectDeserializer implements BlockStateDeserialize
$this->map(Ids::GILDED_BLACKSTONE, fn() => Blocks::GILDED_BLACKSTONE());
$this->map(Ids::GLASS, fn() => Blocks::GLASS());
$this->map(Ids::GLASS_PANE, fn() => Blocks::GLASS_PANE());
$this->map(Ids::GLOW_FRAME, fn(Reader $in) => Helper::decodeItemFrame($in, true));
$this->map(Ids::GLOWINGOBSIDIAN, fn() => Blocks::GLOWING_OBSIDIAN());
$this->map(Ids::GLOWSTONE, fn() => Blocks::GLOWSTONE());
$this->map(Ids::GOLD_BLOCK, fn() => Blocks::GOLD());

View File

@ -345,7 +345,7 @@ final class ItemDeserializer{
//TODO: minecraft:flower_banner_pattern
$this->map(Ids::FLOWER_POT, fn() => Blocks::FLOWER_POT()->asItem());
//TODO: minecraft:fox_spawn_egg
$this->map(Ids::FRAME, fn() => Blocks::ITEM_FRAME()->asItem());
$this->map(Ids::FRAME, fn() => Blocks::ITEM_FRAME()->setGlowing(false)->asItem());
//TODO: minecraft:frog_spawn_egg
//TODO: minecraft:ghast_spawn_egg
$this->map(Ids::GHAST_TEAR, fn() => Items::GHAST_TEAR());
@ -353,7 +353,7 @@ final class ItemDeserializer{
$this->map(Ids::GLISTERING_MELON_SLICE, fn() => Items::GLISTERING_MELON());
//TODO: minecraft:globe_banner_pattern
//TODO: minecraft:glow_berries
//TODO: minecraft:glow_frame
$this->map(Ids::GLOW_FRAME, fn() => Blocks::ITEM_FRAME()->setGlowing(true)->asItem());
$this->map(Ids::GLOW_INK_SAC, fn() => Items::GLOW_INK_SAC());
//TODO: minecraft:glow_squid_spawn_egg
//TODO: minecraft:glow_stick

View File

@ -25,6 +25,7 @@ namespace pocketmine\data\bedrock\item;
use pocketmine\block\Bed;
use pocketmine\block\Block;
use pocketmine\block\ItemFrame;
use pocketmine\block\Skull;
use pocketmine\block\utils\DyeColor;
use pocketmine\block\VanillaBlocks as Blocks;
@ -233,7 +234,7 @@ final class ItemSerializer{
$this->mapBlock(Blocks::FLOWER_POT(), self::id(Ids::FLOWER_POT));
$this->mapBlock(Blocks::HOPPER(), self::id(Ids::HOPPER));
$this->mapBlock(Blocks::IRON_DOOR(), self::id(Ids::IRON_DOOR));
$this->mapBlock(Blocks::ITEM_FRAME(), self::id(Ids::FRAME));
$this->mapBlock(Blocks::ITEM_FRAME(), fn(ItemFrame $block) => new Data($block->isGlowing() ? Ids::GLOW_FRAME : Ids::FRAME));
$this->mapBlock(Blocks::JUNGLE_DOOR(), self::id(Ids::JUNGLE_DOOR));
$this->mapBlock(Blocks::MANGROVE_DOOR(), self::id(Ids::MANGROVE_DOOR));
$this->mapBlock(Blocks::NETHER_WART(), self::id(Ids::NETHER_WART));

View File

@ -605,8 +605,8 @@ final class StringToItemParser extends StringToTParser{
$result->registerBlock("flower_pot_block", fn() => Blocks::FLOWER_POT());
$result->registerBlock("flowing_lava", fn() => Blocks::LAVA());
$result->registerBlock("flowing_water", fn() => Blocks::WATER());
$result->registerBlock("frame", fn() => Blocks::ITEM_FRAME());
$result->registerBlock("frame_block", fn() => Blocks::ITEM_FRAME());
$result->registerBlock("frame", fn() => Blocks::ITEM_FRAME()->setGlowing(false));
$result->registerBlock("frame_block", fn() => Blocks::ITEM_FRAME()->setGlowing(false));
$result->registerBlock("frosted_ice", fn() => Blocks::FROSTED_ICE());
$result->registerBlock("furnace", fn() => Blocks::FURNACE());
$result->registerBlock("gilded_blackstone", fn() => Blocks::GILDED_BLACKSTONE());
@ -614,6 +614,8 @@ final class StringToItemParser extends StringToTParser{
$result->registerBlock("glass_pane", fn() => Blocks::GLASS_PANE());
$result->registerBlock("glass_panel", fn() => Blocks::GLASS_PANE());
$result->registerBlock("glazed_terracotta", fn() => Blocks::GLAZED_TERRACOTTA());
$result->registerBlock("glow_frame", fn() => Blocks::ITEM_FRAME()->setGlowing(true));
$result->registerBlock("glow_item_frame", fn() => Blocks::ITEM_FRAME()->setGlowing(true));
$result->registerBlock("glowing_obsidian", fn() => Blocks::GLOWING_OBSIDIAN());
$result->registerBlock("glowing_redstone_ore", fn() => Blocks::REDSTONE_ORE()->setLit(true));
$result->registerBlock("glowingobsidian", fn() => Blocks::GLOWING_OBSIDIAN());
@ -668,8 +670,8 @@ final class StringToItemParser extends StringToTParser{
$result->registerBlock("iron_ore", fn() => Blocks::IRON_ORE());
$result->registerBlock("iron_pressure_plate", fn() => Blocks::WEIGHTED_PRESSURE_PLATE_HEAVY());
$result->registerBlock("iron_trapdoor", fn() => Blocks::IRON_TRAPDOOR());
$result->registerBlock("item_frame", fn() => Blocks::ITEM_FRAME());
$result->registerBlock("item_frame_block", fn() => Blocks::ITEM_FRAME());
$result->registerBlock("item_frame", fn() => Blocks::ITEM_FRAME()->setGlowing(false));
$result->registerBlock("item_frame_block", fn() => Blocks::ITEM_FRAME()->setGlowing(false));
$result->registerBlock("jack_o_lantern", fn() => Blocks::LIT_PUMPKIN());
$result->registerBlock("jukebox", fn() => Blocks::JUKEBOX());
$result->registerBlock("jungle_button", fn() => Blocks::JUNGLE_BUTTON());

File diff suppressed because one or more lines are too long