Browse Source

Adding plugin

master
Ad5001 2 years ago
commit
c309a594c6

+ 4
- 0
config.yml View File

@@ -0,0 +1,4 @@
---
# This is the default config generated with ImagicalPlugCreator. (C) ImagicalPlugCreator - Ad5001 2016
version: 1.0
...

+ 16
- 0
plugin.yml View File

@@ -0,0 +1,16 @@
---
# ____ _ _ ____ _ _
# | __ ) ___ | |_ | |_ ___ _ __ | __ ) | | ___ ___ | | __ ___
# | _ \ / _ \ | __| | __| / _ \ | '__| | _ \ | | / _ \ / __| | |/ / / __|
# | |_) | | __/ | |_ | |_ | __/ | | | |_) | | | | (_) | | (__ | < \__ \
# |____/ \___| \__| \__| \___| |_| |____/ |_| \___/ \___| |_|\_\ |___/
#
# Extends your Minecraft PE blocks palette ! For PocketMine.
name: BetterBlocks
author: Ad5001
version: 1.0
api: [2.0.0]
main: Ad5001\BetterBlocks\Main
commands:
permissions: []
...

+ 4
- 0
resources/config.yml View File

@@ -0,0 +1,4 @@
---
# This is the default config generated with ImagicalPlugCreator. (C) ImagicalPlugCreator - Ad5001 2016
version: 1.0
...

+ 14
- 0
src/Ad5001/BetterBlocks/CustomBlockData.php View File

@@ -0,0 +1,14 @@
<?php


namespace Ad5001\BetterBlocks;


use pocketmine\Server;
use pocketmine\Player;
use pocketmine\tile\Tile;

use Ad5001\BetterBlocks\Main;


abstract class CustomBlockData extends Tile {} // Data MIGHT be added here soon.

+ 96
- 0
src/Ad5001/BetterBlocks/CustomBlockData/FallableTile.php View File

@@ -0,0 +1,96 @@
<?php

# ____ _ _ ____ _ _
# | __ ) ___ | |_ | |_ ___ _ __ | __ ) | | ___ ___ | | __ ___
# | _ \ / _ \ | __| | __| / _ \ | '__| | _ \ | | / _ \ / __| | |/ / / __|
# | |_) | | __/ | |_ | |_ | __/ | | | |_) | | | | (_) | | (__ | < \__ \
# |____/ \___| \__| \__| \___| |_| |____/ |_| \___/ \___| |_|\_\ |___/
#
# Extends your Minecraft PE blocks palette ! For PocketMine.



namespace Ad5001\BetterBlocks\CustomBlockData;

use pocketmine\Server;
use pocketmine\Player;
use pocketmine\level\format\Chunk;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\math\Vector3;
use pocketmine\nbt\tag\StringTag;
use pocketmine\nbt\tag\DoubleTag;
use pocketmine\nbt\tag\ListTag;
use pocketmine\nbt\tag\IntTag;
use pocketmine\nbt\tag\ByteTag;
use pocketmine\nbt\tag\FloatTag;

use Ad5001\BetterBlocks\CustomBlockData;



class FallableTile extends CustomBlockData {


public function __construct(Chunk $chunk, CompoundTag $nbt){
if(!isset($nbt->Fallable)) $nbt->Fallable = new StringTag("Fallable", "true");
parent::__construct($chunk, $nbt);
}


/*
Sets if the block can fall when a player walks on it.
@param $fallable bool
*/
public function setFallable(bool $fallable) {
if($fallable) {
$this->namedtag->Fallable->setValue("true");
} else {
$this->namedtag->Fallable->setValue("false");
}
return $this;
}


/*
Check if the block is fallable.
@return bool
*/
public function isFallable() : bool {
if($this->namedtag->Fallable->getValue() == "false") {
return false;
}
return true;
}


/*
Makes the block fall
*/
public function fall() {
if($this->level->getBlock($this->getSide(Vector3::SIDE_DOWN))->getId() == 0 || $this->level->getBlock($this->getSide(Vector3::SIDE_DOWN)) instanceof \pocketmine\block\Liquid) {
$fall = \pocketmine\entity\Entity::createEntity("FallingSand", $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), new CompoundTag("", [
"Pos" => new ListTag("Pos", [
new DoubleTag("", $this->x + 0.5),
new DoubleTag("", $this->y),
new DoubleTag("", $this->z + 0.5)
]),
"Motion" => new ListTag("Motion", [
new DoubleTag("", 0),
new DoubleTag("", 0),
new DoubleTag("", 0)
]),
"Rotation" => new ListTag("Rotation", [
new FloatTag("", 0),
new FloatTag("", 0)
]),
"TileID" => new IntTag("TileID", $this->getBlock()->getId()),
"Data" => new ByteTag("Data", $this->getBlock()->getDamage()),
]))->spawnToAll();
// $this->getLevel()->setBlock($this, Block::get(0, 0));
}
}




}

