openmods.utils.ItemUtils Java Examples

The following examples show how to use openmods.utils.ItemUtils. 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: ItemFingerprint.java    From OpenPeripheral-Integration with MIT License 5 votes vote down vote up
public ItemFingerprint(ItemStack stack) {
	String itemId = GameData.getItemRegistry().getNameForObject(stack.getItem());
	this.id = new UniqueIdentifier(itemId);
	this.damage = stack.getItemDamage();

	NBTTagCompound tag = stack.getTagCompound();
	this.nbtHash = tag != null? ItemUtils.getNBTHash(tag) : null;
}
 
Example #2
Source File: TileEntityGlassesBridge.java    From OpenPeripheral-Addons with MIT License 5 votes vote down vote up
@Override
public void addHarvestDrops(EntityPlayer player, List<ItemStack> drops) {
	ItemStack result = new ItemStack(getBlockType());
	if (guid.isPresent()) {
		NBTTagCompound tag = ItemUtils.getItemTag(result);
		tag.setLong(TAG_GUID, guid.get());
	}
	drops.add(result);
}
 
Example #3
Source File: NbtGuidProviders.java    From OpenPeripheral-Addons with MIT License 5 votes vote down vote up
public static NBTTagCompound getOrCreateTerminalTag(ItemStack stack) {
	final NBTTagCompound itemTag = ItemUtils.getItemTag(stack);
	if (!itemTag.hasKey(MAIN_TAG, Constants.NBT.TAG_COMPOUND)) {
		final NBTTagCompound result = new NBTTagCompound();
		itemTag.setTag(MAIN_TAG, result);
		return result;
	} else {
		return itemTag.getCompoundTag(MAIN_TAG);
	}
}
 
Example #4
Source File: ItemGlasses.java    From OpenPeripheral-Addons with MIT License 5 votes vote down vote up
private static Long extractGuid(ItemStack stack) {
	NBTTagCompound tag = ItemUtils.getItemTag(stack);
	if (!tag.hasKey(OPENP_TAG)) return null;

	NBTTagCompound openp = tag.getCompoundTag(OPENP_TAG);
	return TerminalUtils.extractGuid(openp);
}
 
Example #5
Source File: TileEntityTicketMachine.java    From OpenPeripheral-Addons with MIT License 5 votes vote down vote up
@ScriptCallable(returnTypes = ReturnType.BOOLEAN, description = "Create a new ticket to the specified destination")
public boolean createTicket(@Arg(name = "destination", description = "The destination for the ticket") String destination,
		@Arg(name = "amount") @Optionals Integer amount) {
	if (amount == null) amount = 1;
	else Preconditions.checkArgument(amount > 0 && amount <= 64, "Amount must be between 1 and 64");

	ItemStack paperStack = inventory.getStackInSlot(SLOT_PAPER);
	Preconditions.checkArgument(inventory.isItemValidForSlot(SLOT_PAPER, paperStack) && paperStack.stackSize >= amount, "Not enough paper");

	ItemStack inkStack = inventory.getStackInSlot(SLOT_INK);
	Preconditions.checkArgument(inventory.isItemValidForSlot(SLOT_INK, inkStack) && inkStack.stackSize >= amount, "Not enough ink");

	ItemStack output = inventory.getStackInSlot(SLOT_OUTPUT);

	ItemStack newTicket = new ItemStack(ticketItem);
	NBTTagCompound tag = ItemUtils.getItemTag(newTicket);
	tag.setString("owner", owner.getValue());
	tag.setString("dest", destination);

	if (output == null) {
		inventory.setInventorySlotContents(SLOT_OUTPUT, newTicket);
	} else if (ItemStack.areItemStackTagsEqual(output, newTicket) && output.isItemEqual(newTicket) && output.stackSize + amount <= output.getMaxStackSize()) {
		output.stackSize += amount;
	} else throw new IllegalArgumentException("No place in output slot");

	inventory.decrStackSize(SLOT_PAPER, amount);
	inventory.decrStackSize(SLOT_INK, amount);

	worldObj.playSoundEffect(xCoord + 0.5D, yCoord + 0.5D, zCoord + 0.5D, "openperipheraladdons:ticketmachine", 0.3F, 0.6F);
	sync();

	return true;
}
 
Example #6
Source File: ItemInventory.java    From OpenModsLib with MIT License 5 votes vote down vote up
public ItemInventory(@Nonnull ItemStack containerStack, int size) {
	super("", false, size);
	Preconditions.checkNotNull(containerStack);
	this.containerStack = containerStack;
	final NBTTagCompound tag = ItemUtils.getItemTag(containerStack);
	readFromNBT(getInventoryTag(tag));

}
 
Example #7
Source File: ItemInventory.java    From OpenModsLib with MIT License 5 votes vote down vote up
@Override
public void onInventoryChanged(int slotNumber) {
	super.onInventoryChanged(slotNumber);

	NBTTagCompound tag = ItemUtils.getItemTag(containerStack);
	NBTTagCompound inventoryTag = getInventoryTag(tag);
	writeToNBT(inventoryTag);
	tag.setTag(TAG_INVENTORY, inventoryTag);
	containerStack.setTagCompound(tag);
}
 
Example #8
Source File: FingerprintMetaProvider.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
@Override
public Object getMeta(Item target, ItemStack stack) {
	final NBTTagCompound tag = stack.getTagCompound();
	return tag != null? ItemUtils.getNBTHash(tag) : null;
}
 
Example #9
Source File: ItemFingerprint.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
public ItemFingerprint(Item item, int damage, NBTTagCompound tag) {
	String itemId = GameData.getItemRegistry().getNameForObject(item);
	this.id = new UniqueIdentifier(itemId);
	this.damage = damage;
	this.nbtHash = tag != null? ItemUtils.getNBTHash(tag) : null;
}
 
Example #10
Source File: PlayerItemInventory.java    From OpenModsLib with MIT License 4 votes vote down vote up
private static void setGuiId(@Nonnull ItemStack stack, int id) {
	ItemUtils.getItemTag(stack).setInteger(TAG_INV, id);
}
 
Example #11
Source File: PlayerItemInventory.java    From OpenModsLib with MIT License 4 votes vote down vote up
private static int getGuiId(@Nonnull ItemStack stack) {
	return ItemUtils.getItemTag(stack).getInteger(TAG_INV);
}
 
Example #12
Source File: DropTagSerializer.java    From OpenModsLib with MIT License 4 votes vote down vote up
@Nonnull
public ItemStack write(ItemStack stack) {
	NBTTagCompound tag = ItemUtils.getItemTag(stack);
	write(tag);
	return stack;
}
 
Example #13
Source File: DropTagSerializer.java    From OpenModsLib with MIT License 4 votes vote down vote up
@Nonnull
public void read(ItemStack stack, boolean skipEmpty) {
	NBTTagCompound tag = ItemUtils.getItemTag(stack);
	read(tag, skipEmpty);
}