Logicon211 / TModTombstone

A mod (WIP) for Terraria to drop a tombstone with all your items when you die in medium core mode. Instead of scattering it everywhere
1 stars 4 forks source link

[BUG] Dying from explosion (able to dislodge blocks) permanently breaks mod for given character #1

Open Cat-Lady opened 2 months ago

Cat-Lady commented 2 months ago

Hello Logicon211, First of all, thank you for work on the mod - it changed my experience with Mediumcore Terraria from "unplayable for longer due to re-sorting inventory" (and softcore bores me), to "awesome".

Hoever, during my playthrough on Terraria 1.4.4.9 (on tModLoader 2024.4.3.2), I discovered quite critical bug. I will break it down in points:

  1. If a character (host or client) dies from an explosion that is able to dislodge tiles (bomb, dynamite, etc...), the spawning tombstone gets dislodged as well (it is instantly pickupable item, afterwards), and retrieving items is impossible.

It seems that the invulnerability of the block where tombstone is placed turns ON a little bit too late, or the tombstone itself spawns too early, getting caught in the blast before the invulnerability (maybe little delay would help?).

  1. Further playthrough with the mod and dying of any other cause than explosion, spawns the tombstone all right and items are retrievable....

3... as long as the player stays on server. Hoever, disconnecting from the server and returning later on, results in the player being unable to retrieve any item from the (correctly spawned on death) tombstone.

It happens ONLY if the player died from the explosion earlier, and the glitched broken tombstone from point 1 happened.

IF player never died from an tile-dislodging explosion, tombstones work all right, and the items are retrievable even after logout and reconnect.

  1. Furthermore, if player loses items to the explosion-dislodged tombstone and tries to recover them on different world, the tombstone never spawns. Upon connecting/starting world, the message with coordinates and value of items in the tombstone is displayed, but the actual tombstone never materializes (tested multiple times).

Summing it up, the mod works all right up to the points someone died due to tile-dislodging explosion. Afterwards, the specific character is permanently "broken" in regards to how the mod should work between reconnects to server.

I believe that those are two separate issues, connected by the way the breakage by explosion occurs - one is the premature spawn of tombstone and it getting dislodged by explosion, and another one is breakage of the between-relogs ability to retrieve tombstone content. While the second issue would, probably, welcome a separate fix, I believe that both could be avoided if the explosion-death issue would be avoided in the first place.

Cheers, CatLady

Logicon211 commented 2 months ago

Thanks for the thorough checking!

I'm not sure it's possible to fix the potential explosion problem due to the fact that tmodloader doesn't really give me any more tools to work with to do it. My guess is that the frame that is causing it to destroy the tombstone block is happening before the frames where it should be indestructible. It's a timing issue I'm not quite sure I can solve.

As for recovering your items in another world, the tombstone actually does not spawn, it only considers the coordinates. So you should be able to place a tombstone on that coordinate position and then click on it to get your stuff back. This should also work even if the tombstone was destroyed by an explosion. It can be a little finnicky to get the tombstone in the exact right spot considering the coordinate position is a 1x1 block and the tombstone is 2x2.

Try placing down a tombstone in or around that position and see if that gets your stuff back

Cat-Lady commented 2 months ago

Thank you for the quick answer! I will check placing the tombstone in the new world and regaining the items.

BTW, as I am quite new to Terraria modding (in fact, started using TModLoder specifically thanks to your mod), what would you recommend as most convenient pipeline (mods installed, commands?) for quickly getting into hard-to-reach coordinates in a world generated for purpose of retrieving items? Does it need to be golden tombstone placed, specifically? Any, or some "special" version from mod?

On a side note - I get that it might be hard or impossible to fix the explosion issue (probably, the unkillable ghost entity from mod inspired by yours works around that, due to not being a block - but that mod is abandoned and outdated, sadly, no longer working). But, what about the problem with further, non-explosion death tombstones not working after reconnect, if player died earlier due to explosion? As I mentioned, one such death (likely, the dislodged tomb that accompany it), permanently breaks ability to retrieve items between recconnects for said character (tomb exist, but doesn't give items back, if there was a disconnect in-between dying and trying to get items). Before explosion-death, tombstones work all right between reconnects, but never afterwards.

Is there something that can be done about it?

Logicon211 commented 2 months ago

I think there's an item in game (compass maybe?) that displays your coordinates while you have it.

I imagine if there's some kind of issue with multiplayer characters losing stuff permanently it could probably be fixed. It's just trying to nail down the exact reason is difficult to debug since the situation seems very specific. And debugging multiplayer issues is a pain as it requires multiple terraria instances running while trying to test that specific case.

If I had to take a wild guess though maybe the server was restarted in between? I'm not 100% sure if a non-host player would have their inventory saved. I think it may only hold onto other players inventory in memory, and once restarted it likely will not restore them.

The code that handles that I think is here: https://github.com/Logicon211/TModTombstone/blob/master/TombstoneDeathMod2/TombstonePlayer.cs#L334 and https://github.com/Logicon211/TModTombstone/blob/master/TombstoneDeathMod2/TombstonePlayer.cs#L370

These are both tmodloader hooks and it's been a while since I've looked at this code so I don't know exactly how it gets called or what kind of information is saved. That and I think Exuvo actually wrote this part, my original code did not save inventories inbetween world reloads.

I don't have a lot of time on my hands these days to work on updating this so it'll likely go unanswered unless you or someone else wants to take a stab at it. Feel free to fork this repo or open a PR and publish it!