Merge remote-tracking branch 'origin/master' into feature/math-2.0

This commit is contained in:
Camotoy 2023-04-06 00:31:51 -04:00
commit 8008081eed
135 changed files with 886 additions and 1143 deletions

View file

@ -4,7 +4,7 @@ MCProtocolLib is a simple library for communicating with Minecraft clients and s
## Example Code
See [example/com/github/steveice10/mc/protocol/test/MinecraftProtocolTest.java](https://github.com/GeyserMC/MCProtocolLib/tree/master/example/com/github/steveice10/mc/protocol/test) for sample usage.
See the [example](https://github.com/GeyserMC/MCProtocolLib/tree/master/example/src/main/java/com/github/steveice10/mc/protocol/test) folder for sample usage.
## Adding as a Dependency

View file

@ -90,7 +90,7 @@
<dependency>
<groupId>com.github.steveice10</groupId>
<artifactId>packetlib</artifactId>
<version>3.0</version>
<version>3.0.1</version>
<scope>compile</scope>
</dependency>
<dependency>

View file

@ -2,7 +2,6 @@ package com.github.steveice10.mc.protocol.codec;
import com.github.steveice10.mc.auth.data.GameProfile;
import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer;
import com.github.steveice10.mc.protocol.data.MagicValues;
import com.github.steveice10.mc.protocol.data.game.Identifier;
import com.github.steveice10.mc.protocol.data.game.chunk.BitStorage;
import com.github.steveice10.mc.protocol.data.game.chunk.ChunkSection;
@ -476,7 +475,7 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
}
public PositionSource readPositionSource(ByteBuf buf) {
PositionSourceType type = this.readPositionSourceType(buf);
PositionSourceType type = PositionSourceType.from(this.readResourceLocation(buf));
switch (type) {
case BLOCK:
return new BlockPositionSource(this.readPosition(buf));
@ -488,7 +487,7 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
}
public void writePositionSource(ByteBuf buf, PositionSource positionSource) {
this.writePositionSourceType(buf, positionSource.getType());
this.writeResourceLocation(buf, positionSource.getType().getResourceLocation());
if (positionSource instanceof BlockPositionSource) {
this.writePosition(buf, ((BlockPositionSource) positionSource).getPosition());
} else if (positionSource instanceof EntityPositionSource) {
@ -499,14 +498,6 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
throw new IllegalStateException("Unknown position source type!");
}
public PositionSourceType readPositionSourceType(ByteBuf buf) {
return MagicValues.key(PositionSourceType.class, Identifier.formalize(this.readString(buf)));
}
public void writePositionSourceType(ByteBuf buf, PositionSourceType type) {
this.writeString(buf, MagicValues.value(String.class, type));
}
public VillagerData readVillagerData(ByteBuf buf) {
return new VillagerData(this.readVarInt(buf), this.readVarInt(buf), this.readVarInt(buf));
}

View file

@ -1,599 +0,0 @@
package com.github.steveice10.mc.protocol.data;
import com.github.steveice10.mc.protocol.data.game.BossBarAction;
import com.github.steveice10.mc.protocol.data.game.BossBarColor;
import com.github.steveice10.mc.protocol.data.game.BossBarDivision;
import com.github.steveice10.mc.protocol.data.game.ClientCommand;
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.command.CommandParser;
import com.github.steveice10.mc.protocol.data.game.command.CommandType;
import com.github.steveice10.mc.protocol.data.game.command.properties.StringProperties;
import com.github.steveice10.mc.protocol.data.game.entity.EquipmentSlot;
import com.github.steveice10.mc.protocol.data.game.entity.RotationOrigin;
import com.github.steveice10.mc.protocol.data.game.entity.object.MinecartType;
import com.github.steveice10.mc.protocol.data.game.entity.player.Animation;
import com.github.steveice10.mc.protocol.data.game.entity.player.Hand;
import com.github.steveice10.mc.protocol.data.game.entity.player.HandPreference;
import com.github.steveice10.mc.protocol.data.game.entity.player.InteractAction;
import com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction;
import com.github.steveice10.mc.protocol.data.game.entity.player.PlayerState;
import com.github.steveice10.mc.protocol.data.game.entity.player.PositionElement;
import com.github.steveice10.mc.protocol.data.game.inventory.AdvancementTabAction;
import com.github.steveice10.mc.protocol.data.game.inventory.ClickItemAction;
import com.github.steveice10.mc.protocol.data.game.inventory.ContainerActionType;
import com.github.steveice10.mc.protocol.data.game.inventory.ContainerType;
import com.github.steveice10.mc.protocol.data.game.inventory.CraftingBookStateType;
import com.github.steveice10.mc.protocol.data.game.inventory.CreativeGrabAction;
import com.github.steveice10.mc.protocol.data.game.inventory.DropItemAction;
import com.github.steveice10.mc.protocol.data.game.inventory.FillStackAction;
import com.github.steveice10.mc.protocol.data.game.inventory.MoveToHotbarAction;
import com.github.steveice10.mc.protocol.data.game.inventory.ShiftClickItemAction;
import com.github.steveice10.mc.protocol.data.game.inventory.SpreadItemAction;
import com.github.steveice10.mc.protocol.data.game.inventory.UpdateStructureBlockAction;
import com.github.steveice10.mc.protocol.data.game.inventory.UpdateStructureBlockMode;
import com.github.steveice10.mc.protocol.data.game.inventory.property.AnvilProperty;
import com.github.steveice10.mc.protocol.data.game.inventory.property.BrewingStandProperty;
import com.github.steveice10.mc.protocol.data.game.inventory.property.EnchantmentTableProperty;
import com.github.steveice10.mc.protocol.data.game.inventory.property.FurnaceProperty;
import com.github.steveice10.mc.protocol.data.game.level.block.CommandBlockMode;
import com.github.steveice10.mc.protocol.data.game.level.block.StructureMirror;
import com.github.steveice10.mc.protocol.data.game.level.block.StructureRotation;
import com.github.steveice10.mc.protocol.data.game.level.block.value.ChestValueType;
import com.github.steveice10.mc.protocol.data.game.level.block.value.EndGatewayValueType;
import com.github.steveice10.mc.protocol.data.game.level.block.value.GenericBlockValueType;
import com.github.steveice10.mc.protocol.data.game.level.block.value.MobSpawnerValueType;
import com.github.steveice10.mc.protocol.data.game.level.block.value.NoteBlockValueType;
import com.github.steveice10.mc.protocol.data.game.level.block.value.PistonValue;
import com.github.steveice10.mc.protocol.data.game.level.block.value.PistonValueType;
import com.github.steveice10.mc.protocol.data.game.level.event.ComposterEventData;
import com.github.steveice10.mc.protocol.data.game.level.event.DragonFireballEventData;
import com.github.steveice10.mc.protocol.data.game.level.event.SmokeEventData;
import com.github.steveice10.mc.protocol.data.game.level.map.MapIconType;
import com.github.steveice10.mc.protocol.data.game.level.notify.DemoMessageValue;
import com.github.steveice10.mc.protocol.data.game.level.notify.EnterCreditsValue;
import com.github.steveice10.mc.protocol.data.game.level.notify.GameEvent;
import com.github.steveice10.mc.protocol.data.game.level.notify.RespawnScreenValue;
import com.github.steveice10.mc.protocol.data.game.level.particle.positionsource.PositionSourceType;
import com.github.steveice10.mc.protocol.data.game.recipe.RecipeType;
import com.github.steveice10.mc.protocol.data.game.scoreboard.CollisionRule;
import com.github.steveice10.mc.protocol.data.game.scoreboard.NameTagVisibility;
import com.github.steveice10.mc.protocol.data.game.scoreboard.ObjectiveAction;
import com.github.steveice10.mc.protocol.data.game.scoreboard.ScoreType;
import com.github.steveice10.mc.protocol.data.game.scoreboard.ScoreboardAction;
import com.github.steveice10.mc.protocol.data.game.scoreboard.ScoreboardPosition;
import com.github.steveice10.mc.protocol.data.game.scoreboard.TeamAction;
import com.github.steveice10.mc.protocol.data.game.setting.ChatVisibility;
import com.github.steveice10.mc.protocol.data.game.setting.Difficulty;
import com.github.steveice10.mc.protocol.data.handshake.HandshakeIntent;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class MagicValues {
private static final Map<Object, List<Object>> VALUES = new HashMap<>();
static {
register(HandshakeIntent.STATUS, 1);
register(HandshakeIntent.LOGIN, 2);
register(ClientCommand.RESPAWN, 0);
register(ClientCommand.STATS, 1);
register(ChatVisibility.FULL, 0);
register(ChatVisibility.SYSTEM, 1);
register(ChatVisibility.HIDDEN, 2);
register(PlayerState.START_SNEAKING, 0);
register(PlayerState.STOP_SNEAKING, 1);
register(PlayerState.LEAVE_BED, 2);
register(PlayerState.START_SPRINTING, 3);
register(PlayerState.STOP_SPRINTING, 4);
register(PlayerState.START_HORSE_JUMP, 5);
register(PlayerState.STOP_HORSE_JUMP, 6);
register(PlayerState.OPEN_VEHICLE_INVENTORY, 7);
register(PlayerState.START_ELYTRA_FLYING, 8);
register(InteractAction.INTERACT, 0);
register(InteractAction.ATTACK, 1);
register(InteractAction.INTERACT_AT, 2);
register(PlayerAction.START_DIGGING, 0);
register(PlayerAction.CANCEL_DIGGING, 1);
register(PlayerAction.FINISH_DIGGING, 2);
register(PlayerAction.DROP_ITEM_STACK, 3);
register(PlayerAction.DROP_ITEM, 4);
register(PlayerAction.RELEASE_USE_ITEM, 5);
register(PlayerAction.SWAP_HANDS, 6);
register(ContainerActionType.CLICK_ITEM, 0);
register(ContainerActionType.SHIFT_CLICK_ITEM, 1);
register(ContainerActionType.MOVE_TO_HOTBAR_SLOT, 2);
register(ContainerActionType.CREATIVE_GRAB_MAX_STACK, 3);
register(ContainerActionType.DROP_ITEM, 4);
register(ContainerActionType.SPREAD_ITEM, 5);
register(ContainerActionType.FILL_STACK, 6);
register(ClickItemAction.LEFT_CLICK, 0);
register(ClickItemAction.RIGHT_CLICK, 1);
register(ShiftClickItemAction.LEFT_CLICK, 0);
register(ShiftClickItemAction.RIGHT_CLICK, 1);
register(MoveToHotbarAction.SLOT_1, 0);
register(MoveToHotbarAction.SLOT_2, 1);
register(MoveToHotbarAction.SLOT_3, 2);
register(MoveToHotbarAction.SLOT_4, 3);
register(MoveToHotbarAction.SLOT_5, 4);
register(MoveToHotbarAction.SLOT_6, 5);
register(MoveToHotbarAction.SLOT_7, 6);
register(MoveToHotbarAction.SLOT_8, 7);
register(MoveToHotbarAction.SLOT_9, 8);
register(MoveToHotbarAction.OFF_HAND, 40);
register(CreativeGrabAction.GRAB, 2);
register(DropItemAction.LEFT_CLICK_OUTSIDE_NOT_HOLDING, 0);
register(DropItemAction.RIGHT_CLICK_OUTSIDE_NOT_HOLDING, 1);
register(DropItemAction.DROP_FROM_SELECTED, 2);
register(DropItemAction.DROP_SELECTED_STACK, 3);
register(SpreadItemAction.LEFT_MOUSE_BEGIN_DRAG, 0);
register(SpreadItemAction.LEFT_MOUSE_ADD_SLOT, 1);
register(SpreadItemAction.LEFT_MOUSE_END_DRAG, 2);
register(SpreadItemAction.RIGHT_MOUSE_BEGIN_DRAG, 4);
register(SpreadItemAction.RIGHT_MOUSE_ADD_SLOT, 5);
register(SpreadItemAction.RIGHT_MOUSE_END_DRAG, 6);
register(SpreadItemAction.MIDDLE_MOUSE_BEGIN_DRAG, 8);
register(SpreadItemAction.MIDDLE_MOUSE_ADD_SLOT, 9);
register(SpreadItemAction.MIDDLE_MOUSE_END_DRAG, 10);
register(FillStackAction.FILL, 0);
register(Difficulty.PEACEFUL, 0);
register(Difficulty.EASY, 1);
register(Difficulty.NORMAL, 2);
register(Difficulty.HARD, 3);
register(Animation.SWING_ARM, 0);
register(Animation.DAMAGE, 1);
register(Animation.LEAVE_BED, 2);
register(Animation.SWING_OFFHAND, 3);
register(Animation.CRITICAL_HIT, 4);
register(Animation.ENCHANTMENT_CRITICAL_HIT, 5);
register(PositionElement.X, 0);
register(PositionElement.Y, 1);
register(PositionElement.Z, 2);
register(PositionElement.PITCH, 3);
register(PositionElement.YAW, 4);
register(MinecartType.NORMAL, 0);
register(MinecartType.CHEST, 1);
register(MinecartType.POWERED, 2);
register(MinecartType.TNT, 3);
register(MinecartType.MOB_SPAWNER, 4);
register(MinecartType.HOPPER, 5);
register(MinecartType.COMMAND_BLOCK, 6);
register(ScoreboardPosition.PLAYER_LIST, 0);
register(ScoreboardPosition.SIDEBAR, 1);
register(ScoreboardPosition.BELOW_NAME, 2);
register(ScoreboardPosition.SIDEBAR_TEAM_BLACK, 3);
register(ScoreboardPosition.SIDEBAR_TEAM_DARK_BLUE, 4);
register(ScoreboardPosition.SIDEBAR_TEAM_DARK_GREEN, 5);
register(ScoreboardPosition.SIDEBAR_TEAM_DARK_AQUA, 6);
register(ScoreboardPosition.SIDEBAR_TEAM_DARK_RED, 7);
register(ScoreboardPosition.SIDEBAR_TEAM_DARK_PURPLE, 8);
register(ScoreboardPosition.SIDEBAR_TEAM_GOLD, 9);
register(ScoreboardPosition.SIDEBAR_TEAM_GRAY, 10);
register(ScoreboardPosition.SIDEBAR_TEAM_DARK_GRAY, 11);
register(ScoreboardPosition.SIDEBAR_TEAM_BLUE, 12);
register(ScoreboardPosition.SIDEBAR_TEAM_GREEN, 13);
register(ScoreboardPosition.SIDEBAR_TEAM_AQUA, 14);
register(ScoreboardPosition.SIDEBAR_TEAM_RED, 15);
register(ScoreboardPosition.SIDEBAR_TEAM_LIGHT_PURPLE, 16);
register(ScoreboardPosition.SIDEBAR_TEAM_YELLOW, 17);
register(ScoreboardPosition.SIDEBAR_TEAM_WHITE, 18);
register(ObjectiveAction.ADD, 0);
register(ObjectiveAction.REMOVE, 1);
register(ObjectiveAction.UPDATE, 2);
register(TeamAction.CREATE, 0);
register(TeamAction.REMOVE, 1);
register(TeamAction.UPDATE, 2);
register(TeamAction.ADD_PLAYER, 3);
register(TeamAction.REMOVE_PLAYER, 4);
register(ScoreboardAction.ADD_OR_UPDATE, 0);
register(ScoreboardAction.REMOVE, 1);
register(MapIconType.WHITE_ARROW, 0);
register(MapIconType.GREEN_ARROW, 1);
register(MapIconType.RED_ARROW, 2);
register(MapIconType.BLUE_ARROW, 3);
register(MapIconType.WHITE_CROSS, 4);
register(MapIconType.RED_POINTER, 5);
register(MapIconType.WHITE_CIRCLE, 6);
register(MapIconType.SMALL_WHITE_CIRCLE, 7);
register(MapIconType.MANSION, 8);
register(MapIconType.TEMPLE, 9);
register(MapIconType.WHITE_BANNER, 10);
register(MapIconType.ORANGE_BANNER, 11);
register(MapIconType.MAGENTA_BANNER, 12);
register(MapIconType.LIGHT_BLUE_BANNER, 13);
register(MapIconType.YELLOW_BANNER, 14);
register(MapIconType.LIME_BANNER, 15);
register(MapIconType.PINK_BANNER, 16);
register(MapIconType.GRAY_BANNER, 17);
register(MapIconType.LIGHT_GRAY_BANNER, 18);
register(MapIconType.CYAN_BANNER, 19);
register(MapIconType.PURPLE_BANNER, 20);
register(MapIconType.BLUE_BANNER, 21);
register(MapIconType.BROWN_BANNER, 22);
register(MapIconType.GREEN_BANNER, 23);
register(MapIconType.RED_BANNER, 24);
register(MapIconType.BLACK_BANNER, 25);
register(MapIconType.TREASURE_MARKER, 26);
register(ContainerType.GENERIC_9X1, 0);
register(ContainerType.GENERIC_9X2, 1);
register(ContainerType.GENERIC_9X3, 2);
register(ContainerType.GENERIC_9X4, 3);
register(ContainerType.GENERIC_9X5, 4);
register(ContainerType.GENERIC_9X6, 5);
register(ContainerType.GENERIC_3X3, 6);
register(ContainerType.ANVIL, 7);
register(ContainerType.BEACON, 8);
register(ContainerType.BLAST_FURNACE, 9);
register(ContainerType.BREWING_STAND, 10);
register(ContainerType.CRAFTING, 11);
register(ContainerType.ENCHANTMENT, 12);
register(ContainerType.FURNACE, 13);
register(ContainerType.GRINDSTONE, 14);
register(ContainerType.HOPPER, 15);
register(ContainerType.LECTERN, 16);
register(ContainerType.LOOM, 17);
register(ContainerType.MERCHANT, 18);
register(ContainerType.SHULKER_BOX, 19);
register(ContainerType.SMITHING, 20);
register(ContainerType.SMOKER, 21);
register(ContainerType.CARTOGRAPHY, 22);
register(ContainerType.STONECUTTER, 23);
register(BrewingStandProperty.BREW_TIME, 0);
register(EnchantmentTableProperty.LEVEL_SLOT_1, 0);
register(EnchantmentTableProperty.LEVEL_SLOT_2, 1);
register(EnchantmentTableProperty.LEVEL_SLOT_3, 2);
register(EnchantmentTableProperty.XP_SEED, 3);
register(EnchantmentTableProperty.ENCHANTMENT_SLOT_1, 4);
register(EnchantmentTableProperty.ENCHANTMENT_SLOT_2, 5);
register(EnchantmentTableProperty.ENCHANTMENT_SLOT_3, 6);
register(FurnaceProperty.BURN_TIME, 0);
register(FurnaceProperty.CURRENT_ITEM_BURN_TIME, 1);
register(FurnaceProperty.COOK_TIME, 2);
register(FurnaceProperty.TOTAL_COOK_TIME, 3);
register(AnvilProperty.MAXIMUM_COST, 0);
register(GameEvent.INVALID_BED, 0);
register(GameEvent.STOP_RAIN, 1);
register(GameEvent.START_RAIN, 2);
register(GameEvent.CHANGE_GAMEMODE, 3);
register(GameEvent.ENTER_CREDITS, 4);
register(GameEvent.DEMO_MESSAGE, 5);
register(GameEvent.ARROW_HIT_PLAYER, 6);
register(GameEvent.RAIN_STRENGTH, 7);
register(GameEvent.THUNDER_STRENGTH, 8);
register(GameEvent.PUFFERFISH_STING_SOUND, 9);
register(GameEvent.AFFECTED_BY_ELDER_GUARDIAN, 10);
register(GameEvent.ENABLE_RESPAWN_SCREEN, 11);
register(CommandBlockMode.SEQUENCE, 0);
register(CommandBlockMode.AUTO, 1);
register(CommandBlockMode.REDSTONE, 2);
register(UpdateStructureBlockAction.UPDATE_DATA, 0);
register(UpdateStructureBlockAction.SAVE_STRUCTURE, 1);
register(UpdateStructureBlockAction.LOAD_STRUCTURE, 2);
register(UpdateStructureBlockAction.DETECT_SIZE, 3);
register(UpdateStructureBlockMode.SAVE, 0);
register(UpdateStructureBlockMode.LOAD, 1);
register(UpdateStructureBlockMode.CORNER, 2);
register(UpdateStructureBlockMode.DATA, 3);
register(StructureRotation.NONE, 0);
register(StructureRotation.CLOCKWISE_90, 1);
register(StructureRotation.CLOCKWISE_180, 2);
register(StructureRotation.COUNTERCLOCKWISE_90, 3);
register(StructureMirror.NONE, 0);
register(StructureMirror.LEFT_RIGHT, 1);
register(StructureMirror.FRONT_BACK, 2);
register(DemoMessageValue.WELCOME, 0);
register(DemoMessageValue.MOVEMENT_CONTROLS, 101);
register(DemoMessageValue.JUMP_CONTROL, 102);
register(DemoMessageValue.INVENTORY_CONTROL, 103);
register(EnterCreditsValue.SEEN_BEFORE, 0);
register(EnterCreditsValue.FIRST_TIME, 1);
register(RespawnScreenValue.ENABLE_RESPAWN_SCREEN, 0);
register(RespawnScreenValue.IMMEDIATE_RESPAWN, 1);
register(NoteBlockValueType.HARP, 0);
register(NoteBlockValueType.DOUBLE_BASS, 1);
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(NoteBlockValueType.IRON_XYLOPHONE, 10);
register(NoteBlockValueType.COW_BELL, 11);
register(NoteBlockValueType.DIDGERIDOO, 12);
register(NoteBlockValueType.BIT, 13);
register(NoteBlockValueType.BANJO, 14);
register(NoteBlockValueType.PLING, 15);
register(PistonValueType.PUSHING, 0);
register(PistonValueType.PULLING, 1);
register(PistonValueType.CANCELLED_MID_PUSH, 2);
register(MobSpawnerValueType.RESET_DELAY, 1);
register(ChestValueType.VIEWING_PLAYER_COUNT, 1);
register(EndGatewayValueType.TRIGGER_BEAM, 1);
register(GenericBlockValueType.GENERIC_0, 0);
register(GenericBlockValueType.GENERIC_1, 1);
register(PistonValue.DOWN, 0);
register(PistonValue.UP, 1);
register(PistonValue.NORTH, 2);
register(PistonValue.SOUTH, 3);
register(PistonValue.WEST, 4);
register(PistonValue.EAST, 5);
register(SmokeEventData.DOWN, 0);
register(SmokeEventData.UP, 1);
register(SmokeEventData.NORTH, 2);
register(SmokeEventData.SOUTH, 3);
register(SmokeEventData.WEST, 4);
register(SmokeEventData.EAST, 5);
register(ComposterEventData.FILL, 0);
register(ComposterEventData.FILL_SUCCESS, 1);
register(DragonFireballEventData.NO_SOUND, 0);
register(DragonFireballEventData.HAS_SOUND, 1);
register(NameTagVisibility.ALWAYS, "");
register(NameTagVisibility.ALWAYS, "always");
register(NameTagVisibility.NEVER, "never");
register(NameTagVisibility.HIDE_FOR_OTHER_TEAMS, "hideForOtherTeams");
register(NameTagVisibility.HIDE_FOR_OWN_TEAM, "hideForOwnTeam");
register(CollisionRule.ALWAYS, "");
register(CollisionRule.ALWAYS, "always");
register(CollisionRule.NEVER, "never");
register(CollisionRule.PUSH_OTHER_TEAMS, "pushOtherTeams");
register(CollisionRule.PUSH_OWN_TEAM, "pushOwnTeam");
register(ScoreType.INTEGER, 0);
register(ScoreType.HEARTS, 1);
register(Advancement.DisplayData.FrameType.TASK, 0);
register(Advancement.DisplayData.FrameType.CHALLENGE, 1);
register(Advancement.DisplayData.FrameType.GOAL, 2);
register(UnlockRecipesAction.INIT, 0);
register(UnlockRecipesAction.ADD, 1);
register(UnlockRecipesAction.REMOVE, 2);
register(CraftingBookStateType.CRAFTING, 0);
register(CraftingBookStateType.FURNACE, 1);
register(CraftingBookStateType.BLAST_FURNACE, 2);
register(CraftingBookStateType.SMOKER, 3);
register(AdvancementTabAction.OPENED_TAB, 0);
register(AdvancementTabAction.CLOSED_SCREEN, 1);
register(ResourcePackStatus.SUCCESSFULLY_LOADED, 0);
register(ResourcePackStatus.DECLINED, 1);
register(ResourcePackStatus.FAILED_DOWNLOAD, 2);
register(ResourcePackStatus.ACCEPTED, 3);
register(Hand.MAIN_HAND, 0);
register(Hand.OFF_HAND, 1);
register(HandPreference.LEFT_HAND, 0);
register(HandPreference.RIGHT_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);
register(BossBarDivision.NONE, 0);
register(BossBarDivision.NOTCHES_6, 1);
register(BossBarDivision.NOTCHES_10, 2);
register(BossBarDivision.NOTCHES_12, 3);
register(BossBarDivision.NOTCHES_20, 4);
register(EquipmentSlot.MAIN_HAND, 0);
register(EquipmentSlot.OFF_HAND, 1);
register(EquipmentSlot.BOOTS, 2);
register(EquipmentSlot.LEGGINGS, 3);
register(EquipmentSlot.CHESTPLATE, 4);
register(EquipmentSlot.HELMET, 5);
register(RotationOrigin.FEET, 0);
register(RotationOrigin.EYES, 1);
register(RecipeType.CRAFTING_SHAPELESS, "minecraft:crafting_shapeless");
register(RecipeType.CRAFTING_SHAPED, "minecraft:crafting_shaped");
register(RecipeType.CRAFTING_SPECIAL_ARMORDYE, "minecraft:crafting_special_armordye");
register(RecipeType.CRAFTING_SPECIAL_BOOKCLONING, "minecraft:crafting_special_bookcloning");
register(RecipeType.CRAFTING_SPECIAL_MAPCLONING, "minecraft:crafting_special_mapcloning");
register(RecipeType.CRAFTING_SPECIAL_MAPEXTENDING, "minecraft:crafting_special_mapextending");
register(RecipeType.CRAFTING_SPECIAL_FIREWORK_ROCKET, "minecraft:crafting_special_firework_rocket");
register(RecipeType.CRAFTING_SPECIAL_FIREWORK_STAR, "minecraft:crafting_special_firework_star");
register(RecipeType.CRAFTING_SPECIAL_FIREWORK_STAR_FADE, "minecraft:crafting_special_firework_star_fade");
register(RecipeType.CRAFTING_SPECIAL_REPAIRITEM, "minecraft:crafting_special_repairitem");
register(RecipeType.CRAFTING_SPECIAL_TIPPEDARROW, "minecraft:crafting_special_tippedarrow");
register(RecipeType.CRAFTING_SPECIAL_BANNERDUPLICATE, "minecraft:crafting_special_bannerduplicate");
register(RecipeType.CRAFTING_SPECIAL_SHIELDDECORATION, "minecraft:crafting_special_shielddecoration");
register(RecipeType.CRAFTING_SPECIAL_SHULKERBOXCOLORING, "minecraft:crafting_special_shulkerboxcoloring");
register(RecipeType.CRAFTING_SPECIAL_SUSPICIOUSSTEW, "minecraft:crafting_special_suspiciousstew");
register(RecipeType.SMELTING, "minecraft:smelting");
register(RecipeType.BLASTING, "minecraft:blasting");
register(RecipeType.SMOKING, "minecraft:smoking");
register(RecipeType.CAMPFIRE_COOKING, "minecraft:campfire_cooking");
register(RecipeType.STONECUTTING, "minecraft:stonecutting");
register(RecipeType.SMITHING, "minecraft:smithing");
register(CommandType.ROOT, 0);
register(CommandType.LITERAL, 1);
register(CommandType.ARGUMENT, 2);
register(CommandParser.BOOL, 0);
register(CommandParser.FLOAT, 1);
register(CommandParser.DOUBLE, 2);
register(CommandParser.INTEGER, 3);
register(CommandParser.LONG, 4);
register(CommandParser.STRING, 5);
register(CommandParser.ENTITY, 6);
register(CommandParser.GAME_PROFILE, 7);
register(CommandParser.BLOCK_POS, 8);
register(CommandParser.COLUMN_POS, 9);
register(CommandParser.VEC3, 10);
register(CommandParser.VEC2, 11);
register(CommandParser.BLOCK_STATE, 12);
register(CommandParser.BLOCK_PREDICATE, 13);
register(CommandParser.ITEM_STACK, 14);
register(CommandParser.ITEM_PREDICATE, 15);
register(CommandParser.COLOR, 16);
register(CommandParser.COMPONENT, 17);
register(CommandParser.MESSAGE, 18);
register(CommandParser.NBT_COMPOUND_TAG, 19);
register(CommandParser.NBT_TAG, 20);
register(CommandParser.NBT_PATH, 21);
register(CommandParser.OBJECTIVE, 22);
register(CommandParser.OBJECTIVE_CRITERIA, 23);
register(CommandParser.OPERATION, 24);
register(CommandParser.PARTICLE, 25);
register(CommandParser.ANGLE, 26);
register(CommandParser.ROTATION, 27);
register(CommandParser.SCOREBOARD_SLOT, 28);
register(CommandParser.SCORE_HOLDER, 29);
register(CommandParser.SWIZZLE, 30);
register(CommandParser.TEAM, 31);
register(CommandParser.ITEM_SLOT, 32);
register(CommandParser.RESOURCE_LOCATION, 33);
register(CommandParser.FUNCTION, 34);
register(CommandParser.ENTITY_ANCHOR, 35);
register(CommandParser.INT_RANGE, 36);
register(CommandParser.FLOAT_RANGE, 37);
register(CommandParser.DIMENSION, 38);
register(CommandParser.GAMEMODE, 39);
register(CommandParser.TIME, 40);
register(CommandParser.RESOURCE_OR_TAG, 41);
register(CommandParser.RESOURCE_OR_TAG_KEY, 42);
register(CommandParser.RESOURCE, 43);
register(CommandParser.RESOURCE_KEY, 44);
register(CommandParser.TEMPLATE_MIRROR, 45);
register(CommandParser.TEMPLATE_ROTATION, 46);
register(CommandParser.UUID, 47);
register(StringProperties.SINGLE_WORD, 0);
register(StringProperties.QUOTABLE_PHRASE, 1);
register(StringProperties.GREEDY_PHRASE, 2);
register(PositionSourceType.BLOCK, "minecraft:block");
register(PositionSourceType.ENTITY, "minecraft:entity");
}
private MagicValues() {
}
private static void register(Enum<?> key, Object value) {
VALUES.computeIfAbsent(key, k -> new ArrayList<>()).add(value);
}
@SuppressWarnings("unchecked")
public static <T> T key(Class<T> keyType, Object value) {
for (Map.Entry<Object, List<Object>> entry : VALUES.entrySet()) {
if (keyType.isAssignableFrom(entry.getKey().getClass())) {
for (Object val : entry.getValue()) {
if (val == value || val.equals(value)) {
return (T) entry.getKey();
} else if (Number.class.isAssignableFrom(val.getClass()) && Number.class.isAssignableFrom(value.getClass())) {
Number num = (Number) val;
Number num2 = (Number) value;
if (num.doubleValue() == num2.doubleValue()) {
return (T) entry.getKey();
}
} else if (String.class.isAssignableFrom(val.getClass()) && String.class.isAssignableFrom(value.getClass())) {
String str = (String) val;
String str2 = (String) value;
if (str.equalsIgnoreCase(str2)) {
return (T) entry.getKey();
}
}
}
}
}
throw new UnmappedValueException(value, keyType);
}
@SuppressWarnings("unchecked")
public static <T> T value(Class<T> valueType, Object key) {
List<Object> values = VALUES.get(key);
if (values != null) {
for (Object val : values) {
if (valueType.isAssignableFrom(val.getClass())) {
return (T) val;
} else if (Number.class.isAssignableFrom(val.getClass())) {
if (valueType == Byte.class) {
return (T) (Object) ((Number) val).byteValue();
} else if (valueType == Short.class) {
return (T) (Object) ((Number) val).shortValue();
} else if (valueType == Integer.class) {
return (T) (Object) ((Number) val).intValue();
} else if (valueType == Long.class) {
return (T) (Object) ((Number) val).longValue();
} else if (valueType == Float.class) {
return (T) (Object) ((Number) val).floatValue();
} else if (valueType == Double.class) {
return (T) (Object) ((Number) val).doubleValue();
}
}
}
}
throw new UnmappedKeyException(key, valueType);
}
}

View file

@ -7,4 +7,10 @@ public enum BossBarAction {
UPDATE_TITLE,
UPDATE_STYLE,
UPDATE_FLAGS;
private static final BossBarAction[] VALUES = values();
public static BossBarAction from(int id) {
return VALUES[id];
}
}

View file

@ -8,4 +8,10 @@ public enum BossBarColor {
YELLOW,
PURPLE,
WHITE;
private static final BossBarColor[] VALUES = values();
public static BossBarColor from(int id) {
return VALUES[id];
}
}

View file

@ -6,4 +6,10 @@ public enum BossBarDivision {
NOTCHES_10,
NOTCHES_12,
NOTCHES_20;
private static final BossBarDivision[] VALUES = values();
public static BossBarDivision from(int id) {
return VALUES[id];
}
}

View file

@ -3,4 +3,10 @@ package com.github.steveice10.mc.protocol.data.game;
public enum ClientCommand {
RESPAWN,
STATS;
private static final ClientCommand[] VALUES = values();
public static ClientCommand from(int id) {
return VALUES[id];
}
}

View file

@ -5,4 +5,10 @@ public enum ResourcePackStatus {
DECLINED,
FAILED_DOWNLOAD,
ACCEPTED;
private static final ResourcePackStatus[] VALUES = values();
public static ResourcePackStatus from(int id) {
return VALUES[id];
}
}

View file

@ -4,4 +4,10 @@ public enum UnlockRecipesAction {
INIT,
ADD,
REMOVE;
private static final UnlockRecipesAction[] VALUES = values();
public static UnlockRecipesAction from(int id) {
return VALUES[id];
}
}

View file

@ -51,6 +51,12 @@ public class Advancement {
TASK,
CHALLENGE,
GOAL;
private static final FrameType[] VALUES = values();
public static FrameType from(int id) {
return VALUES[id];
}
}
}
}

View file

@ -1,5 +1,7 @@
package com.github.steveice10.mc.protocol.data.game.chat;
import com.github.steveice10.mc.protocol.data.game.Identifier;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
@ -16,23 +18,22 @@ public enum BuiltinChatType {
private final String resourceLocation;
BuiltinChatType() {
this.resourceLocation = "minecraft:" + name().toLowerCase(Locale.ROOT);
this.resourceLocation = Identifier.formalize(name().toLowerCase(Locale.ROOT));
}
public String getResourceLocation() {
return resourceLocation;
}
private static final Map<String, BuiltinChatType> BY_RESOURCE_LOCATION;
static {
BuiltinChatType[] values = values();
BY_RESOURCE_LOCATION = new HashMap<>(values.length);
for (BuiltinChatType type : values) {
BY_RESOURCE_LOCATION.put(type.getResourceLocation(), type);
}
}
private static final Map<String, BuiltinChatType> VALUES = new HashMap<>();
public static BuiltinChatType from(String resourceLocation) {
return BY_RESOURCE_LOCATION.get(resourceLocation);
return VALUES.get(resourceLocation);
}
static {
for (BuiltinChatType type : values()) {
VALUES.put(type.getResourceLocation(), type);
}
}
}

View file

@ -1,5 +1,7 @@
package com.github.steveice10.mc.protocol.data.game.chat;
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
import io.netty.buffer.ByteBuf;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.jetbrains.annotations.Nullable;
@ -9,4 +11,16 @@ import org.jetbrains.annotations.Nullable;
public class MessageSignature {
private final int id;
private final byte @Nullable[] messageSignature;
public static MessageSignature read(ByteBuf in, MinecraftCodecHelper helper) {
int id = helper.readVarInt(in) - 1;
byte[] messageSignature;
if (id == -1) {
messageSignature = new byte[256];
in.readBytes(messageSignature);
} else {
messageSignature = null;
}
return new MessageSignature(id, messageSignature);
}
}

View file

@ -49,4 +49,10 @@ public enum CommandParser {
TEMPLATE_MIRROR,
TEMPLATE_ROTATION,
UUID;
private static final CommandParser[] VALUES = values();
public static CommandParser from(int id) {
return VALUES[id];
}
}

View file

@ -4,4 +4,10 @@ public enum CommandType {
ROOT,
LITERAL,
ARGUMENT;
private static final CommandType[] VALUES = values();
public static CommandType from(int id) {
return VALUES[id];
}
}

View file

@ -26,7 +26,7 @@ public enum SuggestionType {
private static final Map<String, SuggestionType> VALUES = new HashMap<>();
@NotNull
public static SuggestionType byResourceLocation(String resourceLocation) {
public static SuggestionType from(String resourceLocation) {
// Vanilla behavior as of 1.19.3
// 1.16.5 still has AVAILABLE_BIOMES and vanilla doesn't care
return VALUES.getOrDefault(resourceLocation, ASK_SERVER);

View file

@ -4,4 +4,10 @@ public enum StringProperties implements CommandProperties {
SINGLE_WORD,
QUOTABLE_PHRASE,
GREEDY_PHRASE;
public static final StringProperties[] VALUES = values();
public static StringProperties from(int id) {
return VALUES[id];
}
}

View file

@ -7,4 +7,10 @@ public enum EquipmentSlot {
LEGGINGS,
CHESTPLATE,
HELMET;
private static final EquipmentSlot[] VALUES = values();
public static EquipmentSlot from(int id) {
return VALUES[id];
}
}

View file

@ -3,4 +3,10 @@ package com.github.steveice10.mc.protocol.data.game.entity;
public enum RotationOrigin {
FEET,
EYES;
private static final RotationOrigin[] VALUES = values();
public static RotationOrigin from(int id) {
return VALUES[id];
}
}

View file

@ -8,4 +8,10 @@ public enum MinecartType implements ObjectData {
MOB_SPAWNER,
HOPPER,
COMMAND_BLOCK;
private static final MinecartType[] VALUES = values();
public static MinecartType from(int id) {
return VALUES[id];
}
}

View file

@ -7,4 +7,10 @@ public enum Animation {
SWING_OFFHAND,
CRITICAL_HIT,
ENCHANTMENT_CRITICAL_HIT;
private static final Animation[] VALUES = values();
public static Animation from(int id) {
return VALUES[id];
}
}

View file

@ -12,12 +12,14 @@ public enum GameMode implements GameEventValue {
private static final GameMode[] VALUES = values();
public static GameMode byId(int id) {
return VALUES[id];
// Yes, the way this is read is intentional. Don't remove it. As of 1.19.3.
// If the BY_ID field still exists in the vanilla sources, don't remove this.
return id >= 0 && id < VALUES.length ? VALUES[id] : VALUES[0];
}
@Nullable
public static GameMode byNullableId(int id) {
return id == -1 ? null : VALUES[id];
return id == -1 ? null : byId(id);
}
public static int toNullableId(@Nullable GameMode gameMode) {

View file

@ -3,4 +3,10 @@ package com.github.steveice10.mc.protocol.data.game.entity.player;
public enum Hand {
MAIN_HAND,
OFF_HAND;
private static final Hand[] VALUES = values();
public static Hand from(int id) {
return VALUES[id];
}
}

View file

@ -3,4 +3,10 @@ package com.github.steveice10.mc.protocol.data.game.entity.player;
public enum HandPreference {
LEFT_HAND,
RIGHT_HAND;
private static final HandPreference[] VALUES = values();
public static HandPreference from(int id) {
return VALUES[id];
}
}

View file

@ -4,4 +4,10 @@ public enum InteractAction {
INTERACT,
ATTACK,
INTERACT_AT;
private static final InteractAction[] VALUES = values();
public static InteractAction from(int id) {
return VALUES[id];
}
}

View file

@ -8,4 +8,10 @@ public enum PlayerAction {
DROP_ITEM,
RELEASE_USE_ITEM,
SWAP_HANDS;
private static final PlayerAction[] VALUES = values();
public static PlayerAction from(int id) {
return VALUES[id];
}
}

View file

@ -10,4 +10,10 @@ public enum PlayerState {
STOP_HORSE_JUMP,
OPEN_VEHICLE_INVENTORY,
START_ELYTRA_FLYING;
private static final PlayerState[] VALUES = values();
public static PlayerState from(int id) {
return VALUES[id];
}
}

View file

@ -6,4 +6,10 @@ public enum PositionElement {
Z,
PITCH,
YAW;
private static final PositionElement[] VALUES = values();
public static PositionElement from(int id) {
return VALUES[id];
}
}

View file

@ -3,4 +3,10 @@ package com.github.steveice10.mc.protocol.data.game.inventory;
public enum AdvancementTabAction {
OPENED_TAB,
CLOSED_SCREEN;
private static final AdvancementTabAction[] VALUES = values();
public static AdvancementTabAction from(int id) {
return VALUES[id];
}
}

View file

@ -3,4 +3,14 @@ package com.github.steveice10.mc.protocol.data.game.inventory;
public enum ClickItemAction implements ContainerAction {
LEFT_CLICK,
RIGHT_CLICK;
public int getId() {
return this.ordinal();
}
private static final ClickItemAction[] VALUES = values();
public static ClickItemAction from(int id) {
return VALUES[id];
}
}

View file

@ -1,4 +1,5 @@
package com.github.steveice10.mc.protocol.data.game.inventory;
public interface ContainerAction {
int getId();
}

View file

@ -8,4 +8,10 @@ public enum ContainerActionType {
DROP_ITEM,
SPREAD_ITEM,
FILL_STACK;
private static final ContainerActionType[] VALUES = values();
public static ContainerActionType from(int id) {
return VALUES[id];
}
}

View file

@ -25,4 +25,10 @@ public enum ContainerType {
SMOKER,
CARTOGRAPHY,
STONECUTTER;
private static final ContainerType[] VALUES = values();
public static ContainerType from(int id) {
return VALUES[id];
}
}

View file

@ -4,5 +4,11 @@ public enum CraftingBookStateType {
CRAFTING,
FURNACE,
BLAST_FURNACE,
SMOKER
SMOKER;
private static final CraftingBookStateType[] VALUES = values();
public static CraftingBookStateType from(int id) {
return VALUES[id];
}
}

View file

@ -2,4 +2,14 @@ package com.github.steveice10.mc.protocol.data.game.inventory;
public enum CreativeGrabAction implements ContainerAction {
GRAB;
public int getId() {
return this.ordinal() + 2;
}
private static final CreativeGrabAction[] VALUES = values();
public static CreativeGrabAction from(int id) {
return VALUES[id - 2];
}
}

View file

@ -5,4 +5,14 @@ public enum DropItemAction implements ContainerAction {
DROP_SELECTED_STACK,
LEFT_CLICK_OUTSIDE_NOT_HOLDING,
RIGHT_CLICK_OUTSIDE_NOT_HOLDING;
public int getId() {
return this.ordinal();
}
private static final DropItemAction[] VALUES = values();
public static DropItemAction from(int id) {
return VALUES[id];
}
}

View file

@ -2,4 +2,14 @@ package com.github.steveice10.mc.protocol.data.game.inventory;
public enum FillStackAction implements ContainerAction {
FILL;
public int getId() {
return this.ordinal();
}
private static final FillStackAction[] VALUES = values();
public static FillStackAction from(int id) {
return VALUES[id];
}
}

View file

@ -1,14 +1,39 @@
package com.github.steveice10.mc.protocol.data.game.inventory;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
public enum MoveToHotbarAction implements ContainerAction {
SLOT_1,
SLOT_2,
SLOT_3,
SLOT_4,
SLOT_5,
SLOT_6,
SLOT_7,
SLOT_8,
SLOT_9,
OFF_HAND;
SLOT_1(0),
SLOT_2(1),
SLOT_3(2),
SLOT_4(3),
SLOT_5(4),
SLOT_6(5),
SLOT_7(6),
SLOT_8(7),
SLOT_9(8),
OFF_HAND(40);
private final int id;
MoveToHotbarAction(int id) {
this.id = id;
}
public int getId() {
return id;
}
private static Int2ObjectMap<MoveToHotbarAction> VALUES = new Int2ObjectOpenHashMap<>();
public static MoveToHotbarAction from(int id) {
return VALUES.get(id);
}
static {
for (MoveToHotbarAction action : values()) {
VALUES.putIfAbsent(action.id, action);
}
}
}

View file

@ -3,4 +3,14 @@ package com.github.steveice10.mc.protocol.data.game.inventory;
public enum ShiftClickItemAction implements ContainerAction {
LEFT_CLICK,
RIGHT_CLICK;
public int getId() {
return this.ordinal();
}
private static final ShiftClickItemAction[] VALUES = values();
public static ShiftClickItemAction from(int id) {
return VALUES[id];
}
}

View file

@ -1,13 +1,38 @@
package com.github.steveice10.mc.protocol.data.game.inventory;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
public enum SpreadItemAction implements ContainerAction {
LEFT_MOUSE_BEGIN_DRAG,
LEFT_MOUSE_ADD_SLOT,
LEFT_MOUSE_END_DRAG,
RIGHT_MOUSE_BEGIN_DRAG,
RIGHT_MOUSE_ADD_SLOT,
RIGHT_MOUSE_END_DRAG,
MIDDLE_MOUSE_BEGIN_DRAG,
MIDDLE_MOUSE_ADD_SLOT,
MIDDLE_MOUSE_END_DRAG;
LEFT_MOUSE_BEGIN_DRAG(0),
LEFT_MOUSE_ADD_SLOT(1),
LEFT_MOUSE_END_DRAG(2),
RIGHT_MOUSE_BEGIN_DRAG(4),
RIGHT_MOUSE_ADD_SLOT(5),
RIGHT_MOUSE_END_DRAG(6),
MIDDLE_MOUSE_BEGIN_DRAG(8),
MIDDLE_MOUSE_ADD_SLOT(9),
MIDDLE_MOUSE_END_DRAG(10);
private final int id;
SpreadItemAction(int id) {
this.id = id;
}
public int getId() {
return id;
}
private static Int2ObjectMap<SpreadItemAction> VALUES = new Int2ObjectOpenHashMap<>();
public static SpreadItemAction from(int id) {
return VALUES.get(id);
}
static {
for (SpreadItemAction action : values()) {
VALUES.put(action.id, action);
}
}
}

View file

@ -5,4 +5,10 @@ public enum UpdateStructureBlockAction {
SAVE_STRUCTURE,
LOAD_STRUCTURE,
DETECT_SIZE;
private static final UpdateStructureBlockAction[] VALUES = values();
public static UpdateStructureBlockAction from(int id) {
return VALUES[id];
}
}

View file

@ -5,4 +5,10 @@ public enum UpdateStructureBlockMode {
LOAD,
CORNER,
DATA;
private static final UpdateStructureBlockMode[] VALUES = values();
public static UpdateStructureBlockMode from(int id) {
return VALUES[id];
}
}

View file

@ -3,9 +3,15 @@ package com.github.steveice10.mc.protocol.data.game.inventory.property;
/**
* Container properties of an anvil.
*/
public enum AnvilProperty {
public enum AnvilProperty implements ContainerProperty {
/**
* The maximum cost of renaming or repairing in the anvil.
*/
MAXIMUM_COST,
MAXIMUM_COST;
private static final AnvilProperty[] VALUES = values();
public static AnvilProperty from(int id) {
return VALUES[id];
}
}

View file

@ -8,5 +8,11 @@ public enum BrewingStandProperty implements ContainerProperty {
* Time remaining for potions to finish brewing.
* Usually a value between 0 (done) and 400 (just started).
*/
BREW_TIME,
BREW_TIME;
private static final BrewingStandProperty[] VALUES = values();
public static BrewingStandProperty from(int id) {
return VALUES[id];
}
}

View file

@ -1,4 +1,5 @@
package com.github.steveice10.mc.protocol.data.game.inventory.property;
public interface ContainerProperty {
int ordinal();
}

View file

@ -45,6 +45,12 @@ public enum EnchantmentTableProperty implements ContainerProperty {
*/
ENCHANTMENT_SLOT_3;
private static final EnchantmentTableProperty[] VALUES = values();
public static EnchantmentTableProperty from(int id) {
return VALUES[id];
}
/**
* Packs enchantment type and level into one integer as used for the ENCHANTMENT_SLOT_X properties.
*

View file

@ -3,7 +3,7 @@ package com.github.steveice10.mc.protocol.data.game.inventory.property;
/**
* Container properties of a furnace.
*/
public enum FurnaceProperty {
public enum FurnaceProperty implements ContainerProperty {
/**
* Number of ticks left before the current fuel runs out.
*/
@ -22,5 +22,11 @@ public enum FurnaceProperty {
/**
* Number of ticks that the current item needs to be smelted.
*/
TOTAL_COOK_TIME,
TOTAL_COOK_TIME;
private static final FurnaceProperty[] VALUES = values();
public static FurnaceProperty from(int id) {
return VALUES[id];
}
}

View file

@ -4,4 +4,10 @@ public enum CommandBlockMode {
SEQUENCE,
AUTO,
REDSTONE;
private static final CommandBlockMode[] VALUES = values();
public static CommandBlockMode from(int id) {
return VALUES[id];
}
}

View file

@ -4,4 +4,10 @@ public enum StructureMirror {
NONE,
LEFT_RIGHT,
FRONT_BACK;
private static final StructureMirror[] VALUES = values();
public static StructureMirror from(int id) {
return VALUES[id];
}
}

View file

@ -5,4 +5,10 @@ public enum StructureRotation {
CLOCKWISE_90,
CLOCKWISE_180,
COUNTERCLOCKWISE_90;
private static final StructureRotation[] VALUES = values();
public static StructureRotation from(int id) {
return VALUES[id];
}
}

View file

@ -0,0 +1,11 @@
package com.github.steveice10.mc.protocol.data.game.level.block.value;
import com.github.steveice10.mc.protocol.data.game.entity.object.Direction;
import lombok.AllArgsConstructor;
import lombok.Data;
@Data
@AllArgsConstructor
public class BellValue implements BlockValue {
private final Direction direction;
}

View file

@ -0,0 +1,13 @@
package com.github.steveice10.mc.protocol.data.game.level.block.value;
import com.github.steveice10.mc.protocol.data.UnmappedValueException;
public enum BellValueType implements BlockValueType {
SHAKE_DIRECTION;
private static final BellValueType[] VALUES = values();
public static BellValueType from(int id) {
return VALUES[id];
}
}

View file

@ -2,4 +2,10 @@ package com.github.steveice10.mc.protocol.data.game.level.block.value;
public enum ChestValueType implements BlockValueType {
VIEWING_PLAYER_COUNT;
private static final ChestValueType[] VALUES = values();
public static ChestValueType from(int id) {
return VALUES[id];
}
}

View file

@ -2,4 +2,10 @@ package com.github.steveice10.mc.protocol.data.game.level.block.value;
public enum EndGatewayValueType implements BlockValueType {
TRIGGER_BEAM;
private static final EndGatewayValueType[] VALUES = values();
public static EndGatewayValueType from(int id) {
return VALUES[id];
}
}

View file

@ -3,4 +3,10 @@ package com.github.steveice10.mc.protocol.data.game.level.block.value;
public enum GenericBlockValueType implements BlockValueType {
GENERIC_0,
GENERIC_1;
private static final GenericBlockValueType[] VALUES = values();
public static GenericBlockValueType from(int id) {
return VALUES[id];
}
}

View file

@ -2,4 +2,10 @@ package com.github.steveice10.mc.protocol.data.game.level.block.value;
public enum MobSpawnerValueType implements BlockValueType {
RESET_DELAY;
private static final MobSpawnerValueType[] VALUES = values();
public static MobSpawnerValueType from(int id) {
return VALUES[id];
}
}

View file

@ -1,16 +0,0 @@
package com.github.steveice10.mc.protocol.data.game.level.block.value;
import lombok.Data;
@Data
public class NoteBlockValue implements BlockValue {
private final int pitch;
public NoteBlockValue(int pitch) {
if (pitch < 0 || pitch > 24) {
throw new IllegalArgumentException("Pitch must be between 0 and 24.");
}
this.pitch = pitch;
}
}

View file

@ -1,20 +0,0 @@
package com.github.steveice10.mc.protocol.data.game.level.block.value;
public enum NoteBlockValueType implements BlockValueType {
HARP,
DOUBLE_BASS,
SNARE_DRUM,
HI_HAT,
BASS_DRUM,
FLUTE,
BELL,
GUITAR,
CHIME,
XYLOPHONE,
IRON_XYLOPHONE,
COW_BELL,
DIDGERIDOO,
BIT,
BANJO,
PLING;
}

View file

@ -1,10 +1,11 @@
package com.github.steveice10.mc.protocol.data.game.level.block.value;
public enum PistonValue implements BlockValue {
DOWN,
UP,
NORTH,
SOUTH,
WEST,
EAST
import com.github.steveice10.mc.protocol.data.game.entity.object.Direction;
import lombok.AllArgsConstructor;
import lombok.Data;
@Data
@AllArgsConstructor
public class PistonValue implements BlockValue {
private final Direction direction;
}

View file

@ -4,4 +4,10 @@ public enum PistonValueType implements BlockValueType {
PUSHING,
PULLING,
CANCELLED_MID_PUSH;
private static final PistonValueType[] VALUES = values();
public static PistonValueType from(int id) {
return VALUES[id];
}
}

View file

@ -3,4 +3,10 @@ package com.github.steveice10.mc.protocol.data.game.level.event;
public enum ComposterEventData implements LevelEventData {
FILL,
FILL_SUCCESS;
private static final ComposterEventData[] VALUES = values();
public static ComposterEventData from(int id) {
return VALUES[id];
}
}

View file

@ -3,4 +3,10 @@ package com.github.steveice10.mc.protocol.data.game.level.event;
public enum DragonFireballEventData implements LevelEventData {
NO_SOUND,
HAS_SOUND;
private static final DragonFireballEventData[] VALUES = values();
public static DragonFireballEventData from(int id) {
return VALUES[id];
}
}

View file

@ -0,0 +1,11 @@
package com.github.steveice10.mc.protocol.data.game.level.event;
import com.github.steveice10.mc.protocol.data.game.entity.object.Direction;
import lombok.AllArgsConstructor;
import lombok.Data;
@Data
@AllArgsConstructor
public class ElectricSparkData implements LevelEventData {
private final Direction direction;
}

View file

@ -0,0 +1,12 @@
package com.github.steveice10.mc.protocol.data.game.level.event;
public enum FireExtinguishData implements LevelEventData {
EXTINGUISH,
GENERIC_EXTINGUISH;
private static final FireExtinguishData[] VALUES = values();
public static FireExtinguishData from(int id) {
return VALUES[id];
}
}

View file

@ -1,10 +1,11 @@
package com.github.steveice10.mc.protocol.data.game.level.event;
public enum SmokeEventData implements LevelEventData {
DOWN,
UP,
NORTH,
SOUTH,
WEST,
EAST;
import com.github.steveice10.mc.protocol.data.game.entity.object.Direction;
import lombok.AllArgsConstructor;
import lombok.Data;
@Data
@AllArgsConstructor
public class SmokeEventData implements LevelEventData {
private final Direction direction;
}

View file

@ -28,4 +28,10 @@ public enum MapIconType {
RED_BANNER,
BLACK_BANNER,
TREASURE_MARKER;
private static final MapIconType[] VALUES = values();
public static MapIconType from(int id) {
return VALUES[id];
}
}

View file

@ -1,8 +1,34 @@
package com.github.steveice10.mc.protocol.data.game.level.notify;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
public enum DemoMessageValue implements GameEventValue {
WELCOME,
MOVEMENT_CONTROLS,
JUMP_CONTROL,
INVENTORY_CONTROL;
WELCOME(0),
MOVEMENT_CONTROLS(101),
JUMP_CONTROL(102),
INVENTORY_CONTROL(103),
SCREENSHOT_CONTROL(104);
private final int id;
DemoMessageValue(int id) {
this.id = id;
}
public int getId() {
return this.id;
}
private static Int2ObjectMap<DemoMessageValue> VALUES = new Int2ObjectOpenHashMap<>();
public static DemoMessageValue from(int id) {
return VALUES.get(id);
}
static {
for (DemoMessageValue value : values()) {
VALUES.put(value.id, value);
}
}
}

View file

@ -3,4 +3,10 @@ package com.github.steveice10.mc.protocol.data.game.level.notify;
public enum EnterCreditsValue implements GameEventValue {
SEEN_BEFORE,
FIRST_TIME;
private static final EnterCreditsValue[] VALUES = values();
public static EnterCreditsValue from(int id) {
return VALUES[id];
}
}

View file

@ -13,4 +13,10 @@ public enum GameEvent {
PUFFERFISH_STING_SOUND,
AFFECTED_BY_ELDER_GUARDIAN,
ENABLE_RESPAWN_SCREEN;
private static final GameEvent[] VALUES = values();
public static GameEvent from(int id) {
return VALUES[id];
}
}

View file

@ -1,7 +1,12 @@
package com.github.steveice10.mc.protocol.data.game.level.notify;
public enum RespawnScreenValue implements GameEventValue {
ENABLE_RESPAWN_SCREEN,
IMMEDIATE_RESPAWN;
private static final RespawnScreenValue[] VALUES = values();
public static RespawnScreenValue from(int id) {
return VALUES[id];
}
}

View file

@ -1,6 +1,34 @@
package com.github.steveice10.mc.protocol.data.game.level.particle.positionsource;
import com.github.steveice10.mc.protocol.data.game.Identifier;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
public enum PositionSourceType {
BLOCK,
ENTITY;
private final String resourceLocation;
PositionSourceType() {
this.resourceLocation = Identifier.formalize(name().toLowerCase(Locale.ROOT));
}
public String getResourceLocation() {
return resourceLocation;
}
private static final Map<String, PositionSourceType> VALUES = new HashMap<>();
public static PositionSourceType from(String resourceLocation) {
return VALUES.get(resourceLocation);
}
static {
for (PositionSourceType value : values()) {
VALUES.put(value.resourceLocation, value);
}
}
}

View file

@ -1,5 +1,11 @@
package com.github.steveice10.mc.protocol.data.game.recipe;
import com.github.steveice10.mc.protocol.data.game.Identifier;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
public enum RecipeType {
CRAFTING_SHAPED,
CRAFTING_SHAPELESS,
@ -21,5 +27,27 @@ public enum RecipeType {
SMOKING,
CAMPFIRE_COOKING,
STONECUTTING,
SMITHING
SMITHING;
private final String resourceLocation;
RecipeType() {
this.resourceLocation = Identifier.formalize(name().toLowerCase(Locale.ROOT));
}
public String getResourceLocation() {
return resourceLocation;
}
private static final Map<String, RecipeType> VALUES = new HashMap<>();
public static RecipeType from(String resourceLocation) {
return VALUES.get(resourceLocation);
}
static {
for (RecipeType type : values()) {
VALUES.put(type.resourceLocation, type);
}
}
}

View file

@ -1,8 +1,33 @@
package com.github.steveice10.mc.protocol.data.game.scoreboard;
import java.util.HashMap;
import java.util.Map;
public enum CollisionRule {
ALWAYS,
NEVER,
PUSH_OTHER_TEAMS,
PUSH_OWN_TEAM;
ALWAYS("always"),
NEVER("never"),
PUSH_OTHER_TEAMS("pushOtherTeams"),
PUSH_OWN_TEAM("pushOwnTeam");
private final String name;
CollisionRule(String name) {
this.name = name;
}
public String getName() {
return this.name;
}
private static final Map<String, CollisionRule> VALUES = new HashMap<>();
public static CollisionRule from(String name) {
return VALUES.get(name);
}
static {
for (CollisionRule rule : values()) {
VALUES.put(rule.getName(), rule);
}
}
}

View file

@ -1,8 +1,33 @@
package com.github.steveice10.mc.protocol.data.game.scoreboard;
import java.util.HashMap;
import java.util.Map;
public enum NameTagVisibility {
ALWAYS,
NEVER,
HIDE_FOR_OTHER_TEAMS,
HIDE_FOR_OWN_TEAM;
ALWAYS("always"),
NEVER("never"),
HIDE_FOR_OTHER_TEAMS("hideForOtherTeams"),
HIDE_FOR_OWN_TEAM("hideForOwnTeam");
private final String name;
NameTagVisibility(String name) {
this.name = name;
}
public String getName() {
return this.name;
}
private static final Map<String, NameTagVisibility> VALUES = new HashMap<>();
public static NameTagVisibility from(String name) {
return VALUES.get(name);
}
static {
for (NameTagVisibility option : values()) {
VALUES.put(option.name(), option);
}
}
}

View file

@ -4,4 +4,10 @@ public enum ObjectiveAction {
ADD,
REMOVE,
UPDATE;
private static final ObjectiveAction[] VALUES = values();
public static ObjectiveAction from(int id) {
return VALUES[id];
}
}

View file

@ -3,4 +3,10 @@ package com.github.steveice10.mc.protocol.data.game.scoreboard;
public enum ScoreType {
INTEGER,
HEARTS;
private static final ScoreType[] VALUES = values();
public static ScoreType from(int id) {
return VALUES[id];
}
}

View file

@ -3,4 +3,10 @@ package com.github.steveice10.mc.protocol.data.game.scoreboard;
public enum ScoreboardAction {
ADD_OR_UPDATE,
REMOVE;
private static final ScoreboardAction[] VALUES = values();
public static ScoreboardAction from(int id) {
return VALUES[id];
}
}

View file

@ -21,4 +21,10 @@ public enum ScoreboardPosition {
SIDEBAR_TEAM_LIGHT_PURPLE,
SIDEBAR_TEAM_YELLOW,
SIDEBAR_TEAM_WHITE;
private static final ScoreboardPosition[] VALUES = values();
public static ScoreboardPosition from(int id) {
return VALUES[id];
}
}

View file

@ -6,4 +6,10 @@ public enum TeamAction {
UPDATE,
ADD_PLAYER,
REMOVE_PLAYER;
private static final TeamAction[] VALUES = values();
public static TeamAction from(int id) {
return VALUES[id];
}
}

View file

@ -4,4 +4,10 @@ public enum ChatVisibility {
FULL,
SYSTEM,
HIDDEN;
private static final ChatVisibility[] VALUES = values();
public static ChatVisibility from(int id) {
return VALUES[id];
}
}

View file

@ -5,4 +5,10 @@ public enum Difficulty {
EASY,
NORMAL,
HARD;
private static final Difficulty[] VALUES = values();
public static Difficulty from(int id) {
return VALUES[id];
}
}

View file

@ -3,4 +3,10 @@ package com.github.steveice10.mc.protocol.data.handshake;
public enum HandshakeIntent {
STATUS,
LOGIN;
private static final HandshakeIntent[] VALUES = values();
public static HandshakeIntent from(int id) {
return VALUES[id];
}
}

View file

@ -2,7 +2,6 @@ package com.github.steveice10.mc.protocol.packet.handshake.serverbound;
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
import com.github.steveice10.mc.protocol.data.MagicValues;
import com.github.steveice10.mc.protocol.data.handshake.HandshakeIntent;
import io.netty.buffer.ByteBuf;
import lombok.AllArgsConstructor;
@ -25,7 +24,7 @@ public class ClientIntentionPacket implements MinecraftPacket {
this.protocolVersion = helper.readVarInt(in);
this.hostname = helper.readString(in);
this.port = in.readUnsignedShort();
this.intent = MagicValues.key(HandshakeIntent.class, helper.readVarInt(in));
this.intent = HandshakeIntent.from(helper.readVarInt(in) - 1);
}
@Override
@ -33,7 +32,7 @@ public class ClientIntentionPacket implements MinecraftPacket {
helper.writeVarInt(out, this.protocolVersion);
helper.writeString(out, this.hostname);
out.writeShort(this.port);
helper.writeVarInt(out, MagicValues.value(Integer.class, this.intent));
helper.writeVarInt(out, this.intent.ordinal() + 1);
}
@Override

View file

@ -3,7 +3,6 @@ package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer;
import com.github.steveice10.mc.protocol.data.MagicValues;
import com.github.steveice10.mc.protocol.data.game.BossBarAction;
import com.github.steveice10.mc.protocol.data.game.BossBarColor;
import com.github.steveice10.mc.protocol.data.game.BossBarDivision;
@ -68,7 +67,7 @@ public class ClientboundBossEventPacket implements MinecraftPacket {
public ClientboundBossEventPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
this.uuid = helper.readUUID(in);
this.action = MagicValues.key(BossBarAction.class, helper.readVarInt(in));
this.action = BossBarAction.from(helper.readVarInt(in));
if (this.action == BossBarAction.ADD || this.action == BossBarAction.UPDATE_TITLE) {
this.title = helper.readComponent(in);
@ -83,8 +82,8 @@ public class ClientboundBossEventPacket implements MinecraftPacket {
}
if (this.action == BossBarAction.ADD || this.action == BossBarAction.UPDATE_STYLE) {
this.color = MagicValues.key(BossBarColor.class, helper.readVarInt(in));
this.division = MagicValues.key(BossBarDivision.class, helper.readVarInt(in));
this.color = BossBarColor.from(helper.readVarInt(in));
this.division = BossBarDivision.from(helper.readVarInt(in));
} else {
this.color = null;
this.division = null;
@ -105,10 +104,10 @@ public class ClientboundBossEventPacket implements MinecraftPacket {
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
helper.writeUUID(out, this.uuid);
helper.writeVarInt(out, MagicValues.value(Integer.class, this.action));
helper.writeVarInt(out, this.action.ordinal());
if (this.action == BossBarAction.ADD || this.action == BossBarAction.UPDATE_TITLE) {
helper.writeString(out, DefaultComponentSerializer.get().serialize(this.title));
helper.writeComponent(out, this.title);
}
if (this.action == BossBarAction.ADD || this.action == BossBarAction.UPDATE_HEALTH) {
@ -116,8 +115,8 @@ public class ClientboundBossEventPacket implements MinecraftPacket {
}
if (this.action == BossBarAction.ADD || this.action == BossBarAction.UPDATE_STYLE) {
helper.writeVarInt(out, MagicValues.value(Integer.class, this.color));
helper.writeVarInt(out, MagicValues.value(Integer.class, this.division));
helper.writeVarInt(out, this.color.ordinal());
helper.writeVarInt(out, this.division.ordinal());
}
if (this.action == BossBarAction.ADD || this.action == BossBarAction.UPDATE_FLAGS) {

View file

@ -2,7 +2,6 @@ package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
import com.github.steveice10.mc.protocol.data.MagicValues;
import com.github.steveice10.mc.protocol.data.game.setting.Difficulty;
import io.netty.buffer.ByteBuf;
import lombok.AllArgsConstructor;
@ -20,13 +19,13 @@ public class ClientboundChangeDifficultyPacket implements MinecraftPacket {
private final boolean difficultyLocked;
public ClientboundChangeDifficultyPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
this.difficulty = MagicValues.key(Difficulty.class, in.readUnsignedByte());
this.difficulty = Difficulty.from(in.readUnsignedByte());
this.difficultyLocked = in.readBoolean();
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
out.writeByte(MagicValues.value(Integer.class, this.difficulty));
out.writeByte(this.difficulty.ordinal());
out.writeBoolean(this.difficultyLocked);
}
}

View file

@ -58,7 +58,7 @@ public class ClientboundCommandSuggestionsPacket implements MinecraftPacket {
Component tooltip = this.tooltips[index];
if (tooltip != null) {
out.writeBoolean(true);
helper.writeString(out, DefaultComponentSerializer.get().serialize(tooltip));
helper.writeComponent(out, tooltip);
} else {
out.writeBoolean(false);
}

View file

@ -2,7 +2,6 @@ package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
import com.github.steveice10.mc.protocol.data.MagicValues;
import com.github.steveice10.mc.protocol.data.game.command.CommandNode;
import com.github.steveice10.mc.protocol.data.game.command.CommandParser;
import com.github.steveice10.mc.protocol.data.game.command.CommandType;
@ -35,7 +34,7 @@ public class ClientboundCommandsPacket implements MinecraftPacket {
this.nodes = new CommandNode[helper.readVarInt(in)];
for (int i = 0; i < this.nodes.length; i++) {
byte flags = in.readByte();
CommandType type = MagicValues.key(CommandType.class, flags & FLAG_TYPE_MASK);
CommandType type = CommandType.from(flags & FLAG_TYPE_MASK);
boolean executable = (flags & FLAG_EXECUTABLE) != 0;
int[] children = new int[helper.readVarInt(in)];
@ -43,7 +42,7 @@ public class ClientboundCommandsPacket implements MinecraftPacket {
children[j] = helper.readVarInt(in);
}
int redirectIndex = -1;
int redirectIndex = 0;
if ((flags & FLAG_REDIRECT) != 0) {
redirectIndex = helper.readVarInt(in);
}
@ -55,8 +54,9 @@ public class ClientboundCommandsPacket implements MinecraftPacket {
CommandParser parser = null;
CommandProperties properties = null;
String suggestionType = null;
if (type == CommandType.ARGUMENT) {
parser = MagicValues.key(CommandParser.class, helper.readVarInt(in));
parser = CommandParser.from(helper.readVarInt(in));
switch (parser) {
case DOUBLE: {
byte numberFlags = in.readByte();
@ -119,7 +119,7 @@ public class ClientboundCommandsPacket implements MinecraftPacket {
break;
}
case STRING:
properties = MagicValues.key(StringProperties.class, helper.readVarInt(in));
properties = StringProperties.from(helper.readVarInt(in));
break;
case ENTITY: {
byte entityFlags = in.readByte();
@ -139,11 +139,10 @@ public class ClientboundCommandsPacket implements MinecraftPacket {
default:
break;
}
}
String suggestionType = null;
if ((flags & FLAG_SUGGESTION_TYPE) != 0) {
suggestionType = helper.readResourceLocation(in);
if ((flags & FLAG_SUGGESTION_TYPE) != 0) {
suggestionType = helper.readResourceLocation(in);
}
}
this.nodes[i] = new CommandNode(type, executable, children, redirectIndex, name, parser, properties, suggestionType);
@ -156,12 +155,12 @@ public class ClientboundCommandsPacket implements MinecraftPacket {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
helper.writeVarInt(out, this.nodes.length);
for (CommandNode node : this.nodes) {
int flags = MagicValues.value(Integer.class, node.getType()) & FLAG_TYPE_MASK;
int flags = node.getType().ordinal() & FLAG_TYPE_MASK;
if (node.isExecutable()) {
flags |= FLAG_EXECUTABLE;
}
if (node.getRedirectIndex() != -1) {
if (node.getRedirectIndex() != 0) {
flags |= FLAG_REDIRECT;
}
@ -176,7 +175,7 @@ public class ClientboundCommandsPacket implements MinecraftPacket {
helper.writeVarInt(out, childIndex);
}
if (node.getRedirectIndex() != -1) {
if (node.getRedirectIndex() != 0) {
helper.writeVarInt(out, node.getRedirectIndex());
}
@ -185,7 +184,7 @@ public class ClientboundCommandsPacket implements MinecraftPacket {
}
if (node.getType() == CommandType.ARGUMENT) {
helper.writeVarInt(out, MagicValues.value(Integer.class, node.getParser()));
helper.writeVarInt(out, node.getParser().ordinal());
switch (node.getParser()) {
case DOUBLE: {
DoubleProperties properties = (DoubleProperties) node.getProperties();
@ -280,7 +279,7 @@ public class ClientboundCommandsPacket implements MinecraftPacket {
break;
}
case STRING:
helper.writeVarInt(out, MagicValues.value(Integer.class, node.getProperties()));
helper.writeVarInt(out, ((StringProperties) node.getProperties()).ordinal());
break;
case ENTITY: {
EntityProperties properties = (EntityProperties) node.getProperties();
@ -306,10 +305,10 @@ public class ClientboundCommandsPacket implements MinecraftPacket {
default:
break;
}
}
if (node.getSuggestionType() != null) {
helper.writeResourceLocation(out, node.getSuggestionType());
if (node.getSuggestionType() != null) {
helper.writeResourceLocation(out, node.getSuggestionType());
}
}
}

View file

@ -16,13 +16,12 @@ import java.io.IOException;
public class ClientboundDeleteChatPacket implements MinecraftPacket {
private final MessageSignature messageSignature;
public ClientboundDeleteChatPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
int id = helper.readVarInt(in) - 1;
this.messageSignature = new MessageSignature(id, id == -1 ? in.readBytes(new byte[256]).array() : null);
public ClientboundDeleteChatPacket(ByteBuf in, MinecraftCodecHelper helper) {
this.messageSignature = MessageSignature.read(in, helper);
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
helper.writeVarInt(out, this.messageSignature.getId() + 1);
if (this.messageSignature.getMessageSignature() != null) {
out.writeBytes(messageSignature.getMessageSignature());

View file

@ -2,7 +2,6 @@ package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
import com.github.steveice10.mc.protocol.data.MagicValues;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.GlobalPos;
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;

View file

@ -41,7 +41,8 @@ public class ClientboundPlayerChatPacket implements MinecraftPacket {
this.sender = helper.readUUID(in);
this.index = helper.readVarInt(in);
if (in.readBoolean()) {
this.messageSignature = in.readBytes(new byte[256]).array();
this.messageSignature = new byte[256];
in.readBytes(this.messageSignature);
} else {
this.messageSignature = null;
}
@ -53,9 +54,7 @@ public class ClientboundPlayerChatPacket implements MinecraftPacket {
this.lastSeenMessages = new ArrayList<>();
int seenMessageCount = Math.min(helper.readVarInt(in), 20);
for (int i = 0; i < seenMessageCount; i++) {
int id = helper.readVarInt(in) - 1;
byte[] messageSignature = id == -1 ? in.readBytes(new byte[256]).array() : null;
this.lastSeenMessages.add(new MessageSignature(id, messageSignature));
this.lastSeenMessages.add(MessageSignature.read(in, helper));
}
this.unsignedContent = helper.readNullable(in, helper::readComponent);
@ -66,7 +65,7 @@ public class ClientboundPlayerChatPacket implements MinecraftPacket {
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
helper.writeUUID(out, this.sender);
helper.writeVarInt(out, this.index);
out.writeBoolean(this.messageSignature != null);

View file

@ -3,7 +3,6 @@ package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
import com.github.steveice10.mc.auth.data.GameProfile;
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
import com.github.steveice10.mc.protocol.data.MagicValues;
import com.github.steveice10.mc.protocol.data.game.PlayerListEntry;
import com.github.steveice10.mc.protocol.data.game.PlayerListEntryAction;
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;

View file

@ -2,7 +2,6 @@ package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
import com.github.steveice10.mc.protocol.data.MagicValues;
import com.github.steveice10.mc.protocol.data.game.UnlockRecipesAction;
import io.netty.buffer.ByteBuf;
import lombok.*;
@ -73,7 +72,7 @@ public class ClientboundRecipePacket implements MinecraftPacket {
}
public ClientboundRecipePacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
this.action = MagicValues.key(UnlockRecipesAction.class, helper.readVarInt(in));
this.action = UnlockRecipesAction.from(helper.readVarInt(in));
this.openCraftingBook = in.readBoolean();
this.activateCraftingFiltering = in.readBoolean();
@ -101,7 +100,7 @@ public class ClientboundRecipePacket implements MinecraftPacket {
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
helper.writeVarInt(out, MagicValues.value(Integer.class, this.action));
helper.writeVarInt(out, this.action.ordinal());
out.writeBoolean(this.openCraftingBook);
out.writeBoolean(this.activateCraftingFiltering);

View file

@ -2,7 +2,6 @@ package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
import com.github.steveice10.mc.protocol.data.MagicValues;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.GlobalPos;
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
import io.netty.buffer.ByteBuf;

View file

@ -40,7 +40,7 @@ public class ClientboundServerDataPacket implements MinecraftPacket {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
out.writeBoolean(this.motd != null);
if (this.motd != null) {
helper.writeString(out, DefaultComponentSerializer.get().serialize(this.motd));
helper.writeComponent(out, this.motd);
}
out.writeBoolean(this.iconBase64 != null);

View file

@ -25,7 +25,7 @@ public class ClientboundSystemChatPacket implements MinecraftPacket {
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
helper.writeString(out, DefaultComponentSerializer.get().serialize(this.content));
helper.writeComponent(out, this.content);
out.writeBoolean(this.overlay);
}
}

View file

@ -3,7 +3,6 @@ package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer;
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;
@ -59,7 +58,7 @@ public class ClientboundUpdateAdvancementsPacket implements MinecraftPacket {
Component title = helper.readComponent(in);
Component description = helper.readComponent(in);
ItemStack icon = helper.readItemStack(in);
FrameType frameType = MagicValues.key(FrameType.class, helper.readVarInt(in));
FrameType frameType = FrameType.from(helper.readVarInt(in));
int flags = in.readInt();
boolean hasBackgroundTexture = (flags & FLAG_HAS_BACKGROUND_TEXTURE) != 0;
@ -133,10 +132,10 @@ public class ClientboundUpdateAdvancementsPacket implements MinecraftPacket {
DisplayData displayData = advancement.getDisplayData();
if (displayData != null) {
out.writeBoolean(true);
helper.writeString(out, DefaultComponentSerializer.get().serialize(displayData.getTitle()));
helper.writeString(out, DefaultComponentSerializer.get().serialize(displayData.getDescription()));
helper.writeComponent(out, displayData.getTitle());
helper.writeComponent(out, displayData.getDescription());
helper.writeItemStack(out, displayData.getIcon());
helper.writeVarInt(out, MagicValues.value(Integer.class, displayData.getFrameType()));
helper.writeVarInt(out, displayData.getFrameType().ordinal());
String backgroundTexture = displayData.getBackgroundTexture();
int flags = 0;

View file

@ -2,7 +2,6 @@ package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
import com.github.steveice10.mc.protocol.data.MagicValues;
import com.github.steveice10.mc.protocol.data.game.Identifier;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
import com.github.steveice10.mc.protocol.data.game.recipe.CraftingBookCategory;
@ -27,8 +26,8 @@ public class ClientboundUpdateRecipesPacket implements MinecraftPacket {
public ClientboundUpdateRecipesPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
this.recipes = new Recipe[helper.readVarInt(in)];
for (int i = 0; i < this.recipes.length; i++) {
RecipeType type = MagicValues.key(RecipeType.class, Identifier.formalize(helper.readString(in)));
String identifier = helper.readString(in);
RecipeType type = RecipeType.from(helper.readResourceLocation(in));
String identifier = helper.readResourceLocation(in);
RecipeData data;
switch (type) {
case CRAFTING_SHAPELESS: {
@ -105,8 +104,8 @@ public class ClientboundUpdateRecipesPacket implements MinecraftPacket {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
helper.writeVarInt(out, this.recipes.length);
for (Recipe recipe : this.recipes) {
helper.writeString(out, MagicValues.value(String.class, recipe.getType()));
helper.writeString(out, recipe.getIdentifier());
helper.writeResourceLocation(out, recipe.getType().getResourceLocation());
helper.writeResourceLocation(out, recipe.getIdentifier());
switch (recipe.getType()) {
case CRAFTING_SHAPELESS: {
ShapelessRecipeData data = (ShapelessRecipeData) recipe.getData();

View file

@ -2,7 +2,6 @@ package com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity;
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
import com.github.steveice10.mc.protocol.data.MagicValues;
import com.github.steveice10.mc.protocol.data.game.entity.player.Animation;
import io.netty.buffer.ByteBuf;
import lombok.AllArgsConstructor;
@ -21,12 +20,12 @@ public class ClientboundAnimatePacket implements MinecraftPacket {
public ClientboundAnimatePacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
this.entityId = helper.readVarInt(in);
this.animation = MagicValues.key(Animation.class, in.readUnsignedByte());
this.animation = Animation.from(in.readUnsignedByte());
}
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
helper.writeVarInt(out, this.entityId);
out.writeByte(MagicValues.value(Integer.class, this.animation));
out.writeByte(this.animation.ordinal());
}
}

View file

@ -2,7 +2,6 @@ package com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity;
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
import com.github.steveice10.mc.protocol.data.MagicValues;
import com.github.steveice10.mc.protocol.data.game.entity.EquipmentSlot;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Equipment;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
@ -29,7 +28,7 @@ public class ClientboundSetEquipmentPacket implements MinecraftPacket {
List<Equipment> list = new ArrayList<>();
while (hasNextEntry) {
int rawSlot = in.readByte();
EquipmentSlot slot = MagicValues.key(EquipmentSlot.class, ((byte) rawSlot) & 127);
EquipmentSlot slot = EquipmentSlot.from(((byte) rawSlot) & 127);
ItemStack item = helper.readItemStack(in);
list.add(new Equipment(slot, item));
hasNextEntry = (rawSlot & 128) == 128;
@ -41,7 +40,7 @@ public class ClientboundSetEquipmentPacket implements MinecraftPacket {
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
helper.writeVarInt(out, this.entityId);
for (int i = 0; i < this.equipment.length; i++) {
int rawSlot = MagicValues.value(Integer.class, this.equipment[i].getSlot());
int rawSlot = this.equipment[i].getSlot().ordinal();
if (i != equipment.length - 1) {
rawSlot = rawSlot | 128;
}

View file

@ -2,7 +2,6 @@ package com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.playe
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
import com.github.steveice10.mc.protocol.data.MagicValues;
import com.github.steveice10.mc.protocol.data.game.entity.RotationOrigin;
import io.netty.buffer.ByteBuf;
import lombok.AllArgsConstructor;
@ -29,14 +28,14 @@ public class ClientboundPlayerLookAtPacket implements MinecraftPacket {
}
public ClientboundPlayerLookAtPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
this.origin = MagicValues.key(RotationOrigin.class, helper.readVarInt(in));
this.origin = RotationOrigin.from(helper.readVarInt(in));
this.x = in.readDouble();
this.y = in.readDouble();
this.z = in.readDouble();
if (in.readBoolean()) {
this.targetEntityId = helper.readVarInt(in);
this.targetEntityOrigin = MagicValues.key(RotationOrigin.class, helper.readVarInt(in));
this.targetEntityOrigin = RotationOrigin.from(helper.readVarInt(in));
} else {
this.targetEntityId = 0;
this.targetEntityOrigin = null;
@ -45,7 +44,7 @@ public class ClientboundPlayerLookAtPacket implements MinecraftPacket {
@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
helper.writeVarInt(out, MagicValues.value(Integer.class, this.origin));
helper.writeVarInt(out, this.origin.ordinal());
out.writeDouble(this.x);
out.writeDouble(this.y);
out.writeDouble(this.z);
@ -53,7 +52,7 @@ public class ClientboundPlayerLookAtPacket implements MinecraftPacket {
if (this.targetEntityOrigin != null) {
out.writeBoolean(true);
helper.writeVarInt(out, this.targetEntityId);
helper.writeVarInt(out, MagicValues.value(Integer.class, this.targetEntityOrigin));
helper.writeVarInt(out, this.origin.ordinal());
} else {
out.writeBoolean(false);
}

Some files were not shown because too many files have changed in this diff Show more