net.minecraftforge.client.event.GuiScreenEvent Java Examples

The following examples show how to use net.minecraftforge.client.event.GuiScreenEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MixinKeyboard.java    From patchwork-api with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Inject(method = "method_1454", at = @At("HEAD"), cancellable = true)
private void preKeyEvent(int i, boolean[] bls, ParentElement element, int key, int scanCode, int mods, CallbackInfo info) {
	if (i != 1 && (i != 2 || !this.repeatEvents)) {
		if (i == 0) {
			if (MinecraftForge.EVENT_BUS.post(new GuiScreenEvent.KeyboardKeyReleasedEvent.Pre((Screen) element, key, scanCode, mods))) {
				bls[0] = true;
				info.cancel();
			}
		}
	} else {
		if (MinecraftForge.EVENT_BUS.post(new GuiScreenEvent.KeyboardKeyPressedEvent.Pre((Screen) element, key, scanCode, mods))) {
			bls[0] = true;
			info.cancel();
		}
	}
}
 
Example #2
Source File: MixinKeyboard.java    From patchwork-api with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Inject(method = "method_1454", at = @At("RETURN"))
private void postKeyEvent(int i, boolean[] bls, ParentElement element, int key, int scanCode, int mods, CallbackInfo info) {
	if (bls[0]) {
		return;
	}

	if (i != 1 && (i != 2 || !this.repeatEvents)) {
		if (i == 0) {
			if (MinecraftForge.EVENT_BUS.post(new GuiScreenEvent.KeyboardKeyReleasedEvent.Post((Screen) element, key, scanCode, mods))) {
				bls[0] = true;
			}
		}
	} else {
		if (MinecraftForge.EVENT_BUS.post(new GuiScreenEvent.KeyboardKeyPressedEvent.Post((Screen) element, key, scanCode, mods))) {
			bls[0] = true;
		}
	}
}
 
Example #3
Source File: EventHandler.java    From VersionChecker with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void onActionPerformed(GuiScreenEvent.ActionPerformedEvent evt)
{
    if (evt.getGui() instanceof GuiMainMenu)
    {
        GuiMainMenuHandler.onActionPerformed(evt.getButton());
    }
}
 
Example #4
Source File: ShulkerViewer.java    From ForgeHax with MIT License 6 votes vote down vote up
@SubscribeEvent
public void onKeyboardInput(GuiScreenEvent.KeyboardInputEvent event) {
  if (Keyboard.getEventKey() == lockDownKey.getKeyCode()) {
    if (Keyboard.getEventKeyState()) {
      if (toggle_lock.get()) {
        if (!isKeySet) {
          locked = !locked;
          if (!locked) {
            updated = false;
          }
          isKeySet = true;
        }
      } else {
        locked = true;
      }
    } else {
      if (toggle_lock.get()) {
        isKeySet = false;
      } else {
        locked = updated = false;
      }
    }
  }
}
 
Example #5
Source File: MainMenuGuiService.java    From ForgeHax with MIT License 6 votes vote down vote up
@SubscribeEvent
public void onGui(GuiScreenEvent.InitGuiEvent.Post event) {
  if (event.getGui() instanceof GuiMainMenu) {
    GuiMainMenu gui = (GuiMainMenu) event.getGui();
    
    event
        .getButtonList()
        .stream()
        .skip(4) // skip first 4 button
        .forEach(
            button -> {
              button.y += 24;
            }); // lower the rest of the buttons to make room for ours
    
    event
        .getButtonList()
        .add(
            customButton =
                new GuiButton(
                    666,
                    gui.width / 2 - 100,
                    gui.height / 4 + 48 + (24 * 3), // put button in 4th row
                    "Command Input"));
  }
}
 
Example #6
Source File: NEIClientEventHandler.java    From NotEnoughItems with MIT License 5 votes vote down vote up
@SubscribeEvent
public void containerInitEvent(GuiScreenEvent.InitGuiEvent.Pre event) {
    if (event.getGui() instanceof GuiContainer) {
        GuiContainer container = (GuiContainer) event.getGui();
        objectHandlers.forEach(handler -> handler.load(container));
    }
}
 
Example #7
Source File: MixinMouse.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Inject(method = "onMouseScroll", at = @At(value = "INVOKE",
				target = "Lnet/minecraft/client/gui/screen/Screen;mouseScrolled(DDD)Z",
				ordinal = 0), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true)
private void preMouseScrolled(long window, double xOffset, double yOffset, CallbackInfo info, double amount, double mouseX, double mouseY) {
	if (MinecraftForge.EVENT_BUS.post(new GuiScreenEvent.MouseScrollEvent.Pre(client.currentScreen, mouseX, mouseY, amount))) {
		info.cancel();
	}
}
 
