Search in sources :

Example 6 with AbstractContainerScreen

use of net.minecraft.client.gui.screens.inventory.AbstractContainerScreen in project Silent-Gear by SilentChaos512.

the class KeyTracker method getHoveredItem.

private static ItemStack getHoveredItem() {
    Screen currentScreen = Minecraft.getInstance().screen;
    if (currentScreen instanceof AbstractContainerScreen<?>) {
        AbstractContainerScreen<?> containerScreen = (AbstractContainerScreen<?>) currentScreen;
        Slot slot = containerScreen.getSlotUnderMouse();
        if (slot != null) {
            return slot.getItem();
        }
    }
    return ItemStack.EMPTY;
}
Also used : Screen(net.minecraft.client.gui.screens.Screen) AbstractContainerScreen(net.minecraft.client.gui.screens.inventory.AbstractContainerScreen) AbstractContainerScreen(net.minecraft.client.gui.screens.inventory.AbstractContainerScreen) Slot(net.minecraft.world.inventory.Slot)

Example 7 with AbstractContainerScreen

use of net.minecraft.client.gui.screens.inventory.AbstractContainerScreen in project Silent-Gear by SilentChaos512.

the class KeyTracker method getHoveredSlot.

private static int getHoveredSlot() {
    Screen currentScreen = Minecraft.getInstance().screen;
    if (currentScreen instanceof AbstractContainerScreen<?>) {
        AbstractContainerScreen<?> containerScreen = (AbstractContainerScreen<?>) currentScreen;
        Slot slot = containerScreen.getSlotUnderMouse();
        if (slot != null) {
            return slot.index;
        }
    }
    return -1;
}
Also used : Screen(net.minecraft.client.gui.screens.Screen) AbstractContainerScreen(net.minecraft.client.gui.screens.inventory.AbstractContainerScreen) AbstractContainerScreen(net.minecraft.client.gui.screens.inventory.AbstractContainerScreen) Slot(net.minecraft.world.inventory.Slot)

Example 8 with AbstractContainerScreen

use of net.minecraft.client.gui.screens.inventory.AbstractContainerScreen in project Balm by ModdingForBlockheads.

the class AbstractContainerScreenMixin method renderBackground.

@Inject(method = "render(Lcom/mojang/blaze3d/vertex/PoseStack;IIF)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screens/inventory/AbstractContainerScreen;renderBg(Lcom/mojang/blaze3d/vertex/PoseStack;FII)V", shift = At.Shift.AFTER))
public void renderBackground(PoseStack poseStack, int mouseX, int mouseY, float partialTicks, CallbackInfo callbackInfo) {
    Screen screen = (Screen) (Object) this;
    Balm.getEvents().fireEvent(new ContainerScreenDrawEvent.Background(screen, poseStack, mouseX, mouseY));
}
Also used : Screen(net.minecraft.client.gui.screens.Screen) AbstractContainerScreen(net.minecraft.client.gui.screens.inventory.AbstractContainerScreen) ContainerScreenDrawEvent(net.blay09.mods.balm.api.event.client.screen.ContainerScreenDrawEvent) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 9 with AbstractContainerScreen

use of net.minecraft.client.gui.screens.inventory.AbstractContainerScreen in project Cyclic by Lothrazar.

the class ClientInputEvents method onMouseEvent.

@SubscribeEvent(priority = EventPriority.HIGH)
public void onMouseEvent(ScreenEvent.MouseClickedEvent.Pre event) {
    if (event.getScreen() == null || !(event.getScreen() instanceof AbstractContainerScreen<?>)) {
        return;
    }
    AbstractContainerScreen<?> gui = (AbstractContainerScreen<?>) event.getScreen();
    boolean rightClickDown = event.getButton() == 1;
    try {
        if (rightClickDown && gui.getSlotUnderMouse() != null) {
            Slot slotHit = gui.getSlotUnderMouse();
            if (!slotHit.getItem().isEmpty()) {
                ItemStack maybeCharm = slotHit.getItem();
                if (maybeCharm.getItem() instanceof IHasClickToggle) {
                    PacketRegistry.INSTANCE.sendToServer(new PacketItemToggle(slotHit.index));
                    event.setCanceled(true);
                // UtilSound.playSound(ModCyclic.proxy.getClientPlayer(), SoundEvents.UI_BUTTON_CLICK);
                } else if (maybeCharm.getItem() instanceof ItemStorageBag) {
                    PacketRegistry.INSTANCE.sendToServer(new PacketItemGui(slotHit.index));
                    event.setCanceled(true);
                }
            }
        }
    } catch (Exception e) {
        // array out of bounds, or we are in a strange third party GUI that doesnt have slots like this
        // EXAMPLE:  mod.chiselsandbits.bitbag.BagGui
        ModCyclic.LOGGER.error("click error", e);
    // so this fixes ithttps://github.com/PrinceOfAmber/Cyclic/issues/410
    }
}
Also used : PacketItemToggle(com.lothrazar.cyclic.net.PacketItemToggle) IHasClickToggle(com.lothrazar.cyclic.api.IHasClickToggle) AbstractContainerScreen(net.minecraft.client.gui.screens.inventory.AbstractContainerScreen) PacketItemGui(com.lothrazar.cyclic.net.PacketItemGui) Slot(net.minecraft.world.inventory.Slot) ItemStack(net.minecraft.world.item.ItemStack) ItemStorageBag(com.lothrazar.cyclic.item.storagebag.ItemStorageBag) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Aggregations

AbstractContainerScreen (net.minecraft.client.gui.screens.inventory.AbstractContainerScreen)9 Screen (net.minecraft.client.gui.screens.Screen)6 ItemStack (net.minecraft.world.item.ItemStack)4 Minecraft (net.minecraft.client.Minecraft)3 Slot (net.minecraft.world.inventory.Slot)3 ContainerScreenDrawEvent (net.blay09.mods.balm.api.event.client.screen.ContainerScreenDrawEvent)2 InventoryScreen (net.minecraft.client.gui.screens.inventory.InventoryScreen)2 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)2 Inject (org.spongepowered.asm.mixin.injection.Inject)2 IHasClickToggle (com.lothrazar.cyclic.api.IHasClickToggle)1 ItemStorageBag (com.lothrazar.cyclic.item.storagebag.ItemStorageBag)1 PacketItemGui (com.lothrazar.cyclic.net.PacketItemGui)1 PacketItemToggle (com.lothrazar.cyclic.net.PacketItemToggle)1 Config (io.github.lightman314.lightmanscurrency.Config)1 CurrencySoundEvents (io.github.lightman314.lightmanscurrency.CurrencySoundEvents)1 LightmansCurrency (io.github.lightman314.lightmanscurrency.LightmansCurrency)1 WalletScreen (io.github.lightman314.lightmanscurrency.client.gui.screen.inventory.WalletScreen)1 WalletButton (io.github.lightman314.lightmanscurrency.client.gui.widget.button.WalletButton)1 WalletItem (io.github.lightman314.lightmanscurrency.items.WalletItem)1 LightmansCurrencyPacketHandler (io.github.lightman314.lightmanscurrency.network.LightmansCurrencyPacketHandler)1