/** Drop each item in my inventory and hotbar. */
 public void dropInventory() {
   for (int i = currentInventory.getStartIndexMainInventory();
       i < currentInventory.getStartIndexMainInventory() + 36;
       i++) {
     dropItemAt(i);
   }
 }
 public void shiftClick(short slot) {
   Slot slotData = currentInventory.getSlot(slot);
   if (slotData != null) {
     System.out.println("SHIFT CLICK");
     out0EClickWindow.sendMessage(
         currentInventory.getWindowId(), slot, (byte) 1, (byte) 1, slotData);
   }
 }
  public void takeCraftingResult(Id id, int craftedCount) throws MinecraftException {
    // TODO: check curr. inventory type

    currentInventory.setSlot((byte) 0, (byte) 0, id.getValue(), (byte) 0, (byte) craftedCount);
    Id idResult = currentInventory.getSlot((short) 0).getId();
    short availableIndex = getFirstEmptyIndex();
    moveItem((short) 0, availableIndex, craftedCount);
  }
 public void dropItemAt(int index) {
   Slot slot = currentInventory.getSlot((short) index);
   if (slot != null) {
     out0EClickWindow.sendMessageForceEmpty(
         currentInventory.getWindowId(), (short) index, (byte) 1, (byte) 4);
     currentInventory.setSlotEmpty(index);
   }
 }
 public boolean isMyInventoryEmpty() {
   for (int i = currentInventory.getStartIndexMainInventory();
       i < currentInventory.getStartIndexMainInventory() + 36;
       i++) {
     if (currentInventory.getSlot((short) i) != null) return false;
   }
   return true;
 }
 /**
  * @return first empty index in personal inventory (main inventory and hotbar)
  * @throws MinecraftException if inventory is empty
  */
 public short getFirstNotEmptyIndex() throws MinecraftException {
   for (short i = 0; i < mainInventoryItems.length; i++) {
     if (mainInventoryItems[i] != null)
       return (short) (i + currentInventory.getStartIndexMainInventory());
   }
   for (short i = 0; i < hotbarItems.length; i++) {
     if (hotbarItems[i] != null) return (short) (i + currentInventory.getStartIndexHotbar());
   }
   throw new MinecraftException(ErrorMessage.M08);
 }
 public boolean getItemFromChest(Id id) throws MinecraftException {
   if (id.getByteValue() == Id.NONE.getByteValue()) return true;
   if (!currentInventory.getClass().equals(ChestHandler.class)) {
     System.out.println("CHEST NOT OPEN");
     return false;
   } else {
     System.out.println("CHEST OPEN");
   }
   if (!isItemInChest(id)) throw new MinecraftException(ErrorMessage.M03);
   short itemIndex = currentInventory.getIndex(id);
   short emptyIndex = getFirstEmptyIndex();
   moveItem(itemIndex, emptyIndex, 1);
   return true;
 }
 public void rightClickWindow(short slot) {
   Slot slotData = currentInventory.getSlot(slot);
   // System.out.println("WINID: " + currentInventory.getWindowId() + " SLOTDATA: ID: " +
   // slotData.getId());
   if (slotData != null) {
     System.out.println("NOT EMPTY RIGHT CLICK");
     out0EClickWindow.sendMessage(
         currentInventory.getWindowId(), slot, (byte) 1, (byte) 0, slotData);
   } else {
     System.out.println("EMPTY RIGHT CLICK");
     out0EClickWindow.sendMessageForceEmpty(
         currentInventory.getWindowId(), slot, (byte) 1, (byte) 0);
   }
   // in32ConfirmTransaction.newClick(new Out0EClickWindowInfo(currentInventory.getWindowId(),
   // slot, slotData, out0EClickWindow.getActionNumber()));
 }
 private void leftClickWindowForceEmpty(short slot) {
   System.out.println("FORCED EMPTY LEFT CLICK");
   // Slot slotData = currentInventory.getSlot(slot);
   // System.out.println("WINID: " + currentInventory.getWindowId() + " SLOTDATA: ID: " +
   // slotData.getId());
   out0EClickWindow.sendMessageForceEmpty(
       currentInventory.getWindowId(), slot, (byte) 0, (byte) 0);
   // in32ConfirmTransaction.newClick(new Out0EClickWindowInfo(currentInventory.getWindowId(),
   // slot, slotData, out0EClickWindow.getActionNumber()));
 }
 public boolean storeItemToWorkbench(int index, Id id) {
   if (id.getByteValue() == Id.NONE.getByteValue()) return true;
   if (!currentInventory.getClass().equals(WorkbenchHandler.class)) {
     System.out.println("WB NOT OPEN");
     return false;
   } else {
     System.out.println("WB OPEN");
   }
   int itemIndex = ((WorkbenchHandler) currentInventory).getMyInventoryIndex(id);
   moveItem((short) itemIndex, (short) (index + 1), 1);
   return true;
 }
 public boolean storeItemToChest(Id id, int count) {
   if (id.getByteValue() == Id.NONE.getByteValue()) return true;
   if (!currentInventory.getClass().equals(ChestHandler.class)) {
     System.out.println("Chest NOT OPEN");
     return false;
   } else {
     System.out.println("Chest OPEN");
   }
   int itemIndex = ((ChestHandler) currentInventory).getMyInventoryIndex(id);
   short chestAvailableIndex = ((ChestHandler) currentInventory).getFirstEmptyIndex(id, count);
   moveItem((short) itemIndex, chestAvailableIndex, count);
   return true;
 }
