Skip to content

Entity nulling rework - #1299

Open
Robotgiggle wants to merge 13 commits into
1.21from
entity-nulling-rework
Open

Robotgiggle wants to merge 13 commits into
1.21from
entity-nulling-rework

Conversation

@Robotgiggle

@Robotgiggle Robotgiggle commented Sep 13, 2026

Copy link
Copy Markdown
Member

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 isPlayer boolean 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 in validate() 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.

@github-project-automation github-project-automation Bot moved this to 📋 Backlog in Hex Casting Sep 13, 2026
@Robotgiggle Robotgiggle linked an issue Sep 13, 2026 that may be closed by this pull request

@IridescentVoid IridescentVoid left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ActionUtils helper 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)

Comment thread Common/src/main/java/at/petrak/hexcasting/api/casting/iota/EntityIota.java Outdated
Comment thread Common/src/main/java/at/petrak/hexcasting/api/casting/ActionUtils.kt Outdated
Comment thread Common/src/main/resources/assets/hexcasting/lang/en_us.flatten.json5 Outdated
@github-project-automation github-project-automation Bot moved this from 📋 Backlog to 🏗 In progress in Hex Casting Sep 13, 2026
Comment on lines +97 to +113
// 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);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like these being public...

Comment on lines 136 to +149
@@ -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) }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...but I don't see another way, considering how event handlers are registered :(

Comment thread Common/src/main/java/at/petrak/hexcasting/api/casting/iota/EntityIota.java Outdated
Comment thread Common/src/main/java/at/petrak/hexcasting/api/casting/iota/EntityIota.java Outdated
@Robotgiggle Robotgiggle added enhancement New feature or request 1.21 labels Sep 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1.21 enhancement New feature or request

Projects

Status: 🏗 In progress

Development

Successfully merging this pull request may close these issues.

Entity iotas are not immutable after #1208

3 participants