@Override
  public boolean shouldDrawSlot(Slot slot) {
    if (slot.getSlotIndex() >= slotCount) {
      return false;
    }
    // all visible
    if (!slider.isEnabled()) {
      return true;
    }

    return firstSlotId <= slot.getSlotIndex() && lastSlotId > slot.getSlotIndex();
  }
Esempio n. 2
0
 private boolean shouldDrawLid(Slot slot) {
   InventoryCamera inv = container.inventory();
   return (inv.isLidClosed() || lidXSize != 0)
       && slot.inventory == inv
       && slot.getHasStack()
       && inv.storageSlot() == slot.getSlotIndex();
 }
  // updates slot visibility
  protected void updateSlots() {
    firstSlotId = slider.getValue() * columns;
    lastSlotId = Math.min(slotCount, firstSlotId + getDisplayedRows() * columns);

    int xd = border.w + xOffset;
    int yd = border.h + yOffset;

    if (shouldDrawName()) {
      yd += textBackground.h;
    }

    for (Object o : inventorySlots.inventorySlots) {
      Slot slot = (Slot) o;
      if (shouldDrawSlot(slot)) {
        // calc position of the slot
        int offset = slot.getSlotIndex() - firstSlotId;
        int x = (offset % columns) * this.slot.w;
        int y = (offset / columns) * this.slot.h;

        slot.xDisplayPosition = xd + x + 1;
        slot.yDisplayPosition = yd + y + 1;

        if (this.right) {
          slot.xDisplayPosition += parent.realWidth;
        } else {
          slot.xDisplayPosition -= this.xSize;
        }
      } else {
        slot.xDisplayPosition = 0;
        slot.yDisplayPosition = 0;
      }
    }
  }
  @Override
  protected boolean checkHotbarKeys(final int keyCode) {
    final Slot theSlot;

    try {
      theSlot =
          ObfuscationReflectionHelper.getPrivateValue(
              GuiContainer.class, this, "theSlot", "field_147006_u", "f");
    } catch (final Throwable t) {
      return false;
    }

    if (this.mc.thePlayer.inventory.getItemStack() == null && theSlot != null) {
      for (int j = 0; j < 9; ++j) {
        if (keyCode == this.mc.gameSettings.keyBindsHotbar[j].getKeyCode()) {
          final List<Slot> slots = this.getInventorySlots();
          for (final Slot s : slots) {
            if (s.getSlotIndex() == j
                && s.inventory == ((AEBaseContainer) this.inventorySlots).getPlayerInv()) {
              if (!s.canTakeStack(((AEBaseContainer) this.inventorySlots).getPlayerInv().player)) {
                return false;
              }
            }
          }

          if (theSlot.getSlotStackLimit() == 64) {
            this.handleMouseClick(theSlot, theSlot.slotNumber, j, 2);
            return true;
          } else {
            for (final Slot s : slots) {
              if (s.getSlotIndex() == j
                  && s.inventory == ((AEBaseContainer) this.inventorySlots).getPlayerInv()) {
                NetworkHandler.instance.sendToServer(
                    new PacketSwapSlots(s.slotNumber, theSlot.slotNumber));
                return true;
              }
            }
          }
        }
      }
    }

    return false;
  }
  @Override
  public boolean shouldDrawSlot(Slot slot) {
    // all visible
    if (!slider.isEnabled()) {
      return true;
    }

    int index = slot.getSlotIndex();

    return (firstSlotId <= index && lastSlotId > index); // inside visible area
    // || indexStart > index || indexEnd <= index; // or not our concern
  }
Esempio n. 6
0
  private SideData getFromSlot(Slot slot) {
    if (slot.slotNumber < tileEntity.getSizeInventory()) {
      IInvConfiguration config = (IInvConfiguration) tileEntity;

      for (SideData data : config.getSideData()) {
        for (int id : data.availableSlots) {
          if (id == slot.getSlotIndex()) {
            return data;
          }
        }
      }
    }

    return null;
  }
 @Override
 protected Slot addSlotToContainer(Slot slot) {
   if (player.worldObj.isRemote
       && CustomizeableGuiHandler.moveableInvElements != null
       && CustomizeableGuiHandler.moveableInvElements.size() > this.inventorySlots.size()) {
     GuiButtonMoveableElement bme =
         CustomizeableGuiHandler.moveableInvElements.get(this.inventorySlots.size());
     if (bme != null) {
       if (bme.hideElement) {
         IInventory iinv = slot.inventory;
         int indx = slot.getSlotIndex();
         int x = slot.xDisplayPosition;
         int y = slot.yDisplayPosition;
         slot = new SlotNull(iinv, indx, x, y);
       }
       slot.xDisplayPosition = bme.elementX + 1;
       slot.yDisplayPosition = bme.elementY + 1;
     }
   } else if (CommonProxy.hiddenSlots.containsKey(player.getCommandSenderName())) {
     boolean[] hidden = CommonProxy.hiddenSlots.get(player.getCommandSenderName());
     if (hidden != null
         && hidden.length > this.inventorySlots.size()
         && hidden[this.inventorySlots.size()]) {
       IInventory iinv = slot.inventory;
       int indx = slot.getSlotIndex();
       int x = slot.xDisplayPosition;
       int y = slot.yDisplayPosition;
       slot = new SlotNull(iinv, indx, x, y);
     }
   }
   // System.out.print(this.inventorySlots.size()+":"+(slot instanceof SlotNull)+", ");
   slot.slotNumber = this.inventorySlots.size();
   this.inventorySlots.add(slot);
   this.inventoryItemStacks.add((Object) null);
   return slot;
 }
  @Override
  public boolean isAvailable(final Slot slot) {
    if (entity.isAdminMode()) return true;

    final ItemStack[] inv = entity.getRawInventory();
    final ItemStack stack = inv[slot.getSlotIndex()];
    if (stack != null)
      return InventoryHelper.doesInventoryContain(
          inv,
          VendingTileEntity.INVENTORY_SLOT_START,
          VendingTileEntity.GENERAL_INVENTORY_SIZE - 1,
          stack,
          null);

    return true;
  }
  // updates slot visibility
  public void updateSlots() {
    // calculate displayed slots
    firstSlotId = slider.getValue() * columns;
    lastSlotId = Math.min(slotCount, firstSlotId + rows * columns);

    for (Slot slot : container.inventorySlots) {
      if (shouldDrawSlot(slot)) {
        // calc position of the slot
        int offset = slot.getSlotIndex() - firstSlotId;
        int x = (offset % columns) * GuiDynInventory.slot.w;
        int y = (offset / columns) * GuiDynInventory.slot.h;

        slot.xDisplayPosition = xOffset + x + 1;
        slot.yDisplayPosition = yOffset + y + 1;
      } else {
        slot.xDisplayPosition = 0;
        slot.yDisplayPosition = 0;
      }
    }
  }
  @Override
  protected void handleMouseClick(
      final Slot slot, final int slotIdx, final int ctrlDown, final int key) {
    final EntityPlayer player = Minecraft.getMinecraft().thePlayer;

    if (slot instanceof SlotFake) {
      final InventoryAction action =
          ctrlDown == 1
              ? InventoryAction.SPLIT_OR_PLACE_SINGLE
              : InventoryAction.PICKUP_OR_SET_DOWN;

      if (this.drag_click.size() > 1) {
        return;
      }

      final PacketInventoryAction p = new PacketInventoryAction(action, slotIdx, 0);
      NetworkHandler.instance.sendToServer(p);

      return;
    }

    if (slot instanceof SlotPatternTerm) {
      if (key == 6) {
        return; // prevent weird double clicks..
      }

      try {
        NetworkHandler.instance.sendToServer(((SlotPatternTerm) slot).getRequest(key == 1));
      } catch (final IOException e) {
        AELog.debug(e);
      }
    } else if (slot instanceof SlotCraftingTerm) {
      if (key == 6) {
        return; // prevent weird double clicks..
      }

      InventoryAction action = null;
      if (key == 1) {
        action = InventoryAction.CRAFT_SHIFT;
      } else {
        action = ctrlDown == 1 ? InventoryAction.CRAFT_STACK : InventoryAction.CRAFT_ITEM;
      }

      final PacketInventoryAction p = new PacketInventoryAction(action, slotIdx, 0);
      NetworkHandler.instance.sendToServer(p);

      return;
    }

    if (Keyboard.isKeyDown(Keyboard.KEY_SPACE)) {
      if (this.enableSpaceClicking()) {
        IAEItemStack stack = null;
        if (slot instanceof SlotME) {
          stack = ((SlotME) slot).getAEStack();
        }

        int slotNum = this.getInventorySlots().size();

        if (!(slot instanceof SlotME) && slot != null) {
          slotNum = slot.slotNumber;
        }

        ((AEBaseContainer) this.inventorySlots).setTargetStack(stack);
        final PacketInventoryAction p =
            new PacketInventoryAction(InventoryAction.MOVE_REGION, slotNum, 0);
        NetworkHandler.instance.sendToServer(p);
        return;
      }
    }

    if (slot instanceof SlotDisconnected) {
      InventoryAction action = null;

      switch (key) {
        case 0: // pickup / set-down.
          action =
              ctrlDown == 1
                  ? InventoryAction.SPLIT_OR_PLACE_SINGLE
                  : InventoryAction.PICKUP_OR_SET_DOWN;
          break;
        case 1:
          action = ctrlDown == 1 ? InventoryAction.PICKUP_SINGLE : InventoryAction.SHIFT_CLICK;
          break;

        case 3: // creative dupe:
          if (player.capabilities.isCreativeMode) {
            action = InventoryAction.CREATIVE_DUPLICATE;
          }

          break;

        default:
        case 4: // drop item:
        case 6:
      }

      if (action != null) {
        final PacketInventoryAction p =
            new PacketInventoryAction(
                action, slot.getSlotIndex(), ((SlotDisconnected) slot).getSlot().getId());
        NetworkHandler.instance.sendToServer(p);
      }

      return;
    }

    if (slot instanceof SlotME) {
      InventoryAction action = null;
      IAEItemStack stack = null;

      switch (key) {
        case 0: // pickup / set-down.
          action =
              ctrlDown == 1
                  ? InventoryAction.SPLIT_OR_PLACE_SINGLE
                  : InventoryAction.PICKUP_OR_SET_DOWN;
          stack = ((SlotME) slot).getAEStack();

          if (stack != null
              && action == InventoryAction.PICKUP_OR_SET_DOWN
              && stack.getStackSize() == 0
              && player.inventory.getItemStack() == null) {
            action = InventoryAction.AUTO_CRAFT;
          }

          break;
        case 1:
          action = ctrlDown == 1 ? InventoryAction.PICKUP_SINGLE : InventoryAction.SHIFT_CLICK;
          stack = ((SlotME) slot).getAEStack();
          break;

        case 3: // creative dupe:
          stack = ((SlotME) slot).getAEStack();
          if (stack != null && stack.isCraftable()) {
            action = InventoryAction.AUTO_CRAFT;
          } else if (player.capabilities.isCreativeMode) {
            final IAEItemStack slotItem = ((SlotME) slot).getAEStack();
            if (slotItem != null) {
              action = InventoryAction.CREATIVE_DUPLICATE;
            }
          }
          break;

        default:
        case 4: // drop item:
        case 6:
      }

      if (action != null) {
        ((AEBaseContainer) this.inventorySlots).setTargetStack(stack);
        final PacketInventoryAction p =
            new PacketInventoryAction(action, this.getInventorySlots().size(), 0);
        NetworkHandler.instance.sendToServer(p);
      }

      return;
    }

    if (!this.disableShiftClick && isShiftKeyDown()) {
      this.disableShiftClick = true;

      if (this.dbl_whichItem == null
          || this.bl_clicked != slot
          || this.dbl_clickTimer.elapsed(TimeUnit.MILLISECONDS) > 150) {
        // some simple double click logic.
        this.bl_clicked = slot;
        this.dbl_clickTimer = Stopwatch.createStarted();
        if (slot != null) {
          this.dbl_whichItem = slot.getHasStack() ? slot.getStack().copy() : null;
        } else {
          this.dbl_whichItem = null;
        }
      } else if (this.dbl_whichItem != null) {
        // a replica of the weird broken vanilla feature.

        final List<Slot> slots = this.getInventorySlots();
        for (final Slot inventorySlot : slots) {
          if (inventorySlot != null
              && inventorySlot.canTakeStack(this.mc.thePlayer)
              && inventorySlot.getHasStack()
              && inventorySlot.inventory == slot.inventory
              && Container.func_94527_a(inventorySlot, this.dbl_whichItem, true)) {
            this.handleMouseClick(inventorySlot, inventorySlot.slotNumber, ctrlDown, 1);
          }
        }
      }

      this.disableShiftClick = false;
    }

    super.handleMouseClick(slot, slotIdx, ctrlDown, key);
  }
Esempio n. 11
0
 public static void fire(Slot s, ItemStack is) {
   MinecraftForge.EVENT_BUS.post(new AddToSlotEvent(s.getSlotIndex(), s.inventory, is));
 }