private void SendItem(Item item) { if (!p.HasWindowOpen) { return; } p.SendItem(p.window.id, 0, item); item = Item.Nothing; }
public override void Use(Player p, params string[] args) { if (args.Length > 0 && args[0] == "help") { Help(p); return; } string devlist = ""; string temp; foreach (string dev in devs) { temp = dev.Substring(0, 1); temp = temp.ToUpper() + dev.Remove(0, 1); devlist += temp + ", "; } devlist = devlist.Remove(devlist.Length - 2); p.SendMessage(Color.DarkBlue + "ForgeCraft Development Team: " + Color.DarkRed + devlist, WrapMethod.Chat); //lol it was ForgetCraft short slot = (short)p.inventory.FindEmptySlot(); if (slot == -1) return; p.SendItem(slot, 278, 1, 3); }
public void HandleClick(Player p, short slot, ClickType click, short ActionID, bool Shift) { if (slot == -999) { p.inventory.HandleClick(slot, click, ActionID, Shift); return; } if (slot < 0 || slot > InventorySize + 35) { return; } if (Type == WindowType.Workbench || Type == WindowType.Furnace) { crafting.CheckCrafting(slot, items); } if (Shift) { if (slot >= InventorySize) { if (Type == WindowType.Workbench || Type == WindowType.Furnace || Type == WindowType.EnchantmentTable || Type == WindowType.BrewingStand) { p.inventory.HandleClick((short)((slot - InventorySize) + 9), click, ActionID, Shift); return; } } Item item; bool useEmptySlot = false; if (slot < InventorySize) { Item clickItem = items[slot]; if (clickItem.id != -1) { for (int i = 44; i >= 36; i--) { item = p.inventory.items[i]; if (useEmptySlot) { if (item.id == -1) { p.inventory.items[i] = clickItem; items[slot] = Item.Nothing; break; } } else if (item.id == clickItem.id && item.meta == clickItem.meta) { byte stack = Inventory.isStackable(item.id); byte avail = (byte)(stack - item.count); if (avail < 1) { continue; } if (clickItem.count <= avail) { item.count += clickItem.count; items[slot] = Item.Nothing; break; } else { item.count = stack; clickItem.count -= avail; } } if (i == 36 && !useEmptySlot) { useEmptySlot = true; i = 45; } } if (items[slot].id != -1) { useEmptySlot = false; for (int i = 35; i >= 9; i--) { item = p.inventory.items[i]; if (useEmptySlot) { if (item.id == -1) { p.inventory.items[i] = clickItem; items[slot] = Item.Nothing; break; } } else if (item.id == clickItem.id && item.meta == clickItem.meta) { byte stack = Inventory.isStackable(item.id); byte avail = (byte)(stack - item.count); if (avail < 1) { continue; } if (clickItem.count <= avail) { item.count += clickItem.count; items[slot] = Item.Nothing; break; } else { item.count = stack; clickItem.count -= avail; } } if (i == 9 && !useEmptySlot) { useEmptySlot = true; i = 36; } } } } } else { slot = (short)((slot - InventorySize) + 9); Item clickItem = p.inventory.items[slot]; if (clickItem.id != -1) { for (int i = 0; i < InventorySize; i++) { item = items[i]; if (useEmptySlot) { if (item.id == -1) { items[i] = clickItem; p.inventory.items[slot] = Item.Nothing; break; } } else if (item.id == clickItem.id && item.meta == clickItem.meta) { byte stack = Inventory.isStackable(item.id); byte avail = (byte)(stack - item.count); if (avail < 1) { continue; } if (clickItem.count <= avail) { item.count += clickItem.count; p.inventory.items[slot] = Item.Nothing; break; } else { item.count = stack; clickItem.count -= avail; } } if (i == InventorySize - 1 && !useEmptySlot) { useEmptySlot = true; i = -1; } } } } } else { if (slot >= InventorySize) { p.inventory.HandleClick((short)((slot - InventorySize) + 9), click, ActionID, Shift); return; } Item clickItem = items[slot]; if (p.OnMouse.id == -1) { if (clickItem.id != -1) { if (click == ClickType.RightClick && clickItem.count > 1) { p.OnMouse = new Item(clickItem); p.OnMouse.count = (byte)Math.Ceiling((float)p.OnMouse.count / 2F); clickItem.count /= 2; } else { items[slot] = Item.Nothing; p.OnMouse = clickItem; } } } else { if (clickItem.id != -1) { if (p.OnMouse.id == clickItem.id && p.OnMouse.meta == clickItem.meta) { byte stack = Inventory.isStackable(clickItem.id); if (click == ClickType.RightClick && p.OnMouse.count > 1) { if (clickItem.count < stack) { p.OnMouse.count--; clickItem.count++; } } else { if (clickItem.count < stack) { byte avail = (byte)(stack - clickItem.count); if (p.OnMouse.count <= avail) { clickItem.count += p.OnMouse.count; p.OnMouse = Item.Nothing; } else { clickItem.count = stack; p.OnMouse.count -= avail; } } } } else { items[slot] = p.OnMouse; p.OnMouse = clickItem; } } else { if (click == ClickType.RightClick && p.OnMouse.count > 1) { items[slot] = new Item(p.OnMouse); items[slot].count = 1; p.OnMouse.count--; } else { items[slot] = p.OnMouse; p.OnMouse = Item.Nothing; } } } } if (container != null) { container.UpdateContents(p); } List <Item> items2 = new List <Item>(items); items2.AddRange((Item[])p.inventory.items.TruncateStart(9)); p.SendWindowItems(id, items2.ToArray()); p.SendItem(255, -1, p.OnMouse); }
public bool Add(short item, byte count, short meta) { //Console.WriteLine("add1"); byte stackable = isStackable(item); byte c = count; //Console.WriteLine("add2"); for (int i = 36; i < 45; i++) { if (c == 0) { return(true); } if (items[i].id == item) { if (items[i].meta != meta) { continue; } if (items[i].count < stackable) { items[i].count += c; c = 0; if (items[i].count > stackable) { c = (byte)(items[i].count - stackable); items[i].count -= c; } p.SendItem((short)i, item, items[i].count, meta); } } } //Console.WriteLine("add3"); for (int i = 9; i <= 35; i++) { if (c == 0) { return(true); } if (items[i].id == item) { if (items[i].meta != meta) { continue; } if (items[i].count < stackable) { items[i].count += c; c = 0; if (items[i].count > stackable) { c = (byte)(items[i].count - stackable); items[i].count -= c; } p.SendItem((short)i, item, items[i].count, meta); } } } //Console.WriteLine("add4"); return(Add(item, c, meta, FindEmptySlot())); }
public void HandleClick(Player p, short slot, ClickType click, short ActionID, bool Shift) { if (slot == -999) { p.inventory.HandleClick(slot, click, ActionID, Shift); return; } if (slot < 0 || slot > InventorySize + 35) return; if (Type == WindowType.Workbench || Type == WindowType.Furnace) { if (slot == 0) { // TODO: Crafting/smelting output handler. return; } } if (Shift) { if (slot >= InventorySize) { if (Type == WindowType.Workbench || Type == WindowType.Furnace || Type == WindowType.EnchantmentTable || Type == WindowType.BrewingStand) { p.inventory.HandleClick((short)((slot - InventorySize) + 9), click, ActionID, Shift); return; } } Item item; bool useEmptySlot = false; if (slot < InventorySize) { Item clickItem = items[slot]; if (clickItem.id != -1) { for (int i = 44; i >= 36; i--) { item = p.inventory.items[i]; if (useEmptySlot) { if (item.id == -1) { p.inventory.items[i] = clickItem; items[slot] = Item.Nothing; break; } } else if (item.id == clickItem.id && item.meta == clickItem.meta) { byte stack = Inventory.isStackable(item.id); byte avail = (byte)(stack - item.count); if (avail < 1) continue; if (clickItem.count <= avail) { item.count += clickItem.count; items[slot] = Item.Nothing; break; } else { item.count = stack; clickItem.count -= avail; } } if (i == 36 && !useEmptySlot) { useEmptySlot = true; i = 45; } } if (items[slot].id != -1) { useEmptySlot = false; for (int i = 35; i >= 9; i--) { item = p.inventory.items[i]; if (useEmptySlot) { if (item.id == -1) { p.inventory.items[i] = clickItem; items[slot] = Item.Nothing; break; } } else if (item.id == clickItem.id && item.meta == clickItem.meta) { byte stack = Inventory.isStackable(item.id); byte avail = (byte)(stack - item.count); if (avail < 1) continue; if (clickItem.count <= avail) { item.count += clickItem.count; items[slot] = Item.Nothing; break; } else { item.count = stack; clickItem.count -= avail; } } if (i == 9 && !useEmptySlot) { useEmptySlot = true; i = 36; } } } } } else { slot = (short)((slot - InventorySize) + 9); Item clickItem = p.inventory.items[slot]; if (clickItem.id != -1) { for (int i = 0; i < InventorySize; i++) { item = items[i]; if (useEmptySlot) { if (item.id == -1) { items[i] = clickItem; p.inventory.items[slot] = Item.Nothing; break; } } else if (item.id == clickItem.id && item.meta == clickItem.meta) { byte stack = Inventory.isStackable(item.id); byte avail = (byte)(stack - item.count); if (avail < 1) continue; if (clickItem.count <= avail) { item.count += clickItem.count; p.inventory.items[slot] = Item.Nothing; break; } else { item.count = stack; clickItem.count -= avail; } } if (i == InventorySize - 1 && !useEmptySlot) { useEmptySlot = true; i = -1; } } } } } else { if (slot >= InventorySize) { p.inventory.HandleClick((short)((slot - InventorySize) + 9), click, ActionID, Shift); return; } Item clickItem = items[slot]; if (p.OnMouse.id == -1) { if (clickItem.id != -1) { if (click == ClickType.RightClick && clickItem.count > 1) { p.OnMouse = new Item(clickItem); p.OnMouse.count = (byte)Math.Ceiling((float)p.OnMouse.count / 2F); clickItem.count /= 2; } else { items[slot] = Item.Nothing; p.OnMouse = clickItem; } } } else { if (clickItem.id != -1) { if (p.OnMouse.id == clickItem.id && p.OnMouse.meta == clickItem.meta) { byte stack = Inventory.isStackable(clickItem.id); if (click == ClickType.RightClick && p.OnMouse.count > 1) { if (clickItem.count < stack) { p.OnMouse.count--; clickItem.count++; } } else { if (clickItem.count < stack) { byte avail = (byte)(stack - clickItem.count); if (p.OnMouse.count <= avail) { clickItem.count += p.OnMouse.count; p.OnMouse = Item.Nothing; } else { clickItem.count = stack; p.OnMouse.count -= avail; } } } } else { items[slot] = p.OnMouse; p.OnMouse = clickItem; } } else { if (click == ClickType.RightClick && p.OnMouse.count > 1) { items[slot] = new Item(p.OnMouse); items[slot].count = 1; p.OnMouse.count--; } else { items[slot] = p.OnMouse; p.OnMouse = Item.Nothing; } } } } if (container != null) container.UpdateContents(p); List<Item> items2 = new List<Item>(items); items2.AddRange((Item[])p.inventory.items.TruncateStart(9)); p.SendWindowItems(id, items2.ToArray()); p.SendItem(255, -1, p.OnMouse); }