Search in sources :

Example 6 with PrettyPrinter

use of org.spongepowered.asm.util.PrettyPrinter in project SpongeCommon by SpongePowered.

the class PhaseTracker method printRunnawayPhaseCompletion.

private void printRunnawayPhaseCompletion(IPhaseState<?> state) {
    if (!SpongeImpl.getGlobalConfig().getConfig().getPhaseTracker().isVerbose() && !this.hasPrintedAboutRunnawayPhases) {
        // Avoiding spam logs.
        return;
    }
    final PrettyPrinter printer = new PrettyPrinter(60);
    printer.add("Completing Phase").centre().hr();
    printer.addWrapped(60, "Detecting a runaway phase! Potentially a problem " + "where something isn't completing a phase!!! Sponge will stop printing" + "after three more times to avoid generating extra logs");
    printer.add();
    printer.addWrapped(60, "%s : %s", "Completing phase", state);
    printer.add(" Phases Remaining:");
    this.stack.forEach(data -> PHASE_PRINTER.accept(printer, data));
    printer.add();
    printer.add("Stacktrace:");
    printer.add(new Exception("Stack trace"));
    printer.add();
    this.generateVersionInfo(printer);
    printer.trace(System.err, SpongeImpl.getLogger(), Level.ERROR);
    if (!SpongeImpl.getGlobalConfig().getConfig().getPhaseTracker().isVerbose() && this.printRunawayCount++ > 3) {
        this.hasPrintedAboutRunnawayPhases = true;
    }
}
Also used : PrettyPrinter(org.spongepowered.asm.util.PrettyPrinter) ReportedException(net.minecraft.util.ReportedException)

Example 7 with PrettyPrinter

use of org.spongepowered.asm.util.PrettyPrinter in project SpongeCommon by SpongePowered.

the class DeathUpdateState method unwind.

