Update to MC 1.12

This commit is contained in:
Jonas Herzig 2017-06-09 13:22:03 +02:00
parent f0424a2979
commit f1afab396e
22 changed files with 1109 additions and 131 deletions

View file

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.steveice10</groupId>
<artifactId>mcprotocollib</artifactId>
<version>1.11.2-3-SNAPSHOT</version>
<version>1.12-SNAPSHOT</version>
<packaging>jar</packaging>
<name>MCProtocolLib</name>

View file

@ -2,8 +2,8 @@ package com.github.steveice10.mc.protocol;
public class MinecraftConstants {
// General Constants
public static final String GAME_VERSION = "1.11.2";
public static final int PROTOCOL_VERSION = 316;
public static final String GAME_VERSION = "1.12";
public static final int PROTOCOL_VERSION = 335;
// General Key Constants
public static final String PROFILE_KEY = "profile";

View file

@ -19,10 +19,13 @@ import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlaye
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerStatePacket;
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerSwingArmPacket;
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerUseItemPacket;
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientAdvancementTabPacket;
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientCloseWindowPacket;
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientConfirmTransactionPacket;
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientCraftingBookDataPacket;
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientCreativeInventoryActionPacket;
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientEnchantItemPacket;
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientPrepareCraftingGridPacket;
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientWindowActionPacket;
import com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientSpectatePacket;
import com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientSteerBoatPacket;
@ -30,6 +33,8 @@ import com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientSteerV
import com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientTeleportConfirmPacket;
import com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientUpdateSignPacket;
import com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientVehicleMovePacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerAdvancementProgressPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerAdvancementsPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerBossBarPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerChatPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerCombatPacket;
@ -47,6 +52,7 @@ import com.github.steveice10.mc.protocol.packet.ingame.server.ServerStatisticsPa
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerSwitchCameraPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerTabCompletePacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerTitlePacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerUnlockRecipesPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityAnimationPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityAttachPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityCollectItemPacket;
@ -351,10 +357,10 @@ public class MinecraftProtocol extends PacketProtocol {
this.registerIncoming(0x22, ServerSpawnParticlePacket.class);
this.registerIncoming(0x23, ServerJoinGamePacket.class);
this.registerIncoming(0x24, ServerMapDataPacket.class);
this.registerIncoming(0x25, ServerEntityPositionPacket.class);
this.registerIncoming(0x26, ServerEntityPositionRotationPacket.class);
this.registerIncoming(0x27, ServerEntityRotationPacket.class);
this.registerIncoming(0x28, ServerEntityMovementPacket.class);
this.registerIncoming(0x25, ServerEntityMovementPacket.class);
this.registerIncoming(0x26, ServerEntityPositionPacket.class);
this.registerIncoming(0x27, ServerEntityPositionRotationPacket.class);
this.registerIncoming(0x28, ServerEntityRotationPacket.class);
this.registerIncoming(0x29, ServerVehicleMovePacket.class);
this.registerIncoming(0x2A, ServerOpenTileEntityEditorPacket.class);
this.registerIncoming(0x2B, ServerPlayerAbilitiesPacket.class);
@ -362,98 +368,107 @@ public class MinecraftProtocol extends PacketProtocol {
this.registerIncoming(0x2D, ServerPlayerListEntryPacket.class);
this.registerIncoming(0x2E, ServerPlayerPositionRotationPacket.class);
this.registerIncoming(0x2F, ServerPlayerUseBedPacket.class);
this.registerIncoming(0x30, ServerEntityDestroyPacket.class);
this.registerIncoming(0x31, ServerEntityRemoveEffectPacket.class);
this.registerIncoming(0x32, ServerResourcePackSendPacket.class);
this.registerIncoming(0x33, ServerRespawnPacket.class);
this.registerIncoming(0x34, ServerEntityHeadLookPacket.class);
this.registerIncoming(0x35, ServerWorldBorderPacket.class);
this.registerIncoming(0x36, ServerSwitchCameraPacket.class);
this.registerIncoming(0x37, ServerPlayerChangeHeldItemPacket.class);
this.registerIncoming(0x38, ServerDisplayScoreboardPacket.class);
this.registerIncoming(0x39, ServerEntityMetadataPacket.class);
this.registerIncoming(0x3A, ServerEntityAttachPacket.class);
this.registerIncoming(0x3B, ServerEntityVelocityPacket.class);
this.registerIncoming(0x3C, ServerEntityEquipmentPacket.class);
this.registerIncoming(0x3D, ServerPlayerSetExperiencePacket.class);
this.registerIncoming(0x3E, ServerPlayerHealthPacket.class);
this.registerIncoming(0x3F, ServerScoreboardObjectivePacket.class);
this.registerIncoming(0x40, ServerEntitySetPassengersPacket.class);
this.registerIncoming(0x41, ServerTeamPacket.class);
this.registerIncoming(0x42, ServerUpdateScorePacket.class);
this.registerIncoming(0x43, ServerSpawnPositionPacket.class);
this.registerIncoming(0x44, ServerUpdateTimePacket.class);
this.registerIncoming(0x45, ServerTitlePacket.class);
this.registerIncoming(0x46, ServerPlayBuiltinSoundPacket.class);
this.registerIncoming(0x47, ServerPlayerListDataPacket.class);
this.registerIncoming(0x48, ServerEntityCollectItemPacket.class);
this.registerIncoming(0x49, ServerEntityTeleportPacket.class);
this.registerIncoming(0x4A, ServerEntityPropertiesPacket.class);
this.registerIncoming(0x4B, ServerEntityEffectPacket.class);
this.registerIncoming(0x30, ServerUnlockRecipesPacket.class);
this.registerIncoming(0x31, ServerEntityDestroyPacket.class);
this.registerIncoming(0x32, ServerEntityRemoveEffectPacket.class);
this.registerIncoming(0x33, ServerResourcePackSendPacket.class);
this.registerIncoming(0x34, ServerRespawnPacket.class);
this.registerIncoming(0x35, ServerEntityHeadLookPacket.class);
this.registerIncoming(0x36, ServerAdvancementProgressPacket.class);
this.registerIncoming(0x37, ServerWorldBorderPacket.class);
this.registerIncoming(0x38, ServerSwitchCameraPacket.class);
this.registerIncoming(0x39, ServerPlayerChangeHeldItemPacket.class);
this.registerIncoming(0x3A, ServerDisplayScoreboardPacket.class);
this.registerIncoming(0x3B, ServerEntityMetadataPacket.class);
this.registerIncoming(0x3C, ServerEntityAttachPacket.class);
this.registerIncoming(0x3D, ServerEntityVelocityPacket.class);
this.registerIncoming(0x3E, ServerEntityEquipmentPacket.class);
this.registerIncoming(0x3F, ServerPlayerSetExperiencePacket.class);
this.registerIncoming(0x40, ServerPlayerHealthPacket.class);
this.registerIncoming(0x41, ServerScoreboardObjectivePacket.class);
this.registerIncoming(0x42, ServerEntitySetPassengersPacket.class);
this.registerIncoming(0x43, ServerTeamPacket.class);
this.registerIncoming(0x44, ServerUpdateScorePacket.class);
this.registerIncoming(0x45, ServerSpawnPositionPacket.class);
this.registerIncoming(0x46, ServerUpdateTimePacket.class);
this.registerIncoming(0x47, ServerTitlePacket.class);
this.registerIncoming(0x48, ServerPlayBuiltinSoundPacket.class);
this.registerIncoming(0x49, ServerPlayerListDataPacket.class);
this.registerIncoming(0x4A, ServerEntityCollectItemPacket.class);
this.registerIncoming(0x4B, ServerEntityTeleportPacket.class);
this.registerIncoming(0x4C, ServerAdvancementsPacket.class);
this.registerIncoming(0x4D, ServerEntityPropertiesPacket.class);
this.registerIncoming(0x4E, ServerEntityEffectPacket.class);
this.registerOutgoing(0x00, ClientTeleportConfirmPacket.class);
this.registerOutgoing(0x01, ClientTabCompletePacket.class);
this.registerOutgoing(0x02, ClientChatPacket.class);
this.registerOutgoing(0x03, ClientRequestPacket.class);
this.registerOutgoing(0x04, ClientSettingsPacket.class);
this.registerOutgoing(0x05, ClientConfirmTransactionPacket.class);
this.registerOutgoing(0x06, ClientEnchantItemPacket.class);
this.registerOutgoing(0x07, ClientWindowActionPacket.class);
this.registerOutgoing(0x08, ClientCloseWindowPacket.class);
this.registerOutgoing(0x09, ClientPluginMessagePacket.class);
this.registerOutgoing(0x0A, ClientPlayerInteractEntityPacket.class);
this.registerOutgoing(0x0B, ClientKeepAlivePacket.class);
this.registerOutgoing(0x0C, ClientPlayerPositionPacket.class);
this.registerOutgoing(0x0D, ClientPlayerPositionRotationPacket.class);
this.registerOutgoing(0x0E, ClientPlayerRotationPacket.class);
this.registerOutgoing(0x0F, ClientPlayerMovementPacket.class);
this.registerOutgoing(0x10, ClientVehicleMovePacket.class);
this.registerOutgoing(0x11, ClientSteerBoatPacket.class);
this.registerOutgoing(0x12, ClientPlayerAbilitiesPacket.class);
this.registerOutgoing(0x13, ClientPlayerActionPacket.class);
this.registerOutgoing(0x14, ClientPlayerStatePacket.class);
this.registerOutgoing(0x15, ClientSteerVehiclePacket.class);
this.registerOutgoing(0x16, ClientResourcePackStatusPacket.class);
this.registerOutgoing(0x17, ClientPlayerChangeHeldItemPacket.class);
this.registerOutgoing(0x18, ClientCreativeInventoryActionPacket.class);
this.registerOutgoing(0x19, ClientUpdateSignPacket.class);
this.registerOutgoing(0x1A, ClientPlayerSwingArmPacket.class);
this.registerOutgoing(0x1B, ClientSpectatePacket.class);
this.registerOutgoing(0x1C, ClientPlayerPlaceBlockPacket.class);
this.registerOutgoing(0x1D, ClientPlayerUseItemPacket.class);
this.registerOutgoing(0x01, ClientPrepareCraftingGridPacket.class);
this.registerOutgoing(0x02, ClientTabCompletePacket.class);
this.registerOutgoing(0x03, ClientChatPacket.class);
this.registerOutgoing(0x04, ClientRequestPacket.class);
this.registerOutgoing(0x05, ClientSettingsPacket.class);
this.registerOutgoing(0x06, ClientConfirmTransactionPacket.class);
this.registerOutgoing(0x07, ClientEnchantItemPacket.class);
this.registerOutgoing(0x08, ClientWindowActionPacket.class);
this.registerOutgoing(0x09, ClientCloseWindowPacket.class);
this.registerOutgoing(0x0A, ClientPluginMessagePacket.class);
this.registerOutgoing(0x0B, ClientPlayerInteractEntityPacket.class);
this.registerOutgoing(0x0C, ClientKeepAlivePacket.class);
this.registerOutgoing(0x0D, ClientPlayerPositionPacket.class);
this.registerOutgoing(0x0E, ClientPlayerPositionRotationPacket.class);
this.registerOutgoing(0x0F, ClientPlayerRotationPacket.class);
this.registerOutgoing(0x10, ClientPlayerMovementPacket.class);
this.registerOutgoing(0x11, ClientVehicleMovePacket.class);
this.registerOutgoing(0x12, ClientSteerBoatPacket.class);
this.registerOutgoing(0x13, ClientPlayerAbilitiesPacket.class);
this.registerOutgoing(0x14, ClientPlayerActionPacket.class);
this.registerOutgoing(0x15, ClientPlayerStatePacket.class);
this.registerOutgoing(0x16, ClientSteerVehiclePacket.class);
this.registerOutgoing(0x17, ClientCraftingBookDataPacket.class);
this.registerOutgoing(0x18, ClientResourcePackStatusPacket.class);
this.registerOutgoing(0x19, ClientAdvancementTabPacket.class);
this.registerOutgoing(0x1A, ClientPlayerChangeHeldItemPacket.class);
this.registerOutgoing(0x1B, ClientCreativeInventoryActionPacket.class);
this.registerOutgoing(0x1C, ClientUpdateSignPacket.class);
this.registerOutgoing(0x1D, ClientPlayerSwingArmPacket.class);
this.registerOutgoing(0x1E, ClientSpectatePacket.class);
this.registerOutgoing(0x1F, ClientPlayerPlaceBlockPacket.class);
this.registerOutgoing(0x20, ClientPlayerUseItemPacket.class);
}
private void initServerGame(Session session) {
this.registerIncoming(0x00, ClientTeleportConfirmPacket.class);
this.registerIncoming(0x01, ClientTabCompletePacket.class);
this.registerIncoming(0x02, ClientChatPacket.class);
this.registerIncoming(0x03, ClientRequestPacket.class);
this.registerIncoming(0x04, ClientSettingsPacket.class);
this.registerIncoming(0x05, ClientConfirmTransactionPacket.class);
this.registerIncoming(0x06, ClientEnchantItemPacket.class);
this.registerIncoming(0x07, ClientWindowActionPacket.class);
this.registerIncoming(0x08, ClientCloseWindowPacket.class);
this.registerIncoming(0x09, ClientPluginMessagePacket.class);
this.registerIncoming(0x0A, ClientPlayerInteractEntityPacket.class);
this.registerIncoming(0x0B, ClientKeepAlivePacket.class);
this.registerIncoming(0x0C, ClientPlayerPositionPacket.class);
this.registerIncoming(0x0D, ClientPlayerPositionRotationPacket.class);
this.registerIncoming(0x0E, ClientPlayerRotationPacket.class);
this.registerIncoming(0x0F, ClientPlayerMovementPacket.class);
this.registerIncoming(0x10, ClientVehicleMovePacket.class);
this.registerIncoming(0x11, ClientSteerBoatPacket.class);
this.registerIncoming(0x12, ClientPlayerAbilitiesPacket.class);
this.registerIncoming(0x13, ClientPlayerActionPacket.class);
this.registerIncoming(0x14, ClientPlayerStatePacket.class);
this.registerIncoming(0x15, ClientSteerVehiclePacket.class);
this.registerIncoming(0x16, ClientResourcePackStatusPacket.class);
this.registerIncoming(0x17, ClientPlayerChangeHeldItemPacket.class);
this.registerIncoming(0x18, ClientCreativeInventoryActionPacket.class);
this.registerIncoming(0x19, ClientUpdateSignPacket.class);
this.registerIncoming(0x1A, ClientPlayerSwingArmPacket.class);
this.registerIncoming(0x1B, ClientSpectatePacket.class);
this.registerIncoming(0x1C, ClientPlayerPlaceBlockPacket.class);
this.registerIncoming(0x1D, ClientPlayerUseItemPacket.class);
this.registerIncoming(0x01, ClientPrepareCraftingGridPacket.class);
this.registerIncoming(0x02, ClientTabCompletePacket.class);
this.registerIncoming(0x03, ClientChatPacket.class);
this.registerIncoming(0x04, ClientRequestPacket.class);
this.registerIncoming(0x05, ClientSettingsPacket.class);
this.registerIncoming(0x06, ClientConfirmTransactionPacket.class);
this.registerIncoming(0x07, ClientEnchantItemPacket.class);
this.registerIncoming(0x08, ClientWindowActionPacket.class);
this.registerIncoming(0x09, ClientCloseWindowPacket.class);
this.registerIncoming(0x0A, ClientPluginMessagePacket.class);
this.registerIncoming(0x0B, ClientPlayerInteractEntityPacket.class);
this.registerIncoming(0x0C, ClientKeepAlivePacket.class);
this.registerIncoming(0x0D, ClientPlayerPositionPacket.class);
this.registerIncoming(0x0E, ClientPlayerPositionRotationPacket.class);
this.registerIncoming(0x0F, ClientPlayerRotationPacket.class);
this.registerIncoming(0x10, ClientPlayerMovementPacket.class);
this.registerIncoming(0x11, ClientVehicleMovePacket.class);
this.registerIncoming(0x12, ClientSteerBoatPacket.class);
this.registerIncoming(0x13, ClientPlayerAbilitiesPacket.class);
this.registerIncoming(0x14, ClientPlayerActionPacket.class);
this.registerIncoming(0x15, ClientPlayerStatePacket.class);
this.registerIncoming(0x16, ClientSteerVehiclePacket.class);
this.registerIncoming(0x17, ClientCraftingBookDataPacket.class);
this.registerIncoming(0x18, ClientResourcePackStatusPacket.class);
this.registerIncoming(0x19, ClientAdvancementTabPacket.class);
this.registerIncoming(0x1A, ClientPlayerChangeHeldItemPacket.class);
this.registerIncoming(0x1B, ClientCreativeInventoryActionPacket.class);
this.registerIncoming(0x1C, ClientUpdateSignPacket.class);
this.registerIncoming(0x1D, ClientPlayerSwingArmPacket.class);
this.registerIncoming(0x1E, ClientSpectatePacket.class);
this.registerIncoming(0x1F, ClientPlayerPlaceBlockPacket.class);
this.registerIncoming(0x20, ClientPlayerUseItemPacket.class);
this.registerOutgoing(0x00, ServerSpawnObjectPacket.class);
this.registerOutgoing(0x01, ServerSpawnExpOrbPacket.class);
@ -492,10 +507,10 @@ public class MinecraftProtocol extends PacketProtocol {
this.registerOutgoing(0x22, ServerSpawnParticlePacket.class);
this.registerOutgoing(0x23, ServerJoinGamePacket.class);
this.registerOutgoing(0x24, ServerMapDataPacket.class);
this.registerOutgoing(0x25, ServerEntityPositionPacket.class);
this.registerOutgoing(0x26, ServerEntityPositionRotationPacket.class);
this.registerOutgoing(0x27, ServerEntityRotationPacket.class);
this.registerOutgoing(0x28, ServerEntityMovementPacket.class);
this.registerOutgoing(0x25, ServerEntityMovementPacket.class);
this.registerOutgoing(0x26, ServerEntityPositionPacket.class);
this.registerOutgoing(0x27, ServerEntityPositionRotationPacket.class);
this.registerOutgoing(0x28, ServerEntityRotationPacket.class);
this.registerOutgoing(0x29, ServerVehicleMovePacket.class);
this.registerOutgoing(0x2A, ServerOpenTileEntityEditorPacket.class);
this.registerOutgoing(0x2B, ServerPlayerAbilitiesPacket.class);
@ -503,34 +518,37 @@ public class MinecraftProtocol extends PacketProtocol {
this.registerOutgoing(0x2D, ServerPlayerListEntryPacket.class);
this.registerOutgoing(0x2E, ServerPlayerPositionRotationPacket.class);
this.registerOutgoing(0x2F, ServerPlayerUseBedPacket.class);
this.registerOutgoing(0x30, ServerEntityDestroyPacket.class);
this.registerOutgoing(0x31, ServerEntityRemoveEffectPacket.class);
this.registerOutgoing(0x32, ServerResourcePackSendPacket.class);
this.registerOutgoing(0x33, ServerRespawnPacket.class);
this.registerOutgoing(0x34, ServerEntityHeadLookPacket.class);
this.registerOutgoing(0x35, ServerWorldBorderPacket.class);
this.registerOutgoing(0x36, ServerSwitchCameraPacket.class);
this.registerOutgoing(0x37, ServerPlayerChangeHeldItemPacket.class);
this.registerOutgoing(0x38, ServerDisplayScoreboardPacket.class);
this.registerOutgoing(0x39, ServerEntityMetadataPacket.class);
this.registerOutgoing(0x3A, ServerEntityAttachPacket.class);
this.registerOutgoing(0x3B, ServerEntityVelocityPacket.class);
this.registerOutgoing(0x3C, ServerEntityEquipmentPacket.class);
this.registerOutgoing(0x3D, ServerPlayerSetExperiencePacket.class);
this.registerOutgoing(0x3E, ServerPlayerHealthPacket.class);
this.registerOutgoing(0x3F, ServerScoreboardObjectivePacket.class);
this.registerOutgoing(0x40, ServerEntitySetPassengersPacket.class);
this.registerOutgoing(0x41, ServerTeamPacket.class);
this.registerOutgoing(0x42, ServerUpdateScorePacket.class);
this.registerOutgoing(0x43, ServerSpawnPositionPacket.class);
this.registerOutgoing(0x44, ServerUpdateTimePacket.class);
this.registerOutgoing(0x45, ServerTitlePacket.class);
this.registerOutgoing(0x46, ServerPlayBuiltinSoundPacket.class);
this.registerOutgoing(0x47, ServerPlayerListDataPacket.class);
this.registerOutgoing(0x48, ServerEntityCollectItemPacket.class);
this.registerOutgoing(0x49, ServerEntityTeleportPacket.class);
this.registerOutgoing(0x4A, ServerEntityPropertiesPacket.class);
this.registerOutgoing(0x4B, ServerEntityEffectPacket.class);
this.registerOutgoing(0x30, ServerUnlockRecipesPacket.class);
this.registerOutgoing(0x31, ServerEntityDestroyPacket.class);
this.registerOutgoing(0x32, ServerEntityRemoveEffectPacket.class);
this.registerOutgoing(0x33, ServerResourcePackSendPacket.class);
this.registerOutgoing(0x34, ServerRespawnPacket.class);
this.registerOutgoing(0x35, ServerEntityHeadLookPacket.class);
this.registerOutgoing(0x36, ServerAdvancementProgressPacket.class);
this.registerOutgoing(0x37, ServerWorldBorderPacket.class);
this.registerOutgoing(0x38, ServerSwitchCameraPacket.class);
this.registerOutgoing(0x39, ServerPlayerChangeHeldItemPacket.class);
this.registerOutgoing(0x3A, ServerDisplayScoreboardPacket.class);
this.registerOutgoing(0x3B, ServerEntityMetadataPacket.class);
this.registerOutgoing(0x3C, ServerEntityAttachPacket.class);
this.registerOutgoing(0x3D, ServerEntityVelocityPacket.class);
this.registerOutgoing(0x3E, ServerEntityEquipmentPacket.class);
this.registerOutgoing(0x3F, ServerPlayerSetExperiencePacket.class);
this.registerOutgoing(0x40, ServerPlayerHealthPacket.class);
this.registerOutgoing(0x41, ServerScoreboardObjectivePacket.class);
this.registerOutgoing(0x42, ServerEntitySetPassengersPacket.class);
this.registerOutgoing(0x43, ServerTeamPacket.class);
this.registerOutgoing(0x44, ServerUpdateScorePacket.class);
this.registerOutgoing(0x45, ServerSpawnPositionPacket.class);
this.registerOutgoing(0x46, ServerUpdateTimePacket.class);
this.registerOutgoing(0x47, ServerTitlePacket.class);
this.registerOutgoing(0x48, ServerPlayBuiltinSoundPacket.class);
this.registerOutgoing(0x49, ServerPlayerListDataPacket.class);
this.registerOutgoing(0x4A, ServerEntityCollectItemPacket.class);
this.registerOutgoing(0x4B, ServerEntityTeleportPacket.class);
this.registerOutgoing(0x4C, ServerAdvancementsPacket.class);
this.registerOutgoing(0x4D, ServerEntityPropertiesPacket.class);
this.registerOutgoing(0x4E, ServerEntityEffectPacket.class);
}
private void initClientStatus(Session session) {

View file

@ -6,6 +6,8 @@ import com.github.steveice10.mc.protocol.data.game.BossBarDivision;
import com.github.steveice10.mc.protocol.data.game.ClientRequest;
import com.github.steveice10.mc.protocol.data.game.MessageType;
import com.github.steveice10.mc.protocol.data.game.ResourcePackStatus;
import com.github.steveice10.mc.protocol.data.game.UnlockRecipesAction;
import com.github.steveice10.mc.protocol.data.game.advancement.Advancement;
import com.github.steveice10.mc.protocol.data.game.entity.Effect;
import com.github.steveice10.mc.protocol.data.game.entity.EquipmentSlot;
import com.github.steveice10.mc.protocol.data.game.entity.attribute.AttributeType;
@ -29,7 +31,9 @@ import com.github.steveice10.mc.protocol.data.game.scoreboard.TeamColor;
import com.github.steveice10.mc.protocol.data.game.setting.Difficulty;
import com.github.steveice10.mc.protocol.data.game.statistic.Achievement;
import com.github.steveice10.mc.protocol.data.game.statistic.GenericStatistic;
import com.github.steveice10.mc.protocol.data.game.window.AdvancementTabAction;
import com.github.steveice10.mc.protocol.data.game.window.ClickItemParam;
import com.github.steveice10.mc.protocol.data.game.window.CraftingBookDataType;
import com.github.steveice10.mc.protocol.data.game.window.CreativeGrabParam;
import com.github.steveice10.mc.protocol.data.game.window.ShiftClickItemParam;
import com.github.steveice10.mc.protocol.data.game.window.SpreadItemParam;
@ -140,13 +144,13 @@ public class MagicValues {
register(MetadataType.BLOCK_FACE, 10);
register(MetadataType.OPTIONAL_UUID, 11);
register(MetadataType.BLOCK_STATE, 12);
register(MetadataType.NBT_TAG, 13);
register(HandshakeIntent.STATUS, 1);
register(HandshakeIntent.LOGIN, 2);
register(ClientRequest.RESPAWN, 0);
register(ClientRequest.STATS, 1);
register(ClientRequest.OPEN_INVENTORY, 2);
register(ChatVisibility.FULL, 0);
register(ChatVisibility.SYSTEM, 1);
@ -538,6 +542,7 @@ public class MagicValues {
register(UpdatedTileType.END_GATEWAY, 8);
register(UpdatedTileType.SIGN, 9);
register(UpdatedTileType.SHULKER_BOX, 10);
register(UpdatedTileType.BED, 11);
register(ClientNotification.INVALID_BED, 0);
register(ClientNotification.START_RAIN, 2);
@ -669,6 +674,11 @@ public class MagicValues {
register(NoteBlockValueType.SNARE_DRUM, 2);
register(NoteBlockValueType.HI_HAT, 3);
register(NoteBlockValueType.BASS_DRUM, 4);
register(NoteBlockValueType.FLUTE, 5);
register(NoteBlockValueType.BELL, 6);
register(NoteBlockValueType.GUITAR, 7);
register(NoteBlockValueType.CHIME, 8);
register(NoteBlockValueType.XYLOPHONE, 9);
register(PistonValueType.PUSHING, 0);
register(PistonValueType.PULLING, 1);
@ -779,6 +789,10 @@ public class MagicValues {
register(ScoreType.INTEGER, "integer");
register(ScoreType.HEARTS, "hearts");
register(Advancement.DisplayData.FrameType.TASK, 0);
register(Advancement.DisplayData.FrameType.CHALLENGE, 1);
register(Advancement.DisplayData.FrameType.GOAL, 2);
register(WorldBorderAction.SET_SIZE, 0);
register(WorldBorderAction.LERP_SIZE, 1);
register(WorldBorderAction.SET_CENTER, 2);
@ -799,6 +813,16 @@ public class MagicValues {
register(TitleAction.CLEAR, 4);
register(TitleAction.RESET, 5);
register(UnlockRecipesAction.INIT, 0);
register(UnlockRecipesAction.ADD, 1);
register(UnlockRecipesAction.REMOVE, 2);
register(CraftingBookDataType.DISPLAYED_RECIPE, 0);
register(CraftingBookDataType.CRAFTING_BOOK_STATUS, 1);
register(AdvancementTabAction.OPENED_TAB, 0);
register(AdvancementTabAction.CLOSED_SCREEN, 1);
register(ResourcePackStatus.SUCCESSFULLY_LOADED, 0);
register(ResourcePackStatus.DECLINED, 1);
register(ResourcePackStatus.FAILED_DOWNLOAD, 2);

View file

@ -2,6 +2,5 @@ package com.github.steveice10.mc.protocol.data.game;
public enum ClientRequest {
RESPAWN,
STATS,
OPEN_INVENTORY;
STATS;
}

View file

@ -0,0 +1,7 @@
package com.github.steveice10.mc.protocol.data.game;
public enum UnlockRecipesAction {
INIT,
ADD,
REMOVE;
}

View file

@ -0,0 +1,167 @@
package com.github.steveice10.mc.protocol.data.game.advancement;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
import com.github.steveice10.mc.protocol.data.message.Message;
import com.github.steveice10.mc.protocol.util.ReflectionToString;
import java.util.List;
import java.util.Objects;
public class Advancement {
private String id;
private String parentId;
private DisplayData displayData;
private List<String> criteria;
private List<List<String>> requirements;
public Advancement(String id, String parentId, List<String> criteria, List<List<String>> requirements) {
this.id = id;
this.parentId = parentId;
this.criteria = criteria;
this.requirements = requirements;
}
public Advancement(String id, String parentId, List<String> criteria, List<List<String>> requirements, DisplayData displayData) {
this(id, parentId, criteria, requirements);
this.displayData = displayData;
}
public String getId() {
return id;
}
public String getParentId() {
return parentId;
}
public DisplayData getDisplayData() {
return displayData;
}
public List<String> getCriteria() {
return criteria;
}
public List<List<String>> getRequirements() {
return requirements;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Advancement)) return false;
Advancement that = (Advancement) o;
return Objects.equals(this.id, that.id) &&
Objects.equals(this.parentId, that.parentId) &&
Objects.equals(this.displayData, that.displayData) &&
Objects.equals(this.criteria, that.criteria) &&
Objects.equals(this.requirements, that.requirements);
}
@Override
public int hashCode() {
return Objects.hash(id, parentId, displayData, criteria, requirements);
}
@Override
public String toString() {
return ReflectionToString.toString(this);
}
public static class DisplayData {
public enum FrameType {
TASK,
CHALLENGE,
GOAL;
}
private Message title;
private Message description;
private ItemStack icon;
private FrameType frameType;
private boolean showToast;
private boolean hidden;
private String backgroundTexture;
private float posX, posY;
public DisplayData(Message title, Message description, ItemStack icon, FrameType frameType,
boolean showToast, boolean hidden, float posX, float posY) {
this.title = title;
this.description = description;
this.icon = icon;
this.frameType = frameType;
this.showToast = showToast;
this.hidden = hidden;
this.posX = posX;
this.posY = posY;
}
public DisplayData(Message title, Message description, ItemStack icon, FrameType frameType,
boolean showToast, boolean hidden, float posX, float posY, String backgroundTexture) {
this(title, description, icon, frameType, showToast, hidden, posX, posY);
this.backgroundTexture = backgroundTexture;
}
public Message getTitle() {
return title;
}
public Message getDescription() {
return description;
}
public ItemStack getIcon() {
return icon;
}
public FrameType getFrameType() {
return frameType;
}
public boolean doesShowToast() {
return showToast;
}
public boolean isHidden() {
return hidden;
}
public String getBackgroundTexture() {
return backgroundTexture;
}
public float getPosX() {
return posX;
}
public float getPosY() {
return posY;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof DisplayData)) return false;
DisplayData that = (DisplayData) o;
return this.showToast == that.showToast &&
this.hidden == that.hidden &&
Float.compare(that.posX, this.posX) == 0 &&
Float.compare(that.posY, this.posY) == 0 &&
Objects.equals(this.title, that.title) &&
Objects.equals(this.description, that.description) &&
Objects.equals(this.icon, that.icon) &&
this.frameType == that.frameType &&
Objects.equals(this.backgroundTexture, that.backgroundTexture);
}
@Override
public int hashCode() {
return Objects.hash(title, description, icon, frameType, showToast, hidden, backgroundTexture, posX, posY);
}
@Override
public String toString() {
return ReflectionToString.toString(this);
}
}
}

View file

@ -13,5 +13,6 @@ public enum MetadataType {
OPTIONAL_POSITION,
BLOCK_FACE,
OPTIONAL_UUID,
BLOCK_STATE;
BLOCK_STATE,
NBT_TAG;
}

View file

@ -0,0 +1,6 @@
package com.github.steveice10.mc.protocol.data.game.window;
public enum AdvancementTabAction {
OPENED_TAB,
CLOSED_SCREEN;
}

View file

@ -0,0 +1,6 @@
package com.github.steveice10.mc.protocol.data.game.window;
public enum CraftingBookDataType {
DISPLAYED_RECIPE,
CRAFTING_BOOK_STATUS;
}

View file

@ -0,0 +1,50 @@
package com.github.steveice10.mc.protocol.data.game.window;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
import com.github.steveice10.mc.protocol.util.ReflectionToString;
import java.util.Objects;
public class PrepareCraftingGridEntry {
private ItemStack item;
private byte craftingGridSlot;
private byte playerInventorySlot;
public PrepareCraftingGridEntry(ItemStack item, byte craftingGridSlot, byte playerInventorySlot) {
this.item = item;
this.craftingGridSlot = craftingGridSlot;
this.playerInventorySlot = playerInventorySlot;
}
public ItemStack getItem() {
return this.item;
}
public byte getCraftingGridSlot() {
return this.craftingGridSlot;
}
public byte getPlayerInventorySlot() {
return this.playerInventorySlot;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof PrepareCraftingGridEntry)) return false;
PrepareCraftingGridEntry that = (PrepareCraftingGridEntry) o;
return this.craftingGridSlot == that.craftingGridSlot &&
this.playerInventorySlot == that.playerInventorySlot &&
Objects.equals(this.item, that.item);
}
@Override
public int hashCode() {
return Objects.hash(item, craftingGridSlot, playerInventorySlot);
}
@Override
public String toString() {
return ReflectionToString.toString(this);
}
}

View file

@ -10,5 +10,6 @@ public enum UpdatedTileType {
STRUCTURE_BLOCK,
END_GATEWAY,
SIGN,
SHULKER_BOX;
SHULKER_BOX,
BED;
}

View file

@ -5,5 +5,10 @@ public enum NoteBlockValueType implements BlockValueType {
DOUBLE_BASS,
SNARE_DRUM,
HI_HAT,
BASS_DRUM;
BASS_DRUM,
FLUTE,
BELL,
GUITAR,
CHIME,
XYLOPHONE;
}

View file

@ -0,0 +1,48 @@
package com.github.steveice10.mc.protocol.data.message;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
public class KeybindMessage extends Message {
private String keybind;
public KeybindMessage(String keybind) {
this.keybind = keybind;
}
public String getKeybind() {
return this.keybind;
}
@Override
public String getText() {
return this.keybind;
}
@Override
public KeybindMessage clone() {
return (KeybindMessage) new KeybindMessage(this.getKeybind()).setStyle(this.getStyle().clone()).setExtra(this.getExtra());
}
@Override
public JsonElement toJson() {
JsonElement e = super.toJson();
if(e.isJsonObject()) {
JsonObject json = e.getAsJsonObject();
json.addProperty("keybind", this.keybind);
return json;
} else {
return e;
}
}
@Override
public boolean equals(Object o) {
return o instanceof KeybindMessage && super.equals(o) && this.keybind.equals(((KeybindMessage) o).keybind);
}
@Override
public int hashCode() {
return super.hashCode() * 31 + keybind.hashCode();
}
}

View file

@ -159,6 +159,8 @@ public abstract class Message implements Cloneable {
}
msg = new TranslationMessage(json.get("translate").getAsString(), with);
} else if (json.has("keybind")) {
msg = new KeybindMessage(json.get("keybind").getAsString());
} else {
throw new IllegalArgumentException("Unknown message type in json: " + json.toString());
}

View file

@ -0,0 +1,70 @@
package com.github.steveice10.mc.protocol.packet.ingame.client.window;
import com.github.steveice10.mc.protocol.data.MagicValues;
import com.github.steveice10.mc.protocol.data.game.window.AdvancementTabAction;
import com.github.steveice10.mc.protocol.util.ReflectionToString;
import com.github.steveice10.packetlib.io.NetInput;
import com.github.steveice10.packetlib.io.NetOutput;
import com.github.steveice10.packetlib.packet.Packet;
import java.io.IOException;
public class ClientAdvancementTabPacket implements Packet {
private AdvancementTabAction action;
private String tabId;
public ClientAdvancementTabPacket() {
this.action = AdvancementTabAction.CLOSED_SCREEN;
}
public ClientAdvancementTabPacket(String tabId) {
this.action = AdvancementTabAction.OPENED_TAB;
this.tabId = tabId;
}
public String getTabId() {
if (this.action != AdvancementTabAction.OPENED_TAB) {
throw new IllegalStateException("tabId is only set if action is " + AdvancementTabAction.OPENED_TAB
+ " but it was " + this.action);
}
return tabId;
}
@Override
public void read(NetInput in) throws IOException {
switch (this.action = MagicValues.key(AdvancementTabAction.class, in.readVarInt())) {
case CLOSED_SCREEN:
break;
case OPENED_TAB:
this.tabId = in.readString();
break;
default:
throw new IOException("Unknown advancement tab action: " + this.action);
}
}
@Override
public void write(NetOutput out) throws IOException {
out.writeVarInt(MagicValues.value(Integer.class, this.action));
switch (this.action) {
case CLOSED_SCREEN:
break;
case OPENED_TAB:
out.writeString(this.tabId);
break;
default:
throw new IOException("Unknown advancement tab action: " + this.action);
}
}
@Override
public boolean isPriority() {
return false;
}
@Override
public String toString() {
return ReflectionToString.toString(this);
}
}

View file

@ -0,0 +1,99 @@
package com.github.steveice10.mc.protocol.packet.ingame.client.window;
import com.github.steveice10.mc.protocol.data.MagicValues;
import com.github.steveice10.mc.protocol.data.game.window.CraftingBookDataType;
import com.github.steveice10.mc.protocol.util.ReflectionToString;
import com.github.steveice10.packetlib.io.NetInput;
import com.github.steveice10.packetlib.io.NetOutput;
import com.github.steveice10.packetlib.packet.Packet;
import java.io.IOException;
public class ClientCraftingBookDataPacket implements Packet {
private CraftingBookDataType type;
private int recipeId;
private boolean craftingBookOpen;
private boolean filterActive;
@SuppressWarnings("unused")
private ClientCraftingBookDataPacket() {
}
public ClientCraftingBookDataPacket(int recipeId) {
this.type = CraftingBookDataType.DISPLAYED_RECIPE;
this.recipeId = recipeId;
}
public ClientCraftingBookDataPacket(boolean craftingBookOpen, boolean filterActive) {
this.type = CraftingBookDataType.CRAFTING_BOOK_STATUS;
this.craftingBookOpen = craftingBookOpen;
this.filterActive = filterActive;
}
public CraftingBookDataType getType() {
return type;
}
private void ensureType(CraftingBookDataType type, String what) {
if (this.type != type) {
throw new IllegalStateException(what + " is only set when type is " + type + " but it is " + this.type);
}
}
public int getRecipeId() {
ensureType(CraftingBookDataType.DISPLAYED_RECIPE, "recipeId");
return recipeId;
}
public boolean isCraftingBookOpen() {
ensureType(CraftingBookDataType.CRAFTING_BOOK_STATUS, "craftingBookOpen");
return craftingBookOpen;
}
public boolean isFilterActive() {
ensureType(CraftingBookDataType.CRAFTING_BOOK_STATUS, "filterActive");
return filterActive;
}
@Override
public void read(NetInput in) throws IOException {
switch (this.type = MagicValues.key(CraftingBookDataType.class, in.readVarInt())) {
case DISPLAYED_RECIPE:
this.recipeId = in.readInt();
break;
case CRAFTING_BOOK_STATUS:
this.craftingBookOpen = in.readBoolean();
this.filterActive = in.readBoolean();
break;
default:
throw new IOException("Unknown crafting book data type: " + this.type);
}
}
@Override
public void write(NetOutput out) throws IOException {
out.writeVarInt(MagicValues.value(Integer.class, this.type));
switch (this.type) {
case DISPLAYED_RECIPE:
out.writeInt(this.recipeId);
break;
case CRAFTING_BOOK_STATUS:
out.writeBoolean(this.craftingBookOpen);
out.writeBoolean(this.filterActive);
break;
default:
throw new IOException("Unknown crafting book data type: " + this.type);
}
}
@Override
public boolean isPriority() {
return false;
}
@Override
public String toString() {
return ReflectionToString.toString(this);
}
}

View file

@ -0,0 +1,95 @@
package com.github.steveice10.mc.protocol.packet.ingame.client.window;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
import com.github.steveice10.mc.protocol.data.game.window.PrepareCraftingGridEntry;
import com.github.steveice10.mc.protocol.util.NetUtil;
import com.github.steveice10.mc.protocol.util.ReflectionToString;
import com.github.steveice10.packetlib.io.NetInput;
import com.github.steveice10.packetlib.io.NetOutput;
import com.github.steveice10.packetlib.packet.Packet;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class ClientPrepareCraftingGridPacket implements Packet {
private int windowId;
private int actionId;
private List<PrepareCraftingGridEntry> returnEntries;
private List<PrepareCraftingGridEntry> prepareEntries;
@SuppressWarnings("unused")
private ClientPrepareCraftingGridPacket() {
}
public ClientPrepareCraftingGridPacket(int windowId, int actionId, List<PrepareCraftingGridEntry> returnEntries,
List<PrepareCraftingGridEntry> prepareEntries) {
this.windowId = windowId;
this.actionId = actionId;
this.returnEntries = returnEntries;
this.prepareEntries = prepareEntries;
}
public int getWindowId() {
return this.windowId;
}
public int getActionId() {
return this.actionId;
}
public List<PrepareCraftingGridEntry> getReturnEntries() {
return this.returnEntries;
}
public List<PrepareCraftingGridEntry> getPrepareEntries() {
return this.prepareEntries;
}
@Override
public void read(NetInput in) throws IOException {
this.windowId = in.readByte();
this.actionId = in.readShort();
this.returnEntries = readEntries(in);
this.prepareEntries = readEntries(in);
}
private static List<PrepareCraftingGridEntry> readEntries(NetInput in) throws IOException {
List<PrepareCraftingGridEntry> entries = new ArrayList<>();
for (int i = in.readShort(); i > 0; i--) {
ItemStack item = NetUtil.readItem(in);
byte craftingGridSlot = in.readByte();
byte playerInventorySlot = in.readByte();
entries.add(new PrepareCraftingGridEntry(item, craftingGridSlot, playerInventorySlot));
}
return entries;
}
@Override
public void write(NetOutput out) throws IOException {
out.writeByte(this.windowId);
out.writeShort(actionId);
writeEntries(out, this.returnEntries);
writeEntries(out, this.prepareEntries);
}
private static void writeEntries(NetOutput out, List<PrepareCraftingGridEntry> entries) throws IOException {
out.writeShort(entries.size());
for (PrepareCraftingGridEntry entry : entries) {
NetUtil.writeItem(out, entry.getItem());
out.writeByte(entry.getCraftingGridSlot());
out.writeByte(entry.getPlayerInventorySlot());
}
}
@Override
public boolean isPriority() {
return false;
}
@Override
public String toString() {
return ReflectionToString.toString(this);
}
}

View file

@ -0,0 +1,53 @@
package com.github.steveice10.mc.protocol.packet.ingame.server;
import com.github.steveice10.mc.protocol.util.ReflectionToString;
import com.github.steveice10.packetlib.io.NetInput;
import com.github.steveice10.packetlib.io.NetOutput;
import com.github.steveice10.packetlib.packet.Packet;
import java.io.IOException;
public class ServerAdvancementProgressPacket implements Packet {
private String id;
@SuppressWarnings("unused")
private ServerAdvancementProgressPacket() {
}
public ServerAdvancementProgressPacket(String id) {
this.id = id;
}
public String getId() {
return this.id;
}
@Override
public void read(NetInput in) throws IOException {
if (in.readBoolean()) {
this.id = in.readString();
} else {
this.id = null;
}
}
@Override
public void write(NetOutput out) throws IOException {
if (this.id != null) {
out.writeBoolean(true);
out.writeString(this.id);
} else {
out.writeBoolean(false);
}
}
@Override
public boolean isPriority() {
return false;
}
@Override
public String toString() {
return ReflectionToString.toString(this);
}
}

View file

@ -0,0 +1,200 @@
package com.github.steveice10.mc.protocol.packet.ingame.server;
import com.github.steveice10.mc.protocol.data.MagicValues;
import com.github.steveice10.mc.protocol.data.game.advancement.Advancement;
import com.github.steveice10.mc.protocol.data.game.advancement.Advancement.DisplayData;
import com.github.steveice10.mc.protocol.data.game.advancement.Advancement.DisplayData.FrameType;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
import com.github.steveice10.mc.protocol.data.message.Message;
import com.github.steveice10.mc.protocol.util.NetUtil;
import com.github.steveice10.mc.protocol.util.ReflectionToString;
import com.github.steveice10.packetlib.io.NetInput;
import com.github.steveice10.packetlib.io.NetOutput;
import com.github.steveice10.packetlib.packet.Packet;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ServerAdvancementsPacket implements Packet {
private boolean reset;
private List<Advancement> advancements;
private List<String> removedAdvancements;
private Map<String, Map<String, Long>> progress;
@SuppressWarnings("unused")
private ServerAdvancementsPacket() {
}
public ServerAdvancementsPacket(boolean reset, List<Advancement> advancements, List<String> removedAdvancements,
Map<String, Map<String, Long>> progress) {
this.reset = reset;
this.advancements = advancements;
this.removedAdvancements = removedAdvancements;
this.progress = progress;
}
public boolean doesReset() {
return this.reset;
}
public List<Advancement> getAdvancements() {
return this.advancements;
}
public List<String> getRemovedAdvancements() {
return this.removedAdvancements;
}
public Map<String, Map<String, Long>> getProgress() {
return this.progress;
}
public Map<String, Long> getProgress(String advancementId) {
return getProgress().get(advancementId);
}
public Long getAchievedDate(String advancementId, String criterionId) {
return getProgress(advancementId).get(criterionId);
}
@Override
public void read(NetInput in) throws IOException {
this.reset = in.readBoolean();
this.advancements = new ArrayList<>();
for (int i = in.readVarInt(); i > 0; i--) {
String id = in.readString();
String parentId = in.readBoolean() ? in.readString() : null;
DisplayData displayData = null;
if (in.readBoolean()) {
Message title = Message.fromString(in.readString());
Message description = Message.fromString(in.readString());
ItemStack icon = NetUtil.readItem(in);
FrameType frameType = MagicValues.key(FrameType.class, in.readVarInt());
int flags = in.readInt();
boolean hasBackgroundTexture = (flags & 0x1) != 0;
boolean showToast = (flags & 0x2) != 0;
boolean hidden = (flags & 0x4) != 0;
String backgroundTexture = hasBackgroundTexture ? in.readString() : null;
float posX = in.readFloat(), posY = in.readFloat();
displayData = new DisplayData(title, description, icon, frameType, showToast, hidden, posX, posY, backgroundTexture);
}
List<String> criteria = new ArrayList<>();
for (int j = in.readVarInt(); j > 0; j--) {
criteria.add(in.readString());
}
List<List<String>> requirements = new ArrayList<>();
for (int j = in.readVarInt(); j > 0; j--) {
List<String> requirement = new ArrayList<>();
for (int k = in.readVarInt(); k > 0; k--) {
requirement.add(in.readString());
}
requirements.add(requirement);
}
this.advancements.add(new Advancement(id, parentId, criteria, requirements, displayData));
}
this.removedAdvancements = new ArrayList<>();
for (int i = in.readVarInt(); i > 0; i--) {
this.removedAdvancements.add(in.readString());
}
this.progress = new HashMap<>();
for (int i = in.readVarInt(); i > 0; i--) {
String advancementId = in.readString();
Map<String, Long> advancementProgress = new HashMap<>();
for (int j = in.readVarInt(); j > 0; j--) {
String criterionId = in.readString();
Long achievedDate = in.readBoolean() ? in.readLong() : null;
advancementProgress.put(criterionId, achievedDate);
}
this.progress.put(advancementId, advancementProgress);
}
}
@Override
public void write(NetOutput out) throws IOException {
out.writeBoolean(this.reset);
out.writeVarInt(this.advancements.size());
for (Advancement advancement : this.advancements) {
out.writeString(advancement.getId());
if (advancement.getParentId() != null) {
out.writeBoolean(true);
out.writeString(advancement.getParentId());
} else {
out.writeBoolean(false);
}
DisplayData displayData = advancement.getDisplayData();
if (displayData != null) {
out.writeBoolean(true);
out.writeString(displayData.getTitle().toJsonString());
out.writeString(displayData.getDescription().toJsonString());
NetUtil.writeItem(out, displayData.getIcon());
out.writeVarInt(MagicValues.value(Integer.class, displayData.getFrameType()));
String backgroundTexture = displayData.getBackgroundTexture();
int flags = 0;
if (backgroundTexture != null) flags |= 0x1;
if (displayData.doesShowToast()) flags |= 0x2;
if (displayData.isHidden()) flags |= 0x4;
out.writeInt(flags);
if (backgroundTexture != null) {
out.writeString(backgroundTexture);
}
out.writeFloat(displayData.getPosX());
out.writeFloat(displayData.getPosY());
} else {
out.writeBoolean(false);
}
out.writeVarInt(advancement.getCriteria().size());
for (String criterion : advancement.getCriteria()) {
out.writeString(criterion);
}
out.writeVarInt(advancement.getRequirements().size());
for (List<String> requirement : advancement.getRequirements()) {
out.writeVarInt(requirement.size());
for (String criterion : requirement) {
out.writeString(criterion);
}
}
}
out.writeVarInt(this.removedAdvancements.size());
for (String id : this.removedAdvancements) {
out.writeString(id);
}
out.writeVarInt(this.progress.size());
for (Map.Entry<String, Map<String, Long>> advancement : this.progress.entrySet()) {
out.writeString(advancement.getKey());
Map<String, Long> advancementProgress = advancement.getValue();
out.writeVarInt(advancementProgress.size());
for (Map.Entry<String, Long> criterion : advancementProgress.entrySet()) {
out.writeString(criterion.getKey());
if (criterion.getValue() != null) {
out.writeBoolean(true);
out.writeLong(criterion.getValue());
} else {
out.writeBoolean(false);
}
}
}
}
@Override
public boolean isPriority() {
return false;
}
@Override
public String toString() {
return ReflectionToString.toString(this);
}
}

View file

@ -0,0 +1,122 @@
package com.github.steveice10.mc.protocol.packet.ingame.server;
import com.github.steveice10.mc.protocol.data.MagicValues;
import com.github.steveice10.mc.protocol.data.game.UnlockRecipesAction;
import com.github.steveice10.mc.protocol.util.ReflectionToString;
import com.github.steveice10.packetlib.io.NetInput;
import com.github.steveice10.packetlib.io.NetOutput;
import com.github.steveice10.packetlib.packet.Packet;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class ServerUnlockRecipesPacket implements Packet {
private UnlockRecipesAction action;
private List<Integer> recipes;
private List<Integer> alreadyKnownRecipes;
private boolean openCraftingBook;
private boolean activateFiltering;
@SuppressWarnings("unused")
private ServerUnlockRecipesPacket() {
}
private ServerUnlockRecipesPacket(boolean openCraftingBook, boolean activateFiltering, List<Integer> recipes) {
this.openCraftingBook = openCraftingBook;
this.activateFiltering = activateFiltering;
this.recipes = recipes;
}
public ServerUnlockRecipesPacket(boolean openCraftingBook, boolean activateFiltering, List<Integer> recipes, List<Integer> alreadyKnownRecipes) {
this(openCraftingBook, activateFiltering, recipes);
this.action = UnlockRecipesAction.INIT;
this.alreadyKnownRecipes = alreadyKnownRecipes;
}
public ServerUnlockRecipesPacket(boolean openCraftingBook, boolean activateFiltering, List<Integer> recipes, UnlockRecipesAction action) {
this(openCraftingBook, activateFiltering, recipes);
if (action != UnlockRecipesAction.ADD && action != UnlockRecipesAction.REMOVE) {
throw new IllegalArgumentException("action must be ADD or REMOVE");
}
this.action = action;
}
public UnlockRecipesAction getAction() {
return this.action;
}
public List<Integer> getRecipes() {
return this.recipes;
}
public List<Integer> getAlreadyKnownRecipes() {
if (this.action != UnlockRecipesAction.INIT) {
throw new IllegalStateException("alreadyKnownRecipes is only set if action is " + UnlockRecipesAction.INIT
+ " but it was " + this.action);
}
return this.alreadyKnownRecipes;
}
public boolean getOpenCraftingBook() {
return this.openCraftingBook;
}
public boolean getActivateFiltering() {
return this.activateFiltering;
}
@Override
public void read(NetInput in) throws IOException {
this.action = MagicValues.key(UnlockRecipesAction.class, in.readVarInt());
this.openCraftingBook = in.readBoolean();
this.activateFiltering = in.readBoolean();
if (this.action == UnlockRecipesAction.INIT) {
int size = in.readVarInt();
this.alreadyKnownRecipes = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
this.alreadyKnownRecipes.add(in.readVarInt());
}
}
int size = in.readVarInt();
this.alreadyKnownRecipes = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
this.alreadyKnownRecipes.add(in.readVarInt());
}
}
@Override
public void write(NetOutput out) throws IOException {
out.writeVarInt(MagicValues.value(Integer.class, this.action));
out.writeBoolean(this.openCraftingBook);
out.writeBoolean(this.activateFiltering);
if (this.action == UnlockRecipesAction.INIT) {
out.writeVarInt(this.alreadyKnownRecipes.size());
for (Integer recipeId : this.alreadyKnownRecipes) {
out.writeVarInt(recipeId);
}
}
out.writeVarInt(this.recipes.size());
for (Integer recipeId : this.recipes) {
out.writeVarInt(recipeId);
}
}
@Override
public boolean isPriority() {
return false;
}
@Override
public String toString() {
return ReflectionToString.toString(this);
}
}

View file

@ -164,6 +164,9 @@ public class NetUtil {
case BLOCK_STATE:
value = readBlockState(in);
break;
case NBT_TAG:
value = readNBT(in);
break;
default:
throw new IOException("Unknown metadata type id: " + typeId);
}
@ -226,6 +229,8 @@ public class NetUtil {
case BLOCK_STATE:
writeBlockState(out, (BlockState) meta.getValue());
break;
case NBT_TAG:
writeNBT(out, (CompoundTag) meta.getValue());
default:
throw new IOException("Unknown metadata type: " + meta.getType());
}