+ 112
- 0
src/Ad5001/BetterBlocks/CustomBlockData/GraveTile.php View File

@@ -0,0 +1,112 @@
<?php
# ____ _ _ ____ _ _
# | __ ) ___ | |_ | |_ ___ _ __ | __ ) | | ___ ___ | | __ ___
# | _ \ / _ \ | __| | __| / _ \ | '__| | _ \ | | / _ \ / __| | |/ / / __|
# | |_) | | __/ | |_ | |_ | __/ | | | |_) | | | | (_) | | (__ | < \__ \
# |____/ \___| \__| \__| \___| |_| |____/ |_| \___/ \___| |_|\_\ |___/
#
# Extends your Minecraft PE blocks palette ! For PocketMine.


namespace Ad5001\BetterBlocks\CustomBlockData;

use pocketmine\Server;
use pocketmine\Player;
use pocketmine\item\Item;
use pocketmine\tile\Tile;
use pocketmine\nbt\NBT;
use pocketmine\level\format\Chunk;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\StringTag;
use pocketmine\nbt\tag\ListTag;
use pocketmine\tile\Container;
use pocketmine\math\Vector3;
use pocketmine\event\entity\EntityDamageEvent as EDE;

use Ad5001\BetterBlocks\CustomBlockData;
use Ad5001\BetterBlocks\Main;
use Ad5001\BetterBlocks\tasks\SetTextTimeoutTask;



class GraveTile extends CustomBlockData implements Container {

const MESSAGES = [
EDE::CAUSE_CONTACT => "Didn't saw the cactus in his path",
EDE::CAUSE_ENTITY_ATTACK => "Slain by %1",
EDE::CAUSE_PROJECTILE => "Shot by %1",
EDE::CAUSE_SUFFOCATION => "Suffocated in a wall",
EDE::CAUSE_FALL => "Failed his MLG",
EDE::CAUSE_FIRE => "Went up in flames",
EDE::CAUSE_FIRE_TICK => "Burnt to death",
EDE::CAUSE_LAVA => "Tried to swim in lava",
EDE::CAUSE_BLOCK_EXPLOSION => "Trapped with TNT",
EDE::CAUSE_ENTITY_EXPLOSION => "Blown up by a failed pig",
EDE::CAUSE_VOID => "You shouldn't see this sign...",
EDE::CAUSE_SUICIDE => "Suicided",
EDE::CAUSE_MAGIC => "Messed with a witch",
EDE::CAUSE_CUSTOM => "Unknown",
EDE::CAUSE_STARVATION => "Was to hungry to even eat"
];

public function __construct(Chunk $chunk, CompoundTag $nbt){
if(!isset($nbt->Items)) {
$nbt->Items = new ListTag("Items", []);
$nbt->Items->setTagType(NBT::TAG_Compound);
foreach(Server::getInstance()->getPlayer($nbt->Player->getValue())->getInventory()->getContents() as $key => $content) {
$nbt->Items[$index] = $content->nbtSerialize();
}
}
parent::__construct($chunk, $nbt);
if(isset($nbt->Params)) {
$this->level->setBlock($this, \pocketmine\block\Block::get(4, 0));
$v3 = $this->getSide(Vector3::SIDE_NORTH);
$this->level->setBlock($v3, \pocketmine\block\Block::get(68, 2));
$dm = self::MESSAGES[$nbt->DeathCause];
if(isset($nbt->Params[1])) $dm = str_ireplace("%1", $nbt->Params[1], $dm);
$t = Tile::createTile("Sign", $this->level->getChunk($v3->x >> 4, $v3->z >> 4), NBT::parseJSON(json_encode(["x" => $v3->x, "y" => $v3->y, "z" => $v3->z, "Text1" => "§a-=<>=-", "Text2" => "R.I.P", "Text3" => $nbt->Player, "Text4" => $dm], JSON_FORCE_OBJECT)));
$t->setText("§a-=<>=-", "R.I.P", $nbt->Player, $dm);
unset($nbt->Params);
}
}

/*
Return the item from it's index.
@param $index int
@return Item
*/
public function getItem($index) {
return isset($this->namedtag->Items->{$index}) ? $this->namedtag->Items->{$index} : Item::get(0, 0);
}

/*
Sets an item to it's index.
@param $index int
@param $item \pocketmine\item\Item
*/
public function setItem($index, \pocketmine\item\Item $item) {
$this->namedtag->Items->{$index} = $item;
return $this;
}

/*
Returns the size of the Inventory
*/
public function getSize() {
return 40;
}



/*
Drops all the contents of the grave on the ground (when a player goes on it)
*/
public function drop() {
foreach($this->namedtag->Items as $item) {
$item = Item::nbtDeserialize($item);
$this->getLevel()->dropItem($this, $item, new \pocketmine\math\Vector3(0, 0.001, 0), 0);
}
}
}

