mod for the islanders smp
1package net.radsteve.islanders.mixin;
2
3import com.llamalad7.mixinextras.sugar.Local;
4import net.minecraft.entity.player.PlayerEntity;
5import net.minecraft.inventory.CraftingResultInventory;
6import net.minecraft.inventory.RecipeInputInventory;
7import net.minecraft.item.ItemStack;
8import net.minecraft.recipe.CraftingRecipe;
9import net.minecraft.recipe.RecipeEntry;
10import net.minecraft.screen.CraftingScreenHandler;
11import net.minecraft.screen.ScreenHandler;
12import net.minecraft.server.world.ServerWorld;
13import net.radsteve.islanders.Islanders;
14import net.radsteve.islanders.IslandersData;
15import net.radsteve.islanders.SpecialItem;
16import org.jetbrains.annotations.Nullable;
17import org.spongepowered.asm.mixin.Mixin;
18import org.spongepowered.asm.mixin.injection.At;
19import org.spongepowered.asm.mixin.injection.Inject;
20import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
21
22@Mixin(CraftingScreenHandler.class)
23public class CraftingScreenHandlerMixin {
24 @Inject(method = "updateResult", at = @At(value = "INVOKE", target = "Lnet/minecraft/inventory/CraftingResultInventory;setStack(ILnet/minecraft/item/ItemStack;)V"), cancellable = true)
25 private static void islanders$updateResult(
26 ScreenHandler handler,
27 ServerWorld world,
28 PlayerEntity player,
29 RecipeInputInventory craftingInventory,
30 CraftingResultInventory resultInventory,
31 @Nullable RecipeEntry<CraftingRecipe> recipe,
32 CallbackInfo ci,
33 @Local ItemStack result
34 ) {
35 if (SpecialItem.Crown.check(result) && IslandersData.INSTANCE.obtained("crown")) {
36 Islanders.getLogger().info("{} tried crafting crown which was already obtained", player.getNameForScoreboard());
37 ci.cancel();
38 }
39 }
40}