/** * Copies all items from this inventory into the destination inventory */ public void copyAllItemsTo(Inventory destinationInventory) { for (BagType bag : BagType.values()) { IntMap<InventoryItem> sourceBag = getBag(bag); for (Entry<InventoryItem> slot : sourceBag.entries()) { InventoryItem item = slot.value; if (item != null) { InventoryItem newCopy = item.createNewInstance(); if (item.getStackSize() > 1) { for (int i = 1; i < item.getStackSize(); ++i) { newCopy.addToStack(newCopy.createNewInstance()); } } destinationInventory.addToBag(bag, newCopy, slot.key); } } } }
private void gatherControllers(boolean sendEvent) { // gather all joysticks and gamepads, remove any disconnected ones IntMap<AndroidController> removedControllers = new IntMap<AndroidController>(); removedControllers.putAll(controllerMap); for(int deviceId: InputDevice.getDeviceIds()) { InputDevice device = InputDevice.getDevice(deviceId); AndroidController controller = controllerMap.get(deviceId); if(controller != null) { removedControllers.remove(deviceId); } else { addController(deviceId, sendEvent); } } for(Entry<AndroidController> entry: removedControllers.entries()) { removeController(entry.key); } }
private static IntMap<BlockPair> map(Object...objects){ IntMap<BlockPair> colors = new IntMap<>(); for(int i = 0; i < objects.length/2; i ++){ colors.put(Color.rgba8888(Color.valueOf((String)objects[i*2])), (BlockPair)objects[i*2+1]); pairs.add((BlockPair)objects[i*2+1]); } for(Entry<BlockPair> e : colors.entries()){ reverseColors.put(e.value.wall == Blocks.air ? e.value.floor : e.value.wall, e.key); } return colors; }
private int findAcceptableSlot(IntMap<InventoryItem> bag, InventoryItem item) { int slot = 0; // first check for occupied slot that's stackable with the item for (Entry<InventoryItem> entry: bag.entries()) { if (entry.value.isStackable(item)) { return entry.key; } } // then search for an embty slot while (bag.containsKey(slot)) { ++slot; } return slot; }
/** * Removes all items from all bags of this inventory. */ public void clear() { for (ObjectMap.Entry<BagType, IntMap<InventoryItem>> bag : bags.entries()) { Iterator<Entry<InventoryItem>> iterator = bag.value.iterator(); while (iterator.hasNext()) { InventoryItem item = iterator.next().value; item.setInventory(null); onItemRemove(item, bag.key); iterator.remove(); } } }
/** * Writes the Inventory into XML using the supplied XmlWriter. * * The output XML will look like this: * * <pre> * <Inventory> * <BagType> * <Item id="itemId" slot="inventorySlot" /> * ... * </BagType> * </Inventory> * </pre> */ @Override public void writeToXML(XmlWriter writer) throws IOException { writer.element(Inventory.XML_INVENTORY); for (BagType bagType : BagType.values()) { IntMap<InventoryItem> bag = getBag(bagType); if (bag.size > 0) { writer.element(bagType.toString().toLowerCase(Locale.ENGLISH)); Entries<InventoryItem> bagIterator = bag.entries(); while (bagIterator.hasNext) { Entry<InventoryItem> entry = bagIterator.next(); writer.element(Inventory.XML_ITEM) .attribute(XMLUtil.XML_ATTRIBUTE_ID, entry.value.getId()) .attribute(XML_ATTRIBUTE_SLOT, entry.key) .attribute(XML_ATTRIBUTE_STACK_SIZE, entry.value.getStackSize()); ItemOwner itemOwner = entry.value.getOwner(); String ownerId =itemOwner.getOwnerCharacterId(); if (ownerId != null) { writer.attribute(XML_ATTRIBUTE_OWNER_CHARACTER, ownerId); } Faction faction = itemOwner.getOwnerFaction(); if (faction != null) { writer.attribute(XML_ATTRIBUTE_OWNER_FACTION, faction); } writer.pop(); } writer.pop(); } } writer.pop(); }
public Player getPlayerForConnection (Object connectionInformation) { Iterator<Entry<Player>> entries = players.iterator(); Entry<Player> entry = null; if (entries.hasNext()) while ((entry = entries.next()) != null) { if (entry.value.connectionInformation == connectionInformation) { return entry.value; } } return null; }
@Override protected IntMap cloneObject (IntMap original, IDeepCloner cloner, Map<Object, Object> clones) { IntMap map = new IntMap(original.size); for (Object object : original.entries()) { Entry entry = (Entry) object; map.put(entry.key, cloner.deepClone(entry.value, clones)); } return map; }