package net.radsteve.islanders.mixin; import com.llamalad7.mixinextras.sugar.Local; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.inventory.CraftingResultInventory; import net.minecraft.inventory.RecipeInputInventory; import net.minecraft.item.ItemStack; import net.minecraft.recipe.CraftingRecipe; import net.minecraft.recipe.RecipeEntry; import net.minecraft.screen.CraftingScreenHandler; import net.minecraft.screen.ScreenHandler; import net.minecraft.server.world.ServerWorld; import net.radsteve.islanders.Islanders; import net.radsteve.islanders.IslandersData; import net.radsteve.islanders.SpecialItem; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(CraftingScreenHandler.class) public class CraftingScreenHandlerMixin { @Inject(method = "updateResult", at = @At(value = "INVOKE", target = "Lnet/minecraft/inventory/CraftingResultInventory;setStack(ILnet/minecraft/item/ItemStack;)V"), cancellable = true) private static void islanders$updateResult( ScreenHandler handler, ServerWorld world, PlayerEntity player, RecipeInputInventory craftingInventory, CraftingResultInventory resultInventory, @Nullable RecipeEntry recipe, CallbackInfo ci, @Local ItemStack result ) { if (SpecialItem.Crown.check(result) && IslandersData.INSTANCE.obtained("crown")) { Islanders.getLogger().info("{} tried crafting crown which was already obtained", player.getNameForScoreboard()); ci.cancel(); } } }