mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-23 21:38:00 +01:00
Obfuscate recipe results when the page is obfuscated
This commit is contained in:
parent
2eaefdad9b
commit
9bf0dd01c2
2 changed files with 14 additions and 5 deletions
|
@ -33,6 +33,7 @@ class IngredientTree implements SpellbookRecipe.CraftingTreeBuilder {
|
|||
private final int width;
|
||||
|
||||
private boolean addLabels = true;
|
||||
private boolean obfuscateResult;
|
||||
|
||||
public IngredientTree(int x, int y, int width) {
|
||||
this.x = x + 4;
|
||||
|
@ -45,6 +46,11 @@ class IngredientTree implements SpellbookRecipe.CraftingTreeBuilder {
|
|||
return this;
|
||||
}
|
||||
|
||||
public IngredientTree obfuscateResult(boolean obfuscateResult) {
|
||||
this.obfuscateResult = obfuscateResult;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void input(ItemStack... stacks) {
|
||||
if (stacks.length > 0) {
|
||||
|
@ -96,11 +102,11 @@ class IngredientTree implements SpellbookRecipe.CraftingTreeBuilder {
|
|||
int left = x + column * colWidth + 3 + (addLabels && row > 0 ? colWidth : 0);
|
||||
int top = y + row * rowHeight + 3;
|
||||
|
||||
container.addButton(new IngredientButton(left, top, colWidth, rowHeight, entry, !addLabels || ii == 0 ? "" : "+"));
|
||||
container.addButton(new IngredientButton(left, top, colWidth, rowHeight, entry, !addLabels || ii == 0 ? "" : "+", false));
|
||||
ii++;
|
||||
}
|
||||
result.ifPresent(result -> {
|
||||
container.addButton(new IngredientButton(x + width - 17, y + totalHeight / 3 - 2, colWidth, totalHeight, result, addLabels ? "=" : ""));
|
||||
container.addButton(new IngredientButton(x + width - 17, y + totalHeight / 3 - 2, colWidth, totalHeight, result, addLabels ? "=" : "", obfuscateResult));
|
||||
});
|
||||
|
||||
return totalHeight + 7;
|
||||
|
@ -110,13 +116,13 @@ class IngredientTree implements SpellbookRecipe.CraftingTreeBuilder {
|
|||
private final IngredientTree.Entry entry;
|
||||
private String label;
|
||||
|
||||
public IngredientButton(int x, int y, int width, int height, IngredientTree.Entry entry, String label) {
|
||||
public IngredientButton(int x, int y, int width, int height, IngredientTree.Entry entry, String label, boolean obfuscated) {
|
||||
super(x, y, width, height);
|
||||
this.entry = entry;
|
||||
this.label = label;
|
||||
Tooltip tooltip = entry.getTooltip();
|
||||
if (tooltip != null) {
|
||||
this.getStyle().setTooltip(tooltip);
|
||||
this.getStyle().setTooltip(obfuscated ? Tooltip.of("???") : tooltip);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -129,11 +129,14 @@ interface PageElement extends Drawable {
|
|||
}
|
||||
MinecraftClient.getInstance().world.getRecipeManager().get(id).ifPresent(recipe -> {
|
||||
if (recipe instanceof SpellbookRecipe spellRecipe) {
|
||||
|
||||
boolean needsMoreXp = page.getLevel() < 0 || Pony.of(MinecraftClient.getInstance().player).getLevel().get() < page.getLevel();
|
||||
|
||||
IngredientTree tree = new IngredientTree(
|
||||
bounds().left + page().getBounds().left,
|
||||
bounds().top + page().getBounds().top + y + 10,
|
||||
page().getBounds().width - 20
|
||||
);
|
||||
).obfuscateResult(needsMoreXp);
|
||||
spellRecipe.buildCraftingTree(tree);
|
||||
bounds.height = tree.build(container) - 10;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue