Skip to content

Commit

Permalink
fix: stop caching and/or condition tooltips
Browse files Browse the repository at this point in the history
Causes issues with condition tooltips that are lazy initialized like advancement
  • Loading branch information
klikli-dev committed Oct 24, 2024
1 parent decc470 commit 1348950
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public List<Component> getTooltip(Player player, BookConditionContext context) {
}

public static class DistHelper {
public static long lastRequestTime = 0;
public static Component getAdvancementTitle(Player player, ResourceLocation advancementId) {
if (player instanceof LocalPlayer localPlayer) {
//Problem: Advancements are not syncted to the client by vanilla if they are visible - and actively removed if they are not.
Expand All @@ -101,7 +102,11 @@ public static Component getAdvancementTitle(Player player, ResourceLocation adva

//if not available locally, request from server for our local cache
if (adv == null) {
Services.NETWORK.sendToServer(new RequestAdvancementMessage(advancementId));
//only request every second
if(System.currentTimeMillis() - lastRequestTime < 1000) {
lastRequestTime = System.currentTimeMillis();
Services.NETWORK.sendToServer(new RequestAdvancementMessage(advancementId));
}
return Component.translatable(Tooltips.CONDITION_ADVANCEMENT_LOADING);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,15 @@ public boolean testOnLoad() {
public List<Component> getTooltip(Player player, BookConditionContext context) {
if (this.tooltips == null) {
this.tooltips = new ArrayList<>();
if (this.tooltip != null)
this.tooltips.add(this.tooltip);
for (var child : this.children) {
this.tooltips.addAll(child.getTooltip(player, context));
}
}

this.tooltips.clear(); //should not cache because e.g. advancement condition tooltips can change
if (this.tooltip != null)
this.tooltips.add(this.tooltip);
for (var child : this.children) {
this.tooltips.addAll(child.getTooltip(player, context));
}

return this.tooltips != null ? this.tooltips : List.of();
return this.tooltips;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,15 @@ public boolean testOnLoad() {
public List<Component> getTooltip(Player player, BookConditionContext context) {
if (this.tooltips == null) {
this.tooltips = new ArrayList<>();
if (this.tooltip != null)
this.tooltips.add(this.tooltip);
for (var child : this.children) {
this.tooltips.addAll(child.getTooltip(player, context));
}
}

this.tooltips.clear(); //should not cache because e.g. advancement condition tooltips can change
if (this.tooltip != null)
this.tooltips.add(this.tooltip);
for (var child : this.children) {
this.tooltips.addAll(child.getTooltip(player, context));
}

return this.tooltips != null ? this.tooltips : List.of();
return this.tooltips;
}
}

0 comments on commit 1348950

Please sign in to comment.