+ 25
- 0
src/Ad5001/BetterBlocks/CustomBlockData/RedstonePoweringTile.php View File

@@ -0,0 +1,25 @@
<?php

# ____ _ _ ____ _ _
# | __ ) ___ | |_ | |_ ___ _ __ | __ ) | | ___ ___ | | __ ___
# | _ \ / _ \ | __| | __| / _ \ | '__| | _ \ | | / _ \ / __| | |/ / / __|
# | |_) | | __/ | |_ | |_ | __/ | | | |_) | | | | (_) | | (__ | < \__ \
# |____/ \___| \__| \__| \___| |_| |____/ |_| \___/ \___| |_|\_\ |___/
#
# Extends your Minecraft PE blocks palette ! For PocketMine.



namespace Ad5001\BetterBlocks\CustomBlockData;

use pocketmine\Server;
use pocketmine\Player;
use pocketmine\level\format\Chunk;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\StringTag;

use Ad5001\BetterBlocks\CustomBlockData;



class RedstonePoweringTile extends CustomBlockData {} // Will be implemented when redstone will be out on every software.

+ 85
- 0
src/Ad5001/BetterBlocks/CustomBlockData/SoundHolderTile.php View File

@@ -0,0 +1,85 @@
<?php

# ____ _ _ ____ _ _
# | __ ) ___ | |_ | |_ ___ _ __ | __ ) | | ___ ___ | | __ ___
# | _ \ / _ \ | __| | __| / _ \ | '__| | _ \ | | / _ \ / __| | |/ / / __|
# | |_) | | __/ | |_ | |_ | __/ | | | |_) | | | | (_) | | (__ | < \__ \
# |____/ \___| \__| \__| \___| |_| |____/ |_| \___/ \___| |_|\_\ |___/
#
# Extends your Minecraft PE blocks palette ! For PocketMine.



namespace Ad5001\BetterBlocks\CustomBlockData;

use pocketmine\Server;
use pocketmine\Player;
use pocketmine\level\format\Chunk;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\StringTag;

use Ad5001\BetterBlocks\CustomBlockData;



class SoundHolderTile extends CustomBlockData {

const SOUNDS = [
"AnvilBreakSound",
"AnvilFallSound",
"AnvilUseSound",
"BatSound",
"BlazeShootSound",
"ClickSound",
"DoorBumpSound",
"DoorCrashSound",
"EndermanTeleportSound",
"FizzSound",
"GhastShootSound",
"GhastSound",
"LaunchSound",
"PopSound",
"ZombieHealSound",
"ZombieInfectSound"
];


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
parent::__construct($chunk, $nbt);
}


/*
Sets the sound of the Block
@param $sound string
@return bool
*/
public function setSound(string $sound) : bool {
if(in_array($sound, self::SOUNDS)) {
$this->namedtag->Sound->setValue($sound);
return true;
}
return false;;
}

/*
Gets the current used sound
@return string
*/
public function getSound() : string {
return $this->namedtag->Sound->getValue();
}


/*
Plays the sound
*/
public function play() {
$s = "\\pocketmine\\level\\sound\\" . $this->namedtag->Sound->getValue();
$this->getLevel()->addSound(new $s($this));
}



}

