addWindow() public méthode

Returns the created/existing window id
public addWindow ( pocketmine\inventory\Inventory $inventory, integer $forceId = null ) : integer
$inventory pocketmine\inventory\Inventory
$forceId integer
Résultat integer
Exemple #1
1
 public function onActivate(Item $item, Player $player = null)
 {
     if (!$this->getLevel()->getServer()->enchantingTableEnabled) {
         return true;
     }
     if ($player instanceof Player) {
         if ($player->isCreative() and $player->getServer()->limitedCreative) {
             return true;
         }
         $tile = $this->getLevel()->getTile($this);
         $enchantTable = null;
         if ($tile instanceof EnchantTable) {
             $enchantTable = $tile;
         } else {
             $this->getLevel()->setBlock($this, $this, true, true);
             $nbt = new CompoundTag("", [new StringTag("id", Tile::ENCHANT_TABLE), new IntTag("x", $this->x), new IntTag("y", $this->y), new IntTag("z", $this->z)]);
             if ($item->hasCustomName()) {
                 $nbt->CustomName = new StringTag("CustomName", $item->getCustomName());
             }
             if ($item->hasCustomBlockData()) {
                 foreach ($item->getCustomBlockData() as $key => $v) {
                     $nbt->{$key} = $v;
                 }
             }
             /** @var EnchantTable $enchantTable */
             $enchantTable = Tile::createTile(Tile::ENCHANT_TABLE, $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt);
         }
         $player->addWindow(new EnchantInventory($this));
         $player->craftingType = Player::CRAFTING_ENCHANT;
     }
     return true;
 }
Exemple #2
1
 public function onActivate(Item $item, Player $player = null)
 {
     if ($player instanceof Player) {
         $t = $this->getLevel()->getTile($this);
         $dispenser = null;
         if ($t instanceof TileDispenser) {
             $dispenser = $t;
         } else {
             $nbt = new CompoundTag("", [new ListTag("Items", []), new StringTag("id", Tile::DISPENSER), new IntTag("x", $this->x), new IntTag("y", $this->y), new IntTag("z", $this->z)]);
             $nbt->Items->setTagType(NBT::TAG_Compound);
             $dispenser = Tile::createTile(Tile::DISPENSER, $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt);
         }
         if ($player->isCreative() and $player->getServer()->limitedCreative) {
             return true;
         }
         $player->addWindow($dispenser->getInventory());
     }
     return true;
 }
Exemple #3
1
 public function openShop(Player $player)
 {
     $chestBlock = new \pocketmine\block\Chest();
     $player->getLevel()->setBlock(new Vector3($player->getX(), $player->getY() - 4, $player->getZ()), $chestBlock, true, true);
     $nbt = new CompoundTag("", [new ListTag("Items", []), new StringTag("id", Tile::CHEST), new IntTag("x", $player->getX()), new IntTag("y", $player->getY() - 4), new IntTag("z", $player->getZ())]);
     $nbt->Items->setTagType(NBT::TAG_Compound);
     $tile = Tile::createTile("Chest", $player->getLevel()->getChunk($player->getX() >> 4, $player->getZ() >> 4), $nbt);
     if ($tile instanceof Chest) {
         $config = new Config($this->getDataFolder() . "shop.yml", Config::YAML);
         $all = $config->get("Shop");
         $tile->getInventory()->clearAll();
         for ($i = 0; $i < count($all); $i += 2) {
             $slot = $i / 2;
             $tile->getInventory()->setItem($slot, Item::get($all[$i], 0, 1));
         }
         $tile->getInventory()->setItem($tile->getInventory()->getSize() - 1, Item::get(Item::WOOL, 14, 1));
         $player->addWindow($tile->getInventory());
     }
 }