@Override
public void unwind(BasicEntityContext context) {
    final Entity dyingEntity = context.getSource(Entity.class).orElseThrow(TrackingUtil.throwWithContext("Dying entity not found!", context));
    context.getCapturedItemsSupplier().acceptAndClearIfNotEmpty(items -> {
        final DamageSource damageSource = context.getDamageSource();
        try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
            Sponge.getCauseStackManager().pushCause(dyingEntity);
            Sponge.getCauseStackManager().pushCause(damageSource);
            Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, SpawnTypes.DROPPED_ITEM);
            final ArrayList<Entity> entities = new ArrayList<>();
            for (EntityItem item : items) {
                entities.add(EntityUtil.fromNative(item));
            }
            final DropItemEvent.Destruct destruct = SpongeEventFactory.createDropItemEventDestruct(Sponge.getCauseStackManager().getCurrentCause(), entities);
            SpongeImpl.postEvent(destruct);
            if (!destruct.isCancelled()) {
                for (Entity entity : destruct.getEntities()) {
                    EntityUtil.getMixinWorld(entity).forceSpawnEntity(entity);
                }
            }
        }
    });
    context.getCapturedEntitySupplier().acceptAndClearIfNotEmpty(entities -> {
        final List<Entity> experience = entities.stream().filter(entity -> entity instanceof ExperienceOrb).collect(Collectors.toList());
        if (!experience.isEmpty()) {
            try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
                Sponge.getCauseStackManager().pushCause(dyingEntity);
                Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, SpawnTypes.EXPERIENCE);
                final SpawnEntityEvent event = SpongeEventFactory.createSpawnEntityEvent(Sponge.getCauseStackManager().getCurrentCause(), experience);
                SpongeImpl.postEvent(event);
                if (!event.isCancelled()) {
                    for (Entity entity : event.getEntities()) {
                        EntityUtil.getMixinWorld(entity).forceSpawnEntity(entity);
                    }
                }
            }
        }
        final List<Entity> other = entities.stream().filter(entity -> !(entity instanceof ExperienceOrb)).collect(Collectors.toList());
        if (!other.isEmpty()) {
            try (StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
                Sponge.getCauseStackManager().pushCause(dyingEntity);
                Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, InternalSpawnTypes.ENTITY_DEATH);
                final SpawnEntityEvent event1 = SpongeEventFactory.createSpawnEntityEvent(Sponge.getCauseStackManager().getCurrentCause(), other);
                SpongeImpl.postEvent(event1);
                if (!event1.isCancelled()) {
                    for (Entity entity : event1.getEntities()) {
                        EntityUtil.getMixinWorld(entity).forceSpawnEntity(entity);
                    }
                }
            }
        }
    });
    context.getCapturedEntityDropSupplier().acceptIfNotEmpty(map -> {
        if (map.isEmpty()) {
            return;
        }
        final PrettyPrinter printer = new PrettyPrinter(80);
        printer.add("Processing Entity Death Updates Spawning").centre().hr();
        printer.add("Entity Dying: " + dyingEntity);
        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);
    });
    context.getCapturedBlockSupplier().acceptAndClearIfNotEmpty(blocks -> TrackingUtil.processBlockCaptures(blocks, this, context));
}
Also used : EntityItem(net.minecraft.entity.item.EntityItem) SpongeImpl(org.spongepowered.common.SpongeImpl) StackFrame(org.spongepowered.api.event.CauseStackManager.StackFrame) EventContextKeys(org.spongepowered.api.event.cause.EventContextKeys) SpongeEventFactory(org.spongepowered.api.event.SpongeEventFactory) Collection(java.util.Collection) Sponge(org.spongepowered.api.Sponge) SpawnEntityEvent(org.spongepowered.api.event.entity.SpawnEntityEvent) DropItemEvent(org.spongepowered.api.event.item.inventory.DropItemEvent) UUID(java.util.UUID) DamageSource(org.spongepowered.api.event.cause.entity.damage.source.DamageSource) InternalSpawnTypes(org.spongepowered.common.registry.type.event.InternalSpawnTypes) Entity(org.spongepowered.api.entity.Entity) PrettyPrinter(org.spongepowered.asm.util.PrettyPrinter) Collectors(java.util.stream.Collectors) EntityUtil(org.spongepowered.common.entity.EntityUtil) ArrayList(java.util.ArrayList) SpawnTypes(org.spongepowered.api.event.cause.entity.spawn.SpawnTypes) List(java.util.List) TrackingUtil(org.spongepowered.common.event.tracking.TrackingUtil) ExperienceOrb(org.spongepowered.api.entity.ExperienceOrb) Map(java.util.Map) ItemDropData(org.spongepowered.common.event.tracking.context.ItemDropData) CauseStackManager(org.spongepowered.api.event.CauseStackManager) Entity(org.spongepowered.api.entity.Entity) DropItemEvent(org.spongepowered.api.event.item.inventory.DropItemEvent) DamageSource(org.spongepowered.api.event.cause.entity.damage.source.DamageSource) StackFrame(org.spongepowered.api.event.CauseStackManager.StackFrame) ArrayList(java.util.ArrayList) ExperienceOrb(org.spongepowered.api.entity.ExperienceOrb) SpawnEntityEvent(org.spongepowered.api.event.entity.SpawnEntityEvent) PrettyPrinter(org.spongepowered.asm.util.PrettyPrinter) CauseStackManager(org.spongepowered.api.event.CauseStackManager) StackFrame(org.spongepowered.api.event.CauseStackManager.StackFrame) Collection(java.util.Collection) UUID(java.util.UUID) ItemDropData(org.spongepowered.common.event.tracking.context.ItemDropData) Map(java.util.Map) EntityItem(net.minecraft.entity.item.EntityItem)

Example 8 with PrettyPrinter

use of org.spongepowered.asm.util.PrettyPrinter in project SpongeCommon by SpongePowered.

the class AttackEntityPacketState method unwind.

