Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Cancel opening the trade container to open my own GUI

Featured Replies

Posted

I added a villager, and when that villager is right clicked it should open a custom gui instead of the villager trading gui. I got as far as using AT to get the IMerchant value and now I know when its the villager I added.

But the event is uncancelable and if I open my GUI first then the container of the tradegui will just open after it. Is there a way I can do this?

 

I have already looked into GuiOpenEvent but that way I cannot get the container. If I grab either container variable from the player its a ContainerPlayer which is the inventory.

 

Code:

    @SubscribeEvent
    public static void onOpenVillagerGUI(PlayerContainerEvent.Open event){
        if(event.getContainer() instanceof ContainerMerchant){
            ContainerMerchant merchantContainer = (ContainerMerchant) event.getContainer();
            InventoryMerchant merchant = merchantContainer.getMerchantInventory();
            if(!(merchant.merchant instanceof EntityVillager)){
                return;
            }

            EntityVillager villager = (EntityVillager) merchant.merchant;

            if(villager.getProfessionForge().getRegistryName().toString()
                    .equalsIgnoreCase(ModVillage.OLD_PRIEST_PROFESSION.getRegistryName().toString())){

                Minecraft.getMinecraft().player.openGui(Solar.instance, GuiHandler.GUIDE_BOOK_ID_GUI, event.getEntityPlayer().getEntityWorld(), 0, 0, 0);
            }

        }
    }

 

How would I stop the opening, or close it and then open my own GUI?

I think the gui open event should work. The gui that is passed in can be tested to see if it is a GuiMerchant and if so then you should be able to cast it as GuiMerchant and then get the container since the inventorySlots field is public.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.