Search in sources :

Example 6 with ServerboundInteractPacket

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

the class AttackEntityPacketState method unwind.

@Override
public void unwind(final BasicPacketContext context) {
    if (!TrackingUtil.processBlockCaptures(context)) {
        final ServerboundInteractPacket useEntityPacket = context.getPacket();
        final ServerPlayer player = context.getPacketPlayer();
        final net.minecraft.world.entity.@Nullable Entity entity = useEntityPacket.getTarget(player.level);
        if (entity instanceof Entity) {
            ((Entity) entity).offer(Keys.NOTIFIER, player.getUUID());
        }
    }
    ;
}
Also used : LivingEntity(net.minecraft.world.entity.LivingEntity) Entity(org.spongepowered.api.entity.Entity) ItemEntity(net.minecraft.world.entity.item.ItemEntity) ServerPlayer(net.minecraft.server.level.ServerPlayer) ServerboundInteractPacket(net.minecraft.network.protocol.game.ServerboundInteractPacket) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Example 7 with ServerboundInteractPacket

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

the class AttackEntityPacketState method getSpawnTypeForTransaction.

@Override
public Supplier<SpawnType> getSpawnTypeForTransaction(final BasicPacketContext context, final net.minecraft.world.entity.Entity entityToSpawn) {
    final ServerboundInteractPacket useEntityPacket = context.getPacket();
    final ServerPlayer player = context.getPacketPlayer();
    final net.minecraft.world.entity.@Nullable Entity entity = useEntityPacket.getTarget(player.level);
    if (entity != null && (entity.removed || entity instanceof LivingEntity && ((LivingEntity) entity).isDeadOrDying())) {
        return entityToSpawn instanceof ExperienceOrb ? SpawnTypes.EXPERIENCE : SpawnTypes.DROPPED_ITEM;
    }
    if (entityToSpawn instanceof ItemEntity) {
        return SpawnTypes.DROPPED_ITEM;
    }
    return super.getSpawnTypeForTransaction(context, entityToSpawn);
}
Also used : LivingEntity(net.minecraft.world.entity.LivingEntity) ItemEntity(net.minecraft.world.entity.item.ItemEntity) ServerPlayer(net.minecraft.server.level.ServerPlayer) ExperienceOrb(net.minecraft.world.entity.ExperienceOrb) ServerboundInteractPacket(net.minecraft.network.protocol.game.ServerboundInteractPacket) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Example 8 with ServerboundInteractPacket

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

the class AttackEntityPacketState method isPacketIgnored.

@Override
public boolean isPacketIgnored(final Packet<?> packetIn, final 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 9 with ServerboundInteractPacket

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

the class InteractAtEntityPacketState 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 10 with ServerboundInteractPacket

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

the class InteractAtEntityPacketState method populateContext.

@Override
public void populateContext(ServerPlayer playerMP, Packet<?> packet, BasicPacketContext context) {
    final ServerboundInteractPacket useEntityPacket = (ServerboundInteractPacket) packet;
    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