SpongePowered / Sponge

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

1.12.1: TNTMinecart does not throw any spawnentity event when tnt becomes primed #1525

Closed theboomer closed 6 years ago

theboomer commented 7 years ago

When TNT blocks are primed by redstone activation, fire, or primed by hand, a PrimedTNT entity is spawned When TNTMinecarts are primed by pushing onto lit activator rails, no SpawnEntityEvent happens.

The TNTMinecart DOES activate the tnt as it passes over the rails, and its tnt does explode, but the spawnentityevent does not occur for that tnt.

Config: Default, both with and without panda-redstone option. Mobs and Animal spawning false.

I am currently running...

What is the expected result? The SpawnEntityEvent should be fired with a PrimedTNT entity (I think. It seems to be just that, no primed tntminecart entity, right? ) Or whatever it is, it should throw the event.

What is the current result? No SpawnEntityEvent occurs when the tnt in the cart is primed.

I WILL accept this as being intentional because it is not a block at the time of being primed, but is already some kind of entity being able to move and ride the cart, and does not spawn a new entity but merely changes its flavor to a primedtntminecart state, in which case, what event should we be listening for to catch that happening?

Test Plugin:
@Plugin(id = "quickdirtytester")
public class QuickDirty {
    @Inject
    PluginContainer container;

    @Listener
    public void onSpawn(SpawnEntityEvent event) {
        System.out.println("-start event-");
        System.out.println(event.getCause());
        System.out.println(event.getContext());
        for (Entity entity : event.getEntities()) {
            System.out.println("EntitySpawned is " + entity.getType());
        }
        System.out.println("-end event-");
    }
}

Result (SV log, but similar for SF):

[14:03:40] [Server thread/INFO] [MinecraftServer]: <BooMod> planting redstone block beside tnt
[14:03:41] [Server thread/INFO] [STDOUT]: -start event-
[14:03:41] [Server thread/INFO] [STDOUT]: Cause[Context=Context["sponge:spawn_type"=SpongeSpawnType{id=sponge:placement, name=Placement}, "sponge:owner"=EntityPlayerMP['BooMod'/108, l='world', x=-155.93, y=71.00, z=86.91], "sponge:block_hit"=SpongeBlockSnapshot{worldUniqueId=2054196d-616b-4f16-86f4-38137ce0c881, position=(-157, 70, 88), blockState=minecraft:obsidian, extendedState=minecraft:obsidian}, "sponge:used_item"=SpongeItemStackSnapshot{itemType=ItemBlock{Name=null}, quantity=1}, "sponge:notifier"=EntityPlayerMP['BooMod'/108, l='world', x=-155.93, y=71.00, z=86.91]], Stack={EntityPlayerMP['BooMod'/108, l='world', x=-155.93, y=71.00, z=86.91]}]
[14:03:41] [Server thread/INFO] [STDOUT]: Context["sponge:spawn_type"=SpongeSpawnType{id=sponge:placement, name=Placement}, "sponge:owner"=EntityPlayerMP['BooMod'/108, l='world', x=-155.93, y=71.00, z=86.91], "sponge:block_hit"=SpongeBlockSnapshot{worldUniqueId=2054196d-616b-4f16-86f4-38137ce0c881, position=(-157, 70, 88), blockState=minecraft:obsidian, extendedState=minecraft:obsidian}, "sponge:used_item"=SpongeItemStackSnapshot{itemType=ItemBlock{Name=null}, quantity=1}, "sponge:notifier"=EntityPlayerMP['BooMod'/108, l='world', x=-155.93, y=71.00, z=86.91]]
[14:03:41] [Server thread/INFO] [STDOUT]: EntitySpawned is SpongeEntityType{id=minecraft:tnt, name=tnt, translation=SpongeTranslation{id=entity.PrimedTnt.name}, modid=minecraft, class=net.minecraft.entity.item.EntityTNTPrimed}
[14:03:41] [Server thread/INFO] [STDOUT]: -end event-
[14:03:43] [Server thread/INFO] [MinecraftServer]: <BooMod> is primed
[14:03:50] [Server thread/INFO] [MinecraftServer]: <BooMod> has exploded

[14:04:13] [Server thread/INFO] [MinecraftServer]: <BooMod> placing tntcart onto normalrail
[14:04:16] [Server thread/INFO] [STDOUT]: -start event-
[14:04:16] [Server thread/INFO] [STDOUT]: Cause[Context=Context["sponge:spawn_type"=SpongeSpawnType{id=sponge:placement, name=Placement}, "sponge:owner"=EntityPlayerMP['BooMod'/108, l='world', x=-147.79, y=71.00, z=82.70], "sponge:block_hit"=SpongeBlockSnapshot{worldUniqueId=2054196d-616b-4f16-86f4-38137ce0c881, position=(-148, 71, 85), blockState=minecraft:rail[shape=north_south], extendedState=minecraft:rail[shape=north_south]}, "sponge:used_item"=SpongeItemStackSnapshot{itemType=ItemMinecart{Name=minecartTnt}, quantity=1}, "sponge:notifier"=EntityPlayerMP['BooMod'/108, l='world', x=-147.79, y=71.00, z=82.70]], Stack={EntityPlayerMP['BooMod'/108, l='world', x=-147.79, y=71.00, z=82.70]}]
[14:04:16] [Server thread/INFO] [STDOUT]: Context["sponge:spawn_type"=SpongeSpawnType{id=sponge:placement, name=Placement}, "sponge:owner"=EntityPlayerMP['BooMod'/108, l='world', x=-147.79, y=71.00, z=82.70], "sponge:block_hit"=SpongeBlockSnapshot{worldUniqueId=2054196d-616b-4f16-86f4-38137ce0c881, position=(-148, 71, 85), blockState=minecraft:rail[shape=north_south], extendedState=minecraft:rail[shape=north_south]}, "sponge:used_item"=SpongeItemStackSnapshot{itemType=ItemMinecart{Name=minecartTnt}, quantity=1}, "sponge:notifier"=EntityPlayerMP['BooMod'/108, l='world', x=-147.79, y=71.00, z=82.70]]
[14:04:16] [Server thread/INFO] [STDOUT]: EntitySpawned is SpongeEntityType{id=minecraft:tnt_minecart, name=tnt_minecart, translation=SpongeTranslation{id=entity.MinecartTNT.name}, modid=minecraft, class=net.minecraft.entity.item.EntityMinecartTNT}
[14:04:16] [Server thread/INFO] [STDOUT]: -end event-
[14:04:29] [Server thread/INFO] [MinecraftServer]: <BooMod> pushing tntcart into activator rail lit by redstoneblock
[14:04:34] [Server thread/INFO] [MinecraftServer]: <BooMod> is primde
[14:04:40] [Server thread/INFO] [MinecraftServer]: <BooMod> has exploded
ryantheleach commented 7 years ago

Is PrimeExplosiveEvent fired? Also from memory, tnt mine carts explode extremely quickly, They might not prime at all, and instead transition directly into DetonateExplosiveEvent.

To be explicit, this is the events to my rough knowledge, ordering may be slightly off. Creepers prime, swell up, then detonate, explode. TNTBlocks break, spawn entity, prime, detonate, explode. (unsure of ordering between break, spawn and prime) TNTMinecarts, prime?, detonate, explode.

theboomer commented 7 years ago

Just tested now, though it has never been seen before this time.... nope, no PrimeExplosiveEvent detected still. I don't think they have been implimented at all, that and the defuseexplosiveevent...

I haven't yet gone through the tests with the cause/context update but if everything has simply been modified to generate a different cause/context to go with the event being thrown, and not changing the event throwing order/process, the observations as of yesterday are this:

For all cases of placing TNT into a powered space, or providing it power, the block break event happens first, followed by the primedtnt entity spawn event, with 4 exceptions: A locatableblockspawncause (block-spawning) spawn-entity event occurs FIRST for TNT blocks that are: 1) fed power from a repeater 2) fed power from a comparator 3) fed power from an observer block 4) tnt blocks being moved by a piston extension or retraction into a powered space

AFTER the primed TNT entity is spawned for those cases, THEN the ChangeBlockEvent.Break is thrown. I was not interested in fire-ignition but I am 80% sure that it threw the locatableblock spawncause spawn event prior to the block break (I know it does throw locatable as its cause, but it may have been after the break)

As for the tnt carts -- The TNT in them will indeed explode 'instantly' but only in the case where the carts are flung quickly around a corner or against a solid block on the corner. When they pass over an activator rail, the tnt passenger turns into a flashing primed tnt entity and takes the same number of seconds to kaboom as the solid blocks being triggered.

It does indeed seem like the prime explosive event would be what would be used to catch the instant-tnt minecart explosion, but its one of those API things that just isn't there, otherwise its detonate, which is pretty far down the chain of processes to be able to do anything smartly.

gabizou commented 7 years ago

I'll be able to troubleshoot this after some more changes are pushed. I'm trying to clean up IPhaseStates at the same time as cleaning up TrackingPahses. Merging the two into just the IPhaseState to avoid seemingly random delegation would be best. I can't promise a prompt response to fixing this directly, but I'll be keeping this on my radar as the explosion api is technically implemented correctly, just seeming that the vanilla implementation is not implemented as it should be.