+ 62
- 0
src/Ad5001/BetterBlocks/CustomBlockData/StickTile.php View File

@@ -0,0 +1,62 @@
<?php

# ____ _ _ ____ _ _
# | __ ) ___ | |_ | |_ ___ _ __ | __ ) | | ___ ___ | | __ ___
# | _ \ / _ \ | __| | __| / _ \ | '__| | _ \ | | / _ \ / __| | |/ / / __|
# | |_) | | __/ | |_ | |_ | __/ | | | |_) | | | | (_) | | (__ | < \__ \
# |____/ \___| \__| \__| \___| |_| |____/ |_| \___/ \___| |_|\_\ |___/
#
# Extends your Minecraft PE blocks palette ! For PocketMine.



namespace Ad5001\BetterBlocks\CustomBlockData;

use pocketmine\Server;
use pocketmine\Player;
use pocketmine\level\format\Chunk;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\StringTag;

use Ad5001\BetterBlocks\CustomBlockData;



class StickTile extends CustomBlockData {


public function __construct(Chunk $chunk, CompoundTag $nbt){
if(!isset($nbt->Stickable)) $nbt->Stickable = new StringTag("Stickable", "true");
parent::__construct($chunk, $nbt);
}


/*
Sets if the block can stick when a player walks on it.
@param $stickable bool
*/
public function setStickable(bool $stickable) {
if($stickable) {
$this->namedtag->Stickable->setValue("true");
} else {
$this->namedtag->Stickable->setValue("false");
}
return $this;
}


/*
Check if the block is stickable.
@return bool
*/
public function isStickable() : bool {
if($this->namedtag->Stickable->getValue() == "false") {
return false;
}
return true;
}




}

+ 62
- 0
src/Ad5001/BetterBlocks/CustomBlockData/TrapTile.php View File

@@ -0,0 +1,62 @@
<?php

# ____ _ _ ____ _ _
# | __ ) ___ | |_ | |_ ___ _ __ | __ ) | | ___ ___ | | __ ___
# | _ \ / _ \ | __| | __| / _ \ | '__| | _ \ | | / _ \ / __| | |/ / / __|
# | |_) | | __/ | |_ | |_ | __/ | | | |_) | | | | (_) | | (__ | < \__ \
# |____/ \___| \__| \__| \___| |_| |____/ |_| \___/ \___| |_|\_\ |___/
#
# Extends your Minecraft PE blocks palette ! For PocketMine.



namespace Ad5001\BetterBlocks\CustomBlockData;

use pocketmine\Server;
use pocketmine\Player;
use pocketmine\level\format\Chunk;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\StringTag;

use Ad5001\BetterBlocks\CustomBlockData;



class TrapTile extends CustomBlockData {


public function __construct(Chunk $chunk, CompoundTag $nbt){
if(!isset($nbt->TrapActive)) $nbt->TrapActive = new StringTag("TrapActive", "true");
parent::__construct($chunk, $nbt);
}


/*
Sets if the trap is active
@param $trapActive bool
*/
public function setTrapActive(bool $trapActive) {
if($trapActive) {
$this->namedtag->TrapActive->setValue("true");
} else {
$this->namedtag->TrapActive->setValue("false");
}
return $this;
}


/*
Check if the trap is active.
@return bool
*/
public function isTrapActive() : bool {
if($this->namedtag->TrapActive->getValue() == "false") {
return false;
}
return true;
}




}

+ 66
- 0
src/Ad5001/BetterBlocks/CustomBlockData/VacuumTile.php View File

@@ -0,0 +1,66 @@
<?php
# ____ _ _ ____ _ _
# | __ ) ___ | |_ | |_ ___ _ __ | __ ) | | ___ ___ | | __ ___
# | _ \ / _ \ | __| | __| / _ \ | '__| | _ \ | | / _ \ / __| | |/ / / __|
# | |_) | | __/ | |_ | |_ | __/ | | | |_) | | | | (_) | | (__ | < \__ \
# |____/ \___| \__| \__| \___| |_| |____/ |_| \___/ \___| |_|\_\ |___/
#
# Extends your Minecraft PE blocks palette ! For PocketMine.

namespace Ad5001\BetterBlocks\CustomBlockData;

use pocketmine\Server;
use pocketmine\Player;
use pocketmine\level\format\Chunk;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\math\Vector3;
use pocketmine\nbt\tag\IntTag;

