Search in sources :

Example 6 with CPacketUseEntity

use of net.minecraft.network.play.client.CPacketUseEntity in project SpongeCommon by SpongePowered.

the class AttackEntityPacketState method isPacketIgnored.

@Override
public boolean isPacketIgnored(Packet<?> packetIn, EntityPlayerMP packetPlayer) {
    final CPacketUseEntity useEntityPacket = (CPacketUseEntity) packetIn;
    // There are cases where a player is interacting with an entity that
    // doesn't exist on the server.
    @Nullable net.minecraft.entity.Entity entity = useEntityPacket.getEntityFromWorld(packetPlayer.world);
    return entity == null;
}
Also used : CPacketUseEntity(net.minecraft.network.play.client.CPacketUseEntity) Nullable(javax.annotation.Nullable)

Example 7 with CPacketUseEntity

use of net.minecraft.network.play.client.CPacketUseEntity in project SpongeCommon by SpongePowered.

the class InteractAtEntityPacketState method populateContext.

@Override
public void populateContext(EntityPlayerMP playerMP, Packet<?> packet, BasicPacketContext context) {
    final CPacketUseEntity useEntityPacket = (CPacketUseEntity) packet;
    final ItemStack stack = ItemStackUtil.cloneDefensive(playerMP.getHeldItem(useEntityPacket.getHand()));
    if (stack != null) {
        context.itemUsed(stack);
    }
}
Also used : CPacketUseEntity(net.minecraft.network.play.client.CPacketUseEntity) ItemStack(org.spongepowered.api.item.inventory.ItemStack)

Example 8 with CPacketUseEntity

use of net.minecraft.network.play.client.CPacketUseEntity in project SpongeCommon by SpongePowered.

the class InteractEntityPacketState method populateContext.

@Override
public void populateContext(EntityPlayerMP playerMP, Packet<?> packet, BasicPacketContext context) {
    final CPacketUseEntity useEntityPacket = (CPacketUseEntity) packet;
    net.minecraft.entity.Entity entity = useEntityPacket.getEntityFromWorld(playerMP.world);
    if (entity != null) {
        final ItemStack stack = ItemStackUtil.cloneDefensive(playerMP.getHeldItem(useEntityPacket.getHand()));
        if (stack != null) {
            context.itemUsed(stack);
        }
    }
}
Also used : CPacketUseEntity(net.minecraft.network.play.client.CPacketUseEntity) ItemStack(org.spongepowered.api.item.inventory.ItemStack)

Example 9 with CPacketUseEntity

use of net.minecraft.network.play.client.CPacketUseEntity in project SpongeCommon by SpongePowered.

the class InteractEntityPacketState method isPacketIgnored.

@Override
public boolean isPacketIgnored(Packet<?> packetIn, EntityPlayerMP packetPlayer) {
    final CPacketUseEntity useEntityPacket = (CPacketUseEntity) packetIn;
    // There are cases where a player is interacting with an entity that doesn't exist on the server.
    @Nullable net.minecraft.entity.Entity entity = useEntityPacket.getEntityFromWorld(packetPlayer.world);
    return entity == null;
}
Also used : CPacketUseEntity(net.minecraft.network.play.client.CPacketUseEntity) Nullable(javax.annotation.Nullable)

Example 10 with CPacketUseEntity

use of net.minecraft.network.play.client.CPacketUseEntity in project SpongeCommon by SpongePowered.

the class InteractEntityPacketState method unwind.

