Example #1
1
 public function onActivate(Item $item, Player $player = null)
 {
     if ($this->meta < 0x7 && $item->getID() === Item::DYE && $item->getDamage() === 0xf) {
         //Bonemeal
         $block = clone $this;
         $block->meta += mt_rand(2, 5);
         if ($block->meta > 0x7) {
             $block->meta = 0x7;
         }
         Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($this, $block));
         if (!$ev->isCancelled()) {
             $this->getLevel()->setBlock($this, $ev->getNewState(), true, true);
             if ($player->isSurvival()) {
                 $item->count--;
             }
             return true;
         }
     }
     return false;
 }
Example #2
0
 public function __construct(Location $loc, $name, $skin, $slim, Item $item, NPCWork $work)
 {
     $this->pos = $loc;
     $this->eid = Entity::$entityCount++;
     $this->skin = $skin;
     $this->slim = $slim;
     $this->name = $name;
     $this->item = $item->getID();
     $this->meta = $item->getDamage();
     $this->work = $work;
 }
Example #3
0
 public function onActivate(Item $item, Player $player = null)
 {
     if ($item->getID() === Item::DYE and $item->getDamage() === 0xf) {
         //Bonemeal
         $this->meta = 0x7;
         $this->getLevel()->setBlock($this, $this, true, true);
         $item->count--;
         return true;
     }
     return false;
 }
Example #4
0
 public function onActivate(Item $item, Player $player = null)
 {
     if ($item->getID() === Item::DYE and $item->getDamage() === 0xf) {
         $item->count--;
         TallGrassObject::growGrass($this->getLevel(), $this, new Random(mt_rand()), 8, 2);
         return true;
     } elseif ($item->isHoe()) {
         $item->useOn($this);
         $this->getLevel()->setBlock($this, new Farmland());
         return true;
     }
     return false;
 }
Example #5
0
 public function saveNBT()
 {
     $this->namedtag->Item = new Compound("Item", ["id" => new Short("id", $this->item->getID()), "Damage" => new Short("Damage", $this->item->getDamage()), "Count" => new Byte("Count", $this->item->getCount())]);
     $this->namedtag->Health = new Short("Health", $this->getHealth());
     $this->namedtag->Age = new Short("Age", $this->age);
     $this->namedtag->PickupDelay = new Short("PickupDelay", $this->pickupDelay);
     if ($this->owner !== null) {
         $this->namedtag->Owner = new String("Owner", $this->owner);
     }
     if ($this->thrower !== null) {
         $this->namedtag->Thrower = new String("Thrower", $this->thrower);
     }
 }
Example #6
0
 public function onActivate(Item $item, Player $player = null)
 {
     if ($item->getID() === Item::DYE and $item->getDamage() === 0xf) {
         //Bonemeal
         //TODO: change log type
         Tree::growTree($this->getLevel(), $this->x, $this->y, $this->z, new Random(mt_rand()), $this->meta & 0x7);
         if (($player->gamemode & 0x1) === 0) {
             $item->count--;
         }
         return true;
     }
     return false;
 }
Example #7
0
 public function onActivate(Item $item, Player $player = null)
 {
     if ($item->getID() === Item::FLINT_STEEL) {
         if (($player->gamemode & 0x1) === 0) {
             $item->useOn($this);
         }
         $data = ["x" => $this->x + 0.5, "y" => $this->y + 0.5, "z" => $this->z + 0.5, "power" => 4, "fuse" => 20 * 4];
         $this->getLevel()->setBlock($this, new Air(), false, false, true);
         //TODO
         //$e = Server::getInstance()->api->entity->add($this->level, ENTITY_OBJECT, OBJECT_PRIMEDTNT, $data);
         //$e->spawnToAll();
         return true;
     }
     return false;
 }