use Ad5001\BetterBlocks\CustomBlockData;




class VacuumTile extends CustomBlockData {
public function __construct(Chunk $chunk, CompoundTag $nbt){
if(!isset($nbt->AttractRadius)) $nbt->AttractRadius = new IntTag("AttractRadius", 5);
parent::__construct($chunk, $nbt);
}


/*
Sets the attracting radius of the vacuum hopper
@param $radius int
*/
public function setAttractRadius(int $radius) {
$this->namedtag->AttractRadius->setValue($radius);
return $this;
}


/*
Get the radius of attractivity of the Vacuum Hopper.
@return int
*/
public function getAttractRadius() : int {
return (int) $this->namedtag->AttractRadius->getValue();
}

/*
Attracts all blocks in the defined radius.
*/
public function attract() {
foreach ($this->getLevel()->getEntities() as $et) {
if($et->x < $this->x + $this->namedtag->AttractRadius->getValue() && $et->x > $this->x - $this->namedtag->AttractRadius->getValue() &&
$et->y < $this->y + $this->namedtag->AttractRadius->getValue() && $et->y > $this->y - $this->namedtag->AttractRadius->getValue() &&
$et->z < $this->z + $this->namedtag->AttractRadius->getValue() && $et->z > $this->z - $this->namedtag->AttractRadius->getValue()) {
$et->teleport(new Vector3($this->x, $this->y + 1, $this->z));
}
}
}




}

+ 42
- 0
src/Ad5001/BetterBlocks/Dummy3.php View File

@@ -0,0 +1,42 @@
<?php


namespace Ad5001\BetterBlocks;



use pocketmine\Server;


use pocketmine\Player;



use Ad5001\BetterBlocks\Main;







class Dummy {




public function __construct(Main $main) {


$this->main = $main;


$this->server = $main->getServer()


}




}

+ 236
- 0
src/Ad5001/BetterBlocks/Main.php View File

@@ -0,0 +1,236 @@
<?php

# ____ _ _ ____ _ _
# | __ ) ___ | |_ | |_ ___ _ __ | __ ) | | ___ ___ | | __ ___
# | _ \ / _ \ | __| | __| / _ \ | '__| | _ \ | | / _ \ / __| | |/ / / __|
# | |_) | | __/ | |_ | |_ | __/ | | | |_) | | | | (_) | | (__ | < \__ \
# |____/ \___| \__| \__| \___| |_| |____/ |_| \___/ \___| |_|\_\ |___/
#
# Extends your Minecraft PE blocks palette ! For PocketMine.

namespace Ad5001\BetterBlocks;
use pocketmine\event\Listener;
use pocketmine\plugin\PluginBase;
use pocketmine\Server;
use pocketmine\Player;
use pocketmine\tile\Tile;
use pocketmine\item\Item;
use pocketmine\inventory\ShapedRecipe;
use pocketmine\math\Vector3;
use pocketmine\block\Block;
use pocketmine\event\block\BlockBreakEvent;

use pocketmine\nbt\NBT;
use pocketmine\nbt\tag\ListTag;

use Ad5001\BetterBlocks\CustomBlockData\FallableTile;
use Ad5001\BetterBlocks\CustomBlockData\GraveTile;
use Ad5001\BetterBlocks\CustomBlockData\RedstonePoweringTile;
use Ad5001\BetterBlocks\CustomBlockData\SoundHolderTile;
use Ad5001\BetterBlocks\CustomBlockData\StickTile;
use Ad5001\BetterBlocks\CustomBlockData\VacuumTile;

use Ad5001\BetterBlocks\tasks\AttractTask;
use Ad5001\BetterBlocks\tasks\BlockRegenerateTask;
use Ad5001\BetterBlocks\tasks\Drop2CraftTask;

