User Tools

Site Tools


tutorial:transfer-api_fluid-containing-items

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tutorial:transfer-api_fluid-containing-items [2022/02/11 18:16] technici4ntutorial:transfer-api_fluid-containing-items [2022/02/11 18:40] (current) – external edit 127.0.0.1
Line 58: Line 58:
  
 A word of caution: don't use ''ContainerItemContext.withInitial(stack)'' unless you know what you're doing. It **does not** mutate the stack. A word of caution: don't use ''ContainerItemContext.withInitial(stack)'' unless you know what you're doing. It **does not** mutate the stack.
 +
 +==== The API in action ====
 +An example to understand what is going on: how to query a storage for the main hand of a player, and insert 1 bucket of water into it:
 +<code java>
 +PlayerEntity player;
 +
 +// Build the ContainerItemContext.
 +ContainerItemContext handContext = ContainerItemContext.ofPlayerHand(player, Hand.MAIN_HAND);
 +// Use it to query a fluid storage.
 +Storage<FluidVariant> handStorage = handContext.find(FluidStorage.ITEM);
 +if (handStorage != null) {
 + // Use the storage: any usual Storage<FluidVariant> can be attempted.
 + try (Transaction transaction = Transaction.openOuter()) {
 + handStorage.insert(FluidVariant.of(Fluids.WATER), FluidConstants.BUCKET, transaction);
 + transaction.commit();
 + }
 +}
 +</code>
 +
 +TODO:
 +  - filling an item, example from TR
 +  - using the existing base implementations for items
tutorial/transfer-api_fluid-containing-items.1644603403.txt.gz · Last modified: 2022/02/11 18:16 by technici4n