Example #8
Source File: GuiScreenListener.java    From SkyblockAddons with MIT License 5 votes vote down vote up
/**
 * Listens for key presses while a GUI is open
 *
 * @param event the {@code GuiScreenEvent.KeyboardInputEvent} to listen for
 */
@SubscribeEvent()
public void onKeyInput(GuiScreenEvent.KeyboardInputEvent event) {
    int eventKey = Keyboard.getEventKey();

    if (eventKey == DevUtils.DEV_KEY && Keyboard.getEventKeyState()) {
        event.setCanceled(true);

        // Copy Item NBT
        if (main.isDevMode()) {
            GuiScreen currentScreen = event.gui;

            // Check if the player is in an inventory.
            if (GuiContainer.class.isAssignableFrom(currentScreen.getClass())) {
                Slot currentSlot = ((GuiContainer) currentScreen).getSlotUnderMouse();

                if (currentSlot != null && currentSlot.getHasStack()) {
                    DevUtils.copyNBTTagToClipboard(currentSlot.getStack().serializeNBT(),
                            ChatFormatting.GREEN + "Item data was copied to clipboard!");
                }
            }
        }
    }
}
 
Example #9
Source File: Events.java    From ehacks-pro with GNU General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public void onGuiScreenInit(GuiScreenEvent.InitGuiEvent event) {
    if (Wrapper.INSTANCE.player() == null) {
        Wrapper.INSTANCE.mc().getSession();
        ConfigurationManager.instance().initConfigs();
        event.buttonList.add(new GuiButton(1337, 0, 0, 100, 20, "EHacks"));
    }
}
 
Example #10
Source File: GuiModifier.java    From customstuff4 with GNU General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
void onPostInitGui(GuiScreenEvent.InitGuiEvent.Post event)
{
    if (isCorrectGui(event.getGui()))
    {
        event.getButtonList().removeIf(button -> removeButtons.contains(button.id));
        editButtons.forEach(b -> b.postInit(event));
    }
}
 
Example #11
Source File: GuiModifier.java    From customstuff4 with GNU General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
void onRenderGui(GuiScreenEvent.DrawScreenEvent.Post event)
{
    if (isCorrectGui(event.getGui()))
    {
        labels.forEach(m -> m.render(event));
    }
}
 
Example #12
Source File: GuiModifier.java    From customstuff4 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void render(GuiScreenEvent.DrawScreenEvent.Post event)
{
    FontRenderer font = Minecraft.getMinecraft().fontRenderer;

    int left = getLeft(event.getGui(), font.getStringWidth(text));
    int top = getTop(event.getGui(), font.FONT_HEIGHT);

    font.drawString(text, left, top, color.getRGB(), dropShadow);
}
 
Example #13
Source File: Peek.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public void onGuiDraw(GuiScreenEvent.DrawScreenEvent.Post event) {
	if (!(event.getGui() instanceof ContainerScreen<?>)) return;
	ContainerScreen<?> screen = (ContainerScreen<?>) event.getGui();
	
	if (screen.getSlotUnderMouse() == null) return;
	if (!(screen.getSlotUnderMouse().getStack().getItem() instanceof BlockItem)) return;
	if (!(((BlockItem) screen.getSlotUnderMouse().getStack().getItem()).getBlock() instanceof ContainerBlock)) return;
	
	NonNullList<ItemStack> items = NonNullList.withSize(27, new ItemStack(Items.AIR));
	CompoundNBT nbt = screen.getSlotUnderMouse().getStack().getTag();
	
	if (nbt != null && nbt.contains("BlockEntityTag")) {
		CompoundNBT itemnbt = nbt.getCompound("BlockEntityTag");
		if (itemnbt.contains("Items")) ItemStackHelper.loadAllItems(itemnbt, items);
	}
	
	GlStateManager.translatef(0.0F, 0.0F, 500.0F);
	Block block = ((BlockItem) screen.getSlotUnderMouse().getStack().getItem()).getBlock();
	
	int count = block instanceof HopperBlock || block instanceof DispenserBlock ? 18 : 0;
	for (ItemStack i: items) {
		if (count > 26) break;
		int x = event.getMouseX() + 8 + (17 * (count % 9));
		int y = event.getMouseY() - 68 + (17 * (count / 9));
		
		if (i.getItem() != Items.AIR) {
			Screen.fill(x, y, x+17, y+17, 0x90000000);
			Screen.fill(x, y, x+17, y+1, 0xff000000); Screen.fill(x, y+1, x+1, y+17, 0xff000000);
			Screen.fill(x+16, y+1, x+17, y+17, 0xff000000); Screen.fill(x+1, y+16, x+17, y+17, 0xff000000);
		}
		
	    mc.getItemRenderer().renderItemAndEffectIntoGUI(i, x, y);
	    mc.getItemRenderer().renderItemOverlayIntoGUI(mc.fontRenderer, i, x, y, i.getCount() > 1 ? i.getCount() + "" : "");
		count++;
	}
}
 
