Entity nulling rework - #1299
Robotgiggle wants to merge 14 commits into
Conversation
IridescentVoid
left a comment
There was a problem hiding this comment.
A few changes/blockers for merging:
- In discord: design discussion around intuitiveness and other points raised
- Likely performance issues in
EntityIota.isPlayer. It would be best if we can run real benchmarks on whether this is a problem, including when the backing store is a hard disk rather than a SSD. Hex Casting should be playable even for players on older hardware. - Incorrect mishaps raised by some
ActionUtilshelper methods (that were not updated by the pr, but probably should have been) - Discussion: should cleric impeti allow binding to offline players, since references are always considered valid now? After all, binding impeti does not require ambit. (
BlockRedstoneImpetus.useItemOn, around L73)
| // This finds anyone who has ever joined the server by reading the UUIDs from the playerdata folder | ||
| // We can't just use GameProfileCache because it only stores 1000 UUIDs and only keeps them for 30 days | ||
| public static void initPlayerUUIDs(MinecraftServer server) { | ||
| var playerDataDir = server.getWorldPath(LevelResource.PLAYER_DATA_DIR).toFile(); | ||
| String[] uuidStrings = playerDataDir.list(); | ||
| if (uuidStrings == null) return; | ||
| for (String string : uuidStrings) { | ||
| if (string.endsWith(".dat")) { | ||
| UUID playerId = UUID.fromString(string.substring(0, string.length() - 4)); | ||
| playerUUIDs.add(playerId); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public static void addPlayerUUID(UUID newUUID) { | ||
| playerUUIDs.add(newUUID); | ||
| } |
There was a problem hiding this comment.
I don't like these being public...
| @@ -143,6 +145,8 @@ object FabricHexInitializer : ModInitializer { | |||
| ServerTickEvents.END_WORLD_TICK.register(OpFlight::tickAllPlayers) | |||
| ServerTickEvents.END_WORLD_TICK.register(OpAltiora::checkAllPlayers) | |||
|
|
|||
| ServerPlayerEvents.JOIN.register { player -> EntityIota.addPlayerUUID(player.uuid) } | |||
|
|
|||
There was a problem hiding this comment.
...but I don't see another way, considering how event handlers are registered :(
IridescentVoid
left a comment
There was a problem hiding this comment.
Previously mentioned blockers have all been addressed. I have one small nitpick to help avoid future bugs, but otherwise I don't see any major problems. I think the current design is probably acceptable, and it will be playtested on hexxytest prior to release.
Not an approving review as I haven't looked into the code in-depth or actually tested its behavior, but I don't want to block merging of the PR.
Change requests have been addressed; don't block merging.
s5bug
left a comment
There was a problem hiding this comment.
happy with code but haven't tested in-game
Resolves #1227, removes the behavior of entity iotas becoming null when their referenced entity ceases to exist, and replaces it with an entity-doesn't-exist mishap thrown when you try to use an iota pointing to something nonexistent. To check whether the entity currently exists, you can use Augur's Purification on the iota.
Entity iotas nulling themselves is the only instance of iotas changing on their own without player input, so it was always a little bit unintuitive. However, naively removing that behavior would make it possible to save truenames of offline players. Previously, that problem was handled via an added
isPlayerboolean on the iota, but this comes with its own problems (notably, making the iota mutable since setting the value on preexisting iotas needed to be done invalidate()while the player in question was online).This PR implements a different solution that does not require any new data, codec shenanigans, or mutability. When the server starts up, it runs through its playerdata folder and stores all the UUIDs it finds into a set of "known players". When a new player joins, their UUID is also added to the set. Then, when checking playerness of an iota whose entity does not currently exist, it just compares the UUID to the set of known players. This does not account for players who have never joined the server before, but there's no way to get an entity iota for such a player without using commands, and with commands you can spawn in as many saved truenames as you want anyway.