SpongePowered / Sponge

The SpongeAPI implementation targeting vanilla Minecraft and 3rd party platforms.
MIT License
383 stars 211 forks source link

No cause / context /source for a TNT that set off another TNT #1949

Open Blayyke opened 6 years ago

Blayyke commented 6 years ago

I am currently running

Issue Description There is no way to track an explosion event's source back to another TNT entity / block. For instance: Say I set off one TNT in the vicinity of another. The second will blow up as normal, however it will not have any references to the first one, only to the player that the first one had.

-- First block that went off through a player ignition CAUSES:: net.minecraft.entity.item.EntityTNTPrimed -- EntityTNTPrimed['Block of TNT'/7386, l='mines', x=-364.68, y=4.00, z=-631.60] SOURCE::net.minecraft.entity.item.EntityTNTPrimed -- EntityTNTPrimed['Block of TNT'/7386, l='mines', x=-364.68, y=4.00, z=-631.60] CONTEXT::Owner - sponge:owner - org.spongepowered.api.entity.living.player.User - SpongeEventContextKey{id=sponge:owner} CONTEXT::net.minecraft.entity.player.EntityPlayerMP -- EntityPlayerMP['xA5'/328, l='mines', x=-362.08, y=4.00, z=-629.56]

-- Block that was blown up by the first CAUSES:: net.minecraft.entity.item.EntityTNTPrimed -- EntityTNTPrimed['Block of TNT'/8831, l='mines', x=-364.64, y=3.76, z=-630.38] SOURCE::net.minecraft.entity.item.EntityTNTPrimed -- EntityTNTPrimed['Block of TNT'/8831, l='mines', x=-364.64, y=3.76, z=-630.38] CONTEXT::Owner - sponge:owner - org.spongepowered.api.entity.living.player.User - SpongeEventContextKey{id=sponge:owner} CONTEXT::net.minecraft.entity.player.EntityPlayerMP -- EntityPlayerMP['xA5'/328, l='mines', x=-360.84, y=4.00, z=-628.59]

The above lines were printed with the following code (to try debugging):

        System.out.println("CAUSES::");
        for (Object o : event.getCause().all()) {
            System.out.println(o.getClass().getName() + " -- " + o);
        }
        System.out.println("SOURCE::" + event.getSource().getClass().getName() + " -- " + event.getSource());
        event.getContext().asMap().forEach((eventContextKey, o) -> {
            System.out.println("CONTEXT::" + eventContextKey.getName() + " - " + eventContextKey.getId() + " - " + eventContextKey.getAllowedType().getCanonicalName() + " - " + eventContextKey);
            System.out.println("CONTEXT::" + o.getClass().getName() + " -- " + o);
        });
Aaron1011 commented 6 years ago

@gabizou: Unfortunately, it seems that we can't use EventContextKeys.IGNITER here, since it only applies to Living (which PrimedTnt is not). Should we add it directly to the cause, or make a breaking change in bleeding?

gabizou commented 6 years ago

I'd say make it in the cause.