Example #14
Source File: ClientEventHandler.java    From Better-Sprinting with Mozilla Public License 2.0 5 votes vote down vote up
@SubscribeEvent
public static void onGuiInitPost(GuiScreenEvent.InitGuiEvent.Post e){
	Screen gui = e.getGui();
	
	if (gui instanceof ControlsScreen){
		ControlsScreen controls = (ControlsScreen)gui;
		
		e.getWidgetList()
		 .stream()
		 .filter(btn -> btn instanceof OptionButton && ((OptionButton)btn).enumOptions == AbstractOption.AUTO_JUMP)
		 .findFirst()
		 .ifPresent(e::removeWidget);
		
		controls.children()
		        .stream()
		        .filter(widget -> widget instanceof KeyBindingList)
		        .map(widget -> ((KeyBindingList)widget).children())
		        .findFirst()
		        .ifPresent(children -> children.removeIf(entry ->
		        	(entry instanceof KeyEntry && ArrayUtils.contains(ClientModManager.keyBindings, ((KeyEntry)entry).keybinding)) ||
		        	(entry instanceof CategoryEntry && ((CategoryEntry)entry).labelText.equals(I18n.format(ClientModManager.categoryName)))
		        ));
		
		if (!openedControlsFromSprintMenu){
			e.addWidget(new GuiButton((controls.width / 2) + 5, 18, 150, "Better Sprinting", () -> mc.displayGuiScreen(new GuiSprint(mc.currentScreen))));
		}
	}
}
 
Example #15
Source File: InputEventHandler.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public void onGuiKeyInputEventPre(GuiScreenEvent.KeyboardInputEvent.Pre event)
{
    if (event.getGui() instanceof GuiHandyBag)
    {
        int key = Keyboard.getEventKey();

        // Double-tap shift
        if (Keyboard.getEventKeyState() && (key == Keyboard.KEY_LSHIFT || key == Keyboard.KEY_RSHIFT) && this.checkForDoubleTap(key))
        {
            PacketHandler.INSTANCE.sendToServer(new MessageGuiAction(0, new BlockPos(0, 0, 0),
                ReferenceGuiIds.GUI_ID_HANDY_BAG, ItemHandyBag.GUI_ACTION_TOGGLE_SHIFTCLICK_DOUBLETAP, 0));
        }
    }
}
 
Example #16
Source File: GuiEnderUtilities.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public static void onPotionShiftEvent(GuiScreenEvent.PotionShiftEvent event)
{
    // Disable the potion shift in all my GUIs
    if (event.getGui() instanceof GuiEnderUtilities)
    {
        event.setCanceled(true);
    }
}
 
Example #17
Source File: EventHandler.java    From VersionChecker with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void onGuiInit(GuiScreenEvent.InitGuiEvent evt)
{
    if (evt.getGui() instanceof GuiMainMenu)
    {
        IMCHandler.processMessages(FMLInterModComms.fetchRuntimeMessages(Reference.MOD_ID));
        GuiMainMenuHandler.initGui(evt.getGui(), evt.getButtonList());
    }
}
 
Example #18
Source File: ClientProxy.java    From IGW-mod with GNU General Public License v2.0 5 votes vote down vote up
@SubscribeEvent
public void onGuiKeyBind(GuiScreenEvent.KeyboardInputEvent.Post event){
    char chr = Keyboard.getEventCharacter();
    int key = Keyboard.getEventKey();

    if(((key == 0 && chr >= 32) || Keyboard.getEventKeyState()) && key == openInterfaceKey.getKeyCode()) {
        handleSlotPresses();
    }
}
 
Example #19
Source File: ModTest.java    From CommunityMod with GNU Lesser General Public License v2.1 5 votes vote down vote up
@SubscribeEvent
public static void onDrawScreen(GuiScreenEvent.DrawScreenEvent e)
{
    if (isLoaded && e.getGui() instanceof GuiModList)
    {
        e.getGui().drawString(e.getGui().mc.fontRenderer, "ExampleMod loaded! Neat, eh?", e.getMouseX(), e.getMouseY(), -1);
    }
}
 
