Пример #1
0
 public function activate()
 {
     $itemIndex = [];
     for ($i = 0; $i < $this->getSize(); $i++) {
         $item = $this->getInventory()->getItem($i);
         if ($item->getId() != Item::AIR) {
             $itemIndex[] = [$i, $item];
         }
     }
     $max = count($itemIndex) - 1;
     if ($max < 0) {
         $itemArr = null;
     } elseif ($max == 0) {
         $itemArr = $itemIndex[0];
     } else {
         $itemArr = $itemIndex[mt_rand(0, $max)];
     }
     if (is_array($itemArr)) {
         /** @var Item $item */
         $item = $itemArr[1];
         $item->setCount($item->getCount() - 1);
         $this->getInventory()->setItem($itemArr[0], $item->getCount() > 0 ? $item : Item::get(Item::AIR));
         $motion = $this->getMotion();
         $needItem = Item::get($item->getId(), $item->getDamage());
         $block = $this->getLevel()->getBlock($this->add($motion[0], $motion[1], $motion[2]));
         switch ($block->getId()) {
             case Block::CHEST:
             case Block::TRAPPED_CHEST:
             case Block::DROPPER:
             case Block::DISPENSER:
             case Block::BREWING_STAND_BLOCK:
             case Block::FURNACE:
                 $t = $this->getLevel()->getTile($block);
                 /** @var Chest|Dispenser|Dropper|BrewingStand|Furnace $t */
                 if ($t instanceof Tile) {
                     if ($t->getInventory()->canAddItem($needItem)) {
                         $t->getInventory()->addItem($needItem);
                         return;
                     }
                 }
         }
         $itemTag = NBT::putItemHelper($needItem);
         $itemTag->setName("Item");
         $nbt = new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $this->x + $motion[0] * 2 + 0.5), new DoubleTag("", $this->y + ($motion[1] > 0 ? $motion[1] : 0.5)), new DoubleTag("", $this->z + $motion[2] * 2 + 0.5)]), "Motion" => new ListTag("Motion", [new DoubleTag("", $motion[0]), new DoubleTag("", $motion[1]), new DoubleTag("", $motion[2])]), "Rotation" => new ListTag("Rotation", [new FloatTag("", lcg_value() * 360), new FloatTag("", 0)]), "Health" => new ShortTag("Health", 5), "Item" => $itemTag, "PickupDelay" => new ShortTag("PickupDelay", 10)]);
         $f = 0.3;
         $itemEntity = new ItemEntity($this->chunk, $nbt, $this);
         $itemEntity->setMotion($itemEntity->getMotion()->multiply($f));
         $itemEntity->spawnToAll();
         for ($i = 1; $i < 10; $i++) {
             $this->getLevel()->addParticle(new SmokeParticle($this->add($motion[0] * $i * 0.3 + 0.5, $motion[1] == 0 ? 0.5 : $motion[1] * $i * 0.3, $motion[2] * $i * 0.3 + 0.5)));
         }
     }
 }
Пример #2
0
 public function activate()
 {
     $itemArr = [];
     for ($i = 0; $i < $this->getInventory()->getSize(); $i++) {
         $slot = $this->getInventory()->getItem($i);
         if ($slot instanceof Item && $slot->getId() != 0) {
             $itemArr[] = $slot;
         }
     }
     if (!empty($itemArr)) {
         /** @var Item $item */
         $itema = $itemArr[array_rand($itemArr)];
         $item = Item::get($itema->getId(), $itema->getDamage(), 1, $itema->getCompoundTag());
         $this->getInventory()->removeItem($item);
         $motion = $this->getMotion();
         $needItem = Item::get($item->getId(), $item->getDamage());
         $f = 1.5;
         if ($needItem instanceof Launchable) {
             $nbt = new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $this->x + $motion[0] * 2 + 0.5), new DoubleTag("", $this->y + ($motion[1] > 0 ? $motion[1] : 0.5)), new DoubleTag("", $this->z + $motion[2] * 2 + 0.5)]), "Motion" => new ListTag("Motion", [new DoubleTag("", $motion[0]), new DoubleTag("", $motion[1]), new DoubleTag("", $motion[2])]), "Rotation" => new ListTag("Rotation", [new FloatTag("", lcg_value() * 360), new FloatTag("", 0)])]);
             $thrownEntity = Entity::createEntity($needItem->getEntityName(), $this->chunk, $nbt);
             $thrownEntity->setMotion($thrownEntity->getMotion()->multiply($f));
             $thrownEntity->spawnToAll();
         } elseif ($needItem->getId() === Item::DYE && $needItem->getDamage() === Dye::BONEMEAL) {
             // Add instanceof Dispenseable + switch function
             $dispenseto = $this->getLevel()->getBlock($this->add($motion[0], $motion[1], $motion[2]));
             if ($dispenseto instanceof Crops) {
                 $needItem->useOn($dispenseto);
             }
         } elseif ($needItem->getId() === Item::FLINT_AND_STEEL) {
             // Add instanceof Dispenseable + switch function
             $dispenseto = $this->getLevel()->getBlock($this->add($motion[0], $motion[1], $motion[2]));
             $this->getLevel()->setBlock($dispenseto, new Fire());
             $damage = $item->getDamage();
             $item->setDamage($damage + 1);
         } else {
             $item = NBT::putItemHelper($needItem);
             $item->setName("Item");
             $nbt = new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $this->x + $motion[0] * 2 + 0.5), new DoubleTag("", $this->y + ($motion[1] > 0 ? $motion[1] : 0.5)), new DoubleTag("", $this->z + $motion[2] * 2 + 0.5)]), "Motion" => new ListTag("Motion", [new DoubleTag("", $motion[0]), new DoubleTag("", $motion[1]), new DoubleTag("", $motion[2])]), "Rotation" => new ListTag("Rotation", [new FloatTag("", lcg_value() * 360), new FloatTag("", 0)]), "Health" => new ShortTag("Health", 5), "Item" => $item, "PickupDelay" => new ShortTag("PickupDelay", 10)]);
             $f = 0.3;
             $itemEntity = new ItemEntity($this->chunk, $nbt, $this);
             $itemEntity->setMotion($itemEntity->getMotion()->multiply($f));
             $itemEntity->spawnToAll();
         }
         for ($i = 1; $i < 10; $i++) {
             $this->getLevel()->addParticle(new SmokeParticle($this->add($motion[0] * $i * 0.3 + 0.5, $motion[1] == 0 ? 0.5 : $motion[1] * $i * 0.3, $motion[2] * $i * 0.3 + 0.5)));
         }
     }
 }
