Merge pull request #1506 from mezz/GuiScreenInputEvents

Add GuiScreenEvents for keyboard and mouse input
This commit is contained in:
LexManos 2015-06-17 16:45:41 -07:00
commit 1dc7a80d4f
3 changed files with 103 additions and 0 deletions

View File

@ -91,3 +91,23 @@
}
public void func_73866_w_() {}
@@ -246,7 +265,9 @@
{
while (Mouse.next())
{
+ if (MinecraftForge.EVENT_BUS.post(new net.minecraftforge.client.event.GuiScreenEvent.MouseInputEvent.Pre(this))) continue;
this.func_146274_d();
+ if (this.equals(this.field_146297_k.field_71462_r)) MinecraftForge.EVENT_BUS.post(new net.minecraftforge.client.event.GuiScreenEvent.MouseInputEvent.Post(this));
}
}
@@ -254,7 +275,9 @@
{
while (Keyboard.next())
{
+ if (MinecraftForge.EVENT_BUS.post(new net.minecraftforge.client.event.GuiScreenEvent.KeyboardInputEvent.Pre(this))) continue;
this.func_146282_l();
+ if (this.equals(this.field_146297_k.field_71462_r)) MinecraftForge.EVENT_BUS.post(new net.minecraftforge.client.event.GuiScreenEvent.KeyboardInputEvent.Post(this));
}
}
}

View File

@ -46,3 +46,20 @@
Slot slot = this.func_146975_c(p_146286_1_, p_146286_2_);
int l = this.field_147003_i;
int i1 = this.field_147009_r;
@@ -691,4 +702,16 @@
this.field_146297_k.field_71439_g.func_71053_j();
}
}
+
+ /* ======================================== FORGE START =====================================*/
+
+ /**
+ * Returns the slot that is currently displayed under the mouse.
+ */
+ public Slot getSlotUnderMouse()
+ {
+ return this.field_147006_u;
+ }
+
+ /* ======================================== FORGE END =====================================*/
}

View File

@ -176,4 +176,70 @@ public class GuiScreenEvent extends Event
}
}
}
public static class MouseInputEvent extends GuiScreenEvent
{
public MouseInputEvent(GuiScreen gui)
{
super(gui);
}
/**
* This event fires when mouse input is detected by a GuiScreen.
* Cancel this event to bypass {@code GuiScreen.handleMouseInput()}.
*/
@Cancelable
public static class Pre extends MouseInputEvent
{
public Pre(GuiScreen gui)
{
super(gui);
}
}
/**
* This event fires after {@code GuiScreen.handleMouseInput()} provided that the active
* screen has not been changed as a result of {@code GuiScreen.handleMouseInput()}.
*/
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.
* Cancel this event to bypass {@code GuiScreen.handleKeyboardInput()}.
*/
@Cancelable
public static class Pre extends KeyboardInputEvent
{
public Pre(GuiScreen gui)
{
super(gui);
}
}
/**
* This event fires after {@code GuiScreen.handleKeyboardInput()} provided that the active
* screen has not been changed as a result of {@code GuiScreen.handleKeyboardInput()}.
*/
public static class Post extends KeyboardInputEvent
{
public Post(GuiScreen gui)
{
super(gui);
}
}
}
}