class Main extends PluginBase implements Listener {

static $instance;


public function onEnable(){
self::$instance = $this;

// Registering recipes
$ep = Item::get(368, 0);
// Sticky Slime block
$ssb = Item::get(165, 0);
$ssb->setCustomName("§rSticky Slime Block");
$ssb->setNamedTag(NBT::parseJSON('{"isStickable":"true"}'));
$this->getServer()->getCraftingManager()->registerRecipe((new ShapedRecipe($ssb, 3, 3))->addIngredient(1, 1, $ep)->addIngredient(1, 2, Item::get(165, 0)));
// Vacuum Hopper
$vh = Item::get(410, 0);
$vh->setNamedTag(NBT::parseJSON('{"isVacuum":"true"}'));
$vh->setCustomName("§rVacuum Item Hopper");
$this->getServer()->getCraftingManager()->registerRecipe((new ShapedRecipe($vh, 3, 3))->addIngredient(1, 0, $ep)->addIngredient(0, 0, Item::get(410, 0))->addIngredient(0, 1, Item::get(49, 0)));
// Trappers (used to create trap blocks)
$vh = Item::get(69, 0);
$vh->setNamedTag(NBT::parseJSON('{"isTrapper":"true"}'));
$vh->setCustomName("§rTrapper");
$this->getServer()->getCraftingManager()->registerRecipe((new ShapedRecipe($vh, 3, 3))->addIngredient(1, 1, Item::get(70, 0))->addIngredient(0, 0, Item::get(331, 0)));
// Hammes (for fallable blocks)
// Wooden
$wt = Item::get(271, 0);
$wt->setNamedTag(NBT::parseJSON('{"isHammer":"true"}'));
$wt->setCustomName("§rWooden Hammer");
$this->getServer()->getCraftingManager()->registerRecipe((new ShapedRecipe($wt, 3, 3))->addIngredient(2, 0, Item::get(280, 0))->addIngredient(1, 1, Item::get(280, 0))->addIngredient(0, 1, Item::get(5, 0))->addIngredient(0, 2, Item::get(5, 0))->addIngredient(1, 2, Item::get(5, 0)));
// Stone
$wt = Item::get(275, 0);
$wt->setNamedTag(NBT::parseJSON('{"isHammer":"true"}'));
$wt->setCustomName("§rStone Hammer");
$this->getServer()->getCraftingManager()->registerRecipe((new ShapedRecipe($wt, 3, 3))->addIngredient(2, 0, Item::get(280, 0))->addIngredient(1, 1, Item::get(280, 0))->addIngredient(0, 1, Item::get(4, 0))->addIngredient(0, 2, Item::get(4, 0))->addIngredient(1, 2, Item::get(4, 0)));
// Iron
$wt = Item::get(258, 0);
$wt->setNamedTag(NBT::parseJSON('{"isHammer":"true"}'));
$wt->setCustomName("§rIron Hammer");
$this->getServer()->getCraftingManager()->registerRecipe((new ShapedRecipe($wt, 3, 3))->addIngredient(2, 0, Item::get(280, 0))->addIngredient(1, 1, Item::get(280, 0))->addIngredient(0, 1, Item::get(265, 0))->addIngredient(0, 2, Item::get(265, 0))->addIngredient(1, 2, Item::get(265, 0)));
// Gold
$wt = Item::get(286, 0);
$wt->setNamedTag(NBT::parseJSON('{"isHammer":"true"}'));
$wt->setCustomName("§rGold Hammer");
$this->getServer()->getCraftingManager()->registerRecipe((new ShapedRecipe($wt, 3, 3))->addIngredient(2, 0, Item::get(280, 0))->addIngredient(1, 1, Item::get(280, 0))->addIngredient(0, 1, Item::get(266, 0))->addIngredient(0, 2, Item::get(266, 0))->addIngredient(1, 2, Item::get(266, 0)));
// Diamond
$wt = Item::get(279, 0);
$wt->setNamedTag(NBT::parseJSON('{"isHammer":"true"}'));
$wt->setCustomName("§rDiamond Hammer");
$this->getServer()->getCraftingManager()->registerRecipe((new ShapedRecipe($wt, 3, 3))->addIngredient(2, 0, Item::get(280, 0))->addIngredient(1, 1, Item::get(280, 0))->addIngredient(0, 1, Item::get(264, 0))->addIngredient(0, 2, Item::get(264, 0))->addIngredient(1, 2, Item::get(264, 0)));


// Registering tiles
Tile::registerTile(FallableTile::class);
Tile::registerTile(GraveTile::class);
Tile::registerTile(RedstonePoweringTile::class);
Tile::registerTile(SoundHolderTile::class);
Tile::registerTile(StickTile::class);
Tile::registerTile(VacuumTile::class);

$this->getServer()->getPluginManager()->registerEvents($this, $this);
$this->saveDefaultConfig();
}



/*
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)));
} elseif(isset($event->getItem()->getNamedTag()->isVacuum) && $event->getItem()->getNamedTag()->isVacuum->getValue() == "true") {
Tile::createTile("VacuumTile", $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)));
} 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)));
$this->getServer()->getScheduler()->scheduleDelayedTask(new BlockRegenerateTask($this, Block::get(0, 0), $event->getBlock()->getLevel()), 30); // Clears the lever
}
}


/*
Checks when a block breaks to drop the item if custom block.
@param $event BlockBreakEvent
*/
public function onBlockBreak(BlockBreakEvent $event) {
//1
$block = $event->getBlock();
if($event->getBlock()->getLevel()->getTile($block) instanceof CustomBlockData && !$event->isCancelled()) {
switch(substr(get_class($event->getBlock()->getLevel()->getTile($block)), 36)) {
case "GraveTile":
$event->getBlock()->getLevel()->getTile($block)->drop();
break;
case "RedstonePoweringTile":
$redstoneblock = Item::get(152, 0);
$event->setDrops(array_merge([$redstoneblock], $event->getDrops()));
break;
case "SoundHolderTile":
$noteblock = Item::get(25, 0);
$event->setDrops(array_merge([$noteblock], $event->getDrops()));
break;
case "StickTile":
$ssb = Item::get(165, 0);
$ssb->setCustomName("§rSticky Slime Block");
$ssb->setNamedTag(NBT::parseJSON('{"isStickable":"true"}'));
$event->setDrops([$ssb]);
break;
case "TrapTile":
break;
case "VacuumTile":
$vh = Item::get(410, 0);
$vh->setNamedTag(NBT::parseJSON('{"isVacuum":"true"}'));
$vh->setCustomName("§rVacuum Item Hopper");
$event->setDrops([$vh]);
break;
}
}
}



/*
Check if a player touches a block. Check if he right clicks ill a hammer.
@param $event \pocketmine\event\player\PlayerInteractEvent
*/
public function onInteract(\pocketmine\event\player\PlayerInteractEvent $event) {
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...");
}
}