Пример #3
0
 public function activate()
 {
     $itemIndex = [];
     for ($i = 0; $i < $this->getSize(); $i++) {
         $item = $this->getInventory()->getItem($i);
         if ($item->getId() != Item::AIR) {
             $itemIndex[] = [$i, $item];
         }
     }
     $max = count($itemIndex) - 1;
     if ($max < 0) {
         $itemArr = null;
     } elseif ($max == 0) {
         $itemArr = $itemIndex[0];
     } else {
         $itemArr = $itemIndex[mt_rand(0, $max)];
     }
     if (is_array($itemArr)) {
         /** @var Item $item */
         $item = $itemArr[1];
         $item->setCount($item->getCount() - 1);
         $this->getInventory()->setItem($itemArr[0], $item->getCount() > 0 ? $item : Item::get(Item::AIR));
         $motion = $this->getMotion();
         $needItem = Item::get($item->getId(), $item->getDamage());
         $f = 1.5;
         switch ($needItem->getId()) {
             case Item::ARROW:
                 $nbt = new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $this->x + $motion[0] * 2 + 0.5), new DoubleTag("", $this->y + ($motion[1] > 0 ? $motion[1] : 0.5)), new DoubleTag("", $this->z + $motion[2] * 2 + 0.5)]), "Motion" => new ListTag("Motion", [new DoubleTag("", $motion[0]), new DoubleTag("", $motion[1]), new DoubleTag("", $motion[2])]), "Rotation" => new ListTag("Rotation", [new FloatTag("", lcg_value() * 360), new FloatTag("", 0)]), "Fire" => new ShortTag("Fire", 0)]);
                 $arrow = Entity::createEntity("Arrow", $this->chunk, $nbt);
                 $arrow->setMotion($arrow->getMotion()->multiply($f));
                 $arrow->spawnToAll();
                 break;
             case Item::SNOWBALL:
                 $nbt = new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $this->x + $motion[0] * 2 + 0.5), new DoubleTag("", $this->y + ($motion[1] > 0 ? $motion[1] : 0.5)), new DoubleTag("", $this->z + $motion[2] * 2 + 0.5)]), "Motion" => new ListTag("Motion", [new DoubleTag("", $motion[0]), new DoubleTag("", $motion[1]), new DoubleTag("", $motion[2])]), "Rotation" => new ListTag("Rotation", [new FloatTag("", lcg_value() * 360), new FloatTag("", 0)])]);
                 $snowball = Entity::createEntity("Snowball", $this->chunk, $nbt);
                 $snowball->setMotion($snowball->getMotion()->multiply($f));
                 $snowball->spawnToAll();
                 break;
             case Item::EGG:
                 $nbt = new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $this->x + $motion[0] * 2 + 0.5), new DoubleTag("", $this->y + ($motion[1] > 0 ? $motion[1] : 0.5)), new DoubleTag("", $this->z + $motion[2] * 2 + 0.5)]), "Motion" => new ListTag("Motion", [new DoubleTag("", $motion[0]), new DoubleTag("", $motion[1]), new DoubleTag("", $motion[2])]), "Rotation" => new ListTag("Rotation", [new FloatTag("", lcg_value() * 360), new FloatTag("", 0)])]);
                 $egg = Entity::createEntity("Egg", $this->chunk, $nbt);
                 $egg->setMotion($egg->getMotion()->multiply($f));
                 $egg->spawnToAll();
                 break;
             case Item::SPLASH_POTION:
                 $nbt = new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $this->x + $motion[0] * 2 + 0.5), new DoubleTag("", $this->y + ($motion[1] > 0 ? $motion[1] : 0.5)), new DoubleTag("", $this->z + $motion[2] * 2 + 0.5)]), "Motion" => new ListTag("Motion", [new DoubleTag("", $motion[0]), new DoubleTag("", $motion[1]), new DoubleTag("", $motion[2])]), "Rotation" => new ListTag("Rotation", [new FloatTag("", lcg_value() * 360), new FloatTag("", 0)]), "PotionId" => new ShortTag("PotionId", $item->getDamage())]);
                 $thrownPotion = Entity::createEntity("ThrownPotion", $this->chunk, $nbt);
                 $thrownPotion->setMotion($thrownPotion->getMotion()->multiply($f));
                 $thrownPotion->spawnToAll();
                 break;
             case Item::ENCHANTING_BOTTLE:
                 $nbt = new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $this->x + $motion[0] * 2 + 0.5), new DoubleTag("", $this->y + ($motion[1] > 0 ? $motion[1] : 0.5)), new DoubleTag("", $this->z + $motion[2] * 2 + 0.5)]), "Motion" => new ListTag("Motion", [new DoubleTag("", $motion[0]), new DoubleTag("", $motion[1]), new DoubleTag("", $motion[2])]), "Rotation" => new ListTag("Rotation", [new FloatTag("", lcg_value() * 360), new FloatTag("", 0)])]);
                 $thrownExpBottle = Entity::createEntity("ThrownExpBottle", $this->chunk, $nbt);
                 $thrownExpBottle->setMotion($thrownExpBottle->getMotion()->multiply($f));
                 $thrownExpBottle->spawnToAll();
                 break;
             default:
                 $itemTag = NBT::putItemHelper($needItem);
                 $itemTag->setName("Item");
                 $nbt = new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $this->x + $motion[0] * 2 + 0.5), new DoubleTag("", $this->y + ($motion[1] > 0 ? $motion[1] : 0.5)), new DoubleTag("", $this->z + $motion[2] * 2 + 0.5)]), "Motion" => new ListTag("Motion", [new DoubleTag("", $motion[0]), new DoubleTag("", $motion[1]), new DoubleTag("", $motion[2])]), "Rotation" => new ListTag("Rotation", [new FloatTag("", lcg_value() * 360), new FloatTag("", 0)]), "Health" => new ShortTag("Health", 5), "Item" => $itemTag, "PickupDelay" => new ShortTag("PickupDelay", 10)]);
                 $f = 0.3;
                 $itemEntity = new ItemEntity($this->chunk, $nbt, $this);
                 $itemEntity->setMotion($itemEntity->getMotion()->multiply($f));
                 $itemEntity->spawnToAll();
                 break;
         }
         for ($i = 1; $i < 10; $i++) {
             $this->getLevel()->addParticle(new SmokeParticle($this->add($motion[0] * $i * 0.3 + 0.5, $motion[1] == 0 ? 0.5 : $motion[1] * $i * 0.3, $motion[2] * $i * 0.3 + 0.5)));
         }
     }
 }
