/*
* This file is part of Spoutcraft.
*
* Copyright (c) 2011 SpoutcraftDev <http://spoutcraft.org/>
* Spoutcraft is licensed under the GNU Lesser General Public License.
*
* Spoutcraft 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, either version 3 of the License, or
* (at your option) any later version.
*
* Spoutcraft 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 program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.spoutcraft.client.packet;
import java.io.IOException;
import net.minecraft.src.MovementInputFromOptions;
import org.spoutcraft.api.gui.ScreenType;
import org.spoutcraft.api.io.SpoutInputStream;
import org.spoutcraft.api.io.SpoutOutputStream;
public class PacketKeyPress implements SpoutPacket {
public boolean pressDown;
public int key;
public byte settingKeys[] = new byte[10];
public int screenType = -1;
public PacketKeyPress() {
}
public PacketKeyPress(int key, boolean pressDown, MovementInputFromOptions input) {
this.key = key;
this.pressDown = pressDown;
this.settingKeys[0] = (byte)input.gameSettings.keyBindForward.keyCode;
this.settingKeys[1] = (byte)input.gameSettings.keyBindLeft.keyCode;
this.settingKeys[2] = (byte)input.gameSettings.keyBindBack.keyCode;
this.settingKeys[3] = (byte)input.gameSettings.keyBindRight.keyCode;
this.settingKeys[4] = (byte)input.gameSettings.keyBindJump.keyCode;
this.settingKeys[5] = (byte)input.gameSettings.keyBindInventory.keyCode;
this.settingKeys[6] = (byte)input.gameSettings.keyBindDrop.keyCode;
this.settingKeys[7] = (byte)input.gameSettings.keyBindChat.keyCode;
this.settingKeys[8] = (byte)input.gameSettings.keyBindToggleFog.keyCode;
this.settingKeys[9] = (byte)input.gameSettings.keyBindSneak.keyCode;
}
public PacketKeyPress(int key, boolean pressDown, MovementInputFromOptions input, ScreenType type) {
this.key = key;
this.pressDown = pressDown;
this.settingKeys[0] = (byte)input.gameSettings.keyBindForward.keyCode;
this.settingKeys[1] = (byte)input.gameSettings.keyBindLeft.keyCode;
this.settingKeys[2] = (byte)input.gameSettings.keyBindBack.keyCode;
this.settingKeys[3] = (byte)input.gameSettings.keyBindRight.keyCode;
this.settingKeys[4] = (byte)input.gameSettings.keyBindJump.keyCode;
this.settingKeys[5] = (byte)input.gameSettings.keyBindInventory.keyCode;
this.settingKeys[6] = (byte)input.gameSettings.keyBindDrop.keyCode;
this.settingKeys[7] = (byte)input.gameSettings.keyBindChat.keyCode;
this.settingKeys[8] = (byte)input.gameSettings.keyBindToggleFog.keyCode;
this.settingKeys[9] = (byte)input.gameSettings.keyBindSneak.keyCode;
this.screenType = type.getCode();
}
public void readData(SpoutInputStream datainputstream) throws IOException {
this.key = datainputstream.readInt();
this.pressDown = datainputstream.readBoolean();
this.screenType = datainputstream.readInt();
for (int i = 0; i < 10; i++) {
this.settingKeys[i] = (byte) datainputstream.read();
}
}
public void writeData(SpoutOutputStream dataoutputstream) throws IOException {
dataoutputstream.writeInt(this.key);
dataoutputstream.writeBoolean(this.pressDown);
dataoutputstream.writeInt(this.screenType);
for (int i = 0; i < 10; i++) {
dataoutputstream.write(this.settingKeys[i]);
}
}
public void run(int id) {
}
public int getNumBytes() {
return 4 + 1 + 4 + 10;
}
public PacketType getPacketType() {
return PacketType.PacketKeyPress;
}
public int getVersion() {
return 1;
}
public void failure(int playerId) {
}
}