-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fixed crappy key handler - * Key can now be bound to something other than C * Configured keyboard key will save and work on reload * Less complex naming and handler to ease adding new keys * Fixed Chisel blocks not being able to be placed on cables * Fixed language handler crashing game
Showing
11 changed files
with
96 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package mods.eln | ||
|
||
data class KeyState(val name: String, var state: Boolean = false) | ||
|
||
object ServerKeyHandler { | ||
val WRENCH = "Wrench" | ||
val WIKI = "Wiki" | ||
private val keyState = listOf(KeyState(WRENCH)) | ||
|
||
fun get(name: String): Boolean { | ||
return keyState.firstOrNull {it.name == name}?.state?: false | ||
} | ||
|
||
fun set(name: String, state: Boolean) { | ||
keyState.firstOrNull { it.name == name }?.state = state | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,65 @@ | ||
package mods.eln.client; | ||
package mods.eln.client | ||
|
||
import cpw.mods.fml.client.registry.ClientRegistry; | ||
import cpw.mods.fml.common.eventhandler.SubscribeEvent; | ||
import cpw.mods.fml.common.gameevent.InputEvent.KeyInputEvent; | ||
import cpw.mods.fml.common.gameevent.TickEvent.ClientTickEvent; | ||
import cpw.mods.fml.common.gameevent.TickEvent.Phase; | ||
import mods.eln.Eln; | ||
import mods.eln.misc.UtilsClient; | ||
import mods.eln.wiki.Root; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.settings.KeyBinding; | ||
import net.minecraft.util.StatCollector; | ||
import org.lwjgl.input.Keyboard; | ||
import cpw.mods.fml.client.registry.ClientRegistry | ||
import cpw.mods.fml.common.eventhandler.SubscribeEvent | ||
import cpw.mods.fml.common.gameevent.InputEvent.KeyInputEvent | ||
import mods.eln.Eln | ||
import mods.eln.ServerKeyHandler | ||
import mods.eln.i18n.I18N.tr | ||
import mods.eln.misc.Utils | ||
import mods.eln.misc.UtilsClient.clientOpenGui | ||
import mods.eln.misc.UtilsClient.sendPacketToServer | ||
import mods.eln.wiki.Root | ||
import net.minecraft.client.settings.KeyBinding | ||
import net.minecraft.util.StatCollector | ||
import org.lwjgl.input.Keyboard | ||
import java.io.ByteArrayOutputStream | ||
import java.io.DataOutputStream | ||
import java.io.IOException | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.DataOutputStream; | ||
import java.io.IOException; | ||
//import mods.eln.wiki.Root; | ||
data class ElectricalAgeKey(var defaultKeybind: Int, val name: String, var lastState: Boolean = false, var binding: KeyBinding? = null) | ||
|
||
public class ClientKeyHandler { | ||
class ClientKeyHandler { | ||
// Note: C is the default wrench key, but it can be changed with the GUI in-game. This is override with the value stored in options.txt | ||
private val keyboardKeys = listOf( | ||
ElectricalAgeKey(Keyboard.KEY_C, ServerKeyHandler.WRENCH), | ||
ElectricalAgeKey(Keyboard.KEY_W, ServerKeyHandler.WIKI) | ||
) | ||
|
||
static public final int openWikiId = 0; | ||
static public final int wrenchId = 1; | ||
static final String openWiki = "Open Wiki"; | ||
static final String wrench = "Wrench"; | ||
private static final int[] keyValues = {Keyboard.KEY_X, Keyboard.KEY_C}; | ||
private static final String[] desc = {openWiki, wrench}; | ||
public static final KeyBinding[] keys = new KeyBinding[desc.length]; | ||
|
||
boolean[] states = new boolean[desc.length]; | ||
|
||
Minecraft mc; | ||
|
||
public ClientKeyHandler() { | ||
mc = Minecraft.getMinecraft(); | ||
|
||
for (int i = 0; i < desc.length; ++i) { | ||
if (i != 3) | ||
states[i] = false; | ||
keys[i] = new KeyBinding(desc[i], keyValues[i], StatCollector.translateToLocal("ElectricalAge")); | ||
ClientRegistry.registerKeyBinding(keys[i]); | ||
} | ||
} | ||
|
||
@SubscribeEvent | ||
public void onKeyInput(KeyInputEvent event) { | ||
for (int i = 0; i < desc.length; ++i) { | ||
boolean s = keys[i].getIsKeyPressed(); | ||
if (s == false) continue; | ||
if (states[i]) | ||
setState(i, false); | ||
setState(i, true); | ||
init { | ||
keyboardKeys.forEach { | ||
it.binding = KeyBinding(it.name, it.defaultKeybind, StatCollector.translateToLocal("ElectricalAge")) | ||
ClientRegistry.registerKeyBinding(it.binding) | ||
} | ||
} | ||
|
||
@SubscribeEvent | ||
public void tick(ClientTickEvent event) { | ||
if (event.phase != Phase.START) return; | ||
for (int i = 0; i < desc.length; ++i) { | ||
boolean s = keys[i].getIsKeyPressed(); | ||
if (s == false && states[i] == true) { | ||
setState(i, false); | ||
} | ||
fun onKeyInput(event: KeyInputEvent?) { | ||
keyboardKeys.forEach { | ||
setState(it.name, it.binding?.isKeyPressed ?: return@forEach) | ||
} | ||
} | ||
|
||
void setState(int id, boolean state) { | ||
states[id] = state; | ||
|
||
if (id == openWikiId) { | ||
UtilsClient.clientOpenGui(new Root(null)); | ||
} | ||
fun setState(name: String, state: Boolean) { | ||
val entry = keyboardKeys.firstOrNull { it.name == name }?: return | ||
if (entry.lastState != state) { | ||
entry.lastState = state // Be sure to set the state so that it calls again when key released | ||
|
||
ByteArrayOutputStream bos = new ByteArrayOutputStream(64); | ||
DataOutputStream stream = new DataOutputStream(bos); | ||
if (entry.name == ServerKeyHandler.WIKI) { | ||
clientOpenGui(Root(null)) | ||
} | ||
|
||
try { | ||
stream.writeByte(Eln.packetPlayerKey); | ||
stream.writeByte(id); | ||
stream.writeBoolean(state); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
Utils.println("Sending a client key event to server: ${entry.name} is $state") | ||
val bos = ByteArrayOutputStream(64) | ||
val stream = DataOutputStream(bos) | ||
try { | ||
stream.writeByte(Eln.packetPlayerKey.toInt()) | ||
stream.writeUTF(entry.name) | ||
stream.writeBoolean(state) | ||
} catch (e: IOException) { | ||
e.printStackTrace() | ||
} | ||
sendPacketToServer(bos) | ||
} | ||
|
||
UtilsClient.sendPacketToServer(bos); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.