Example #20
Source File: MixinMouse.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Inject(method = "method_1605", at = @At("RETURN"), locals = LocalCapture.CAPTURE_FAILHARD)
private void postMouseReleased(boolean[] handled, double mouseX, double mouseY, int button, CallbackInfo info) {
	if (handled[0]) {
		return;
	}

	if (MinecraftForge.EVENT_BUS.post(new GuiScreenEvent.MouseReleasedEvent.Post(client.currentScreen, mouseX, mouseY, button))) {
		handled[0] = true;
		info.cancel();
	}
}
 
Example #21
Source File: MixinMouse.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Inject(method = "method_1605", at = @At("HEAD"), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true)
private void preMouseReleased(boolean[] handled, double mouseX, double mouseY, int button, CallbackInfo info) {
	if (MinecraftForge.EVENT_BUS.post(new GuiScreenEvent.MouseReleasedEvent.Pre(client.currentScreen, mouseX, mouseY, button))) {
		handled[0] = true;
		info.cancel();
	}
}
 
Example #22
Source File: MixinMouse.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Inject(method = "method_1611", at = @At("RETURN"), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true)
private void postMouseClicked(boolean[] handled, double mouseX, double mouseY, int button, CallbackInfo info) {
	if (handled[0]) {
		return;
	}

	if (MinecraftForge.EVENT_BUS.post(new GuiScreenEvent.MouseClickedEvent.Post(client.currentScreen, mouseX, mouseY, button))) {
		handled[0] = true;
		info.cancel();
	}
}
 
Example #23
Source File: MixinMouse.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Inject(method = "method_1611", at = @At("HEAD"), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true)
public void preMouseClicked(boolean[] handled, double mouseX, double mouseY, int button, CallbackInfo info) {
	if (MinecraftForge.EVENT_BUS.post(new GuiScreenEvent.MouseClickedEvent.Pre(client.currentScreen, mouseX, mouseY, button))) {
		handled[0] = true;
		info.cancel();
	}
}
 
Example #24
Source File: MixinAbstractInventoryScreen.java    From patchwork-api with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Inject(method = "method_2476", at = @At("RETURN"))
private void potionShift(CallbackInfo info) {
	if (offsetGuiForEffects) {
		if (MinecraftForge.EVENT_BUS.post(new GuiScreenEvent.PotionShiftEvent(this))) {
			this.x = (this.width - this.containerWidth) / 2;
		}
	}
}
 
Example #25
Source File: MixinGameRenderer.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/Screen;render(IIF)V"), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true)
private void beforeRenderScreen(float tickDelta, long startTime, boolean fullRender, CallbackInfo info, int mouseX, int mouseY) {
	if (MinecraftForge.EVENT_BUS.post(new GuiScreenEvent.DrawScreenEvent.Pre(client.currentScreen, mouseX, mouseY, tickDelta))) {
		info.cancel();
	}
}
 
Example #26
Source File: MixinKeyboard.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Inject(method = "method_1458", at = @At("HEAD"), cancellable = true)
private static void preCharTyped(Element element, int character, int mods, CallbackInfo info) {
	if (MinecraftForge.EVENT_BUS.post(new GuiScreenEvent.KeyboardCharTypedEvent.Pre((Screen) element, (char) character, mods))) {
		info.cancel();
	}
}
 
Example #27
Source File: MixinKeyboard.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Redirect(method = "method_1458", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/Element;charTyped(CI)Z"))
private static boolean charTyped(Element element, char character, int mods) {
	return element.charTyped(character, mods) || MinecraftForge.EVENT_BUS.post(new GuiScreenEvent.KeyboardCharTypedEvent.Post((Screen) element, character, mods));
}
 
Example #28
Source File: MixinKeyboard.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Inject(method = "method_1473", at = @At("HEAD"), cancellable = true)
private static void preCharTyped(Element element, char character, int mods, CallbackInfo info) {
	if (MinecraftForge.EVENT_BUS.post(new GuiScreenEvent.KeyboardCharTypedEvent.Pre((Screen) element, (char) character, mods))) {
		info.cancel();
	}
}
 
Example #29
Source File: MixinKeyboard.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Redirect(method = "method_1473", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/Element;charTyped(CI)Z"))
private static boolean charTyped2(Element element, char character, int mods) {
	return element.charTyped(character, mods) || MinecraftForge.EVENT_BUS.post(new GuiScreenEvent.KeyboardCharTypedEvent.Post((Screen) element, character, mods));
}
 
Example #30
Source File: CCCEventHandler.java    From CodeChickenCore with MIT License 4 votes vote down vote up
@SubscribeEvent
@SideOnly(Side.CLIENT)
public void posGuiRender(GuiScreenEvent.DrawScreenEvent.Post event) {
    if(event.gui instanceof GuiModList)
        GuiModListScroll.draw((GuiModList)event.gui, event.mouseX, event.mouseY);
}