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 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) { $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) { $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) { $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("", [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 (isset($chest->namedtag->Lock) and $chest->namedtag->Lock instanceof String) { if ($chest->namedtag->Lock->getValue() !== $item->getCustomName()) { return true; } } if ($player->isCreative()) { return true; } $player->addWindow($chest->getInventory()); } return 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 !== null) { $ev = new PlayerInteractEvent($player, $item, $target, $face, $target->getId() === 0 ? PlayerInteractEvent::RIGHT_CLICK_AIR : PlayerInteractEvent::RIGHT_CLICK_BLOCK); if ($player->isSpectator()) { $ev->setCancelled(); } 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 ($t->distance($s) <= $distance) { $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); } else { return false; } if (!($block->canBeReplaced() === true or $hand->getId() === Item::SLAB and $block->getId() === Item::SLAB)) { return false; //can anyone explain this to me?- Zombie } 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 ($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 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; } }
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 (isset($furnace->namedtag->Lock) and $furnace->namedtag->Lock instanceof String) { if ($furnace->namedtag->Lock->getValue() !== $item->getCustomName()) { return true; } } if ($player->isCreative()) { return true; } $player->addWindow($furnace->getInventory()); } return true; }