forked from DaFuqs/Spectrum
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
103 additions
and
426 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
src/main/java/de/dafuqs/spectrum/blocks/fluid/RemainderlessItemFluidStorage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package de.dafuqs.spectrum.blocks.fluid; | ||
|
||
import net.fabricmc.fabric.api.transfer.v1.context.ContainerItemContext; | ||
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; | ||
import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant; | ||
import net.fabricmc.fabric.api.transfer.v1.storage.StoragePreconditions; | ||
import net.fabricmc.fabric.api.transfer.v1.storage.base.ExtractionOnlyStorage; | ||
import net.fabricmc.fabric.api.transfer.v1.storage.base.SingleSlotStorage; | ||
import net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext; | ||
import net.minecraft.item.Item; | ||
|
||
|
||
@SuppressWarnings("UnstableApiUsage") | ||
public class RemainderlessItemFluidStorage implements ExtractionOnlyStorage<FluidVariant>, SingleSlotStorage<FluidVariant> { | ||
|
||
private final ContainerItemContext context; | ||
private final Item fullItem; | ||
private final FluidVariant containedFluid; | ||
private final long containedAmount; | ||
|
||
|
||
public RemainderlessItemFluidStorage(ContainerItemContext context, FluidVariant containedFluid, long containedAmount) { | ||
StoragePreconditions.notBlankNotNegative(containedFluid, containedAmount); | ||
|
||
this.context = context; | ||
this.fullItem = context.getItemVariant().getItem(); | ||
this.containedFluid = containedFluid; | ||
this.containedAmount = containedAmount; | ||
} | ||
|
||
@Override | ||
public long extract(FluidVariant resource, long maxAmount, TransactionContext transaction) { | ||
// If the context's item is not fullItem anymore, can't extract! | ||
if (!context.getItemVariant().isOf(fullItem)) return 0; | ||
|
||
// Make sure that the fluid and the amount match. | ||
if (resource.equals(containedFluid) && maxAmount >= containedAmount) { | ||
// If that's ok, just convert one of the full item into the empty item, copying the nbt. | ||
|
||
|
||
if (context.extract(context.getItemVariant(), 1, transaction) == 1) { | ||
// Conversion ok! | ||
return containedAmount; | ||
} | ||
} | ||
return 0; | ||
} | ||
|
||
@Override | ||
public boolean isResourceBlank() { | ||
return getResource().isBlank(); | ||
} | ||
|
||
@Override | ||
public FluidVariant getResource() { | ||
if (context.getItemVariant().isOf(fullItem)) { | ||
return containedFluid; | ||
} else { | ||
return FluidVariant.blank(); | ||
} | ||
} | ||
|
||
@Override | ||
public long getAmount() { | ||
if (context.getItemVariant().isOf(fullItem)) { | ||
return containedAmount; | ||
} else { | ||
return 0; | ||
} | ||
} | ||
|
||
@Override | ||
public long getCapacity() { | ||
return getAmount(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "FullItemFluidStorage[context=%s, fluid=%s, amount=%d]" | ||
.formatted(context, containedFluid, containedAmount); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 0 additions & 119 deletions
119
src/main/resources/data/spectrum/recipes/titration_barrel/bristle_mead_fluid.json
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 0 additions & 25 deletions
25
src/main/resources/data/spectrum/recipes/titration_barrel/clotted_cream_fluid.json
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.