openmods.inventory.GenericInventory Java Examples

The following examples show how to use openmods.inventory.GenericInventory. 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: AdapterWritingDesk.java    From OpenPeripheral-Integration with MIT License 5 votes vote down vote up
@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 #2
Source File: ItemInventoryWalker.java    From OpenModsLib with MIT License 5 votes vote down vote up
@Override
protected NBTTagCompound processTag(IDataFixer fixer, NBTTagCompound compound, int version) {
	if (compound.hasKey(ItemInventory.TAG_INVENTORY, Constants.NBT.TAG_COMPOUND)) {
		final NBTTagCompound inventoryTag = compound.getCompoundTag(ItemInventory.TAG_INVENTORY);
		final NBTTagCompound newInventoryTag = DataFixesManager.processInventory(fixer, inventoryTag, version, GenericInventory.TAG_ITEMS);
		compound.setTag(ItemInventory.TAG_INVENTORY, newInventoryTag);
	}

	return compound;
}
 
Example #3
Source File: GenericInventoryTeFixerWalker.java    From OpenModsLib with MIT License 4 votes vote down vote up
@Override
public void register(DataFixer registry, Class<?> registeringClass) {
	registry.registerWalker(FixTypes.BLOCK_ENTITY, new ItemStackDataLists(registeringClass, GenericInventory.TAG_ITEMS));
}
 
Example #4
Source File: ContainerBase.java    From OpenModsLib with MIT License 4 votes vote down vote up
@Override
public void onSlotChanged() {
	super.onSlotChanged();
	// hackish, but required
	if (inventory instanceof GenericInventory) ((GenericInventory)inventory).onInventoryChanged(getSlotIndex());
}
 
Example #5
Source File: OpenTileEntity.java    From OpenModsLib with MIT License 4 votes vote down vote up
protected GenericInventory registerInventoryCallback(GenericInventory inventory) {
	return inventory.addCallback(createInventoryCallback());
}