mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-18 19:39:22 +00:00
New key handling
This commit is contained in:
1 parent
899c1f519c
commit
6ff67693b9
3 files changed
+44
-14
No files matched your search
@@ -281,10 +281,6 @@ public class FMLClientHandler implements IFMLSidedHandler
|
||||
FMLCommonHandler.instance().tickEnd(EnumSet.of(TickType.WORLD), client.field_6324_e, client.field_6313_p, client.field_6324_e);
|
||||
FMLCommonHandler.instance().tickEnd(EnumSet.of(TickType.GAME,TickType.WORLDGUI), 0.0f, client.field_6313_p, client.field_6324_e);
|
||||
}
|
||||
for (IKeyHandler entry : keyHandlers)
|
||||
{
|
||||
entry.onEndTick();
|
||||
}
|
||||
}
|
||||
|
||||
public void onWorldLoadTick()
|
||||
@@ -716,7 +712,7 @@ public class FMLClientHandler implements IFMLSidedHandler
|
||||
public void registerKeyHandler(BaseMod mod, KeyBinding keyHandler, boolean allowRepeat)
|
||||
{
|
||||
ModLoaderModContainer mlmc=ModLoaderHelper.registerKeyHelper(mod);
|
||||
mlmc.addKeyHandler(new KeyBindingHandler(keyHandler, allowRepeat, mlmc));
|
||||
mlmc.addKeyHandler(new ModLoaderKeyBindingHandler(keyHandler, allowRepeat, mlmc));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+42
-5
@@ -14,36 +14,42 @@
|
||||
|
||||
package cpw.mods.fml.client;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
import net.minecraft.src.KeyBinding;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.IKeyHandler;
|
||||
import cpw.mods.fml.common.ModContainer;
|
||||
import cpw.mods.fml.common.TickType;
|
||||
import cpw.mods.fml.common.modloader.ModLoaderModContainer;
|
||||
|
||||
/**
|
||||
* @author cpw
|
||||
*
|
||||
*/
|
||||
public class KeyBindingHandler implements IKeyHandler
|
||||
public class ModLoaderKeyBindingHandler implements IKeyHandler
|
||||
{
|
||||
|
||||
private boolean shouldRepeat;
|
||||
private KeyBinding keyBinding;
|
||||
private ModContainer modContainer;
|
||||
private boolean lastState = false;
|
||||
private boolean armed;
|
||||
|
||||
/**
|
||||
* @param keyHandler
|
||||
* @param allowRepeat
|
||||
* @param modContainer
|
||||
* @param modContainer
|
||||
*/
|
||||
public KeyBindingHandler(KeyBinding keyHandler, boolean allowRepeat, ModContainer modContainer)
|
||||
public ModLoaderKeyBindingHandler(KeyBinding keyHandler, boolean allowRepeat, ModContainer modContainer)
|
||||
{
|
||||
this.keyBinding=keyHandler;
|
||||
this.shouldRepeat=allowRepeat;
|
||||
this.modContainer=modContainer;
|
||||
FMLCommonHandler.instance().registerTickHandler(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -60,8 +66,7 @@ public class KeyBindingHandler implements IKeyHandler
|
||||
return modContainer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEndTick()
|
||||
public void onRenderEndTick()
|
||||
{
|
||||
int keyCode = keyBinding.field_1370_b;
|
||||
boolean state = (keyCode < 0 ? Mouse.isButtonDown(keyCode + 100) : Keyboard.isKeyDown(keyCode));
|
||||
@@ -71,4 +76,36 @@ public class KeyBindingHandler implements IKeyHandler
|
||||
}
|
||||
lastState = state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tickStart(EnumSet<TickType> type, Object... tickData)
|
||||
{
|
||||
// NO-OP for ML
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tickEnd(EnumSet<TickType> type, Object... tickData)
|
||||
{
|
||||
if (type.contains(TickType.GUILOAD)|| type.contains(TickType.GAME))
|
||||
{
|
||||
armed = true;
|
||||
}
|
||||
if (type.contains(TickType.RENDER) && armed)
|
||||
{
|
||||
onRenderEndTick();
|
||||
armed = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumSet<TickType> ticks()
|
||||
{
|
||||
return EnumSet.of(TickType.GAME, TickType.RENDER, TickType.GUILOAD);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLabel()
|
||||
{
|
||||
return getOwningContainer()+" KB "+keyBinding.field_1371_a;
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ package cpw.mods.fml.common;
|
||||
* @author cpw
|
||||
*
|
||||
*/
|
||||
public interface IKeyHandler
|
||||
public interface IKeyHandler extends ITickHandler
|
||||
{
|
||||
|
||||
Object getKeyBinding();
|
||||
@@ -27,7 +27,4 @@ public interface IKeyHandler
|
||||
* @return
|
||||
*/
|
||||
ModContainer getOwningContainer();
|
||||
|
||||
void onEndTick();
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user