public static createTile ( string $type, pocketmine\level\format\FullChunk $chunk, |
||
$type | string | |
$chunk | pocketmine\level\format\FullChunk | |
$nbt | ||
$args | ||
return |
public function onActivate(Item $item, Player $player = null) { if ($player instanceof Player) { $t = $this->getLevel()->getTile($this); if ($t instanceof FurnaceTile) { $furnace = $t; } else { $nbt = new CompoundTag("", [new ListTag("Items", []), new StringTag("id", Tile::FURNACE), new IntTag("x", $this->x), new IntTag("y", $this->y), new IntTag("z", $this->z)]); $nbt->Items->setTagType(NBT::TAG_Compound); $furnace = Tile::createTile("Furnace", $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt); } if (isset($furnace->namedtag->Lock) and $furnace->namedtag->Lock instanceof StringTag) { if ($furnace->namedtag->Lock->getValue() !== $item->getCustomName()) { return true; } } if ($player->isCreative() and $player->getServer()->limitedCreative) { return true; } $player->addWindow($furnace->getInventory()); } return true; }
public function onActivate(Item $item, Player $player = null) { if (!$this->getLevel()->getServer()->enchantingTableEnabled) { return true; } if ($player instanceof Player) { if ($player->isCreative() and $player->getServer()->limitedCreative) { return true; } $tile = $this->getLevel()->getTile($this); $enchantTable = null; if ($tile instanceof EnchantTable) { $enchantTable = $tile; } else { $this->getLevel()->setBlock($this, $this, true, true); $nbt = new CompoundTag("", [new StringTag("id", Tile::ENCHANT_TABLE), new IntTag("x", $this->x), new IntTag("y", $this->y), new IntTag("z", $this->z)]); if ($item->hasCustomName()) { $nbt->CustomName = new StringTag("CustomName", $item->getCustomName()); } if ($item->hasCustomBlockData()) { foreach ($item->getCustomBlockData() as $key => $v) { $nbt->{$key} = $v; } } /** @var EnchantTable $enchantTable */ $enchantTable = Tile::createTile(Tile::ENCHANT_TABLE, $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt); } $player->addWindow(new EnchantInventory($this)); $player->craftingType = Player::CRAFTING_ENCHANT; } return true; }
public function onActivate(Item $item, Player $player = null) { if ($player instanceof Player) { $top = $this->getSide(1); if ($top->isTransparent() !== true) { return true; } $t = $this->getLevel()->getTile($this); $chest = null; if ($t instanceof TileChest) { $chest = $t; } else { $nbt = new CompoundTag("", [new EnumTag("Items", []), new StringTag("id", Tile::CHEST), new IntTag("x", $this->x), new IntTag("y", $this->y), new IntTag("z", $this->z)]); $nbt->Items->setTagType(NBT::TAG_Compound); $chest = Tile::createTile("Chest", $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt); } if (isset($chest->namedtag->Lock) and $chest->namedtag->Lock instanceof StringTag) { if ($chest->namedtag->Lock->getValue() !== $item->getCustomName()) { return true; } } if ($player->isCreative() and $player->getServer()->limitedCreative) { return true; } $player->addWindow($chest->getInventory()); } return true; }
public function onActivate(Item $item, Player $player = null) { if ($player instanceof Player) { $top = $this->getSide(1); if ($top->isTransparent() !== true) { return true; } $this->BroadcastRedstoneUpdate(Level::REDSTONE_UPDATE_PLACE, Block::REDSTONESOURCEPOWER); $this->getLevel()->scheduleUpdate($this, 2); $t = $this->getLevel()->getTile($this); $chest = null; if ($t instanceof TileChest) { $chest = $t; } else { $nbt = new CompoundTag("", [new ListTag("Items", []), new StringTag("id", Tile::CHEST), new IntTag("x", $this->x), new IntTag("y", $this->y), new IntTag("z", $this->z)]); $nbt->Items->setTagType(NBT::TAG_Compound); $chest = Tile::createTile("Chest", $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt); } if (isset($chest->namedtag->Lock) and $chest->namedtag->Lock instanceof StringTag) { if ($chest->namedtag->Lock->getValue() !== $item->getCustomName()) { return true; } } $player->addWindow($chest->getInventory()); } return true; }
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null) { $this->getLevel()->setBlock($this, $this, true, true); $nbt = new CompoundTag("", [new StringTag("id", MainClass::TILE_NOTE), new IntTag("x", $block->x), new IntTag("y", $block->y), new IntTag("z", $block->z), new ByteTag("note", 0)]); $pot = Tile::createTile("Note", $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt); return true; }
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null) { if ($face !== 0) { $nbt = new CompoundTag("", ["id" => new StringTag("id", Tile::SIGN), "x" => new IntTag("x", $block->x), "y" => new IntTag("y", $block->y), "z" => new IntTag("z", $block->z), "Text1" => new StringTag("Text1", ""), "Text2" => new StringTag("Text2", ""), "Text3" => new StringTag("Text3", ""), "Text4" => new StringTag("Text4", "")]); if ($player !== null) { $nbt->Creator = new StringTag("Creator", $player->getRawUniqueId()); } if ($item->hasCustomBlockData()) { foreach ($item->getCustomBlockData() as $key => $v) { $nbt->{$key} = $v; } } if ($face === 1) { $this->meta = floor(($player->yaw + 180) * 16 / 360 + 0.5) & 0xf; $this->getLevel()->setBlock($block, Block::get(Item::SIGN_POST, $this->meta), true); Tile::createTile(Tile::SIGN, $this->getLevel()->getChunk($block->x >> 4, $block->z >> 4), $nbt); return true; } else { $this->meta = $face; $this->getLevel()->setBlock($block, Block::get(Item::WALL_SIGN, $this->meta), true); Tile::createTile(Tile::SIGN, $this->getLevel()->getChunk($block->x >> 4, $block->z >> 4), $nbt); return true; } } return false; }
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null) { $this->getLevel()->setBlock($block, $this, true, true); $nbt = new CompoundTag("", [new StringTag("id", Tile::MOB_SPAWNER), new IntTag("x", $block->x), new IntTag("y", $block->y), new IntTag("z", $block->z), new IntTag("EntityId", 0)]); Tile::createTile(Tile::MOB_SPAWNER, $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt); return true; }
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null) { $this->getLevel()->setBlock($block, $this, true, false); $nbt = new CompoundTag("", [new StringTag("id", Tile::DAY_LIGHT_DETECTOR), new IntTag("x", $this->x), new IntTag("y", $this->y), new IntTag("z", $this->z)]); Tile::createTile(Tile::DAY_LIGHT_DETECTOR, $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt); return true; }
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null) { $nbt = new CompoundTag("", [new StringTag("id", MainClass::TILE_CAULDRON), new IntTag("x", $block->x), new IntTag("y", $block->y), new IntTag("z", $block->z), new ShortTag("PotionId", 0xffff), new ByteTag("SplashPotion", 0), new ListTag("Items", [])]); $chunk = $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4); $tile = Tile::createTile("Cauldron", $chunk, $nbt); // $this->getLevel()->setBlock($block, $this, true, true); return true; }
/** * @return DLDetector */ protected function getTile() { $t = $this->getLevel()->getTile($this); if ($t instanceof DLDetector) { return $t; } else { $nbt = new CompoundTag("", [new StringTag("id", Tile::DAY_LIGHT_DETECTOR), new IntTag("x", $this->x), new IntTag("y", $this->y), new IntTag("z", $this->z)]); return Tile::createTile(Tile::DAY_LIGHT_DETECTOR, $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt); } }
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null) { if ($this->getSide(Vector3::SIDE_DOWN)->isTransparent() === false) { $this->getLevel()->setBlock($block, $this, true, true); $nbt = new Compound("", [new String("id", Tile::FLOWER_POT), new Int("x", $block->x), new Int("y", $block->y), new Int("z", $block->z), new Int("item", 0), new Int("data", 0)]); $pot = Tile::createTile("FlowerPot", $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt); return true; } return false; }
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null) { $down = $block->getSide(0); if ($down->isTransparent() === false || $down instanceof Slab && ($down->meta & 0x8) === 0x8 || $down instanceof WoodSlab && ($down->meta & 0x8) === 0x8 || $down instanceof Stair && ($down->meta & 0x4) === 0x4) { $this->getLevel()->setBlock($block, $this, true, true); $nbt = new Compound("", [new String("id", Tile::FLOWER_POT), new Int("x", $block->x), new Int("y", $block->y), new Int("z", $block->z), new Short("item", 0), new Int("mData", 0)]); $pot = Tile::createTile("FlowerPot", $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt); return true; } return false; }
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null) { if ($face !== 0) { $this->getLevel()->setBlock($block, Block::get(MainClass::BLOCK_SKULL, 0), true, true); $nbt = new Compound("", [new String("id", Tile::SKULL), new Int("x", $block->x), new Int("y", $block->y), new Int("z", $block->z), new Byte("SkullType", $item->getDamage()), new Byte("Rot", floor($player->yaw * 16 / 360 + 0.5) & 0xf)]); $chunk = $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4); $pot = Tile::createTile("Skull", $chunk, $nbt); $this->getLevel()->setBlock($block, Block::get(MainClass::BLOCK_SKULL, $face), true, true); return true; } return false; }
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null) { $this->getLevel()->setBlock($block, $this, true, true); $nbt = new CompoundTag("", [new StringTag("id", Tile::MOB_SPAWNER), new IntTag("x", $block->x), new IntTag("y", $block->y), new IntTag("z", $block->z), new IntTag("EntityId", 0)]); if ($item->hasCustomBlockData()) { foreach ($item->getCustomBlockData() as $key => $v) { $nbt->{$key} = $v; } } Tile::createTile(Tile::MOB_SPAWNER, $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt); return true; }
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null) { $nbt = new CompoundTag("", [new StringTag("id", Tile::CAULDRON), new IntTag("x", $block->x), new IntTag("y", $block->y), new IntTag("z", $block->z), new ShortTag("PotionId", 0xffff), new ByteTag("SplashPotion", 0), new ListTag("Items", [])]); if ($item->hasCustomBlockData()) { foreach ($item->getCustomBlockData() as $key => $v) { $nbt->{$key} = $v; } } $chunk = $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4); $tile = Tile::createTile("Cauldron", $chunk, $nbt); $this->getLevel()->setBlock($block, $this, true, true); return true; }
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null) { $this->getLevel()->setBlock($block, $this, true, true); $nbt = new Compound("", [new String("id", Tile::ENCHANT_TABLE), new Int("x", $this->x), new Int("y", $this->y), new Int("z", $this->z)]); if ($item->hasCustomName()) { $nbt->CustomName = new String("CustomName", $item->getCustomName()); } if ($item->hasCustomBlockData()) { foreach ($item->getCustomBlockData() as $key => $v) { $nbt->{$key} = $v; } } Tile::createTile(Tile::ENCHANT_TABLE, $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt); return true; }
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null) { if ($this->getSide(Vector3::SIDE_DOWN)->isTransparent()) { return false; } $this->getLevel()->setBlock($block, $this, true, true); $nbt = new CompoundTag("", [new StringTag("id", Tile::FLOWER_POT), new IntTag("x", $block->x), new IntTag("y", $block->y), new IntTag("z", $block->z), new ShortTag("item", 0), new IntTag("mData", 0)]); if ($item->hasCustomBlockData()) { foreach ($item->getCustomBlockData() as $key => $v) { $nbt->{$key} = $v; } } Tile::createTile(Tile::FLOWER_POT, $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt); return true; }
public function onActivate(Item $item, Player $player = null) { if ($player instanceof Player) { //TODO lock $t = $this->getLevel()->getTile($this); //$brewingStand = false; if ($t instanceof TileBrewingStand) { $brewingStand = $t; } else { $nbt = new CompoundTag("", [new ListTag("Items", []), new StringTag("id", Tile::BREWING_STAND), new IntTag("x", $this->x), new IntTag("y", $this->y), new IntTag("z", $this->z)]); $nbt->Items->setTagType(NBT::TAG_Compound); $brewingStand = Tile::createTile(Tile::BREWING_STAND, $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt); } $player->addWindow($brewingStand->getInventory()); } return true; }
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null) { $down = $this->getSide(0); if ($face !== 0 && $fy > 0.5 && $target->getId() !== self::SKULL_BLOCK && !$down instanceof SkullBlock) { $this->getLevel()->setBlock($block, Block::get(Block::SKULL_BLOCK, 0), true, true); if ($face === 1) { $rot = new Byte("Rot", floor($player->yaw * 16 / 360 + 0.5) & 0xf); } else { $rot = new Byte("Rot", 0); } $nbt = new Compound("", [new String("id", Tile::SKULL), new Int("x", $block->x), new Int("y", $block->y), new Int("z", $block->z), new Byte("SkullType", $item->getDamage()), $rot]); $chunk = $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4); $pot = Tile::createTile("Skull", $chunk, $nbt); $this->getLevel()->setBlock($block, Block::get(Block::SKULL_BLOCK, $face), true, true); return true; } return false; }
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null) { if ($block->getSide(Vector3::SIDE_DOWN)->isTransparent() === false) { $this->getLevel()->setBlock($block, $this, true, true); $nbt = new Compound("", [new String("id", Tile::BREWING_STAND), new Int("x", $this->x), new Int("y", $this->y), new Int("z", $this->z)]); if ($item->hasCustomName()) { $nbt->CustomName = new String("CustomName", $item->getCustomName()); } if ($item->hasCustomBlockData()) { foreach ($item->getCustomBlockData() as $key => $v) { $nbt->{$key} = $v; } } Tile::createTile(Tile::BREWING_STAND, $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt); return true; } return false; }
public function onActivate(Item $item, Player $player = null) { if ($player instanceof Player) { $t = $this->getLevel()->getTile($this); $furnace = false; if ($t instanceof Furnace) { $furnace = $t; } else { $nbt = new Compound("", [new Enum("Items", []), new String("id", Tile::FURNACE), new Int("x", $this->x), new Int("y", $this->y), new Int("z", $this->z)]); $nbt->Items->setTagType(NBT::TAG_Compound); $furnace = Tile::createTile("Furnace", $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt); } if ($player->isCreative()) { return true; } $player->addWindow($furnace->getInventory()); } return true; }
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null) { if ($face !== 0) { $this->meta = $face; if ($face === 1) { $rot = floor($player->yaw * 16 / 360 + 0.5) & 0xf; } else { $rot = $face; } $this->getLevel()->setBlock($block, $this, true); $nbt = new CompoundTag("", [new StringTag("id", Tile::SKULL), new ByteTag("SkullType", $item->getDamage()), new ByteTag("Rot", $rot), new IntTag("x", (int) $this->x), new IntTag("y", (int) $this->y), new IntTag("z", (int) $this->z)]); if ($item->hasCustomName()) { $nbt->CustomName = new StringTag("CustomName", $item->getCustomName()); } /** @var Spawnable $tile */ Tile::createTile("Skull", $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt); return true; } return false; }
public function onActivate(Item $item, Player $player = null) { if ($player instanceof Player) { $t = $this->getLevel()->getTile($this); $hopper = null; if ($t instanceof HopperTile) { $hopper = $t; } else { $nbt = new CompoundTag("", [new ListTag("Items", []), new StringTag("id", Tile::HOPPER), new IntTag("x", $this->x), new IntTag("y", $this->y), new IntTag("z", $this->z)]); $nbt->Items->setTagType(NBT::TAG_Compound); $hopper = Tile::createTile(Tile::HOPPER, $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt); } if (isset($hopper->namedtag->Lock) and $hopper->namedtag->Lock instanceof StringTag) { if ($hopper->namedtag->Lock->getValue() !== $item->getCustomName()) { return true; } } $player->addWindow($hopper->getInventory()); } return true; }
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null) { if ($player instanceof Player) { $pitch = $player->getPitch(); if (abs($pitch) >= 45) { if ($pitch < 0) { $f = 0; } else { $f = 1; } } else { $f = $player->getDirection() + 2; } } else { $f = 0; } $faces = [0 => 0, 1 => 1, 2 => 5, 3 => 3, 4 => 4, 5 => 2]; $this->meta = $faces[$f]; $this->getLevel()->setBlock($block, $this, true, true); $nbt = new CompoundTag("", [new StringTag("id", Tile::PISTON), new IntTag("x", $this->x), new IntTag("y", $this->y), new IntTag("z", $this->z), new IntTag("blockData", 0), new IntTag("blockId", Item::PISTON_HEAD), new ByteTag("extending", 0), new IntTag("facing", $faces[$f]), new FloatTag("progress", 0.0)]); $tile = Tile::createTile("Piston", $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt); return true; }
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null) { if ($face > 1) { $faces = [2 => 3, 3 => 2, 4 => 1, 5 => 4]; $itemTag = NBT::putItemHelper(Item::get(Item::AIR)); $itemTag->setName("Item"); $nbt = new CompoundTag("", [new StringTag("id", MainClass::TILE_ITEM_FRAME), new IntTag("x", $block->x), new IntTag("y", $block->y), new IntTag("z", $block->z), new CompoundTag("Item", $itemTag->getValue()), new FloatTag("ItemDropChance", 1.0), new ByteTag("ItemRotation", 0)]); if ($item->hasCustomBlockData()) { foreach ($item->getCustomBlockData() as $key => $value) { //Reformat: support "Item" tag by give command if ($key === "Item" and $value instanceof CompoundTag) { $value = NBT::putItemHelper(NBT::getItemHelper($value)); $value->setName("Item"); } $nbt->{$key} = $value; } } //var_dump($nbt);//debug Tile::createTile("ItemFrame", $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt); $this->getLevel()->setBlock($block, Block::get(MainClass::BLOCK_ITEM_FRAME, $faces[$face]), true, true); return true; } return false; }
/** * Uses a item on a position and face, placing it or activating the block * * @param Vector3 $vector * @param Item $item * @param int $face * @param float $fx default 0.0 * @param float $fy default 0.0 * @param float $fz default 0.0 * @param Player $player default null * * @return boolean */ public function useItemOn(Vector3 $vector, Item &$item, $face, $fx = 0.0, $fy = 0.0, $fz = 0.0, Player $player = null) { $target = $this->getBlock($vector); $block = $target->getSide($face); if ($block->y > 127 or $block->y < 0) { return false; } if ($target->getId() === Item::AIR) { return false; } if ($player !== null) { $ev = new PlayerInteractEvent($player, $item, $target, $face, $target->getId() === 0 ? PlayerInteractEvent::RIGHT_CLICK_AIR : PlayerInteractEvent::RIGHT_CLICK_BLOCK); if (!$player->isOp() and ($distance = $this->server->getSpawnRadius()) > -1) { $t = new Vector2($target->x, $target->z); $s = new Vector2($this->getSpawnLocation()->x, $this->getSpawnLocation()->z); if (count($this->server->getOps()->getAll()) > 0 and $t->distance($s) <= $distance) { //set it to cancelled so plugins can bypass this $ev->setCancelled(); } } $this->server->getPluginManager()->callEvent($ev); if (!$ev->isCancelled()) { $target->onUpdate(self::BLOCK_UPDATE_TOUCH); if (!$player->isSneaking() and $target->canBeActivated() === true and $target->onActivate($item, $player) === true) { return true; } if (!$player->isSneaking() and $item->canBeActivated() and $item->onActivate($this, $player, $block, $target, $face, $fx, $fy, $fz)) { if ($item->getCount() <= 0) { $item = Item::get(Item::AIR, 0, 0); return true; } } } else { return false; } } elseif ($target->canBeActivated() === true and $target->onActivate($item, $player) === true) { return true; } if ($item->canBePlaced()) { $hand = $item->getBlock(); $hand->position($block); } elseif ($block->getId() === Item::FIRE) { $this->setBlock($block, new Air(), true); return false; } else { return false; } if (!($block->canBeReplaced() === true or $hand->getId() === Item::SLAB and $block->getId() === Item::SLAB)) { return false; } if ($target->canBeReplaced() === true) { $block = $target; $hand->position($block); //$face = -1; } if ($hand->isSolid() === true and $hand->getBoundingBox() !== null) { $entities = $this->getCollidingEntities($hand->getBoundingBox()); $realCount = 0; foreach ($entities as $e) { if ($e instanceof Arrow or $e instanceof DroppedItem) { continue; } ++$realCount; } if ($player !== null) { if ($diff = $player->getNextPosition()->subtract($player->getPosition()) and $diff->lengthSquared() > 1.0E-5) { $bb = $player->getBoundingBox()->getOffsetBoundingBox($diff->x, $diff->y, $diff->z); if ($hand->getBoundingBox()->intersectsWith($bb)) { ++$realCount; } } } if ($realCount > 0) { return false; //Entity in block } } $tag = $item->getNamedTagEntry("CanPlaceOn"); if ($tag instanceof Enum) { $canPlace = false; foreach ($tag as $v) { if ($v instanceof String) { $entry = Item::fromString($v->getValue()); if ($entry->getId() > 0 and $entry->getBlock() !== null and $entry->getBlock()->getId() === $target->getId()) { $canPlace = true; break; } } } if (!$canPlace) { return false; } } if ($player !== null) { $ev = new BlockPlaceEvent($player, $hand, $block, $target, $item); if (!$player->isOp() and ($distance = $this->server->getSpawnRadius()) > -1) { $t = new Vector2($target->x, $target->z); $s = new Vector2($this->getSpawnLocation()->x, $this->getSpawnLocation()->z); if (count($this->server->getOps()->getAll()) > 0 and $t->distance($s) <= $distance) { //set it to cancelled so plugins can bypass this $ev->setCancelled(); } } $this->server->getPluginManager()->callEvent($ev); if ($ev->isCancelled()) { return false; } } if ($hand->place($item, $block, $target, $face, $fx, $fy, $fz, $player) === false) { return false; } if ($hand->getId() === Item::SIGN_POST or $hand->getId() === Item::WALL_SIGN) { $nbt = new Compound("", ["id" => new String("id", Tile::SIGN), "x" => new Int("x", $block->x), "y" => new Int("y", $block->y), "z" => new Int("z", $block->z), "Text1" => new String("Text1", ""), "Text2" => new String("Text2", ""), "Text3" => new String("Text3", ""), "Text4" => new String("Text4", "")]); if ($player !== null) { $nbt->Creator = new String("Creator", $player->getRawUniqueId()); } if ($item->hasCustomBlockData()) { foreach ($item->getCustomBlockData() as $key => $v) { $nbt->{$key} = $v; } } Tile::createTile("Sign", $this->getChunk($block->x >> 4, $block->z >> 4), $nbt); } $item->setCount($item->getCount() - 1); if ($item->getCount() <= 0) { $item = Item::get(Item::AIR, 0, 0); } return true; }
public function onActivate(Item $item, Player $player = null) { if ($player instanceof Player) { $top = $this->getSide(1); if ($top->isTransparent() !== true) { return true; } $t = $this->getLevel()->getTile($this); $chest = null; if ($t instanceof TileChest) { $chest = $t; } else { $nbt = new Compound(false, [new Enum("Items", []), new String("id", Tile::CHEST), new Int("x", $this->x), new Int("y", $this->y), new Int("z", $this->z)]); $nbt->Items->setTagType(NBT::TAG_Compound); $chest = Tile::createTile("Chest", $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt); } if ($player->isCreative()) { return true; } $player->addWindow($chest->getInventory()); } return true; }
public function initChunk() { if ($this->getProvider() instanceof LevelProvider and !$this->isInit) { $changed = \false; if ($this->NBTentities !== \null) { $this->getProvider()->getLevel()->timings->syncChunkLoadEntitiesTimer->startTiming(); foreach ($this->NBTentities as $nbt) { if ($nbt instanceof Compound) { if (!isset($nbt->id)) { $this->setChanged(); continue; } if ($nbt["Pos"][0] >> 4 !== $this->x or $nbt["Pos"][2] >> 4 !== $this->z) { $changed = \true; continue; //Fixes entities allocated in wrong chunks. } if (($entity = Entity::createEntity($nbt["id"], $this, $nbt)) instanceof Entity) { $entity->spawnToAll(); } else { $changed = \true; continue; } } } $this->getProvider()->getLevel()->timings->syncChunkLoadEntitiesTimer->stopTiming(); $this->getProvider()->getLevel()->timings->syncChunkLoadTileEntitiesTimer->startTiming(); foreach ($this->NBTtiles as $nbt) { if ($nbt instanceof Compound) { if (!isset($nbt->id)) { $changed = \true; continue; } if ($nbt["x"] >> 4 !== $this->x or $nbt["z"] >> 4 !== $this->z) { $changed = \true; continue; //Fixes tiles allocated in wrong chunks. } if (Tile::createTile($nbt["id"], $this, $nbt) === \null) { $changed = \true; continue; } } } $this->getProvider()->getLevel()->timings->syncChunkLoadTileEntitiesTimer->stopTiming(); $this->NBTentities = \null; $this->NBTtiles = \null; } $this->setChanged($changed); $this->isInit = \true; } }
/** * Uses a item on a position and face, placing it or activating the block * * @param Vector3 $vector * @param Item $item * @param int $face * @param float $fx default 0.0 * @param float $fy default 0.0 * @param float $fz default 0.0 * @param Player $player default null * * @return boolean */ public function useItemOn(Vector3 $vector, Item &$item, $face, $fx = 0.0, $fy = 0.0, $fz = 0.0, Player $player = null) { $target = $this->getBlock($vector); $block = $target->getSide($face); if ($block->y > 127 or $block->y < 0) { return false; } if ($target->getId() === Item::AIR) { return false; } if ($player instanceof Player) { $ev = new PlayerInteractEvent($player, $item, $target, $face); if (!$player->isOp() and ($distance = $this->server->getConfigInt("spawn-protection", 16)) > -1) { $t = new Vector2($target->x, $target->z); $s = new Vector2($this->getSpawnLocation()->x, $this->getSpawnLocation()->z); if ($t->distance($s) <= $distance) { //set it to cancelled so plugins can bypass this $ev->setCancelled(); } } $this->server->getPluginManager()->callEvent($ev); if (!$ev->isCancelled()) { $target->onUpdate(self::BLOCK_UPDATE_TOUCH); if ($target->canBeActivated() === true and $target->onActivate($item, $player) === true) { return true; } if ($item->canBeActivated() and $item->onActivate($this, $player, $block, $target, $face, $fx, $fy, $fz)) { if ($item->getCount() <= 0) { $item = Item::get(Item::AIR, 0, 0); return true; } } } } elseif ($target->canBeActivated() === true and $target->onActivate($item, $player) === true) { return true; } if ($item->isPlaceable()) { $hand = $item->getBlock(); $hand->position($block); } elseif ($block->getId() === Item::FIRE) { $this->setBlock($block, new Air(), true); return false; } else { return false; } if (!($block->canBeReplaced() === true or $hand->getId() === Item::SLAB and $block->getId() === Item::SLAB)) { return false; } if ($target->canBeReplaced() === true) { $block = $target; $hand->position($block); //$face = -1; } if ($hand->isSolid() === true and $hand->getBoundingBox() !== null) { $entities = $this->getCollidingEntities($hand->getBoundingBox()); $realCount = 0; foreach ($entities as $e) { if ($e instanceof Arrow or $e instanceof DroppedItem) { continue; } ++$realCount; } if ($realCount > 0) { return false; //Entity in block } } if ($player instanceof Player) { $ev = new BlockPlaceEvent($player, $hand, $block, $target, $item); if (!$player->isOp() and ($distance = $this->server->getConfigInt("spawn-protection", 16)) > -1) { $t = new Vector2($target->x, $target->z); $s = new Vector2($this->getSpawnLocation()->x, $this->getSpawnLocation()->z); if ($t->distance($s) <= $distance) { //set it to cancelled so plugins can bypass this $ev->setCancelled(); } } $this->server->getPluginManager()->callEvent($ev); if ($ev->isCancelled()) { return false; } } if ($hand->place($item, $block, $target, $face, $fx, $fy, $fz, $player) === false) { return false; } if ($hand->getId() === Item::SIGN_POST or $hand->getId() === Item::WALL_SIGN) { $tile = Tile::createTile("Sign", $this->getChunk($block->x >> 4, $block->z >> 4), new Compound(false, ["id" => new String("id", Tile::SIGN), "x" => new Int("x", $block->x), "y" => new Int("y", $block->y), "z" => new Int("z", $block->z), "Text1" => new String("Text1", ""), "Text2" => new String("Text2", ""), "Text3" => new String("Text3", ""), "Text4" => new String("Text4", "")])); if ($player instanceof Player) { $tile->namedtag->Creator = new String("Creator", $player->getName()); } } $item->setCount($item->getCount() - 1); if ($item->getCount() <= 0) { $item = Item::get(Item::AIR, 0, 0); } return true; }
public function blockBreak(BlockBreakEvent $event) { $block = $event->getBlock(); if ($block->getId() === $this->data["lucky_block"] && $this->isAllowedWorld($block->getLevel())) { $player = $event->getPlayer(); if (!$player->hasPermission("luckyblock.use")) { $player->sendMessage($this->tag . $this->message->get("not_allowed")); return; } $event->setCancelled(); $player->getLevel()->setBlock($block, new Block(Block::AIR), false, true); $rand = new Random(); switch ($rand->nextRange(1, 12)) { case 1: if (!isset($this->data["functions"]["spawnTree"]) || $this->data["functions"]["spawnTree"]) { $type = Sapling::OAK; switch ($rand->nextRange(0, 3)) { case 1: $type = Sapling::BIRCH; break; case 2: $type = Sapling::SPRUCE; break; case 3: $type = Sapling::JUNGLE; break; } if ($player->getLevel()->setBlock($block, new Sapling($type), true, true)) { $player->getLevel()->getBlock($block)->onActivate(new Item(Item::DYE, 15), $player); $player->sendMessage($this->tag . $this->message->get("tree")); } break; } case 2: if (!isset($this->data["functions"]["explosion"]) || $this->data["functions"]["explosion"]) { $explosion = new Explosion($block, mt_rand($this->data["explosion_min"], $this->data["explosion_max"])); if ($explosion->explodeA()) { $explosion->explodeB(); } $player->sendMessage($this->tag . $this->message->get("explosion")); break; } case 3: if (!isset($this->data["functions"]["dropItem"]) || $this->data["functions"]["dropItem"]) { if (mt_rand(0, 1)) { if ($this->itemLoop($player, $block)) { break; } } if (count($this->data["items_dropped"]) === 0) { $item = $this->randItem(); } else { $item = $this->data["items_dropped"][mt_rand(0, count($this->data["items_dropped"]) - 1)]; } $player->getLevel()->dropItem($block, $item); $player->sendMessage($this->tag . $this->message->get("drop")); break; } case 4: if (!isset($this->data["functions"]["bedrock"]) || $this->data["functions"]["bedrock"]) { $player->getLevel()->setBlock($block, new Block(Block::BEDROCK)); $p = new Position($block->x, $block->y + 1, $block->z, $block->level); if ($player->getLevel()->getBlock($p)->getId() != Block::AIR) { break; } $block->getLevel()->setBlock($p, Block::get(Item::SIGN_POST)); $sign = new Sign($player->getLevel()->getChunk($block->x >> 4, $block->z >> 4), new CompoundTag(false, array(new IntTag("x", (int) $block->x), new IntTag("y", (int) $block->y + 1), new IntTag("z", (int) $block->z), new StringTag("Text1", $this->tag), new StringTag("Text2", $this->message->get("signText"))))); $sign->spawnToAll(); $player->sendMessage($this->tag . $this->message->get("sign")); break; } case 5: if (!isset($this->data["functions"]["prison"]) || $this->data["functions"]["prison"]) { $pos = $event->getPlayer(); $pos->x = round($pos->x) + 0.5; $pos->y = round($pos->y); $pos->z = round($pos->z) + 0.5; $player->teleport($pos, $player->getYaw(), $player->getPitch()); $arr = []; switch ($rand->nextRange(1, 5)) { case 1: $player->getLevel()->setBlock(new Position($pos->x, $pos->y - 1, $pos->z, $pos->getLevel()), new Block(Block::OBSIDIAN)); for ($x = $pos->x - 1; $x <= $pos->x + 1; $x++) { for ($z = $pos->z - 1; $z <= $pos->z + 1; $z++) { if (!($x === $pos->x && $z === $pos->z)) { for ($y = $pos->y; $y <= $pos->y + 2; $y++) { $player->getLevel()->setBlock(new Position($x, $y, $z, $pos->getLevel()), new Block(Block::OBSIDIAN)); } } } } $player->getLevel()->updateAround($pos); $player->sendMessage($this->tag . $this->message->get("prison")); break; case 2: $player->getLevel()->setBlock(new Position($pos->x, $pos->y - 1, $pos->z, $pos->getLevel()), new Block(Block::STILL_LAVA)); $player->getLevel()->setBlock(new Position($pos->x, $pos->y - 2, $pos->z, $pos->getLevel()), new Block(Block::GLASS)); for ($x = $pos->x - 1; $x <= $pos->x + 1; $x++) { for ($z = $pos->z - 1; $z <= $pos->z + 1; $z++) { if (!($x === $pos->x && $z === $pos->z)) { for ($y = $pos->y; $y <= $pos->y + 2; $y++) { $player->getLevel()->setBlock(new Position($x, $y, $z, $pos->getLevel()), new Block(Block::IRON_BAR)); } } } } $player->getLevel()->updateAround($pos); $player->sendMessage($this->tag . $this->message->get("prison")); break; case 3: $player->getLevel()->setBlock(new Position($pos->x, $pos->y - 1, $pos->z, $pos->getLevel()), new Block(Block::SANDSTONE)); for ($x = $pos->x - 1; $x <= $pos->x + 1; $x++) { for ($z = $pos->z - 1; $z <= $pos->z + 1; $z++) { if (!($x === $pos->x && $z === $pos->z)) { for ($y = $pos->y; $y <= $pos->y + 2; $y++) { $player->getLevel()->setBlock(new Position($x, $y, $z, $pos->getLevel()), new Block(Block::IRON_BAR)); } } } } break; case 4: $arr = [["x" => -1, "y" => -1, "z" => -1, "block" => Block::OBSIDIAN], ["x" => -1, "y" => -1, "z" => 0, "block" => Block::OBSIDIAN], ["x" => -1, "y" => -1, "z" => 1, "block" => Block::OBSIDIAN], ["x" => 0, "y" => -1, "z" => -1, "block" => Block::OBSIDIAN], ["x" => 0, "y" => -1, "z" => 0, "block" => Block::OBSIDIAN], ["x" => 0, "y" => -1, "z" => 1, "block" => Block::OBSIDIAN], ["x" => 1, "y" => -1, "z" => -1, "block" => Block::OBSIDIAN], ["x" => 1, "y" => -1, "z" => 0, "block" => Block::OBSIDIAN], ["x" => 1, "y" => -1, "z" => 1, "block" => Block::OBSIDIAN], ["x" => -1, "y" => 0, "z" => -1, "block" => Block::OBSIDIAN], ["x" => -1, "y" => 0, "z" => 0, "block" => Block::OBSIDIAN], ["x" => -1, "y" => 0, "z" => 1, "block" => Block::OBSIDIAN], ["x" => 0, "y" => 0, "z" => -1, "block" => Block::OBSIDIAN], ["x" => 0, "y" => 0, "z" => 0, "block" => Block::STILL_WATER], ["x" => 0, "y" => 0, "z" => 1, "block" => Block::OBSIDIAN], ["x" => 1, "y" => 0, "z" => -1, "block" => Block::OBSIDIAN], ["x" => 1, "y" => 0, "z" => 0, "block" => Block::OBSIDIAN], ["x" => 1, "y" => 0, "z" => 1, "block" => Block::OBSIDIAN], ["x" => 1, "y" => 0, "z" => 1, "block" => Block::OBSIDIAN], ["x" => -1, "y" => 1, "z" => -1, "block" => Block::OBSIDIAN], ["x" => -1, "y" => 1, "z" => 0, "block" => Block::GLASS], ["x" => -1, "y" => 1, "z" => 1, "block" => Block::OBSIDIAN], ["x" => 0, "y" => 1, "z" => -1, "block" => Block::GLASS], ["x" => 0, "y" => 1, "z" => 0, "block" => Block::STILL_WATER], ["x" => 0, "y" => 1, "z" => 1, "block" => Block::GLASS], ["x" => 1, "y" => 1, "z" => -1, "block" => Block::OBSIDIAN], ["x" => 1, "y" => 1, "z" => 0, "block" => Block::GLASS], ["x" => 1, "y" => 1, "z" => 1, "block" => Block::OBSIDIAN], ["x" => -1, "y" => 2, "z" => -1, "block" => Block::OBSIDIAN], ["x" => -1, "y" => 2, "z" => 0, "block" => Block::OBSIDIAN], ["x" => -1, "y" => 2, "z" => 1, "block" => Block::OBSIDIAN], ["x" => 0, "y" => 2, "z" => -1, "block" => Block::OBSIDIAN], ["x" => 0, "y" => 2, "z" => 0, "block" => Block::OBSIDIAN], ["x" => 0, "y" => 2, "z" => 1, "block" => Block::OBSIDIAN], ["x" => 1, "y" => 2, "z" => -1, "block" => Block::OBSIDIAN], ["x" => 1, "y" => 2, "z" => 0, "block" => Block::OBSIDIAN], ["x" => 1, "y" => 2, "z" => 1, "block" => Block::OBSIDIAN]]; break; case 5: $arr = [["x" => -1, "y" => 0, "z" => -1, "block" => Block::STILL_LAVA], ["x" => -1, "y" => 0, "z" => 0, "block" => Block::STILL_LAVA], ["x" => -1, "y" => 0, "z" => 1, "block" => Block::STILL_LAVA], ["x" => 0, "y" => 0, "z" => -1, "block" => Block::STILL_LAVA], ["x" => 0, "y" => 0, "z" => 0, "block" => Block::STILL_LAVA], ["x" => 0, "y" => 0, "z" => 1, "block" => Block::STILL_LAVA], ["x" => 1, "y" => 0, "z" => -1, "block" => Block::STILL_LAVA], ["x" => 1, "y" => 0, "z" => 0, "block" => Block::STILL_LAVA], ["x" => 1, "y" => 0, "z" => 1, "block" => Block::STILL_LAVA], ["x" => -1, "y" => 1, "z" => -1, "block" => Block::COBWEB], ["x" => -1, "y" => 1, "z" => 0, "block" => Block::COBWEB], ["x" => -1, "y" => 1, "z" => 1, "block" => Block::COBWEB], ["x" => 0, "y" => 1, "z" => -1, "block" => Block::COBWEB], ["x" => 0, "y" => 1, "z" => 0, "block" => Block::COBWEB], ["x" => 0, "y" => 1, "z" => 1, "block" => Block::COBWEB], ["x" => 1, "y" => 1, "z" => -1, "block" => Block::COBWEB], ["x" => 1, "y" => 1, "z" => 0, "block" => Block::COBWEB], ["x" => 1, "y" => 1, "z" => 1, "block" => Block::COBWEB]]; break; } $pos = $player->getPosition(); foreach ($arr as $i => $c) { $player->getLevel()->setBlock($pos->add($c["x"], $c["y"], $c["z"]), Block::get($c["block"]), true, true); } break; } case 6: if (!isset($this->data["functions"]["chest"]) || $this->data["functions"]["chest"]) { $player->getLevel()->setBlock($block, new Block(Block::CHEST), true, true); $nbt = new CompoundTag("", [new ListTag("Items", []), new StringTag("id", Tile::CHEST), new IntTag("x", $block->x), new IntTag("y", $block->y), new IntTag("z", $block->z)]); $nbt->Items->setTagType(NBT::TAG_Compound); $tile = Tile::createTile("Chest", $block->getLevel()->getChunk($block->x >> 4, $block->z >> 4), $nbt); if ($tile instanceof Chest) { for ($i = 0; $i <= mt_rand(1, $this->data["max_chest_item"]); $i++) { if (count($this->data["items_dropped"]) === 0) { $item = $this->randItem(); } else { $item = $this->data["items_dropped"][mt_rand(0, count($this->data["items_dropped"]) - 1)]; } $tile->getInventory()->setItem($i, $item); } $player->sendMessage($this->tag . $this->message->get("chest")); } break; } case 7: if (!isset($this->data["functions"]["teleport"]) || $this->data["functions"]["teleport"]) { $player->teleport($player->getLevel()->getSpawnLocation(), $player->getYaw(), $player->getPitch()); $player->sendMessage($this->tag . $this->message->get("spawn")); break; } case 8: if (!isset($this->data["functions"]["potion"]) || $this->data["functions"]["potion"]) { if (count($this->data["potions"])) { $effect = Effect::getEffectByName($this->data["potions"][$rand->nextRange(0, count($this->data["potions"]) - 1)]); $effect->setDuration($rand->nextRange(20, $this->data["max_duration"] * 20)); $player->addEffect($effect); $player->sendMessage($this->tag . $this->message->get("effect")); } else { $player->sendMessage($this->tag . $this->message->get("unlucky")); } break; } case 9: //exec command if (!isset($this->data["functions"]["execCmd"]) || $this->data["functions"]["execCmd"]) { if (count($this->data["commands"])) { $cmd = $this->data["commands"][$rand->nextRange(0, count($this->data["commands"]) - 1)]; $cmd = str_replace(["%PLAYER%", "%X%", "%Y%", "%Z%", "%WORLD%", "%IP%", "%XP%"], [$player->getName(), $player->getX(), $player->getY(), $player->getZ(), $player->getLevel()->getName(), $player->getAddress(), $player->getXpLevel()], $cmd); $this->getServer()->dispatchCommand(new ConsoleCommandSender(), $cmd); $player->sendMessage($this->tag . $this->message->get("command")); break; } } case 10: //mob if (!isset($this->data["functions"]["mob"]) || $this->data["functions"]["mob"]) { if (count($this->data["mob"])) { $mob = $this->data["mob"][$rand->nextRange(0, count($this->data["mob"]) - 1)]; if ($this->isExistsEntity($mob)) { $nbt = new CompoundTag("", [new ListTag("Pos", [new DoubleTag("", $block->getX()), new DoubleTag("", $block->getY()), new DoubleTag("", $block->getZ())]), new ListTag("Rotation", [new FloatTag("", $player->getYaw()), new FloatTag("", $player->getPitch())]), new StringTag("CustomName", $this->tag)]); $entity = Entity::createEntity($mob, $player->getLevel()->getChunk($block->getX() >> 4, $block->getZ() >> 4), $nbt); if ($entity instanceof Entity) { $entity->spawnToAll(); $this->getServer()->getScheduler()->scheduleDelayedTask(new TaskExplodeMob($this, $entity, mt_rand($this->data["explosion_min"], $this->data["explosion_max"])), 20 * mt_rand(1, $this->data["mob_explosion_delay"])); $player->sendMessage($this->tag . $this->message->get("mob")); break; } } } } case 11: if (!isset($this->data["functions"]["lightning"]) || $this->data["functions"]["lightning"]) { $player->getLevel()->spawnLightning($player); $player->sendMessage($this->tag . $this->message->get("lightning")); break; } case 12: $player->sendMessage($this->tag . $this->message->get("unlucky")); break; } $player->getLevel()->save(); } }