theboomer commented 7 years ago

Does spongevanilla absolutely get everything that goes into spongecommon when the builds get made, does it get any backlog waiting list pushed in? For example, if person A puts code into spongecommon to fix a bug with fireworks, and directs the spongeforge system to build , but does not direct the spongevanilla, and a few days later another person adds code to spongecommon to fix a furnace bug, and immediately directs both spongeforge and spongevanilla to build it.... is spongevanilla being told just to build and it looks back at any changes since last time and gets both the fireworks and furnace codes included, or does the furnace fixer just direct spongevanilla to build with his specific spongecommon change, and thereafter as folks continue to make changes and push into both spforge and spvanilla simultaneously, the firework bug fix never gets included in the spongevanilla?
Scenario B: if the fireworks person triggers both SF and SV to build, yet the spongevanilla version has a problem merging that code and building a version with that fireworks fix, and it goes unnoticed that no build was made, and then the furnace fix gets put in common and then both SF and SV are successful building versions for that, will the fireworks fix failure to incorporate be evident anywhere, or does that become lost in time waiting to be reported as a bug again later that SV has that particular broken firework issue still...

Spongevanilla often goes without builds for longer times than spongeforge, though often due to SF direct updates only, but sometimes a pile of spongecommon changes can occur with no SV updates for days or longer after that, so if for example, the PrimeEntityEvent works in spongeforge afterall, and not in SV, is it possible that n-many months ago when spongecommon got that code in it, SV never got built with it in it? Because I can look for SC pushes that may mention some of these things, and if there is a void in the SV build log that makes no mention of that corresponding fix, would that be helpful or time wisely spent at all?

stephan-gh commented 7 years ago

@theboomer SpongeCommon is a shared module between SpongeVanilla and SpongeForge and is identical on both platforms. Both implementations point to a specific revision of SpongeCommon. When we push a change to SpongeCommon, this revision must be updated separately in both implementations.

If SpongeVanilla isn't updated directly to the new SpongeCommon revision, that doesn't mean that changes or fixes get lost. As soon as the SpongeCommon revision is updated, all previous changes will be included in the next build as well.

theboomer commented 7 years ago

Okay thats encouraging :) But is it possible for a SV build to be incomplete/unsuccessful when that code is included, and if it fails, does the system ignore that merge thereafter automatically, or would that just totally break all build attempts downstream period because that code is part of it now and if it cant compile, it never will until the issue is fixed to let it compile?

stephan-gh commented 7 years ago

@theboomer Keep in mind there is no automatic merge of the changes. We need to update the revision manually on both implementations, which is the primary reason why usually only a single implementation (the one the author of the SpongeCommon changes works with locally) is updated immediately, and the other one is usually updated with a slight delay.

If something in SpongeCommon is incompatible with SpongeVanilla, it will cause the build to fail. SpongeVanilla cannot be updated until it is fixed.

theboomer commented 7 years ago

Okay, thanks Minecrell -removed- If this is the case, then there is nothing to gain for looking at history for build gaps after SC, I believe.

phit commented 7 years ago

tldr you don't understand git submodules, instead of writing this whole thing, that nobody wants to read, you should just look up the docs for that, then minecrells reply will make sense!

this is a nice small summary, basic understanding of git is required though https://gist.github.com/gitaarik/8735255

theboomer commented 7 years ago

That unfortunately doesn't add any clarity to me, because it seems to still keep suggesting that you NEED to point to each "commit" for it to be included, and if each of those code contributions is a commit... Or is a 'commit' the actual 'current final version' and not the chunk of coded being added into it, making it so that spongecommon always has everything there, and SF/SV just need to be pointed to where "the latest" refers now, rather than 'those were included'?

phit commented 7 years ago

Technically this completely wrong, but yes for your understanding its the "current final version", so for all intents and purposes previous changes will be included. To explain how it actually works I would have to write a book, but there is plenty of sources out there that have done so.

ryantheleach commented 6 years ago

@theboomer You are incorrect, the entity is primed not spawned, I just checked in Vanilla. (and the MCP sources)

The TNTMinecart itself is primed, and has nothing to do with PrimedTNT which is the entity form of block TNT, which is always primed.

To elaborate, A creeper doesn't become a new entity PrimedCreeper when primed, it just changes internal state which makes it Primed.

A TNTMinecart follows the same process, it's not TNT riding a cart, it's an inherently different entity, a TNTMinecraft. It goes over the activator rail and becomes Primed, and (should) fire a PrimeEvent.

At no stage is it replaced with a minecart entity with a TNT entity riding it.