Inheritance: extends Animal
Exemple #1
0
 public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null)
 {
     if ($player instanceof Player) {
         $this->meta = ((int) $player->getDirection() + 5) % 4;
     }
     $this->getLevel()->setBlock($block, $this, true, true);
     if ($player != null) {
         $firstBlock = $this->getLevel()->getBlock($block->add(0, -1, 0));
         $secondBlock = $this->getLevel()->getBlock($block->add(0, -2, 0));
         $thirdBlock = $this->getLevel()->getBlock($block->add(0, -1, -1));
         $fourthBlock = $this->getLevel()->getBlock($block->add(0, -1, 1));
         $fifthBlock = $this->getLevel()->getBlock($block->add(0, -2, -1));
         $sixthBlock = $this->getLevel()->getBlock($block->add(0, -2, 1));
         if ($firstBlock->getId() === Item::SNOW_BLOCK && $secondBlock->getId() === Item::SNOW_BLOCK) {
             //Block match snowgolem
             $this->getLevel()->setBlock($block, new Air());
             $this->getLevel()->setBlock($firstBlock, new Air());
             $this->getLevel()->setBlock($secondBlock, new Air());
             $snowGolem = new SnowGolem($player->getLevel()->getChunk($this->getX() >> 4, $this->getZ() >> 4), new Compound("", ["Pos" => new Enum("Pos", [new Double("", $this->x), new Double("", $this->y), new Double("", $this->z)]), "Motion" => new Enum("Motion", [new Double("", 0), new Double("", 0), new Double("", 0)]), "Rotation" => new Enum("Rotation", [new Float("", 0), new Float("", 0)])]));
             $snowGolem->spawnToAll();
         } elseif ($firstBlock->getId() === Item::IRON_BLOCK && $secondBlock->getId() === Item::IRON_BLOCK) {
             if ($thirdBlock->getId() === Item::IRON_BLOCK && $fourthBlock->getId() === Item::IRON_BLOCK && $fifthBlock->getId() === Item::AIR && $sixthBlock->getId() === Item::AIR) {
                 $this->getLevel()->setBlock($thirdBlock, new Air());
                 $this->getLevel()->setBlock($fourthBlock, new Air());
             } elseif ($fifthBlock->getId() === Item::IRON_BLOCK && $sixthBlock->getId() === Item::IRON_BLOCK && $thirdBlock->getId() === Item::AIR && $fourthBlock->getId() === Item::AIR) {
                 $this->getLevel()->setBlock($fifthBlock, new Air());
                 $this->getLevel()->setBlock($sixthBlock, new Air());
             } else {
                 return true;
             }
             $this->getLevel()->setBlock($block, new Air());
             $this->getLevel()->setBlock($firstBlock, new Air());
             $this->getLevel()->setBlock($secondBlock, new Air());
             $ironGolem = new IronGolem($player->getLevel()->getChunk($this->getX() >> 4, $this->getZ() >> 4), new Compound("", ["Pos" => new Enum("Pos", [new Double("", $this->x), new Double("", $this->y), new Double("", $this->z)]), "Motion" => new Enum("Motion", [new Double("", 0), new Double("", 0), new Double("", 0)]), "Rotation" => new Enum("Rotation", [new Float("", 0), new Float("", 0)])]));
             $ironGolem->spawnToAll();
         }
     }
     return true;
 }
 public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null)
 {
     if ($player instanceof Player) {
         $this->meta = ((int) $player->getDirection() + 5) % 4;
     }
     $this->getLevel()->setBlock($block, $this, true, true);
     if ($player != null) {
         // interesting for snow golem AND iron golem (this can be the body)
         $firstBlock = $this->getLevel()->getBlock($block->add(0, -1, 0));
         $secondBlock = $this->getLevel()->getBlock($block->add(0, -2, 0));
         // interesting for iron golem (checking arms and air beyond the feet)
         $armBlock1 = $this->getLevel()->getBlock($block->add(0, -1, -1));
         // arm 1
         $armBlock2 = $this->getLevel()->getBlock($block->add(0, -1, 1));
         // arm2
         $airBlock1 = $this->getLevel()->getBlock($block->add(0, -2, -1));
         // beneath arms
         $airBlock2 = $this->getLevel()->getBlock($block->add(0, -2, 1));
         // beneath arms
         // we've to test in all 3d!
         $armBlock3 = $this->getLevel()->getBlock($block->add(-1, -1, 0));
         // arm 1
         $armBlock4 = $this->getLevel()->getBlock($block->add(1, -1, 0));
         // arm2
         $airBlock3 = $this->getLevel()->getBlock($block->add(-1, -2, 0));
         // beneath arms
         $airBlock4 = $this->getLevel()->getBlock($block->add(1, -2, 0));
         // beneath arms
         // $player->getServer()->getLogger()->debug("[1st:$firstBlock] [2nd:$secondBlock] [arm1:$armBlock1] [arm2:$armBlock2] [arm3:$armBlock3] [arm4:$armBlock4] [air1:$airBlock1] [air2:$airBlock2] [air3:$airBlock3] [air4:$airBlock4]");
         if ($firstBlock->getId() === Item::SNOW_BLOCK && $secondBlock->getId() === Item::SNOW_BLOCK) {
             //Block match snowgolem
             $this->getLevel()->setBlock($block, new Air());
             $this->getLevel()->setBlock($firstBlock, new Air());
             $this->getLevel()->setBlock($secondBlock, new Air());
             $snowGolem = new SnowGolem($player->getLevel()->getChunk($this->getX() >> 4, $this->getZ() >> 4), new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $this->x), new DoubleTag("", $this->y), new DoubleTag("", $this->z)]), "Motion" => new ListTag("Motion", [new DoubleTag("", 0), new DoubleTag("", 0), new DoubleTag("", 0)]), "Rotation" => new ListTag("Rotation", [new FloatTag("", 0), new FloatTag("", 0)])]));
             $snowGolem->spawnToAll();
         } elseif ($firstBlock->getId() === Item::IRON_BLOCK && $secondBlock->getId() === Item::IRON_BLOCK) {
             // possible iron golem
             if ($armBlock1->getId() === Item::IRON_BLOCK && $armBlock2->getId() === Item::IRON_BLOCK && $airBlock1->getId() === Item::AIR && $airBlock2->getId() === Item::AIR || $armBlock3->getId() === Item::IRON_BLOCK && $armBlock4->getId() === Item::IRON_BLOCK && $airBlock3->getId() === Item::AIR && $airBlock4->getId() === Item::AIR) {
                 $this->getLevel()->setBlock($block, new Air());
                 $this->getLevel()->setBlock($firstBlock, new Air());
                 $this->getLevel()->setBlock($secondBlock, new Air());
                 $this->getLevel()->setBlock($armBlock1, new Air());
                 $this->getLevel()->setBlock($armBlock2, new Air());
                 $this->getLevel()->setBlock($armBlock3, new Air());
                 $this->getLevel()->setBlock($armBlock4, new Air());
                 $ironGolem = new IronGolem($player->getLevel()->getChunk($this->getX() >> 4, $this->getZ() >> 4), new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $this->x), new DoubleTag("", $this->y), new DoubleTag("", $this->z)]), "Motion" => new ListTag("Motion", [new DoubleTag("", 0), new DoubleTag("", 0), new DoubleTag("", 0)]), "Rotation" => new ListTag("Rotation", [new FloatTag("", 0), new FloatTag("", 0)])]));
                 $ironGolem->spawnToAll();
             }
         }
     }
     return true;
 }
