#Conditionally block a recipe from being crafted.

7 messages · Page 1 of 1 (latest)

chilly ginkgo
#

I'm making a mod where there's a limited number of maces on a server, and I want to block the crafting of any more when the amount of players (with maces). I have most of the code worked out but I can't figure out how to get the crafting to work. I'm very new to modding btw this is my first mod, I mainly get through with Claude and GPT.

I tried this code and it works barely but I feel like it could be much better.

@Mixin(CraftingResultInventory.class)
public abstract class CraftingResultInventoryMixin implements RecipeUnlocker {
    @Inject(method = "setStack", at = @At("HEAD"), cancellable = true)
    private void preventMaceCrafting(int slot, ItemStack stack, CallbackInfo ci) {
        if (stack.isOf(Items.MACE) && MaceEventHandler.getPlayersWithMace().size() >= MaceEventHandler.MAX_MACE_PLAYERS) {
            ci.cancel();
        }
    }
}
lucid mantle
#

!!llm

glossy shardBOT
#

Whilst LLMs (Large Language Models) like ChatGPT and Gemini are impressive tools, **they are not recommended for first-time Fabric mod developers due to their inconsistency and potential for generating inaccurate code. **

LLMs may generate incorrect code that:

  • Targets the wrong Minecraft version, leading to outdated or incompatible features.
  • Uses incorrect mappings, causing errors or unexpected behavior.
  • Is designed for the wrong loader (NeoForge vs. Fabric), resulting in incompatibility.
  • Relies on non-existent Fabric API modules, creating code that references features that don't exist (called LLM hallucinations)

It's crucial to remember that LLMs should be seen as problem-solving aids, not code-generating machines. The output they provide often requires significant modification and understanding of Java before it can be implemented as a functional mod.

Therefore, learning Java is an absolute necessity before attempting to use any LLM-generated code in your mod. Knowing how the generated code works is key to using it effectively and fixing any problems that may arise.

lucid mantle
#

And what exactly in that code is not good for you, it looks pretty simple, you check if there are already too many maces and cancel the crafting, I am not sure about the crafting order of operations.

chilly ginkgo
#

Sorry I should've specified the issue, it was if you put a breeze rod then a heavy core, the output would still show the wind charges. I fixed it by clearing the output.

lucid mantle
#

Seems you solved it yourself.

chilly ginkgo
#
@Mixin(CraftingResultInventory.class)
public abstract class CraftingResultInventoryMixin implements RecipeUnlocker {

    @Unique
    private static final String MOD_ID = "mace-utils";
    private static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);

    @Inject(method = "setStack", at = @At("HEAD"), cancellable = true)
    private void preventMaceCrafting(int slot, ItemStack stack, CallbackInfo ci) {
        if (stack.isOf(Items.MACE) && MaceEventHandler.getPlayersWithMace().size() >= MaceEventHandler.MAX_MACE_PLAYERS) {
            ((CraftingResultInventory)(Object)this).clear();
            ci.cancel();
        }
    }
}

Code if anyone else is having the same issue