Package org.spout.vanilla.inventory.entity

Examples of org.spout.vanilla.inventory.entity.QuickbarInventory


      return;
    }
    switch (VanillaPlugin.getInstance().getEngine().getPlatform()) {
      case PROXY:
      case SERVER:
        QuickbarInventory quickbar = getPlayerInventory().getQuickbar();
        //debug("[Window - " + title + "] Slot changed: " + slot + " = " + item);
        //callProtocolEvent(new WindowSlotEvent(this, inventory, slots.revert(slot), item));
        reload();
        // Update the held item
        if (inventory instanceof QuickbarInventory && slot == quickbar.getSelectedSlot().getIndex()) {
          ((QuickbarInventory) inventory).updateHeldItem(getPlayer());
        }
        break;
      case CLIENT:
        slots.getWidgets()[slot].update();
View Full Code Here


    if (event instanceof PlayerInteractEntityEvent) {
      final PlayerInteractEntityEvent pie = (PlayerInteractEntityEvent) event;
      final Player player = (Player) pie.getEntity();
      switch (pie.getAction()) {
        case RIGHT_CLICK:
          final QuickbarInventory playerQuickbar = PlayerUtil.getQuickbar(player);
          if (playerQuickbar == null) {
            return;
          }
          final Slot selected = playerQuickbar.getSelectedSlot();
          if (selected.get() != null && selected.get().equalsIgnoreSize(new ItemStack(VanillaMaterials.BUCKET, 0))) {
            selected.addAmount(-1);
            playerQuickbar.add(new ItemStack(VanillaMaterials.MILK_BUCKET, 1));
          }
      }
    }
  }
View Full Code Here

   *
   * @param entity to get the current slot of
   * @return Current slot
   */
  public static Slot getHeldSlot(Entity entity) {
    QuickbarInventory bar = getQuickbar(entity);
    return bar == null ? null : bar.getSelectedSlot();
  }
View Full Code Here

    String name = command.getName();
    if (name.startsWith("quickbar_")) {
      Player player = (Player) source;
      PlayerInventory inventory = player.get(PlayerInventory.class);
      if (inventory != null) {
        QuickbarInventory quickbar = inventory.getQuickbar();
        HUD hud = player.get(HUD.class);
        int newSlot = quickbar.getSelectedSlot().getIndex();
        if (name.endsWith("left")) {
          newSlot++;
          if (newSlot > 8) {
            newSlot = 0;
          }
        } else if (name.endsWith("right")) {
          newSlot--;
          if (newSlot < 0) {
            newSlot = 8;
          }
        } else {
          newSlot = Integer.parseInt(name.substring(name.indexOf('_') + 1)) - 1;
        }

        quickbar.setSelectedSlot(newSlot);
        hud.getQuickbar().update();
      }
    }
  }
View Full Code Here

    }

    // From chest to inventory/quickbar
    if (from instanceof DropperInventory) {
      // To quickbar (reversed)
      final QuickbarInventory qbar = inventory.getQuickbar();
      qbar.add(qbar.size() - 1, 0, stack);
      from.set(slot, stack);
      if (stack.isEmpty()) {
        return true;
      }
View Full Code Here

    }

    // From chest to inventory/quickbar
    if (from instanceof DispenserInventory) {
      // To quickbar (reversed)
      final QuickbarInventory qbar = inventory.getQuickbar();
      qbar.add(qbar.size() - 1, 0, stack);
      from.set(slot, stack);
      if (stack.isEmpty()) {
        return true;
      }
View Full Code Here

    }

    // From chest to inventory/quickbar
    if (from instanceof ChestInventory) {
      // To quickbar (reversed)
      final QuickbarInventory qbar = inventory.getQuickbar();
      qbar.add(qbar.size() - 1, 0, stack);
      from.set(slot, stack);
      if (stack.isEmpty()) {
        return true;
      }
View Full Code Here

    final int newSlot = message.getSlot();
    if (newSlot < 0 || newSlot > 8) {
      return;
    }
    Player player = session.getPlayer();
    QuickbarInventory quickbar = PlayerUtil.getQuickbar(session.getPlayer());
    if (quickbar == null) {
      return;
    }
    PlayerHeldItemChangeEvent event = new PlayerHeldItemChangeEvent(player, quickbar.getSelectedSlot().getIndex(), newSlot);
    if (player.getEngine().getEventManager().callEvent(event).isCancelled()) {
      // Reset
      player.getNetwork().callProtocolEvent(new PlayerSelectedSlotChangeEvent(session.getPlayer(), event.getPreviousSlot()), player);
    } else {
      quickbar.setSelectedSlot(event.getNewSlot());
      quickbar.updateHeldItem(player);
      // Changed slot by event handler
      if (newSlot != event.getNewSlot()) {
        player.getNetwork().callProtocolEvent(new PlayerSelectedSlotChangeEvent(session.getPlayer(), event.getNewSlot()), player);
      }
    }
View Full Code Here

    }
  }

  @Override
  public void handleClient(ClientSession session, PlayerHeldItemChangeMessage message) {
    QuickbarInventory quickbar = PlayerUtil.getQuickbar(session.getPlayer());
    if (quickbar == null) {
      return;
    }
    quickbar.setSelectedSlot(message.getSlot());
  }
View Full Code Here

  public void update() {
    PlayerInventory inventory = hud.getOwner().get(PlayerInventory.class);
    if (inventory == null) {
      return;
    }
    QuickbarInventory quickbar = inventory.getQuickbar();
    if (quickbar == null) {
      return;
    }
    int slot = quickbar.getSelectedSlot().getIndex();

    if (slot < 0 || slot > 8) {
      throw new IllegalArgumentException("Slot must be between 0 and 8");
    }
View Full Code Here

TOP

Related Classes of org.spout.vanilla.inventory.entity.QuickbarInventory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.