package com.ambientaddons.mixin; import com.ambientaddons.events.GuiContainerEvent; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.inventory.Container; import net.minecraft.inventory.Slot; import net.minecraftforge.common.MinecraftForge; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; // credit Harry282/Skyblock-Client, under AGPL 3.0 @Mixin(GuiContainer.class) public abstract class MixinGuiContainer extends GuiScreen { private final GuiContainer gui = (GuiContainer) (Object) this; @Shadow public Container inventorySlots; @Inject(method = "drawSlot", at = @At("HEAD"), cancellable = true) private void onDrawSlot(Slot slot, CallbackInfo ci) { if (MinecraftForge.EVENT_BUS.post(new GuiContainerEvent.DrawSlotEvent(inventorySlots, gui, slot))) { ci.cancel(); } } @Inject(method = "handleMouseClick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/PlayerControllerMP;windowClick(IIIILnet/minecraft/entity/player/EntityPlayer;)Lnet/minecraft/item/ItemStack;"), cancellable = true) private void onMouseClick(Slot slot, int slotId, int clickedButton, int clickType, CallbackInfo ci) { if (MinecraftForge.EVENT_BUS.post(new GuiContainerEvent.SlotClickEvent(inventorySlots, gui, slot, slotId))) { ci.cancel(); } } }