Fabricators-of-Create / Create

[Fabric Mod] Building Tools and Aesthetic Technology
MIT License
834 stars 188 forks source link

Spout won't fill Buckets #1324

Closed fabien-gigante closed 2 months ago

fabien-gigante commented 2 months ago

Describe the Bug

A spout will not fill empty buckets placed on either a depot or conveyor belt. Same behavior with all fluids. (Empty bottles are correctly filled however.)

Reproduction Steps

  1. Place a spout over a depot (or over an running conveyor belt)
  2. Fill the spout with water (or any other appropriate liquid that a bucket can take)
  3. Place empty buckets on the depot (or the belt)
  4. Output buckets are empty

Expected Result

Output buckets should be filled with water (or any other appropriate liquid).

Screenshots and Videos

2024-02-18_14 47 06 2024-02-18_14 52 47

Crash Report or Log

crash-2024-02-18_15.16.11-client.txt

Operating System

Windows 10

Mod Version

0.5.1f

Minecraft Version

1.20.1

Other Mods

Removed all other mods. Same issue.

Additional Context

Using build create-fabric-0.5.1-f-build.1242+mc1.20.1.jar

denys-duchier commented 2 months ago

please crash your game by holding F3+C for 10s and attach the crash report

fabien-gigante commented 2 months ago

Crash report attached : crash-2024-02-18_15.16.11-client.txt

drwoops commented 2 months ago

please downgrade fabric api to 0.88.1

IThundxr commented 2 months ago

please downgrade fabric api to 0.88.1

They are using the 0.5.1f builds so they dont need to do that.

drwoops commented 2 months ago

ah indeed. dev build I guess.

fabien-gigante commented 2 months ago

I tried anyway (forcing build.1242 to take fabric api to 0.88.1 by altering its json file). But still the same problem.

Interestingly, the recipe "empty bucket -> water bucket" doesn't show up in JEI. 2024-02-18_15 26 12

I also noticed (don't know if related, but it might), that item drains are outputing buckets that are still full.

fabien-gigante commented 2 months ago

I managed to temporarilly hack my way :

public class GenericItemFilling {
    public static ItemStack fillItem(Level world, long requiredAmount, ItemStack stack, FluidStack availableFluid) {
        FluidStack toFill = availableFluid.copy();
                Fluid fluid = toFill.getFluid();
                ...

                        t.commit();
            stack.shrink(1);

                        ItemVariant itemVariant = ctx.getItemVariant();
                        ItemStack container;
                        if (itemVariant.getItem() == Items.BUCKET) {
                            if (FluidHelper.isWater(fluid)) container = new ItemStack(Items.WATER_BUCKET);
                            else if (FluidHelper.isLava(fluid)) container = new ItemStack(Items.LAVA_BUCKET);
                            else if (fluid == Milk.STILL_MILK) container = new ItemStack(Items.MILK_BUCKET);
                        }
                        else container = itemVariant.toStack((int)ctx.getAmount());

                        return container;
               ...

Not a good solution , I know. But I didn't understand what the root cause was.

IThundxr commented 2 months ago

I managed to temporarilly hack my way :

public class GenericItemFilling {
  public static ItemStack fillItem(Level world, long requiredAmount, ItemStack stack, FluidStack availableFluid) {
      FluidStack toFill = availableFluid.copy();
                Fluid fluid = toFill.getFluid();
                ...

                        t.commit();
          stack.shrink(1);

                        ItemVariant itemVariant = ctx.getItemVariant();
                        ItemStack container;
                        if (itemVariant.getItem() == Items.BUCKET) {
                            if (FluidHelper.isWater(fluid)) container = new ItemStack(Items.WATER_BUCKET);
                            else if (FluidHelper.isLava(fluid)) container = new ItemStack(Items.LAVA_BUCKET);
                            else if (fluid == Milk.STILL_MILK) container = new ItemStack(Items.MILK_BUCKET);
                        }
                        else container = itemVariant.toStack((int)ctx.getAmount());

                        return container;
               ...

Not a good solution , I know. But I didn't understand what the root cause was.

Yeah the issue is ctx.getItemVariant returns a empty bucket, need to somehow apply the filled tank to it and grab the filled bucket

fabien-gigante commented 2 months ago

Isn't the exchange in the context supposed to happen here ? Do you know why it's not happening ?

public final class EmptyItemFluidStorage implements InsertionOnlyStorage<FluidVariant> {
   public long insert(FluidVariant resource, long maxAmount, TransactionContext transaction) {
   ...
            ItemVariant newVariant = emptyToFullMapping.apply(context.getItemVariant());
            if (context.exchange(newVariant, 1, transaction) == 1) {
TropheusJ commented 2 months ago

because the context is constant

fabien-gigante commented 2 months ago

Thanks, very clear. The latest version of porting_lib defines a MutableContainerItemContext that would be quite useful here. Not available on 1.20.1 though.

fabien-gigante commented 2 months ago

Just confirmed that replacing

       ContainerItemContext ctx = ContainerItemContext.withConstant(split);`

by

        ContainerItemContext ctx = new MutableContainerItemContext(split);

works like a charm indeed !

Need to find a way to properly bring this to 1.20.1, I guess...

IThundxr commented 2 months ago

Just confirmed that replacing

       ContainerItemContext ctx = ContainerItemContext.withConstant(split);`

by

        ContainerItemContext ctx = new MutableContainerItemContext(split);

works like a charm indeed !

Need to find a way to properly bring this to 1.20.1, I guess...

im working on porting it to 1.19.2 & 1.20.1 already

fabien-gigante commented 2 months ago

Impressive reponsiveness !

Do you need a distinct issue to fix "Drain won't empty Buckets" ? Same root cause, same fix, but in GenericItemEmptying this time, I think.

IThundxr commented 2 months ago

Impressive reponsiveness !

Do you need a distinct issue to fix "Drain won't empty Buckets" ? Same root cause, same fix, but in GenericItemEmptying this time, I think.

nah its fine ill fix that aswell

fabien-gigante commented 2 months ago

To fix JEI, the same modification should be made to SpoutCategory.consumeRecipes and ItemDrainCategory.consumeRecipes . (In each method, the first context creation used for test can stay constant, but the second one needs to be mutable.)

Are you including those as well, while you're at it ? Or do you prefer a distinct issue to log and fix the JEI problem separately ?

IThundxr commented 2 months ago

To fix JEI, the same modification should be made to SpoutCategory.consumeRecipes and ItemDrainCategory.consumeRecipes . (In each method, the first context creation used for test can stay constant, but the second one needs to be mutable.)

Are you including those as well, while you're at it ? Or do you prefer a distinct issue to log and fix the JEI problem separately ?

Fixed that aswell