openperipheral.api.helpers.Index Java Examples
The following examples show how to use
openperipheral.api.helpers.Index.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AdapterInventory.java From OpenPeripheral-Integration with MIT License | 6 votes |
@Asynchronous(false) @ScriptCallable(description = "Swap two slots in the inventory") public void swapStacks(IInventory target, @Arg(name = "from", description = "The first slot") Index fromSlot, @Arg(name = "to", description = "The other slot") Index intoSlot, @Optionals @Arg(name = "fromDirection") ForgeDirection fromDirection, @Arg(name = "fromDirection") ForgeDirection toDirection) { IInventory inventory = InventoryUtils.getInventory(target); Preconditions.checkNotNull(inventory, "Invalid target!"); final int size = inventory.getSizeInventory(); fromSlot.checkElementIndex("first slot id", size); intoSlot.checkElementIndex("second slot id", size); if (inventory instanceof ISidedInventory) { InventoryUtils.swapStacks((ISidedInventory)inventory, fromSlot.value, Objects.firstNonNull(fromDirection, ForgeDirection.UNKNOWN), intoSlot.value, Objects.firstNonNull(toDirection, ForgeDirection.UNKNOWN)); } else InventoryUtils.swapStacks(inventory, fromSlot.value, intoSlot.value); inventory.markDirty(); }
Example #2
Source File: AdapterWritingDesk.java From OpenPeripheral-Integration with MIT License | 6 votes |
@ScriptCallable( returnTypes = ReturnType.NUMBER, description = "Push a page from the notebook into a specific slot in external inventory. Returns the amount of items moved") public int pushNotebookPage( TileEntity desk, @Arg(name = "deskSlot") Index deskSlot, @Arg(name = "direction", description = "The direction of the other inventory. (north, south, east, west, up or down)") ForgeDirection direction, @Arg(name = "fromSlot", description = "The page slot in inventory that you're pushing from") Index fromSlot, @Optionals @Arg(name = "intoSlot", description = "The slot in the other inventory that you want to push into") Index intoSlot) { IInventory source = createInventoryWrapper(desk, deskSlot); IInventory target = getTargetTile(desk, direction); if (intoSlot == null) intoSlot = Index.fromJava(-1, 0); final int amount = ItemDistribution.moveItemInto(source, fromSlot.value, target, intoSlot.value, 64, direction.getOpposite(), true); if (amount > 0) target.markDirty(); return amount; }
Example #3
Source File: AdapterWritingDesk.java From OpenPeripheral-Integration with MIT License | 6 votes |
@ScriptCallable(description = "Create a symbol page from the target symbol") public void writeSymbol(final TileEntity desk, @Arg(name = "deskSlot") Index deskSlot, @Arg(name = "notebookSlot", description = "The source symbol to copy") Index notebookSlot) { Preconditions.checkNotNull(MystcraftAccess.pageApi, "Functionality not available"); final NotebookWrapper wrapper = createInventoryWrapper(desk, deskSlot); ItemStack page = wrapper.getPageFromSlot(notebookSlot); final String symbol = MystcraftAccess.pageApi.getPageSymbol(page); if (symbol != null) { FakePlayerPool.instance.executeOnPlayer((WorldServer)desk.getWorldObj(), new PlayerUser() { @Override public void usePlayer(OpenModsFakePlayer fakePlayer) { WRITE_SYMBOL.call(desk, fakePlayer, symbol); } }); } }
Example #4
Source File: AdapterWritingDesk.java From OpenPeripheral-Integration with MIT License | 6 votes |
@ScriptCallable(returnTypes = ReturnType.BOOLEAN, description = "Pull an item from the target inventory into any slot in the current one. Returns true if item was consumed") public boolean pullNotebookPage(TileEntity desk, @Arg(name = "deskSlot") Index deskSlot, @Arg(name = "direction", description = "The direction of the other inventory)") ForgeDirection direction, @Arg(name = "fromSlot", description = "The slot in the other inventory that you're pulling from") Index fromSlot) { IInventory inv = getTargetTile(desk, direction); fromSlot.checkElementIndex("input slot", inv.getSizeInventory()); ItemStack stack = inv.getStackInSlot(fromSlot.value); Preconditions.checkNotNull(stack, "Other inventory empty"); final NotebookWrapper wrapper = createInventoryWrapper(desk, deskSlot); ItemStack added = wrapper.addPage(stack); inv.setInventorySlotContents(fromSlot.value, added); inv.markDirty(); return added == null; }
Example #5
Source File: TileEntitySelector.java From OpenPeripheral-Addons with MIT License | 5 votes |
@ScriptCallable(description = "Set the item being displayed on a specific slot") public void setSlot( @Arg(name = "slot", description = "The slot you want to modify") Index slot, @Optionals @Arg(name = "item", description = "The item you want to display. nil to set empty") ItemStack stack) { slot.checkElementIndex("slot id", 10); if (stack != null) stack.stackSize = 1; this.slots[slot.value].set(stack); sync(); }
Example #6
Source File: AdapterInventory.java From OpenPeripheral-Integration with MIT License | 5 votes |
@ScriptCallable(returnTypes = ReturnType.OBJECT, description = "Get details of an item in a particular slot") public Object getStackInSlot(IInventory target, @Arg(name = "slotNumber", description = "Slot number") Index slot, @Optionals @Arg(name = "proxy", description = "If true, method will return proxy instead of computing whole table") Boolean proxy) { IInventory inventory = InventoryUtils.getInventory(target); slot.checkElementIndex("slot id", inventory.getSizeInventory()); ItemStack stack = inventory.getStackInSlot(slot.value); return proxy == Boolean.TRUE? OpcAccess.itemStackMetaBuilder.createProxy(stack) : stack; }
Example #7
Source File: AdapterInventory.java From OpenPeripheral-Integration with MIT License | 5 votes |
@ScriptCallable(returnTypes = ReturnType.TABLE, description = "Get a table with all the items of the chest") public Map<Index, Object> getAllStacks(IInventory target, @Env(Constants.ARG_ARCHITECTURE) IArchitecture access, @Optionals @Arg(name = "proxy", description = "If false, method will compute whole table, instead of returning proxy") Boolean proxy) { final IInventory inventory = InventoryUtils.getInventory(target); Map<Index, Object> result = Maps.newHashMap(); for (int i = 0; i < inventory.getSizeInventory(); i++) { ItemStack stack = inventory.getStackInSlot(i); if (stack != null) result.put(access.createIndex(i), (proxy != Boolean.FALSE)? OpcAccess.itemStackMetaBuilder.createProxy(stack) : stack); } return result; }
Example #8
Source File: AdapterSign.java From OpenPeripheral-Integration with MIT License | 5 votes |
@ScriptCallable(description = "Sets the text on the sign") public void setLine(TileEntitySign sign, @Arg(name = "line", description = "The line number to set the text on the sign") Index line, @Arg(name = "text", description = "The text to display on the sign") String text) { line.checkElementIndex("line", sign.signText.length); setLine(sign, line.value, text); updateSign(sign); }
Example #9
Source File: AdapterSign.java From OpenPeripheral-Integration with MIT License | 5 votes |
@Asynchronous @ScriptCallable(returnTypes = ReturnType.STRING, description = "Gets the text from the supplied line of the sign") public String getLine(TileEntitySign sign, @Arg(name = "line", description = "The line number to get from the sign") Index line) { line.checkElementIndex("line", sign.signText.length); return sign.signText[line.value]; }
Example #10
Source File: TileEntitySelector.java From OpenPeripheral-Addons with MIT License | 5 votes |
@Asynchronous @ScriptCallable(description = "Get the item currently being displayed in a specific slot", returnTypes = ReturnType.TABLE, name = "getSlot") public ItemStack getSlotOneBased(@Arg(name = "slot", description = "The slot you want to get details about") Index slot) { slot.checkElementIndex("slot id", 10); return slots[slot.value].get(); }
Example #11
Source File: TileEntitySelector.java From OpenPeripheral-Addons with MIT License | 5 votes |
@ScriptCallable(description = "Set the items being displayed in all slots") public void setSlots( @Env(Constants.ARG_ARCHITECTURE) IArchitecture access, @Arg(name = "items", description = "A table containing itemstacks") Map<Index, ItemStack> stacks) { for (int slot = 0; slot < 9; slot++) { final ItemStack value = stacks.get(access.wrapObject(slot)); if (value != null) value.stackSize = 1; this.slots[slot].set(value); } sync(); }
Example #12
Source File: AdapterInventory.java From OpenPeripheral-Integration with MIT License | 5 votes |
@Asynchronous(false) @ScriptCallable(description = "Destroy a stack") public void destroyStack(IInventory target, @Arg(name = "slotNumber", description = "The slot number") Index slot) { IInventory inventory = InventoryUtils.getInventory(target); slot.checkElementIndex("slot id", inventory.getSizeInventory()); inventory.setInventorySlotContents(slot.value, null); inventory.markDirty(); }
Example #13
Source File: DrawableContainerMaster.java From OpenPeripheral-Addons with MIT License | 5 votes |
@Override public Set<Index> getAllIds(IArchitecture access) { final Set<Index> indices = Sets.newHashSet(); for (int value : containers.keySet()) indices.add(access.createIndex(value)); return indices; }
Example #14
Source File: DrawableContainerMaster.java From OpenPeripheral-Addons with MIT License | 5 votes |
@Override public Map<Index, Drawable> getAllObjects(IArchitecture access) { final Map<Index, Drawable> result = Maps.newHashMap(); for (Map.Entry<Integer, Drawable> e : containers.entrySet()) result.put(access.createIndex(e.getKey()), e.getValue()); return result; }
Example #15
Source File: ConverterNumberInbound.java From OpenPeripheral with MIT License | 5 votes |
@Override public Object toJava(IConverter registry, Object o, Class<?> required) { final Double d; if (o instanceof Double) { d = (Double)o; } else try { d = Double.parseDouble(o.toString()); } catch (NumberFormatException e) { return null; } if (required == Integer.class || required == int.class) return d.intValue(); if (required == Double.class || required == double.class) return d; if (required == Float.class || required == float.class) return d.floatValue(); if (required == Long.class || required == long.class) return d.longValue(); if (required == Short.class || required == short.class) return d.shortValue(); if (required == Byte.class || required == byte.class) return d.byteValue(); if (required == Boolean.class || required == boolean.class) return d != 0; if (required == Index.class) return Index.toJava(d.intValue(), offset); return null; }
Example #16
Source File: IndexedTypeInfoBuilderTest.java From OpenPeripheral with MIT License | 5 votes |
@Test public void testAllDeducedList() { IndexedTypeInfoBuilder builder = new IndexedTypeInfoBuilder(LIST_TYPE); final IndexedTypeInfo result = builder.build(); matchDocTypes(result, "number", "boolean"); matchKeyType(result, Index.class); matchConstantValue(result, Boolean.class); }
Example #17
Source File: IndexedTypeInfoBuilderTest.java From OpenPeripheral with MIT License | 5 votes |
@Test public void testAllDeducedArrayObject() { IndexedTypeInfoBuilder builder = new IndexedTypeInfoBuilder(String[].class); final IndexedTypeInfo result = builder.build(); matchDocTypes(result, "number", "string"); matchKeyType(result, Index.class); matchConstantValue(result, String.class); }
Example #18
Source File: IndexedTypeInfoBuilderTest.java From OpenPeripheral with MIT License | 5 votes |
@Test public void testAllDeducedArrayPrimitive() { IndexedTypeInfoBuilder builder = new IndexedTypeInfoBuilder(boolean[].class); final IndexedTypeInfo result = builder.build(); matchDocTypes(result, "number", "boolean"); matchKeyType(result, Index.class); matchConstantValue(result, boolean.class); }
Example #19
Source File: IndexedTypeInfoBuilderTest.java From OpenPeripheral with MIT License | 5 votes |
@Test public void testOverrideValueTypeSimple() { IndexedTypeInfoBuilder builder = new IndexedTypeInfoBuilder(LIST_TYPE); builder.overrideValueType(Boolean.class); final IndexedTypeInfo result = builder.build(); matchDocTypes(result, "number", "boolean"); matchKeyType(result, Index.class); matchConstantValue(result, Boolean.class); }
Example #20
Source File: AdapterWorldInventory.java From OpenPeripheral-Integration with MIT License | 5 votes |
@Alias("pullItemIntoSlot") @ScriptCallable(returnTypes = ReturnType.NUMBER, description = "Pull an item from a slot in another inventory into a slot in this one. Returns the amount of items moved") public int pullItem(IInventory target, @Arg(name = "direction", description = "The direction of the other inventory") ForgeDirection direction, @Arg(name = "slot", description = "The slot in the OTHER inventory that you're pulling from") Index fromSlot, @Optionals @Arg(name = "maxAmount", description = "The maximum amount of items you want to pull") Integer maxAmount, @Arg(name = "intoSlot", description = "The slot in the current inventory that you want to pull into") Index intoSlot) { final TileEntity otherTarget = getNeighborTarget(target, direction); if (otherTarget == null) throw new IllegalArgumentException("Other block not found"); if (!(otherTarget instanceof IInventory)) throw new IllegalArgumentException("Other block is not inventory"); final IInventory otherInventory = InventoryUtils.getInventory((IInventory)otherTarget); final IInventory thisInventory = InventoryUtils.getInventory(target); if (otherTarget == target) return 0; if (maxAmount == null) maxAmount = 64; if (intoSlot == null) intoSlot = ANY_SLOT_INDEX; checkSlotId(otherInventory, fromSlot, "input"); checkSlotId(thisInventory, intoSlot, "output"); final int amount = ItemDistribution.moveItemInto(otherInventory, fromSlot.value, thisInventory, intoSlot.value, maxAmount, direction.getOpposite(), true); if (amount > 0) { thisInventory.markDirty(); otherInventory.markDirty(); } return amount; }
Example #21
Source File: AdapterWorldInventory.java From OpenPeripheral-Integration with MIT License | 5 votes |
@Alias("pushItemIntoSlot") @ScriptCallable(returnTypes = ReturnType.NUMBER, description = "Push an item from the current inventory into pipe or slot on the other inventory. Returns the amount of items moved") public int pushItem(IInventory target, @Arg(name = "direction", description = "The direction of the other inventory") ForgeDirection direction, @Arg(name = "slot", description = "The slot in the current inventory that you're pushing from") Index fromSlot, @Optionals @Arg(name = "maxAmount", description = "The maximum amount of items you want to push") Integer maxAmount, @Arg(name = "intoSlot", description = "The slot in the other inventory that you want to push into (ignored when target is pipe") Index intoSlot) { final TileEntity otherTarget = getNeighborTarget(target, direction); Preconditions.checkNotNull(otherTarget, "Other target not found"); final IInventory thisInventory = InventoryUtils.getInventory(target); if (maxAmount == null) maxAmount = 64; if (intoSlot == null) intoSlot = ANY_SLOT_INDEX; checkSlotId(thisInventory, fromSlot, "input"); final int amount; if (otherTarget instanceof IInventory) { final IInventory otherInventory = InventoryUtils.getInventory((IInventory)otherTarget); checkSlotId(otherInventory, intoSlot, "output"); amount = ItemDistribution.moveItemInto(thisInventory, fromSlot.value, otherInventory, intoSlot.value, maxAmount, direction, true); if (amount > 0) otherInventory.markDirty(); } else { final CustomSinks.ICustomSink adapter = CustomSinks.createSink(otherTarget); if (adapter == null) throw new IllegalArgumentException("Invalid target"); amount = ItemDistribution.moveItemInto(thisInventory, fromSlot.value, adapter, maxAmount, direction, true); } if (amount > 0) thisInventory.markDirty(); return amount; }
Example #22
Source File: AdapterStorage.java From OpenPeripheral-Integration with MIT License | 5 votes |
@ScriptCallable(returnTypes = { ReturnType.NUMBER, ReturnType.STRING }) public IMultiReturn getCellStatus(IChestOrDrive target, @Arg(name = "slot") Index slot) { try { int status = target.getCellStatus(slot.value); return MultiReturn.wrap(status, intToState(status)); } catch (IndexOutOfBoundsException e) { throw new IllegalArgumentException("Invalid cell index: " + slot); } }
Example #23
Source File: AdapterWritingDesk.java From OpenPeripheral-Integration with MIT License | 5 votes |
private NotebookWrapper createInventoryWrapper(TileEntity tile, Index slot) { ItemStack notebook = GET_NOTEBOOK.call(tile, slot.byteValue()); Preconditions.checkState(notebook != null, "Empty slot"); Item item = notebook.getItem(); Preconditions.checkState(item instanceof IItemPageCollection, "Invalid item in slot"); return new NotebookWrapper((WorldServer)tile.getWorldObj(), (IItemPageCollection)item, notebook); }
Example #24
Source File: AdapterWritingDesk.java From OpenPeripheral-Integration with MIT License | 5 votes |
@ScriptCallable( returnTypes = ReturnType.NUMBER, description = "Push a page from the notebook into a specific slot in external inventory. Returns the amount of items moved") public int pushNotebookPage( TileEntity desk, @Arg(name = "deskSlot") Index deskSlot, @Arg(name = "direction", description = "The direction of the other inventory. (north, south, east, west, up or down)") ForgeDirection direction, @Arg(name = "fromSlot", description = "The page slot in inventory that you're pushing from") Index fromSlot, @Optionals @Arg(name = "intoSlot", description = "The slot in the other inventory that you want to push into") Index intoSlot) { final NotebookWrapper wrapper = createInventoryWrapper(desk, deskSlot); ItemStack page = wrapper.getPageFromSlot(fromSlot); ItemStack removedPage = wrapper.removePage(page); Preconditions.checkNotNull(removedPage, "No page in notebook"); GenericInventory tmp = new GenericInventory("tmp", false, 1); tmp.setInventorySlotContents(0, removedPage.copy()); final IInventory target = getTargetTile(desk, direction); if (intoSlot == null) intoSlot = Index.fromJava(-1, 0); int result = ItemDistribution.moveItemInto(tmp, 0, target, intoSlot.value, removedPage.stackSize, direction, true); int remains = removedPage.stackSize - result; if (remains >= 0) { ItemStack returns = removedPage.copy(); returns.stackSize = remains; wrapper.addPage(returns); } return result; }
Example #25
Source File: AdapterWritingDesk.java From OpenPeripheral-Integration with MIT License | 5 votes |
@ScriptCallable(returnTypes = ReturnType.NUMBER, description = "Pull an item from the target inventory into any slot in the current one. Returns the amount of items moved") public int pullNotebookPage(TileEntity desk, @Arg(name = "deskSlot") Index deskSlot, @Arg(name = "direction", description = "The direction of the other inventory)") ForgeDirection direction, @Arg(name = "fromSlot", description = "The slot in the other inventory that you're pulling from") int notebookSlot) { IInventory source = getTargetTile(desk, direction); IInventory target = createInventoryWrapper(desk, deskSlot); final int amount = ItemDistribution.moveItemInto(source, notebookSlot - 1, target, -1, 1, direction.getOpposite(), true, false); if (amount > 0) source.markDirty(); return amount; }
Example #26
Source File: AdapterWritingDesk.java From OpenPeripheral-Integration with MIT License | 5 votes |
@ScriptCallable(description = "Create a symbol page from the target symbol") public void writeSymbol(final TileEntity desk, @Arg(name = "deskSlot") Index deskSlot, @Arg(name = "notebookSlot", description = "The source symbol to copy") Index notebookSlot) { final String symbol = getSymbolFromPage(getNotebookStackInSlot(desk, deskSlot, notebookSlot)); if (symbol != null) { FakePlayerPool.instance.executeOnPlayer((WorldServer)desk.getWorldObj(), new PlayerUser() { @Override public void usePlayer(OpenModsFakePlayer fakePlayer) { WRITE_SYMBOL.call(desk, fakePlayer, symbol); } }); } }
Example #27
Source File: AdapterWritingDesk.java From OpenPeripheral-Integration with MIT License | 4 votes |
@ScriptCallable(description = "Get the number of pages in a notebook", returnTypes = ReturnType.NUMBER) public Integer getNotebookSize(Object desk, @Arg(name = "deskSlot") Index deskSlot) { return createInventoryWrapper(desk, deskSlot).getItemCount(); }
Example #28
Source File: AdapterWritingDesk.java From OpenPeripheral-Integration with MIT License | 4 votes |
@ScriptCallable(description = "Get the contents of a slot in a notebook", returnTypes = ReturnType.NUMBER) public ItemStack getNotebookStackInSlot(Object desk, @Arg(name = "deskSlot") Index deskSlot, @Arg(name = "notebookSlot") Index notebookSlot) { return createInventoryWrapper(desk, deskSlot).getStackInSlot(notebookSlot.value); }
Example #29
Source File: AdapterWritingDesk.java From OpenPeripheral-Integration with MIT License | 4 votes |
@ScriptCallable(description = "Get the last slot index in a notebook", returnTypes = ReturnType.NUMBER) public Integer getLastNotebookSlot(Object desk, @Arg(name = "deskSlot") Index deskSlot) { return createInventoryWrapper(desk, deskSlot).getSizeInventory() - 1; }
Example #30
Source File: AdapterWritingDesk.java From OpenPeripheral-Integration with MIT License | 4 votes |
@ScriptCallable(description = "Swap notebook slots") public void swapNotebookPages(Object desk, @Arg(name = "deskSlot") Index deskSlot, @Arg(name = "from") Index from, @Arg(name = "to") Index to) { InventoryUtils.swapStacks(createInventoryWrapper(desk, deskSlot), from.value, to.value); }