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();
}
}
}