Esempio n. 1
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());
                     }
                 }
             }
         }
     }
 }
Esempio n. 2
0
 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;
 }
Esempio n. 3
0
 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;
 }
Esempio n. 4
0
 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;
 }
Esempio n. 5
0
 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;
 }
Esempio n. 6
0
 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));
 }
Esempio n. 7
0
 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;
 }
Esempio n. 8
0
 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(Player $player, Item $item, Vector3 $block, $face, $action = PlayerInteractEvent::RIGHT_CLICK_BLOCK)
 {
     if ($block instanceof Block) {
         $this->blockTouched = $block;
         $this->touchVector = new Vector3(0, 0, 0);
     } else {
         $this->touchVector = $block;
         $this->blockTouched = Block::get(0, 0, new Position(0, 0, 0, $player->level));
     }
     $this->player = $player;
     $this->item = $item;
     $this->blockFace = (int) $face;
     $this->action = (int) $action;
 }
Esempio n. 10
0
 /**
  *
  * @param int $item        	
  * @param int $data        	
  */
 public function setFlowerPotData($item, $data)
 {
     $this->namedtag->item = new Short("item", (int) $item);
     $this->namedtag->data = new Int("data", (int) $data);
     $this->spawnToAll();
     if ($this->chunk) {
         $this->chunk->setChanged();
         $this->level->clearChunkCache($this->chunk->getX(), $this->chunk->getZ());
         $block = $this->level->getBlock($this);
         if ($block->getId() === Block::FLOWER_POT_BLOCK) {
             $this->level->setBlock($this, Block::get(Block::FLOWER_POT_BLOCK, $data), true, true);
         }
     }
     return true;
 }
Esempio n. 11
0
 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;
 }
Esempio n. 12
0
 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;
 }
Esempio n. 13
0
 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;
 }
Esempio n. 14
0
 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;
 }
Esempio n. 15
0
 public function __construct($meta = 0, $count = 1)
 {
     $this->block = Block::get(Item::PUMPKIN_STEM);
     parent::__construct(self::PUMPKIN_SEEDS, 0, $count, "Pumpkin Seeds");
 }
Esempio n. 16
0
 public function __construct($meta = 0, $count = 1)
 {
     $this->block = Block::get(Item::SPRUCE_DOOR_BLOCK);
     parent::__construct(self::SPRUCE_DOOR, 0, $count, "Spruce Door");
 }
Esempio n. 17
0
 /**
  * @param Vector3 $spawn default null
  *
  * @return bool|Position
  */
 public function getSafeSpawn($spawn = null)
 {
     if (!$spawn instanceof Vector3 or $spawn->y <= 0) {
         $spawn = $this->getSpawnLocation();
     }
     if ($spawn instanceof Vector3) {
         $v = $spawn->floor();
         $chunk = $this->getChunk($v->x >> 4, $v->z >> 4, false);
         $x = $v->x & 0xf;
         $z = $v->z & 0xf;
         if ($chunk !== null) {
             $y = (int) min(126, $v->y);
             $wasAir = $chunk->getBlockId($x, $y - 1, $z) === 0;
             for (; $y > 0; --$y) {
                 $b = $chunk->getFullBlock($x, $y, $z);
                 $block = Block::get($b >> 4, $b & 0xf);
                 if ($this->isFullBlock($block)) {
                     if ($wasAir) {
                         $y++;
                         break;
                     }
                 } else {
                     $wasAir = true;
                 }
             }
             for (; $y >= 0 and $y < 128; ++$y) {
                 $b = $chunk->getFullBlock($x, $y + 1, $z);
                 $block = Block::get($b >> 4, $b & 0xf);
                 if (!$this->isFullBlock($block)) {
                     $b = $chunk->getFullBlock($x, $y, $z);
                     $block = Block::get($b >> 4, $b & 0xf);
                     if (!$this->isFullBlock($block)) {
                         return new Position($spawn->x, $y === (int) $spawn->y ? $spawn->y + 0.2 : $y, $spawn->z, $this);
                     }
                 } else {
                     ++$y;
                 }
             }
             $v->y = $y;
         }
         return new Position($spawn->x, $v->y + 0.2, $spawn->z, $this);
     }
     return false;
 }
