public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null) { $down = $block->getSide(Vector3::SIDE_DOWN); 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($this, Block::get($this->id, 0)); $up = $block->getSide(Vector3::SIDE_UP); if ($block->getSide(Vector3::SIDE_EAST) && $block->getSide(Vector3::SIDE_WEST)) { if ($up->getSide(Vector3::SIDE_EAST)) { $this->setDirection(Vector3::SIDE_EAST, true); } elseif ($up->getSide(Vector3::SIDE_WEST)) { $this->setDirection(Vector3::SIDE_WEST, true); } else { $this->setDirection(Vector3::SIDE_EAST); } } elseif ($block->getSide(Vector3::SIDE_SOUTH) && $block->getSide(Vector3::SIDE_NORTH)) { if ($up->getSide(Vector3::SIDE_SOUTH)) { $this->setDirection(Vector3::SIDE_SOUTH, true); } elseif ($up->getSide(Vector3::SIDE_NORTH)) { $this->setDirection(Vector3::SIDE_NORTH, true); } else { $this->setDirection(Vector3::SIDE_SOUTH); } } else { $this->setDirection(Vector3::SIDE_NORTH); } return true; } return false; }
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null) { if ($block->getSide(0)->getID() === self::FARMLAND) { $this->getLevel()->setBlock($block, $this, true, true); return true; } return false; }
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz) { if ($target->isTransparent() === false and $face > 1 and $block->isSolid() === false) { $faces = [2 => 1, 3 => 3, 4 => 0, 5 => 2]; $motives = [["Kebab", 1, 1], ["Aztec", 1, 1], ["Alban", 1, 1], ["Aztec2", 1, 1], ["Bomb", 1, 1], ["Plant", 1, 1], ["Wasteland", 1, 1], ["Wanderer", 1, 2], ["Graham", 1, 2], ["Pool", 2, 1], ["Courbet", 2, 1], ["Sunset", 2, 1], ["Sea", 2, 1], ["Creebet", 2, 1], ["Match", 2, 2], ["Bust", 2, 2], ["Stage", 2, 2], ["Void", 2, 2], ["SkullAndRoses", 2, 2], ["Fighters", 4, 2], ["Skeleton", 4, 3], ["DonkeyKong", 4, 3], ["Pointer", 4, 4], ["Pigscene", 4, 4], ["Flaming Skull", 4, 4]]; $right = [4, 5, 3, 2]; $validMotives = []; foreach ($motives as $motive) { $valid = true; for ($x = 0; $x < $motive[1] && $valid; $x++) { for ($z = 0; $z < $motive[2] && $valid; $z++) { if ($target->getSide($right[$face - 2], $x)->isTransparent() || $target->getSide(Vector3::SIDE_UP, $z)->isTransparent() || $block->getSide($right[$face - 2], $x)->isSolid() || $block->getSide(Vector3::SIDE_UP, $z)->isSolid()) { $valid = false; } } } if ($valid) { $validMotives[] = $motive; } } $motive = $motives[mt_rand(0, count($validMotives) - 1)]; $data = ["x" => $target->x, "y" => $target->y, "z" => $target->z, "yaw" => $faces[$face] * 90, "Motive" => $motive[0]]; $nbt = new CompoundTag("", ["Motive" => new StringTag("Motive", $data["Motive"]), "Pos" => new EnumTag("Pos", [new DoubleTag("", $data["x"]), new DoubleTag("", $data["y"]), new DoubleTag("", $data["z"])]), "Motion" => new EnumTag("Motion", [new DoubleTag("", 0), new DoubleTag("", 0), new DoubleTag("", 0)]), "Rotation" => new EnumTag("Rotation", [new FloatTag("", $data["yaw"]), new FloatTag("", 0)])]); $painting = new PaintingEntity($player->getLevel()->getChunk($block->getX() >> 4, $block->getZ() >> 4), $nbt); $painting->spawnToAll(); if ($player->isSurvival()) { $item = $player->getInventory()->getItemInHand(); $count = $item->getCount(); if (--$count <= 0) { $player->getInventory()->setItemInHand(Item::get(Item::AIR)); return; } $item->setCount($count); $player->getInventory()->setItemInHand($item); } //TODO //$e = $server->api->entity->add($level, ENTITY_OBJECT, OBJECT_PAINTING, $data); //$e->spawnToAll(); /*if(($player->gamemode & 0x01) === 0x00){ $player->removeItem(Item::get($this->getId(), $this->getDamage(), 1)); }*/ return true; } return false; }
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null) { $down = $target->getSide(Vector3::SIDE_DOWN); if ($down->isTransparent() === false || $down instanceof Fence || $down instanceof FenceGate) { $this->getLevel()->setBlock($block, $this, true, true); return true; } return false; }
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz) { $realPos = $target->getSide($face)->add(0.5, 0.4, 0.5); $camera = new TripoidCamera($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)])])); $camera->spawnToAll(); if ($player->isSurvival()) { --$this->count; } return true; }
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null) { $down = $block->getSide(0); if ($down->getId() === self::AIR) { return false; } $faces = [0 => 3, 1 => 0, 2 => 1, 3 => 2]; $this->meta = $faces[$player instanceof Player ? $player->getDirection() : 0] & 0x3; $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) { $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 Short("item", 0), new Int("mData", 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) { if ($target instanceof Water) { $up = $target->getSide(Vector3::SIDE_UP); if ($up->getId() === Block::AIR) { $this->getLevel()->setBlock($up, $this, \true, \true); return \true; } } return \false; }
public static function addToDeactiveQueue(\SplPriorityQueue $queue, Block $location, $updateLevel) { if ($updateLevel <= 0) { return; } for ($s = 0; $s <= 5; $s++) { $sideBlock = $location->getSide($s); if ($sideBlock->getPowerLevel() === $updateLevel - 1) { $queue->insert($sideBlock, $sideBlock->getPowerLevel()); } } }
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null) { $down = $block->getSide(0); if ($down->isTransparent() && !($down instanceof Slab && ($down->meta & 0x8) === 0x8) || $down instanceof WoodSlab && ($down->meta & 0x8) === 0x8 || $down instanceof Stair && ($down->meta & 0x4) === 0x4) { return false; } if ($player instanceof Player) { $this->meta = ((int) $player->getDirection() + 5) % 4; } $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) { $down = $block->getSide(Vector3::SIDE_DOWN); if ($down->isTransparent() === false) { $up = $block->getSide(Vector3::SIDE_UP); if ($block->getSide(Vector3::SIDE_EAST) && $block->getSide(Vector3::SIDE_WEST)) { if ($up->getSide(Vector3::SIDE_EAST)) { $this->setDirection(Vector3::SIDE_EAST, true); } elseif ($up->getSide(Vector3::SIDE_WEST)) { $this->setDirection(Vector3::SIDE_WEST, true); } else { $this->setDirection(Vector3::SIDE_EAST); } } elseif ($block->getSide(Vector3::SIDE_SOUTH) && $block->getSide(Vector3::SIDE_NORTH)) { if ($up->getSide(Vector3::SIDE_SOUTH)) { $this->setDirection(Vector3::SIDE_SOUTH, true); } elseif ($up->getSide(Vector3::SIDE_NORTH)) { $this->setDirection(Vector3::SIDE_NORTH, true); } else { $this->setDirection(Vector3::SIDE_SOUTH); } } else { $this->setDirection(Vector3::SIDE_NORTH); } return true; } return false; }
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz) { $realPos = $block->getSide($face); $boat = Entity::createEntity("Boat", $player->getLevel()->getChunk($realPos->x >> 4, $realPos->z >> 4), new Compound("", ["Pos" => new Enum("Pos", [new Double("", $realPos->x), new Double("", $realPos->y), new Double("", $realPos->z)]), "Motion" => new Enum("Motion", [new Double("", 0), new Double("", 0), new Double("", 0)]), "Rotation" => new Enum("Rotation", [new Float("", 0), new Float("", 0)])])); $boat->spawnToAll(); --$this->count; if ($this->count <= 0) { $player->getInventory()->setItemInHand(Item::get(Item::AIR)); return true; } $player->getInventory()->setItemInHand($this); return true; }
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz) { $realPos = $block->getSide($face); $boat = new BoatEntity($player->getLevel()->getChunk($realPos->getX() >> 4, $realPos->getZ() >> 4), new Compound("", ["Pos" => new Enum("Pos", [new Double("", $realPos->getX()), new Double("", $realPos->getY()), new Double("", $realPos->getZ())]), "Motion" => new Enum("Motion", [new Double("", 0), new Double("", 0), new Double("", 0)]), "Rotation" => new Enum("Rotation", [new Float("", 0), new Float("", 0)])])); $boat->spawnToAll(); $item = $player->getInventory()->getItemInHand(); $count = $item->getCount(); if (--$count <= 0) { $player->getInventory()->setItemInHand(Item::get(Item::AIR)); return; } $item->setCount($count); $player->getInventory()->setItemInHand($item); return true; }
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(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz) { $realPos = $block->getSide(Vector3::SIDE_UP); if (!$block instanceof RailBlock) { return false; } $cart = new MinecartEntity($player->getLevel()->getChunk($realPos->getX() >> 4, $realPos->getZ() >> 4), new Compound("", ["Pos" => new Enum("Pos", [new Double("", $realPos->getX()), new Double("", $realPos->getY()), new Double("", $realPos->getZ())]), "Motion" => new Enum("Motion", [new Double("", 0), new Double("", 0), new Double("", 0)]), "Rotation" => new Enum("Rotation", [new Float("", 0), new Float("", 0)])])); $cart->spawnToAll(); if ($player->isSurvival()) { $item = $player->getInventory()->getItemInHand(); $count = $item->getCount(); if (--$count <= 0) { $player->getInventory()->setItemInHand(Item::get(Item::AIR)); return; } $item->setCount($count); $player->getInventory()->setItemInHand($item); } return true; }
public function calculateDirection(Block $block) { $up = $block->getSide(Vector3::SIDE_UP); $down = $block->getSide(Vector3::SIDE_DOWN); if ($block->getSide(Vector3::SIDE_EAST) instanceof RailBlock && ($block->getSide(Vector3::SIDE_SOUTH) instanceof RailBlock || $up->getSide(Vector3::SIDE_SOUTH) instanceof RailBlock || $down->getSide(Vector3::SIDE_SOUTH) instanceof RailBlock)) { return $this->setDirection(self::SIDE_SOUTH_EAST); } elseif ($block->getSide(Vector3::SIDE_SOUTH) instanceof RailBlock && ($block->getSide(Vector3::SIDE_EAST) instanceof RailBlock || $up->getSide(Vector3::SIDE_EAST) instanceof RailBlock || $down->getSide(Vector3::SIDE_EAST) instanceof RailBlock)) { return $this->setDirection(self::SIDE_SOUTH_EAST); } elseif ($block->getSide(Vector3::SIDE_SOUTH) instanceof RailBlock && ($block->getSide(Vector3::SIDE_WEST) instanceof RailBlock || $up->getSide(Vector3::SIDE_WEST) instanceof RailBlock || $down->getSide(Vector3::SIDE_WEST) instanceof RailBlock)) { return $this->setDirection(self::SIDE_SOUTH_WEST); } elseif ($block->getSide(Vector3::SIDE_EAST) instanceof RailBlock && ($block->getSide(Vector3::SIDE_NORTH) instanceof RailBlock || $up->getSide(Vector3::SIDE_NORTH) instanceof RailBlock || $down->getSide(Vector3::SIDE_NORTH) instanceof RailBlock)) { return $this->setDirection(self::SIDE_NORTH_EAST); } elseif ($block->getSide(Vector3::SIDE_NORTH) instanceof RailBlock && ($block->getSide(Vector3::SIDE_WEST) instanceof RailBlock || $up->getSide(Vector3::SIDE_WEST) instanceof RailBlock || $down->getSide(Vector3::SIDE_WEST) instanceof RailBlock)) { return $this->setDirection(self::SIDE_NORTH_WEST); } elseif ($block->getSide(Vector3::SIDE_NORTH) instanceof RailBlock && ($block->getSide(Vector3::SIDE_EAST) instanceof RailBlock || $up->getSide(Vector3::SIDE_EAST) instanceof RailBlock || $down->getSide(Vector3::SIDE_EAST) instanceof RailBlock)) { return $this->setDirection(self::SIDE_NORTH_EAST); } elseif ($block->getSide(Vector3::SIDE_WEST) instanceof RailBlock && ($block->getSide(Vector3::SIDE_SOUTH) instanceof RailBlock || $up->getSide(Vector3::SIDE_SOUTH) instanceof RailBlock || $down->getSide(Vector3::SIDE_SOUTH) instanceof RailBlock)) { return $this->setDirection(self::SIDE_SOUTH_WEST); } elseif ($block->getSide(Vector3::SIDE_WEST) instanceof RailBlock && ($block->getSide(Vector3::SIDE_NORTH) instanceof RailBlock || $up->getSide(Vector3::SIDE_NORTH) instanceof RailBlock || $down->getSide(Vector3::SIDE_NORTH) instanceof RailBlock)) { return $this->setDirection(Vector3::SIDE_NORTH_WEST); } elseif ($block->getSide(Vector3::SIDE_NORTH) instanceof RailBlock && $up->getSide(Vector3::SIDE_SOUTH) instanceof RailBlock) { $this->setDirection(Vector3::SIDE_SOUTH, true); } elseif ($block->getSide(Vector3::SIDE_WEST) instanceof RailBlock && $up->getSide(Vector3::SIDE_EAST) instanceof RailBlock) { $this->setDirection(Vector3::SIDE_EAST, true); } elseif ($block->getSide(Vector3::SIDE_SOUTH) instanceof RailBlock && $up->getSide(Vector3::SIDE_NORTH) instanceof RailBlock) { $this->setDirection(Vector3::SIDE_NORTH, true); } elseif ($block->getSide(Vector3::SIDE_EAST) instanceof RailBlock && $up->getSide(Vector3::SIDE_WEST) instanceof RailBlock) { $this->setDirection(Vector3::SIDE_WEST, true); } elseif ($block->getSide(Vector3::SIDE_SOUTH) instanceof RailBlock && $block->getSide(Vector3::SIDE_NORTH) instanceof RailBlock) { $this->setDirection(Vector3::SIDE_NORTH); } elseif ($block->getSide(Vector3::SIDE_EAST) instanceof RailBlock && $block->getSide(Vector3::SIDE_WEST) instanceof RailBlock) { $this->setDirection(Vector3::SIDE_WEST); } elseif ($block->getSide(Vector3::SIDE_SOUTH) instanceof RailBlock) { $this->setDirection(Vector3::SIDE_SOUTH); } elseif ($block->getSide(Vector3::SIDE_EAST) instanceof RailBlock) { $this->setDirection(Vector3::SIDE_EAST); } elseif ($block->getSide(Vector3::SIDE_NORTH) instanceof RailBlock) { $this->setDirection(Vector3::SIDE_NORTH); } elseif ($block->getSide(Vector3::SIDE_WEST) instanceof RailBlock) { $this->setDirection(Vector3::SIDE_WEST); } else { $this->setDirection(Vector3::SIDE_SOUTH); } for ($i = Vector3::SIDE_NORTH; $i < Vector3::SIDE_EAST; $i++) { $pos = $block->getSide($i); if ($pos instanceof RailBlock) { $this->getLevel()->scheduleUpdate($pos, 0); } $pos = $block->getSide(Vector3::SIDE_DOWN)->getSide($i); if ($pos instanceof RailBlock) { $this->getLevel()->scheduleUpdate($pos, 0); } $pos = $block->getSide(Vector3::SIDE_UP)->getSide($i); if ($pos instanceof RailBlock) { $this->getLevel()->scheduleUpdate($pos, 0); } } }
/** * @param Block $block * * @param * @param $hash Hash */ public function doRedstoneBlockUpdate($block, $type, $power, $hash = NULL) { if ($hash == NULL) { $hash = Level::blockHash(0, 0, 0); } $block->onRedstoneUpdate($type, $power); for ($side = 0; $side <= 5; $side++) { $aroundBlock = $block->getSide($side); if ($aroundBlock->getId() == Block::OBSERVER) { #ToDo:AddAInterfaceForThis $aroundBlock->onRedstoneUpdate($type, $power, $hash); } } }
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() === static::WOOD_TYPE) { return true; } elseif ($pos->getId() === $this->id and $distance < 3) { $visited[$index] = true; $down = $pos->getSide(0)->getId(); if ($down === static::WOOD_TYPE) { 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; }
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null) { $down = $block->getSide(Vector3::SIDE_DOWN); $class = ""; if ($down->isTransparent() === false) { $up = $block->getSide(Vector3::SIDE_UP); if ($block->getSide(Vector3::SIDE_EAST) instanceof RailBlock && $block->getSide(Vector3::SIDE_SOUTH) instanceof RailBlock) { return $this->setDirection(self::SIDE_SOUTH_EAST); } elseif ($block->getSide(Vector3::SIDE_EAST) instanceof RailBlock && $block->getSide(Vector3::SIDE_NORTH) instanceof RailBlock) { return $this->setDirection(self::SIDE_NORTH_EAST); } elseif ($block->getSide(Vector3::SIDE_SOUTH) instanceof RailBlock && $block->getSide(Vector3::SIDE_WEST) instanceof RailBlock) { return $this->setDirection(self::SIDE_SOUTH_WEST); } elseif ($block->getSide(Vector3::SIDE_NORTH) instanceof RailBlock && $block->getSide(Vector3::SIDE_WEST) instanceof RailBlock) { return $this->setDirection(self::SIDE_NORTH_WEST); } elseif ($block->getSide(Vector3::SIDE_EAST) instanceof RailBlock && $block->getSide(Vector3::SIDE_WEST) instanceof RailBlock) { if ($up->getSide(Vector3::SIDE_EAST) instanceof RailBlock) { return $this->setDirection(Vector3::SIDE_EAST, true); } elseif ($up->getSide(Vector3::SIDE_WEST) instanceof RailBlock) { return $this->setDirection(Vector3::SIDE_WEST, true); } else { return $this->setDirection(Vector3::SIDE_EAST); } } elseif ($block->getSide(Vector3::SIDE_SOUTH) instanceof RailBlock && $block->getSide(Vector3::SIDE_NORTH) instanceof RailBlock) { if ($up->getSide(Vector3::SIDE_SOUTH) instanceof RailBlock) { return $this->setDirection(Vector3::SIDE_SOUTH, true); } elseif ($up->getSide(Vector3::SIDE_NORTH) instanceof RailBlock) { return $this->setDirection(Vector3::SIDE_NORTH, true); } else { return $this->setDirection(Vector3::SIDE_SOUTH); } } else { return $this->setDirection(Vector3::SIDE_NORTH); } } return false; }
private function destroyTrunk(Block $bl) { $damage = 0; if ($bl->getId() != Block::WOOD) { return $damage; } $down = $bl->getSide(Vector3::SIDE_DOWN); if ($down->getId() == Block::WOOD) { return $damage; } $l = $bl->getLevel(); for ($y = $bl->getY() + 1; $y < 128; ++$y) { $x = $bl->getX(); $z = $bl->getZ(); $bl = $l->getBlock(new Vector3($x, $y, $z)); if ($bl->getId() != Block::WOOD) { break; } ++$damage; $l->dropItem($bl, new ItemBlock($bl)); $l->setBlockIdAt($x, $y, $z, 0); $l->setBlockDataAt($x, $y, $z, 0); } return $damage; }
/** * @todo REMOVE THIS HACK */ private function fakeLightLvl(Block $block) { $block->getSide(Vector3::SIDE_UP) instanceof Transparent || $block->getSide(Vector3::SIDE_UP) instanceof LightSource ? $block->getSide(Vector3::SIDE_UP) instanceof LightSource ? $lightLvl = $block->getLightLevel() : ($lightLvl = 9) : ($lightLvl = 0); return $lightLvl; }
public function checkTorchOff(Block $pos, array $ignore = []) { $sides = [Vector3::SIDE_EAST, Vector3::SIDE_WEST, Vector3::SIDE_SOUTH, Vector3::SIDE_NORTH, Vector3::SIDE_UP]; foreach ($sides as $side) { if (!in_array($side, $ignore)) { /** @var RedstoneTorch $block */ $block = $pos->getSide($side); if ($block->getId() == self::UNLIT_REDSTONE_TORCH) { $faces = [1 => 4, 2 => 5, 3 => 2, 4 => 3, 5 => 0, 6 => 0, 0 => 0]; if ($this->isRightPlace($block->getSide($faces[$block->meta]), $pos)) { $ignoreBlock = $this->getSide($this->getOppositeSide($faces[$block->meta])); $block->turnOn(Level::blockHash($ignoreBlock->x, $ignoreBlock->y, $ignoreBlock->z)); } } } } }
public function getHellDoorBlocks(Block $block, $data) { $data["nestingDepth"]++; if ($data["nestingDepth"] >= 20) { return $data; } $sides = [Vector3::SIDE_EAST, Vector3::SIDE_WEST, Vector3::SIDE_NORTH, Vector3::SIDE_SOUTH, Vector3::SIDE_UP, Vector3::SIDE_DOWN]; $blockPos = "{$block->x}:{$block->y}:{$block->z}"; if (!isset($data[$blockPos])) { $data[$blockPos] = true; } foreach ($sides as $side) { if ($data["nestingDepth"] >= 20) { break; } $sideBlock = $block->getSide($side); $sideBlockPos = "{$sideBlock->x}:{$sideBlock->y}:{$sideBlock->z}"; if (isset($data[$sideBlockPos])) { continue; } $id = $sideBlock->getId(); if ($id == 90) { $data[$sideBlockPos] = true; $returns = $this->getHellDoorBlocks($sideBlock, $data); if ($returns["nestingDepth"] >= 20) { break; } foreach ($returns as $returnPos => $bool) { if (!isset($data[$returnPos])) { $data[$returnPos] = true; } } } } return $data; }
private function getChanceOfNeighborsEncouragingFire(Block $block) { if ($block->getId() !== self::AIR) { return 0; } else { $chance = 0; for ($i = 0; $i < 5; $i++) { $chance = max($chance, $block->getSide($i)->getBurnChance()); } return $chance; } }
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null) { $down = $block->getSide(Vector3::SIDE_DOWN); if (!$down->isTransparent() || $down instanceof Fence || $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); return true; } return false; }
/** * @param Block $stump * @return int */ public function getTreetop(Block $stump) { $level = $stump->getLevel(); $floor = $level->getBlock($stump->getSide(0)); if (!in_array($floor->getId(), self::FLOORS)) { return -1; } $found = null; $maxHeight = $this->getConfig()->get("maxWorldHeight") - $stump->getY(); for ($height = 0; $height < $maxHeight; $height++) { $block = $level->getBlock($stump->add(0, $height, 0)); if (in_array($block->getId(), self::WOODS)) { if ($found === null) { $found = [$block->getId(), $block->getDamage()]; } elseif ($found[0] !== $block->getId() or $found[1] !== $block->getDamage()) { return -1; } } elseif ($found !== null and in_array($block->getId(), self::LEAVES)) { return $height; } else { return -1; } } return -1; }
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz) { if ($target->isTransparent() === false and $face !== 0 and $face !== 1 and $block->isSolid() === false) { $faces = [2 => 1, 3 => 3, 4 => 0, 5 => 2]; $motives = PaintingEntity::MOTIVES; $face2side = [4, 5, 3, 2]; $foundApplicableMotive = false; $searchedMotives = []; while (!$foundApplicableMotive) { if (count($searchedMotives) == count($motives)) { break; } $rand = -1; while (!isset($motives[$rand])) { $rand = mt_rand(0, count($motives) - 1); } $motive = $motives[$rand]; $foundApplicableMotive = true; $searchedMotives[$rand] = true; for ($x = 0; $x < $motive[1] && $foundApplicableMotive; $x++) { for ($z = 0; $z < $motive[2] && $foundApplicableMotive; $z++) { if ($target->getSide($face2side[$face - 2], $x)->isTransparent() || $target->getSide(Vector3::SIDE_UP, $z)->isTransparent() || $block->getSide($face2side[$face - 2], $x)->isSolid() || $block->getSide(Vector3::SIDE_UP, $z)->isSolid()) { $foundApplicableMotive = false; } } } } if (!$foundApplicableMotive) { return false; } //WIP overlapping calculation AND BTW: EVEN MCPE DOESN'T DO THIS! /* for($x = 0; $x < $motive[1] && $valid; $x++){ for($z = 0; $z < $motive[2] && $valid; $z++){ $entPos = $target->getSide($right[$face - 2], $x); //getEntitiesAtThatPos (high intensive calculation) if($entity instanceof PaintingEntity){ return false; } } } */ $data = ["x" => $target->x, "y" => $target->y - 0.1, "z" => $target->z, "yaw" => $faces[$face] * 90, "Motive" => $motive[0]]; if ($motive[2] <= 1) { $data["y"] = $data["y"] + 1; } if ($motive[2] >= 2) { $data["y"] = $data["y"] + 0.4; } if ($motive[2] >= 3) { $data["y"] = $data["y"] + 0.1; } switch ($face2side[$face - 2]) { case Vector3::SIDE_NORTH: $data["z"] = $data["z"] + 0.1; break; case Vector3::SIDE_SOUTH: $data["z"] = $data["z"] - 0.1; break; case Vector3::SIDE_WEST: $data["x"] = $data["x"] + 0.1; break; case Vector3::SIDE_EAST: $data["x"] = $data["x"] - 0.1; break; } $nbt = new CompoundTag("", ["Motive" => new StringTag("Motive", $data["Motive"]), "Pos" => new ListTag("Pos", [new DoubleTag("", $data["x"]), new DoubleTag("", $data["y"]), new DoubleTag("", $data["z"])]), "Motion" => new ListTag("Motion", [new DoubleTag("", 0), new DoubleTag("", 0), new DoubleTag("", 0)]), "Rotation" => new ListTag("Rotation", [new FloatTag("", $data["yaw"]), new FloatTag("", 0)])]); $painting = new PaintingEntity($player->getLevel()->getChunk($block->getX() >> 4, $block->getZ() >> 4), $nbt); $painting->spawnToAll(); unset($player->getLevel()->updateEntities[$painting->getId()]); if ($player->isSurvival()) { $item = $player->getInventory()->getItemInHand(); $count = $item->getCount(); if (--$count <= 0) { $player->getInventory()->setItemInHand(Item::get(Item::AIR)); } $item->setCount($count); $player->getInventory()->setItemInHand($item); } return true; } return false; }