Skip to content

Commit

Permalink
Implement calculated value for blocks. (#260)
Browse files Browse the repository at this point in the history
It is ~ value, as calculation formula cannot be applied per block. At least I think so.

Part of #192
  • Loading branch information
BONNe committed Jun 16, 2022
1 parent 4948689 commit 1914fc1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/main/java/world/bentobox/level/panels/DetailsPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,16 @@ private void updateFilters()
{
sorter = (o1, o2) ->
{
int o1Value = this.addon.getBlockConfig().getBlockValues().getOrDefault(o1.getKey(), 0);
int o2Value = this.addon.getBlockConfig().getBlockValues().getOrDefault(o2.getKey(), 0);
int blockLimit = this.addon.getBlockConfig().getBlockLimits().getOrDefault(o1.getKey(), 0);
int o1Count = blockLimit > 0 ? Math.min(o1.getValue(), blockLimit) : o1.getValue();

blockLimit = this.addon.getBlockConfig().getBlockLimits().getOrDefault(o2.getKey(), 0);
int o2Count = blockLimit > 0 ? Math.min(o2.getValue(), blockLimit) : o2.getValue();

long o1Value = (long) o1Count *
this.addon.getBlockConfig().getBlockValues().getOrDefault(o1.getKey(), 0);
long o2Value = (long) o2Count *
this.addon.getBlockConfig().getBlockValues().getOrDefault(o2.getKey(), 0);

if (o1Value == o2Value)
{
Expand All @@ -192,7 +200,7 @@ private void updateFilters()
}
else
{
return Integer.compare(o2Value, o1Value);
return Long.compare(o2Value, o1Value);
}
};
}
Expand Down Expand Up @@ -659,12 +667,17 @@ private PanelItem createMaterialButton(ItemTemplateRecord template,
String count = this.user.getTranslationOrNothing(reference + "count",
"[number]", String.valueOf(materialCount.getValue()));

long calculatedValue = (long) Math.min(blockLimit > 0 ? blockLimit : Integer.MAX_VALUE, materialCount.getValue()) * blockValue;
String valueText = calculatedValue > 0 ? this.user.getTranslationOrNothing(reference + "calculated",
"[number]", String.valueOf(calculatedValue)) : "";

if (template.description() != null)
{
builder.description(this.user.getTranslation(this.world, template.description(),
"[description]", description,
"[id]", blockId,
"[value]", value,
"[calculated]", valueText,
"[limit]", limit,
"[count]", count).
replaceAll("(?m)^[ \\t]*\\r?\\n", "").
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/locales/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,14 @@ level:
[description]
[count]
[value]
[calculated]
[limit]
[id]
id: "&7 Block id: &e [id]"
value: "&7 Block value: &e [number]"
limit: "&7 Block limit: &e [number]"
count: "&7 Number of blocks: &e [number]"
calculated: "&7 Calculated value: &e [number]"
all_blocks:
name: "&f&l All Blocks"
description: |-
Expand Down

0 comments on commit 1914fc1

Please sign in to comment.