Fixing stickable blocks + sound holder blocks
This commit is contained in:
parent
9094478518
commit
020718b525
4 changed files with 97 additions and 15 deletions
|
@ -18,6 +18,7 @@ use pocketmine\level\format\Chunk;
|
|||
use pocketmine\nbt\tag\CompoundTag;
|
||||
use pocketmine\nbt\tag\StringTag;
|
||||
|
||||
use Ad5001\BetterBlocks\Main;
|
||||
use Ad5001\BetterBlocks\CustomBlockData;
|
||||
|
||||
|
||||
|
@ -25,7 +26,6 @@ use Ad5001\BetterBlocks\CustomBlockData;
|
|||
class SoundHolderTile extends CustomBlockData {
|
||||
|
||||
const SOUNDS = [
|
||||
"AnvilBreakSound",
|
||||
"AnvilFallSound",
|
||||
"AnvilUseSound",
|
||||
"BatSound",
|
||||
|
@ -45,7 +45,7 @@ class SoundHolderTile extends CustomBlockData {
|
|||
|
||||
|
||||
public function __construct(Chunk $chunk, CompoundTag $nbt){
|
||||
if(!isset($nbt->Sound)) $nbt->Sound = new StringTag("Sound", self::SOUND(rand(0, count(self::SOUNDS) - 1))); // TODO: Customize the sound
|
||||
if(!isset($nbt->Sound)) $nbt->Sound = new StringTag("Sound", self::SOUNDS[rand(0, count(self::SOUNDS) - 1)]); // TODO: Customize the sound
|
||||
parent::__construct($chunk, $nbt);
|
||||
}
|
||||
|
||||
|
@ -77,6 +77,7 @@ class SoundHolderTile extends CustomBlockData {
|
|||
*/
|
||||
public function play() {
|
||||
$s = "\\pocketmine\\level\\sound\\" . $this->namedtag->Sound->getValue();
|
||||
Main::$instance->getLogger()->debug("Playing sound $s...");
|
||||
$this->getLevel()->addSound(new $s($this));
|
||||
}
|
||||
|
||||
|
|
|
@ -33,13 +33,23 @@ use Ad5001\BetterBlocks\tasks\AttractTask;
|
|||
use Ad5001\BetterBlocks\tasks\BlockRegenerateTask;
|
||||
use Ad5001\BetterBlocks\tasks\Drop2CraftTask;
|
||||
use Ad5001\BetterBlocks\tasks\SetVacuumTask;
|
||||
use Ad5001\BetterBlocks\tasks\StickTask;
|
||||
|
||||
class Main extends PluginBase implements Listener {
|
||||
|
||||
static $instance;
|
||||
|
||||
const PMMP_INCOMPATIBLE = [
|
||||
"Vacuum Hoppers",
|
||||
"Sticky Slime Blocks"
|
||||
];
|
||||
|
||||
|
||||
public function onEnable(){
|
||||
if($this->getServer()->getName() == "PocketMine-MP") {
|
||||
$this->getLogger()->notice("This plugin only has partial support of Pocketmine due to all the features an API missing. The following things will be deactivated: " . implode(", ", self::PMMP_INCOMPATIBLE));
|
||||
}
|
||||
|
||||
self::$instance = $this;
|
||||
|
||||
// Registering recipes
|
||||
|
@ -95,8 +105,11 @@ class Main extends PluginBase implements Listener {
|
|||
Tile::registerTile(StickTile::class);
|
||||
|
||||
// Launch tasks
|
||||
$this->getServer()->getScheduler()->scheduleRepeatingTask(new AttractTask($this), 5);
|
||||
$this->getServer()->getScheduler()->scheduleRepeatingTask(new Drop2CraftTask($this), 5);
|
||||
if($this->getServer()->getName() !== "PocketMine-MP") { // Removes uncessery lag on PMMP
|
||||
$this->getServer()->getScheduler()->scheduleRepeatingTask(new AttractTask($this), 5);
|
||||
$this->getServer()->getScheduler()->scheduleRepeatingTask(new StickTask($this), 1);
|
||||
}
|
||||
|
||||
$this->getServer()->getPluginManager()->registerEvents($this, $this);
|
||||
$this->saveDefaultConfig();
|
||||
|
@ -107,18 +120,17 @@ class Main extends PluginBase implements Listener {
|
|||
/*
|
||||
When a custom block item is placed (Sticcky Slime Blocks, Vaccum hoppers and for Trap Blocks)
|
||||
@param $event \pocketmine\event\block\BlockPlaceEvent
|
||||
@retu
|
||||
*/
|
||||
public function onBlockPlace(\pocketmine\event\block\BlockPlaceEvent $event) {
|
||||
if(isset($event->getItem()->getNamedTag()->isStickable) && $event->getItem()->getNamedTag()->isStickable->getValue() == "true") {
|
||||
Tile::createTile("StickTile", $event->getBlock()->getLevel()->getChunk($event->getBlock()->x >> 4, $event->getBlock()->z >> 4), NBT::parseJSON(json_encode([$event->getBlock()->x, $event->getBlock()->y, $event->getBlock()->z], JSON_FORCE_OBJECT)));
|
||||
$this->getLogger()->debug("Created tile Sticky Slime Block");
|
||||
Tile::createTile("StickTile", $event->getBlock()->getLevel()->getChunk($event->getBlock()->x >> 4, $event->getBlock()->z >> 4), NBT::parseJSON(json_encode(["x" => $event->getBlock()->x, "y" => $event->getBlock()->y, "z" => $event->getBlock()->z], JSON_FORCE_OBJECT)));
|
||||
} elseif(isset($event->getItem()->getNamedTag()->isVacuum) && $event->getItem()->getNamedTag()->isVacuum->getValue() == "true") {
|
||||
$this->getServer()->getScheduler()->scheduleRepeatingTask(new SetVacuumTask($this, $event->getBlock()), 1); // Tile gets created after the event so delaying it one 1 tick.
|
||||
} elseif(isset($event->getItem()->getNamedTag()->isTrapper) && $event->getItem()->getNamedTag()->isTrapper->getValue() == "true") {
|
||||
Tile::createTile("TrapTile", $event->getBlock()->getLevel()->getChunk($event->getBlock()->x >> 4, $event->getBlock()->z >> 4), NBT::parseJSON(json_encode([$event->getBlock()->x, $event->getBlock()->y - 1, $event->getBlock()->z], JSON_FORCE_OBJECT)));
|
||||
Tile::createTile("TrapTile", $event->getBlock()->getLevel()->getChunk($event->getBlock()->x >> 4, $event->getBlock()->z >> 4), NBT::parseJSON(json_encode(["x" => $event->getBlock()->x, "y" => $event->getBlock()->y - 1, "z" => $event->getBlock()->z], JSON_FORCE_OBJECT)));
|
||||
$this->getServer()->getScheduler()->scheduleDelayedTask(new BlockRegenerateTask($this, Block::get(0, 0), $event->getBlock()->getLevel()), 30); // Clears the lever
|
||||
}
|
||||
$this->getLogger()->debug("Created tile " . json_encode($event->getBlock()->getLevel()->getTile($event->getBlock())));
|
||||
}
|
||||
|
||||
|
||||
|
@ -180,6 +192,10 @@ class Main extends PluginBase implements Listener {
|
|||
if(isset($event->getItem()->getNamedTag()->isHammer) && $event->getItem()->getNamedTag()->isHammer == "true" && !($event->getBlock() instanceof \pocketmine\block\Fallable) && !($event->getBlock()->getLevel()->getTile($event->getBlock()) instanceof Tile)) {
|
||||
Tile::createTile("FallableTile", $event->getBlock()->getLevel()->getChunk($event->getBlock()->x >> 4, $event->getBlock()->z >> 4), NBT::parseJSON('{"x":"'.$event->getBlock()->x.'","y":"' .$event->getBlock()->y.'","z":"'. $event->getBlock()->z . '"}'));
|
||||
$event->getPlayer()->sendPopup("This block seems now unstable... You shouldn't walk on it...");
|
||||
} elseif($event->getBlock()->getLevel()->getTile($event->getBlock()) instanceof SoundHolderTile) {
|
||||
$s = SoundHolderTile::SOUNDS[rand(0, count(SoundHolderTile::SOUNDS) - 1)];
|
||||
$event->getBlock()->getLevel()->getTile($event->getBlock())->setSound($s);
|
||||
$event->getPlayer()->sendPopup("Sound has changed to $s.");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -219,7 +235,7 @@ class Main extends PluginBase implements Listener {
|
|||
|
||||
|
||||
/*
|
||||
Checks when a player moves to 1) Trigger traps blocks, 2) Set person as sticky 3) Makes fallable block fall if a player walks on it.
|
||||
Checks when a player moves to 1) Trigger traps blocks 2) Makes fallable block fall if a player walks on it. 3) Play a sound when a player walks on it.
|
||||
@param $event \pocketmine\event\player\PlayerMoveEvent
|
||||
*/
|
||||
public function onPlayerMove(\pocketmine\event\player\PlayerMoveEvent $event) {
|
||||
|
@ -237,13 +253,13 @@ class Main extends PluginBase implements Listener {
|
|||
$this->getServer()->getScheduler()->scheduleDelayedTask(new BlockRegenerateTask($this, $b, $event->getPlayer()->getLevel()), 30);
|
||||
}
|
||||
// 2)
|
||||
if($tileUnder instanceof StickTile || $tileUpper instanceof StickTile) {
|
||||
$event->getPlayer()->setMotion($event->getPlayer()->getMotion()->x, 0, $event->getPlayer()->getMotion()->z);
|
||||
}
|
||||
// 3)
|
||||
if($tileUnder instanceof FallableTile) {
|
||||
$tileUnder->fall();
|
||||
}
|
||||
// 3)
|
||||
if($tileUnder instanceof SoundHolderTile) {
|
||||
$tileUnder->play();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ class Drop2CraftTask extends PluginTask {
|
|||
$v3 = $et->round();
|
||||
$v3->y--;
|
||||
if($et->getLevel()->getBlock($v3)->isSolid()) {
|
||||
Tile::createTile("RedstonePoweringTile", $this->getLevel()->getChunk($et->x >> 4, $et->z >> 4), NBT::parseJSON(json_encode([$v3->x, $v3->y, $v3->z])));
|
||||
Tile::createTile("RedstonePoweringTile", $et->getLevel()->getChunk($et->x >> 4, $et->z >> 4), NBT::parseJSON(json_encode(["x" => $v3->x, "y" => $v3->y, "z" => $v3->z], JSON_FORCE_OBJECT)));
|
||||
$et->close();
|
||||
}
|
||||
break;
|
||||
|
@ -62,15 +62,17 @@ class Drop2CraftTask extends PluginTask {
|
|||
$v3 = $et->round();
|
||||
$v3->y--;
|
||||
if($et->getLevel()->getBlock($v3)->isSolid()) {
|
||||
Tile::createTile("SoundHolderTile", $this->getLevel()->getChunk($et->x >> 4, $et->z >> 4), NBT::parseJSON(json_encode([$v3->x, $v3->y, $v3->z])));
|
||||
Tile::createTile("SoundHolderTile", $et->getLevel()->getChunk($et->x >> 4, $et->z >> 4), NBT::parseJSON(json_encode(["x" => $v3->x, "y" => $v3->y, "z" => $v3->z], JSON_FORCE_OBJECT)));
|
||||
$et->close();
|
||||
}
|
||||
break;
|
||||
case 69: // Levers drops
|
||||
$this->getLogger()->debug("Found lever");
|
||||
$v3 = $et->round();
|
||||
$v3->y--;
|
||||
if($et->getLevel()->getBlock($v3)->isSolid() && isset($et->getItem()->getNamedTag()->isTrapper)) {
|
||||
Tile::createTile("TrapTile", $v3->getLevel()->getChunk($v3->x >> 4, $v3->z >> 4), NBT::parseJSON(json_encode([$v3->x, $v3->y - 1, $v3->z])));
|
||||
$this->getLogger()->debug("Found trapper");
|
||||
Tile::createTile("TrapTile", $et->getLevel()->getChunk($v3->x >> 4, $v3->z >> 4), NBT::parseJSON(json_encode(["x" => $v3->x, "y" => $v3->y - 1, "z" => $v3->z], JSON_FORCE_OBJECT)));
|
||||
$et->close();
|
||||
}
|
||||
break;
|
||||
|
|
63
src/Ad5001/BetterBlocks/tasks/StickTask.php
Normal file
63
src/Ad5001/BetterBlocks/tasks/StickTask.php
Normal file
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
# ____ _ _ ____ _ _
|
||||
# | __ ) ___ | |_ | |_ ___ _ __ | __ ) | | ___ ___ | | __ ___
|
||||
# | _ \ / _ \ | __| | __| / _ \ | '__| | _ \ | | / _ \ / __| | |/ / / __|
|
||||
# | |_) | | __/ | |_ | |_ | __/ | | | |_) | | | | (_) | | (__ | < \__ \
|
||||
# |____/ \___| \__| \__| \___| |_| |____/ |_| \___/ \___| |_|\_\ |___/
|
||||
#
|
||||
# Extends your Minecraft PE blocks palette ! For PocketMine.
|
||||
|
||||
namespace Ad5001\BetterBlocks\tasks;
|
||||
|
||||
|
||||
use pocketmine\Server;
|
||||
use pocketmine\scheduler\PluginTask;
|
||||
use pocketmine\Player;
|
||||
|
||||
|
||||
use Ad5001\BetterBlocks\CustomBlockData;
|
||||
use Ad5001\BetterBlocks\CustomBlockData\StickTile;
|
||||
use Ad5001\BetterBlocks\Main;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class StickTask extends PluginTask {
|
||||
|
||||
|
||||
|
||||
|
||||
public function __construct(Main $main) {
|
||||
parent::__construct($main);
|
||||
$this->main = $main;
|
||||
$this->server = $main->getServer();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function onRun($tick) {
|
||||
foreach($this->server->getOnlinePlayers() as $player) {
|
||||
$v3Under = $player->round();
|
||||
$v3Under->y--;
|
||||
$v3Upper = $player->round();
|
||||
$v3Upper->y += 2;
|
||||
$tileUnder = $player->getLevel()->getTile($v3Under);
|
||||
$tileUpper = $player->getLevel()->getTile($v3Upper);
|
||||
if($tileUnder instanceof StickTile){
|
||||
$player->setMotion(new \pocketmine\math\Vector3($player->getMotion()->x, -0.5, $player->getMotion()->z));
|
||||
}
|
||||
if($tileUpper instanceof StickTile) {
|
||||
$player->setMotion(new \pocketmine\math\Vector3($player->getMotion()->x, 0.5, $player->getMotion()->z));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in a new issue