diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/annotation/NoEncryption.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/annotation/NoEncryption.java index 413a03235..669dbfd22 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/annotation/NoEncryption.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/annotation/NoEncryption.java @@ -5,6 +5,11 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +/** + * Packets with this annotation will be sent in plain text over the network + * + * @see com.nukkitx.protocol.bedrock.packet.ServerToClientHandshakePacket + */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) public @interface NoEncryption { diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/event/EntityDefinitionTriggerEventData.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/event/EntityDefinitionTriggerEventData.java new file mode 100644 index 000000000..6114ef788 --- /dev/null +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/event/EntityDefinitionTriggerEventData.java @@ -0,0 +1,13 @@ +package com.nukkitx.protocol.bedrock.data.event; + +import lombok.Value; + +@Value +public class EntityDefinitionTriggerEventData implements EventData { + private final String id; + + @Override + public EventDataType getType() { + return EventDataType.ENTITY_DEFINITION_TRIGGER; + } +} diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/event/EventDataType.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/event/EventDataType.java index 7dae11ad8..0f32fd9be 100644 --- a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/event/EventDataType.java +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/event/EventDataType.java @@ -18,5 +18,10 @@ public enum EventDataType { PET_DIED, CAULDRON_BLOCK_USED, COMPOSTER_BLOCK_USED, - BELL_BLOCK_USED + BELL_BLOCK_USED, + ENTITY_DEFINITION_TRIGGER, // 18 + RAID_UPDATE, // 19 + MOVEMENT, // 20 + MOVEMENT_THRESHOLD, // 21 + EXTRACT_HONEY // 22 } diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/event/ExtractHoneyEventData.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/event/ExtractHoneyEventData.java new file mode 100644 index 000000000..2782033f4 --- /dev/null +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/event/ExtractHoneyEventData.java @@ -0,0 +1,14 @@ +package com.nukkitx.protocol.bedrock.data.event; + +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class ExtractHoneyEventData implements EventData { + public static final ExtractHoneyEventData INSTANCE = new ExtractHoneyEventData(); + + @Override + public EventDataType getType() { + return EventDataType.EXTRACT_HONEY; + } +} diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/event/MovementEventData.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/event/MovementEventData.java new file mode 100644 index 000000000..daa44329a --- /dev/null +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/event/MovementEventData.java @@ -0,0 +1,17 @@ +package com.nukkitx.protocol.bedrock.data.event; + +import com.nukkitx.math.vector.Vector2f; +import com.nukkitx.math.vector.Vector3f; +import lombok.Value; + +@Value +public class MovementEventData implements EventData { + private final int movementType; + private final Vector2f rotation; // Guess + private final Vector3f position; // Guess + + @Override + public EventDataType getType() { + return EventDataType.MOVEMENT; + } +} diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/event/MovementThresholdEventData.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/event/MovementThresholdEventData.java new file mode 100644 index 000000000..65e91ab1c --- /dev/null +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/event/MovementThresholdEventData.java @@ -0,0 +1,17 @@ +package com.nukkitx.protocol.bedrock.data.event; + +import lombok.Value; + +@Value +public class MovementThresholdEventData implements EventData { + private final float unknown0; + private final float unknown1; + private final float playerMovementScoreThreshold; + private final float playerMovementDistanceThreshold; + private final int playerMovementDurationThreshold; + + @Override + public EventDataType getType() { + return EventDataType.MOVEMENT_THRESHOLD; + } +} diff --git a/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/event/RaidUpdateEventData.java b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/event/RaidUpdateEventData.java new file mode 100644 index 000000000..3639e5ca9 --- /dev/null +++ b/bedrock/bedrock-common/src/main/java/com/nukkitx/protocol/bedrock/data/event/RaidUpdateEventData.java @@ -0,0 +1,15 @@ +package com.nukkitx.protocol.bedrock.data.event; + +import lombok.Value; + +@Value +public class RaidUpdateEventData implements EventData { + private final int currentWave; + private final int totalWaves; + private final boolean unknown0; // Hero of the village? + + @Override + public EventDataType getType() { + return EventDataType.RAID_UPDATE; + } +} diff --git a/bedrock/bedrock-v388/src/main/java/com/nukkitx/protocol/bedrock/v388/serializer/EventSerializer_v388.java b/bedrock/bedrock-v388/src/main/java/com/nukkitx/protocol/bedrock/v388/serializer/EventSerializer_v388.java index d1b10b419..9ea75902f 100644 --- a/bedrock/bedrock-v388/src/main/java/com/nukkitx/protocol/bedrock/v388/serializer/EventSerializer_v388.java +++ b/bedrock/bedrock-v388/src/main/java/com/nukkitx/protocol/bedrock/v388/serializer/EventSerializer_v388.java @@ -1,5 +1,7 @@ package com.nukkitx.protocol.bedrock.v388.serializer; +import com.nukkitx.math.vector.Vector2f; +import com.nukkitx.math.vector.Vector3f; import com.nukkitx.network.VarInts; import com.nukkitx.network.util.Preconditions; import com.nukkitx.protocol.bedrock.data.event.*; @@ -80,6 +82,9 @@ public void serialize(ByteBuf buffer, EventPacket packet) { BedrockUtils.writeString(buffer, agentCommandEventData.getDataKey()); BedrockUtils.writeString(buffer, agentCommandEventData.getOutput()); break; + case AGENT_CREATED: + // No extra data + break; case PATTERN_REMOVED: PatternRemovedEventData patternRemovedEventData = (PatternRemovedEventData) eventData; VarInts.writeInt(buffer, patternRemovedEventData.getItemId()); @@ -130,8 +135,28 @@ public void serialize(ByteBuf buffer, EventPacket packet) { case BELL_BLOCK_USED: VarInts.writeInt(buffer, ((BellBlockUsedEventData) eventData).getUnknown0()); break; - case AGENT_CREATED: - // No extra data + case ENTITY_DEFINITION_TRIGGER: + BedrockUtils.writeString(buffer, ((EntityDefinitionTriggerEventData) eventData).getId()); + break; + case RAID_UPDATE: + RaidUpdateEventData raidUpdateEventData = (RaidUpdateEventData) eventData; + VarInts.writeInt(buffer, raidUpdateEventData.getCurrentWave()); + VarInts.writeInt(buffer, raidUpdateEventData.getTotalWaves()); + buffer.writeBoolean(raidUpdateEventData.isUnknown0()); + break; + case MOVEMENT: + MovementEventData movementEventData = (MovementEventData) eventData; + buffer.writeByte(movementEventData.getMovementType()); + BedrockUtils.writeVector2f(buffer, movementEventData.getRotation()); + BedrockUtils.writeVector3f(buffer, movementEventData.getPosition()); + break; + case MOVEMENT_THRESHOLD: + MovementThresholdEventData movementThresholdEventData = (MovementThresholdEventData) eventData; + buffer.writeFloatLE(movementThresholdEventData.getUnknown0()); + buffer.writeFloatLE(movementThresholdEventData.getUnknown1()); + buffer.writeFloatLE(movementThresholdEventData.getPlayerMovementScoreThreshold()); + buffer.writeFloatLE(movementThresholdEventData.getPlayerMovementDistanceThreshold()); + VarInts.writeInt(buffer, movementThresholdEventData.getPlayerMovementDurationThreshold()); break; } } @@ -256,6 +281,31 @@ public void deserialize(ByteBuf buffer, EventPacket packet) { case BELL_BLOCK_USED: data = new BellBlockUsedEventData(VarInts.readInt(buffer)); break; + case ENTITY_DEFINITION_TRIGGER: + String id = BedrockUtils.readString(buffer); + data = new EntityDefinitionTriggerEventData(id); + break; + case RAID_UPDATE: + int currentWave = VarInts.readInt(buffer); + int totalWaves = VarInts.readInt(buffer); + unknownBool = buffer.readBoolean(); + data = new RaidUpdateEventData(currentWave, totalWaves, unknownBool); + break; + case MOVEMENT: + int movementType = buffer.readUnsignedByte(); + Vector2f rotation = BedrockUtils.readVector2f(buffer); + Vector3f position = BedrockUtils.readVector3f(buffer); + data = new MovementEventData(movementType, rotation, position); + break; + case MOVEMENT_THRESHOLD: + float unknownFloat0 = buffer.readFloatLE(); + float unknownFloat1 = buffer.readFloatLE(); + float playerMovementScoreThreshold = buffer.readFloatLE(); + float playerMovementDistanceThreshold = buffer.readFloatLE(); + int playerMovementDurationThreshold = VarInts.readInt(buffer); + data = new MovementThresholdEventData(unknownFloat0, unknownFloat1, playerMovementScoreThreshold, + playerMovementDistanceThreshold, playerMovementDurationThreshold); + break; default: throw new IllegalArgumentException("Unknown EventDataType"); } diff --git a/bedrock/bedrock-v389/src/main/java/com/nukkitx/protocol/bedrock/v389/Bedrock_v389.java b/bedrock/bedrock-v389/src/main/java/com/nukkitx/protocol/bedrock/v389/Bedrock_v389.java index ab7284e78..a45bdc136 100644 --- a/bedrock/bedrock-v389/src/main/java/com/nukkitx/protocol/bedrock/v389/Bedrock_v389.java +++ b/bedrock/bedrock-v389/src/main/java/com/nukkitx/protocol/bedrock/v389/Bedrock_v389.java @@ -3,6 +3,7 @@ import com.nukkitx.protocol.bedrock.BedrockPacketCodec; import com.nukkitx.protocol.bedrock.packet.*; import com.nukkitx.protocol.bedrock.v388.serializer.*; +import com.nukkitx.protocol.bedrock.v389.serializer.EventSerializer_v389; import lombok.experimental.UtilityClass; @UtilityClass @@ -74,7 +75,7 @@ public class Bedrock_v389 { .registerPacket(SetPlayerGameTypePacket.class, SetPlayerGameTypeSerializer_v388.INSTANCE, 62) .registerPacket(PlayerListPacket.class, PlayerListSerializer_v388.INSTANCE, 63) .registerPacket(SimpleEventPacket.class, SimpleEventSerializer_v388.INSTANCE, 64) - .registerPacket(EventPacket.class, EventSerializer_v388.INSTANCE, 65) + .registerPacket(EventPacket.class, EventSerializer_v389.INSTANCE, 65) .registerPacket(SpawnExperienceOrbPacket.class, SpawnExperienceOrbSerializer_v388.INSTANCE, 66) .registerPacket(ClientboundMapItemDataPacket.class, ClientboundMapItemDataSerializer_v388.INSTANCE, 67) .registerPacket(MapInfoRequestPacket.class, MapInfoRequestSerializer_v388.INSTANCE, 68) diff --git a/bedrock/bedrock-v389/src/main/java/com/nukkitx/protocol/bedrock/v389/serializer/EventSerializer_v389.java b/bedrock/bedrock-v389/src/main/java/com/nukkitx/protocol/bedrock/v389/serializer/EventSerializer_v389.java new file mode 100644 index 000000000..876636da9 --- /dev/null +++ b/bedrock/bedrock-v389/src/main/java/com/nukkitx/protocol/bedrock/v389/serializer/EventSerializer_v389.java @@ -0,0 +1,321 @@ +package com.nukkitx.protocol.bedrock.v389.serializer; + +import com.nukkitx.math.vector.Vector2f; +import com.nukkitx.math.vector.Vector3f; +import com.nukkitx.network.VarInts; +import com.nukkitx.network.util.Preconditions; +import com.nukkitx.protocol.bedrock.data.event.*; +import com.nukkitx.protocol.bedrock.packet.EventPacket; +import com.nukkitx.protocol.bedrock.v388.BedrockUtils; +import com.nukkitx.protocol.serializer.PacketSerializer; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import java.util.Arrays; +import java.util.List; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class EventSerializer_v389 implements PacketSerializer { + public static final EventSerializer_v389 INSTANCE = new EventSerializer_v389(); + + private static final EventDataType[] VALUES = EventDataType.values(); + + @Override + public void serialize(ByteBuf buffer, EventPacket packet) { + VarInts.writeLong(buffer, packet.getUniqueEntityId()); + EventData eventData = packet.getEventData(); + VarInts.writeInt(buffer, eventData.getType().ordinal()); + buffer.writeByte(packet.getUnknown0()); + + switch (eventData.getType()) { + case ACHIEVEMENT_AWARDED: + VarInts.writeInt(buffer, ((AchievementAwardedEventData) eventData).getAchievementId()); + break; + case ENTITY_INTERACT: + EntityInteractEventData entityInteractEventData = (EntityInteractEventData) eventData; + VarInts.writeInt(buffer, entityInteractEventData.getInteractionType()); + VarInts.writeInt(buffer, entityInteractEventData.getLegacyEntityTypeId()); + VarInts.writeInt(buffer, entityInteractEventData.getVariant()); + buffer.writeByte(entityInteractEventData.getPaletteColor()); + break; + case PORTAL_BUILT: + VarInts.writeInt(buffer, ((PortalBuiltEventData) eventData).getDimensionId()); + break; + case PORTAL_USED: + PortalUsedEventData portalUsedEventData = (PortalUsedEventData) eventData; + VarInts.writeInt(buffer, portalUsedEventData.getFromDimensionId()); + VarInts.writeInt(buffer, portalUsedEventData.getToDimensionId()); + break; + case MOB_KILLED: + MobKilledEventData mobKilledEventData = (MobKilledEventData) eventData; + VarInts.writeLong(buffer, mobKilledEventData.getKillerUniqueEntityId()); + VarInts.writeLong(buffer, mobKilledEventData.getVictimUniqueEntityId()); + VarInts.writeInt(buffer, mobKilledEventData.getEntityDamageCause()); + VarInts.writeInt(buffer, mobKilledEventData.getVillagerTradeTier()); + BedrockUtils.writeString(buffer, mobKilledEventData.getVillagerDisplayName()); + break; + case CAULDRON_USED: + CauldronUsedEventData cauldronUsedEventData = (CauldronUsedEventData) eventData; + VarInts.writeUnsignedInt(buffer, cauldronUsedEventData.getPotionId()); + VarInts.writeInt(buffer, cauldronUsedEventData.getColor()); + VarInts.writeInt(buffer, cauldronUsedEventData.getFillLevel()); + break; + case PLAYER_DIED: + PlayerDiedEventData playerDiedEventData = (PlayerDiedEventData) eventData; + VarInts.writeInt(buffer, playerDiedEventData.getUnknown0()); + VarInts.writeInt(buffer, playerDiedEventData.getUnknown1()); + VarInts.writeInt(buffer, playerDiedEventData.getEntityDamageCause()); + buffer.writeBoolean(playerDiedEventData.isInRaid()); + break; + case BOSS_KILLED: + BossKilledEventData bossKilledEventData = (BossKilledEventData) eventData; + VarInts.writeLong(buffer, bossKilledEventData.getBossUniqueEntityId()); + VarInts.writeInt(buffer, bossKilledEventData.getPlayerPartySize()); + VarInts.writeInt(buffer, bossKilledEventData.getLegacyEntityTypeId()); + break; + case AGENT_COMMAND: + AgentCommandEventData agentCommandEventData = (AgentCommandEventData) eventData; + VarInts.writeInt(buffer, agentCommandEventData.getAgentResult()); + VarInts.writeInt(buffer, agentCommandEventData.getDataValue()); + BedrockUtils.writeString(buffer, agentCommandEventData.getCommand()); + BedrockUtils.writeString(buffer, agentCommandEventData.getDataKey()); + BedrockUtils.writeString(buffer, agentCommandEventData.getOutput()); + break; + case AGENT_CREATED: + // No extra data + break; + case PATTERN_REMOVED: + PatternRemovedEventData patternRemovedEventData = (PatternRemovedEventData) eventData; + VarInts.writeInt(buffer, patternRemovedEventData.getItemId()); + VarInts.writeInt(buffer, patternRemovedEventData.getAuxValue()); + VarInts.writeInt(buffer, patternRemovedEventData.getPatternsSize()); + VarInts.writeInt(buffer, patternRemovedEventData.getPatternIndex()); + VarInts.writeInt(buffer, patternRemovedEventData.getPatternColor()); + break; + case SLASH_COMMAND_EXECUTED: + SlashCommandExecutedEventData slashCommandExecutedEventData = (SlashCommandExecutedEventData) eventData; + VarInts.writeInt(buffer, slashCommandExecutedEventData.getSuccessCount()); + List outputMessages = slashCommandExecutedEventData.getOutputMessages(); + VarInts.writeInt(buffer, outputMessages.size()); + BedrockUtils.writeString(buffer, slashCommandExecutedEventData.getCommandName()); + BedrockUtils.writeString(buffer, String.join(";", outputMessages)); + break; + case FISH_BUCKETED: + FishBucketedEventData fishBucketedEventData = (FishBucketedEventData) eventData; + VarInts.writeInt(buffer, fishBucketedEventData.getUnknown0()); + VarInts.writeInt(buffer, fishBucketedEventData.getUnknown1()); + VarInts.writeInt(buffer, fishBucketedEventData.getUnknown2()); + buffer.writeBoolean(fishBucketedEventData.isUnknown3()); + break; + case MOB_BORN: + MobBornEventData mobBornEventData = (MobBornEventData) eventData; + VarInts.writeInt(buffer, mobBornEventData.getLegacyEntityTypeId()); + VarInts.writeInt(buffer, mobBornEventData.getVariant()); + buffer.writeByte(mobBornEventData.getColor()); + break; + case PET_DIED: + PetDiedEventData petDiedEventData = (PetDiedEventData) eventData; + buffer.writeBoolean(petDiedEventData.isUnknown0()); + VarInts.writeLong(buffer, petDiedEventData.getKillerUniqueEntityId()); + VarInts.writeLong(buffer, petDiedEventData.getPetUniqueEntityId()); + VarInts.writeInt(buffer, petDiedEventData.getEntityDamageCause()); + VarInts.writeInt(buffer, petDiedEventData.getUnknown1()); + break; + case CAULDRON_BLOCK_USED: + CauldronBlockUsedEventData cauldronBlockUsedEventData = (CauldronBlockUsedEventData) eventData; + VarInts.writeInt(buffer, cauldronBlockUsedEventData.getBlockInteractionType()); + VarInts.writeInt(buffer, cauldronBlockUsedEventData.getUnknown0()); + break; + case COMPOSTER_BLOCK_USED: + ComposterBlockUsedEventData composterBlockUsedEventData = (ComposterBlockUsedEventData) eventData; + VarInts.writeInt(buffer, composterBlockUsedEventData.getBlockInteractionType()); + VarInts.writeInt(buffer, composterBlockUsedEventData.getUnknown0()); + break; + case BELL_BLOCK_USED: + VarInts.writeInt(buffer, ((BellBlockUsedEventData) eventData).getUnknown0()); + break; + case ENTITY_DEFINITION_TRIGGER: + BedrockUtils.writeString(buffer, ((EntityDefinitionTriggerEventData) eventData).getId()); + break; + case RAID_UPDATE: + RaidUpdateEventData raidUpdateEventData = (RaidUpdateEventData) eventData; + VarInts.writeInt(buffer, raidUpdateEventData.getCurrentWave()); + VarInts.writeInt(buffer, raidUpdateEventData.getTotalWaves()); + buffer.writeBoolean(raidUpdateEventData.isUnknown0()); + break; + case MOVEMENT: + MovementEventData movementEventData = (MovementEventData) eventData; + buffer.writeByte(movementEventData.getMovementType()); + BedrockUtils.writeVector2f(buffer, movementEventData.getRotation()); + BedrockUtils.writeVector3f(buffer, movementEventData.getPosition()); + break; + case MOVEMENT_THRESHOLD: + MovementThresholdEventData movementThresholdEventData = (MovementThresholdEventData) eventData; + buffer.writeFloatLE(movementThresholdEventData.getUnknown0()); + buffer.writeFloatLE(movementThresholdEventData.getUnknown1()); + buffer.writeFloatLE(movementThresholdEventData.getPlayerMovementScoreThreshold()); + buffer.writeFloatLE(movementThresholdEventData.getPlayerMovementDistanceThreshold()); + VarInts.writeInt(buffer, movementThresholdEventData.getPlayerMovementDurationThreshold()); + break; + case EXTRACT_HONEY: + // No extra data + break; + } + } + + @Override + public void deserialize(ByteBuf buffer, EventPacket packet) { + packet.setUniqueEntityId(VarInts.readLong(buffer)); + + int eventId = VarInts.readInt(buffer); + Preconditions.checkElementIndex(eventId, VALUES.length, "EventDataType"); + EventDataType type = VALUES[eventId]; + + packet.setUnknown0(buffer.readByte()); + + EventData data; + + switch (type) { + case ACHIEVEMENT_AWARDED: + data = new AchievementAwardedEventData(VarInts.readInt(buffer)); + break; + case ENTITY_INTERACT: + int interactionType = VarInts.readInt(buffer); + int legacyEntityTypeId = VarInts.readInt(buffer); + int variant = VarInts.readInt(buffer); + int paletteColor = buffer.readUnsignedByte(); + data = new EntityInteractEventData(interactionType, legacyEntityTypeId, variant, paletteColor); + break; + case PORTAL_BUILT: + data = new PortalBuiltEventData(VarInts.readInt(buffer)); + break; + case PORTAL_USED: + int fromDimensionId = VarInts.readInt(buffer); + int toDimensionId = VarInts.readInt(buffer); + data = new PortalUsedEventData(fromDimensionId, toDimensionId); + break; + case MOB_KILLED: + long killerUniqueEntityId = VarInts.readLong(buffer); + long victimUniqueEntityId = VarInts.readLong(buffer); + int entityDamageCause = VarInts.readInt(buffer); + int villagerTradeTier = VarInts.readInt(buffer); + String villagerDisplayName = BedrockUtils.readString(buffer); + data = new MobKilledEventData(killerUniqueEntityId, victimUniqueEntityId, entityDamageCause, + villagerTradeTier, villagerDisplayName); + break; + case CAULDRON_USED: + int potionId = VarInts.readInt(buffer); + int color = VarInts.readInt(buffer); + int fillLevel = VarInts.readInt(buffer); + data = new CauldronUsedEventData(potionId, color, fillLevel); + break; + case PLAYER_DIED: + int unknown0 = VarInts.readInt(buffer); + int unknown1 = VarInts.readInt(buffer); + entityDamageCause = VarInts.readInt(buffer); + boolean inRaid = buffer.readBoolean(); + data = new PlayerDiedEventData(unknown0, unknown1, entityDamageCause, inRaid); + break; + case BOSS_KILLED: + long bossUniqueEntityId = VarInts.readLong(buffer); + int playerPartySize = VarInts.readInt(buffer); + legacyEntityTypeId = VarInts.readInt(buffer); + data = new BossKilledEventData(bossUniqueEntityId, playerPartySize, legacyEntityTypeId); + break; + case AGENT_COMMAND: + int agentResult = VarInts.readInt(buffer); + int dataValue = VarInts.readInt(buffer); + String command = BedrockUtils.readString(buffer); + String dataKey = BedrockUtils.readString(buffer); + String output = BedrockUtils.readString(buffer); + data = new AgentCommandEventData(agentResult, command, dataKey, dataValue, output); + break; + case AGENT_CREATED: + data = AgentCreatedEventData.INSTANCE; + break; + case PATTERN_REMOVED: + int itemId = VarInts.readInt(buffer); + int auxValue = VarInts.readInt(buffer); + int patternsSize = VarInts.readInt(buffer); + int patternIndex = VarInts.readInt(buffer); + int patternColor = VarInts.readInt(buffer); + data = new PatternRemovedEventData(itemId, auxValue, patternsSize, patternIndex, patternColor); + break; + case SLASH_COMMAND_EXECUTED: + int successCount = VarInts.readInt(buffer); + VarInts.readInt(buffer); + String commandName = BedrockUtils.readString(buffer); + List outputMessages = Arrays.asList(BedrockUtils.readString(buffer).split(";")); + data = new SlashCommandExecutedEventData(commandName, successCount, outputMessages); + break; + case FISH_BUCKETED: + unknown0 = VarInts.readInt(buffer); + unknown1 = VarInts.readInt(buffer); + int unknown2 = VarInts.readInt(buffer); + boolean unknown3 = buffer.readBoolean(); + data = new FishBucketedEventData(unknown0, unknown1, unknown2, unknown3); + break; + case MOB_BORN: + legacyEntityTypeId = VarInts.readInt(buffer); + variant = VarInts.readInt(buffer); + color = buffer.readUnsignedByte(); + data = new MobBornEventData(legacyEntityTypeId, variant, color); + break; + case PET_DIED: + boolean unknownBool = buffer.readBoolean(); + killerUniqueEntityId = VarInts.readLong(buffer); + long petUniqueEntityId = VarInts.readLong(buffer); + entityDamageCause = VarInts.readInt(buffer); + unknown1 = VarInts.readInt(buffer); + data = new PetDiedEventData(unknownBool, killerUniqueEntityId, petUniqueEntityId, entityDamageCause, + unknown1); + break; + case CAULDRON_BLOCK_USED: + int blockInterationType = VarInts.readInt(buffer); + unknown0 = VarInts.readInt(buffer); + data = new CauldronBlockUsedEventData(blockInterationType, unknown0); + break; + case COMPOSTER_BLOCK_USED: + blockInterationType = VarInts.readInt(buffer); + unknown0 = VarInts.readInt(buffer); + data = new ComposterBlockUsedEventData(blockInterationType, unknown0); + break; + case BELL_BLOCK_USED: + data = new BellBlockUsedEventData(VarInts.readInt(buffer)); + break; + case ENTITY_DEFINITION_TRIGGER: + String id = BedrockUtils.readString(buffer); + data = new EntityDefinitionTriggerEventData(id); + break; + case RAID_UPDATE: + int currentWave = VarInts.readInt(buffer); + int totalWaves = VarInts.readInt(buffer); + unknownBool = buffer.readBoolean(); + data = new RaidUpdateEventData(currentWave, totalWaves, unknownBool); + break; + case MOVEMENT: + int movementType = buffer.readUnsignedByte(); + Vector2f rotation = BedrockUtils.readVector2f(buffer); + Vector3f position = BedrockUtils.readVector3f(buffer); + data = new MovementEventData(movementType, rotation, position); + break; + case MOVEMENT_THRESHOLD: + float unknownFloat0 = buffer.readFloatLE(); + float unknownFloat1 = buffer.readFloatLE(); + float playerMovementScoreThreshold = buffer.readFloatLE(); + float playerMovementDistanceThreshold = buffer.readFloatLE(); + int playerMovementDurationThreshold = VarInts.readInt(buffer); + data = new MovementThresholdEventData(unknownFloat0, unknownFloat1, playerMovementScoreThreshold, + playerMovementDistanceThreshold, playerMovementDurationThreshold); + break; + case EXTRACT_HONEY: + data = ExtractHoneyEventData.INSTANCE; + break; + default: + throw new IllegalArgumentException("Unknown EventDataType"); + } + packet.setEventData(data); + } +} +