public function checkBlock($player, $x, $y, $z) { $pos = new Vector3($x, $y - 1, $z); $blockId = $player->getLevel()->getBlock($pos); //$this->getLogger()->info($blockId." is on pos".$x."-".$y."-".$z.""); $world = $player->getLevel()->getName(); if ($blockId instanceof Block) { $this->getLogger($pos); if ($blockId->getId() === Block::get($this->damageBlock)->getId()) { // $this->getLogger()->info($blockId." is on pos".$x."-".$y."-".$z.""); $this->doDamage($player); return true; } elseif ($blockId->getId() === Block::get($this->healingBlock)->getId()) { $this->healPlayer($player); return true; } elseif ($blockId->getId() === Block::get($this->effectBlock)->getId()) { $this->giveEffect($player); return true; } elseif ($this->isCommandBlock($x, $y, $z, $world)) { $this->executeCmds($x, $y, $z, $world, $player); return true; } else { return true; } } else { //$this->getLogger()->info($blockId." is not a block on pos".$x."-".$y."-".$z.""); } }
public function onRun($tick) { $blocks = 0; while ($this->pos->x < $this->xMax) { while ($this->pos->z < $this->zMax) { while ($this->pos->y < 128) { if ($this->pos->y === 0) { $block = $this->bottomBlock; } elseif ($this->pos->y < $this->height) { $block = $this->plotFillBlock; } elseif ($this->pos->y === $this->height) { $block = $this->plotFloorBlock; } else { $block = Block::get(0); } $this->level->setBlock($this->pos, $block, false, false); $blocks++; if ($blocks === $this->maxBlocksPerTick) { $this->getOwner()->getServer()->getScheduler()->scheduleDelayedTask($this, 1); return; } $this->pos->y++; } $this->pos->y = 0; $this->pos->z++; } $this->pos->z = $this->plotBeginPos->z; $this->pos->x++; } }
public function readMacro($name) { if (!is_file($path = $this->getFile($name))) { return null; } $string = file_get_contents($path); $nbt = new NBT(); $type = ord(substr($string, 0, 1)); $string = substr($string, 1); if ($type === 0) { $nbt->read($string); } else { $nbt->readCompressed($string, $type); } $tag = $nbt->getData(); $author = $tag["author"]; $description = $tag["description"]; /** @var tag\Enum $tags */ $tags = $tag["ops"]; $ops = []; /** @var tag\Compound $t */ foreach ($tags as $t) { $type = $tag["type"]; if ($type === 1) { $ops[] = new MacroOperation($t["delta"]); } else { $vectors = $t["vectors"]; /** @noinspection PhpParamsInspection */ $ops[] = new MacroOperation(new Vector3($vectors[0], $vectors[1], $vectors[2]), Block::get($t["blockID"], $t["blockDamage"])); } } return new Macro(false, $ops, $author, $description); }
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) { $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 readMacro($name) { $result = $this->getMacroRaw($name); $array = $result->fetch_assoc(); $result->close(); if (!is_array($array)) { return null; } $result = $this->getMacroRaw("macros_deltas", "owner", $name); $deltas = $result->fetch_all(MYSQLI_ASSOC); $result->close(); $result = $this->getMacroRaw("macros_ops", "owner", $name); $ops = array_merge($deltas, $result->fetch_all(MYSQLI_ASSOC)); $opers = []; foreach ($ops as $op) { if (isset($op["delta"])) { $opers[$op["offset"]] = new MacroOperation($op["delta"]); } else { $opers[$op["offset"]] = new MacroOperation(new Vector3($op["x"], $op["y"], $op["z"]), Block::get($op["id"], $op["damage"])); } } ksort($opers); $macro = new Macro(false, array_values($opers), $array["author"], $array["description"]); return $macro; }
public function __construct($meta = 0, $count = 1) { if ($meta == 3) { $this->block = Block::get(CropPlus::COCOA_BEANS_BLOCK); } parent::__construct(Item::DYE, $meta, $count, "Dye"); }
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null) { if ($face !== 0) { $nbt = new CompoundTag("", ["id" => new StringTag("id", Tile::SIGN), "x" => new IntTag("x", $block->x), "y" => new IntTag("y", $block->y), "z" => new IntTag("z", $block->z), "Text1" => new StringTag("Text1", ""), "Text2" => new StringTag("Text2", ""), "Text3" => new StringTag("Text3", ""), "Text4" => new StringTag("Text4", "")]); if ($player !== null) { $nbt->Creator = new StringTag("Creator", $player->getRawUniqueId()); } if ($item->hasCustomBlockData()) { foreach ($item->getCustomBlockData() as $key => $v) { $nbt->{$key} = $v; } } if ($face === 1) { $this->meta = floor(($player->yaw + 180) * 16 / 360 + 0.5) & 0xf; $this->getLevel()->setBlock($block, Block::get(Item::SIGN_POST, $this->meta), true); Tile::createTile(Tile::SIGN, $this->getLevel()->getChunk($block->x >> 4, $block->z >> 4), $nbt); return true; } else { $this->meta = $face; $this->getLevel()->setBlock($block, Block::get(Item::WALL_SIGN, $this->meta), true); Tile::createTile(Tile::SIGN, $this->getLevel()->getChunk($block->x >> 4, $block->z >> 4), $nbt); return true; } } return false; }
public function onUpdate() { $this->entityBaseTick(); if ($this->closed !== false) { return false; } $this->motionY -= $this->gravity; $this->move($this->motionX, $this->motionY, $this->motionZ); $friction = 1 - $this->drag; $this->motionX *= $friction; $this->motionY *= 1 - $this->drag; $this->motionZ *= $friction; $pos = $this->floor(); if ($this->ticksLived === 1) { $block = $this->level->getBlock($pos); if ($block->getID() != $this->blockId) { $this->kill(); return true; } $this->level->setBlock($pos, Block::get(0, true)); } if ($this->onGround) { $this->kill(); $block = $this->level->getBlock($pos); if (!$block->isFullBlock) { $this->getLevel()->dropItem($this, Item::get($this->getBlock(), 0, 1)); } else { $this->getLevel()->setBlock($pos, Block::get($this->getBlock(), 0), true); } } $this->updateMovement(); return !$this->onGround or $this->motionX == 0 and $this->motionY == 0 and $this->motionZ == 0; }
public function populate(ChunkManager $level, $chunkX, $chunkZ, Random $random) { $chunk = $level->getChunk($chunkX, $chunkZ); for ($x = 0; $x < 16; ++$x) { for ($z = 0; $z < 16; ++$z) { $biome = Biome::getBiome($chunk->getBiomeId($x, $z)); $cover = $biome->getGroundCover(); if (count($cover) > 0) { $diffY = 0; if (!$cover[0]->isSolid()) { $diffY = 1; } $column = $chunk->getBlockIdColumn($x, $z); for ($y = 127; $y > 0; --$y) { if ($column[$y] !== "" and !Block::get(ord($column[$y]))->isTransparent()) { break; } } $startY = min(127, $y + $diffY); $endY = $startY - count($cover); for ($y = $startY; $y > $endY and $y >= 0; --$y) { $b = $cover[$startY - $y]; if ($column[$y] === "" and $b->isSolid()) { break; } if ($b->getDamage() === 0) { $chunk->setBlockId($x, $y, $z, $b->getId()); } else { $chunk->setBlock($x, $y, $z, $b->getId(), $b->getDamage()); } } } } } }
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) instanceof RailBlock && $block->getSide(Vector3::SIDE_WEST) instanceof RailBlock) { if ($up->getSide(Vector3::SIDE_EAST) instanceof RailBlock) { $this->setDirection(Vector3::SIDE_EAST, true); } elseif ($up->getSide(Vector3::SIDE_WEST) instanceof RailBlock) { $this->setDirection(Vector3::SIDE_WEST, true); } else { $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) { $this->setDirection(Vector3::SIDE_SOUTH, true); } elseif ($up->getSide(Vector3::SIDE_NORTH) instanceof RailBlock) { $this->setDirection(Vector3::SIDE_NORTH, true); } else { $this->setDirection(Vector3::SIDE_SOUTH); } } else { $this->setDirection(Vector3::SIDE_NORTH); } return true; } return false; }
public function onRun($tick) { $blocks = 0; while ($this->pos->x < $this->xMax) { while ($this->pos->z < $this->zMax) { while ($this->pos->y < 128) { if ($this->pos->y === 0) { $block = $this->bottomBlock; } elseif ($this->pos->y < $this->height) { $block = $this->plotFillBlock; } elseif ($this->pos->y === $this->height) { $block = $this->plotFloorBlock; } else { $block = Block::get(0); } $this->level->setBlock($this->pos, $block, false, false); $blocks++; if ($blocks === $this->maxBlocksPerTick) { $this->getOwner()->getServer()->getScheduler()->scheduleDelayedTask($this, 1); return; } $this->pos->y++; } $this->pos->y = 0; $this->pos->z++; } $this->pos->z = $this->plotBeginPos->z; $this->pos->x++; } if ($this->issuer !== null) { $this->issuer->sendMessage(TextFormat::GREEN . "Successfully cleared this plot"); } }
public function onEntityDamage(EntityDamageEvent $event) { if (!$event->isCancelled() && $event instanceof EntityDamageByEntityEvent) { $e = $event->getEntity(); $arrow = $event->getDamager(); $damage = round($event->getDamage() / 2); if ($arrow instanceof AbilityArrow) { $shoter = $arrow->shootingEntity; if ($shoter instanceof Player) { if ($arrow instanceof FireArrow) { $e->setOnFire(rand(3, 10)); } elseif ($arrow instanceof TeleportArrow) { $shoter->teleport($e); } elseif ($arrow instanceof SpiderArrow) { $e->getLevel()->setBlock($e, Block::get(30)); } elseif ($arrow instanceof HealArrow) { $damage = -$damage; } elseif ($arrow instanceof PowerArrow) { $damage = round($damage * rand(2, 3) / 2); } else { return; } $arrow->kill(); } } $event->setDamage($damage); } }
public function resetArena() { foreach ($this->players as $p) { if ($p instanceof Player) { $p->sendMessage(TextFormat::AQUA . "[SimpleSpleef] " . TextFormat::GOLD . "You have won!"); $this->removePlayer($p); if ($this->plugin->getConfig()->get("display") == true) { $this->plugin->getServer()->broadcastMessage(TextFormat::AQUA . "[SimpleSpleef] " . TextFormat::GOLD . $p->getDisplayName() . " has won spleef in Arena " . $this->getArenaName()); } } } $this->enabled = false; foreach ($this->broken as $block) { if ($block instanceof Position) { $level = $block->getLevel(); $x = $block->getX(); $y = $block->getY(); $z = $block->getZ(); $level->setBlock(new Vector3($x, $y, $z), Block::get(Block::SNOW_BLOCK)); } } $this->second = $this->plugin->getConfig()->get("wait"); $this->broken = array(); $this->active = false; $this->enabled = true; }
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 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, false, true); return Level::BLOCK_UPDATE_WEAK; } return false; }
public function onUpdate($currentTick) { if ($this->onGround and ($this->motionX != 0 or $this->motionY != 0 or $this->motionZ != 0)) { $this->getLevel->setBlock($this, Block::get(30)); $this->kill(); } return parent::onUpdate($currentTick); }
public function __construct($meta = 0, $count = 1) { if ($meta === self::COCOA_BEANS) { $this->block = Block::get(Item::COCOA_POD); $this->meta = 1; } parent::__construct(self::DYE, $meta, $count, $this->getNameByMeta($meta)); }
public function onUpdate($type) { if ($type === Level::BLOCK_UPDATE_NORMAL or $type === Level::BLOCK_UPDATE_TOUCH) { $this->getLevel()->setBlock($this, Block::get(123, $this->meta), \false, \true); return Level::BLOCK_UPDATE_WEAK; } return \false; }
public function attack($damage, EntityDamageEvent $source) { parent::attack($damage, $source); if ($source->isCancelled()) { return false; } $this->level->addParticle(new DestroyBlockParticle($this->add(0.5), Block::get(Block::LADDER))); $this->kill(); }
public function __construct($meta = 0, $count = 1) { if ($meta === 3) { $this->block = Block::get(Item::COCOA_BLOCK); parent::__construct(self::DYE, 3, $count, "Cocoa Beans"); } else { parent::__construct(self::DYE, $meta, $count, $this->getNameByMeta($meta)); } }
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) { $down = $this->getSide(0); if ($down->isTransparent() === false) { $this->getLevel()->setBlock($block, Block::get(Item::POWERED_RAIL, 0), true, true); return true; } return false; }
public function __construct($meta = 0, $count = 1) { $this->id = self::REDSTONE_DUST & 0xffff; $this->meta = $meta !== null ? $meta & 0xffff : null; $this->count = (int) $count; $this->name = "Redstone Dust"; $this->block = Block::get(Block::REDSTONE_DUST, $this->meta); $this->name = $this->block->getName(); }
public function setDirection($face, $isOnSlope = false) { $extrabitset = ($this->meta & 0x8) === 0x8; if ($face !== Vector3::SIDE_WEST && $face !== Vector3::SIDE_EAST && $face !== Vector3::SIDE_NORTH && $face !== Vector3::SIDE_SOUTH) { throw new IllegalArgumentException("This rail variant can't be on a curve!"); } $this->meta = $extrabitset ? $this->meta | 0x8 : $this->meta & ~0x8; $this->getLevel()->setBlock($this, Block::get($this->id, $this->meta)); }
public function onPlayerMove(PlayerMoveEvent $event) { $player = $event->getPlayer(); $level = $player->getLevel(); $block = Block::get($player->getInventory()->getItemInHand()->getId(), 0); $pos = new Vector3($player->getFloorX(), $player->getFloorY() - 1, $player->getFloorZ()); if ($this->isPlayer($player)) { $level->setBlock($pos, $block); } }
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null) { $down = $this->getSide(0); if ($down->isTransparent() === false) { // TODO: Add support for Curved and Sloped rails. $this->getLevel()->setBlock($block, Block::get(Item::RAIL, 0), true, true); return true; } return false; }
public function onEnable() { $cfg = $this->getConfig(); $ticks = $cfg->get("ticks"); $this->getServer()->getScheduler()->scheduleDelayedRepeatingTask(new Tasks\ChangeBlockTask($this, new Position($cfg->get("x1"), $cfg->get("y1"), $cfg->get("z1"), $this->getServer()->getDefaultLevel()), [Block::get(Block::STAINED_CLAY, 4), Block::get(Block::STAINED_CLAY, 13), Block::get(Block::STAINED_CLAY, 14)]), $ticks, $ticks); $this->getServer()->getScheduler()->scheduleDelayedRepeatingTask(new Tasks\ChangeBlockTask($this, new Position($cfg->get("x2"), $cfg->get("y2"), $cfg->get("z2"), $this->getServer()->getDefaultLevel()), [Block::get(Block::STAINED_CLAY, 4), Block::get(Block::STAINED_CLAY, 13), Block::get(Block::STAINED_CLAY, 14)]), $ticks, $ticks); $this->getServer()->getScheduler()->scheduleDelayedRepeatingTask(new Tasks\ChangeBlockTask($this, new Position($cfg->get("x3"), $cfg->get("y3"), $cfg->get("z3"), $this->getServer()->getDefaultLevel()), [Block::get(Block::STAINED_CLAY, 4), Block::get(Block::STAINED_CLAY, 13), Block::get(Block::STAINED_CLAY, 14)]), $ticks, $ticks); $this->getServer()->getScheduler()->scheduleDelayedRepeatingTask(new Tasks\ChangeBlockTask($this, new Position($cfg->get("x4"), $cfg->get("y4"), $cfg->get("z4"), $this->getServer()->getDefaultLevel()), [Block::get(Block::STAINED_CLAY, 4), Block::get(Block::STAINED_CLAY, 13), Block::get(Block::STAINED_CLAY, 14)]), $ticks, $ticks); $this->getServer()->getScheduler()->scheduleDelayedRepeatingTask(new Tasks\ChangeBlockTask($this, new Position($cfg->get("x5"), $cfg->get("y5"), $cfg->get("z5"), $this->getServer()->getDefaultLevel()), [Block::get(Block::STAINED_CLAY, 4), Block::get(Block::STAINED_CLAY, 13), Block::get(Block::STAINED_CLAY, 14)]), $ticks, $ticks); $this->getLogger()->info("BlockChanger has been enabled."); }
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null) { $down = $this->getSide(0); $up = $this->getSide(1); if ($down->getId() === self::GRASS or $down->getId() === self::DIRT) { $this->getLevel()->setBlock($block, $this, true); $this->getLevel()->setBlock($up, Block::get($this->id, $this->meta ^ 0x8), true); return true; } return false; }
public function __construct() { parent::__construct(); $this->setGroundCover([Block::get(Block::DIRT, 0), Block::get(Block::DIRT, 0), Block::get(Block::DIRT, 0), Block::get(Block::DIRT, 0), Block::get(Block::DIRT, 0)]); $tallGrass = new TallGrass(); $tallGrass->setBaseAmount(5); $this->addPopulator($tallGrass); $this->setElevation(46, 68); $this->temperature = 0.5; $this->rainfall = 0.5; }
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; }