Example #8
0
 public function onActivate(Item $item, Player $player = null)
 {
     if ($item->getID() === Item::DYE and $item->getDamage() === 0xf) {
         //Bonemeal
         if ($this->getSide(0)->getID() !== self::SUGARCANE_BLOCK) {
             for ($y = 1; $y < 3; ++$y) {
                 $b = $this->getLevel()->getBlock(new Vector3($this->x, $this->y + $y, $this->z));
                 if ($b->getID() === self::AIR) {
                     $this->getLevel()->setBlock($b, new Sugarcane(), true);
                     break;
                 }
             }
             $this->meta = 0;
             $this->getLevel()->setBlock($this, $this, true);
         }
         if (($player->gamemode & 0x1) === 0) {
             $item->count--;
         }
         return true;
     }
     return false;
 }
Example #9
0
 /**
  * This method should not be used by plugins, use the Inventory
  *
  * @param int  $index
  * @param Item $item
  *
  * @return bool
  */
 public function setItem($index, Item $item)
 {
     $i = $this->getSlotIndex($index);
     $d = new Compound(false, [new Byte("Count", $item->getCount()), new Byte("Slot", $index), new Short("id", $item->getID()), new Short("Damage", $item->getDamage())]);
     if ($item->getID() === Item::AIR or $item->getCount() <= 0) {
         if ($i >= 0) {
             unset($this->namedtag->Items[$i]);
         }
     } elseif ($i < 0) {
         for ($i = 0; $i <= $this->getSize(); ++$i) {
             if (!isset($this->namedtag->Items[$i])) {
                 break;
             }
         }
         $this->namedtag->Items[$i] = $d;
     } else {
         $this->namedtag->Items[$i] = $d;
     }
     return true;
 }
Example #10
0
 protected function putSlot(Item $item)
 {
     if ($item->getID() === 0) {
         $this->putShort(-1);
     } else {
         $this->putShort($item->getID());
         $this->putByte($item->getCount());
         $this->putShort($item->getDamage());
         $nbt = $item->getCompoundTag();
         $this->putByte(strlen($nbt));
         $this->put($nbt);
     }
 }
 public function match(Item $item)
 {
     return $this->matchRaw($this->id, $item->getID(), $this->defaultID) and $this->matchRaw($this->damage, $item->getDamage(), $this->defaultDamage);
 }
 /**
  * @param Player $player
  * @param Item $item
  * @return boolean
  */
 private function hasItemPlayer(Player $player, Item $item)
 {
     if ($this->SignShop->getProvider()->getPlayer(strtolower($player->getName()))["authorized"] == "root") {
         return true;
     }
     $ris = 0;
     if ($player->getGamemode() != 1) {
         for ($i = 0; $i <= $player->getInventory()->getSize(); ++$i) {
             $inv = $player->getInventory()->getItem($i);
             if ($inv->getID() == $item->getID() && $inv->getDamage() == $item->getDamage()) {
                 $ris = $ris + $inv->getCount();
             }
         }
     }
     if ($ris >= $item->getCount()) {
         return true;
     }
     return false;
 }
Example #13
0
 public final function equals(Item $item, $checkDamage = false)
 {
     return $this->id === $item->getID() and ($checkDamage === false or $this->getDamage() === $item->getDamage());
 }
Example #14
0
 /**
  * @param Vector3 $source
  * @param Item    $item
  * @param Vector3 $motion
  */
 public function dropItem(Vector3 $source, Item $item, Vector3 $motion = null, $delay = 10)
 {
     $motion = $motion === null ? new Vector3(lcg_value() * 0.2 - 0.1, 0.2, lcg_value() * 0.2 - 0.1) : $motion;
     if ($item->getID() !== Item::AIR and $item->getCount() > 0) {
         $itemEntity = new DroppedItem($this->getChunkAt($source->getX() >> 4, $source->getZ() >> 4), new Compound("", ["Pos" => new Enum("Pos", [new Double("", $source->getX()), new Double("", $source->getY()), new Double("", $source->getZ())]), "Motion" => new Enum("Motion", [new Double("", $motion->x), new Double("", $motion->y), new Double("", $motion->z)]), "Rotation" => new Enum("Rotation", [new Float("", lcg_value() * 360), new Float("", 0)]), "Health" => new Short("Health", 5), "Item" => new Compound("Item", ["id" => new Short("id", $item->getID()), "Damage" => new Short("Damage", $item->getDamage()), "Count" => new Byte("Count", $item->getCount())]), "PickupDelay" => new Short("PickupDelay", $delay)]));
         $itemEntity->spawnToAll();
     }
 }
