public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz) { if ($this->meta === AIR) { if ($target instanceof LiquidBlock) { $level->setBlock($target, new AirBlock(), true, false, true); if (($player->gamemode & 0x1) === 0) { $this->meta = $target instanceof WaterBlock ? WATER : LAVA; } return true; } } elseif ($this->meta === WATER) { //Support Make Non-Support Water to Support Water if ($block->getID() === AIR || $block instanceof WaterBlock && ($block->getMetadata() & 0x7) != 0x0) { $water = new WaterBlock(); $level->setBlock($block, $water, true, false, true); $water->place(clone $this, $player, $block, $target, $face, $fx, $fy, $fz); if (($player->gamemode & 0x1) === 0) { $this->meta = 0; } return true; } } elseif ($this->meta === LAVA) { if ($block->getID() === AIR) { $level->setBlock($block, new LavaBlock(), true, false, true); if (($player->gamemode & 0x1) === 0) { $this->meta = 0; } return true; } } return false; }
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz) { if (($target->isTransparent === false or $target->getID() === SLAB) and $face !== 0 and $face !== 1) { $faces = array(2 => 0, 3 => 1, 4 => 2, 5 => 3); $this->meta = $faces[$face] & 0x3; if ($fy > 0.5) { $this->meta |= 0x8; } $this->level->setBlock($block, $this, true, false, true); return true; } }
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz) { $this->meta &= 0x7; if ($face === 0) { if ($target->getID() === WOOD_SLAB and ($target->getMetadata() & 0x8) === 0x8 and ($target->getMetadata() & 0x7) === ($this->meta & 0x7)) { $this->level->setBlock($target, BlockAPI::get(DOUBLE_WOOD_SLAB, $this->meta), true, false, true); return true; } elseif ($block->getID() === WOOD_SLAB and ($block->getMetadata() & 0x7) === ($this->meta & 0x7)) { $this->level->setBlock($block, BlockAPI::get(DOUBLE_WOOD_SLAB, $this->meta), true, false, true); return true; } else { $this->meta |= 0x8; } } elseif ($face === 1) { if ($target->getID() === WOOD_SLAB and ($target->getMetadata() & 0x8) === 0 and ($target->getMetadata() & 0x7) === ($this->meta & 0x7)) { $this->level->setBlock($target, BlockAPI::get(DOUBLE_WOOD_SLAB, $this->meta), true, false, true); return true; } elseif ($block->getID() === WOOD_SLAB and ($block->getMetadata() & 0x7) === ($this->meta & 0x7)) { $this->level->setBlock($block, BlockAPI::get(DOUBLE_WOOD_SLAB, $this->meta), true, false, true); return true; } } elseif (!$player->entity->inBlock($block)) { if ($block->getID() === WOOD_SLAB) { if (($block->getMetadata() & 0x7) === ($this->meta & 0x7)) { $this->level->setBlock($block, BlockAPI::get(DOUBLE_WOOD_SLAB, $this->meta), true, false, true); return true; } return false; } else { if ($fy > 0.5) { $this->meta |= 0x8; } } } else { return false; } if ($block->getID() === WOOD_SLAB and ($target->getMetadata() & 0x7) !== ($this->meta & 0x7)) { return false; } $this->level->setBlock($block, $this, true, false, true); return true; }
public function setBlock(Vector3 $pos, Block $block, $update = true, $tiles = false, $direct = false) { if (!isset($this->level) or $pos instanceof Position and $pos->level !== $this or $pos->x < 0 or $pos->y < 0 or $pos->z < 0) { return false; } $ret = $this->level->setBlock($pos->x, $pos->y, $pos->z, $block->getID(), $block->getMetadata()); if ($ret === true) { if (!$pos instanceof Position) { $pos = new Position($pos->x, $pos->y, $pos->z, $this); } $block->position($pos); 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->getMetadata(); $this->server->api->player->broadcastPacket($this->players, $pk); } else { $i = ($pos->x >> 4) . ":" . ($pos->y >> 4) . ":" . ($pos->z >> 4); if (!isset($this->changedBlocks[$i])) { $this->changedBlocks[$i] = array(); $this->changedCount[$i] = 0; } if (ADVANCED_CACHE == true) { Cache::remove("world:{$this->name}:" . ($pos->x >> 4) . ":" . ($pos->z >> 4)); } $this->changedBlocks[$i][] = clone $block; ++$this->changedCount[$i]; } if ($update === true) { $this->server->api->block->blockUpdateAround($pos, BLOCK_UPDATE_NORMAL, 1); $this->server->api->entity->updateRadius($pos, 3); } if ($tiles === true) { if (($t = $this->server->api->tile->get($pos)) !== false) { $t->close(); } } } return $ret; }
private function findLog(Block $pos, array $visited, $distance, &$check, $fromSide = null) { ++$check; $index = $pos->x . "." . $pos->y . "." . $pos->z; if (isset($visited[$index])) { return false; } if ($pos->getID() === WOOD) { return true; } elseif ($pos->getID() === LEAVES and $distance < 3) { $visited[$index] = true; $down = $pos->getSide(0)->getID(); if ($down === WOOD) { return true; } if ($fromSide === null) { for ($side = 2; $side <= 5; ++$side) { if ($this->findLog($pos->getSide($side), $visited, $distance + 1, $check, $side) === true) { return true; } } } else { //No more loops switch ($fromSide) { case 2: if ($this->findLog($pos->getSide(2), $visited, $distance + 1, $check, $fromSide) === true) { return true; } elseif ($this->findLog($pos->getSide(4), $visited, $distance + 1, $check, $fromSide) === true) { return true; } elseif ($this->findLog($pos->getSide(5), $visited, $distance + 1, $check, $fromSide) === true) { return true; } break; case 3: if ($this->findLog($pos->getSide(3), $visited, $distance + 1, $check, $fromSide) === true) { return true; } elseif ($this->findLog($pos->getSide(4), $visited, $distance + 1, $check, $fromSide) === true) { return true; } elseif ($this->findLog($pos->getSide(5), $visited, $distance + 1, $check, $fromSide) === true) { return true; } break; case 4: if ($this->findLog($pos->getSide(2), $visited, $distance + 1, $check, $fromSide) === true) { return true; } elseif ($this->findLog($pos->getSide(3), $visited, $distance + 1, $check, $fromSide) === true) { return true; } elseif ($this->findLog($pos->getSide(4), $visited, $distance + 1, $check, $fromSide) === true) { return true; } break; case 5: if ($this->findLog($pos->getSide(2), $visited, $distance + 1, $check, $fromSide) === true) { return true; } elseif ($this->findLog($pos->getSide(3), $visited, $distance + 1, $check, $fromSide) === true) { return true; } elseif ($this->findLog($pos->getSide(5), $visited, $distance + 1, $check, $fromSide) === true) { return true; } break; } } } return false; }
private function cancelAction(Block $block, Player $player, $send = true) { $pk = new UpdateBlockPacket(); $pk->x = $block->x; $pk->y = $block->y; $pk->z = $block->z; $pk->block = $block->getID(); $pk->meta = $block->getMetadata(); $player->dataPacket($pk); if ($send === true) { $player->sendInventorySlot($player->slot); } return false; }