public function onUpdate($type) { if ($type === Level::BLOCK_UPDATE_NORMAL or $type === Level::BLOCK_UPDATE_TOUCH) { $this->getLevel()->setBlock($this, Block::get(Item::GLOWING_REDSTONE_ORE, $this->meta), false, true); return Level::BLOCK_UPDATE_WEAK; } return false; }
public function onUpdate($type) { if ($type === Level::BLOCK_UPDATE_SCHEDULED or $type === Level::BLOCK_UPDATE_RANDOM) { $this->getLevel()->setBlock($this, Block::get(Item::REDSTONE_ORE, $this->meta), false, false, true); return Level::BLOCK_UPDATE_WEAK; } return false; }
public function onActivate(Item $item, Player $player = null) { if ($item->isHoe()) { $item->useOn($this); $this->getLevel()->setBlock($this, Block::get(Item::FARMLAND, 0), true); return true; } return false; }
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null) { if ($face !== 0) { $faces = [2 => 2, 3 => 3, 4 => 4, 5 => 5]; if (!isset($faces[$face])) { $this->meta = floor(($player->yaw + 180) * 16 / 360 + 0.5) & 0xf; $this->getLevel()->setBlock($block, Block::get(Item::SIGN_POST, $this->meta), true); return true; } else { $this->meta = $faces[$face]; $this->getLevel()->setBlock($block, Block::get(Item::WALL_SIGN, $this->meta), true); return true; } } 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; } } else { //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; } } } if ($block->getId() === self::WOOD_SLAB and ($target->getDamage() & 0x7) !== ($this->meta & 0x7)) { return false; } $this->getLevel()->setBlock($block, $this, true, true); return true; }
/** * Returns the Block on the side $side, works like Vector3::side() * * @param int $side * @param int $step * * @return Block */ public function getSide($side, $step = 1) { if ($this->isValid()) { return $this->getLevel()->getBlock(Vector3::getSide($side, $step)); } return Block::get(Item::AIR, 0, Position::fromObject(Vector3::getSide($side, $step))); }
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null) { $down = $this->getSide(0); if ($down->isTransparent() === false) { $faces = [0 => 3, 1 => 4, 2 => 2, 3 => 5]; $d = $player instanceof Player ? $player->getDirection() : 0; $next = $this->getSide($faces[($d + 3) % 4]); $downNext = $this->getSide(0); if ($next->canBeReplaced() === true and $downNext->isTransparent() === false) { $meta = ($d + 3) % 4 & 0x3; $this->getLevel()->setBlock($block, Block::get($this->id, $meta), true, true); $this->getLevel()->setBlock($next, Block::get($this->id, $meta | 0x8), true, true); return true; } } return false; }
public function onActivate(Item $item, Player $player = null) { if (($this->getDamage() & 0x8) === 0x8) { //Top $down = $this->getSide(0); if ($down->getId() === $this->getId()) { $meta = $down->getDamage() ^ 0x4; $this->getLevel()->setBlock($down, Block::get($this->getId(), $meta), true); $players = $this->getLevel()->getChunkPlayers($this->x >> 4, $this->z >> 4); if ($player instanceof Player) { unset($players[$player->getLoaderId()]); } $this->level->addSound(new DoorSound($this)); return true; } return false; } else { $this->meta ^= 0x4; $this->getLevel()->setBlock($this, $this, true); $players = $this->getLevel()->getChunkPlayers($this->x >> 4, $this->z >> 4); if ($player instanceof Player) { unset($players[$player->getLoaderId()]); } $this->level->addSound(new DoorSound($this)); } return true; }
private function checkForHarden() { if ($this instanceof Lava) { $colliding = false; for ($side = 0; $side <= 5 and !$colliding; ++$side) { $colliding = $this->getSide($side) instanceof Water; } if ($colliding) { if ($this->getDamage() === 0) { $this->getLevel()->setBlock($this, Block::get(Item::OBSIDIAN), true); } elseif ($this->getDamage() <= 4) { $this->getLevel()->setBlock($this, Block::get(Item::COBBLESTONE), true); } } } }