/*
Detects when a player drops an item to set it as "Droped by the player" to build some custom blocks.
@param $event \pocketmine\event\player\PlayerDropItemEvent
*/
public function onPlayerItemDrop(\pocketmine\event\player\PlayerDropItemEvent $event) {
$event->getItem()->setNamedTag(NBT::parseJSON('{"isDropedByPlayer":"true"}'));
}


/*
Checks when a player death to set up a grave.
@param $event \pocketmine\event\player\PlayerDeathEvent
*/
public function onPlayerDeath(\pocketmine\event\player\PlayerDeathEvent $event) {
$player = $event->getPlayer();
$cause = $player->getLastDamageCause();
$nbt = NBT::parseJSON(json_encode([
"x" => $player->x,
"y" => $player->y,
"z" => $player->z,
"Player" => $player->getName(),
"DeathCause" => $cause == null ? 14 : $cause->getCause(),
"Params" => $event->getDeathMessage()->getParameters()
], JSON_FORCE_OBJECT));
$nbt->Items = new ListTag("Items", []);
$nbt->Items->setTagType(NBT::TAG_Compound);
foreach($event->getDrops() as $index => $content) {
$nbt->Items[$index] = $content->nbtSerialize();
}
$event->setDrops([]);
Tile::createTile("GraveTile", $player->getLevel()->getChunk($player->x >> 4, $player->z >> 4), $nbt);
}