Exemple #4
1
 public function onActivate(Item $item, Player $player = null)
 {
     if ($player instanceof Player) {
         $t = $this->getLevel()->getTile($this);
         if ($t instanceof FurnaceTile) {
             $furnace = $t;
         } else {
             $nbt = new CompoundTag("", [new ListTag("Items", []), new StringTag("id", Tile::FURNACE), new IntTag("x", $this->x), new IntTag("y", $this->y), new IntTag("z", $this->z)]);
             $nbt->Items->setTagType(NBT::TAG_Compound);
             $furnace = Tile::createTile("Furnace", $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt);
         }
         if (isset($furnace->namedtag->Lock) and $furnace->namedtag->Lock instanceof StringTag) {
             if ($furnace->namedtag->Lock->getValue() !== $item->getCustomName()) {
                 return true;
             }
         }
         if ($player->isCreative() and $player->getServer()->limitedCreative) {
             return true;
         }
         $player->addWindow($furnace->getInventory());
     }
     return true;
 }
 public function onActivate(Item $item, Player $player = null)
 {
     if ($player instanceof Player) {
         $top = $this->getSide(1);
         if ($top->isTransparent() !== true) {
             return true;
         }
         $this->BroadcastRedstoneUpdate(Level::REDSTONE_UPDATE_PLACE, Block::REDSTONESOURCEPOWER);
         $this->getLevel()->scheduleUpdate($this, 2);
         $t = $this->getLevel()->getTile($this);
         $chest = null;
         if ($t instanceof TileChest) {
             $chest = $t;
         } else {
             $nbt = new CompoundTag("", [new ListTag("Items", []), new StringTag("id", Tile::CHEST), new IntTag("x", $this->x), new IntTag("y", $this->y), new IntTag("z", $this->z)]);
             $nbt->Items->setTagType(NBT::TAG_Compound);
             $chest = Tile::createTile("Chest", $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt);
         }
         if (isset($chest->namedtag->Lock) and $chest->namedtag->Lock instanceof StringTag) {
             if ($chest->namedtag->Lock->getValue() !== $item->getCustomName()) {
                 return true;
             }
         }
         $player->addWindow($chest->getInventory());
     }
     return true;
 }
Exemple #6
1
 public function onActivate(Item $item, Player $player = null)
 {
     if ($player instanceof Player) {
         $top = $this->getSide(1);
         if ($top->isTransparent() !== true) {
             return true;
         }
         $t = $this->getLevel()->getTile($this);
         $chest = null;
         if ($t instanceof TileChest) {
             $chest = $t;
         } else {
             $nbt = new CompoundTag("", [new EnumTag("Items", []), new StringTag("id", Tile::CHEST), new IntTag("x", $this->x), new IntTag("y", $this->y), new IntTag("z", $this->z)]);
             $nbt->Items->setTagType(NBT::TAG_Compound);
             $chest = Tile::createTile("Chest", $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt);
         }
         if (isset($chest->namedtag->Lock) and $chest->namedtag->Lock instanceof StringTag) {
             if ($chest->namedtag->Lock->getValue() !== $item->getCustomName()) {
                 return true;
             }
         }
         if ($player->isCreative() and $player->getServer()->limitedCreative) {
             return true;
         }
         $player->addWindow($chest->getInventory());
     }
     return true;
 }
Exemple #7
0
 public function onActivate(Item $item, Player $player = null)
 {
     if ($player instanceof Player) {
         $player->addWindow(new AnvilInventory($this));
     }
     return true;
 }
 public function onActivate(Item $item, Player $player = null)
 {
     if ($player instanceof Player) {
         //TODO lock
         $player->addWindow(new EnchantInventory($this));
     }
     return true;
 }
Exemple #9
0
 public function onActivate(Item $item, Player $player = null)
 {
     if ($player instanceof Player) {
         $player->addWindow(new AnvilInventory($this));
         $player->craftingType = Player::CRAFTING_ANVIL;
     }
     return true;
 }
Exemple #10
0
 public function onActivate(Item $item, Player $player = null)
 {
     if ($player instanceof Player) {
         if ($player->isCreative()) {
             return true;
         }
         $player->addWindow(new BrewingInventory($this));
     }
     return true;
 }
 public function onActivate(Item $item, Player $player = null)
 {
     if ($player instanceof Player) {
         //TODO lock
         if ($player->isCreative()) {
             return true;
         }
         if (($t = $this->getLevel()->getTile($this)) instanceof TileBrewingStand) {
             $player->addWindow(new BrewingInventory($t));
         }
     }
     return true;
 }
Exemple #12
0
 public function onActivate(Item $item, Player $player = null)
 {
     if (!$this->getLevel()->getServer()->anviletEnabled) {
         return true;
     }
     if ($player instanceof Player) {
         if ($player->isCreative()) {
             return true;
         }
         $player->addWindow(new AnvilInventory($this));
     }
     return true;
 }
