diff --git a/pom.xml b/pom.xml
index 8d8b7d98..9fef15c4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
4.0.0
org.spacehq
mcprotocollib
- 1.8.8-SNAPSHOT
+ 15w32c
jar
MCProtocolLib
diff --git a/src/main/java/org/spacehq/mc/protocol/MinecraftConstants.java b/src/main/java/org/spacehq/mc/protocol/MinecraftConstants.java
index 0a916f7e..23591786 100644
--- a/src/main/java/org/spacehq/mc/protocol/MinecraftConstants.java
+++ b/src/main/java/org/spacehq/mc/protocol/MinecraftConstants.java
@@ -2,8 +2,8 @@ package org.spacehq.mc.protocol;
public class MinecraftConstants {
// General Constants
- public static final String GAME_VERSION = "1.8.8";
- public static final int PROTOCOL_VERSION = 47;
+ public static final String GAME_VERSION = "15w32c";
+ public static final int PROTOCOL_VERSION = 54;
// General Key Constants
public static final String PROFILE_KEY = "profile";
diff --git a/src/main/java/org/spacehq/mc/protocol/MinecraftProtocol.java b/src/main/java/org/spacehq/mc/protocol/MinecraftProtocol.java
index 0f5104f9..2e5cc422 100644
--- a/src/main/java/org/spacehq/mc/protocol/MinecraftProtocol.java
+++ b/src/main/java/org/spacehq/mc/protocol/MinecraftProtocol.java
@@ -22,6 +22,7 @@ import org.spacehq.mc.protocol.packet.ingame.client.player.ClientPlayerPositionP
import org.spacehq.mc.protocol.packet.ingame.client.player.ClientPlayerPositionRotationPacket;
import org.spacehq.mc.protocol.packet.ingame.client.player.ClientPlayerRotationPacket;
import org.spacehq.mc.protocol.packet.ingame.client.player.ClientPlayerStatePacket;
+import org.spacehq.mc.protocol.packet.ingame.client.player.ClientPlayerUseItemPacket;
import org.spacehq.mc.protocol.packet.ingame.client.player.ClientSpectatePacket;
import org.spacehq.mc.protocol.packet.ingame.client.player.ClientSteerVehiclePacket;
import org.spacehq.mc.protocol.packet.ingame.client.player.ClientSwingArmPacket;
@@ -56,7 +57,7 @@ import org.spacehq.mc.protocol.packet.ingame.server.entity.ServerEntityEquipment
import org.spacehq.mc.protocol.packet.ingame.server.entity.ServerEntityHeadLookPacket;
import org.spacehq.mc.protocol.packet.ingame.server.entity.ServerEntityMetadataPacket;
import org.spacehq.mc.protocol.packet.ingame.server.entity.ServerEntityMovementPacket;
-import org.spacehq.mc.protocol.packet.ingame.server.entity.ServerEntityNBTUpdatePacket;
+import org.spacehq.mc.protocol.packet.ingame.server.ServerBossBarPacket;
import org.spacehq.mc.protocol.packet.ingame.server.entity.ServerEntityPositionPacket;
import org.spacehq.mc.protocol.packet.ingame.server.entity.ServerEntityPositionRotationPacket;
import org.spacehq.mc.protocol.packet.ingame.server.entity.ServerEntityPropertiesPacket;
@@ -386,7 +387,7 @@ public class MinecraftProtocol extends PacketProtocol {
this.registerIncoming(70, ServerSetCompressionPacket.class);
this.registerIncoming(71, ServerPlayerListDataPacket.class);
this.registerIncoming(72, ServerResourcePackSendPacket.class);
- this.registerIncoming(73, ServerEntityNBTUpdatePacket.class);
+ this.registerIncoming(73, ServerBossBarPacket.class);
this.registerOutgoing(0, ClientKeepAlivePacket.class);
this.registerOutgoing(1, ClientChatPacket.class);
@@ -396,24 +397,25 @@ public class MinecraftProtocol extends PacketProtocol {
this.registerOutgoing(5, ClientPlayerRotationPacket.class);
this.registerOutgoing(6, ClientPlayerPositionRotationPacket.class);
this.registerOutgoing(7, ClientPlayerActionPacket.class);
- this.registerOutgoing(8, ClientPlayerPlaceBlockPacket.class);
- this.registerOutgoing(9, ClientChangeHeldItemPacket.class);
- this.registerOutgoing(10, ClientSwingArmPacket.class);
- this.registerOutgoing(11, ClientPlayerStatePacket.class);
- this.registerOutgoing(12, ClientSteerVehiclePacket.class);
- this.registerOutgoing(13, ClientCloseWindowPacket.class);
- this.registerOutgoing(14, ClientWindowActionPacket.class);
- this.registerOutgoing(15, ClientConfirmTransactionPacket.class);
- this.registerOutgoing(16, ClientCreativeInventoryActionPacket.class);
- this.registerOutgoing(17, ClientEnchantItemPacket.class);
- this.registerOutgoing(18, ClientUpdateSignPacket.class);
- this.registerOutgoing(19, ClientPlayerAbilitiesPacket.class);
- this.registerOutgoing(20, ClientTabCompletePacket.class);
- this.registerOutgoing(21, ClientSettingsPacket.class);
- this.registerOutgoing(22, ClientRequestPacket.class);
- this.registerOutgoing(23, ClientPluginMessagePacket.class);
- this.registerOutgoing(24, ClientSpectatePacket.class);
- this.registerOutgoing(25, ClientResourcePackStatusPacket.class);
+ this.registerOutgoing(8, ClientPlayerUseItemPacket.class);
+ this.registerOutgoing(9, ClientPlayerPlaceBlockPacket.class);
+ this.registerOutgoing(10, ClientChangeHeldItemPacket.class);
+ this.registerOutgoing(11, ClientSwingArmPacket.class);
+ this.registerOutgoing(12, ClientPlayerStatePacket.class);
+ this.registerOutgoing(13, ClientSteerVehiclePacket.class);
+ this.registerOutgoing(14, ClientCloseWindowPacket.class);
+ this.registerOutgoing(15, ClientWindowActionPacket.class);
+ this.registerOutgoing(16, ClientConfirmTransactionPacket.class);
+ this.registerOutgoing(17, ClientCreativeInventoryActionPacket.class);
+ this.registerOutgoing(18, ClientEnchantItemPacket.class);
+ this.registerOutgoing(19, ClientUpdateSignPacket.class);
+ this.registerOutgoing(20, ClientPlayerAbilitiesPacket.class);
+ this.registerOutgoing(21, ClientTabCompletePacket.class);
+ this.registerOutgoing(22, ClientSettingsPacket.class);
+ this.registerOutgoing(23, ClientRequestPacket.class);
+ this.registerOutgoing(24, ClientPluginMessagePacket.class);
+ this.registerOutgoing(25, ClientSpectatePacket.class);
+ this.registerOutgoing(26, ClientResourcePackStatusPacket.class);
}
private void initServerGame(Session session) {
@@ -517,7 +519,7 @@ public class MinecraftProtocol extends PacketProtocol {
this.registerOutgoing(70, ServerSetCompressionPacket.class);
this.registerOutgoing(71, ServerPlayerListDataPacket.class);
this.registerOutgoing(72, ServerResourcePackSendPacket.class);
- this.registerOutgoing(73, ServerEntityNBTUpdatePacket.class);
+ this.registerOutgoing(73, ServerBossBarPacket.class);
}
private void initClientStatus(Session session) {
diff --git a/src/main/java/org/spacehq/mc/protocol/data/game/values/BossBarAction.java b/src/main/java/org/spacehq/mc/protocol/data/game/values/BossBarAction.java
new file mode 100644
index 00000000..f261b7f8
--- /dev/null
+++ b/src/main/java/org/spacehq/mc/protocol/data/game/values/BossBarAction.java
@@ -0,0 +1,10 @@
+package org.spacehq.mc.protocol.data.game.values;
+
+public enum BossBarAction {
+ ADD,
+ REMOVE,
+ UPDATE_HEALTH,
+ UPDATE_TITLE,
+ UPDATE_STYLE,
+ UPDATE_FLAGS;
+}
diff --git a/src/main/java/org/spacehq/mc/protocol/data/game/values/BossBarColor.java b/src/main/java/org/spacehq/mc/protocol/data/game/values/BossBarColor.java
new file mode 100644
index 00000000..a1cd7372
--- /dev/null
+++ b/src/main/java/org/spacehq/mc/protocol/data/game/values/BossBarColor.java
@@ -0,0 +1,11 @@
+package org.spacehq.mc.protocol.data.game.values;
+
+public enum BossBarColor {
+ PINK,
+ CYAN,
+ RED,
+ LIME,
+ YELLOW,
+ PURPLE,
+ WHITE;
+}
diff --git a/src/main/java/org/spacehq/mc/protocol/data/game/values/ClientRequest.java b/src/main/java/org/spacehq/mc/protocol/data/game/values/ClientRequest.java
index 3deab79f..51a5d396 100644
--- a/src/main/java/org/spacehq/mc/protocol/data/game/values/ClientRequest.java
+++ b/src/main/java/org/spacehq/mc/protocol/data/game/values/ClientRequest.java
@@ -1,9 +1,7 @@
package org.spacehq.mc.protocol.data.game.values;
public enum ClientRequest {
-
RESPAWN,
STATS,
- OPEN_INVENTORY_ACHIEVEMENT;
-
+ OPEN_INVENTORY;
}
diff --git a/src/main/java/org/spacehq/mc/protocol/data/game/values/Hand.java b/src/main/java/org/spacehq/mc/protocol/data/game/values/Hand.java
new file mode 100644
index 00000000..8efff300
--- /dev/null
+++ b/src/main/java/org/spacehq/mc/protocol/data/game/values/Hand.java
@@ -0,0 +1,6 @@
+package org.spacehq.mc.protocol.data.game.values;
+
+public enum Hand {
+ MAIN_HAND,
+ OFF_HAND;
+}
diff --git a/src/main/java/org/spacehq/mc/protocol/data/game/values/MagicValues.java b/src/main/java/org/spacehq/mc/protocol/data/game/values/MagicValues.java
index d483dc91..47a59cdd 100644
--- a/src/main/java/org/spacehq/mc/protocol/data/game/values/MagicValues.java
+++ b/src/main/java/org/spacehq/mc/protocol/data/game/values/MagicValues.java
@@ -109,7 +109,7 @@ public class MagicValues {
register(ClientRequest.RESPAWN, 0);
register(ClientRequest.STATS, 1);
- register(ClientRequest.OPEN_INVENTORY_ACHIEVEMENT, 2);
+ register(ClientRequest.OPEN_INVENTORY, 2);
register(ChatVisibility.FULL, 0);
register(ChatVisibility.SYSTEM, 1);
@@ -121,7 +121,6 @@ public class MagicValues {
register(PlayerState.START_SPRINTING, 3);
register(PlayerState.STOP_SPRINTING, 4);
register(PlayerState.RIDING_JUMP, 5);
- register(PlayerState.OPEN_INVENTORY, 6);
register(InteractAction.INTERACT, 0);
register(InteractAction.ATTACK, 1);
@@ -133,6 +132,7 @@ public class MagicValues {
register(PlayerAction.DROP_ITEM_STACK, 3);
register(PlayerAction.DROP_ITEM, 4);
register(PlayerAction.RELEASE_USE_ITEM, 5);
+ register(PlayerAction.SWAP_HANDS, 6);
register(Face.BOTTOM, 0);
register(Face.TOP, 1);
@@ -881,6 +881,24 @@ public class MagicValues {
register(ResourcePackStatus.DECLINED, 1);
register(ResourcePackStatus.FAILED_DOWNLOAD, 2);
register(ResourcePackStatus.ACCEPTED, 3);
+
+ register(Hand.MAIN_HAND, 0);
+ register(Hand.OFF_HAND, 1);
+
+ register(BossBarAction.ADD, 0);
+ register(BossBarAction.REMOVE, 1);
+ register(BossBarAction.UPDATE_HEALTH, 2);
+ register(BossBarAction.UPDATE_TITLE, 3);
+ register(BossBarAction.UPDATE_STYLE, 4);
+ register(BossBarAction.UPDATE_FLAGS, 5);
+
+ register(BossBarColor.PINK, 0);
+ register(BossBarColor.CYAN, 1);
+ register(BossBarColor.RED, 2);
+ register(BossBarColor.LIME, 3);
+ register(BossBarColor.YELLOW, 4);
+ register(BossBarColor.PURPLE, 5);
+ register(BossBarColor.WHITE, 6);
}
private static void register(Enum> key, Object value) {
diff --git a/src/main/java/org/spacehq/mc/protocol/data/game/values/entity/player/PlayerAction.java b/src/main/java/org/spacehq/mc/protocol/data/game/values/entity/player/PlayerAction.java
index ee87462f..ba4ec882 100644
--- a/src/main/java/org/spacehq/mc/protocol/data/game/values/entity/player/PlayerAction.java
+++ b/src/main/java/org/spacehq/mc/protocol/data/game/values/entity/player/PlayerAction.java
@@ -7,6 +7,7 @@ public enum PlayerAction {
FINISH_DIGGING,
DROP_ITEM_STACK,
DROP_ITEM,
- RELEASE_USE_ITEM;
+ RELEASE_USE_ITEM,
+ SWAP_HANDS;
}
diff --git a/src/main/java/org/spacehq/mc/protocol/data/game/values/entity/player/PlayerState.java b/src/main/java/org/spacehq/mc/protocol/data/game/values/entity/player/PlayerState.java
index 9aa16826..aa8c684f 100644
--- a/src/main/java/org/spacehq/mc/protocol/data/game/values/entity/player/PlayerState.java
+++ b/src/main/java/org/spacehq/mc/protocol/data/game/values/entity/player/PlayerState.java
@@ -1,13 +1,10 @@
package org.spacehq.mc.protocol.data.game.values.entity.player;
public enum PlayerState {
-
START_SNEAKING,
STOP_SNEAKING,
LEAVE_BED,
START_SPRINTING,
STOP_SPRINTING,
- RIDING_JUMP,
- OPEN_INVENTORY;
-
+ RIDING_JUMP;
}
diff --git a/src/main/java/org/spacehq/mc/protocol/packet/ingame/client/ClientSettingsPacket.java b/src/main/java/org/spacehq/mc/protocol/packet/ingame/client/ClientSettingsPacket.java
index 5d1c5e25..a081bb24 100644
--- a/src/main/java/org/spacehq/mc/protocol/packet/ingame/client/ClientSettingsPacket.java
+++ b/src/main/java/org/spacehq/mc/protocol/packet/ingame/client/ClientSettingsPacket.java
@@ -1,5 +1,6 @@
package org.spacehq.mc.protocol.packet.ingame.client;
+import org.spacehq.mc.protocol.data.game.values.Hand;
import org.spacehq.mc.protocol.data.game.values.MagicValues;
import org.spacehq.mc.protocol.data.game.values.setting.ChatVisibility;
import org.spacehq.mc.protocol.data.game.values.setting.SkinPart;
@@ -19,17 +20,19 @@ public class ClientSettingsPacket implements Packet {
private ChatVisibility chatVisibility;
private boolean chatColors;
private List visibleParts;
+ private Hand mainHand;
@SuppressWarnings("unused")
private ClientSettingsPacket() {
}
- public ClientSettingsPacket(String locale, int renderDistance, ChatVisibility chatVisibility, boolean chatColors, SkinPart... visibleParts) {
+ public ClientSettingsPacket(String locale, int renderDistance, ChatVisibility chatVisibility, boolean chatColors, SkinPart[] visibleParts, Hand mainHand) {
this.locale = locale;
this.renderDistance = renderDistance;
this.chatVisibility = chatVisibility;
this.chatColors = chatColors;
this.visibleParts = Arrays.asList(visibleParts);
+ this.mainHand = mainHand;
}
public String getLocale() {
@@ -52,13 +55,18 @@ public class ClientSettingsPacket implements Packet {
return this.visibleParts;
}
+ public Hand getMainHand() {
+ return this.mainHand;
+ }
+
@Override
public void read(NetInput in) throws IOException {
this.locale = in.readString();
this.renderDistance = in.readByte();
- this.chatVisibility = MagicValues.key(ChatVisibility.class, in.readByte());
+ this.chatVisibility = MagicValues.key(ChatVisibility.class, in.readVarInt());
this.chatColors = in.readBoolean();
this.visibleParts = new ArrayList();
+
int flags = in.readUnsignedByte();
for(SkinPart part : SkinPart.values()) {
int bit = 1 << part.ordinal();
@@ -66,20 +74,25 @@ public class ClientSettingsPacket implements Packet {
this.visibleParts.add(part);
}
}
+
+ this.mainHand = MagicValues.key(Hand.class, in.readVarInt());
}
@Override
public void write(NetOutput out) throws IOException {
out.writeString(this.locale);
out.writeByte(this.renderDistance);
- out.writeByte(MagicValues.value(Integer.class, this.chatVisibility));
+ out.writeVarInt(MagicValues.value(Integer.class, this.chatVisibility));
out.writeBoolean(this.chatColors);
+
int flags = 0;
for(SkinPart part : this.visibleParts) {
flags |= 1 << part.ordinal();
}
out.writeByte(flags);
+
+ out.writeVarInt(MagicValues.value(Integer.class, this.mainHand));
}
@Override
diff --git a/src/main/java/org/spacehq/mc/protocol/packet/ingame/client/player/ClientPlayerInteractEntityPacket.java b/src/main/java/org/spacehq/mc/protocol/packet/ingame/client/player/ClientPlayerInteractEntityPacket.java
index ab81a716..f8eba14a 100644
--- a/src/main/java/org/spacehq/mc/protocol/packet/ingame/client/player/ClientPlayerInteractEntityPacket.java
+++ b/src/main/java/org/spacehq/mc/protocol/packet/ingame/client/player/ClientPlayerInteractEntityPacket.java
@@ -1,5 +1,6 @@
package org.spacehq.mc.protocol.packet.ingame.client.player;
+import org.spacehq.mc.protocol.data.game.values.Hand;
import org.spacehq.mc.protocol.data.game.values.MagicValues;
import org.spacehq.mc.protocol.data.game.values.entity.player.InteractAction;
import org.spacehq.packetlib.io.NetInput;
@@ -16,21 +17,27 @@ public class ClientPlayerInteractEntityPacket implements Packet {
private float targetX;
private float targetY;
private float targetZ;
+ private Hand hand;
@SuppressWarnings("unused")
private ClientPlayerInteractEntityPacket() {
}
public ClientPlayerInteractEntityPacket(int entityId, InteractAction action) {
- this(entityId, action, 0, 0, 0);
+ this(entityId, action, Hand.MAIN_HAND);
}
- public ClientPlayerInteractEntityPacket(int entityId, InteractAction action, float targetX, float targetY, float targetZ) {
+ public ClientPlayerInteractEntityPacket(int entityId, InteractAction action, Hand hand) {
+ this(entityId, action, 0, 0, 0, hand);
+ }
+
+ public ClientPlayerInteractEntityPacket(int entityId, InteractAction action, float targetX, float targetY, float targetZ, Hand hand) {
this.entityId = entityId;
this.action = action;
this.targetX = targetX;
this.targetY = targetY;
this.targetZ = targetZ;
+ this.hand = hand;
}
public int getEntityId() {
@@ -41,6 +48,22 @@ public class ClientPlayerInteractEntityPacket implements Packet {
return this.action;
}
+ public float getTargetX() {
+ return this.targetX;
+ }
+
+ public float getTargetY() {
+ return this.targetY;
+ }
+
+ public float getTargetZ() {
+ return this.targetZ;
+ }
+
+ public Hand getHand() {
+ return this.hand;
+ }
+
@Override
public void read(NetInput in) throws IOException {
this.entityId = in.readVarInt();
@@ -50,6 +73,10 @@ public class ClientPlayerInteractEntityPacket implements Packet {
this.targetY = in.readFloat();
this.targetZ = in.readFloat();
}
+
+ if(this.action == InteractAction.INTERACT || this.action == InteractAction.INTERACT_AT) {
+ this.hand = MagicValues.key(Hand.class, in.readVarInt());
+ }
}
@Override
@@ -61,6 +88,10 @@ public class ClientPlayerInteractEntityPacket implements Packet {
out.writeFloat(this.targetY);
out.writeFloat(this.targetZ);
}
+
+ if(this.action == InteractAction.INTERACT || this.action == InteractAction.INTERACT_AT) {
+ out.writeVarInt(MagicValues.value(Integer.class, this.hand));
+ }
}
@Override
diff --git a/src/main/java/org/spacehq/mc/protocol/packet/ingame/client/player/ClientPlayerPlaceBlockPacket.java b/src/main/java/org/spacehq/mc/protocol/packet/ingame/client/player/ClientPlayerPlaceBlockPacket.java
index 119d4588..5d5629ed 100644
--- a/src/main/java/org/spacehq/mc/protocol/packet/ingame/client/player/ClientPlayerPlaceBlockPacket.java
+++ b/src/main/java/org/spacehq/mc/protocol/packet/ingame/client/player/ClientPlayerPlaceBlockPacket.java
@@ -1,8 +1,8 @@
package org.spacehq.mc.protocol.packet.ingame.client.player;
-import org.spacehq.mc.protocol.data.game.ItemStack;
import org.spacehq.mc.protocol.data.game.Position;
import org.spacehq.mc.protocol.data.game.values.Face;
+import org.spacehq.mc.protocol.data.game.values.Hand;
import org.spacehq.mc.protocol.data.game.values.MagicValues;
import org.spacehq.mc.protocol.util.NetUtil;
import org.spacehq.packetlib.io.NetInput;
@@ -15,7 +15,7 @@ public class ClientPlayerPlaceBlockPacket implements Packet {
private Position position;
private Face face;
- private ItemStack held;
+ private Hand hand;
private float cursorX;
private float cursorY;
private float cursorZ;
@@ -24,10 +24,10 @@ public class ClientPlayerPlaceBlockPacket implements Packet {
private ClientPlayerPlaceBlockPacket() {
}
- public ClientPlayerPlaceBlockPacket(Position position, Face face, ItemStack held, float cursorX, float cursorY, float cursorZ) {
+ public ClientPlayerPlaceBlockPacket(Position position, Face face, Hand hand, float cursorX, float cursorY, float cursorZ) {
this.position = position;
this.face = face;
- this.held = held;
+ this.hand = hand;
this.cursorX = cursorX;
this.cursorY = cursorY;
this.cursorZ = cursorZ;
@@ -41,8 +41,8 @@ public class ClientPlayerPlaceBlockPacket implements Packet {
return this.face;
}
- public ItemStack getHeldItem() {
- return this.held;
+ public Hand getHand() {
+ return this.hand;
}
public float getCursorX() {
@@ -61,7 +61,7 @@ public class ClientPlayerPlaceBlockPacket implements Packet {
public void read(NetInput in) throws IOException {
this.position = NetUtil.readPosition(in);
this.face = MagicValues.key(Face.class, in.readUnsignedByte());
- this.held = NetUtil.readItem(in);
+ this.hand = MagicValues.key(Hand.class, in.readVarInt());
this.cursorX = in.readByte() / 16f;
this.cursorY = in.readByte() / 16f;
this.cursorZ = in.readByte() / 16f;
@@ -71,7 +71,7 @@ public class ClientPlayerPlaceBlockPacket implements Packet {
public void write(NetOutput out) throws IOException {
NetUtil.writePosition(out, this.position);
out.writeByte(MagicValues.value(Integer.class, this.face));
- NetUtil.writeItem(out, this.held);
+ out.writeVarInt(MagicValues.value(Integer.class, this.hand));
out.writeByte((int) (this.cursorX * 16));
out.writeByte((int) (this.cursorY * 16));
out.writeByte((int) (this.cursorZ * 16));
diff --git a/src/main/java/org/spacehq/mc/protocol/packet/ingame/client/player/ClientPlayerUseItemPacket.java b/src/main/java/org/spacehq/mc/protocol/packet/ingame/client/player/ClientPlayerUseItemPacket.java
new file mode 100644
index 00000000..384b8371
--- /dev/null
+++ b/src/main/java/org/spacehq/mc/protocol/packet/ingame/client/player/ClientPlayerUseItemPacket.java
@@ -0,0 +1,40 @@
+package org.spacehq.mc.protocol.packet.ingame.client.player;
+
+import org.spacehq.mc.protocol.data.game.values.Hand;
+import org.spacehq.mc.protocol.data.game.values.MagicValues;
+import org.spacehq.packetlib.io.NetInput;
+import org.spacehq.packetlib.io.NetOutput;
+import org.spacehq.packetlib.packet.Packet;
+
+import java.io.IOException;
+
+public class ClientPlayerUseItemPacket implements Packet {
+ private Hand hand;
+
+ @SuppressWarnings("unused")
+ private ClientPlayerUseItemPacket() {
+ }
+
+ public ClientPlayerUseItemPacket(Hand hand) {
+ this.hand = hand;
+ }
+
+ public Hand getHand() {
+ return this.hand;
+ }
+
+ @Override
+ public void read(NetInput in) throws IOException {
+ this.hand = MagicValues.key(Hand.class, in.readVarInt());
+ }
+
+ @Override
+ public void write(NetOutput out) throws IOException {
+ out.writeVarInt(MagicValues.value(Integer.class, this.hand));
+ }
+
+ @Override
+ public boolean isPriority() {
+ return false;
+ }
+}
diff --git a/src/main/java/org/spacehq/mc/protocol/packet/ingame/client/player/ClientSwingArmPacket.java b/src/main/java/org/spacehq/mc/protocol/packet/ingame/client/player/ClientSwingArmPacket.java
index 319e01f8..3b981184 100644
--- a/src/main/java/org/spacehq/mc/protocol/packet/ingame/client/player/ClientSwingArmPacket.java
+++ b/src/main/java/org/spacehq/mc/protocol/packet/ingame/client/player/ClientSwingArmPacket.java
@@ -1,5 +1,7 @@
package org.spacehq.mc.protocol.packet.ingame.client.player;
+import org.spacehq.mc.protocol.data.game.values.Hand;
+import org.spacehq.mc.protocol.data.game.values.MagicValues;
import org.spacehq.packetlib.io.NetInput;
import org.spacehq.packetlib.io.NetOutput;
import org.spacehq.packetlib.packet.Packet;
@@ -7,21 +9,32 @@ import org.spacehq.packetlib.packet.Packet;
import java.io.IOException;
public class ClientSwingArmPacket implements Packet {
+ private Hand hand;
- public ClientSwingArmPacket() {
+ @SuppressWarnings("unused")
+ private ClientSwingArmPacket() {
+ }
+
+ public ClientSwingArmPacket(Hand hand) {
+ this.hand = hand;
+ }
+
+ public Hand getHand() {
+ return this.hand;
}
@Override
public void read(NetInput in) throws IOException {
+ this.hand = MagicValues.key(Hand.class, in.readVarInt());
}
@Override
public void write(NetOutput out) throws IOException {
+ out.writeVarInt(MagicValues.value(Integer.class, this.hand));
}
@Override
public boolean isPriority() {
return false;
}
-
}
diff --git a/src/main/java/org/spacehq/mc/protocol/packet/ingame/server/ServerBossBarPacket.java b/src/main/java/org/spacehq/mc/protocol/packet/ingame/server/ServerBossBarPacket.java
new file mode 100644
index 00000000..5397ccbf
--- /dev/null
+++ b/src/main/java/org/spacehq/mc/protocol/packet/ingame/server/ServerBossBarPacket.java
@@ -0,0 +1,151 @@
+package org.spacehq.mc.protocol.packet.ingame.server;
+
+import org.spacehq.mc.protocol.data.game.values.BossBarAction;
+import org.spacehq.mc.protocol.data.game.values.BossBarColor;
+import org.spacehq.mc.protocol.data.game.values.MagicValues;
+import org.spacehq.mc.protocol.data.message.Message;
+import org.spacehq.packetlib.io.NetInput;
+import org.spacehq.packetlib.io.NetOutput;
+import org.spacehq.packetlib.packet.Packet;
+
+import java.io.IOException;
+import java.util.UUID;
+
+public class ServerBossBarPacket implements Packet {
+ private UUID uuid;
+ private BossBarAction action;
+
+ private Message title;
+ private float health;
+ private BossBarColor color;
+ private int dividers;
+ private int flags;
+
+ @SuppressWarnings("unused")
+ private ServerBossBarPacket() {
+ }
+
+ public ServerBossBarPacket(UUID uuid, BossBarAction action, Message title, float health, BossBarColor color, int dividers, int flags) {
+ this.uuid = uuid;
+ this.action = BossBarAction.ADD;
+
+ this.title = title;
+ this.health = health;
+ this.color = color;
+ this.dividers = dividers;
+ this.flags = flags;
+ }
+
+ public ServerBossBarPacket(UUID uuid) {
+ this.uuid = uuid;
+ this.action = BossBarAction.REMOVE;
+ }
+
+ public ServerBossBarPacket(UUID uuid, BossBarAction action, float health) {
+ this.uuid = uuid;
+ this.action = BossBarAction.UPDATE_HEALTH;
+
+ this.health = health;
+ }
+
+ public ServerBossBarPacket(UUID uuid, BossBarAction action, Message title) {
+ this.uuid = uuid;
+ this.action = BossBarAction.UPDATE_TITLE;
+
+ this.title = title;
+ }
+
+ public ServerBossBarPacket(UUID uuid, BossBarAction action, BossBarColor color, int dividers) {
+ this.uuid = uuid;
+ this.action = BossBarAction.UPDATE_STYLE;
+
+ this.color = color;
+ this.dividers = dividers;
+ }
+
+ public ServerBossBarPacket(UUID uuid, BossBarAction action, int flags) {
+ this.uuid = uuid;
+ this.action = BossBarAction.UPDATE_FLAGS;
+
+ this.flags = flags;
+ }
+
+ public UUID getUUID() {
+ return this.uuid;
+ }
+
+ public BossBarAction getAction() {
+ return this.action;
+ }
+
+ public Message getTitle() {
+ return this.title;
+ }
+
+ public float getHealth() {
+ return this.health;
+ }
+
+ public BossBarColor getColor() {
+ return this.color;
+ }
+
+ public int getDividers() {
+ return this.dividers;
+ }
+
+ public int getFlags() {
+ return this.flags;
+ }
+
+ @Override
+ public void read(NetInput in) throws IOException {
+ this.uuid = in.readUUID();
+ this.action = MagicValues.key(BossBarAction.class, in.readVarInt());
+
+ if(this.action == BossBarAction.ADD || this.action == BossBarAction.UPDATE_TITLE) {
+ this.title = Message.fromString(in.readString());
+ }
+
+ if(this.action == BossBarAction.ADD || this.action == BossBarAction.UPDATE_HEALTH) {
+ this.health = in.readFloat();
+ }
+
+ if(this.action == BossBarAction.ADD || this.action == BossBarAction.UPDATE_STYLE) {
+ this.color = MagicValues.key(BossBarColor.class, in.readVarInt());
+ this.dividers = in.readVarInt();
+ }
+
+ if(this.action == BossBarAction.ADD || this.action == BossBarAction.UPDATE_FLAGS) {
+ this.flags = in.readUnsignedByte();
+ }
+ }
+
+ @Override
+ public void write(NetOutput out) throws IOException {
+ out.writeUUID(this.uuid);
+ out.writeVarInt(MagicValues.value(Integer.class, this.action));
+
+ if(this.action == BossBarAction.ADD || this.action == BossBarAction.UPDATE_TITLE) {
+ out.writeString(this.title.toJsonString());
+ }
+
+ if(this.action == BossBarAction.ADD || this.action == BossBarAction.UPDATE_HEALTH) {
+ out.writeFloat(this.health);
+ }
+
+ if(this.action == BossBarAction.ADD || this.action == BossBarAction.UPDATE_STYLE) {
+ out.writeVarInt(MagicValues.value(Integer.class, this.color));
+ out.writeVarInt(this.dividers);
+ }
+
+ if(this.action == BossBarAction.ADD || this.action == BossBarAction.UPDATE_FLAGS) {
+ out.writeByte(this.flags);
+ }
+ }
+
+ @Override
+ public boolean isPriority() {
+ return false;
+ }
+}
diff --git a/src/main/java/org/spacehq/mc/protocol/packet/ingame/server/ServerCombatPacket.java b/src/main/java/org/spacehq/mc/protocol/packet/ingame/server/ServerCombatPacket.java
index 1d6198ad..61a838a9 100644
--- a/src/main/java/org/spacehq/mc/protocol/packet/ingame/server/ServerCombatPacket.java
+++ b/src/main/java/org/spacehq/mc/protocol/packet/ingame/server/ServerCombatPacket.java
@@ -2,6 +2,7 @@ package org.spacehq.mc.protocol.packet.ingame.server;
import org.spacehq.mc.protocol.data.game.values.MagicValues;
import org.spacehq.mc.protocol.data.game.values.entity.player.CombatState;
+import org.spacehq.mc.protocol.data.message.Message;
import org.spacehq.packetlib.io.NetInput;
import org.spacehq.packetlib.io.NetOutput;
import org.spacehq.packetlib.packet.Packet;
@@ -14,7 +15,7 @@ public class ServerCombatPacket implements Packet {
private int entityId;
private int duration;
private int playerId;
- private String message;
+ private Message message;
public ServerCombatPacket() {
this.state = CombatState.ENTER_COMBAT;
@@ -26,7 +27,7 @@ public class ServerCombatPacket implements Packet {
this.duration = duration;
}
- public ServerCombatPacket(int entityId, int playerId, String message) {
+ public ServerCombatPacket(int entityId, int playerId, Message message) {
this.state = CombatState.ENTITY_DEAD;
this.entityId = entityId;
this.playerId = playerId;
@@ -49,7 +50,7 @@ public class ServerCombatPacket implements Packet {
return this.playerId;
}
- public String getMessage() {
+ public Message getMessage() {
return this.message;
}
@@ -62,7 +63,7 @@ public class ServerCombatPacket implements Packet {
} else if(this.state == CombatState.ENTITY_DEAD) {
this.playerId = in.readVarInt();
this.entityId = in.readInt();
- this.message = in.readString();
+ this.message = Message.fromString(in.readString());
}
}
@@ -75,7 +76,7 @@ public class ServerCombatPacket implements Packet {
} else if(this.state == CombatState.ENTITY_DEAD) {
out.writeVarInt(this.playerId);
out.writeInt(this.entityId);
- out.writeString(this.message);
+ out.writeString(this.message.toJsonString());
}
}
diff --git a/src/main/java/org/spacehq/mc/protocol/packet/ingame/server/entity/ServerEntityEquipmentPacket.java b/src/main/java/org/spacehq/mc/protocol/packet/ingame/server/entity/ServerEntityEquipmentPacket.java
index d1e45dab..73e9ad59 100644
--- a/src/main/java/org/spacehq/mc/protocol/packet/ingame/server/entity/ServerEntityEquipmentPacket.java
+++ b/src/main/java/org/spacehq/mc/protocol/packet/ingame/server/entity/ServerEntityEquipmentPacket.java
@@ -39,14 +39,14 @@ public class ServerEntityEquipmentPacket implements Packet {
@Override
public void read(NetInput in) throws IOException {
this.entityId = in.readVarInt();
- this.slot = in.readShort();
+ this.slot = in.readVarInt();
this.item = NetUtil.readItem(in);
}
@Override
public void write(NetOutput out) throws IOException {
out.writeVarInt(this.entityId);
- out.writeShort(this.slot);
+ out.writeVarInt(this.slot);
NetUtil.writeItem(out, this.item);
}
diff --git a/src/main/java/org/spacehq/mc/protocol/packet/ingame/server/entity/ServerEntityNBTUpdatePacket.java b/src/main/java/org/spacehq/mc/protocol/packet/ingame/server/entity/ServerEntityNBTUpdatePacket.java
deleted file mode 100644
index 3b2dd56d..00000000
--- a/src/main/java/org/spacehq/mc/protocol/packet/ingame/server/entity/ServerEntityNBTUpdatePacket.java
+++ /dev/null
@@ -1,48 +0,0 @@
-package org.spacehq.mc.protocol.packet.ingame.server.entity;
-
-import org.spacehq.mc.protocol.util.NetUtil;
-import org.spacehq.opennbt.tag.builtin.CompoundTag;
-import org.spacehq.packetlib.io.NetInput;
-import org.spacehq.packetlib.io.NetOutput;
-import org.spacehq.packetlib.packet.Packet;
-
-import java.io.IOException;
-
-public class ServerEntityNBTUpdatePacket implements Packet {
- private int entityId;
- private CompoundTag tag;
-
- @SuppressWarnings("unused")
- private ServerEntityNBTUpdatePacket() {
- }
-
- public ServerEntityNBTUpdatePacket(int entityId, CompoundTag tag) {
- this.entityId = entityId;
- this.tag = tag;
- }
-
- public int getEntityId() {
- return this.entityId;
- }
-
- public CompoundTag getTag() {
- return this.tag;
- }
-
- @Override
- public void read(NetInput in) throws IOException {
- this.entityId = in.readVarInt();
- this.tag = NetUtil.readNBT(in);
- }
-
- @Override
- public void write(NetOutput out) throws IOException {
- out.writeVarInt(this.entityId);
- NetUtil.writeNBT(out, this.tag);
- }
-
- @Override
- public boolean isPriority() {
- return false;
- }
-}
diff --git a/src/main/java/org/spacehq/mc/protocol/packet/ingame/server/entity/spawn/ServerSpawnMobPacket.java b/src/main/java/org/spacehq/mc/protocol/packet/ingame/server/entity/spawn/ServerSpawnMobPacket.java
index 8ca80f2e..ad267af6 100644
--- a/src/main/java/org/spacehq/mc/protocol/packet/ingame/server/entity/spawn/ServerSpawnMobPacket.java
+++ b/src/main/java/org/spacehq/mc/protocol/packet/ingame/server/entity/spawn/ServerSpawnMobPacket.java
@@ -9,10 +9,12 @@ import org.spacehq.packetlib.io.NetOutput;
import org.spacehq.packetlib.packet.Packet;
import java.io.IOException;
+import java.util.UUID;
public class ServerSpawnMobPacket implements Packet {
private int entityId;
+ private UUID uuid;
private MobType type;
private double x;
private double y;
@@ -29,8 +31,9 @@ public class ServerSpawnMobPacket implements Packet {
private ServerSpawnMobPacket() {
}
- public ServerSpawnMobPacket(int entityId, MobType type, double x, double y, double z, float yaw, float pitch, float headYaw, double motX, double motY, double motZ, EntityMetadata metadata[]) {
+ public ServerSpawnMobPacket(int entityId, UUID uuid, MobType type, double x, double y, double z, float yaw, float pitch, float headYaw, double motX, double motY, double motZ, EntityMetadata metadata[]) {
this.entityId = entityId;
+ this.uuid = uuid;
this.type = type;
this.x = x;
this.y = y;
@@ -48,6 +51,10 @@ public class ServerSpawnMobPacket implements Packet {
return this.entityId;
}
+ public UUID getUUID() {
+ return this.uuid;
+ }
+
public MobType getType() {
return this.type;
}
@@ -95,6 +102,7 @@ public class ServerSpawnMobPacket implements Packet {
@Override
public void read(NetInput in) throws IOException {
this.entityId = in.readVarInt();
+ this.uuid = in.readUUID();
this.type = MagicValues.key(MobType.class, in.readByte());
this.x = in.readInt() / 32D;
this.y = in.readInt() / 32D;
@@ -111,6 +119,7 @@ public class ServerSpawnMobPacket implements Packet {
@Override
public void write(NetOutput out) throws IOException {
out.writeVarInt(this.entityId);
+ out.writeUUID(this.uuid);
out.writeByte(MagicValues.value(Integer.class, this.type));
out.writeInt((int) (this.x * 32));
out.writeInt((int) (this.y * 32));
diff --git a/src/main/java/org/spacehq/mc/protocol/packet/ingame/server/entity/spawn/ServerSpawnObjectPacket.java b/src/main/java/org/spacehq/mc/protocol/packet/ingame/server/entity/spawn/ServerSpawnObjectPacket.java
index 75ab443d..dd1a06f0 100644
--- a/src/main/java/org/spacehq/mc/protocol/packet/ingame/server/entity/spawn/ServerSpawnObjectPacket.java
+++ b/src/main/java/org/spacehq/mc/protocol/packet/ingame/server/entity/spawn/ServerSpawnObjectPacket.java
@@ -13,10 +13,12 @@ import org.spacehq.packetlib.io.NetOutput;
import org.spacehq.packetlib.packet.Packet;
import java.io.IOException;
+import java.util.UUID;
public class ServerSpawnObjectPacket implements Packet {
private int entityId;
+ private UUID uuid;
private ObjectType type;
private double x;
private double y;
@@ -32,21 +34,21 @@ public class ServerSpawnObjectPacket implements Packet {
private ServerSpawnObjectPacket() {
}
- public ServerSpawnObjectPacket(int entityId, ObjectType type, double x, double y, double z, float yaw, float pitch) {
- this(entityId, type, null, x, y, z, yaw, pitch, 0, 0, 0);
+ public ServerSpawnObjectPacket(int entityId, UUID uuid, ObjectType type, double x, double y, double z, float yaw, float pitch) {
+ this(entityId, uuid, type, null, x, y, z, yaw, pitch, 0, 0, 0);
}
- public ServerSpawnObjectPacket(int entityId, ObjectType type, ObjectData data, double x, double y, double z, float yaw, float pitch) {
- this(entityId, type, data, x, y, z, yaw, pitch, 0, 0, 0);
+ public ServerSpawnObjectPacket(int entityId, UUID uuid, ObjectType type, ObjectData data, double x, double y, double z, float yaw, float pitch) {
+ this(entityId, uuid, type, data, x, y, z, yaw, pitch, 0, 0, 0);
}
- public ServerSpawnObjectPacket(int entityId, ObjectType type, double x, double y, double z, float yaw, float pitch, double motX, double motY, double motZ) {
- this(entityId, type, new ObjectData() {
- }, x, y, z, yaw, pitch, motX, motY, motZ);
+ public ServerSpawnObjectPacket(int entityId, UUID uuid, ObjectType type, double x, double y, double z, float yaw, float pitch, double motX, double motY, double motZ) {
+ this(entityId, uuid, type, new ObjectData() {}, x, y, z, yaw, pitch, motX, motY, motZ);
}
- public ServerSpawnObjectPacket(int entityId, ObjectType type, ObjectData data, double x, double y, double z, float yaw, float pitch, double motX, double motY, double motZ) {
+ public ServerSpawnObjectPacket(int entityId, UUID uuid, ObjectType type, ObjectData data, double x, double y, double z, float yaw, float pitch, double motX, double motY, double motZ) {
this.entityId = entityId;
+ this.uuid = uuid;
this.type = type;
this.data = data;
this.x = x;
@@ -63,6 +65,10 @@ public class ServerSpawnObjectPacket implements Packet {
return this.entityId;
}
+ public UUID getUUID() {
+ return this.uuid;
+ }
+
public ObjectType getType() {
return this.type;
}
@@ -106,12 +112,14 @@ public class ServerSpawnObjectPacket implements Packet {
@Override
public void read(NetInput in) throws IOException {
this.entityId = in.readVarInt();
+ this.uuid = in.readUUID();
this.type = MagicValues.key(ObjectType.class, in.readByte());
this.x = in.readInt() / 32D;
this.y = in.readInt() / 32D;
this.z = in.readInt() / 32D;
this.pitch = in.readByte() * 360 / 256f;
this.yaw = in.readByte() * 360 / 256f;
+
int data = in.readInt();
if(data > 0) {
if(this.type == ObjectType.MINECART) {
@@ -128,22 +136,24 @@ public class ServerSpawnObjectPacket implements Packet {
this.data = new ObjectData() {
};
}
-
- this.motX = in.readShort() / 8000D;
- this.motY = in.readShort() / 8000D;
- this.motZ = in.readShort() / 8000D;
}
+
+ this.motX = in.readShort() / 8000D;
+ this.motY = in.readShort() / 8000D;
+ this.motZ = in.readShort() / 8000D;
}
@Override
public void write(NetOutput out) throws IOException {
out.writeVarInt(this.entityId);
+ out.writeUUID(this.uuid);
out.writeByte(MagicValues.value(Integer.class, this.type));
out.writeInt((int) (this.x * 32));
out.writeInt((int) (this.y * 32));
out.writeInt((int) (this.z * 32));
out.writeByte((byte) (this.pitch * 256 / 360));
out.writeByte((byte) (this.yaw * 256 / 360));
+
int data = 0;
if(this.data != null) {
if(this.data instanceof MinecartType) {
@@ -162,11 +172,10 @@ public class ServerSpawnObjectPacket implements Packet {
}
out.writeInt(data);
- if(data > 0) {
- out.writeShort((int) (this.motX * 8000));
- out.writeShort((int) (this.motY * 8000));
- out.writeShort((int) (this.motZ * 8000));
- }
+
+ out.writeShort((int) (this.motX * 8000));
+ out.writeShort((int) (this.motY * 8000));
+ out.writeShort((int) (this.motZ * 8000));
}
@Override
diff --git a/src/main/java/org/spacehq/mc/protocol/packet/ingame/server/entity/spawn/ServerSpawnPlayerPacket.java b/src/main/java/org/spacehq/mc/protocol/packet/ingame/server/entity/spawn/ServerSpawnPlayerPacket.java
index cfda9a48..2f514fa4 100644
--- a/src/main/java/org/spacehq/mc/protocol/packet/ingame/server/entity/spawn/ServerSpawnPlayerPacket.java
+++ b/src/main/java/org/spacehq/mc/protocol/packet/ingame/server/entity/spawn/ServerSpawnPlayerPacket.java
@@ -18,14 +18,13 @@ public class ServerSpawnPlayerPacket implements Packet {
private double z;
private float yaw;
private float pitch;
- private int currentItem;
private EntityMetadata metadata[];
@SuppressWarnings("unused")
private ServerSpawnPlayerPacket() {
}
- public ServerSpawnPlayerPacket(int entityId, UUID uuid, double x, double y, double z, float yaw, float pitch, int currentItem, EntityMetadata metadata[]) {
+ public ServerSpawnPlayerPacket(int entityId, UUID uuid, double x, double y, double z, float yaw, float pitch, EntityMetadata metadata[]) {
this.entityId = entityId;
this.uuid = uuid;
this.x = x;
@@ -33,7 +32,6 @@ public class ServerSpawnPlayerPacket implements Packet {
this.z = z;
this.yaw = yaw;
this.pitch = pitch;
- this.currentItem = currentItem;
this.metadata = metadata;
}
@@ -65,10 +63,6 @@ public class ServerSpawnPlayerPacket implements Packet {
return this.pitch;
}
- public int getCurrentItem() {
- return this.currentItem;
- }
-
public EntityMetadata[] getMetadata() {
return this.metadata;
}
@@ -82,7 +76,6 @@ public class ServerSpawnPlayerPacket implements Packet {
this.z = in.readInt() / 32D;
this.yaw = in.readByte() * 360 / 256f;
this.pitch = in.readByte() * 360 / 256f;
- this.currentItem = in.readShort();
this.metadata = NetUtil.readEntityMetadata(in);
}
@@ -95,7 +88,6 @@ public class ServerSpawnPlayerPacket implements Packet {
out.writeInt((int) (this.z * 32));
out.writeByte((byte) (this.yaw * 256 / 360));
out.writeByte((byte) (this.pitch * 256 / 360));
- out.writeShort(this.currentItem);
NetUtil.writeEntityMetadata(out, this.metadata);
}