Search in sources :

Example 1 with ServerboundPlayerCommandPacket

use of net.minecraft.network.protocol.game.ServerboundPlayerCommandPacket in project SpongeCommon by SpongePowered.

the class PacketPhase method setupPacketToStateMapping.

private void setupPacketToStateMapping() {
    this.packetTranslationMap.put(ServerboundKeepAlivePacket.class, packet -> PacketPhase.General.IGNORED);
    this.packetTranslationMap.put(ServerboundChatPacket.class, packet -> PacketPhase.General.CHAT_COMMAND);
    this.packetTranslationMap.put(ServerboundInteractPacket.class, packet -> {
        final ServerboundInteractPacket useEntityPacket = (ServerboundInteractPacket) packet;
        final ServerboundInteractPacket.Action action = useEntityPacket.getAction();
        if (action == ServerboundInteractPacket.Action.INTERACT) {
            return PacketPhase.General.INTERACT_ENTITY;
        } else if (action == ServerboundInteractPacket.Action.ATTACK) {
            return PacketPhase.General.ATTACK_ENTITY;
        } else if (action == ServerboundInteractPacket.Action.INTERACT_AT) {
            return PacketPhase.General.INTERACT_AT_ENTITY;
        } else {
            return PacketPhase.General.INVALID;
        }
    });
    this.packetTranslationMap.put(ServerboundMovePlayerPacket.class, packet -> PacketPhase.General.MOVEMENT);
    this.packetTranslationMap.put(ServerboundMovePlayerPacket.Pos.class, packet -> PacketPhase.General.MOVEMENT);
    this.packetTranslationMap.put(ServerboundMovePlayerPacket.Rot.class, packet -> PacketPhase.General.MOVEMENT);
    this.packetTranslationMap.put(ServerboundMovePlayerPacket.PosRot.class, packet -> PacketPhase.General.MOVEMENT);
    this.packetTranslationMap.put(ServerboundPlayerActionPacket.class, packet -> {
        final ServerboundPlayerActionPacket playerDigging = (ServerboundPlayerActionPacket) packet;
        final ServerboundPlayerActionPacket.Action action = playerDigging.getAction();
        final IPhaseState<? extends PacketContext<?>> state = PacketPhase.INTERACTION_ACTION_MAPPINGS.get(action);
        return state == null ? PacketPhase.General.UNKNOWN : state;
    });
    this.packetTranslationMap.put(ServerboundUseItemOnPacket.class, packet -> {
        // Note that CPacketPlayerTryUseItem is swapped with CPacketPlayerBlockPlacement
        final ServerboundUseItemOnPacket blockPlace = (ServerboundUseItemOnPacket) packet;
        final BlockPos blockPos = blockPlace.getHitResult().getBlockPos();
        final Direction front = blockPlace.getHitResult().getDirection();
        final MinecraftServer server = SpongeCommon.server();
        if (blockPos.getY() < server.getMaxBuildHeight() - 1 || front != Direction.UP && blockPos.getY() < server.getMaxBuildHeight()) {
            return PacketPhase.General.PLACE_BLOCK;
        }
        return PacketPhase.General.INVALID;
    });
    this.packetTranslationMap.put(ServerboundUseItemPacket.class, packet -> PacketPhase.General.USE_ITEM);
    this.packetTranslationMap.put(ServerboundSetCarriedItemPacket.class, packet -> PacketPhase.Inventory.SET_CARRIED_ITEM);
    this.packetTranslationMap.put(ServerboundSwingPacket.class, packet -> PacketPhase.General.ANIMATION);
    this.packetTranslationMap.put(ServerboundPlayerCommandPacket.class, packet -> {
        final ServerboundPlayerCommandPacket playerAction = (ServerboundPlayerCommandPacket) packet;
        final ServerboundPlayerCommandPacket.Action action = playerAction.getAction();
        return PacketPhase.PLAYER_ACTION_MAPPINGS.get(action);
    });
    this.packetTranslationMap.put(ServerboundPlayerInputPacket.class, packet -> PacketPhase.General.HANDLED_EXTERNALLY);
    this.packetTranslationMap.put(ServerboundContainerClosePacket.class, packet -> PacketPhase.General.CLOSE_WINDOW);
    this.packetTranslationMap.put(ServerboundContainerClickPacket.class, packet -> PacketPhase.fromWindowPacket((ServerboundContainerClickPacket) packet));
    this.packetTranslationMap.put(ServerboundContainerAckPacket.class, packet -> PacketPhase.General.UNKNOWN);
    this.packetTranslationMap.put(ServerboundSetCreativeModeSlotPacket.class, packet -> PacketPhase.General.CREATIVE_INVENTORY);
    this.packetTranslationMap.put(ServerboundContainerButtonClickPacket.class, packet -> PacketPhase.Inventory.ENCHANT_ITEM);
    this.packetTranslationMap.put(ServerboundSignUpdatePacket.class, packet -> PacketPhase.General.UPDATE_SIGN);
    this.packetTranslationMap.put(ServerboundPlayerAbilitiesPacket.class, packet -> PacketPhase.General.IGNORED);
    this.packetTranslationMap.put(ServerboundCommandSuggestionPacket.class, packet -> PacketPhase.General.TAB_COMPLETE);
    this.packetTranslationMap.put(ServerboundClientCommandPacket.class, packet -> {
        final ServerboundClientCommandPacket clientStatus = (ServerboundClientCommandPacket) packet;
        final ServerboundClientCommandPacket.Action status = clientStatus.getAction();
        if (status == ServerboundClientCommandPacket.Action.PERFORM_RESPAWN) {
            return PacketPhase.General.REQUEST_RESPAWN;
        }
        return PacketPhase.General.IGNORED;
    });
    this.packetTranslationMap.put(ServerboundCustomPayloadPacket.class, packet -> PacketPhase.General.HANDLED_EXTERNALLY);
    this.packetTranslationMap.put(ServerboundTeleportToEntityPacket.class, packet -> PacketPhase.General.IGNORED);
    this.packetTranslationMap.put(ServerboundResourcePackPacket.class, packet -> PacketPhase.General.RESOURCE_PACK);
    this.packetTranslationMap.put(ServerboundPlaceRecipePacket.class, packet -> PacketPhase.Inventory.PLACE_RECIPE);
}
Also used : Direction(net.minecraft.core.Direction) MinecraftServer(net.minecraft.server.MinecraftServer) ServerboundClientCommandPacket(net.minecraft.network.protocol.game.ServerboundClientCommandPacket) ServerboundUseItemOnPacket(net.minecraft.network.protocol.game.ServerboundUseItemOnPacket) ServerboundPlayerActionPacket(net.minecraft.network.protocol.game.ServerboundPlayerActionPacket) ServerboundMovePlayerPacket(net.minecraft.network.protocol.game.ServerboundMovePlayerPacket) BlockPos(net.minecraft.core.BlockPos) ServerboundInteractPacket(net.minecraft.network.protocol.game.ServerboundInteractPacket) ServerboundPlayerCommandPacket(net.minecraft.network.protocol.game.ServerboundPlayerCommandPacket) ServerboundContainerClickPacket(net.minecraft.network.protocol.game.ServerboundContainerClickPacket)

Aggregations

BlockPos (net.minecraft.core.BlockPos)1 Direction (net.minecraft.core.Direction)1 ServerboundClientCommandPacket (net.minecraft.network.protocol.game.ServerboundClientCommandPacket)1 ServerboundContainerClickPacket (net.minecraft.network.protocol.game.ServerboundContainerClickPacket)1 ServerboundInteractPacket (net.minecraft.network.protocol.game.ServerboundInteractPacket)1 ServerboundMovePlayerPacket (net.minecraft.network.protocol.game.ServerboundMovePlayerPacket)1 ServerboundPlayerActionPacket (net.minecraft.network.protocol.game.ServerboundPlayerActionPacket)1 ServerboundPlayerCommandPacket (net.minecraft.network.protocol.game.ServerboundPlayerCommandPacket)1 ServerboundUseItemOnPacket (net.minecraft.network.protocol.game.ServerboundUseItemOnPacket)1 MinecraftServer (net.minecraft.server.MinecraftServer)1