User Tools

Site Tools


tutorial:transfer-api_fluid_implementation

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_implementation [2022/02/02 20:27] – [A more involved example] technici4ntutorial:transfer-api_fluid_implementation [2022/02/02 20:28] (current) – [Internal tanks] technici4n
Line 1: Line 1:
-===== Fabric Transfer API: How to implement Storage<FluidVariant> =====+====== Fabric Transfer API: How to implement Storage<FluidVariant> ======
 //This article is part of a series on the Fabric Transfer API. [[tutorial:transfer-api|Link to the home page of the series]].// //This article is part of a series on the Fabric Transfer API. [[tutorial:transfer-api|Link to the home page of the series]].//
  
Line 5: Line 5:
 It's possible to implement directly by implementing the interface and filling the methods, but Fabric API already provides many implementations that you can use and combine for almost any task. It's possible to implement directly by implementing the interface and filling the methods, but Fabric API already provides many implementations that you can use and combine for almost any task.
  
-==== Overview of the base implementations ==== +===== Overview of the base implementations ===== 
-=== SingleVariantStorage ===+==== SingleVariantStorage ====
 [[https://github.com/FabricMC/fabric/blob/1.18/fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/api/transfer/v1/storage/base/SingleVariantStorage.java|SingleVariantStorage<FluidVariant>]] is a storage implementation that can only store a single fluid at a given time. It's suitable for a single tank or "fluid slot". [[https://github.com/FabricMC/fabric/blob/1.18/fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/api/transfer/v1/storage/base/SingleVariantStorage.java|SingleVariantStorage<FluidVariant>]] is a storage implementation that can only store a single fluid at a given time. It's suitable for a single tank or "fluid slot".
  
Line 41: Line 41:
 </code> </code>
  
-=== FilteringStorage ===+==== FilteringStorage ====
 [[https://github.com/FabricMC/fabric/blob/1.18/fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/api/transfer/v1/storage/base/FilteringStorage.java|FilteringStorage]] can filter access to another existing storage. [[https://github.com/FabricMC/fabric/blob/1.18/fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/api/transfer/v1/storage/base/FilteringStorage.java|FilteringStorage]] can filter access to another existing storage.
  
Line 58: Line 58:
 Subclassing ''FilteringStorage'' and overriding ''canInsert'' and/or ''canExtract'' is also possible if more advanced filtering is necessary. Subclassing ''FilteringStorage'' and overriding ''canInsert'' and/or ''canExtract'' is also possible if more advanced filtering is necessary.
  
-=== CombinedStorage ===+==== CombinedStorage ====
 [[https://github.com/FabricMC/fabric/blob/1.18/fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/api/transfer/v1/storage/base/CombinedStorage.java|CombinedStorage]] can create a ''Storage'' that wraps multiple storages. [[https://github.com/FabricMC/fabric/blob/1.18/fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/api/transfer/v1/storage/base/CombinedStorage.java|CombinedStorage]] can create a ''Storage'' that wraps multiple storages.
  
Line 70: Line 70:
  
  
-==== A more involved example ====+===== A more involved example =====
 To better understand how these classes can be combined together, let's write a machine that converts water to lava. Here are our requirements: To better understand how these classes can be combined together, let's write a machine that converts water to lava. Here are our requirements:
   * The machine will have two internal "tanks" that can store 4 buckets each: one tank that contains water, and one that contains lava.   * The machine will have two internal "tanks" that can store 4 buckets each: one tank that contains water, and one that contains lava.
Line 81: Line 81:
 Finally, we will use ''CombinedStorage'' so that both tanks can be accessed from the sides. Finally, we will use ''CombinedStorage'' so that both tanks can be accessed from the sides.
  
-=== Internal tanks ===+==== Internal tanks ====
 First, let's add the internal tanks to the block entity: First, let's add the internal tanks to the block entity:
 <code java> <code java>
Line 124: Line 124:
  
  // ... [other code omitted]  // ... [other code omitted]
 +}
 </code> </code>
  
-=== Conversion logic ===+==== Conversion logic ====
 The conversion logic is straightforward: The conversion logic is straightforward:
 <code java> <code java>
Line 143: Line 144:
 </code> </code>
  
-=== Exposing the tanks to external pipes ===+==== Exposing the tanks to external pipes ====
 We can use the filtering and combined storages to ensure that pipes can only do what we want them to do: We can use the filtering and combined storages to ensure that pipes can only do what we want them to do:
 <code java> <code java>
tutorial/transfer-api_fluid_implementation.1643833625.txt.gz · Last modified: 2022/02/02 20:27 by technici4n