Exemple #13
0
 public function onActivate(Item $item, Player $player = null)
 {
     if ($player instanceof Player) {
         $t = $this->getLevel()->getTile($this);
         if ($t instanceof TileHopper) {
             if ($t->hasLock() and !$t->checkLock($item->getCustomName())) {
                 $player->getServer()->getLogger()->debug($player->getName() . " attempted to open a locked hopper");
                 return true;
             }
             $player->addWindow($t->getInventory());
         }
     }
     return true;
 }
Exemple #14
0
 public function onActivate(Item $item, Player $player = null)
 {
     if (!$this->getLevel()->getServer()->anvilEnabled) {
         return true;
     }
     if ($player instanceof Player) {
         if ($player->isCreative() and $player->getServer()->limitedCreative) {
             return true;
         }
         $player->addWindow(new AnvilInventory($this));
         $player->craftingType = Player::CRAFTING_ANVIL;
     }
     return true;
 }
 public function onActivate(Item $item, Player $player = null)
 {
     if ($player instanceof Player) {
         //TODO lock
         $t = $this->getLevel()->getTile($this);
         //$brewingStand = false;
         if ($t instanceof TileBrewingStand) {
             $brewingStand = $t;
         } else {
             $nbt = new CompoundTag("", [new ListTag("Items", []), new StringTag("id", Tile::BREWING_STAND), new IntTag("x", $this->x), new IntTag("y", $this->y), new IntTag("z", $this->z)]);
             $nbt->Items->setTagType(NBT::TAG_Compound);
             $brewingStand = Tile::createTile(Tile::BREWING_STAND, $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt);
         }
         $player->addWindow($brewingStand->getInventory());
     }
     return true;
 }
 public function onActivate(Item $item, Player $player = null)
 {
     if ($player instanceof Player) {
         $t = $this->getLevel()->getTile($this);
         $furnace = false;
         if ($t instanceof Furnace) {
             $furnace = $t;
         } else {
             $nbt = new Compound("", [new Enum("Items", []), new String("id", Tile::FURNACE), new Int("x", $this->x), new Int("y", $this->y), new Int("z", $this->z)]);
             $nbt->Items->setTagType(NBT::TAG_Compound);
             $furnace = Tile::createTile("Furnace", $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt);
         }
         if ($player->isCreative()) {
             return true;
         }
         $player->addWindow($furnace->getInventory());
     }
     return true;
 }
Exemple #17
0
 public function onActivate(Item $item, Player $player = null)
 {
     if ($player instanceof Player) {
         $t = $this->getLevel()->getTile($this);
         $hopper = null;
         if ($t instanceof HopperTile) {
             $hopper = $t;
         } else {
             $nbt = new CompoundTag("", [new ListTag("Items", []), new StringTag("id", Tile::HOPPER), new IntTag("x", $this->x), new IntTag("y", $this->y), new IntTag("z", $this->z)]);
             $nbt->Items->setTagType(NBT::TAG_Compound);
             $hopper = Tile::createTile(Tile::HOPPER, $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt);
         }
         if (isset($hopper->namedtag->Lock) and $hopper->namedtag->Lock instanceof StringTag) {
             if ($hopper->namedtag->Lock->getValue() !== $item->getCustomName()) {
                 return true;
             }
         }
         $player->addWindow($hopper->getInventory());
     }
     return true;
 }
Exemple #18
0
 public function onActivate(Item $item, Player $player = null)
 {
     if ($player instanceof Player) {
         $top = $this->getSide(1);
         if ($top->isTransparent() !== true) {
             return true;
         }
         $t = $this->getLevel()->getTile($this);
         $chest = null;
         if ($t instanceof TileChest) {
             $chest = $t;
         } else {
             $nbt = new Compound(false, [new Enum("Items", []), new String("id", Tile::CHEST), new Int("x", $this->x), new Int("y", $this->y), new Int("z", $this->z)]);
             $nbt->Items->setTagType(NBT::TAG_Compound);
             $chest = Tile::createTile("Chest", $this->getLevel()->getChunk($this->x >> 4, $this->z >> 4), $nbt);
         }
         if ($player->isCreative()) {
             return true;
         }
         $player->addWindow($chest->getInventory());
     }
     return true;
 }