public function activateBlockWithoutWire(Block $block) { if ($block instanceof Door or $block instanceof Trapdoor or $block instanceof FenceGate) { if (!$block->isOpened()) { $block->onActivate(new Item(0)); } } if ($block->getId() == Block::TNT) { $block->onActivate(new Item(Item::FLINT_AND_STEEL)); } /** @var InactiveRedstoneLamp $block */ if ($block->getId() == Block::INACTIVE_REDSTONE_LAMP) { $block->turnOn(); } /** @var Dropper|Dispenser $block */ if ($block->getId() == Block::DROPPER or $block->getId() == Block::DISPENSER) { $block->activate(); } /** @var PoweredRepeater $block */ if ($block->getId() == Block::UNPOWERED_REPEATER_BLOCK) { if ($this->equals($block->getSide($block->getDirection()))) { $block->activate(); } } }
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz) { if ($player === null or $player->isSurvival() !== true) { return false; } if ($target->getId() === Block::STILL_WATER or $target->getId() === Block::WATER) { $player->getServer()->getPluginManager()->callEvent($ev = new PlayerGlassBottleEvent($player, $target, $this)); if ($ev->isCancelled()) { return false; } else { if ($this->count <= 1) { $player->getInventory()->setItemInHand(Item::get(Item::POTION, 0, 1)); return true; } else { $this->count--; $player->getInventory()->setItemInHand($this); } if ($player->getInventory()->canAddItem(Item::get(Item::POTION, 0, 1)) === true) { $player->getInventory()->AddItem(Item::get(Item::POTION, 0, 1)); } else { $motion = $player->getDirectionVector()->multiply(0.4); $position = clone $player->getPosition(); $player->getLevel()->dropItem($position->add(0, 0.5, 0), Item::get(Item::POTION, 0, 1), $motion, 40); } return true; } } return false; }
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null) { if ($target->isTransparent() === false || $target->getId() === Block::LEAVES || $target->getId() === Block::LEAVES2) { $faces = [2 => 2, 3 => 3, 4 => 4, 5 => 5]; if (isset($faces[$face])) { $this->meta = $faces[$face]; $this->getLevel()->setBlock($block, $this, true, true); return true; } } return false; }
/** * TODO: Move this to each item * * @param Entity|Block $object * * @return bool */ public function useOn($object) { if ($this->isHoe()) { if ($object instanceof Block and ($object->getId() === self::GRASS or $object->getId() === self::DIRT)) { $this->meta++; } } elseif ($object instanceof Entity and !$this->isSword()) { $this->meta += 2; } else { $this->meta++; } return true; }
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null) { if (($target->isTransparent() === false or $target->getId() === self::SLAB or $target->getId() === self::PACKED_ICE) and $face !== 0 and $face !== 1) { $faces = [2 => 3, 3 => 2, 4 => 1, 5 => 0]; $this->meta = $faces[$face] & 0x3; if ($fy > 0.5) { $this->meta |= 0x4; } $this->getLevel()->setBlock($block, $this, true, true); return true; } return false; }
/** * TODO: Move this to each item * * @param Entity|Block $object * * @return bool */ public function useOn($object) { if ($this->isUnbreakable()) { return false; } $break = true; if (($ench = $this->getEnchantment(Enchantment::TYPE_MINING_DURABILITY)) != null) { $rnd = mt_rand(1, 100); if ($rnd <= 100 / ($ench->getLevel() + 1)) { $break = false; } } if ($object instanceof Block) { if (!$break) { return false; } if ($object->getToolType() === Tool::TYPE_PICKAXE and $this->isPickaxe() or $object->getToolType() === Tool::TYPE_SHOVEL and $this->isShovel() or $object->getToolType() === Tool::TYPE_AXE and $this->isAxe() or $object->getToolType() === Tool::TYPE_SWORD and $this->isSword() or $object->getToolType() === Tool::TYPE_SHEARS and $this->isShears()) { $this->meta++; } elseif (!$this->isShears() and $object->getBreakTime($this) > 0) { $this->meta += 2; } } elseif ($this->isHoe()) { if (!$break) { return false; } if ($object instanceof Block and ($object->getId() === self::GRASS or $object->getId() === self::DIRT)) { $this->meta++; } } elseif ($object instanceof Entity) { $return = true; if (!$this->isSword()) { if ($break) { $this->meta += 2; $return = false; } } else { if ($break) { $this->meta++; $return = false; } if (!$this->hasEnchantments()) { return $return; } //TODO: move attacking from player class here //$fire = $this->getEnchantment(Enchantment::TYPE_WEAPON_FIRE_ASPECT); //$object->setOnFire($fire->getLevel() * 4); } } return true; }
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz) { if ($target->getId() == Block::MONSTER_SPAWNER) { return true; } else { $entity = null; $chunk = $level->getChunk($block->getX() >> 4, $block->getZ() >> 4); if (!$chunk instanceof FullChunk) { return false; } $nbt = new CompoundTag("", ["Pos" => new EnumTag("Pos", [new DoubleTag("", $block->getX() + 0.5), new DoubleTag("", $block->getY()), new DoubleTag("", $block->getZ() + 0.5)]), "Motion" => new EnumTag("Motion", [new DoubleTag("", 0), new DoubleTag("", 0), new DoubleTag("", 0)]), "Rotation" => new EnumTag("Rotation", [new FloatTag("", lcg_value() * 360), new FloatTag("", 0)])]); if ($this->hasCustomName()) { $nbt->CustomName = new StringTag("CustomName", $this->getCustomName()); } $entity = Entity::createEntity($this->meta, $chunk, $nbt); if ($entity instanceof Entity) { if ($player->isSurvival()) { --$this->count; } $entity->spawnToAll(); 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 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 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)); }
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null) { if ($target->isTransparent() === false || $target->getId() === self::FENCE) { $this->getLevel()->setBlock($block, $this, true, true); return 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 static function fillUpChest(Block $chest, Player $player) { if ($chest->getId() == Item::CHEST || $chest->getId()) { if ($player->gamemode == Player::CREATIVE) { $player->sendMessage("[HG] You are in creative Mode"); return; } if (!$player->isOp()) { $pk = new ContainerSetContentPacket(); $pk->windowid = $player->getWindowId($player->getInventory()); // ContainerSetContentPacket::SPECIAL_INVENTORY; for ($i = 1; $i < 5; $i++) { $pk->slots[] = HungerGameKit::randomItems(); } $player->dataPacket($pk->setChannel(Network::CHANNEL_WORLD_EVENTS)); if ($player->getInventory() != null) { $player->getInventory()->sendContents($player); } // $player->sendMessage ( "[HG] openning chest" ); } } }
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = \null) { if (($target->isTransparent() === \false or $target->getId() === self::SLAB) and $face !== 0 and $face !== 1) { $faces = [2 => 0, 3 => 1, 4 => 2, 5 => 3]; $this->meta = $faces[$face] & 0x3; if ($fy > 0.5) { $this->meta |= 0x8; } $this->getLevel()->setBlock($block, $this, \true, \true); return \true; } return \false; }
/** * TODO: Move this to each item * * @param Entity|Block $object * * @return bool */ public function useOn($object) { if ($this->isUnbreakable()) { return true; } if ($object instanceof Block) { if ($object->getToolType() === Tool::TYPE_PICKAXE and $this->isPickaxe() or $object->getToolType() === Tool::TYPE_SHOVEL and $this->isShovel() or $object->getToolType() === Tool::TYPE_AXE and $this->isAxe() or $object->getToolType() === Tool::TYPE_SWORD and $this->isSword() or $object->getToolType() === Tool::TYPE_SHEARS and $this->isShears()) { $this->meta++; } elseif (!$this->isShears() and $object->getBreakTime($this) > 0) { $this->meta += 2; } } elseif ($this->isHoe()) { if ($object instanceof Block and ($object->getId() === self::GRASS or $object->getId() === self::DIRT)) { $this->meta++; } } elseif ($object instanceof Entity and !$this->isSword()) { $this->meta += 2; } else { $this->meta++; } return true; }
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz) { if (!in_array($target->getId(), array(Block::RAIL, Block::ACTIVATOR_RAIL, Block::DETECTOR_RAIL, Block::POWERED_RAIL))) { return false; } $realPos = $target->add(0.5, 0, 0.5); $cart = new MinecartHopperEntity($player->getLevel()->getChunk($realPos->getX() >> 4, $realPos->getZ() >> 4), new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $realPos->getX()), new DoubleTag("", $realPos->getY()), new DoubleTag("", $realPos->getZ())]), "Motion" => new ListTag("Motion", [new DoubleTag("", 0), new DoubleTag("", 0), new DoubleTag("", 0)]), "Rotation" => new ListTag("Rotation", [new FloatTag("", 0), new FloatTag("", 0)])])); $cart->spawnToAll(); if ($player->isSurvival()) { --$this->count; } return true; }
public function treeDetect(Block $block, Player $player, $isdrop = true) { if ($block->getId() == Block::LOG or $block->getId() == Block::LEAVE) { $drops = $block->getDrops($player->getInventory()->getItemInHand()); if ($isdrop == true) { foreach ($drops as $drop) { if ($drop[2] > 0) { $player->getInventory()->addItem(Item::get(...$drop)); } } } $block->getLevel()->setBlock($block, new Air(), false, false); } $id = $block->getLevel()->getBlockIdAt($block->x, $block->y - 1, $block->z); if ($id == Block::LOG or $id == Block::LEAVE) { $this->treeDetect($block->getLevel()->getBlock($block->add(0, -1, 0)), $player); } $id = $block->getLevel()->getBlockIdAt($block->x, $block->y + 1, $block->z); if ($id == Block::LOG or $id == Block::LEAVE) { $this->treeDetect($block->getLevel()->getBlock($block->add(0, 1, 0)), $player); } $id = $block->getLevel()->getBlockIdAt($block->x, $block->y, $block->z - 1); if ($id == Block::LOG or $id == Block::LEAVE) { $this->treeDetect($block->getLevel()->getBlock($block->add(0, 0, -1)), $player); } $id = $block->getLevel()->getBlockIdAt($block->x, $block->y, $block->z + 1); if ($id == Block::LOG or $id == Block::LEAVE) { $this->treeDetect($block->getLevel()->getBlock($block->add(0, 0, 1)), $player); } $id = $block->getLevel()->getBlockIdAt($block->x - 1, $block->y, $block->z); if ($id == Block::LOG or $id == Block::LEAVE) { $this->treeDetect($block->getLevel()->getBlock($block->add(-1, 0, 0)), $player); } $id = $block->getLevel()->getBlockIdAt($block->x + 1, $block->y, $block->z); if ($id == Block::LOG or $id == Block::LEAVE) { $this->treeDetect($block->getLevel()->getBlock($block->add(1, 0, 0)), $player); } }
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null) { if (($target->isTransparent() === false or $target->getId() === self::SLAB) and $face !== 0 and $face !== 1) { $faces = [self::SIDE_SOUTH => self::MASK_SIDE_SOUTH, self::SIDE_NORTH => self::MASK_SIDE_NORTH, self::SIDE_EAST => self::MASK_SIDE_EAST, self::SIDE_WEST => self::MASK_SIDE_WEST]; echo $face, PHP_EOL, $faces[$face], PHP_EOL; $this->meta = $faces[$face] & self::MASK_SIDE; if ($fy > 0.5) { $this->meta |= self::MASK_UPPER; } $this->getLevel()->setBlock($block, $this, true, true); return true; } 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 place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null) { if (($target->isTransparent() === false or $target->getId() === self::SLAB) and $face !== 0 and $face !== 1) { //Search the correct combination of 2,3,4,5 //Trapdoor works if it placed in the bottom of block, if placed in top doesn't work $faces = [2 => 0, 3 => 1, 4 => 2, 5 => 3]; $this->meta = $faces[$face] & 0x3; if ($fy > 0.5) { $this->meta |= 0x8; } $this->getLevel()->setBlock($block, $this, true, true); $this->getLevel()->addSound(new DoorSound($this)); return true; } return false; }
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz) { if ($block->getId() === self::AIR and $target instanceof Solid) { $level->setBlock($block, new Fire(), true); if (($player->gamemode & 0x1) === 0 and $this->useOn($block)) { if ($this->getDamage() >= $this->getMaxDurability()) { $player->getInventory()->setItemInHand(new Item(Item::AIR, 0, 0)); } else { $this->meta++; $player->getInventory()->setItemInHand($this); } } return true; } return false; }
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) { $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) { $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 place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null) { if (($target->isTransparent() === false or $target->getId() === self::SLAB) and $face !== 0 and $face !== 1) { $faces = []; switch ($faces) { case 0x0: return Vector3::SIDE_SOUTH; case 0x1: return Vector3::SIDE_NORTH; case 0x2: return Vector3::SIDE_EAST; case 0x3: return Vector3::SIDE_WEST; } $this->meta = $faces[$face] & 0x3; if ($fy > 0.5) { $this->meta |= 0x8; } $this->getLevel()->setBlock($block, $this, true, true); return true; } return false; }
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null) { if (($target->isTransparent() === false or $target->getId() === self::SLAB) and $face !== 0 and $face !== 1) { switch ($face) { case 2: $this->meta |= 0b11; break; case 3: $this->meta |= 0b10; break; case 4: $this->meta |= 0b1; break; case 5: break; } if ($fy > 0.5) { $this->meta |= 0b100; } $this->getLevel()->setBlock($block, $this, true, true); 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 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 function canConnect(Block $block) { return ($block->getId() !== self::COBBLE_WALL and $block->getId() !== self::FENCE_GATE) ? $block->isSolid() and !$block->isTransparent() : true; }
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; }