It gets highlighted in red even without the static, I'm confused, this is the whole code for the tickhandler.
public class PlayerTickHandler implements ITickHandler
{
private final EnumSet<TickType> ticksToGet;
/*
* This Tick Handler will fire for whatever TickType's you construct and register it with.
*/
public PlayerTickHandler(EnumSet<TickType> ticksToGet)
{
this.ticksToGet = ticksToGet;
}
/*
* I suggest putting all your tick Logic in EITHER of these, but staying in one
*/
@Override
public void tickStart(EnumSet<TickType> type, Object... tickData)
{
if (FMLCommonHandler.instance().getEffectiveSide().isClient()){
playerTick((EntityPlayer)tickData[0]);
}
}
@Override
public void tickEnd(EnumSet<TickType> type, Object... tickData)
{
}
@Override
public EnumSet<TickType> ticks()
{
return ticksToGet;
}
@Override
public String getLabel()
{
return "AfgPlayerTick";
}
@Override
public void playerTick(EntityPlayer player)
{ System.out.println("Heyheyehey");
if(PacketHandler.keypressed1 = true)
{
AfgExtendedPlayer props = AfgExtendedPlayer.get(player);
props.plusCurrentSS(.1F);
System.out.println("CurrentSS: " + props.getCurrentSS());
}
if(PacketHandler.keypressed2 = true)
{
AfgExtendedPlayer props = AfgExtendedPlayer.get(player);
props.minusCurrentSS(.1F);
System.out.println("CurrentSS: " + props.getCurrentSS());
}
}
}
Then are you sure your tick handler is even working? Put a println outside of any 'if' statements and see if that prints.
no it didn't, which is weird because I have it registered, and it was working not too long ago..
@EventHandler // used in 1.6.2
public void load(FMLInitializationEvent event) {
TickRegistry.registerTickHandler(new PlayerTickHandler(EnumSet.of(TickType.PLAYER)), Side.SERVER);
So, I think I finally have everything figured out with the packet handling, but for some reason the variable I'm using to see if the key was pressed isn't...
private void handlePacketKeyPress(Packet250CustomPayload packet1, Player player, DataInputStream inputStream)
{
byte key;
try {
key = inputStream.readByte();
} catch (IOException e) {
e.printStackTrace();
return;
}
switch (key) {
case KeybindHandler.SpeedUp: keypressed1 = true; System.out.println("this worked"); break;
case KeybindHandler.SlowDown: keypressed2 = true; System.out.println("this worked too"); break;
//this much is working, because the lines print, but the variable is not changing or the playerTick method isn't reading it for some reason?
}
}
Edit: I know that I need to set the keypressed variables back to false afterwards, but since they aren't working at all I figured I should get that first.
Please read my above post more carefully; the things you did differently are the things causing it to not work.
EDIT: Also, in your onPacketData method, you only ever call 'handleExtendedProperties', so EVERY packet you send will be handled the same, which is not what you want. That's actually the source of your error, although you other things are wrong as well like I mentioned just above.
Yeah, sorry, didn't even see that one, I think I got it all correct now, but I can't test it, because the keys won't work or appear in the controls, even though I registered the keyhandler, but don't I need to register it in the main class somehow?
Keyhandler
@SideOnly(Side.CLIENT)
public class KeybindHandler extends KeyHandler
{
/** Key index for easy handling and retrieval of keys and key descriptions */
public static final byte SpeedUp = 0, SlowDown = 1;
/** Key descriptions - this is what the player sees when changing key bindings in-game */
public static final String[] desc = {"Description 1","Description 2"};
/** Default key values */
private static final int[] keyValues = {Keyboard.KEY_Z, Keyboard.KEY_C};
/** This stores all the keybindings, but they must first be initialized */
public static final KeyBinding[] keys = new KeyBinding[desc.length];
/** Initializes keybindings and registers a new KeyHandler instance */
public static final void init()
{
// this way avoids declaring every key binding as its own 'static final' field
boolean[] repeat = new boolean[desc.length];
for (int i = 0; i < desc.length; ++i) {
keys[i] = new KeyBinding(desc[i], keyValues[i]);
repeat[i] = false;
}
KeyBindingRegistry.registerKeyBinding(new KeybindHandler(keys, repeat));
}
public KeybindHandler(KeyBinding[] keys, boolean[] repeat) { super(keys, repeat); }
public static byte key;
public static boolean[] repeat;
@Override
public void keyDown(EnumSet<TickType> types, KeyBinding kb, boolean tickEnd, boolean isRepeat) {
if (tickEnd)
{
if (kb.keyCode == keys[SpeedUp].keyCode) { key = SpeedUp; }
else if (kb.keyCode == keys[SlowDown].keyCode) { key = SlowDown; }
EntityClientPlayerMP player = FMLClientHandler.instance().getClient().thePlayer;
player.sendQueue.addToSendQueue(PacketKeyPress.getPacket((byte)(key)));
}
}
@Override
public String getLabel() {
// TODO Auto-generated method stub
return null;
}
@Override
public void keyUp(EnumSet<TickType> types, KeyBinding kb, boolean tickEnd) {
// TODO Auto-generated method stub
}
@Override
public EnumSet<TickType> ticks() {
// TODO Auto-generated method stub
return null;
}
}
So, one last question for you, and in hindsight I should probably put this in the keybinding tutorial page but oh well, I'm already writing it, so in your comment there you showed a better way to do multiple keybindings which helped a lot, but if I'm correct that has the keymap on the keybinding class, which the server can't access, so when you send a packet, how does the server know what key was pressed?
I'm also confused on this line in the example packet you listed(specifically ModInfo.CHANNEL), is it specific to your mod or am I missing something?:
return new Packet250CustomPayload(ModInfo.CHANNEL, bos.toByteArray());
Got another error, this time in the packet handling portion of the gui tutorial, at these lines it's saying .isServer cannot be resolved or is not a field, but I can see it clearly in the Side.java class, really confusing me.
wondering if you could give me any help, it's saying "proxy cannot be resolved" and "The method saveProxyData(EntityPlayer) is undefined for the type ExtendedPLayer"
0
0
0
0
nope, didn't work
0
playerTick Method
0
Yeah, sorry, didn't even see that one, I think I got it all correct now, but I can't test it, because the keys won't work or appear in the controls, even though I registered the keyhandler, but don't I need to register it in the main class somehow?
Keyhandler
0
The Packet
Keydown method
0
Well, I think I got that to work, but for some reason I'm getting this error on world startup and when joining a server:
2013-12-24 18:17:06 [INFO] [STDERR] java.io.EOFException
2013-12-24 18:17:06 [INFO] [STDERR] at java.io.DataInputStream.readByte(Unknown Source)
2013-12-24 18:17:06 [INFO] [STDERR] at afg.flash.PacketHandler.handleExtendedProperties(PacketHandler.java:46)
2013-12-24 18:17:06 [INFO] [STDERR] at afg.flash.PacketHandler.onPacketData(PacketHandler.java:23)
2013-12-24 18:17:06 [INFO] [STDERR] at cpw.mods.fml.common.network.NetworkRegistry.handlePacket(NetworkRegistry.java:255)
2013-12-24 18:17:06 [INFO] [STDERR] at cpw.mods.fml.common.network.NetworkRegistry.handleCustomPacket(NetworkRegistry.java:245)
2013-12-24 18:17:06 [INFO] [STDERR] at cpw.mods.fml.common.network.FMLNetworkHandler.handlePacket250Packet(FMLNetworkHandler.java:85)
2013-12-24 18:17:06 [INFO] [STDERR] at net.minecraft.client.multiplayer.NetClientHandler.handleCustomPayload(NetClientHandler.java:1651)
2013-12-24 18:17:06 [INFO] [STDERR] at net.minecraft.network.packet.Packet250CustomPayload.processPacket(Packet250CustomPayload.java:70)
2013-12-24 18:17:06 [INFO] [STDERR] at net.minecraft.network.MemoryConnection.processReadPackets(MemoryConnection.java:89)
2013-12-24 18:17:06 [INFO] [STDERR] at net.minecraft.client.Minecraft.runTick(Minecraft.java:1967)
2013-12-24 18:17:06 [INFO] [STDERR] at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:910)
2013-12-24 18:17:06 [INFO] [STDERR] at net.minecraft.client.Minecraft.run(Minecraft.java:838)
2013-12-24 18:17:06 [INFO] [STDERR] at net.minecraft.client.main.Main.main(Main.java:93)
2013-12-24 18:17:06 [INFO] [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2013-12-24 18:17:06 [INFO] [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
2013-12-24 18:17:06 [INFO] [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
2013-12-24 18:17:06 [INFO] [STDERR] at java.lang.reflect.Method.invoke(Unknown Source)
2013-12-24 18:17:06 [INFO] [STDERR] at net.minecraft.launchwrapper.Launch.launch(Launch.java:131)
2013-12-24 18:17:06 [INFO] [STDERR] at net.minecraft.launchwrapper.Launch.main(Launch.java:27)
0
what I have there doesn't seem to be working.
0
I'm also confused on this line in the example packet you listed(specifically ModInfo.CHANNEL), is it specific to your mod or am I missing something?:
0
EDIT: Nevermind, i feel really dumb now, just have to add a parenthesis...
0
I'm attempting to follow your Tutorial, and I'm having a bit of trouble with the bit about keeping the value after death, specifically these lines.
proxy.storeEntityData(((EntityPlayer) event.entity).username, playerData);
// call our handy static one-liner to save custom data to the proxy
PlayerValues.saveProxyData((EntityPlayer) event.entity);
}
wondering if you could give me any help, it's saying "proxy cannot be resolved" and "The method saveProxyData(EntityPlayer) is undefined for the type ExtendedPLayer"
0
1