mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-24 05:47:59 +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 final int width;
|
||||||
|
|
||||||
private boolean addLabels = true;
|
private boolean addLabels = true;
|
||||||
|
private boolean obfuscateResult;
|
||||||
|
|
||||||
public IngredientTree(int x, int y, int width) {
|
public IngredientTree(int x, int y, int width) {
|
||||||
this.x = x + 4;
|
this.x = x + 4;
|
||||||
|
@ -45,6 +46,11 @@ class IngredientTree implements SpellbookRecipe.CraftingTreeBuilder {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IngredientTree obfuscateResult(boolean obfuscateResult) {
|
||||||
|
this.obfuscateResult = obfuscateResult;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void input(ItemStack... stacks) {
|
public void input(ItemStack... stacks) {
|
||||||
if (stacks.length > 0) {
|
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 left = x + column * colWidth + 3 + (addLabels && row > 0 ? colWidth : 0);
|
||||||
int top = y + row * rowHeight + 3;
|
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++;
|
ii++;
|
||||||
}
|
}
|
||||||
result.ifPresent(result -> {
|
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;
|
return totalHeight + 7;
|
||||||
|
@ -110,13 +116,13 @@ class IngredientTree implements SpellbookRecipe.CraftingTreeBuilder {
|
||||||
private final IngredientTree.Entry entry;
|
private final IngredientTree.Entry entry;
|
||||||
private String label;
|
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);
|
super(x, y, width, height);
|
||||||
this.entry = entry;
|
this.entry = entry;
|
||||||
this.label = label;
|
this.label = label;
|
||||||
Tooltip tooltip = entry.getTooltip();
|
Tooltip tooltip = entry.getTooltip();
|
||||||
if (tooltip != null) {
|
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 -> {
|
MinecraftClient.getInstance().world.getRecipeManager().get(id).ifPresent(recipe -> {
|
||||||
if (recipe instanceof SpellbookRecipe spellRecipe) {
|
if (recipe instanceof SpellbookRecipe spellRecipe) {
|
||||||
|
|
||||||
|
boolean needsMoreXp = page.getLevel() < 0 || Pony.of(MinecraftClient.getInstance().player).getLevel().get() < page.getLevel();
|
||||||
|
|
||||||
IngredientTree tree = new IngredientTree(
|
IngredientTree tree = new IngredientTree(
|
||||||
bounds().left + page().getBounds().left,
|
bounds().left + page().getBounds().left,
|
||||||
bounds().top + page().getBounds().top + y + 10,
|
bounds().top + page().getBounds().top + y + 10,
|
||||||
page().getBounds().width - 20
|
page().getBounds().width - 20
|
||||||
);
|
).obfuscateResult(needsMoreXp);
|
||||||
spellRecipe.buildCraftingTree(tree);
|
spellRecipe.buildCraftingTree(tree);
|
||||||
bounds.height = tree.build(container) - 10;
|
bounds.height = tree.build(container) - 10;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue