Example usage for net.minecraftforge.client.event GuiOpenEvent getGui

List of usage examples for net.minecraftforge.client.event GuiOpenEvent getGui

Introduction

In this page you can find the example usage for net.minecraftforge.client.event GuiOpenEvent getGui.

Prototype

public Screen getGui() 

Source Link

Usage

From source file:com.crowsofwar.avatar.client.AvatarClientProxy.java

License:Open Source License

@SubscribeEvent
public void onMainMenu(GuiOpenEvent e) {
    if (AvatarInfo.IS_PREVIEW && e.getGui() instanceof GuiMainMenu && !displayedMainMenu) {
        GuiScreen screen = new PreviewWarningGui();
        mc.displayGuiScreen(screen);//w  ww.ja  va2s  .c  om
        e.setGui(screen);
        displayedMainMenu = true;
    }
}

From source file:com.specialeffect.mods.moving.MouseHandler.java

License:Open Source License

@SubscribeEvent
public void onGuiOpen(GuiOpenEvent event) {
    // It's important that when the 'controls' menu is opened, we are
    // not overriding the sensitivity setting. It's also important that
    // we get any user updates to sensitivity.

    // This corresponds to the opening of the controls pane 
    if (null != event.getGui() && event.getGui().getClass() == GuiControls.class) {
        this.resetSensitivity();
    }//from  www . j  av  a 2 s  . c  o  m
    // This corresponds to the opening/closing of *any other pane*.
    // NB: Important to know that new screens are opened before the controls
    // pane is closed; and close events don't have guiscreens attached to them.
    else {
        this.querySensitivity();
    }

    // For any  open event, make sure cursor not overridden
    if (null != event.getGui()) {
        try {
            Mouse.setNativeCursor(null);
        } catch (LWJGLException e) {
        }
    } else {
        // For any close event, make sure we're in the right 'grabbed' state.
        // (also sets cursor if applicable)
        if (mInputSource == InputSource.Mouse) {
            this.setMouseNotGrabbed();
        }
    }
}

From source file:de.canitzp.rarmor.event.ClientEvents.java

@SubscribeEvent
public static void onOpenGui(GuiOpenEvent event) {
    if (!stopGuiOverride) {
        if (event.getGui() instanceof GuiInventory) {
            EntityPlayer player = Minecraft.getMinecraft().player;
            int openingMode = Config.rarmorOpeningMode;
            boolean sneaking = player.isSneaking();
            if (openingMode == 2 || (openingMode == 0 && !sneaking) || (openingMode == 1 && sneaking)) {
                IRarmorData data = RarmorAPI.methodHandler.getDataForChestplate(player, true);
                if (data != null) {
                    openRarmor(player, data);
                    event.setCanceled(true);
                }//from   w w  w  . j a  va  2  s . c o m
            }
        }
    }
}

From source file:hellfirepvp.astralsorcery.client.event.ClientRenderEventHandler.java

License:Open Source License

@SubscribeEvent
@SideOnly(Side.CLIENT)/*www  .j  av a 2 s  . c o  m*/
public void onOpen(GuiOpenEvent event) {
    if (event.getGui() instanceof GuiScreenJournal) {
        SoundHelper.playSoundClient(Sounds.bookFlip, 1F, 1F);
    }
    if (Minecraft.getMinecraft().currentScreen != null
            && Minecraft.getMinecraft().currentScreen instanceof GuiScreenJournal
            && (event.getGui() == null || !(event.getGui() instanceof GuiScreenJournal))) {
        SoundHelper.playSoundClient(Sounds.bookClose, 1F, 1F);
    }
}

From source file:jayavery.geomastery.main.ClientEvents.java

License:Open Source License

/** Alters which vanilla Gui is opened. */
@SubscribeEvent/*from w w  w . j a  v  a 2 s  .  co  m*/
public void guiOpen(GuiOpenEvent event) {

    EntityPlayer player = Minecraft.getMinecraft().player;

    if (event.getGui() instanceof net.minecraft.client.gui.inventory.GuiInventory
            && player.inventoryContainer instanceof ContainerInventory) {

        event.setGui(new jayavery.geomastery.gui.GuiInventory((ContainerInventory) player.inventoryContainer));
    }
}

From source file:org.blockartistry.DynSurround.client.gui.HumDinger.java

License:MIT License

@SubscribeEvent
public static void onGuiOpen(@Nonnull final GuiOpenEvent event) {
    if (!hasPlayed && event.getGui() instanceof GuiMainMenu) {
        hasPlayed = true;//from   w w  w . j a v  a 2  s  . com
        final SoundEvent se = SoundEvent.REGISTRY
                .getObject(new ResourceLocation(possibles[XorShiftRandom.current().nextInt(possibles.length)]));
        SoundEngine.instance().playSound(new AdhocSound(se, SoundCategory.MASTER));
    }
}

From source file:tv.rewinside.rewimod.forge.listener.GuiListener.java

License:Open Source License