@Override
public void unwind(BasicPacketContext context) {
    final EntityPlayerMP player = context.getPacketPlayer();
    final CPacketUseEntity useEntityPacket = context.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());
    context.getCapturedItemsSupplier().acceptAndClearIfNotEmpty(items -> {
        // For destruction, this should be empty, however, some
        // times,
        // it may not be?
        final PrettyPrinter printer = new PrettyPrinter(60);
        printer.add("Processing Attack Entity").centre().hr();
        printer.add("There are some captured items after the entity was destructed!");
        printer.addWrapped(60, "%s : %s", "Items captured", items);
        printer.add("Stacktrace:");
        printer.add(new Exception("Stack trace"));
        printer.trace(System.err, SpongeImpl.getLogger(), Level.TRACE);
    });
    context.getCapturedBlockSupplier().acceptAndClearIfNotEmpty(blocks -> TrackingUtil.processBlockCaptures(blocks, this, context));
    context.getCapturedEntityDropSupplier().acceptIfNotEmpty(map -> {
        for (Map.Entry<UUID, Collection<ItemDropData>> entry : map.asMap().entrySet()) {
            final UUID key = entry.getKey();
            final Optional<Entity> affectedEntity = spongeWorld.getEntity(key);
            if (!affectedEntity.isPresent()) {
                continue;
            }
            final Collection<ItemDropData> itemStacks = entry.getValue();
            if (itemStacks.isEmpty()) {
                return;
            }
            final List<ItemDropData> items = new ArrayList<>(itemStacks);
            if (!items.isEmpty()) {
                try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
                    final List<Entity> itemEntities = items.stream().map(data -> data.create(((WorldServer) player.world))).map(EntityUtil::fromNative).collect(Collectors.toList());
                    Sponge.getCauseStackManager().pushCause(player);
                    Sponge.getCauseStackManager().pushCause(affectedEntity.get());
                    Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, InternalSpawnTypes.DROPPED_ITEM);
                    final DropItemEvent.Destruct destruct = SpongeEventFactory.createDropItemEventDestruct(Sponge.getCauseStackManager().getCurrentCause(), itemEntities);
                    SpongeImpl.postEvent(destruct);
                    if (!destruct.isCancelled()) {
                        processSpawnedEntities(player, destruct);
                    }
                }
            }
        }
    });
    context.getCapturedEntityItemDropSupplier().acceptIfNotEmpty(map -> {
        try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
            Sponge.getCauseStackManager().pushCause(player);
            Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, InternalSpawnTypes.DROPPED_ITEM);
            for (Map.Entry<UUID, Collection<EntityItem>> entry : map.asMap().entrySet()) {
                final UUID key = entry.getKey();
                final Optional<Entity> attackedEntities = spongeWorld.getEntity(key);
                if (!attackedEntities.isPresent()) {
                    continue;
                }
                final List<Entity> items = entry.getValue().stream().map(EntityUtil::fromNative).collect(Collectors.toList());
                final DropItemEvent.Destruct destruct = SpongeEventFactory.createDropItemEventDestruct(Sponge.getCauseStackManager().getCurrentCause(), items);
                SpongeImpl.postEvent(destruct);
                if (!destruct.isCancelled()) {
                    processSpawnedEntities(player, destruct);
                }
            }
        }
    });
}
Also used : CPacketUseEntity(net.minecraft.network.play.client.CPacketUseEntity) Entity(org.spongepowered.api.entity.Entity) DropItemEvent(org.spongepowered.api.event.item.inventory.DropItemEvent) ArrayList(java.util.ArrayList) World(org.spongepowered.api.world.World) 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)

Example 9 with PrettyPrinter

use of org.spongepowered.asm.util.PrettyPrinter in project SpongeCommon by SpongePowered.

the class InteractAtEntityPacketState method unwind.

