mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-12 08:17:35 +00:00
[1.13.x] Fire InputEvents (#5533)
This commit is contained in:
1 parent
8515b9dd10
commit
bbc92fa51c
7 files changed
+148
-54
No files matched your search
@@ -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));
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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 {}
|
||||
}
|
||||
@@ -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));
|
||||
|
||||
Reference in new issue
Block a user