Skip to content

Commit

Permalink
Register purified water bucket as fluid storage
Browse files Browse the repository at this point in the history
  • Loading branch information
Tiviacz1337 committed Mar 19, 2024
1 parent 5bcde54 commit 4f2e7b5
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/main/java/net/dehydration/init/FluidInit.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
package net.dehydration.init;

import net.dehydration.fluid.PurifiedWaterFluid;
import net.dehydration.item.PurifiedBucket;
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidConstants;
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidStorage;
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant;
import net.fabricmc.fabric.api.transfer.v1.fluid.base.EmptyItemFluidStorage;
import net.fabricmc.fabric.api.transfer.v1.fluid.base.FullItemFluidStorage;
import net.minecraft.fluid.FlowableFluid;
import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.FluidState;
import net.minecraft.item.Items;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;

Expand All @@ -12,7 +19,27 @@ public class FluidInit {
public static final FlowableFluid PURIFIED_FLOWING_WATER = register("dehydration:purified_flowing_water", new PurifiedWaterFluid.Flowing());
public static final FlowableFluid PURIFIED_WATER = register("dehydration:purified_water", new PurifiedWaterFluid.Still());

public static void init() {
public static void init()
{
initFluidStorage();
}

private static void initFluidStorage()
{
FluidStorage.GENERAL_COMBINED_PROVIDER.register(context ->
{
if(context.getItemVariant().getItem() instanceof PurifiedBucket bucketItem)
{
Fluid bucketFluid = FluidInit.PURIFIED_WATER;
if(bucketFluid != null && bucketFluid.getBucketItem() == bucketItem)
{
return new FullItemFluidStorage(context, Items.BUCKET, FluidVariant.of(bucketFluid), FluidConstants.BUCKET);
}
}
return null;
});

FluidStorage.combinedItemApiProvider(Items.BUCKET).register(context -> new EmptyItemFluidStorage(context, ItemInit.PURIFIED_BUCKET, FluidInit.PURIFIED_WATER, FluidConstants.BUCKET));
}

private static <T extends Fluid> T register(String id, T value) {
Expand Down

0 comments on commit 4f2e7b5

Please sign in to comment.