@Override
public void unwind(BasicPacketContext phaseContext) {
    final EntityPlayerMP player = phaseContext.getPacketPlayer();
    final CPacketUseEntity useEntityPacket = phaseContext.getPacket();
    final net.minecraft.entity.Entity entity = useEntityPacket.getEntityFromWorld(player.world);
    if (entity == null) {
        // Something happened?
        return;
    }
    final World spongeWorld = EntityUtil.getSpongeWorld(player);
    EntityUtil.toMixin(entity).setNotifier(player.getUniqueID());
    phaseContext.getCapturedBlockSupplier().acceptAndClearIfNotEmpty(blocks -> {
        final PrettyPrinter printer = new PrettyPrinter(80);
        printer.add("Processing Interact Entity").centre().hr();
        printer.add("The blocks captured are:");
        for (BlockSnapshot blockSnapshot : blocks) {
            printer.add("  Block: %s", blockSnapshot);
        }
        printer.trace(System.err);
    });
    phaseContext.getCapturedEntitySupplier().acceptAndClearIfNotEmpty(entities -> {
        final PrettyPrinter printer = new PrettyPrinter(80);
        printer.add("Processing Interact Entity").centre().hr();
        printer.add("The entities captured are:");
        for (Entity capturedEntity : entities) {
            printer.add("  Entity: %s", capturedEntity);
        }
        printer.trace(System.err);
    });
    try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
        Sponge.getCauseStackManager().pushCause(player);
        Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, InternalSpawnTypes.PLACEMENT);
        phaseContext.getCapturedItemsSupplier().acceptAndClearIfNotEmpty(entities -> {
            final List<Entity> items = entities.stream().map(EntityUtil::fromNative).collect(Collectors.toList());
            SpawnEntityEvent event = SpongeEventFactory.createSpawnEntityEvent(Sponge.getCauseStackManager().getCurrentCause(), items);
            SpongeImpl.postEvent(event);
            if (!event.isCancelled()) {
                processSpawnedEntities(player, event);
            }
        });
    }
    phaseContext.getCapturedEntityDropSupplier().acceptIfNotEmpty(map -> {
        final PrettyPrinter printer = new PrettyPrinter(80);
        printer.add("Processing Interact Entity").centre().hr();
        printer.add("The item stacks captured are: ");
        for (Map.Entry<UUID, Collection<ItemDropData>> entry : map.asMap().entrySet()) {
            printer.add("  - Entity with UUID: %s", entry.getKey());
            for (ItemDropData stack : entry.getValue()) {
                printer.add("    - %s", stack);
            }
        }
        printer.trace(System.err);
    });
    phaseContext.getCapturedBlockSupplier().acceptAndClearIfNotEmpty(snapshots -> TrackingUtil.processBlockCaptures(snapshots, this, phaseContext));
}
Also used : CPacketUseEntity(net.minecraft.network.play.client.CPacketUseEntity) Entity(org.spongepowered.api.entity.Entity) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) World(org.spongepowered.api.world.World) SpawnEntityEvent(org.spongepowered.api.event.entity.SpawnEntityEvent) CPacketUseEntity(net.minecraft.network.play.client.CPacketUseEntity) PrettyPrinter(org.spongepowered.asm.util.PrettyPrinter) CauseStackManager(org.spongepowered.api.event.CauseStackManager) Collection(java.util.Collection) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) UUID(java.util.UUID) ItemDropData(org.spongepowered.common.event.tracking.context.ItemDropData) Map(java.util.Map)

Aggregations

CPacketUseEntity (net.minecraft.network.play.client.CPacketUseEntity)10 Nullable (javax.annotation.Nullable)4 World (org.spongepowered.api.world.World)4 Collection (java.util.Collection)3 Map (java.util.Map)3 UUID (java.util.UUID)3 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)3 Entity (org.spongepowered.api.entity.Entity)3 CauseStackManager (org.spongepowered.api.event.CauseStackManager)3 PrettyPrinter (org.spongepowered.asm.util.PrettyPrinter)3 ItemDropData (org.spongepowered.common.event.tracking.context.ItemDropData)3 EntityItem (net.minecraft.entity.item.EntityItem)2 CPacketPlayer (net.minecraft.network.play.client.CPacketPlayer)2 DropItemEvent (org.spongepowered.api.event.item.inventory.DropItemEvent)2 ItemStack (org.spongepowered.api.item.inventory.ItemStack)2 Vector3d (com.flowpowered.math.vector.Vector3d)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Entity (net.minecraft.entity.Entity)1