Start with no recipes and unlock them as you discover spells

This commit is contained in:
Sollace 2022-01-12 13:03:36 +02:00
parent 10af9e6f49
commit 472034bf15
3 changed files with 35 additions and 15 deletions

View file

@ -3,6 +3,7 @@ package com.minelittlepony.unicopia.container;
import com.minelittlepony.common.client.gui.IViewRoot;
import com.minelittlepony.common.client.gui.ScrollContainer;
import com.minelittlepony.common.client.gui.element.Button;
import com.minelittlepony.common.client.gui.element.Label;
import com.minelittlepony.common.client.gui.sprite.TextureSprite;
import com.minelittlepony.unicopia.ability.magic.spell.crafting.SpellbookRecipe;
import com.minelittlepony.unicopia.ability.magic.spell.trait.Trait;
@ -15,6 +16,8 @@ import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.client.gui.screen.recipebook.RecipeBookProvider;
import net.minecraft.client.gui.screen.recipebook.RecipeBookWidget;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.player.PlayerInventory;
@ -23,10 +26,12 @@ import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Identifier;
public class SpellbookScreen extends HandledScreen<SpellbookScreenHandler> {
public class SpellbookScreen extends HandledScreen<SpellbookScreenHandler> implements RecipeBookProvider {
public static final Identifier TEXTURE = new Identifier("unicopia", "textures/gui/container/book.png");
public static final Identifier SLOT = new Identifier("unicopia", "textures/gui/container/slot.png");
private final RecipeBookWidget recipeBook = new RecipeBookWidget();
private final ScrollContainer container = new ScrollContainer() {
{
backgroundColor = 0xFFf9efd3;
@ -89,6 +94,18 @@ public class SpellbookScreen extends HandledScreen<SpellbookScreenHandler> {
addDrawableChild(new PageButton(x + 350, y + 187, 1));
addDrawableChild(new PageButton(x + 300, y + 187, -1));
container.init(this::initPageContent);
addDrawable(container);
((IViewRoot)this).getChildElements().add(container);
}
@Override
public void refreshRecipeBook() {
container.init(this::initPageContent);
}
@Override
public RecipeBookWidget getRecipeBookWidget() {
return recipeBook;
}
@Override
@ -147,8 +164,6 @@ public class SpellbookScreen extends HandledScreen<SpellbookScreenHandler> {
private void initPageContent() {
container.getContentPadding().setVertical(10);
container.getContentPadding().bottom = 30;
addDrawable(container);
((IViewRoot)this).getChildElements().add(container);
switch (SpellbookPage.getCurrent()) {
case DISCOVERIES: {
@ -173,11 +188,16 @@ public class SpellbookScreen extends HandledScreen<SpellbookScreenHandler> {
case RECIPES:
int top = 0;
for (SpellbookRecipe recipe : this.client.world.getRecipeManager().listAllOfType(URecipes.SPELLBOOK)) {
IngredientTree tree = new IngredientTree(0, top,
container.width - container.scrollbar.getBounds().width + 2,
20);
recipe.buildCraftingTree(tree);
top += tree.build(container);
if (client.player.getRecipeBook().contains(recipe)) {
IngredientTree tree = new IngredientTree(0, top,
container.width - container.scrollbar.getBounds().width + 2,
20);
recipe.buildCraftingTree(tree);
top += tree.build(container);
}
}
if (top == 0) {
container.addButton(new Label(container.width / 2, 0).setCentered()).getStyle().setText("gui.unicopia.spellbook.page.recipes.empty");
}
}
}

View file

@ -7,7 +7,6 @@ import com.minelittlepony.unicopia.EquinePredicates;
import com.minelittlepony.unicopia.USounds;
import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits;
import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.item.UItems;
import com.minelittlepony.unicopia.item.URecipes;
import com.minelittlepony.unicopia.util.InventoryUtil;
import com.mojang.datafixers.util.Pair;
@ -132,6 +131,10 @@ public class SpellbookScreenHandler extends ScreenHandler {
onContentChanged(input);
}
public int getOutputSlotId() {
return outputSlot.id;
}
@Override
public boolean canUse(PlayerEntity player) {
return EquinePredicates.IS_CASTER.test(player);
@ -139,6 +142,7 @@ public class SpellbookScreenHandler extends ScreenHandler {
@Override
public void onContentChanged(Inventory inventory) {
super.onContentChanged(inventory);
context.run((world, pos) -> {
if (!world.isClient && !gemSlot.getStack().isEmpty()) {
outputSlot.setStack(
@ -410,7 +414,7 @@ public class SpellbookScreenHandler extends ScreenHandler {
}
}
public static class ResultSlot extends CraftingResultSlot implements SpellbookSlot {
public class ResultSlot extends CraftingResultSlot implements SpellbookSlot {
private final PlayerEntity player;
private final SpellbookInventory input;
@ -423,11 +427,6 @@ public class SpellbookScreenHandler extends ScreenHandler {
this.ring = params[2];
}
@Override
public boolean canInsert(ItemStack stack) {
return stack.getItem() == UItems.GEMSTONE;
}
@Override
public void setStack(ItemStack stack) {
super.setStack(stack);

View file

@ -298,6 +298,7 @@
"gui.unicopia.spellbook.page.inventory": "Inventory",
"gui.unicopia.spellbook.page.discoveries": "Discoveries",
"gui.unicopia.spellbook.page.recipes": "Recipes",
"gui.unicopia.spellbook.page.recipes.empty": "0 Recipes Unlocked",
"gui.unicopia.action.spells_cleared": "Removed all spells",
"gui.unicopia.action.no_spells_cleared": "You have no active spells",