2016-06-23 03:49:47 +00:00
|
|
|
/*
|
|
|
|
* Minecraft Forge
|
|
|
|
* Copyright (c) 2016.
|
|
|
|
*
|
|
|
|
* 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;
|
2016-01-13 04:01:27 +00:00
|
|
|
import org.lwjgl.input.Mouse;
|
|
|
|
|
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
|
|
|
import net.minecraft.client.gui.ScaledResolution;
|
|
|
|
|
Initial update to 1.8, Super beta. Most rendering related hooks are out due to major changes in 1.8.
Some notes:
Almost all int x, int y, int z parameters have been changed to BlockPos class
ForgeDirection has been removed, replaced by net.minecraft.util.EnumFacing.
All FML classes have moved from packet cpw.mods.fml to net.minecraftforge.fml
Fluid Rendering has been disabled for the time being, to be re-evaulated and a test mod created for it.
Minecraft now uses a Model based system for rendering blocks and Items. The intention is to expand the model format to better suit modder's needed once it is evaulated.
As such, The model loaders from Forge have been removed, to be replaced by expanding vanilla's model format.
Metadata has been extracted out in Minecraft to IBlockState, which holds a list of properties instead of magic number metadata. DO NOT listen to the fearmongering, you can do EVERYTHING with block states you could previously with metadata.
Stencil Bits are disabled entirely by for the main Display, Modders must enable and recreate the FrameBuffer if they wish to use Stencil Bits.
2014-11-26 03:56:35 +00:00
|
|
|
import net.minecraftforge.fml.common.eventhandler.Cancelable;
|
|
|
|
import net.minecraftforge.fml.common.eventhandler.Event;
|
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
2014-05-07 20:52:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Event classes for GuiScreen events.
|
|
|
|
*
|
|
|
|
* @author bspkrs
|
|
|
|
*/
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
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
|
|
|
/**
|
2016-05-29 21:05:07 +00:00
|
|
|
* This event fires just after initializing {@link GuiScreen#mc}, {@link GuiScreen#fontRendererObj},
|
|
|
|
* {@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.
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The x coordinate of the mouse pointer on the screen.
|
|
|
|
*/
|
|
|
|
public int getMouseX()
|
|
|
|
{
|
|
|
|
return mouseX;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The y coordinate of the mouse pointer on the screen.
|
|
|
|
*/
|
|
|
|
public int getMouseY()
|
|
|
|
{
|
|
|
|
return mouseY;
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
}
|