Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Wrong Products Count of Smelting Raw Cassiterite Sand #210

Closed
Phoupraw opened this issue Jul 26, 2023 · 7 comments
Closed

[Bug] Wrong Products Count of Smelting Raw Cassiterite Sand #210

Phoupraw opened this issue Jul 26, 2023 · 7 comments
Labels
type: bug Something isn't working

Comments

@Phoupraw
Copy link
Contributor

GregTech CEu Version

1.20.1-1.0.8

Recipe Viewer Installed

EMI

Environment

Singleplayer

Cross-Mod Interaction

No

Expected Behavior

EMI shows that I can get two tin ingots from each raw cassiterite sand.
image

Actual Behavior

When I smelted 32 sands in furnace, I only got 33 ingots.

Steps to Reproduce

  1. Put 32 raw cassiterite sands into the ingredient slot of a furnace.
  2. Put enough fuel in the fuel slot of the furnace.
  3. Wait for smelting.
  4. There are only 33 tin ingots in the result slot of the furnace in the end.

Additional Information

It seems that if there is existing ingots in the result slot of furnace, following smelting only produces one ingot.

@Phoupraw Phoupraw added the type: bug Something isn't working label Jul 26, 2023
@screret
Copy link
Member

screret commented Jul 26, 2023

This is an, uhh, fundamental flaw in the furnace's logic that forge patches

Guess we'll have to do that too

@Phoupraw
Copy link
Contributor Author

Phoupraw commented Jul 26, 2023

This is an, uhh, fundamental flaw in the furnace's logic that forge patches

Guess we'll have to do that too

But this is in fabric.

@Phoupraw
Copy link
Contributor Author

Phoupraw commented Aug 3, 2023

I fixed it by mixin:

@Mixin(AbstractFurnaceBlockEntity.class)
abstract class MAbstractFurnaceBlockEntity {

    @Unique
    private static final ThreadLocal<ItemStack> LOCAL_craftRecipe_itemStack2 = new ThreadLocal<>();
    
    @Redirect(method = "craftRecipe", at = @At(value = "INVOKE", target = "Lnet/minecraft/recipe/Recipe;getOutput(Lnet/minecraft/registry/DynamicRegistryManager;)Lnet/minecraft/item/ItemStack;"))
    private static ItemStack correctIncrement(Recipe<?> instance, DynamicRegistryManager dynamicRegistryManager) {
        var r = instance.getOutput(dynamicRegistryManager);
        LOCAL_craftRecipe_itemStack2.set(r);
        return r;
    }

    @Redirect(method = "craftRecipe", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;increment(I)V"))
    private static void correctIncrement(ItemStack instance, int amount) {
        ItemStack output = LOCAL_craftRecipe_itemStack2.get();
        if (output == null) {
            instance.increment(amount);
        } else {
            instance.increment(output.getCount());
        }
    }

}

@screret
Copy link
Member

screret commented Aug 3, 2023

maybe PR this to fabric API as well? so it could get actually fixed for everyone

@Phoupraw
Copy link
Contributor Author

Phoupraw commented Aug 3, 2023

maybe PR this to fabric API as well? so it could get actually fixed for everyone

My mixin doesn't entirely solve the bug. It doesn't check the count of the existing result stack to avoid over max count. It just prevents loss in survival gameplay.

@Phoupraw
Copy link
Contributor Author

Phoupraw commented Aug 4, 2023

maybe PR this to fabric API as well? so it could get actually fixed for everyone

My mixin doesn't entirely solve the bug. It doesn't check the count of the existing result stack to avoid over max count. It just prevents loss in survival gameplay.

I completely sovled the bug. Now the count won't increase to over max count.

@Mixin(AbstractFurnaceBlockEntity.class)
abstract class MAbstractFurnaceBlockEntity {

    @Unique
    private static final ThreadLocal<ItemStack> LOCAL_recipe_output = new ThreadLocal<>();

    @Redirect(method = "craftRecipe", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;increment(I)V"))
    private static void correctIncrement(ItemStack instance, int amount) {
        ItemStack output = LOCAL_recipe_output.get();
        if (output == null) {
            Enchantist.LOGGER.error("LOCAL_recipe_output.get() == null");
            instance.increment(amount);
        } else {
            instance.increment(output.getCount());
        }
    }

    /**
     @param itemStack recipe output
     @param itemStack2 output slot
     */
    @Inject(method = "canAcceptRecipeOutput", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;areItemsEqual(Lnet/minecraft/item/ItemStack;Lnet/minecraft/item/ItemStack;)Z"), cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD)
    private static void correctPredicate(DynamicRegistryManager registryManager, @Nullable Recipe<?> recipe, DefaultedList<ItemStack> slots, int count, CallbackInfoReturnable<Boolean> cir, ItemStack itemStack, ItemStack itemStack2) {
        LOCAL_recipe_output.set(itemStack);
        cir.setReturnValue(itemStack2.isEmpty() || ItemStack.canCombine(itemStack, itemStack2) && itemStack.getCount() + itemStack2.getCount() <= itemStack2.getMaxCount());
    }

}

@screret
Copy link
Member

screret commented Jan 13, 2024

fabric is deead, fabric is dee-ee-eeaaad

@screret screret closed this as not planned Won't fix, can't repro, duplicate, stale Jan 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants