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)
 {
     $down = $this->getSide(0);
     if ($target->isTransparent() === false and $face !== 0) {
         $faces = [1 => 5, 2 => 4, 3 => 3, 4 => 2, 5 => 1];
         $this->meta = $faces[$face];
         $side = $faces[$face];
         $faces = [1 => 4, 2 => 5, 3 => 2, 4 => 3, 5 => 0, 6 => 0, 0 => 0];
         if ($this->getSide($faces[$side])->isCharged($this->getHash())) {
             $this->id = 75;
             $this->getLevel()->setBlock($block, $this);
             return;
         }
         $this->getLevel()->setBlock($block, $this);
         $this->BroadcastRedstoneUpdate(Level::REDSTONE_UPDATE_PLACE, Block::REDSTONESOURCEPOWER);
         return true;
     } elseif ($down->isTransparent() === false or $down->getId() === self::FENCE or $down->getId() === self::COBBLE_WALL or $down->getId() === self::GLASS || $down instanceof Slab && ($down->meta & 0x8) === 0x8 || $down instanceof WoodSlab && ($down->meta & 0x8) === 0x8 || $down instanceof Stair && ($down->meta & 0x4) === 0x4) {
         $this->meta = 0;
         if ($target->isCharged($this->getHash())) {
             $this->id = 75;
             $this->getLevel()->setBlock($block, $this);
             return;
         }
         $this->getLevel()->setBlock($block, $this);
         $this->BroadcastRedstoneUpdate(Level::REDSTONE_UPDATE_PLACE, Block::REDSTONESOURCEPOWER);
         return true;
     }
     return false;
 }
Exemple #3
0
 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 => 0, 3 => 2, 4 => 1, 5 => 3];
         $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]];
         $motive = $motives[mt_rand(0, count($motives) - 1)];
         $data = ["x" => $target->x, "y" => $target->y + 0.4, "z" => $target->z, "yaw" => $faces[$face] * 90, "Motive" => $motive[0]];
         $nbt = new Compound("", ["Motive" => new String("Motive", $data["Motive"]), "Pos" => new Enum("Pos", [new Double("", $data["x"]), new Double("", $data["y"]), new Double("", $data["z"])]), "Motion" => new Enum("Motion", [new Double("", 0), new Double("", 0), new Double("", 0)]), "Rotation" => new Enum("Rotation", [new Float("", $data["yaw"]), new Float("", 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);
         			}*/
         return true;
     }
     return false;
 }
Exemple #4
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;
 }
Exemple #5
0
 public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null)
 {
     if (!$target->isTransparent() || ($face === 0 && ($this->getSide(0) instanceof Slab && ($this->getSide(0)->meta & 0x8) === 0x8) || $this->getSide(0) instanceof WoodSlab && ($this->getSide(0)->meta & 0x8) === 0x8 || $this->getSide(0) instanceof Stair && ($this->getSide(0)->meta & 0x4) === 0x4)) {
         $this->meta = $face;
         $this->getLevel()->setBlock($block, $this, true, false);
         return true;
     }
     return false;
 }
Exemple #6
0
 public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null)
 {
     if ($face !== 0 && $face !== 1 && !$target->isTransparent()) {
         $ret = $this->setFacingDirection($face);
         $this->getLevel()->setBlock($block, $this, true);
         return $ret;
     }
     return false;
 }
 public function __construct(Player $player, Block $block, Item $item, $instaBreak = false)
 {
     $this->block = $block;
     $this->item = $item;
     $this->player = $player;
     $this->instaBreak = (bool) $instaBreak;
     $drops = $player->isSurvival() ? $block->getDrops($item) : [];
     foreach ($drops as $i) {
         $this->blockDrops[] = Item::get($i[0], $i[1], $i[2]);
     }
 }
Exemple #8
0
 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 Int("item", 0), new Int("data", 0)]);
         $pot = Tile::createTile("FlowerPot", $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt);
         return true;
     }
     return false;
 }
Exemple #9
0
 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;
 }
Exemple #10
0
 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;
 }
Exemple #11
0
 public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null)
 {
     if ($target->isTransparent() === false) {
         $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;
 }
Exemple #12
0
 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;
 }
Exemple #13
0
 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;
 }
 public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null)
 {
     $below = $this->getSide(0);
     if ($target->isTransparent() === false and $face !== 0) {
         $faces = [1 => 5, 2 => 4, 3 => 3, 4 => 2, 5 => 1];
         $this->meta = $faces[$face];
         $this->getLevel()->setBlock($block, $this, true, true);
         return true;
     } elseif ($this->getSide($faces[$side])->isTransparent() === true and !($side === 0 and ($below->getId() === self::FENCE or $below->getId() === self::COBBLE_WALL or $below->getId() === self::GLASS || $below instanceof Slab && ($below->meta & 0x8) === 0x8 || $below instanceof WoodSlab && ($below->meta & 0x8) === 0x8 || $below instanceof Stair && ($below->meta & 0x4) === 0x4))) {
         $this->meta = 0;
         $this->getLevel()->setBlock($block, $this, true, true);
         return true;
     }
     return false;
 }
Exemple #15
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());
                     }
                 }
             }
         }
     }
 }
Exemple #16
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));
 }
 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;
 }
Exemple #18
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;
 }
Exemple #19
0
 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();
     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;
 }
Exemple #20
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;
 }
Exemple #21
0
 public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null)
 {
     if ($target->isTransparent() === false) {
         $faces = [0 => 0, 1 => 1, 2 => 2, 3 => 3];
         $damage = $this->getDamage();
         $this->meta = $faces[$player instanceof Player ? $player->getDirection() : 0] & 0x4;
         if ($damage >= 0 && $damage <= 3) {
             $this->meta = $faces[$player instanceof Player ? $player->getDirection() : 0];
         } elseif ($damage >= 4 && $damage <= 7) {
             $this->meta = $faces[$player instanceof Player ? $player->getDirection() : 0] | 0x4;
         } elseif ($damage >= 8 && $damage <= 11) {
             $this->meta = $faces[$player instanceof Player ? $player->getDirection() : 0] | 0x8;
         }
         $this->getLevel()->setBlock($block, $this, true);
         return true;
     }
     return false;
 }
Exemple #22
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;
 }
Exemple #23
0
 public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null)
 {
     if ($target->isTransparent() === false) {
         $faces = [3 => 3, 2 => 4, 4 => 2, 5 => 1];
         if ($face === 0) {
             $to = $player instanceof Player ? $player->getDirection() : 0;
             $this->meta = $to ^ 0x1 === 0x1 ? 0 : 7;
         } elseif ($face === 1) {
             $to = $player instanceof Player ? $player->getDirection() : 0;
             $this->meta = $to ^ 0x1 === 0x1 ? 6 : 5;
         } else {
             $this->meta = $faces[$face];
         }
         $this->getLevel()->setBlock($block, $this, true, true);
         return true;
     }
     return false;
 }
Exemple #24
0
 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;
 }
Exemple #25
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 onRun()
 {
     Block::init();
     Biome::init();
     $manager = new SimpleChunkManager($this->seed);
     $this->saveToThreadStore("generation.level{$this->levelId}.manager", $manager);
     /** @var Generator $generator */
     $generator = $this->generator;
     $generator = new $generator($this->settings);
     $generator->init($manager, new Random($manager->getSeed()));
     $this->saveToThreadStore("generation.level{$this->levelId}.generator", $generator);
 }
 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;
 }
Exemple #28
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;
 }
Exemple #29
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;
 }
Exemple #30
0
 /**
  * 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;
 }