@Override
public void unwind(BasicPacketContext context) {
    final EntityPlayerMP player = context.getPacketPlayer();
    final CPacketUseEntity useEntityPacket = context.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());
    try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
        Sponge.getCauseStackManager().pushCause(player);
        Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, InternalSpawnTypes.PLACEMENT);
        context.getCapturedEntitySupplier().acceptAndClearIfNotEmpty(entities -> {
            SpawnEntityEvent event = SpongeEventFactory.createSpawnEntityEvent(Sponge.getCauseStackManager().getCurrentCause(), entities);
            SpongeImpl.postEvent(event);
            if (!event.isCancelled()) {
                processSpawnedEntities(player, event);
            }
        });
        context.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);
            }
        });
        context.getCapturedEntityDropSupplier().acceptIfNotEmpty(map -> {
            final PrettyPrinter printer = new PrettyPrinter(80);
            printer.add("Processing Interact At 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);
        });
        context.getCapturedEntityItemDropSupplier().acceptIfNotEmpty(map -> {
            for (Map.Entry<UUID, Collection<EntityItem>> entry : map.asMap().entrySet()) {
                final UUID entityUuid = entry.getKey();
                final net.minecraft.entity.Entity entityFromUuid = player.getServerWorld().getEntityFromUuid(entityUuid);
                if (entityFromUuid != null) {
                    final List<Entity> entities = entry.getValue().stream().map(EntityUtil::fromNative).collect(Collectors.toList());
                    if (!entities.isEmpty()) {
                        DropItemEvent.Custom event = SpongeEventFactory.createDropItemEventCustom(Sponge.getCauseStackManager().getCurrentCause(), entities);
                        SpongeImpl.postEvent(event);
                        if (!event.isCancelled()) {
                            processSpawnedEntities(player, event);
                        }
                    }
                }
            }
        });
        context.getCapturedItemStackSupplier().acceptAndClearIfNotEmpty(drops -> {
            final List<EntityItem> items = drops.stream().map(drop -> drop.create(player.getServerWorld())).collect(Collectors.toList());
            final List<Entity> entities = items.stream().map(EntityUtil::fromNative).collect(Collectors.toList());
            if (!entities.isEmpty()) {
                DropItemEvent.Custom event = SpongeEventFactory.createDropItemEventCustom(Sponge.getCauseStackManager().getCurrentCause(), entities);
                SpongeImpl.postEvent(event);
                if (!event.isCancelled()) {
                    processSpawnedEntities(player, event);
                }
            }
        });
    }
    context.getCapturedBlockSupplier().acceptAndClearIfNotEmpty(snapshots -> TrackingUtil.processBlockCaptures(snapshots, this, context));
}
Also used : SpongeImpl(org.spongepowered.common.SpongeImpl) EventContextKeys(org.spongepowered.api.event.cause.EventContextKeys) CPacketUseEntity(net.minecraft.network.play.client.CPacketUseEntity) DropItemEvent(org.spongepowered.api.event.item.inventory.DropItemEvent) PrettyPrinter(org.spongepowered.asm.util.PrettyPrinter) ItemStackUtil(org.spongepowered.common.item.inventory.util.ItemStackUtil) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ItemStack(org.spongepowered.api.item.inventory.ItemStack) TrackingUtil(org.spongepowered.common.event.tracking.TrackingUtil) Map(java.util.Map) CauseStackManager(org.spongepowered.api.event.CauseStackManager) Nullable(javax.annotation.Nullable) EntityItem(net.minecraft.entity.item.EntityItem) Packet(net.minecraft.network.Packet) SpongeEventFactory(org.spongepowered.api.event.SpongeEventFactory) Collection(java.util.Collection) Sponge(org.spongepowered.api.Sponge) SpawnEntityEvent(org.spongepowered.api.event.entity.SpawnEntityEvent) UUID(java.util.UUID) InternalSpawnTypes(org.spongepowered.common.registry.type.event.InternalSpawnTypes) Entity(org.spongepowered.api.entity.Entity) Collectors(java.util.stream.Collectors) EntityUtil(org.spongepowered.common.entity.EntityUtil) List(java.util.List) World(org.spongepowered.api.world.World) ItemDropData(org.spongepowered.common.event.tracking.context.ItemDropData) CPacketUseEntity(net.minecraft.network.play.client.CPacketUseEntity) Entity(org.spongepowered.api.entity.Entity) DropItemEvent(org.spongepowered.api.event.item.inventory.DropItemEvent) 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) EntityItem(net.minecraft.entity.item.EntityItem)

Example 10 with PrettyPrinter

use of org.spongepowered.asm.util.PrettyPrinter in project SpongeCommon by SpongePowered.

the class InteractionPacketState method unwind.