Esempio n. 18
0
 public function __construct($meta = 0, $count = 1)
 {
     $this->block = Block::get(Item::WHEAT_BLOCK);
     parent::__construct(self::WHEAT_SEEDS, 0, $count, "Wheat Seeds");
 }
Esempio n. 19
0
 public function __construct($meta = 0, $count = 1)
 {
     $this->block = Block::get(Item::BIRCH_DOOR_BLOCK);
     parent::__construct(self::BIRCH_DOOR, 0, $count, "Birch Door");
 }
Esempio n. 20
0
 public function __construct($meta = 0, $count = 1)
 {
     $this->block = Block::get(self::CAKE_BLOCK);
     parent::__construct(self::CAKE, 0, $count, "Cake");
 }
Esempio n. 21
0
 public function __construct($meta = 0, $count = 1)
 {
     $this->block = Block::get(Item::REDSTONE_WIRE);
     parent::__construct(self::REDSTONE, 0, $count, "Redstone");
 }
Esempio n. 22
0
 public function __construct($meta = 0, $count = 1)
 {
     $this->block = Block::get(Item::SUGARCANE_BLOCK);
     parent::__construct(self::SUGARCANE, 0, $count, "Sugar Cane");
 }
Esempio n. 23
0
 public function __construct()
 {
     $this->setGroundCover([Block::get(Block::SAND, 0), Block::get(Block::SAND, 0), Block::get(Block::SANDSTONE, 0), Block::get(Block::SANDSTONE, 0), Block::get(Block::SANDSTONE, 0)]);
 }
Esempio n. 24
0
 public function __construct($meta = 0, $count = 1)
 {
     $this->block = Block::get(Block::SKULL_BLOCK);
     parent::__construct(self::SKULL, $meta, $count, "Skull");
 }
Esempio n. 25
0
 public function __construct()
 {
     $this->setGroundCover([Block::get(Block::GRASS, 0), Block::get(Block::DIRT, 0), Block::get(Block::DIRT, 0), Block::get(Block::DIRT, 0), Block::get(Block::DIRT, 0)]);
 }
Esempio n. 26
0
 public function getBlock()
 {
     if ($this->block instanceof Block) {
         return clone $this->block;
     } else {
         return Block::get(self::AIR);
     }
 }
Esempio n. 27
0
 public function onUpdate()
 {
     if ($this->closed === true) {
         return false;
     }
     $this->timings->startTiming();
     $ret = false;
     $fuel = $this->inventory->getFuel();
     $raw = $this->inventory->getSmelting();
     $product = $this->inventory->getResult();
     $smelt = $this->server->getCraftingManager()->matchFurnaceRecipe($raw);
     $canSmelt = ($smelt instanceof FurnaceRecipe and $raw->getCount() > 0 and ($smelt->getResult()->equals($product) and $product->getCount() < $product->getMaxStackSize() or $product->getId() === Item::AIR));
     if ($this->namedtag["BurnTime"] <= 0 and $canSmelt and $fuel->getFuelTime() !== null and $fuel->getCount() > 0) {
         $this->checkFuel($fuel);
     }
     if ($this->namedtag["BurnTime"] > 0) {
         $this->namedtag->BurnTime = new Short("BurnTime", $this->namedtag["BurnTime"] - 1);
         $this->namedtag->BurnTicks = new Short("BurnTicks", ceil($this->namedtag["BurnTime"] / $this->namedtag["MaxTime"] * 200));
         if ($smelt instanceof FurnaceRecipe and $canSmelt) {
             $this->namedtag->CookTime = new Short("CookTime", $this->namedtag["CookTime"] + 1);
             if ($this->namedtag["CookTime"] >= 200) {
                 //10 seconds
                 $product = Item::get($smelt->getResult()->getId(), $smelt->getResult()->getDamage(), $product->getCount() + 1);
                 $this->server->getPluginManager()->callEvent($ev = new FurnaceSmeltEvent($this, $raw, $product));
                 if (!$ev->isCancelled()) {
                     $this->inventory->setResult($ev->getResult());
                     $raw->setCount($raw->getCount() - 1);
                     if ($raw->getCount() === 0) {
                         $raw = Item::get(Item::AIR, 0, 0);
                     }
                     $this->inventory->setSmelting($raw);
                 }
                 $this->namedtag->CookTime = new Short("CookTime", $this->namedtag["CookTime"] - 200);
             }
         } elseif ($this->namedtag["BurnTime"] <= 0) {
             $this->namedtag->BurnTime = new Short("BurnTime", 0);
             $this->namedtag->CookTime = new Short("CookTime", 0);
             $this->namedtag->BurnTicks = new Short("BurnTicks", 0);
         } else {
             $this->namedtag->CookTime = new Short("CookTime", 0);
         }
         $ret = true;
     } else {
         if ($this->getBlock()->getId() === Item::BURNING_FURNACE) {
             $this->getLevel()->setBlock($this, Block::get(Item::FURNACE, $this->getBlock()->getDamage()), true);
         }
         $this->namedtag->BurnTime = new Short("BurnTime", 0);
         $this->namedtag->CookTime = new Short("CookTime", 0);
         $this->namedtag->BurnTicks = new Short("BurnTicks", 0);
     }
     foreach ($this->getInventory()->getViewers() as $player) {
         $windowId = $player->getWindowId($this->getInventory());
         if ($windowId > 0) {
             $pk = new ContainerSetDataPacket();
             $pk->windowid = $windowId;
             $pk->property = 0;
             //Smelting
             $pk->value = floor($this->namedtag["CookTime"]);
             $player->dataPacket($pk);
             $pk = new ContainerSetDataPacket();
             $pk->windowid = $windowId;
             $pk->property = 1;
             //Fire icon
             $pk->value = $this->namedtag["BurnTicks"];
             $player->dataPacket($pk);
         }
     }
     $this->lastUpdate = microtime(true);
     $this->timings->stopTiming();
     return $ret;
 }
