The same blocks, simply better. For PocketMine & forks.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GraveTile.php 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. # ____ _ _ ____ _ _
  3. # | __ ) ___ | |_ | |_ ___ _ __ | __ ) | | ___ ___ | | __ ___
  4. # | _ \ / _ \ | __| | __| / _ \ | '__| | _ \ | | / _ \ / __| | |/ / / __|
  5. # | |_) | | __/ | |_ | |_ | __/ | | | |_) | | | | (_) | | (__ | < \__ \
  6. # |____/ \___| \__| \__| \___| |_| |____/ |_| \___/ \___| |_|\_\ |___/
  7. #
  8. # Extends your Minecraft PE blocks palette ! For PocketMine.
  9. namespace Ad5001\BetterBlocks\CustomBlockData;
  10. use pocketmine\Server;
  11. use pocketmine\Player;
  12. use pocketmine\item\Item;
  13. use pocketmine\tile\Tile;
  14. use pocketmine\nbt\NBT;
  15. use pocketmine\level\format\Chunk;
  16. use pocketmine\nbt\tag\CompoundTag;
  17. use pocketmine\nbt\tag\StringTag;
  18. use pocketmine\nbt\tag\ListTag;
  19. use pocketmine\tile\Container;
  20. use pocketmine\math\Vector3;
  21. use pocketmine\event\entity\EntityDamageEvent as EDE;
  22. use Ad5001\BetterBlocks\CustomBlockData;
  23. use Ad5001\BetterBlocks\Main;
  24. use Ad5001\BetterBlocks\tasks\SetTextTimeoutTask;
  25. class GraveTile extends CustomBlockData implements Container {
  26. const MESSAGES = [
  27. EDE::CAUSE_CONTACT => "Didn't saw the cactus in his path",
  28. EDE::CAUSE_ENTITY_ATTACK => "Slain by %1",
  29. EDE::CAUSE_PROJECTILE => "Shot by %1",
  30. EDE::CAUSE_SUFFOCATION => "Suffocated in a wall",
  31. EDE::CAUSE_FALL => "Failed his MLG",
  32. EDE::CAUSE_FIRE => "Went up in flames",
  33. EDE::CAUSE_FIRE_TICK => "Burnt to death",
  34. EDE::CAUSE_LAVA => "Tried to swim in lava",
  35. EDE::CAUSE_BLOCK_EXPLOSION => "Trapped with TNT",
  36. EDE::CAUSE_ENTITY_EXPLOSION => "Blown up by a failed pig",
  37. EDE::CAUSE_VOID => "You shouldn't see this sign...",
  38. EDE::CAUSE_SUICIDE => "Suicided",
  39. EDE::CAUSE_MAGIC => "Messed with a witch",
  40. EDE::CAUSE_CUSTOM => "Unknown",
  41. EDE::CAUSE_STARVATION => "Was to hungry to even eat"
  42. ];
  43. public function __construct(Chunk $chunk, CompoundTag $nbt){
  44. if(!isset($nbt->Items)) {
  45. $nbt->Items = new ListTag("Items", []);
  46. $nbt->Items->setTagType(NBT::TAG_Compound);
  47. foreach(Server::getInstance()->getPlayer($nbt->Player->getValue())->getInventory()->getContents() as $key => $content) {
  48. $nbt->Items[$index] = $content->nbtSerialize();
  49. }
  50. }
  51. parent::__construct($chunk, $nbt);
  52. if(isset($nbt->Params)) {
  53. $this->level->setBlock($this, \pocketmine\block\Block::get(4, 0));
  54. $v3 = $this->getSide(Vector3::SIDE_NORTH);
  55. $this->level->setBlock($v3, \pocketmine\block\Block::get(68, 2));
  56. $dm = self::MESSAGES[$nbt->DeathCause];
  57. if(isset($nbt->Params[1])) $dm = str_ireplace("%1", $nbt->Params[1], $dm);
  58. $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)));
  59. $t->setText("§a-=<>=-", "R.I.P", $nbt->Player, $dm);
  60. unset($nbt->Params);
  61. }
  62. }
  63. /*
  64. Return the item from it's index.
  65. @param $index int
  66. @return Item
  67. */
  68. public function getItem($index) {
  69. return isset($this->namedtag->Items->{$index}) ? $this->namedtag->Items->{$index} : Item::get(0, 0);
  70. }
  71. /*
  72. Sets an item to it's index.
  73. @param $index int
  74. @param $item \pocketmine\item\Item
  75. */
  76. public function setItem($index, \pocketmine\item\Item $item) {
  77. $this->namedtag->Items->{$index} = $item;
  78. return $this;
  79. }
  80. /*
  81. Returns the size of the Inventory
  82. */
  83. public function getSize() {
  84. return 40;
  85. }
  86. /*
  87. Drops all the contents of the grave on the ground (when a player goes on it)
  88. */
  89. public function drop() {
  90. foreach($this->namedtag->Items as $item) {
  91. $item = Item::nbtDeserialize($item);
  92. $this->getLevel()->dropItem($this, $item, new \pocketmine\math\Vector3(0, 0.001, 0), 0);
  93. }
  94. }
  95. }