Пример #4
0
 public function activate()
 {
     $itemArr = [];
     for ($i = 0; $i < $this->getInventory()->getSize(); $i++) {
         $slot = $this->getInventory()->getItem($i);
         if ($slot instanceof Item && $slot->getId() != 0) {
             $itemArr[] = $slot;
         }
     }
     if (!empty($itemArr)) {
         /** @var Item $item */
         $itema = $itemArr[array_rand($itemArr)];
         $item = Item::get($itema->getId(), $itema->getDamage(), 1, $itema->getCompoundTag());
         $this->getInventory()->removeItem($item);
         $motion = $this->getMotion();
         $needItem = Item::get($item->getId(), $item->getDamage());
         $item = NBT::putItemHelper($needItem);
         $item->setName("Item");
         $nbt = new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $this->x + $motion[0] * 2 + 0.5), new DoubleTag("", $this->y + ($motion[1] > 0 ? $motion[1] : 0.5)), new DoubleTag("", $this->z + $motion[2] * 2 + 0.5)]), "Motion" => new ListTag("Motion", [new DoubleTag("", $motion[0]), new DoubleTag("", $motion[1]), new DoubleTag("", $motion[2])]), "Rotation" => new ListTag("Rotation", [new FloatTag("", lcg_value() * 360), new FloatTag("", 0)]), "Health" => new ShortTag("Health", 5), "Item" => $item, "PickupDelay" => new ShortTag("PickupDelay", 10)]);
         $f = 0.3;
         $itemEntity = new ItemEntity($this->chunk, $nbt, $this);
         $itemEntity->setMotion($itemEntity->getMotion()->multiply($f));
         $itemEntity->spawnToAll();
     }
 }