@SubscribeEvent
public void onGuiOpen(GuiOpenEvent event) {
    if (event.getGui() instanceof GuiMainMenu) {
        event.setGui(new GuiRewiMainMenu());
    }//from   w  w  w.ja  v  a  2  s.  c  o m
}

From source file:vazkii.quark.client.feature.PanoramaMaker.java

License:Creative Commons License

@SubscribeEvent
public void loadMainMenu(GuiOpenEvent event) {
    if (overrideMainMenu && !overridenOnce && event.getGui() instanceof GuiMainMenu) {
        File mcDir = ModuleLoader.configFile.getParentFile().getParentFile();
        File panoramasDir = new File(mcDir, "/screenshots/panoramas");

        List<File[]> validFiles = new ArrayList();

        ImmutableSet<String> set = ImmutableSet.of("panorama_0.png", "panorama_1.png", "panorama_2.png",
                "panorama_3.png", "panorama_4.png", "panorama_5.png");

        if (panoramasDir.exists()) {
            File[] subDirs;//  w  w  w .j a  v  a 2 s  .  c o  m

            File mainMenu = new File(panoramasDir, "main_menu");
            if (mainMenu.exists())
                subDirs = new File[] { mainMenu };
            else
                subDirs = panoramasDir
                        .listFiles((File f) -> f.isDirectory() && !f.getName().endsWith("fullres"));

            for (File f : subDirs)
                if (set.stream().allMatch((String s) -> new File(f, s).exists()))
                    validFiles.add(f.listFiles((File f1) -> set.contains(f1.getName())));
        }

        if (!validFiles.isEmpty()) {
            File[] files = validFiles.get(new Random().nextInt(validFiles.size()));
            Arrays.sort(files);

            Minecraft mc = Minecraft.getMinecraft();
            ResourceLocation[] resources = new ResourceLocation[6];

            for (int i = 0; i < resources.length; i++) {
                File f = files[i];
                try {
                    BufferedImage img = ImageIO.read(f);
                    DynamicTexture tex = new DynamicTexture(img);
                    String name = "quark:" + f.getName();

                    resources[i] = mc.getTextureManager().getDynamicTextureLocation(name, tex);
                } catch (IOException e) {
                    e.printStackTrace();
                    return;
                }
            }

            try {
                Field field = ReflectionHelper.findField(GuiMainMenu.class,
                        LibObfuscation.TITLE_PANORAMA_PATHS);
                field.setAccessible(true);

                if (Modifier.isFinal(field.getModifiers())) {
                    Field modfield = Field.class.getDeclaredField("modifiers");
                    modfield.setAccessible(true);
                    modfield.setInt(field, field.getModifiers() & ~Modifier.FINAL);
                }

                field.set(null, resources);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        overridenOnce = true;
    }
}

From source file:vazkii.quark.vanity.feature.PanoramaMaker.java

License:Creative Commons License

@SubscribeEvent
public void loadMainMenu(GuiOpenEvent event) {
    if (overrideMainMenu && !overridenOnce && event.getGui() instanceof GuiMainMenu) {
        File mcDir = ModuleLoader.configFile.getParentFile().getParentFile();
        File panoramasDir = new File(mcDir, "/screenshots/panoramas");
        List<File[]> validFiles = new ArrayList();

        ImmutableSet<String> set = ImmutableSet.of("panorama_0.png", "panorama_1.png", "panorama_2.png",
                "panorama_3.png", "panorama_4.png", "panorama_5.png");

        if (panoramasDir.exists()) {
            File[] subDirs;//  ww w  .j av a 2 s .  c  o  m

            File mainMenu = new File(panoramasDir, "main_menu");
            if (mainMenu.exists())
                subDirs = new File[] { mainMenu };
            else
                subDirs = panoramasDir.listFiles((File f) -> f.isDirectory());

            for (File f : subDirs)
                if (set.stream().allMatch((String s) -> new File(f, s).exists()))
                    validFiles.add(f.listFiles((File f1) -> set.contains(f1.getName())));
        }

        if (!validFiles.isEmpty()) {
            File[] files = validFiles.get(new Random().nextInt(validFiles.size()));
            Arrays.sort(files);

            Minecraft mc = Minecraft.getMinecraft();
            ResourceLocation[] resources = new ResourceLocation[6];

            for (int i = 0; i < resources.length; i++) {
                File f = files[i];
                try {
                    DynamicTexture tex = new DynamicTexture(ImageIO.read(f));
                    String name = "quark:" + f.getName();

                    resources[i] = mc.getTextureManager().getDynamicTextureLocation(name, tex);
                } catch (IOException e) {
                    e.printStackTrace();
                    return;
                }
            }

            try {
                Field field = ReflectionHelper.findField(GuiMainMenu.class,
                        LibObfuscation.TITLE_PANORAMA_PATHS);
                field.setAccessible(true);

                if (Modifier.isFinal(field.getModifiers())) {
                    Field modfield = Field.class.getDeclaredField("modifiers");
                    modfield.setAccessible(true);
                    modfield.setInt(field, field.getModifiers() & ~Modifier.FINAL);
                }

                field.set(null, resources);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        overridenOnce = true;
    }
}