Quark

Quark

143M Downloads

Quark explosive errors not calling the right events

Raycoms opened this issue ยท 7 comments

commented

It seems like the explosive arrows of quark explode and deal damage even if their event has been canceled. And it seems not possible to undo the changes removing the blocks and entities from its event.

commented

We do this:

     * ExplosionEvent.Detonate handler.
     *
     * @param event ExplosionEvent.Detonate
     */
    @SubscribeEvent
    public void on(final ExplosionEvent.Detonate event)
    {
        if (!Configurations.enableColonyProtection || !Configurations.turnOffExplosionsInColonies)
        {
            return;
        }

        final World eventWorld = event.getWorld();
        final Predicate<BlockPos> getBlocksInColony = pos -> colony.isCoordInColony(eventWorld, pos);
        final Predicate<Entity> getEntitiesInColony = entity -> colony.isCoordInColony(entity.getEntityWorld(), entity.getPosition());
        // if block is in colony -> remove from list
        final List<BlockPos> blocksToRemove = event.getAffectedBlocks().stream()
                                                .filter(getBlocksInColony)
                                                .collect(Collectors.toList());

        // if entity is in colony -> remove from list
        final List<Entity> entitiesToRemove = event.getAffectedEntities().stream()
                                                .filter(getEntitiesInColony)
                                                .collect(Collectors.toList());
        event.getAffectedBlocks().removeAll(blocksToRemove);
        event.getAffectedEntities().removeAll(entitiesToRemove);
    }

    /**
     * ExplosionEvent.Start handler.
     *
     * @param event ExplosionEvent.Detonate
     */
    @SubscribeEvent
    public void on(final ExplosionEvent.Start event)
    {
        if (Configurations.enableColonyProtection
              && Configurations.turnOffExplosionsInColonies
              && colony.isCoordInColony(event.getWorld(), new BlockPos(event.getExplosion().getPosition())))
        {
            cancelEvent(event, null);
        }
    }```

1) should work if someone launches the arrow inside a colony. But 2) should work at any time.

But for some reason the explosive arrows still explode our stuff.

And I don't want to turn them off because they are useful outside of the colonies.
commented

Before: https://youtu.be/SwNPNrdbU_0
@SubscribeEvent public void test(ExplosionEvent.Start e) { e.setCanceled(true); }
After : https://youtu.be/6ozXm4R0PD0

The event seems to be working fine for me.

commented

Hmm, then I guess the problem is the clean-up task

commented

I can't exactly decipher what you're saying. But, there is a config option to disable the explosive arrow from destroying blocks. As well as a config option to turn down the amount of power the explosion has. Also you mention an event, I'am guessing you mean the ExplosionEvent which the explosion arrows do adhere to.

commented

Since our mod does add an anti griefing protection to the game. And in this we do cancel all explosion start events and do remove all "affected" blocks from the maps.

But even with this your arrows explode blocks, so something is going wrong.

commented

The explosive arrows use the same explosion code as the primed tnt entity. Can you show a snippet of your code that cancel the event. The event that they both share is ExplosionEvent.Start.

Edit: Or link me the code. If, it is on github.

commented

Closing because I'm cleaning up the issues page. This issue is really old and probably irrelevant. If you feel i should be re-opened please tell me why.