Created
September 14, 2024 22:08
-
-
Save Steellgold/cfeaa7440cb5b6975910a69c9eefe9c6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace wapy\faction\blocks; | |
use pocketmine\block\Block; | |
use pocketmine\block\Transparent; | |
use pocketmine\data\bedrock\block\convert\BlockStateReader; | |
use pocketmine\data\bedrock\block\convert\BlockStateWriter; | |
use pocketmine\data\runtime\RuntimeDataDescriber; | |
use pocketmine\item\Bucket; | |
use pocketmine\item\Item; | |
use pocketmine\item\LiquidBucket; | |
use pocketmine\math\Facing; | |
use pocketmine\math\Vector3; | |
use pocketmine\nbt\tag\CompoundTag; | |
use pocketmine\player\Player; | |
use pocketmine\world\BlockTransaction; | |
use wapy\libs\customiesdevs\customies\block\permutations\BlockProperty; | |
use wapy\libs\customiesdevs\customies\block\permutations\Permutable; | |
use wapy\libs\customiesdevs\customies\block\permutations\Permutation; | |
use wapy\libs\customiesdevs\customies\block\permutations\Permutations; | |
use wapy\libs\customiesdevs\customies\block\permutations\RotatableTrait; | |
class Citern extends Transparent implements Permutable { | |
use RotatableTrait { | |
getBlockProperties as rotatableBlockProperties; | |
getPermutations as rotatablePermutations; | |
getCurrentBlockProperties as rotatableCurrentBlockProperties; | |
serializeState as serializeRotation; | |
deserializeState as deserializeRotation; | |
} | |
public int $percentage = 0; | |
// public string $type = "water"; | |
private function getGeometryState(int $perc, string $type = null): string { | |
if ($perc == 0) { | |
return "geometry.empty_citern"; | |
} | |
return "geometry.{$type}_{$perc}_citern"; | |
} | |
public function getBlockProperties(): array { | |
return [ | |
new BlockProperty("customies:rotation", [2, 3, 4, 5]), | |
// new BlockProperty("wapy:citern_type", ["lava", "water"]), | |
new BlockProperty("percentage", [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) | |
]; | |
} | |
public function getPermutations(): array { | |
// $permutations = [...$this->rotatablePermutations()]; | |
// | |
// $permutations[] = (new Permutation("q.block_property('wapy:citern_percentage') == 0")) | |
// ->withComponent("minecraft:geometry", CompoundTag::create() | |
// ->setString("identifier", $this->getGeometryState(0)) | |
// ); | |
// | |
// $types = ['lava', 'water']; | |
// $percentages = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]; | |
// | |
// foreach ($types as $type) { | |
// foreach ($percentages as $perc) { | |
// $condition = "q.block_property('wapy:citern_type') == '{$type}' && q.block_property('wapy:citern_percentage') == {$perc}"; | |
// $permutation = (new Permutation($condition)) | |
// ->withComponent("minecraft:geometry", CompoundTag::create() | |
// ->setString("identifier", $this->getGeometryState($perc, $type)) | |
// ); | |
// $permutations[] = $permutation; | |
// } | |
// } | |
// | |
// return $permutations; | |
return [ ...$this->rotatablePermutations(), | |
(new Permutation("q.block_property('percentage') == 10")) | |
->withComponent("minecraft:geometry", CompoundTag::create() | |
->setString("identifier", "geometry.water_10_citern")), | |
(new Permutation("q.block_property('percentage') == 20")) | |
->withComponent("minecraft:geometry", CompoundTag::create() | |
->setString("identifier", "geometry.water_20_citern")), | |
(new Permutation("q.block_property('percentage') == 30")) | |
->withComponent("minecraft:geometry", CompoundTag::create() | |
->setString("identifier", "geometry.water_30_citern")), | |
(new Permutation("q.block_property('percentage') == 40")) | |
->withComponent("minecraft:geometry", CompoundTag::create() | |
->setString("identifier", "geometry.water_40_citern")), | |
(new Permutation("q.block_property('percentage') == 50")) | |
->withComponent("minecraft:geometry", CompoundTag::create() | |
->setString("identifier", "geometry.water_50_citern")), | |
(new Permutation("q.block_property('percentage') == 60")) | |
->withComponent("minecraft:geometry", CompoundTag::create() | |
->setString("identifier", "geometry.water_60_citern")), | |
(new Permutation("q.block_property('percentage') == 70")) | |
->withComponent("minecraft:geometry", CompoundTag::create() | |
->setString("identifier", "geometry.water_70_citern")), | |
(new Permutation("q.block_property('percentage') == 80")) | |
->withComponent("minecraft:geometry", CompoundTag::create() | |
->setString("identifier", "geometry.water_80_citern")), | |
(new Permutation("q.block_property('percentage') == 90")) | |
->withComponent("minecraft:geometry", CompoundTag::create() | |
->setString("identifier", "geometry.water_90_citern")), | |
(new Permutation("q.block_property('percentage') == 100")) | |
->withComponent("minecraft:geometry", CompoundTag::create() | |
->setString("identifier", "geometry.water_100_citern")), | |
]; | |
} | |
public function getCurrentBlockProperties(): array { | |
return [$this->facing, $this->percentage]; | |
} | |
public function getLightFilter(): int { | |
return 0; | |
} | |
public function serializeState(BlockStateWriter $out): void { | |
$this->serializeRotation($out); | |
// $out->writeString("wapy:citern_type", $this->type); | |
$out->writeInt("percentage", $this->percentage); | |
} | |
public function deserializeState(BlockStateReader $in): void { | |
$this->deserializeRotation($in); | |
// $this->type = $in->readString("wapy:citern_type"); | |
$this->percentage = $in->readInt("percentage"); | |
} | |
protected function describeBlockOnlyState(RuntimeDataDescriber $w): void { | |
$w->horizontalFacing($this->facing); | |
// $w->int("citern_percentage",$this->percentage); | |
} | |
/** | |
* @throws \Exception | |
*/ | |
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []): bool { | |
$tile = $this->position->getWorld()->getTile($this->position); | |
if ($item instanceof LiquidBucket) { | |
$block = $this->position->getWorld()->getBlock($this->position); | |
if ($block instanceof Citern) { | |
$block->percentage = $this->percentage + 10; | |
var_dump($block->percentage); | |
// $block->type = "water"; | |
$this->writeStateToMeta(); | |
$block->position->getWorld()->scheduleDelayedBlockUpdate($block->position,1); | |
// $block->position->getWorld()->setBlock($block->position, $block); | |
} | |
} | |
return true; | |
} | |
/** | |
* @throws \Exception | |
*/ | |
protected function writeStateToMeta(): int { | |
return Permutations::toMeta($this); | |
} | |
public function getStateBitmask(): int { | |
return Permutations::getStateBitmask($this); | |
} | |
/** | |
* @throws \Exception | |
*/ | |
public function readStateFromData(int $id, int $stateMeta): void { | |
$blockProperties = Permutations::fromMeta($this, $stateMeta); | |
$this->facing = $blockProperties[0] ?? Facing::NORTH; | |
// $this->type = $blockProperties[1] ?? "water"; | |
$this->percentage = $blockProperties[1] ?? 0; | |
var_dump($this->facing, $this->percentage); | |
} | |
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null): bool { | |
if($player !== null) { | |
$this->facing = $player->getHorizontalFacing(); | |
// $this->type = "water"; | |
$this->percentage = 0; | |
} | |
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment