本文整理匯總了Java中openperipheral.api.helpers.Index類的典型用法代碼示例。如果您正苦於以下問題:Java Index類的具體用法?Java Index怎麽用?Java Index使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Index類屬於openperipheral.api.helpers包,在下文中一共展示了Index類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: pushNotebookPage
import openperipheral.api.helpers.Index; //導入依賴的package包/類
@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;
}
示例2: pullNotebookPage
import openperipheral.api.helpers.Index; //導入依賴的package包/類
@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;
}
示例3: writeSymbol
import openperipheral.api.helpers.Index; //導入依賴的package包/類
@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);
}
});
}
}
示例4: swapStacks
import openperipheral.api.helpers.Index; //導入依賴的package包/類
@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();
}
示例5: pullNotebookPage
import openperipheral.api.helpers.Index; //導入依賴的package包/類
@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;
}
示例6: writeSymbol
import openperipheral.api.helpers.Index; //導入依賴的package包/類
@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);
}
});
}
}
示例7: pushNotebookPage
import openperipheral.api.helpers.Index; //導入依賴的package包/類
@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;
}
示例8: createInventoryWrapper
import openperipheral.api.helpers.Index; //導入依賴的package包/類
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);
}
示例9: getCellStatus
import openperipheral.api.helpers.Index; //導入依賴的package包/類
@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);
}
}
示例10: pullItem
import openperipheral.api.helpers.Index; //導入依賴的package包/類
@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;
}
示例11: pushItem
import openperipheral.api.helpers.Index; //導入依賴的package包/類
@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;
}
示例12: getStackInSlot
import openperipheral.api.helpers.Index; //導入依賴的package包/類
@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;
}
示例13: getAllStacks
import openperipheral.api.helpers.Index; //導入依賴的package包/類
@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;
}
示例14: destroyStack
import openperipheral.api.helpers.Index; //導入依賴的package包/類
@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();
}
示例15: setLine
import openperipheral.api.helpers.Index; //導入依賴的package包/類
@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);
}