Skip to content

Commit

Permalink
Add FluidTankInteraction to ItemActionResult conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
Kneelawk committed Apr 27, 2024
1 parent 58ec960 commit 87fde14
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ repositories {
}

archivesBaseName = "libblockatttributes"
version = "0.15.0-pre.2"
version = "0.15.0-pre.3"

license {
header = project.file('misc/LICENSE_HEADER.txt');
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/alexiil/mc/lib/attributes/fluid/FluidVolumeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.ItemActionResult;

import alexiil.mc.lib.attributes.Simulation;
import alexiil.mc.lib.attributes.fluid.amount.FluidAmount;
Expand Down Expand Up @@ -427,6 +428,25 @@ public ActionResult asActionResult() {
return wasContainerValid() ? ActionResult.FAIL : ActionResult.PASS;
}

/** Converts this interaction result into a vanilla minecraft {@link ActionResult}, suitable for normal block or
* item "use" methods.
*
* @return
* <ol>
* <li>{@link ActionResult#SUCCESS} if {@link #didMoveAny()} returns true.</li>
* <li>{@link ActionResult#FAIL} if {@link #wasContainerValid()} returns true.</li>
* <li>{@link ActionResult#PASS} otherwise.</li>
* </ol>
* (This is based on the principle that attempting to use an empty bucket on an empty tank should return
* {@link ActionResult#FAIL}, but using an unrelated item - such as an iron ingot - should return
* {@link ActionResult#PASS}) */
public ItemActionResult asItemActionResult() {
if (didMoveAny()) {
return ItemActionResult.SUCCESS;
}
return wasContainerValid() ? ItemActionResult.FAIL : ItemActionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
}

@Deprecated(since = "0.6.0", forRemoval = true)
public int amountMoved() {
return fluidMoved.getAmount();
Expand Down

0 comments on commit 87fde14

Please sign in to comment.