Exemple #3
-2
 public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null)
 {
     if ($player instanceof Player) {
         $this->meta = ((int) $player->getDirection() + 5) % 4;
     }
     $this->getLevel()->setBlock($block, $this, true, true);
     if ($player != null) {
         $level = $this->getLevel();
         if ($player->getServer()->allowSnowGolem) {
             $block0 = $level->getBlock($block->add(0, -1, 0));
             $block1 = $level->getBlock($block->add(0, -2, 0));
             if ($block0->getId() == Item::SNOW_BLOCK and $block1->getId() == Item::SNOW_BLOCK) {
                 $level->setBlock($block, new Air());
                 $level->setBlock($block0, new Air());
                 $level->setBlock($block1, new Air());
                 $golem = new SnowGolem($player->getLevel()->getChunk($this->getX() >> 4, $this->getZ() >> 4), new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $this->x), new DoubleTag("", $this->y), new DoubleTag("", $this->z)]), "Motion" => new ListTag("Motion", [new DoubleTag("", 0), new DoubleTag("", 0), new DoubleTag("", 0)]), "Rotation" => new ListTag("Rotation", [new FloatTag("", 0), new FloatTag("", 0)])]));
                 $golem->spawnToAll();
             }
         }
         if ($player->getServer()->allowIronGolem) {
             $block0 = $level->getBlock($block->add(0, -1, 0));
             $block1 = $level->getBlock($block->add(0, -2, 0));
             $block2 = $level->getBlock($block->add(-1, -1, 0));
             $block3 = $level->getBlock($block->add(1, -1, 0));
             $block4 = $level->getBlock($block->add(0, -1, -1));
             $block5 = $level->getBlock($block->add(0, -1, 1));
             if ($block0->getId() == Item::IRON_BLOCK and $block1->getId() == Item::IRON_BLOCK) {
                 if ($block2->getId() == Item::IRON_BLOCK and $block3->getId() == Item::IRON_BLOCK and $block4->getId() == Item::AIR and $block5->getId() == Item::AIR) {
                     $level->setBlock($block2, new Air());
                     $level->setBlock($block3, new Air());
                 } elseif ($block4->getId() == Item::IRON_BLOCK and $block5->getId() == Item::IRON_BLOCK and $block2->getId() == Item::AIR and $block3->getId() == Item::AIR) {
                     $level->setBlock($block4, new Air());
                     $level->setBlock($block5, new Air());
                 } else {
                     return;
                 }
                 $level->setBlock($block, new Air());
                 $level->setBlock($block0, new Air());
                 $level->setBlock($block1, new Air());
                 $golem = new IronGolem($player->getLevel()->getChunk($this->getX() >> 4, $this->getZ() >> 4), new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $this->x), new DoubleTag("", $this->y), new DoubleTag("", $this->z)]), "Motion" => new ListTag("Motion", [new DoubleTag("", 0), new DoubleTag("", 0), new DoubleTag("", 0)]), "Rotation" => new ListTag("Rotation", [new FloatTag("", 0), new FloatTag("", 0)])]));
                 $golem->spawnToAll();
             }
         }
     }
     return true;
 }