Esempio n. 28
0
 public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null)
 {
     $down = $this->getSide(Vector3::SIDE_DOWN);
     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;
     }
     $arrayXZ = [[1, 0], [0, 1], [-1, 0], [0, -1]];
     $arrayY = [0, 1, -1];
     $connected = [];
     foreach ($arrayXZ as $xz) {
         $x = $xz[0];
         $z = $xz[1];
         foreach ($arrayY as $y) {
             $v3 = (new Vector3($x, $y, $z))->add($this);
             $block = $this->level->getBlock($v3);
             if ($block instanceof Rail) {
                 if ($block->connect($this)) {
                     $connected[] = $v3;
                     break;
                 }
             }
         }
         if (count($connected) == 2) {
             break;
         }
     }
     switch (count($connected)) {
         case 1:
             $v3 = $connected[0]->subtract($this);
             $this->meta = $v3->y != 1 ? $v3->x == 0 ? 0 : 1 : ($v3->z == 0 ? $v3->x / -2 + 2.5 : $v3->z / 2 + 4.5);
             break;
         case 2:
             $subtract = [];
             foreach ($connected as $key => $value) {
                 $subtract[$key] = $value->subtract($this);
             }
             if (abs($subtract[0]->x) == abs($subtract[1]->z) and abs($subtract[1]->x) == abs($subtract[0]->z)) {
                 $v3 = $connected[0]->subtract($this)->add($connected[1]->subtract($this));
                 $this->meta = $v3->x == 1 ? $v3->z == 1 ? 6 : 9 : ($v3->z == 1 ? 7 : 8);
             } elseif ($subtract[0]->y == 1 or $subtract[1]->y == 1) {
                 $v3 = $subtract[0]->y == 1 ? $subtract[0] : $subtract[1];
                 $this->meta = $v3->x == 0 ? $v3->z == -1 ? 4 : 5 : ($v3->x == 1 ? 2 : 3);
             } else {
                 $this->meta = $subtract[0]->x == 0 ? 0 : 1;
             }
             break;
         default:
             break;
     }
     $this->level->setBlock($this, Block::get($this->id, $this->meta), true, true);
     return true;
 }
Esempio n. 29
0
 public function __construct($meta = 0, $count = 1)
 {
     $this->block = Block::get(Item::BREWING_STAND);
     parent::__construct(self::BREWING_STAND_FULL, 0, $count, "Brewing Stand");
 }
Esempio n. 30
0
 public function __construct($meta = 0, $count = 1)
 {
     $this->block = Block::get(Item::MELON_STEM);
     parent::__construct(self::MELON_SEEDS, 0, $count, "Melon Seeds");
 }