public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz) { if ($this->meta === Item::AIR) { if ($target instanceof Liquid) { $level->setBlock($target, new Air(), true); if (($player->gamemode & 0x1) === 0) { $this->meta = $target instanceof Water ? Item::WATER : Item::LAVA; } return true; } } elseif ($this->meta === Item::WATER) { //Support Make Non-Support Water to Support Water if ($block->getID() === self::AIR || $block instanceof Water && ($block->getDamage() & 0x7) != 0x0) { $water = new Water(); $level->setBlock($block, $water, true); $water->place(clone $this, $block, $target, $face, $fx, $fy, $fz, $player); if (($player->gamemode & 0x1) === 0) { $this->meta = 0; } return true; } } elseif ($this->meta === Item::LAVA) { if ($block->getID() === self::AIR) { $level->setBlock($block, new Lava(), true); if (($player->gamemode & 0x1) === 0) { $this->meta = 0; } return true; } } return false; }
/** * @param Block $block * @return bool */ private function isBlockSpecified(Block $block) { $key = array_change_key_case($this->getConfig()->getNested("level." . $block->getLevel()->getName()), CASE_LOWER); if (is_array($key)) { return in_array($block->getId() . ":" . $block->getDamage(), $key); } }
/** * @param CommandSender $sender * @param Block $block */ public function sendBlockInfo(CommandSender $sender, Block $block) { $sender->sendMessage("Name: " . $block->getName()); $sender->sendMessage("XYZ: " . $block->getFloorX() . ":" . $block->getFloorY() . ":" . $block->getFloorZ()); $sender->sendMessage("Level: " . $block->getLevel()->getName()); $sender->sendMessage("Block-id: " . $block->getId() . ":" . $block->getDamage()); $sender->sendMessage("Hardness: " . $block->getHardness()); $sender->sendMessage("Resistance: " . $block->getResistance()); $sender->sendMessage("Tool-type: " . $block->getToolType()); $sender->sendMessage("Friction: " . $block->getFrictionFactor()); $sender->sendMessage("Light-level: " . $block->getLightLevel()); //$sender->sendMessage("Is-placeable: ".($block->canBePlaced() ? TextFormat::GREEN."yes" : TextFormat::RED."no")); $sender->sendMessage("Is-replaceable: " . ($block->canBeReplaced() ? TextFormat::GREEN . "yes" : TextFormat::RED . "no")); $sender->sendMessage("Is-transparent: " . ($block->isTransparent() ? TextFormat::GREEN . "yes" : TextFormat::RED . "no")); $sender->sendMessage("Is-solid: " . ($block->isSolid() ? TextFormat::GREEN . "yes" : TextFormat::RED . "no")); //$sender->sendMessage("Is-flowable: ".($block->canBeFlowedInto() ? TextFormat::GREEN."yes" : TextFormat::RED."no")); //$sender->sendMessage("Is-activateable: ".($block->canBeActivated() ? TextFormat::GREEN."yes" : TextFormat::RED."no")); $sender->sendMessage("Is-passable: " . ($block->canPassThrough() ? TextFormat::GREEN . "yes" : TextFormat::RED . "no")); $dropCount = 0; $dropNames = ""; foreach ($block->getDrops() as $drop) { $dropNames .= $drop->getName() . ", "; $dropCount++; } $sender->sendMessage("Drops (" . $dropCount . "): " . substr($dropNames, 0, -2)); }
/** * @param Block $block * @return bool */ public function isFreezable(Block $block) { if (isset($this->configs[$ilevel = strtolower($block->getLevel()->getName())])) { return $this->configs[$ilevel]->exists($block->getId() . ":" . $block->getDamage(), true); } return false; }
/** * @param Block $block * @return bool */ public function isBlockSpecified(Block $block) { $key = array_change_key_case($this->getConfig()->get("level"), CASE_LOWER); $levelKey = $key[strtolower($block->getLevel()->getName())]; if (is_array($levelKey)) { return in_array($block->getId() . ":" . $block->getDamage(), $levelKey); } }
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null) { if ($target->getId() === Block::WOOD and $target->getDamage() === Wood::JUNGLE) { if ($face !== 0 and $face !== 1) { $faces = [2 => 0, 3 => 2, 4 => 3, 5 => 1]; $this->meta = $faces[$face]; $this->getLevel()->setBlock($block, $this, true); return true; } } return false; }
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz) { $bucketContents = Block::get($this->meta); if ($bucketContents instanceof Air) { // Bucket Empty so pick up block if ($target instanceof Liquid and $target->getDamage() === 0) { $result = clone $this; if ($target instanceof StillWater) { $toStore = Block::WATER; } elseif ($target instanceof StillLava) { $toStore = Block::LAVA; } else { return false; } $result->setDamage($toStore); $player->getServer()->getPluginManager()->callEvent($ev = new PlayerBucketFillEvent($player, $block, $face, $this, $result)); if (!$ev->isCancelled()) { $player->getLevel()->setBlock($target, new Air(), true, true); if ($player->isSurvival()) { $player->getInventory()->setItemInHand($ev->getItem(), $player); } return true; } else { $player->getInventory()->sendContents($player); } } } elseif ($bucketContents instanceof Liquid) { // Bucket Full, so empty $result = clone $this; $result->setDamage(0); if ($bucketContents instanceof Water) { $toCreate = Block::STILL_WATER; } elseif ($bucketContents instanceof Lava) { $toCreate = Block::STILL_LAVA; } else { return false; } $bucketContents = Block::get($toCreate); $player->getServer()->getPluginManager()->callEvent($ev = new PlayerBucketFillEvent($player, $block, $face, $this, $result)); if (!$ev->isCancelled()) { $player->getLevel()->setBlock($block, $bucketContents, true, true); if ($player->isSurvival()) { $player->getInventory()->setItemInHand($ev->getItem(), $player); } return true; } else { $player->getInventory()->sendContents($player); } } return false; }
/** * @param Block $sourceBlock a Block with the absolute X, Y and Z from the original level */ public function addEntry(Block $sourceBlock) { if (!$this->isWritable) { throw new \InvalidStateException("This clip is not writable"); } if (!$sourceBlock->isValid()) { throw new \InvalidArgumentException("Source block must contain a level and absolute coords"); } if ($sourceBlock->getLevel()->getName() !== $this->levelName) { throw new \InvalidStateException("Block is not from the level clip is being written in"); } $delta = $sourceBlock->subtract($this->anchor); $insert = Block::get($sourceBlock->getId(), $sourceBlock->getDamage(), Position::fromObject($delta->subtract($this->anchor))); $this->entries[] = $insert; }
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz) { $targetBlock = Block::get($this->meta); if ($targetBlock instanceof Air) { if ($target instanceof Liquid and $target->getDamage() === 0) { $result = clone $this; $id = $target->getId(); if ($id == self::STILL_WATER) { $id = self::WATER; } if ($id == self::STILL_LAVA) { $id = self::LAVA; } $result->setDamage($id); $player->getServer()->getPluginManager()->callEvent($ev = new PlayerBucketFillEvent($player, $block, $face, $this, $result)); if (!$ev->isCancelled()) { $player->getLevel()->setBlock($target, new Air(), true, true); if ($player->isSurvival()) { $player->getInventory()->setItemInHand($ev->getItem()); } return true; } else { $player->getInventory()->sendContents($player); } } } elseif ($targetBlock instanceof Liquid) { $result = clone $this; $result->setDamage(0); $player->getServer()->getPluginManager()->callEvent($ev = new PlayerBucketEmptyEvent($player, $block, $face, $this, $result)); if (!$ev->isCancelled()) { //Only disallow water placement in the Nether, allow other liquids to be placed //In vanilla, water buckets are emptied when used in the Nether, but no water placed. if (!($player->getLevel()->getDimension() === Level::DIMENSION_NETHER and $targetBlock->getID() === self::WATER)) { $player->getLevel()->setBlock($block, $targetBlock, true, true); } if ($player->isSurvival()) { $player->getInventory()->setItemInHand($ev->getItem()); } return true; } else { $player->getInventory()->sendContents($player); } } return false; }
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null) { $this->meta &= 0x7; if ($face === 0) { if ($target->getID() === self::WOOD_SLAB and ($target->getDamage() & 0x8) === 0x8 and ($target->getDamage() & 0x7) === ($this->meta & 0x7)) { $this->getLevel()->setBlock($target, Block::get(Item::DOUBLE_WOOD_SLAB, $this->meta), true); return true; } elseif ($block->getID() === self::WOOD_SLAB and ($block->getDamage() & 0x7) === ($this->meta & 0x7)) { $this->getLevel()->setBlock($block, Block::get(Item::DOUBLE_WOOD_SLAB, $this->meta), true); return true; } else { $this->meta |= 0x8; } } elseif ($face === 1) { if ($target->getID() === self::WOOD_SLAB and ($target->getDamage() & 0x8) === 0 and ($target->getDamage() & 0x7) === ($this->meta & 0x7)) { $this->getLevel()->setBlock($target, Block::get(Item::DOUBLE_WOOD_SLAB, $this->meta), true); return true; } elseif ($block->getID() === self::WOOD_SLAB and ($block->getDamage() & 0x7) === ($this->meta & 0x7)) { $this->getLevel()->setBlock($block, Block::get(Item::DOUBLE_WOOD_SLAB, $this->meta), true); return true; } } elseif (!$player instanceof Player) { //TODO: collision if ($block->getID() === self::WOOD_SLAB) { if (($block->getDamage() & 0x7) === ($this->meta & 0x7)) { $this->getLevel()->setBlock($block, Block::get(Item::DOUBLE_WOOD_SLAB, $this->meta), true); return true; } return false; } else { if ($fy > 0.5) { $this->meta |= 0x8; } } } else { return false; } if ($block->getID() === self::WOOD_SLAB and ($target->getDamage() & 0x7) !== ($this->meta & 0x7)) { return false; } $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->meta &= 0x7; if ($face === 0) { if ($target->getId() === self::SLAB and ($target->getDamage() & 0x8) === 0x8 and ($target->getDamage() & 0x7) === ($this->meta & 0x7)) { $this->getLevel()->setBlock($target, Block::get(Item::DOUBLE_SLAB, $this->meta), \true); return \true; } elseif ($block->getId() === self::SLAB and ($block->getDamage() & 0x7) === ($this->meta & 0x7)) { $this->getLevel()->setBlock($block, Block::get(Item::DOUBLE_SLAB, $this->meta), \true); return \true; } else { $this->meta |= 0x8; } } elseif ($face === 1) { if ($target->getId() === self::SLAB and ($target->getDamage() & 0x8) === 0 and ($target->getDamage() & 0x7) === ($this->meta & 0x7)) { $this->getLevel()->setBlock($target, Block::get(Item::DOUBLE_SLAB, $this->meta), \true); return \true; } elseif ($block->getId() === self::SLAB and ($block->getDamage() & 0x7) === ($this->meta & 0x7)) { $this->getLevel()->setBlock($block, Block::get(Item::DOUBLE_SLAB, $this->meta), \true); return \true; } //TODO: check for collision } else { if ($block->getId() === self::SLAB) { if (($block->getDamage() & 0x7) === ($this->meta & 0x7)) { $this->getLevel()->setBlock($block, Block::get(Item::DOUBLE_SLAB, $this->meta), \true); return \true; } return \false; } else { if ($fy > 0.5) { $this->meta |= 0x8; } } } if ($block->getId() === self::SLAB and ($target->getDamage() & 0x7) !== ($this->meta & 0x7)) { return \false; } $this->getLevel()->setBlock($block, $this, \true, \true); return \true; }
public function matches(Block $block) { return $block->getId() === $this->block->getId() and ($this->damageSensitive or $block->getDamage() === $this->block->getDamage()); }
public function replaceBlock($startX, $startY, $startZ, $endX, $endY, $endZ, Block $block, Block $target, Player $player = null) { $count = 0; $x = $startX; $y = $startY; $z = $startZ; if (is_array($y)) { $startY = $y[1]; $y = $y[0]; } if (is_array($z)) { $startZ = $z[1]; $z = $z[0]; } while (true) { if ($count < $this->getData("limit-block", 130)) { $chunk = $block->getLevel()->getChunk($x >> 4, $z >> 4, true); if ($chunk !== null) { $id = $chunk->getBlockId($x & 0xf, $y & 0x7f, $z & 0xf); $meta = $chunk->getBlockData($x & 0xf, $y & 0x7f, $z & 0xf); if ($id === $block->getId() && $meta === $block->getDamage()) { ++$count; $this->saveUndo($block, $pos = new Vector3($x, $y, $z)); $this->set($target, $pos); } } if ($z < $endZ) { $z++; } else { $z = $startZ; if ($y < $endY) { $y++; } else { $y = $startY; if ($x < $endX) { $x++; } else { break; } } } } else { self::core()->getScheduler()->scheduleDelayedTask(new WorldEditorTask([$this, "replaceBlock"], [$x, [$y, $startY], [$z, $startZ], $endX, $endY, $endZ, $block, $target, $player], $this), 1); return; } } if ($player !== null) { $player->sendMessage("[WorldEditor]모든 블럭을 변경했어요"); } if ($this->getData("debug", false)) { $name = $player === null ? "" : "{$player->getName()}님이 "; self::core()->getLogger()->info("[WorldEditor]{$name}블럭변경을 끝냈어요"); } }
/** * @param Block $block * @return bool */ public function isRocketPad(Block $block) { if (is_array($this->getConfig()->getNested("pad.blockId"))) { return in_array($block->getId() . ":" . $block->getDamage(), $this->getConfig()->getNested("pad.blockId")); } }
/** * @param Block $leaves * @return Sapling */ public function getSapling(Block $leaves) { if ($leaves instanceof Leaves) { $damage = $leaves->getDamage(); if ($leaves instanceof Leaves2) { switch ($damage) { default: case Leaves2::ACACIA: return new Sapling(Sapling::ACACIA); case Leaves2::DARK_OAK: return new Sapling(Sapling::DARK_OAK); } } else { return new Sapling($damage); } } else { return new Sapling(); } }
public function isBlockLiquid(Block $block) { return in_array($block->getId() . ":" . $block->getDamage(), $this->key); }
public function getInstrument(Block $block) { switch ($block->getId()) { case self::STONE: case self::COBBLESTONE: case self::COBBLE_STAIRS: case self::BEDROCK: case self::GOLD_ORE: case self::IRON_ORE: case self::COAL_ORE: case self::LAPIS_ORE: case self::DIAMOND_ORE: case self::REDSTONE_ORE: case self::EMERALD_ORE: case self::GLOWING_REDSTONE_ORE: case self::FURNACE: case self::BURNING_FURNACE: case self::BRICKS: case self::BRICK_STAIRS: case self::STONE_BRICK: case self::STONE_BRICK_STAIRS: case self::NETHERRACK: case self::COBBLE_WALL: case self::STONECUTTER: case self::MOSS_STONE: case self::OBSIDIAN: case self::SANDSTONE: case self::END_STONE: case self::MONSTER_SPAWNER: case self::END_PORTAL_FRAME: case self::QUARTZ_BLOCK: case self::QUARTZ_STAIRS: case self::NETHER_BRICKS: case self::NETHER_BRICKS_STAIRS: case self::ENCHANT_TABLE: case self::STONE_PRESSURE_PLATE: return NoteBlockSound::INSTRUMENT_BASS_DRUM; case self::SAND: case self::GRAVEL: case self::SOUL_SAND: return NoteBlockSound::INSTRUMENT_SNARE_DRUM; case self::GLASS: case self::GLASS_PANEL: case self::GLOWSTONE: return NoteBlockSound::INSTRUMENT_CLICKS_AND_STICKS; case self::WOOD: case self::WOOD2: case self::PLANK: case self::SPRUCE_WOOD_STAIRS: case self::BIRCH_WOOD_STAIRS: case self::JUNGLE_WOOD_STAIRS: case self::DOUBLE_WOOD_SLAB: case self::ACACIA_WOOD_STAIRS: case self::DARK_OAK_WOOD_STAIRS: case self::WOOD_STAIRS: case self::BOOKSHELF: case self::CHEST: case self::WORKBENCH: case self::SIGN_POST: case self::WALL_SIGN: case self::WOOD_DOOR_BLOCK: case self::SPRUCE_DOOR_BLOCK: case self::BIRCH_DOOR_BLOCK: case self::JUNGLE_DOOR_BLOCK: case self::ACACIA_DOOR_BLOCK: case self::DARK_OAK_DOOR_BLOCK: case self::TRAPDOOR: case self::FENCE: case self::FENCE_GATE: case self::FENCE_GATE_SPRUCE: case self::FENCE_GATE_BIRCH: case self::FENCE_GATE_JUNGLE: case self::FENCE_GATE_DARK_OAK: case self::FENCE_GATE_ACACIA: case self::WOOD_SLAB: case self::BROWN_MUSHROOM: case self::RED_MUSHROOM: case self::NOTEBLOCK: case self::WOODEN_PRESSURE_PLATE: case self::DAYLIGHT_DETECTOR: case self::DAYLIGHT_DETECTOR_INVERTED: return NoteBlockSound::INSTRUMENT_BASS_GUITAR; break; case self::SLAB: case self::DOUBLE_SLAB: if ($block->getDamage() == 2) { // Wooden Slab return NoteBlockSound::INSTRUMENT_BASS_GUITAR; } else { // else : Stones return NoteBlockSound::INSTRUMENT_BASS_DRUM; } break; default: return NoteBlockSound::INSTRUMENT_PIANO_OR_HARP; break; } }
private static function rotateBlockByOne(Block $block) { return Block::get($block->getID(), $block->getDamage(), new Position($block->getZ(), $block->getY(), -$block->getX(), $block->getLevel())); }
public function __construct(Vector3 $pos, Block $b) { parent::__construct($pos->x, $pos->y, $pos->z); $this->data = $b->getId() + ($b->getDamage() << 12); }
public function __construct(Block $block, $meta = 0, $count = 1) { $this->block = $block; parent::__construct($block->getId(), $block->getDamage(), $count, $block->getName()); }
/** * Sets on Vector3 the data from a Block object, * does block updates and puts the changes to the send queue. * * If $direct is true, it'll send changes directly to players. if false, it'll be queued * and the best way to send queued changes will be done in the next tick. * This way big changes can be sent on a single chunk update packet instead of thousands of packets. * * If $update is true, it'll get the neighbour blocks (6 sides) and update them. * If you are doing big changes, you might want to set this to false, then update manually. * * @param Vector3 $pos * @param Block $block * @param bool $direct * @param bool $update * * @return bool Whether the block has been updated or not */ public function setBlock(Vector3 $pos, Block $block, $direct = false, $update = true) { if ($pos->y < 0 or $pos->y >= 128) { return false; } unset($this->blockCache[$index = PHP_INT_SIZE === 8 ? ($pos->x & 0xfffffff) << 35 | ($pos->y & 0x7f) << 28 | $pos->z & 0xfffffff : $pos->x . ":" . $pos->y . ":" . $pos->z]); if ($this->getChunk($pos->x >> 4, $pos->z >> 4, true)->setBlock($pos->x & 0xf, $pos->y & 0x7f, $pos->z & 0xf, $block->getId(), $block->getDamage())) { if (!$pos instanceof Position) { $pos = $this->temporalPosition->setComponents($pos->x, $pos->y, $pos->z); } $block->position($pos); $index = PHP_INT_SIZE === 8 ? ($pos->x >> 4 & 4294967295.0) << 32 | $pos->z >> 4 & 4294967295.0 : ($pos->x >> 4) . ":" . ($pos->z >> 4); if (ADVANCED_CACHE == true) { Cache::remove("world:" . $this->getId() . ":" . $index); } if ($direct === true) { $pk = new UpdateBlockPacket(); $pk->x = $pos->x; $pk->y = $pos->y; $pk->z = $pos->z; $pk->block = $block->getId(); $pk->meta = $block->getDamage(); Server::broadcastPacket($this->getUsingChunk($pos->x >> 4, $pos->z >> 4), $pk); } else { if (!$pos instanceof Position) { $pos = $this->temporalPosition->setComponents($pos->x, $pos->y, $pos->z); } $block->position($pos); if (!isset($this->changedBlocks[$index])) { $this->changedBlocks[$index] = []; $this->changedCount[$index] = 0; } $Y = $pos->y >> 4; if (!isset($this->changedBlocks[$index][$Y])) { $this->changedBlocks[$index][$Y] = []; $this->changedCount[$index] |= 1 << $Y; } $this->changedBlocks[$index][$Y][] = clone $block; } if ($update === true) { $this->updateAllLight($block); $this->server->getPluginManager()->callEvent($ev = new BlockUpdateEvent($block)); if (!$ev->isCancelled()) { $ev->getBlock()->onUpdate(self::BLOCK_UPDATE_NORMAL); foreach ($this->getNearbyEntities(new AxisAlignedBB($block->x - 1, $block->y - 1, $block->z - 1, $block->x + 2, $block->y + 2, $block->z + 2)) as $entity) { $entity->scheduleUpdate(); } } $this->updateAround($pos); } return true; } return false; }
public static function keyBlock(Block $block) { return "{$block->getID()}:{$block->getDamage()}"; }
/** * Sets on Vector3 the data from a Block object, * does block updates and puts the changes to the send queue. * * If $direct is true, it'll send changes directly to players. if false, it'll be queued * and the best way to send queued changes will be done in the next tick. * This way big changes can be sent on a single chunk update packet instead of thousands of packets. * * If $update is true, it'll get the neighbour blocks (6 sides) and update them. * If you are doing big changes, you might want to set this to false, then update manually. * * @param Vector3 $pos * @param Block $block * @param bool $direct @deprecated * @param bool $update * @param bool $extended * * @return bool Whether the block has been updated or not */ public function setBlock(Vector3 $pos, Block $block, $direct = false, $update = true, $extended = false) { if ($pos->y < 0 or $pos->y >= 128) { return false; } if ($this->getChunk($pos->x >> 4, $pos->z >> 4, true)->setBlock($pos->x & 0xf, $pos->y & 0x7f, $pos->z & 0xf, $block->getId(), $block->getDamage())) { if (!$pos instanceof Position) { $pos = $this->temporalPosition->setComponents($pos->x, $pos->y, $pos->z); } $block->position($pos); unset($this->blockCache[Level::blockHash($pos->x, $pos->y, $pos->z)]); $index = Level::chunkHash($pos->x >> 4, $pos->z >> 4); if ($direct === true) { $this->sendBlocks($this->getChunkPlayers($pos->x >> 4, $pos->z >> 4), [$block], UpdateBlockPacket::FLAG_ALL_PRIORITY); unset($this->chunkCache[$index]); } else { if (!isset($this->changedBlocks[$index])) { $this->changedBlocks[$index] = []; } $this->changedBlocks[$index][Level::blockHash($block->x, $block->y, $block->z)] = clone $block; } foreach ($this->getChunkLoaders($pos->x >> 4, $pos->z >> 4) as $loader) { $loader->onBlockChanged($block); } if ($update === true) { $this->updateAllLight($block); $this->server->getPluginManager()->callEvent($ev = new BlockUpdateEvent($block)); if (!$ev->isCancelled()) { foreach ($this->getNearbyEntities(new AxisAlignedBB($block->x - 1, $block->y - 1, $block->z - 1, $block->x + 1, $block->y + 1, $block->z + 1)) as $entity) { $entity->scheduleUpdate(); } $ev->getBlock()->onUpdate(self::BLOCK_UPDATE_NORMAL); $ev->getBlock()->onUpdate(self::BLOCK_UPDATE_REDSTONE); } $this->updateAround($pos, $extended); } return true; } return false; }
/** * Sets on Vector3 the data from a Block object, * does block updates and puts the changes to the send queue. * * If $direct is true, it'll send changes directly to players. if false, it'll be queued * and the best way to send queued changes will be done in the next tick. * This way big changes can be sent on a single chunk update packet instead of thousands of packets. * * If $update is true, it'll get the neighbour blocks (6 sides) and update them. * If you are doing big changes, you might want to set this to false, then update manually. * * @param Vector3 $pos * @param Block $block * @param bool $direct * @param bool $update * * @return bool */ public function setBlock(Vector3 $pos, Block $block, $direct = false, $update = true) { if ($pos->y < 0 or $pos->y >= 128 or !$block instanceof Block) { return false; } if ($this->getChunkAt($pos->x >> 4, $pos->z >> 4, true)->setBlock($pos->x & 0xf, $pos->y & 0x7f, $pos->z & 0xf, $block->getID(), $block->getDamage())) { if (!$pos instanceof Position) { $pos = new Position($pos->x, $pos->y, $pos->z, $this); } $block->position($pos); $index = Level::chunkHash($pos->x >> 4, $pos->z >> 4); if (ADVANCED_CACHE == true) { Cache::remove("world:" . $this->getID() . ":" . $index); } if ($direct === true) { $pk = new UpdateBlockPacket(); $pk->x = $pos->x; $pk->y = $pos->y; $pk->z = $pos->z; $pk->block = $block->getID(); $pk->meta = $block->getDamage(); foreach ($this->getUsingChunk($pos->x >> 4, $pos->z >> 4) as $player) { /** @var Player $player */ $player->directDataPacket($pk); } } else { if (!$pos instanceof Position) { $pos = new Position($pos->x, $pos->y, $pos->z, $this); } $block->position($pos); if (!isset($this->changedBlocks[$index])) { $this->changedBlocks[$index] = []; $this->changedCount[$index] = 0; } $Y = $pos->y >> 4; if (!isset($this->changedBlocks[$index][$Y])) { $this->changedBlocks[$index][$Y] = []; $this->changedCount[$index] |= 1 << $Y; } $this->changedBlocks[$index][$Y][] = clone $block; } if ($update === true) { $this->updateAround($pos, self::BLOCK_UPDATE_NORMAL); $block->onUpdate(self::BLOCK_UPDATE_NORMAL); } } }
public function __construct(Vector3 $pos, Block $b) { parent::__construct($pos, Particle::TYPE_TERRAIN, $b->getDamage() << 8 | $b->getId()); }
public function __construct(Vector3 $pos, Block $b) { parent::__construct($pos, 15, $b->getDamage() << 8 | $b->getId()); }
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz) { $targetBlock = Block::get($this->meta); if ($targetBlock instanceof Air) { if ($target instanceof Liquid and $target->getDamage() === 0) { $result = clone $this; $result->setDamage($target->getId()); $player->getServer()->getPluginManager()->callEvent($ev = new PlayerBucketFillEvent($player, $block, $face, $this, $result)); if (!$ev->isCancelled()) { $player->getLevel()->setBlock($target, new Air(), true, true); if ($player->isSurvival()) { $player->getInventory()->setItemInHand($ev->getItem(), $player); } return true; } else { $player->getInventory()->sendContents($player); } } } elseif ($targetBlock instanceof Liquid) { $result = clone $this; $result->setDamage(0); $player->getServer()->getPluginManager()->callEvent($ev = new PlayerBucketFillEvent($player, $block, $face, $this, $result)); if (!$ev->isCancelled()) { $player->getLevel()->setBlock($block, $targetBlock, true, true); if ($player->isSurvival()) { $player->getInventory()->setItemInHand($ev->getItem(), $player); } return true; } else { $player->getInventory()->sendContents($player); } } return false; }