[1.13.x] Fire InputEvents (#5533)

This commit is contained in:
0uti 2019-04-16 03:50:18 +02:00 committed by LexManos
parent 8515b9dd10
commit bbc92fa51c
7 changed files with 148 additions and 54 deletions

View File

@ -36,6 +36,15 @@
}
}, "keyPressed event handler", iguieventlistener.getClass().getCanonicalName());
@@ -341,7 +348,7 @@
}
}
}
-
+ net.minecraftforge.client.ForgeHooksClient.fireKeyInput(p_197961_3_, p_197961_4_, p_197961_5_, p_197961_6_);
}
}
@@ -351,12 +358,16 @@
if (iguieventlistener != null) {
if (Character.charCount(p_197963_3_) == 1) {

View File

@ -18,6 +18,15 @@
}, "mouseReleased event handler", this.field_198036_a.field_71462_r.getClass().getCanonicalName());
}
}
@@ -103,7 +107,7 @@
}
}
}
-
+ net.minecraftforge.client.ForgeHooksClient.fireMouseInput(p_198023_3_, p_198023_4_, p_198023_5_);
}
}
@@ -111,7 +115,9 @@
if (p_198020_1_ == Minecraft.func_71410_x().field_195558_d.func_198092_i()) {
double d0 = p_198020_5_ * this.field_198036_a.field_71474_y.field_208033_V;

View File

@ -18,14 +18,6 @@
Display.setVSyncEnabled(this.field_71474_y.field_74352_v);
this.func_175601_h();
}
@@ -1982,6 +2013,7 @@
}
}
}
+ net.minecraftforge.fml.common.FMLCommonHandler.instance().fireKeyInput();
}
this.func_184117_aA();
@@ -2239,6 +2271,8 @@
{
while (Mouse.next())
@ -35,14 +27,6 @@
int i = Mouse.getEventButton();
KeyBinding.func_74510_a(i - 100, Mouse.getEventButtonState());
@@ -2294,6 +2328,7 @@
this.field_71462_r.func_146274_d();
}
}
+ net.minecraftforge.fml.common.FMLCommonHandler.instance().fireMouseInput();
}
}
@@ -2304,6 +2339,7 @@
public void func_71371_a(String p_71371_1_, String p_71371_2_, @Nullable WorldSettings p_71371_3_)

View File

@ -127,6 +127,7 @@ import net.minecraftforge.client.model.ModelDynBucket;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.client.model.animation.Animation;
import net.minecraftforge.client.model.pipeline.QuadGatheringTransformer;
import net.minecraftforge.client.event.InputEvent;
import net.minecraftforge.common.ForgeMod;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.model.IModelPart;
@ -1036,4 +1037,14 @@ public class ForgeHooksClient
LOGGER.error("Unable to invalidate log4j thread cache, thread fields in logs may be inaccurate", e);
}
}
public static void fireMouseInput(int button, int action, int mods)
{
MinecraftForge.EVENT_BUS.post(new InputEvent.MouseInputEvent(button, action, mods));
}
public static void fireKeyInput(int key, int scanCode, int action, int modifiers)
{
MinecraftForge.EVENT_BUS.post(new InputEvent.KeyInputEvent(key, scanCode, action, modifiers));
}
}

View File

@ -0,0 +1,119 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2019.
*
* 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
*/
package net.minecraftforge.client.event;
import net.minecraft.client.util.InputMappings;
import net.minecraftforge.eventbus.api.Event;
import org.lwjgl.glfw.GLFW;
public class InputEvent extends Event
{
/**
* This event fires when a mouse button is pressed.
*/
public static class MouseInputEvent extends InputEvent
{
private final int button;
private final int action;
private final int mods;
public MouseInputEvent(int button, int action, int mods)
{
this.button = button;
this.action = action;
this.mods = mods;
}
public int getButton()
{
return this.button;
}
public int getAction()
{
return this.action;
}
public int getMods()
{
return this.mods;
}
}
/**
* This event fires when keyboard input is detected.
*/
public static class KeyInputEvent extends InputEvent
{
private final int key;
private final int scanCode;
private final int action;
private final int modifiers;
public KeyInputEvent(int key, int scanCode, int action, int modifiers)
{
this.key = key;
this.scanCode = scanCode;
this.action = action;
this.modifiers = modifiers;
}
/**
* The keyboard key that was pressed or released
* https://www.glfw.org/docs/latest/group__keys.html
*
* @see GLFW key constants starting with "GLFW_KEY_"
*/
public int getKey()
{
return this.key;
}
/**
* Platform-specific scan code.
* Used for {@link InputMappings#getInputByCode(int, int)}
*
* The scan code is unique for every key, regardless of whether it has a key code.
* Scan codes are platform-specific but consistent over time, so keys will have different scan codes depending
* on the platform but they are safe to save to disk as custom key bindings.
*/
public int getScanCode()
{
return this.scanCode;
}
public int getAction()
{
return this.action;
}
/**
* Bit field representing the modifier keys pressed.
*
* @see GLFW#GLFW_MOD_SHIFT
* @see GLFW#GLFW_MOD_CONTROL
* @see GLFW#GLFW_MOD_ALT
* @see GLFW#GLFW_MOD_SUPER
*/
public int getModifiers()
{
return this.modifiers;
}
}
}

View File

@ -1,27 +0,0 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2019.
*
* 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
*/
package net.minecraftforge.fml.common.gameevent;
import net.minecraftforge.eventbus.api.Event;
public class InputEvent extends Event {
public static class MouseInputEvent extends InputEvent {}
public static class KeyInputEvent extends InputEvent {}
}

View File

@ -28,22 +28,11 @@ import net.minecraft.world.dimension.DimensionType;
import net.minecraftforge.client.model.animation.Animation;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.LogicalSide;
import net.minecraftforge.fml.common.gameevent.InputEvent;
import net.minecraftforge.fml.common.gameevent.PlayerEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
public class BasicEventHooks
{
public static void fireMouseInput()
{
MinecraftForge.EVENT_BUS.post(new InputEvent.MouseInputEvent());
}
public static void fireKeyInput()
{
MinecraftForge.EVENT_BUS.post(new InputEvent.KeyInputEvent());
}
public static void firePlayerChangedDimensionEvent(EntityPlayer player, DimensionType fromDim, DimensionType toDim)
{
MinecraftForge.EVENT_BUS.post(new PlayerEvent.PlayerChangedDimensionEvent(player, fromDim, toDim));