Exemple #12
0
  /**
   * Takes planned block and puts it in the world.
   *
   * @param plan Planned block
   */
  private void putBlock(BlockPlan plan) {
    inventoryStorage.toBuild(plan);
    Util.logger.log(LogElement.Building, LogLevel.Debug, "Putting block");
    move.lookAt(new Location(plan.x, plan.y, plan.z));
    waitForConfirmation = 0;
    try {
      out.write(10);
      out.writeInt(info.getId());
      out.write(1);
      out.closePacket();

      blockPlacementPacket.sendMessage(
          plan.x, (byte) (plan.y - 1), plan.z, (byte) 1, (byte) 1, (byte) 1, (byte) 1);
    } catch (IOException ex) {
      System.out.println("IO Error while placing a block.");
      System.exit(0);
    }
  }
  public void moveItem(short startIndex, short endIndex, int count) {
    System.out.println("MOVING ITEM, start index: " + startIndex + " endIndex: " + endIndex);
    Slot oldStartIndexSlot = currentInventory.getSlot(startIndex);
    Slot oldEndIndexSlot = currentInventory.getSlot(endIndex);

    leftClickWindow(startIndex);
    for (int i = 0; i < count; i++) {
      rightClickWindow(endIndex);
      Slot slotEndIndex = currentInventory.getSlot(endIndex);
      if (slotEndIndex == null) {
        currentInventory.setSlot(
            (byte) 0, (byte) endIndex, oldStartIndexSlot.getId().getValue(), (byte) 0, (byte) 1);
      } else {
        currentInventory.getSlot(endIndex).incCountBy(1);
      }
    }
    leftClickWindowForceEmpty(startIndex);

    if (currentInventory.getSlot(startIndex).getCount() - count > 0)
      currentInventory.getSlot(startIndex).decCountBy(count);
    else currentInventory.setSlotEmpty(startIndex);

    //        if (oldStartIndexSlot != null) {
    //            Slot newStartIndexSlot = new Slot(startIndex,
    // oldStartIndexSlot.getId().getValue(), (byte)oldStartIndexSlot.getCount());
    //            refreshSlotInMyInventory(startIndex, newStartIndexSlot);
    //        }
    //        if(oldEndIndexSlot != null) {
    //            Slot newEndIndexSlot = new Slot(endIndex, oldEndIndexSlot.getId().getValue(),
    // (byte)(oldEndIndexSlot.getCount() + 1));
    //            refreshSlotInMyInventory(endIndex, newEndIndexSlot);
    //        } else {
    //            Slot newEndIndexSlot = new Slot(endIndex, oldStartIndexSlot.getId().getValue(),
    // (byte)1);
    //            refreshSlotInMyInventory(endIndex, newEndIndexSlot);
    //        }

  }
 public void refreshSlotInMyInventory(int index, Slot slotData) {
   int myIndex = index - currentInventory.getStartIndexMainInventory();
   if (myIndex > -1 && myIndex < 27) {
     System.out.println(
         "REFRESH INDEX MAIN INVENTORY: "
             + (index - currentInventory.getStartIndexMainInventory()));
     mainInventoryItems[index - currentInventory.getStartIndexMainInventory()] = slotData;
   } else {
     myIndex = index - currentInventory.getStartIndexHotbar();
     if (myIndex > -1 && myIndex < 9) {
       System.out.println(
           "REFRESH INDEX HOTBAR: " + (index - currentInventory.getStartIndexHotbar()));
       hotbarItems[index - currentInventory.getStartIndexHotbar()] = slotData;
     }
   }
 }
 private void endLeftMouseDrag() {
   System.out.println("END LEFT MOUSE DRAG");
   out0EClickWindow.sendMessageForceEmpty(
       currentInventory.getWindowId(), (short) -999, (byte) 2, (byte) 5);
 }
 public boolean isItemInChest(Id id) throws MinecraftException {
   System.out.println(currentInventory.getClass() + "    " + ChestHandler.class);
   if (!currentInventory.getClass().equals(ChestHandler.class))
     throw new MinecraftException(ErrorMessage.M02);
   return ((ChestHandler) currentInventory).isItemInChest(id);
 }
 public void closeCurrentInventory() {
   if (currentInventory != null) {
     out0DCloseWindow.sendMessage(currentInventory.getWindowId());
     currentInventory = null;
   }
 }