Search in sources :

Example 1 with ServerboundInteractPacket

use of net.minecraft.network.protocol.game.ServerboundInteractPacket 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)

Example 2 with ServerboundInteractPacket

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

the class InteractEntityPacketState method unwind.

@Override
public void unwind(BasicPacketContext phaseContext) {
    final ServerPlayer player = phaseContext.getPacketPlayer();
    final ServerboundInteractPacket useEntityPacket = phaseContext.getPacket();
    final net.minecraft.world.entity.Entity entity = useEntityPacket.getTarget(player.level);
    if (entity == null) {
        // Something happened?
        return;
    }
    if (entity instanceof CreatorTrackedBridge) {
        ((CreatorTrackedBridge) entity).tracker$setTrackedUUID(PlayerTracker.Type.CREATOR, player.getUUID());
    } else {
        ((Entity) entity).offer(Keys.NOTIFIER, player.getUUID());
    }
    TrackingUtil.processBlockCaptures(phaseContext);
}
Also used : Entity(org.spongepowered.api.entity.Entity) CreatorTrackedBridge(org.spongepowered.common.bridge.CreatorTrackedBridge) ServerPlayer(net.minecraft.server.level.ServerPlayer) ServerboundInteractPacket(net.minecraft.network.protocol.game.ServerboundInteractPacket)

Example 3 with ServerboundInteractPacket

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

the class InteractEntityPacketState method isPacketIgnored.

@Override
public boolean isPacketIgnored(Packet<?> packetIn, ServerPlayer packetPlayer) {
    final ServerboundInteractPacket useEntityPacket = (ServerboundInteractPacket) packetIn;
    // There are cases where a player is interacting with an entity that doesn't exist on the server.
    final net.minecraft.world.entity.@Nullable Entity entity = useEntityPacket.getTarget(packetPlayer.level);
    return entity == null;
}
Also used : ServerboundInteractPacket(net.minecraft.network.protocol.game.ServerboundInteractPacket) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Example 4 with ServerboundInteractPacket

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

the class InteractAtEntityPacketState method unwind.

@Override
public void unwind(BasicPacketContext context) {
    final ServerPlayer player = context.getPacketPlayer();
    final ServerboundInteractPacket useEntityPacket = context.getPacket();
    final net.minecraft.world.entity.Entity entity = useEntityPacket.getTarget(player.level);
    if (entity == null) {
        // Something happened?
        return;
    }
    final World spongeWorld = (World) player.level;
    if (entity instanceof CreatorTrackedBridge) {
        ((CreatorTrackedBridge) entity).tracker$setTrackedUUID(PlayerTracker.Type.CREATOR, player.getUUID());
    } else {
        ((Entity) entity).offer(Keys.NOTIFIER, player.getUUID());
    }
    // TODO - Determine if we need to pass the supplier or perform some parameterized
    // process if not empty method on the capture object.
    TrackingUtil.processBlockCaptures(context);
}
Also used : Entity(org.spongepowered.api.entity.Entity) CreatorTrackedBridge(org.spongepowered.common.bridge.CreatorTrackedBridge) ServerPlayer(net.minecraft.server.level.ServerPlayer) ServerboundInteractPacket(net.minecraft.network.protocol.game.ServerboundInteractPacket) World(org.spongepowered.api.world.World)

Example 5 with ServerboundInteractPacket

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

the class InteractEntityPacketState method populateContext.

@Override
public void populateContext(ServerPlayer playerMP, Packet<?> packet, BasicPacketContext context) {
    final ServerboundInteractPacket useEntityPacket = (ServerboundInteractPacket) packet;
    net.minecraft.world.entity.Entity entity = useEntityPacket.getTarget(playerMP.level);
    if (entity != null) {
        final ItemStack stack = ItemStackUtil.cloneDefensive(playerMP.getItemInHand(useEntityPacket.getHand()));
        if (stack != null) {
            context.itemUsed(stack);
        }
        final HandType handType = (HandType) (Object) useEntityPacket.getHand();
        context.handUsed(handType);
    }
}
Also used : HandType(org.spongepowered.api.data.type.HandType) ServerboundInteractPacket(net.minecraft.network.protocol.game.ServerboundInteractPacket) ItemStack(org.spongepowered.api.item.inventory.ItemStack)

Aggregations

ServerboundInteractPacket (net.minecraft.network.protocol.game.ServerboundInteractPacket)10 Nullable (org.checkerframework.checker.nullness.qual.Nullable)5 ServerPlayer (net.minecraft.server.level.ServerPlayer)4 Entity (org.spongepowered.api.entity.Entity)3 LivingEntity (net.minecraft.world.entity.LivingEntity)2 ItemEntity (net.minecraft.world.entity.item.ItemEntity)2 HandType (org.spongepowered.api.data.type.HandType)2 ItemStack (org.spongepowered.api.item.inventory.ItemStack)2 CreatorTrackedBridge (org.spongepowered.common.bridge.CreatorTrackedBridge)2 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 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 ExperienceOrb (net.minecraft.world.entity.ExperienceOrb)1 World (org.spongepowered.api.world.World)1