Apotheosis

Apotheosis

90M Downloads

Datapack-modifed augments persist following removal until WorldTier change

Hamderber opened this issue ยท 1 comments

commented

Issue:
If a datapack is used to modify the WorldTier attributes, that change isn't applied until the WorldTier changes or is refreshed by unlocking another tier.

Example/reproducable:
Use a datapack to change Haven World Tier to reduce health by 5 hearts. Loading into a pre-datapack world doesn't change the health for pre-existing players on Haven Tier. Once they unlock the next tier, their current tier is refreshed and the datapack takes effect. Similarly, the same is true for when the datapack is removed and a player hasn't updated their current/unlocked World Tiers. In this example, they would retain a max health of 5 less hearts until changing World Tiers or unlocking the next one, which triggers an update for the current one.

Example datapack used:

src/generated/resources/data/apotheosis/tier_augments/haven/player_max_health.json

{
    "type": "apotheosis:attribute",
    "modifier": {
        "attribute": "minecraft:generic.max_health",
        "operation": "add_multiplied_base",
        "value": -0.5
    },
    "modifier_id": "apotheosis:haven/player_max_health",
    "sort_index": 400,
    "target": "players",
    "tier": "haven"
}

The following code is a method of resolving this. I elected not to submit a pull request because I'm not entirely sure where this should go, or if this is the correct solution.

@SubscribeEvent
    private void applyWorldTierOnLogin(EntityJoinLevelEvent event) {
  	  if (event.getLevel().isClientSide()) return;
  	  if (!(event.getEntity() instanceof Player player)) return;
  	  
  	  // Only works when the 'oldTier == tier' is bypassed. Maybe add a boolean ignoreCurrentTier option/overload?
  	  WorldTier.setTier(player, player.getData(Attachments.WORLD_TIER));
    }
commented

Ideally I wouldn't need to rerun the tier augments each time a player logs in... I'll need to fiddle around with a tracking mechanism that allows it to be updated.

Fortunately this isn't a critical issue or anything, since generally the Tier Augments should be static for the lifespan of a world.