2016-06-23 03:49:47 +00:00
|
|
|
/*
|
|
|
|
* Minecraft Forge
|
2018-07-01 21:17:28 +00:00
|
|
|
* Copyright (c) 2016-2018.
|
2016-06-23 03:49:47 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation version 2.1
|
|
|
|
* of the License.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
2014-05-07 20:52:10 +00:00
|
|
|
package net.minecraftforge.client.event;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2016-05-29 21:05:07 +00:00
|
|
|
import net.minecraft.client.Minecraft;
|
|
|
|
import net.minecraft.client.renderer.InventoryEffectRenderer;
|
2018-06-21 19:37:32 +00:00
|
|
|
import net.minecraftforge.api.distmarker.Dist;
|
|
|
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
2016-01-13 04:01:27 +00:00
|
|
|
|
2014-05-07 20:52:10 +00:00
|
|
|
import net.minecraft.client.gui.GuiButton;
|
|
|
|
import net.minecraft.client.gui.GuiScreen;
|
2016-01-13 04:01:27 +00:00
|
|
|
|
2018-06-11 01:12:46 +00:00
|
|
|
import net.minecraftforge.eventbus.api.Cancelable;
|
|
|
|
import net.minecraftforge.eventbus.api.Event;
|
2014-05-07 20:52:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Event classes for GuiScreen events.
|
|
|
|
*
|
|
|
|
* @author bspkrs
|
|
|
|
*/
|
2018-06-21 19:37:32 +00:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2014-05-07 20:52:10 +00:00
|
|
|
public class GuiScreenEvent extends Event
|
|
|
|
{
|
2016-03-24 08:44:52 +00:00
|
|
|
private final GuiScreen gui;
|
2014-05-07 20:52:10 +00:00
|
|
|
|
|
|
|
public GuiScreenEvent(GuiScreen gui)
|
|
|
|
{
|
|
|
|
this.gui = gui;
|
|
|
|
}
|
|
|
|
|
2016-03-24 08:44:52 +00:00
|
|
|
/**
|
|
|
|
* The GuiScreen object generating this event.
|
|
|
|
*/
|
|
|
|
public GuiScreen getGui()
|
|
|
|
{
|
|
|
|
return gui;
|
|
|
|
}
|
|
|
|
|
2014-05-07 20:52:10 +00:00
|
|
|
public static class InitGuiEvent extends GuiScreenEvent
|
|
|
|
{
|
2016-03-24 08:44:52 +00:00
|
|
|
private List<GuiButton> buttonList;
|
2014-05-07 20:52:10 +00:00
|
|
|
|
2015-11-27 03:38:21 +00:00
|
|
|
public InitGuiEvent(GuiScreen gui, List<GuiButton> buttonList)
|
2014-05-07 20:52:10 +00:00
|
|
|
{
|
|
|
|
super(gui);
|
2016-03-24 08:44:52 +00:00
|
|
|
this.setButtonList(buttonList);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-05-29 21:05:07 +00:00
|
|
|
* The {@link #buttonList} field from the GuiScreen object referenced by {@link #gui}.
|
2016-03-24 08:44:52 +00:00
|
|
|
*/
|
|
|
|
public List<GuiButton> getButtonList()
|
|
|
|
{
|
|
|
|
return buttonList;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setButtonList(List<GuiButton> buttonList)
|
|
|
|
{
|
2014-05-07 20:52:10 +00:00
|
|
|
this.buttonList = buttonList;
|
|
|
|
}
|
2016-03-24 08:44:52 +00:00
|
|
|
|
2014-05-07 20:52:10 +00:00
|
|
|
/**
|
2017-06-11 00:59:01 +00:00
|
|
|
* This event fires just after initializing {@link GuiScreen#mc}, {@link GuiScreen#fontRenderer},
|
2016-05-29 21:05:07 +00:00
|
|
|
* {@link GuiScreen#width}, and {@link GuiScreen#height}.<br/><br/>
|
2014-05-07 20:52:10 +00:00
|
|
|
*
|
2016-05-29 21:05:07 +00:00
|
|
|
* If canceled the following lines are skipped in {@link GuiScreen#setWorldAndResolution(Minecraft, int, int)}:<br/>
|
2014-05-07 20:52:10 +00:00
|
|
|
* {@code this.buttonList.clear();}<br/>
|
|
|
|
* {@code this.initGui();}<br/>
|
|
|
|
*/
|
|
|
|
@Cancelable
|
|
|
|
public static class Pre extends InitGuiEvent
|
|
|
|
{
|
2015-11-27 03:38:21 +00:00
|
|
|
public Pre(GuiScreen gui, List<GuiButton> buttonList)
|
2014-05-07 20:52:10 +00:00
|
|
|
{
|
|
|
|
super(gui, buttonList);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-05-29 21:05:07 +00:00
|
|
|
* This event fires right after {@link GuiScreen#initGui()}.
|
2014-05-07 20:52:10 +00:00
|
|
|
* This is a good place to alter a GuiScreen's component layout if desired.
|
|
|
|
*/
|
|
|
|
public static class Post extends InitGuiEvent
|
|
|
|
{
|
2015-11-27 03:38:21 +00:00
|
|
|
public Post(GuiScreen gui, List<GuiButton> buttonList)
|
2014-05-07 20:52:10 +00:00
|
|
|
{
|
|
|
|
super(gui, buttonList);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static class DrawScreenEvent extends GuiScreenEvent
|
|
|
|
{
|
2016-03-24 08:44:52 +00:00
|
|
|
private final int mouseX;
|
|
|
|
private final int mouseY;
|
|
|
|
private final float renderPartialTicks;
|
|
|
|
|
|
|
|
public DrawScreenEvent(GuiScreen gui, int mouseX, int mouseY, float renderPartialTicks)
|
|
|
|
{
|
|
|
|
super(gui);
|
|
|
|
this.mouseX = mouseX;
|
|
|
|
this.mouseY = mouseY;
|
|
|
|
this.renderPartialTicks = renderPartialTicks;
|
|
|
|
}
|
|
|
|
|
2014-05-07 20:52:10 +00:00
|
|
|
/**
|
|
|
|
* The x coordinate of the mouse pointer on the screen.
|
|
|
|
*/
|
2016-03-24 08:44:52 +00:00
|
|
|
public int getMouseX()
|
|
|
|
{
|
|
|
|
return mouseX;
|
|
|
|
}
|
|
|
|
|
2014-05-07 20:52:10 +00:00
|
|
|
/**
|
|
|
|
* The y coordinate of the mouse pointer on the screen.
|
|
|
|
*/
|
2016-03-24 08:44:52 +00:00
|
|
|
public int getMouseY()
|
|
|
|
{
|
|
|
|
return mouseY;
|
|
|
|
}
|
|
|
|
|
2014-05-07 20:52:10 +00:00
|
|
|
/**
|
|
|
|
* Partial render ticks elapsed.
|
|
|
|
*/
|
2016-03-24 08:44:52 +00:00
|
|
|
public float getRenderPartialTicks()
|
2014-05-07 20:52:10 +00:00
|
|
|
{
|
2016-03-24 08:44:52 +00:00
|
|
|
return renderPartialTicks;
|
2014-05-07 20:52:10 +00:00
|
|
|
}
|
2016-03-24 08:44:52 +00:00
|
|
|
|
2014-05-07 20:52:10 +00:00
|
|
|
/**
|
2016-05-29 21:05:07 +00:00
|
|
|
* This event fires just before {@link GuiScreen#drawScreen(int, int, float)} is called.
|
|
|
|
* Cancel this event to skip {@link GuiScreen#drawScreen(int, int, float)}.
|
2014-05-07 20:52:10 +00:00
|
|
|
*/
|
|
|
|
@Cancelable
|
|
|
|
public static class Pre extends DrawScreenEvent
|
|
|
|
{
|
|
|
|
public Pre(GuiScreen gui, int mouseX, int mouseY, float renderPartialTicks)
|
|
|
|
{
|
|
|
|
super(gui, mouseX, mouseY, renderPartialTicks);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-05-29 21:05:07 +00:00
|
|
|
* This event fires just after {@link GuiScreen#drawScreen(int, int, float)} is called.
|
2014-05-07 20:52:10 +00:00
|
|
|
*/
|
|
|
|
public static class Post extends DrawScreenEvent
|
|
|
|
{
|
|
|
|
public Post(GuiScreen gui, int mouseX, int mouseY, float renderPartialTicks)
|
|
|
|
{
|
|
|
|
super(gui, mouseX, mouseY, renderPartialTicks);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-01-13 04:01:27 +00:00
|
|
|
|
|
|
|
/**
|
2016-05-29 21:05:07 +00:00
|
|
|
* This event fires at the end of {@link GuiScreen#drawDefaultBackground()} and before the rest of the Gui draws.
|
2016-01-13 04:01:27 +00:00
|
|
|
* This allows drawing next to Guis, above the background but below any tooltips.
|
|
|
|
*/
|
2018-08-27 17:10:07 +00:00
|
|
|
/*
|
2016-01-13 04:01:27 +00:00
|
|
|
public static class BackgroundDrawnEvent extends GuiScreenEvent
|
|
|
|
{
|
|
|
|
private final int mouseX;
|
|
|
|
private final int mouseY;
|
|
|
|
|
|
|
|
public BackgroundDrawnEvent(GuiScreen gui)
|
|
|
|
{
|
|
|
|
super(gui);
|
|
|
|
final ScaledResolution scaledresolution = new ScaledResolution(gui.mc);
|
|
|
|
final int scaledWidth = scaledresolution.getScaledWidth();
|
|
|
|
final int scaledHeight = scaledresolution.getScaledHeight();
|
|
|
|
this.mouseX = Mouse.getX() * scaledWidth / gui.mc.displayWidth;
|
|
|
|
this.mouseY = scaledHeight - Mouse.getY() * scaledHeight / gui.mc.displayHeight - 1;
|
|
|
|
}
|
|
|
|
|
2018-08-27 17:10:07 +00:00
|
|
|
*/
|
|
|
|
/**
|
2016-01-13 04:01:27 +00:00
|
|
|
* The x coordinate of the mouse pointer on the screen.
|
2018-08-27 17:10:07 +00:00
|
|
|
*//*
|
|
|
|
|
2016-01-13 04:01:27 +00:00
|
|
|
public int getMouseX()
|
|
|
|
{
|
|
|
|
return mouseX;
|
|
|
|
}
|
|
|
|
|
2018-08-27 17:10:07 +00:00
|
|
|
*/
|
|
|
|
/**
|
2016-01-13 04:01:27 +00:00
|
|
|
* The y coordinate of the mouse pointer on the screen.
|
2018-08-27 17:10:07 +00:00
|
|
|
*//*
|
|
|
|
|
2016-01-13 04:01:27 +00:00
|
|
|
public int getMouseY()
|
|
|
|
{
|
|
|
|
return mouseY;
|
|
|
|
}
|
|
|
|
}
|
2018-08-27 17:10:07 +00:00
|
|
|
*/
|
2016-04-09 03:18:17 +00:00
|
|
|
|
|
|
|
/**
|
2016-05-29 21:05:07 +00:00
|
|
|
* This event fires in {@link InventoryEffectRenderer#updateActivePotionEffects()}
|
2016-04-09 03:18:17 +00:00
|
|
|
* when potion effects are active and the gui wants to move over.
|
|
|
|
* Cancel this event to prevent the Gui from being moved.
|
|
|
|
*/
|
|
|
|
@Cancelable
|
|
|
|
public static class PotionShiftEvent extends GuiScreenEvent
|
|
|
|
{
|
|
|
|
public PotionShiftEvent(GuiScreen gui)
|
|
|
|
{
|
|
|
|
super(gui);
|
|
|
|
}
|
|
|
|
}
|
2014-05-07 20:52:10 +00:00
|
|
|
|
|
|
|
public static class ActionPerformedEvent extends GuiScreenEvent
|
|
|
|
{
|
2016-03-24 08:44:52 +00:00
|
|
|
private GuiButton button;
|
|
|
|
private List<GuiButton> buttonList;
|
|
|
|
|
|
|
|
public ActionPerformedEvent(GuiScreen gui, GuiButton button, List<GuiButton> buttonList)
|
|
|
|
{
|
|
|
|
super(gui);
|
|
|
|
this.setButton(button);
|
|
|
|
this.setButtonList(new ArrayList<GuiButton>(buttonList));
|
|
|
|
}
|
|
|
|
|
2014-05-07 20:52:10 +00:00
|
|
|
/**
|
|
|
|
* The button that was clicked.
|
|
|
|
*/
|
2016-03-24 08:44:52 +00:00
|
|
|
public GuiButton getButton()
|
|
|
|
{
|
|
|
|
return button;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setButton(GuiButton button)
|
|
|
|
{
|
|
|
|
this.button = button;
|
|
|
|
}
|
|
|
|
|
2014-05-07 20:52:10 +00:00
|
|
|
/**
|
2016-05-29 21:05:07 +00:00
|
|
|
* A COPY of the {@link #buttonList} field from the GuiScreen referenced by {@link #gui}.
|
2014-05-07 20:52:10 +00:00
|
|
|
*/
|
2016-03-24 08:44:52 +00:00
|
|
|
public List<GuiButton> getButtonList()
|
|
|
|
{
|
|
|
|
return buttonList;
|
|
|
|
}
|
2014-05-07 20:52:10 +00:00
|
|
|
|
2016-03-24 08:44:52 +00:00
|
|
|
public void setButtonList(List<GuiButton> buttonList)
|
2014-05-07 20:52:10 +00:00
|
|
|
{
|
2016-03-24 08:44:52 +00:00
|
|
|
this.buttonList = buttonList;
|
2014-05-07 20:52:10 +00:00
|
|
|
}
|
2016-03-24 08:44:52 +00:00
|
|
|
|
2014-05-07 20:52:10 +00:00
|
|
|
/**
|
|
|
|
* This event fires once it has been determined that a GuiButton object has been clicked.
|
2016-05-29 21:05:07 +00:00
|
|
|
* Cancel this event to bypass {@link GuiScreen#actionPerformed(GuiButton)}.
|
2014-05-07 20:52:10 +00:00
|
|
|
* Replace button with a different button from buttonList to have that button's action executed.
|
|
|
|
*/
|
|
|
|
@Cancelable
|
|
|
|
public static class Pre extends ActionPerformedEvent
|
|
|
|
{
|
2015-11-27 03:38:21 +00:00
|
|
|
public Pre(GuiScreen gui, GuiButton button, List<GuiButton> buttonList)
|
2014-05-07 20:52:10 +00:00
|
|
|
{
|
|
|
|
super(gui, button, buttonList);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-05-29 21:05:07 +00:00
|
|
|
* This event fires after {@link GuiScreen#actionPerformed(GuiButton)} provided that the active
|
|
|
|
* screen has not been changed as a result of {@link GuiScreen#actionPerformed(GuiButton)}.
|
2014-05-07 20:52:10 +00:00
|
|
|
*/
|
|
|
|
public static class Post extends ActionPerformedEvent
|
|
|
|
{
|
2015-11-27 03:38:21 +00:00
|
|
|
public Post(GuiScreen gui, GuiButton button, List<GuiButton> buttonList)
|
2014-05-07 20:52:10 +00:00
|
|
|
{
|
|
|
|
super(gui, button, buttonList);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-11-23 01:44:54 +00:00
|
|
|
|
|
|
|
public static class MouseInputEvent extends GuiScreenEvent
|
|
|
|
{
|
|
|
|
public MouseInputEvent(GuiScreen gui)
|
|
|
|
{
|
|
|
|
super(gui);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This event fires when mouse input is detected by a GuiScreen.
|
2016-05-29 21:05:07 +00:00
|
|
|
* Cancel this event to bypass {@link GuiScreen#handleMouseInput()}.
|
2014-11-23 01:44:54 +00:00
|
|
|
*/
|
|
|
|
@Cancelable
|
|
|
|
public static class Pre extends MouseInputEvent
|
|
|
|
{
|
|
|
|
public Pre(GuiScreen gui)
|
|
|
|
{
|
|
|
|
super(gui);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-05-29 21:05:07 +00:00
|
|
|
* This event fires after {@link GuiScreen#handleMouseInput()} provided that the active
|
2016-12-03 18:32:09 +00:00
|
|
|
* screen has not been changed as a result of {@link GuiScreen#handleMouseInput()} and
|
|
|
|
* the {@link GuiScreen#mouseHandled} flag has not been set.
|
|
|
|
* Cancel this event when you successfully use the mouse input to prevent other handlers from using the same input.
|
2014-11-23 01:44:54 +00:00
|
|
|
*/
|
2016-12-03 18:32:09 +00:00
|
|
|
@Cancelable
|
2014-11-23 01:44:54 +00:00
|
|
|
public static class Post extends MouseInputEvent
|
|
|
|
{
|
|
|
|
public Post(GuiScreen gui)
|
|
|
|
{
|
|
|
|
super(gui);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static class KeyboardInputEvent extends GuiScreenEvent
|
|
|
|
{
|
|
|
|
public KeyboardInputEvent(GuiScreen gui)
|
|
|
|
{
|
|
|
|
super(gui);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This event fires when keyboard input is detected by a GuiScreen.
|
2016-05-29 21:05:07 +00:00
|
|
|
* Cancel this event to bypass {@link GuiScreen#handleKeyboardInput()}.
|
2014-11-23 01:44:54 +00:00
|
|
|
*/
|
|
|
|
@Cancelable
|
|
|
|
public static class Pre extends KeyboardInputEvent
|
|
|
|
{
|
|
|
|
public Pre(GuiScreen gui)
|
|
|
|
{
|
|
|
|
super(gui);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-05-29 21:05:07 +00:00
|
|
|
* This event fires after {@link GuiScreen#handleKeyboardInput()} provided that the active
|
2016-12-03 18:32:09 +00:00
|
|
|
* screen has not been changed as a result of {@link GuiScreen#handleKeyboardInput()} and
|
|
|
|
* the {@link GuiScreen#keyHandled} flag has not been set.
|
|
|
|
* Cancel this event when you successfully use the keyboard input to prevent other handlers from using the same input.
|
2014-11-23 01:44:54 +00:00
|
|
|
*/
|
2016-12-03 18:32:09 +00:00
|
|
|
@Cancelable
|
2014-11-23 01:44:54 +00:00
|
|
|
public static class Post extends KeyboardInputEvent
|
|
|
|
{
|
|
|
|
public Post(GuiScreen gui)
|
|
|
|
{
|
|
|
|
super(gui);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-05-07 20:52:10 +00:00
|
|
|
}
|