/*
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.
@param $event \pocketmine\event\player\PlayerMoveEvent
*/
public function onPlayerMove(\pocketmine\event\player\PlayerMoveEvent $event) {
$v3Under = $event->getPlayer()->round();
$v3Under->y--;
$v3Upper = $event->getPlayer()->round();
$v3Upper->y += 2;
$tileUnder = $event->getPlayer()->getLevel()->getTile($v3Under);
$tileUpper = $event->getPlayer()->getLevel()->getTile($v3Upper);

// 1)
if($tileUnder instanceof TrapTile) {
$block = clone $event->getPlayer()->getLevel()->getBlock($v3Under);
$event->getPlayer()->getLevel()->setBlock($v3Under, Block::get(0, 0));
$this->getServer()->getScheduler()->scheduleDelayedTask(new BlockRegenerateTask($this, $block, $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();
}
}


}

+ 55
- 0
src/Ad5001/BetterBlocks/tasks/AttractTask.php View File

@@ -0,0 +1,55 @@
<?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\VacuumTile;







class AttractTask extends PluginTask {




public function __construct(Main $main) {
parent::__construct($main);
$this->main = $main;
$this->server = $main->getServer();
}




public function onRun($tick) {
foreach($this->server->getLevels() as $level) {
foreach($level->getTiles() as $tile) {
if($tile instanceof VacuumTile) {

}
}
}
}




}

+ 49
- 0
src/Ad5001/BetterBlocks/tasks/BlockRegenerateTask.php View File

@@ -0,0 +1,49 @@
<?php

# ____ _ _ ____ _ _
# | __ ) ___ | |_ | |_ ___ _ __ | __ ) | | ___ ___ | | __ ___
# | _ \ / _ \ | __| | __| / _ \ | '__| | _ \ | | / _ \ / __| | |/ / / __|
# | |_) | | __/ | |_ | |_ | __/ | | | |_) | | | | (_) | | (__ | < \__ \
# |____/ \___| \__| \__| \___| |_| |____/ |_| \___/ \___| |_|\_\ |___/
#
# Extends your Minecraft PE blocks palette ! For PocketMine.

namespace Ad5001\BetterBlocks\tasks;


use pocketmine\Server;
use pocketmine\scheduler\PluginTask;
use pocketmine\Player;
use pocketmine\level\Level;
use pocketmine\block\Block;

use Ad5001\BetterBlocks\CustomBlockData;
use Ad5001\BetterBlocks\Main;


class BlockRegenerateTask extends PluginTask {




public function __construct(Main $main, Block $block, Level $lvl) {
parent::__construct($main);
$this->main = $main;
$this->server = $main->getServer();
$this->block = $block;
$this->lvl = $lvl;
}




public function onRun($tick) {
$this->lvl->setBlock($this->block, $this->block); // Delays a the block setting.
$this->lvl->setBlock($this->block, $this->block); // Levers are not deleting
$this->main->getLogger()->debug($this->lvl->getBlock($this->block));
}




}

+ 84
- 0
src/Ad5001/BetterBlocks/tasks/Drop2CraftTask.php View File

@@ -0,0 +1,84 @@
<?php

# ____ _ _ ____ _ _
# | __ ) ___ | |_ | |_ ___ _ __ | __ ) | | ___ ___ | | __ ___
# | _ \ / _ \ | __| | __| / _ \ | '__| | _ \ | | / _ \ / __| | |/ / / __|
# | |_) | | __/ | |_ | |_ | __/ | | | |_) | | | | (_) | | (__ | < \__ \
# |____/ \___| \__| \__| \___| |_| |____/ |_| \___/ \___| |_|\_\ |___/
#
# Extends your Minecraft PE blocks palette ! For PocketMine.



namespace Ad5001\BetterBlocks\tasks;



use pocketmine\Server;
use pocketmine\scheduler\PluginTask;
use pocketmine\Player;
use pocketmine\nbt\NBT;
use pocketmine\tile\Tile;
use pocketmine\item\Item;
use pocketmine\entity\Item as EtItem;

use Ad5001\BetterBlocks\CustomBlockData;
use Ad5001\BetterBlocks\CustomBlockData\FallableTile;
use Ad5001\BetterBlocks\CustomBlockData\RedstonePoweringTile;
use Ad5001\BetterBlocks\CustomBlockData\SoundHolderTile;



class Drop2CraftTask extends PluginTask {




public function __construct(Main $main) {
parent::__construct($main);
$this->main = $main;
$this->server = $main->getServer();
}




public function onRun($tick) {
foreach($this->server->getLevels() as $level) {
foreach($level->getEntities() as $et) {
if($et instanceof EtItem && isset($et->getItem()->getNamedTag()->isDropedByPlayer)) {
switch($et->getItem()->getId()) {
case 152: // Redstone block: For the Redstone Powering Block
$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])));
$et->close();
}
break;
case 25: // Note block: For the Sound Holding block.
$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])));
$et->close();
}
break;
case 69: // Levers drops
$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])));
$et->close();
}
break;
}
}
}
}
}




}

Loading…
Cancel
Save