-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split HTIngredient to HTItemIngredient and HTFluidIngredient
Added new item Fluid/Item Filter for Exporter
- Loading branch information
1 parent
21e1b2a
commit d2a4224
Showing
35 changed files
with
490 additions
and
341 deletions.
There are no files selected for viewing
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
6 changes: 6 additions & 0 deletions
6
src/main/generated/assets/ragium/models/item/fluid_filter.json
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,6 @@ | ||
{ | ||
"parent": "minecraft:item/generated", | ||
"textures": { | ||
"layer0": "ragium:item/fluid_filter" | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/generated/assets/ragium/models/item/item_filter.json
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,6 @@ | ||
{ | ||
"parent": "minecraft:item/generated", | ||
"textures": { | ||
"layer0": "ragium:item/item_filter" | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/generated/data/ragium/tags/item/exporter_filters/fluid.json
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,5 @@ | ||
{ | ||
"values": [ | ||
"ragium:fluid_filter" | ||
] | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/generated/data/ragium/tags/item/exporter_filters/item.json
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,5 @@ | ||
{ | ||
"values": [ | ||
"ragium:item_filter" | ||
] | ||
} |
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
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
104 changes: 104 additions & 0 deletions
104
src/main/kotlin/hiiragi283/ragium/api/recipe/HTFluidIngredient.kt
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,104 @@ | ||
package hiiragi283.ragium.api.recipe | ||
|
||
import com.mojang.serialization.Codec | ||
import com.mojang.serialization.codecs.RecordCodecBuilder | ||
import hiiragi283.ragium.api.extension.contains | ||
import hiiragi283.ragium.api.extension.isOf | ||
import hiiragi283.ragium.api.extension.longRangeCodec | ||
import hiiragi283.ragium.api.extension.useTransaction | ||
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidConstants | ||
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant | ||
import net.fabricmc.fabric.api.transfer.v1.storage.StorageUtil | ||
import net.fabricmc.fabric.api.transfer.v1.storage.base.ResourceAmount | ||
import net.fabricmc.fabric.api.transfer.v1.storage.base.SingleSlotStorage | ||
import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction | ||
import net.minecraft.fluid.Fluid | ||
import net.minecraft.fluid.Fluids | ||
import net.minecraft.network.RegistryByteBuf | ||
import net.minecraft.network.codec.PacketCodec | ||
import net.minecraft.network.codec.PacketCodecs | ||
import net.minecraft.registry.Registries | ||
import net.minecraft.registry.RegistryCodecs | ||
import net.minecraft.registry.RegistryKeys | ||
import net.minecraft.registry.entry.RegistryEntry | ||
import net.minecraft.registry.entry.RegistryEntryList | ||
import net.minecraft.registry.tag.TagKey | ||
import java.util.function.BiPredicate | ||
|
||
class HTFluidIngredient private constructor(private val entryList: RegistryEntryList<Fluid>, val amount: Long) : BiPredicate<Fluid, Long> { | ||
companion object { | ||
@JvmField | ||
val CODEC: Codec<HTFluidIngredient> = RecordCodecBuilder.create { instance -> | ||
instance | ||
.group( | ||
RegistryCodecs | ||
.entryList(RegistryKeys.FLUID) | ||
.fieldOf("fluids") | ||
.forGetter(HTFluidIngredient::entryList), | ||
longRangeCodec(1, Long.MAX_VALUE) | ||
.optionalFieldOf("amount", FluidConstants.BUCKET) | ||
.forGetter(HTFluidIngredient::amount), | ||
).apply(instance, ::HTFluidIngredient) | ||
} | ||
|
||
@JvmField | ||
val PACKET_CODEC: PacketCodec<RegistryByteBuf, HTFluidIngredient> = PacketCodec | ||
.tuple( | ||
PacketCodecs.registryEntryList(RegistryKeys.FLUID), | ||
HTFluidIngredient::entryList, | ||
PacketCodecs.VAR_LONG, | ||
HTFluidIngredient::amount, | ||
::HTFluidIngredient, | ||
) | ||
|
||
@JvmStatic | ||
fun of(fluid: Fluid, amount: Long = FluidConstants.BUCKET): HTFluidIngredient = | ||
HTFluidIngredient(RegistryEntryList.of(fluid.registryEntry), amount) | ||
|
||
@JvmStatic | ||
fun of(tagKey: TagKey<Fluid>, amount: Long = FluidConstants.BUCKET): HTFluidIngredient = | ||
HTFluidIngredient(Registries.FLUID.getOrCreateEntryList(tagKey), amount) | ||
} | ||
|
||
val isEmpty: Boolean | ||
get() = entryList.storage.map( | ||
{ false }, | ||
{ it.isEmpty() || it.any { entry: RegistryEntry<Fluid> -> entry.isOf(Fluids.EMPTY) } }, | ||
) || | ||
amount <= 0 | ||
|
||
fun <T : Any> map(transform: (RegistryEntry<Fluid>, Long) -> T): List<T> = entryList.map { transform(it, amount) } | ||
|
||
val firstEntry: RegistryEntry<Fluid>? | ||
get() = entryList.firstOrNull() | ||
|
||
val entryMap: Map<RegistryEntry<Fluid>, Long> = entryList.associateWith { amount } | ||
|
||
val valueMap: Map<Fluid, Long> | ||
get() = entryMap.mapKeys { it.key.value() } | ||
|
||
fun test(resource: ResourceAmount<FluidVariant>): Boolean = test(resource.resource.fluid, resource.amount) | ||
|
||
override fun test(fluid: Fluid, amount: Long): Boolean = when { | ||
fluid == Fluids.EMPTY || amount <= 0 -> this.isEmpty | ||
else -> fluid in entryList && amount >= this.amount | ||
} | ||
|
||
fun onConsume(storage: SingleSlotStorage<FluidVariant>) { | ||
useTransaction { transaction: Transaction -> | ||
val foundVariant: FluidVariant = StorageUtil.findExtractableResource( | ||
storage, | ||
{ test(it.fluid, storage.amount) }, | ||
transaction, | ||
) ?: return | ||
if (test(foundVariant.fluid, amount)) { | ||
val extracted: Long = storage.extract(foundVariant, amount, transaction) | ||
if (extracted == amount) { | ||
transaction.commit() | ||
} else { | ||
transaction.abort() | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.