Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add observers #6464

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/build-docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
run: echo NAME=$(echo "${GITHUB_REPOSITORY,,}") >> $GITHUB_OUTPUT

- name: Build image for tag
uses: docker/build-push-action@v6.7.0
uses: docker/build-push-action@v6.8.0
with:
push: true
context: ./pocketmine-mp
Expand All @@ -66,7 +66,7 @@ jobs:

- name: Build image for major tag
if: steps.channel.outputs.CHANNEL == 'stable'
uses: docker/build-push-action@v6.7.0
uses: docker/build-push-action@v6.8.0
with:
push: true
context: ./pocketmine-mp
Expand All @@ -79,7 +79,7 @@ jobs:

- name: Build image for minor tag
if: steps.channel.outputs.CHANNEL == 'stable'
uses: docker/build-push-action@v6.7.0
uses: docker/build-push-action@v6.8.0
with:
push: true
context: ./pocketmine-mp
Expand All @@ -92,7 +92,7 @@ jobs:

- name: Build image for latest tag
if: steps.channel.outputs.CHANNEL == 'stable'
uses: docker/build-push-action@v6.7.0
uses: docker/build-push-action@v6.8.0
with:
push: true
context: ./pocketmine-mp
Expand Down
3 changes: 2 additions & 1 deletion src/block/BlockTypeIds.php
Original file line number Diff line number Diff line change
Expand Up @@ -745,8 +745,9 @@ private function __construct(){
public const PITCHER_PLANT = 10715;
public const PITCHER_CROP = 10716;
public const DOUBLE_PITCHER_CROP = 10717;
public const OBSERVER = 10718;

public const FIRST_UNUSED_BLOCK_ID = 10718;
public const FIRST_UNUSED_BLOCK_ID = 10719;

private static int $nextDynamicId = self::FIRST_UNUSED_BLOCK_ID;

Expand Down
44 changes: 44 additions & 0 deletions src/block/Observer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace pocketmine\block;

use pocketmine\block\utils\AnyFacingTrait;
use pocketmine\block\utils\PoweredByRedstoneTrait;
use pocketmine\data\runtime\RuntimeDataDescriber;
use pocketmine\item\Item;
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\player\Player;
use pocketmine\world\BlockTransaction;

class Observer extends Opaque{
use AnyFacingTrait;
use PoweredByRedstoneTrait;

protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{
$w->facing($this->facing);
}

public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if($player !== null){
if(abs($player->getPosition()->x - $this->position->x) < 2 && abs($player->getPosition()->z - $this->position->z) < 2){
$y = $player->getEyePos()->y;

if($y - $this->position->y > 2){
$this->facing = Facing::DOWN;
}elseif($this->position->y - $y > 0){
$this->facing = Facing::UP;
}else{
$this->facing = $player->getHorizontalFacing();
}
}else{
$this->facing = $player->getHorizontalFacing();
}
}

return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
}

// TODO: redstone logic

}
2 changes: 2 additions & 0 deletions src/block/VanillaBlocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,7 @@
* @method static WoodenTrapdoor OAK_TRAPDOOR()
* @method static WallSign OAK_WALL_SIGN()
* @method static Wood OAK_WOOD()
* @method static Observer OBSERVER()
* @method static Opaque OBSIDIAN()
* @method static Flower ORANGE_TULIP()
* @method static Flower OXEYE_DAISY()
Expand Down Expand Up @@ -1011,6 +1012,7 @@ public function getBreakTime(Item $item) : float{
self::register("redstone_torch", new RedstoneTorch(new BID(Ids::REDSTONE_TORCH), "Redstone Torch", new Info(BreakInfo::instant())));
self::register("redstone_wire", new RedstoneWire(new BID(Ids::REDSTONE_WIRE), "Redstone", new Info(BreakInfo::instant())));
self::register("reserved6", new Reserved6(new BID(Ids::RESERVED6), "reserved6", new Info(BreakInfo::instant())));
self::register("observer", new Observer(new BID(Ids::OBSERVER), "Observer", new Info(BreakInfo::pickaxe(3, ToolTier::WOOD, 3))));

$sandTypeInfo = new Info(BreakInfo::shovel(0.5), [Tags::SAND]);
self::register("sand", new Sand(new BID(Ids::SAND), "Sand", $sandTypeInfo));
Expand Down
14 changes: 14 additions & 0 deletions src/data/bedrock/block/convert/BlockObjectToStateSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
use pocketmine\block\NetherPortal;
use pocketmine\block\NetherVines;
use pocketmine\block\NetherWartPlant;
use pocketmine\block\Observer;
use pocketmine\block\PinkPetals;
use pocketmine\block\PitcherCrop;
use pocketmine\block\Potato;
Expand Down Expand Up @@ -1515,6 +1516,19 @@ private function registerSerializers() : void{
return Writer::create(Ids::NETHER_WART)
->writeInt(StateNames::AGE, $block->getAge());
});
$this->map(Blocks::OBSERVER(), function(Observer $block) : Writer {
return Writer::create(Ids::OBSERVER)
->writeString(StateNames::MC_FACING_DIRECTION, match($block->getFacing()){
Facing::DOWN => StringValues::MC_BLOCK_FACE_DOWN,
Facing::UP => StringValues::MC_BLOCK_FACE_UP,
Facing::NORTH => StringValues::MC_BLOCK_FACE_NORTH,
Facing::SOUTH => StringValues::MC_BLOCK_FACE_SOUTH,
Facing::WEST => StringValues::MC_BLOCK_FACE_WEST,
Facing::EAST => StringValues::MC_BLOCK_FACE_EAST,
default => throw new BlockStateSerializeException("Invalid Facing " . $block->getFacing())
})
->writeBool(StateNames::POWERED_BIT, $block->isPowered());
});
$this->map(Blocks::PEONY(), fn(DoublePlant $block) => Helper::encodeDoublePlant($block, Writer::create(Ids::PEONY)));
$this->map(Blocks::PINK_PETALS(), function(PinkPetals $block) : Writer{
return Writer::create(Ids::PINK_PETALS)
Expand Down
12 changes: 12 additions & 0 deletions src/data/bedrock/block/convert/BlockStateToObjectDeserializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1390,6 +1390,18 @@ private function registerDeserializers() : void{
});
$this->mapSlab(Ids::NORMAL_STONE_SLAB, Ids::NORMAL_STONE_DOUBLE_SLAB, fn() => Blocks::STONE_SLAB());
$this->mapStairs(Ids::NORMAL_STONE_STAIRS, fn() => Blocks::STONE_STAIRS());
$this->map(Ids::OBSERVER, function(Reader $in) : Block{
return Blocks::OBSERVER()
->setFacing(match ($in->readString(StateNames::MC_FACING_DIRECTION)) {
StringValues::MC_BLOCK_FACE_DOWN => Facing::DOWN,
StringValues::MC_BLOCK_FACE_UP => Facing::UP,
StringValues::MC_BLOCK_FACE_NORTH => Facing::NORTH,
StringValues::MC_BLOCK_FACE_SOUTH => Facing::SOUTH,
StringValues::MC_BLOCK_FACE_WEST => Facing::WEST,
StringValues::MC_BLOCK_FACE_EAST => Facing::EAST,
})
->setPowered($in->readBool(StateNames::POWERED_BIT));
});
$this->map(Ids::OCHRE_FROGLIGHT, fn(Reader $in) => Blocks::FROGLIGHT()->setFroglightType(FroglightType::OCHRE)->setAxis($in->readPillarAxis()));
$this->map(Ids::OXIDIZED_COPPER, fn() => Helper::decodeCopper(Blocks::COPPER(), CopperOxidation::OXIDIZED));
$this->map(Ids::OXIDIZED_CUT_COPPER, fn() => Helper::decodeCopper(Blocks::CUT_COPPER(), CopperOxidation::OXIDIZED));
Expand Down
1 change: 1 addition & 0 deletions src/item/StringToItemParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,7 @@ private static function registerBlocks(self $result) : void{
$result->registerBlock("oak_wood", fn() => Blocks::OAK_WOOD()->setStripped(false));
$result->registerBlock("oak_wood_stairs", fn() => Blocks::OAK_STAIRS());
$result->registerBlock("oak_wooden_stairs", fn() => Blocks::OAK_STAIRS());
$result->registerBlock("observer", fn() => Blocks::OBSERVER());
$result->registerBlock("obsidian", fn() => Blocks::OBSIDIAN());
$result->registerBlock("orange_tulip", fn() => Blocks::ORANGE_TULIP());
$result->registerBlock("oxeye_daisy", fn() => Blocks::OXEYE_DAISY());
Expand Down