Show a complete list of items with the applicable trait, but as a mystery for items that haven't yet been discovered

This commit is contained in:
Sollace 2022-09-10 17:03:13 +02:00
parent f923f7e872
commit 5595468c4b
5 changed files with 128 additions and 24 deletions

View file

@ -1,5 +1,7 @@
package com.minelittlepony.unicopia.ability.magic.spell.crafting;
import java.util.List;
import com.minelittlepony.unicopia.ability.magic.spell.trait.Trait;
import com.minelittlepony.unicopia.container.SpellbookScreenHandler.SpellbookInventory;
import com.minelittlepony.unicopia.item.UItems;
@ -34,6 +36,16 @@ public interface SpellbookRecipe extends Recipe<SpellbookInventory> {
void input(Trait trait, float value);
void mystery(ItemStack...stacks);
void result(ItemStack...stack);
default void input(List<ItemStack> stacks) {
input(stacks.toArray(ItemStack[]::new));
}
default void mystery(List<ItemStack> stacks) {
mystery(stacks.toArray(ItemStack[]::new));
}
}
}

View file

@ -9,13 +9,19 @@ import com.minelittlepony.common.client.gui.element.Button;
import com.minelittlepony.unicopia.ability.magic.spell.crafting.SpellbookRecipe;
import com.minelittlepony.unicopia.ability.magic.spell.trait.Trait;
import com.minelittlepony.unicopia.client.gui.ItemTraitsTooltipRenderer;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.client.render.*;
import net.minecraft.client.render.item.ItemRenderer;
import net.minecraft.client.render.model.json.ModelTransformation;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.item.ItemStack;
import net.minecraft.screen.PlayerScreenHandler;
import net.minecraft.text.Text;
import net.minecraft.util.math.Vector4f;
class IngredientTree implements SpellbookRecipe.CraftingTreeBuilder {
@ -53,6 +59,13 @@ class IngredientTree implements SpellbookRecipe.CraftingTreeBuilder {
}
}
@Override
public void mystery(ItemStack... stacks) {
if (stacks.length > 0) {
entries.add(new HiddenStacks(stacks));
}
}
@Override
public void result(ItemStack...stacks) {
if (stacks.length > 0) {
@ -80,7 +93,7 @@ class IngredientTree implements SpellbookRecipe.CraftingTreeBuilder {
int column = ii % cols;
int row = ii / cols;
int left = x + column * colWidth + 3 + (row > 0 ? colWidth : 0);
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 ? "" : "+"));
@ -101,13 +114,14 @@ class IngredientTree implements SpellbookRecipe.CraftingTreeBuilder {
super(x, y, width, height);
this.entry = entry;
this.label = label;
this.getStyle().setTooltip(entry.getTooltip());
Tooltip tooltip = entry.getTooltip();
if (tooltip != null) {
this.getStyle().setTooltip(tooltip);
}
}
@Override
public void renderButton(MatrixStack matrices, int mouseX, int mouseY, float tickDelta) {
RenderSystem.setShaderColor(1, 1, 1, 1);
RenderSystem.setShaderTexture(0, SpellbookScreen.SLOT);
RenderSystem.enableBlend();
@ -124,6 +138,18 @@ class IngredientTree implements SpellbookRecipe.CraftingTreeBuilder {
);
entry.render(matrices, x, y, tickDelta);
}
@Override
public void renderToolTip(MatrixStack matrices, Screen parent, int mouseX, int mouseY) {
if (visible) {
getStyle().getTooltip().ifPresent(tooltip -> {
List<Text> lines = tooltip.getLines();
if (!lines.isEmpty()) {
parent.renderTooltip(matrices, tooltip.getLines(), mouseX + getStyle().toolTipX, mouseY + getStyle().toolTipY);
}
});
}
}
}
interface Entry {
@ -134,10 +160,10 @@ class IngredientTree implements SpellbookRecipe.CraftingTreeBuilder {
class Stacks implements IngredientTree.Entry {
private int ticker;
private int index;
private final ItemStack[] stacks;
protected int index;
protected final ItemStack[] stacks;
private final ItemRenderer itemRenderer = MinecraftClient.getInstance().getItemRenderer();
protected final ItemRenderer itemRenderer = MinecraftClient.getInstance().getItemRenderer();
Stacks(ItemStack[] stacks) {
this.stacks = stacks;
@ -150,19 +176,68 @@ class IngredientTree implements SpellbookRecipe.CraftingTreeBuilder {
if (ticker++ % 500 == 0) {
index = (index + 1) % stacks.length;
}
float z = itemRenderer.zOffset;
itemRenderer.zOffset = -100;
Vector4f vector4f = new Vector4f(x, y, z, 1);
vector4f.transform(matrices.peek().getPositionMatrix());
Vector4f pos = new Vector4f(x, y, 0, 1);
pos.transform(matrices.peek().getPositionMatrix());
drawItem((int)pos.getX(), (int)pos.getY());
}
itemRenderer.renderInGui(stacks[index], (int)vector4f.getX(), (int)vector4f.getY());
itemRenderer.zOffset = z;
protected void drawItem(int x, int y) {
itemRenderer.renderInGui(stacks[index], x, y);
}
@Override
public Tooltip getTooltip() {
return () -> stacks[index].getTooltip(MinecraftClient.getInstance().player, TooltipContext.Default.NORMAL);
return () -> {
if (stacks[index].isEmpty()) {
return List.of();
}
return stacks[index].getTooltip(MinecraftClient.getInstance().player, TooltipContext.Default.NORMAL);
};
}
}
class HiddenStacks extends Stacks {
HiddenStacks(ItemStack[] stacks) {
super(stacks);
}
@Override
protected void drawItem(int x, int y) {
var model = itemRenderer.getModel(stacks[index], null, null, 0);
MinecraftClient.getInstance().getTextureManager().getTexture(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE).setFilter(false, false);
RenderSystem.setShaderTexture(0, PlayerScreenHandler.BLOCK_ATLAS_TEXTURE);
RenderSystem.enableBlend();
RenderSystem.blendFunc(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA);
RenderSystem.setShaderColor(1, 1, 1, 0.2F);
MatrixStack matrixStack = RenderSystem.getModelViewStack();
matrixStack.push();
matrixStack.translate(x, y, 100 + itemRenderer.zOffset);
matrixStack.translate(8, 8, 0);
matrixStack.scale(1, -1, 1);
matrixStack.scale(8, 8, 8);
RenderSystem.applyModelViewMatrix();
VertexConsumerProvider.Immediate immediate = MinecraftClient.getInstance().getBufferBuilders().getEntityVertexConsumers();
boolean bl = !model.isSideLit();
if (bl) {
DiffuseLighting.disableGuiDepthLighting();
}
itemRenderer.renderItem(stacks[index], ModelTransformation.Mode.GUI, false, new MatrixStack(), immediate, 0, OverlayTexture.DEFAULT_UV, model);
immediate.draw();
RenderSystem.enableDepthTest();
if (bl) {
DiffuseLighting.enableGuiDepthLighting();
}
matrixStack.pop();
RenderSystem.applyModelViewMatrix();
RenderSystem.setShaderColor(1, 1, 1, 1);
}
@Override
public Tooltip getTooltip() {
return List::of;
}
}

View file

@ -104,7 +104,7 @@ public class SpellbookCraftingPageContent extends ScrollContainer implements Spe
public void drawOverlays(MatrixStack matrices, int mouseX, int mouseY, float tickDelta) {
matrices.push();
matrices.translate(margin.left, margin.top, 0);
matrices.translate(-2, -2, 0);
matrices.translate(-2, -2, 200);
RenderSystem.enableBlend();
RenderSystem.setShaderTexture(0, SpellbookScreen.TEXTURE);
int tileSize = 25;

View file

@ -132,8 +132,6 @@ public class SpellbookScreen extends HandledScreen<SpellbookScreenHandler> imple
drawTexture(matrices, x, y, 0, 0, backgroundWidth, backgroundHeight, 512, 256);
this.clearAndInit();
tabs.getAllTabs().forEach(tab -> {
Bounds bounds = tab.bounds();
chapters.getCurrentChapter();

View file

@ -1,8 +1,12 @@
package com.minelittlepony.unicopia.container;
import java.util.Comparator;
import java.util.List;
import com.minelittlepony.common.client.gui.IViewRoot;
import com.minelittlepony.common.client.gui.ScrollContainer;
import com.minelittlepony.common.client.gui.element.Label;
import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits;
import com.minelittlepony.unicopia.ability.magic.spell.trait.Trait;
import com.minelittlepony.unicopia.entity.player.Pony;
import com.mojang.blaze3d.systems.RenderSystem;
@ -10,12 +14,14 @@ import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawableHelper;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.item.*;
import net.minecraft.text.Text;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.math.MathHelper;
public class SpellbookTraitDexPageContent extends DrawableHelper implements SpellbookChapterList.Content, SpellbookScreen.RecipesChangedListener {
private final Trait[] traits = Trait.all().toArray(Trait[]::new);
private final Trait[] traits = Trait.values();
private int offset;
private final DexPage leftPage = new DexPage();
@ -51,6 +57,7 @@ public class SpellbookTraitDexPageContent extends DrawableHelper implements Spel
public DexPage() {
scrollbar.layoutToEnd = true;
backgroundColor = 0xFFf9efd3;
getContentPadding().setVertical(10);
}
public void init(SpellbookScreen screen, int page) {
@ -80,8 +87,20 @@ public class SpellbookTraitDexPageContent extends DrawableHelper implements Spel
.setText(known ? Text.translatable("gui.unicopia.trait.label",
Text.translatable("trait." + trait.getId().getNamespace() + "." + trait.getId().getPath() + ".name")
) : Text.literal("???"));
IngredientTree tree = new IngredientTree(0, 50, width).noLabels();
Pony.of(MinecraftClient.getInstance().player).getDiscoveries().getKnownItems(trait).forEach(i -> tree.input(i.getDefaultStack()));
IngredientTree tree = new IngredientTree(0, 50, width + 18).noLabels();
List<Item> knownItems = Pony.of(MinecraftClient.getInstance().player).getDiscoveries().getKnownItems(trait).toList();
SpellTraits.getItems(trait)
.sorted(Comparator.comparing(u -> knownItems.contains(u) ? 0 : 1))
.forEach(i -> {
DefaultedList<ItemStack> stacks = DefaultedList.of();
i.appendStacks(ItemGroup.SEARCH, stacks);
if (knownItems.contains(i)) {
tree.input(stacks);
} else {
tree.mystery(stacks);
}
});
tree.build(this);
});
screen.addDrawable(this);
@ -93,7 +112,7 @@ public class SpellbookTraitDexPageContent extends DrawableHelper implements Spel
public void drawOverlays(MatrixStack matrices, int mouseX, int mouseY, float tickDelta) {
matrices.push();
matrices.translate(margin.left, margin.top, 0);
matrices.translate(-2, -2, 0);
matrices.translate(-2, -2, 200);
RenderSystem.enableBlend();
RenderSystem.setShaderTexture(0, SpellbookScreen.TEXTURE);
int tileSize = 25;
@ -102,10 +121,7 @@ public class SpellbookTraitDexPageContent extends DrawableHelper implements Spel
final int right = width - tileSize + 9;
drawTexture(matrices, 0, 0, 405, 62, tileSize, tileSize, 512, 256);
drawTexture(matrices, right, 0, 425, 62, tileSize, tileSize, 512, 256);
drawTexture(matrices, 0, bottom, 405, 72, tileSize, tileSize, 512, 256);
drawTexture(matrices, right, bottom, 425, 72, tileSize, tileSize, 512, 256);
for (int i = tileSize; i < right; i += tileSize) {
drawTexture(matrices, i, 0, 415, 62, tileSize, tileSize, 512, 256);
@ -116,6 +132,9 @@ public class SpellbookTraitDexPageContent extends DrawableHelper implements Spel
drawTexture(matrices, 0, i, 405, 67, tileSize, tileSize, 512, 256);
drawTexture(matrices, right, i, 425, 67, tileSize, tileSize, 512, 256);
}
drawTexture(matrices, right, 0, 425, 62, tileSize, tileSize, 512, 256);
drawTexture(matrices, right, bottom, 425, 72, tileSize, tileSize, 512, 256);
matrices.pop();
if (this == rightPage) {