From 472034bf15f2e9d3e943f830cab9e10ece3a1c8c Mon Sep 17 00:00:00 2001 From: Sollace Date: Wed, 12 Jan 2022 13:03:36 +0200 Subject: [PATCH] Start with no recipes and unlock them as you discover spells --- .../unicopia/container/SpellbookScreen.java | 36 ++++++++++++++----- .../container/SpellbookScreenHandler.java | 13 ++++--- .../resources/assets/unicopia/lang/en_us.json | 1 + 3 files changed, 35 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/container/SpellbookScreen.java b/src/main/java/com/minelittlepony/unicopia/container/SpellbookScreen.java index 82cb85c6..fbcf7204 100644 --- a/src/main/java/com/minelittlepony/unicopia/container/SpellbookScreen.java +++ b/src/main/java/com/minelittlepony/unicopia/container/SpellbookScreen.java @@ -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 { +public class SpellbookScreen extends HandledScreen 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 { 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 { 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 { 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"); } } } diff --git a/src/main/java/com/minelittlepony/unicopia/container/SpellbookScreenHandler.java b/src/main/java/com/minelittlepony/unicopia/container/SpellbookScreenHandler.java index f6b5439f..85b78c21 100644 --- a/src/main/java/com/minelittlepony/unicopia/container/SpellbookScreenHandler.java +++ b/src/main/java/com/minelittlepony/unicopia/container/SpellbookScreenHandler.java @@ -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); diff --git a/src/main/resources/assets/unicopia/lang/en_us.json b/src/main/resources/assets/unicopia/lang/en_us.json index 2355c256..fc0dc302 100644 --- a/src/main/resources/assets/unicopia/lang/en_us.json +++ b/src/main/resources/assets/unicopia/lang/en_us.json @@ -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",