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());
}
}
;
}
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);
}
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;
}
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;
}
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);
}
Aggregations