Fixed key handler, added complete keybind support, added proper error messages, more work on walkie talkies.
This commit is contained in:
parent
cafe2a7dfb
commit
0feba0d9b3
6 changed files with 91 additions and 31 deletions
|
@ -25,9 +25,7 @@ import cpw.mods.fml.relauncher.SideOnly;
|
|||
@SideOnly(Side.CLIENT)
|
||||
public class ClientPlayerTickHandler implements ITickHandler
|
||||
{
|
||||
public boolean lastTickConfiguratorChange = false;
|
||||
public boolean lastTickElectricBowChange = false;
|
||||
public boolean lastTickWalkieTalkieChange = false;
|
||||
public boolean lastTickUpdate = false;
|
||||
|
||||
@Override
|
||||
public void tickStart(EnumSet<TickType> type, Object... tickData) {}
|
||||
|
@ -47,56 +45,59 @@ public class ClientPlayerTickHandler implements ITickHandler
|
|||
{
|
||||
ItemConfigurator item = (ItemConfigurator)entityPlayer.getCurrentEquippedItem().getItem();
|
||||
|
||||
if(entityPlayer.isSneaking() && Keyboard.isKeyDown(Keyboard.KEY_M))
|
||||
if(entityPlayer.isSneaking() && MekanismKeyHandler.modeSwitchDown)
|
||||
{
|
||||
if(!lastTickConfiguratorChange)
|
||||
if(!lastTickUpdate)
|
||||
{
|
||||
item.setState(stack, (byte)(item.getState(stack) < 2 ? item.getState(stack)+1 : 0));
|
||||
PacketHandler.sendPacket(Transmission.SERVER, new PacketConfiguratorState().setParams(item.getState(stack)));
|
||||
entityPlayer.sendChatToPlayer(ChatMessageComponent.createFromText(EnumColor.DARK_BLUE + "[Mekanism] " + EnumColor.GREY + "Configure State: " + item.getColor(item.getState(stack)) + item.getState(item.getState(stack))));
|
||||
lastTickConfiguratorChange = true;
|
||||
lastTickUpdate = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
lastTickConfiguratorChange = false;
|
||||
lastTickUpdate = false;
|
||||
}
|
||||
}
|
||||
else if(entityPlayer.getCurrentEquippedItem().getItem() instanceof ItemElectricBow)
|
||||
{
|
||||
ItemElectricBow item = (ItemElectricBow)entityPlayer.getCurrentEquippedItem().getItem();
|
||||
|
||||
if(entityPlayer.isSneaking() && Keyboard.isKeyDown(Keyboard.KEY_M))
|
||||
if(entityPlayer.isSneaking() && MekanismKeyHandler.modeSwitchDown)
|
||||
{
|
||||
if(!lastTickElectricBowChange)
|
||||
if(!lastTickUpdate)
|
||||
{
|
||||
item.setFireState(stack, !item.getFireState(stack));
|
||||
PacketHandler.sendPacket(Transmission.SERVER, new PacketElectricBowState().setParams(item.getFireState(stack)));
|
||||
entityPlayer.sendChatToPlayer(ChatMessageComponent.createFromText(EnumColor.DARK_BLUE + "[Mekanism] " + EnumColor.GREY + "Fire Mode: " + (item.getFireState(stack) ? (EnumColor.DARK_GREEN + "ON") : (EnumColor.DARK_RED + "OFF"))));
|
||||
lastTickElectricBowChange = true;
|
||||
lastTickUpdate = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
lastTickElectricBowChange = false;
|
||||
lastTickUpdate = false;
|
||||
}
|
||||
}
|
||||
else if(entityPlayer.getCurrentEquippedItem().getItem() instanceof ItemWalkieTalkie)
|
||||
{
|
||||
ItemWalkieTalkie item = (ItemWalkieTalkie)entityPlayer.getCurrentEquippedItem().getItem();
|
||||
|
||||
if(entityPlayer.isSneaking() && Keyboard.isKeyDown(Keyboard.KEY_M) && item.getOn(stack))
|
||||
if(entityPlayer.isSneaking() && MekanismKeyHandler.modeSwitchDown && item.getOn(stack))
|
||||
{
|
||||
if(!lastTickWalkieTalkieChange)
|
||||
if(!lastTickUpdate)
|
||||
{
|
||||
int newChan = item.getChannel(stack) < 9 ? item.getChannel(stack)+1 : 1;
|
||||
item.setChannel(stack, newChan);
|
||||
PacketHandler.sendPacket(Transmission.SERVER, new PacketWalkieTalkieState().setParams(newChan));
|
||||
lastTickWalkieTalkieChange = true;
|
||||
lastTickUpdate = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
lastTickWalkieTalkieChange = false;
|
||||
lastTickUpdate = false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
lastTickUpdate = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,11 +14,12 @@ public class MekanismKeyHandler extends KeyHandler
|
|||
public static KeyBinding modeSwitch = new KeyBinding("Mekanism Mode Switch", Keyboard.KEY_M);
|
||||
public static KeyBinding voice = new KeyBinding("Mekanism Voice", Keyboard.KEY_U);
|
||||
|
||||
public static boolean modeSwitchDown = false;
|
||||
public static boolean voiceDown = false;
|
||||
|
||||
public MekanismKeyHandler()
|
||||
{
|
||||
super(new KeyBinding[] {modeSwitch, voice});
|
||||
super(new KeyBinding[] {modeSwitch, voice}, new boolean[] {false, false});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -30,7 +31,11 @@ public class MekanismKeyHandler extends KeyHandler
|
|||
@Override
|
||||
public void keyDown(EnumSet<TickType> types, KeyBinding kb, boolean tickEnd, boolean isRepeat)
|
||||
{
|
||||
if(kb == voice)
|
||||
if(kb.keyCode == modeSwitch.keyCode)
|
||||
{
|
||||
modeSwitchDown = true;
|
||||
}
|
||||
else if(kb.keyCode == voice.keyCode)
|
||||
{
|
||||
voiceDown = true;
|
||||
}
|
||||
|
@ -39,7 +44,11 @@ public class MekanismKeyHandler extends KeyHandler
|
|||
@Override
|
||||
public void keyUp(EnumSet<TickType> types, KeyBinding kb, boolean tickEnd)
|
||||
{
|
||||
if(kb == voice)
|
||||
if(kb.keyCode == modeSwitch.keyCode)
|
||||
{
|
||||
modeSwitchDown = false;
|
||||
}
|
||||
else if(kb.keyCode == voice.keyCode)
|
||||
{
|
||||
voiceDown = false;
|
||||
}
|
||||
|
|
|
@ -34,6 +34,9 @@ public class VoiceClientManager implements IConnectionHandler
|
|||
public TargetDataLine targetLine;
|
||||
public SourceDataLine sourceLine;
|
||||
|
||||
public Thread microphoneThread;
|
||||
public Thread speakerThread;
|
||||
|
||||
public DataInputStream input;
|
||||
public DataOutputStream output;
|
||||
|
||||
|
@ -89,12 +92,14 @@ public class VoiceClientManager implements IConnectionHandler
|
|||
|
||||
public void start()
|
||||
{
|
||||
System.out.println("Started client connection.");
|
||||
|
||||
try {
|
||||
input = new DataInputStream(new BufferedInputStream(socket.getInputStream()));
|
||||
output = new DataOutputStream(new BufferedOutputStream(socket.getOutputStream()));
|
||||
|
||||
//Speaker (Out)
|
||||
new Thread(new Runnable()
|
||||
speakerThread = new Thread(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
|
@ -106,7 +111,6 @@ public class VoiceClientManager implements IConnectionHandler
|
|||
|
||||
while(running)
|
||||
{
|
||||
System.out.println("Looped");
|
||||
short byteCount = VoiceClientManager.this.input.readShort();
|
||||
byte[] audioData = new byte[byteCount];
|
||||
VoiceClientManager.this.input.readFully(audioData);
|
||||
|
@ -115,12 +119,15 @@ public class VoiceClientManager implements IConnectionHandler
|
|||
}
|
||||
} catch(Exception e) {
|
||||
System.err.println("Error while running speaker loop.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
});
|
||||
|
||||
speakerThread.start();
|
||||
|
||||
//Microphone (In)
|
||||
new Thread(new Runnable()
|
||||
microphoneThread = new Thread(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
|
@ -147,7 +154,6 @@ public class VoiceClientManager implements IConnectionHandler
|
|||
|
||||
if(bytesRead > 0)
|
||||
{
|
||||
System.out.println("Writing");
|
||||
output.writeShort(audioData.length);
|
||||
output.write(audioData);
|
||||
}
|
||||
|
@ -180,13 +186,23 @@ public class VoiceClientManager implements IConnectionHandler
|
|||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
} catch(Exception e) {}
|
||||
});
|
||||
|
||||
microphoneThread.start();
|
||||
} catch(Exception e) {
|
||||
System.err.println("Error in core client initiation.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void stop()
|
||||
{
|
||||
System.out.println("Stopped client connection.");
|
||||
|
||||
try {
|
||||
microphoneThread.interrupt();
|
||||
speakerThread.interrupt();
|
||||
|
||||
sourceLine.flush();
|
||||
sourceLine.close();
|
||||
|
||||
|
|
|
@ -354,7 +354,7 @@ public class Mekanism
|
|||
"COC", "TAT", "COC", Character.valueOf('C'), AtomicCore, Character.valueOf('O'), "ingotRefinedObsidian", Character.valueOf('T'), EnergyTablet.getUnchargedItem(), Character.valueOf('A'), MekanismUtils.getEnergyCube(EnergyCubeTier.ELITE)
|
||||
}));
|
||||
CraftingManager.getInstance().getRecipeList().add(new MekanismRecipe(new ItemStack(ControlCircuit), new Object[] {
|
||||
" P ", "PEP", " P ", Character.valueOf('P'), "ingotOsmium", Character.valueOf('E'), EnrichedAlloy
|
||||
"RER", Character.valueOf('R'), Item.redstone, Character.valueOf('E'), EnrichedAlloy
|
||||
}));
|
||||
CraftingManager.getInstance().getRecipeList().add(new ShapelessOreRecipe(new ItemStack(EnrichedIron, 2), new Object[] {
|
||||
MaganeseAlloy, Item.ingotIron
|
||||
|
@ -419,6 +419,9 @@ public class Mekanism
|
|||
CraftingManager.getInstance().getRecipeList().add(new MekanismRecipe(new ItemStack(NetworkReader), new Object[] {
|
||||
" G ", "AEA", " I ", Character.valueOf('G'), Block.glass, Character.valueOf('A'), EnrichedAlloy, Character.valueOf('E'), EnergyTablet.getUnchargedItem(), Character.valueOf('I'), "ingotSteel"
|
||||
}));
|
||||
CraftingManager.getInstance().getRecipeList().add(new MekanismRecipe(new ItemStack(WalkieTalkie), new Object[] {
|
||||
" O", "SCS", " S ", Character.valueOf('O'), "ingotOsmium", Character.valueOf('S'), "ingotSteel", Character.valueOf('C'), "circuitBasic"
|
||||
}));
|
||||
|
||||
//Factory Recipes
|
||||
CraftingManager.getInstance().getRecipeList().add(new MekanismRecipe(MekanismUtils.getFactory(FactoryTier.BASIC, RecipeType.SMELTING), new Object[] {
|
||||
|
|
|
@ -55,6 +55,8 @@ public class VoiceConnection
|
|||
}
|
||||
}
|
||||
} catch(Exception e) {
|
||||
System.err.println("Error while starting server-based connection.");
|
||||
e.printStackTrace();
|
||||
open = false;
|
||||
}
|
||||
|
||||
|
@ -73,6 +75,7 @@ public class VoiceConnection
|
|||
|
||||
if(byteCount > 0)
|
||||
{
|
||||
System.out.println("Got data");
|
||||
Mekanism.voiceManager.sendToPlayers(byteCount, audioData, VoiceConnection.this);
|
||||
}
|
||||
} catch(Exception e) {
|
||||
|
@ -96,7 +99,10 @@ public class VoiceConnection
|
|||
socket.close();
|
||||
|
||||
Mekanism.voiceManager.connections.remove(this);
|
||||
} catch(Exception e) {}
|
||||
} catch(Exception e) {
|
||||
System.err.println("Error while stopping server-based connection.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void sendToPlayer(short byteCount, byte[] audioData, VoiceConnection connection)
|
||||
|
@ -111,7 +117,10 @@ public class VoiceConnection
|
|||
output.write(audioData);
|
||||
|
||||
output.flush();
|
||||
} catch(Exception e) {}
|
||||
} catch(Exception e) {
|
||||
System.err.println("Error while sending data to player.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canListen(int channel)
|
||||
|
@ -122,9 +131,12 @@ public class VoiceConnection
|
|||
{
|
||||
if(itemStack.getItem() instanceof ItemWalkieTalkie)
|
||||
{
|
||||
if(((ItemWalkieTalkie)itemStack.getItem()).getChannel(itemStack) == channel)
|
||||
if(((ItemWalkieTalkie)itemStack.getItem()).getOn(itemStack))
|
||||
{
|
||||
return true;
|
||||
if(((ItemWalkieTalkie)itemStack.getItem()).getChannel(itemStack) == channel)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -143,7 +155,10 @@ public class VoiceConnection
|
|||
|
||||
if(walkieTalkie != null)
|
||||
{
|
||||
return walkieTalkie.getChannel(itemStack);
|
||||
if(walkieTalkie.getOn(itemStack))
|
||||
{
|
||||
return walkieTalkie.getChannel(itemStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package mekanism.common;
|
|||
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -25,6 +26,8 @@ public class VoiceServerManager implements IConnectionHandler
|
|||
|
||||
public void start()
|
||||
{
|
||||
System.out.println("Starting up voice server.");
|
||||
|
||||
try {
|
||||
serverSocket = new ServerSocket(36123);
|
||||
|
||||
|
@ -39,6 +42,12 @@ public class VoiceServerManager implements IConnectionHandler
|
|||
Socket s = serverSocket.accept();
|
||||
VoiceConnection connection = new VoiceConnection(s);
|
||||
connections.add(connection);
|
||||
System.out.println("Accepted new connection.");
|
||||
} catch(SocketException e) {
|
||||
if(!e.getLocalizedMessage().toLowerCase().equals("socket closed"))
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch(Exception e) {
|
||||
System.err.println("Error while accepting connection.");
|
||||
e.printStackTrace();
|
||||
|
@ -60,6 +69,13 @@ public class VoiceServerManager implements IConnectionHandler
|
|||
|
||||
serverSocket.close();
|
||||
serverSocket = null;
|
||||
|
||||
System.out.println("Shutting down voice server.");
|
||||
} catch(SocketException e) {
|
||||
if(!e.getLocalizedMessage().toLowerCase().equals("socket closed"))
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch(Exception e) {
|
||||
System.err.println("Error while stopping voice server.");
|
||||
e.printStackTrace();
|
||||
|
|
Loading…
Add table
Reference in a new issue