Example #15
0
 private function W_replace($selection, Item $block1, $blocks2)
 {
     if (!is_array($selection) or $selection[0] === false or $selection[1] === false or $selection[0][3] !== $selection[1][3]) {
         return "Make a selection first.";
     }
     $totalCount = $this->countBlocks($selection);
     if ($totalCount > 524288) {
         $send = false;
     } else {
         $send = true;
     }
     $level = $this->getServer()->getLevelByName($selection[0][3]);
     $id1 = $block1->getID();
     $meta1 = $block1->getDamage();
     $bcnt2 = count($blocks2) - 1;
     if ($bcnt2 < 0) {
         return "Incorrect blocks.";
     }
     $startX = min($selection[0][0], $selection[1][0]);
     $endX = max($selection[0][0], $selection[1][0]);
     $startY = min($selection[0][1], $selection[1][1]);
     $endY = max($selection[0][1], $selection[1][1]);
     $startZ = min($selection[0][2], $selection[1][2]);
     $endZ = max($selection[0][2], $selection[1][2]);
     $count = 0;
     for ($x = $startX; $x <= $endX; ++$x) {
         for ($y = $startY; $y <= $endY; ++$y) {
             for ($z = $startZ; $z <= $endZ; ++$z) {
                 $b = $level->getBlock(new Vector3($x, $y, $z));
                 if ($b->getID() === $id1 and ($meta1 === false or $b->getDamage() === $meta1)) {
                     $count += (int) $level->setBlock($b, $blocks2[mt_rand(0, $bcnt2)]->getBlock(), false, $send);
                 }
                 unset($b);
             }
         }
     }
     if ($send === false) {
         $forceSend = function ($X, $Y, $Z) {
             $this->changedCount[$X . ":" . $Y . ":" . $Z] = 4096;
         };
         $forceSend->bindTo($level, $level);
         for ($X = $startX >> 4; $X <= $endX >> 4; ++$X) {
             for ($Y = $startY >> 4; $Y <= $endY >> 4; ++$Y) {
                 for ($Z = $startZ >> 4; $Z <= $endZ >> 4; ++$Z) {
                     $forceSend($X, $Y, $Z);
                 }
             }
         }
     }
     return "{$count} block(s) have been changed.";
 }
Example #16
0
 protected function getCreativeBlock(Item $item)
 {
     foreach (Block::$creative as $i => $d) {
         if ($d[0] === $item->getID() and $d[1] === $item->getDamage()) {
             return $i;
         }
     }
     return -1;
 }
Example #17
0
 public function __construct(Player $player, Vector3 $bait, Item $item)
 {
     parent::__construct($player->getLevel()->getChunk($player->x >> 4, $player->z >> 4), new Compound("", ["Pos" => new Enum("Pos", [new Double("", $bait->x), new Double("", $bait->y), new Double("", $bait->z)]), "Motion" => new Enum("Motion", [new Double("", 0), new Double("", 0), new Double("", 0)]), "Rotation" => new Enum("Rotation", [new Float("", 0), new Float("", 0)])]));
     $this->item = $item->getID() == 0 ? Item::get(1000, 0, 0) : $item;
     $this->player = $player;
     parent::spawnToAll();
 }
Example #18
0
 protected function putSlot(Item $item)
 {
     if ($item->getID() === 0) {
         $this->putShort(-1);
     } else {
         $this->putShort($item->getID());
         $this->putByte($item->getCount());
         $this->putShort($item->getDamage());
         $this->putShort(-1);
     }
 }
Example #19
0
 /**
  * @param Item $input
  *
  * @return FurnaceRecipe
  */
 public function matchFurnaceRecipe(Item $input)
 {
     if (isset($this->furnaceRecipes[$input->getID() . ":" . $input->getDamage()])) {
         return $this->furnaceRecipes[$input->getID() . ":" . $input->getDamage()];
     } elseif (isset($this->furnaceRecipes[$input->getID() . ":?"])) {
         return $this->furnaceRecipes[$input->getID() . ":?"];
     }
     return null;
 }