@Override
public void unwind(BasicPacketContext phaseContext) {
    final EntityPlayerMP player = phaseContext.getPacketPlayer();
    final ItemStack usedStack = phaseContext.getItemUsed();
    final ItemStackSnapshot usedSnapshot = ItemStackUtil.snapshotOf(usedStack);
    final Entity spongePlayer = EntityUtil.fromNative(player);
    try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
        Sponge.getCauseStackManager().pushCause(spongePlayer);
        Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, InternalSpawnTypes.DROPPED_ITEM);
        final boolean hasBlocks = !phaseContext.getCapturedBlockSupplier().isEmpty();
        final List<BlockSnapshot> capturedBlcoks = phaseContext.getCapturedBlocks();
        @Nullable final BlockSnapshot firstBlockChange = hasBlocks ? capturedBlcoks.get(0) : null;
        if (hasBlocks) {
            if (!TrackingUtil.processBlockCaptures(capturedBlcoks, this, phaseContext)) {
                // Stop entities like XP from being spawned
                return;
            }
        } else {
            phaseContext.getBlockItemDropSupplier().acceptIfNotEmpty(map -> {
                if (ShouldFire.DROP_ITEM_EVENT_DESTRUCT) {
                    for (BlockSnapshot blockChange : capturedBlcoks) {
                        final Location<World> location = blockChange.getLocation().get();
                        final Vector3d position = location.getPosition();
                        final BlockPos blockPos = VecHelper.toBlockPos(position);
                        final Collection<EntityItem> entityItems = map.get(blockPos);
                        if (!entityItems.isEmpty()) {
                            final List<Entity> items = entityItems.stream().map(EntityUtil::fromNative).collect(Collectors.toList());
                            final DropItemEvent.Destruct event = SpongeEventFactory.createDropItemEventDestruct(Sponge.getCauseStackManager().getCurrentCause(), items);
                            SpongeImpl.postEvent(event);
                            if (!event.isCancelled()) {
                                processSpawnedEntities(player, event);
                            }
                        }
                    }
                } else {
                    for (BlockSnapshot blockChange : capturedBlcoks) {
                        final Location<World> location = blockChange.getLocation().get();
                        final Vector3d position = location.getPosition();
                        final BlockPos blockPos = VecHelper.toBlockPos(position);
                        final Collection<EntityItem> entityItems = map.get(blockPos);
                        if (!entityItems.isEmpty()) {
                            processEntities(player, (Collection<Entity>) (Collection<?>) entityItems);
                        }
                    }
                }
            });
        }
        phaseContext.getCapturedItemsSupplier().acceptAndClearIfNotEmpty(items -> {
            final ArrayList<Entity> entities = new ArrayList<>();
            for (EntityItem item : items) {
                entities.add(EntityUtil.fromNative(item));
            }
            final DropItemEvent.Dispense dispense = SpongeEventFactory.createDropItemEventDispense(Sponge.getCauseStackManager().getCurrentCause(), entities);
            SpongeImpl.postEvent(dispense);
            if (!dispense.isCancelled()) {
                processSpawnedEntities(player, dispense);
            }
        });
        phaseContext.getCapturedEntityDropSupplier().acceptIfNotEmpty(map -> {
            if (map.isEmpty()) {
                return;
            }
            final PrettyPrinter printer = new PrettyPrinter(80);
            printer.add("Processing Interaction").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.getCapturedEntitySupplier().acceptAndClearIfNotEmpty(entities -> {
            final List<Entity> projectiles = new ArrayList<>(entities.size());
            final List<Entity> spawnEggs = new ArrayList<>(entities.size());
            final List<Entity> xpOrbs = new ArrayList<>(entities.size());
            final List<Entity> normalPlacement = new ArrayList<>(entities.size());
            final List<Entity> items = new ArrayList<>(entities.size());
            for (Entity entity : entities) {
                if (entity instanceof Projectile || entity instanceof EntityThrowable) {
                    projectiles.add(entity);
                } else if (usedSnapshot.getType() == ItemTypes.SPAWN_EGG) {
                    spawnEggs.add(entity);
                } else if (entity instanceof EntityItem) {
                    items.add(entity);
                } else if (entity instanceof EntityXPOrb) {
                    xpOrbs.add(entity);
                } else {
                    normalPlacement.add(entity);
                }
            }
            if (!projectiles.isEmpty()) {
                if (ShouldFire.SPAWN_ENTITY_EVENT) {
                    try (CauseStackManager.StackFrame frame2 = Sponge.getCauseStackManager().pushCauseFrame()) {
                        Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, InternalSpawnTypes.PROJECTILE);
                        Sponge.getCauseStackManager().pushCause(usedSnapshot);
                        final SpawnEntityEvent event = SpongeEventFactory.createSpawnEntityEvent(Sponge.getCauseStackManager().getCurrentCause(), projectiles);
                        if (!SpongeImpl.postEvent(event)) {
                            processSpawnedEntities(player, event);
                        }
                    }
                } else {
                    processEntities(player, projectiles);
                }
            }
            if (!spawnEggs.isEmpty()) {
                if (ShouldFire.SPAWN_ENTITY_EVENT) {
                    try (CauseStackManager.StackFrame frame2 = Sponge.getCauseStackManager().pushCauseFrame()) {
                        Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, InternalSpawnTypes.PROJECTILE);
                        Sponge.getCauseStackManager().pushCause(usedSnapshot);
                        final SpawnEntityEvent event = SpongeEventFactory.createSpawnEntityEvent(Sponge.getCauseStackManager().getCurrentCause(), spawnEggs);
                        if (!SpongeImpl.postEvent(event)) {
                            processSpawnedEntities(player, event);
                        }
                    }
                } else {
                    processEntities(player, spawnEggs);
                }
            }
            if (!items.isEmpty()) {
                if (ShouldFire.DROP_ITEM_EVENT_DISPENSE) {
                    final DropItemEvent.Dispense dispense = SpongeEventFactory.createDropItemEventDispense(Sponge.getCauseStackManager().getCurrentCause(), items);
                    if (!SpongeImpl.postEvent(dispense)) {
                        processSpawnedEntities(player, dispense);
                    }
                } else {
                    processEntities(player, items);
                }
            }
            if (!xpOrbs.isEmpty()) {
                if (ShouldFire.SPAWN_ENTITY_EVENT) {
                    try (final CauseStackManager.StackFrame stackFrame = Sponge.getCauseStackManager().pushCauseFrame()) {
                        if (firstBlockChange != null) {
                            stackFrame.pushCause(firstBlockChange);
                        }
                        stackFrame.addContext(EventContextKeys.SPAWN_TYPE, InternalSpawnTypes.EXPERIENCE);
                        final SpawnEntityEvent event = SpongeEventFactory.createSpawnEntityEvent(Sponge.getCauseStackManager().getCurrentCause(), xpOrbs);
                        if (!SpongeImpl.postEvent(event)) {
                            processSpawnedEntities(player, event);
                        }
                    }
                } else {
                    processEntities(player, xpOrbs);
                }
            }
            if (!normalPlacement.isEmpty()) {
                if (ShouldFire.SPAWN_ENTITY_EVENT) {
                    try (final CauseStackManager.StackFrame stackFrame = Sponge.getCauseStackManager().pushCauseFrame()) {
                        if (firstBlockChange != null) {
                            stackFrame.pushCause(firstBlockChange);
                        }
                        final SpawnEntityEvent event = SpongeEventFactory.createSpawnEntityEvent(Sponge.getCauseStackManager().getCurrentCause(), normalPlacement);
                        if (!SpongeImpl.postEvent(event)) {
                            processSpawnedEntities(player, event);
                        }
                    }
                } else {
                    processEntities(player, normalPlacement);
                }
            }
        });
        final IMixinContainer mixinContainer = ContainerUtil.toMixin(player.openContainer);
        mixinContainer.setCaptureInventory(false);
        mixinContainer.getCapturedTransactions().clear();
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) ArrayList(java.util.ArrayList) World(org.spongepowered.api.world.World) PrettyPrinter(org.spongepowered.asm.util.PrettyPrinter) CauseStackManager(org.spongepowered.api.event.CauseStackManager) BlockPos(net.minecraft.util.math.BlockPos) UUID(java.util.UUID) EntityItem(net.minecraft.entity.item.EntityItem) DropItemEvent(org.spongepowered.api.event.item.inventory.DropItemEvent) EntityThrowable(net.minecraft.entity.projectile.EntityThrowable) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) SpawnEntityEvent(org.spongepowered.api.event.entity.SpawnEntityEvent) Projectile(org.spongepowered.api.entity.projectile.Projectile) IMixinContainer(org.spongepowered.common.interfaces.IMixinContainer) Vector3d(com.flowpowered.math.vector.Vector3d) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) Collection(java.util.Collection) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ItemStack(org.spongepowered.api.item.inventory.ItemStack) ItemDropData(org.spongepowered.common.event.tracking.context.ItemDropData) Map(java.util.Map) Nullable(javax.annotation.Nullable) EntityXPOrb(net.minecraft.entity.item.EntityXPOrb)

Aggregations

PrettyPrinter (org.spongepowered.asm.util.PrettyPrinter)27 Map (java.util.Map)9 Collection (java.util.Collection)7 ReportedException (net.minecraft.util.ReportedException)7 CauseStackManager (org.spongepowered.api.event.CauseStackManager)7 UUID (java.util.UUID)6 Entity (org.spongepowered.api.entity.Entity)6 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)5 SpawnEntityEvent (org.spongepowered.api.event.entity.SpawnEntityEvent)5 DropItemEvent (org.spongepowered.api.event.item.inventory.DropItemEvent)5 ItemDropData (org.spongepowered.common.event.tracking.context.ItemDropData)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 EntityItem (net.minecraft.entity.item.EntityItem)4 Sponge (org.spongepowered.api.Sponge)4 World (org.spongepowered.api.world.World)4 SpongeImpl (org.spongepowered.common.SpongeImpl)4 IOException (java.io.IOException)3 Collectors (java.util.stream.Collectors)3 Nullable (javax.annotation.Nullable)3