From 0305f7db93e8dbee018129da51a7471407f8ba2c Mon Sep 17 00:00:00 2001 From: Vasco Lavos Date: Tue, 14 Jan 2014 18:46:33 +0000 Subject: [PATCH] And some more API work, with Internal Handlers and Lexicon Pages. --- MODSRC/vazkii/botania/api/BotaniaAPI.java | 18 +++++++++++ .../vazkii/botania/api/LexiconCategory.java | 12 +++++-- MODSRC/vazkii/botania/api/LexiconEntry.java | 18 +++++++++-- .../api/internal/DummyMethodHandler.java | 28 ++++++++++++++++ .../api/internal/IInternalMethodHandler.java | 27 ++++++++++++++++ .../vazkii/botania/api/page/LexiconPage.java | 6 ++++ MODSRC/vazkii/botania/api/page/PageDummy.java | 32 +++++++++++++++++++ .../core/handler/InternalMethodHandler.java | 25 +++++++++++++++ .../vazkii/botania/common/page/PageText.java | 28 ++++++++++++++++ 9 files changed, 188 insertions(+), 6 deletions(-) create mode 100644 MODSRC/vazkii/botania/api/internal/DummyMethodHandler.java create mode 100644 MODSRC/vazkii/botania/api/internal/IInternalMethodHandler.java create mode 100644 MODSRC/vazkii/botania/api/page/PageDummy.java create mode 100644 MODSRC/vazkii/botania/common/core/handler/InternalMethodHandler.java create mode 100644 MODSRC/vazkii/botania/common/page/PageText.java diff --git a/MODSRC/vazkii/botania/api/BotaniaAPI.java b/MODSRC/vazkii/botania/api/BotaniaAPI.java index d7cc93244..702047845 100644 --- a/MODSRC/vazkii/botania/api/BotaniaAPI.java +++ b/MODSRC/vazkii/botania/api/BotaniaAPI.java @@ -16,19 +16,37 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import vazkii.botania.api.internal.DummyMethodHandler; +import vazkii.botania.api.internal.IInternalMethodHandler; + public final class BotaniaAPI { private static List categories = new ArrayList(); private static List allEntries = new ArrayList(); + /** + * The internal method handler in use. Do not overwrite. + * @see IInternalMethodHandler + */ + public static IInternalMethodHandler internalHandler = new DummyMethodHandler(); + + /** + * Adds a category to the list of registered categories to appear in the Lexicon. + */ public static void addCategory(LexiconCategory category) { categories.add(category); } + /** + * Gets all registered categories. + */ public static List getAllCategories() { return categories; } + /** + * Registers a Lexicon Entry and adds it to the category passed in. + */ public static void addEntry(LexiconEntry entry, LexiconCategory category) { allEntries.add(entry); category.entries.add(entry); diff --git a/MODSRC/vazkii/botania/api/LexiconCategory.java b/MODSRC/vazkii/botania/api/LexiconCategory.java index 8f3ec861d..34c894791 100644 --- a/MODSRC/vazkii/botania/api/LexiconCategory.java +++ b/MODSRC/vazkii/botania/api/LexiconCategory.java @@ -16,11 +16,17 @@ import java.util.List; public final class LexiconCategory { - public final String tag; + public final String unlocalizedName; public final List entries = new ArrayList(); - public LexiconCategory(String tag) { - this.tag = tag; + /** + * @param unlocalizedName The unlocalized name of this category. This will be localized by the client display. + */ + public LexiconCategory(String unlocalizedName) { + this.unlocalizedName = unlocalizedName; } + public String getUnlocalizedName() { + return unlocalizedName; + } } diff --git a/MODSRC/vazkii/botania/api/LexiconEntry.java b/MODSRC/vazkii/botania/api/LexiconEntry.java index 3bad43246..f2a7c82cb 100644 --- a/MODSRC/vazkii/botania/api/LexiconEntry.java +++ b/MODSRC/vazkii/botania/api/LexiconEntry.java @@ -21,21 +21,33 @@ import vazkii.botania.api.page.LexiconPage; public class LexiconEntry { - public final String id; + public final String unlocalizedName; public List pages = new ArrayList(); - public LexiconEntry(String id) { - this.id = id; + /** + * @param unlocalizedName The unlocalized name of this entry. This will be localized by the client display. + */ + public LexiconEntry(String unlocalizedName) { + this.unlocalizedName = unlocalizedName; } + /** + * Sets what pages you want this entry to have. + */ public void setLexiconPages(LexiconPage... pages) { this.pages.addAll(Arrays.asList(pages)); } + /** + * Adds a page to the list of pages. + */ public void addPage(LexiconPage page) { pages.add(page); } + /** + * Should this entry be displayed in the list of entries? + */ public boolean shouldBeDisplayed(GuiScreen screen, EntityPlayer player) { return true; } diff --git a/MODSRC/vazkii/botania/api/internal/DummyMethodHandler.java b/MODSRC/vazkii/botania/api/internal/DummyMethodHandler.java new file mode 100644 index 000000000..c354b1543 --- /dev/null +++ b/MODSRC/vazkii/botania/api/internal/DummyMethodHandler.java @@ -0,0 +1,28 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under a + * Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License + * (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB) + * + * File Created @ [Jan 14, 2014, 6:43:03 PM (GMT)] + */ +package vazkii.botania.api.internal; + +import vazkii.botania.api.page.LexiconPage; +import vazkii.botania.api.page.PageDummy; + +public class DummyMethodHandler implements IInternalMethodHandler { + + @Override + public LexiconPage textPage(String key) { + return dummyPage(key); + } + + private LexiconPage dummyPage(String key) { + return new PageDummy(key); + } + +} diff --git a/MODSRC/vazkii/botania/api/internal/IInternalMethodHandler.java b/MODSRC/vazkii/botania/api/internal/IInternalMethodHandler.java new file mode 100644 index 000000000..9f38f9bfc --- /dev/null +++ b/MODSRC/vazkii/botania/api/internal/IInternalMethodHandler.java @@ -0,0 +1,27 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under a + * Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License + * (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB) + * + * File Created @ [Jan 14, 2014, 6:34:34 PM (GMT)] + */ +package vazkii.botania.api.internal; + +import vazkii.botania.api.page.LexiconPage; + +/** + * Any methods that refer to internal methods in Botania are here. + * This is defaulted to a dummy handler, whose methods do nothing. + * This handler is set to a proper one on PreInit. Make sure to + * make your mod load after Botania if you have any intention of + * doing anythign with this on PreInit. + */ +public interface IInternalMethodHandler { + + public LexiconPage textPage(String key); + +} diff --git a/MODSRC/vazkii/botania/api/page/LexiconPage.java b/MODSRC/vazkii/botania/api/page/LexiconPage.java index 7f86b3d33..952413527 100644 --- a/MODSRC/vazkii/botania/api/page/LexiconPage.java +++ b/MODSRC/vazkii/botania/api/page/LexiconPage.java @@ -21,6 +21,12 @@ public abstract class LexiconPage { this.unlocalizedName = unlocalizedName; } + /** + * Does the rendering for this page. + * @param gui The active GuiScreen + * @param x The leftmost part of the gui. + * @param y The top part of the gui. + */ public abstract void renderScreen(GuiScreen gui, int x, int y); public String getUnlocalizedName() { diff --git a/MODSRC/vazkii/botania/api/page/PageDummy.java b/MODSRC/vazkii/botania/api/page/PageDummy.java new file mode 100644 index 000000000..9d7062e42 --- /dev/null +++ b/MODSRC/vazkii/botania/api/page/PageDummy.java @@ -0,0 +1,32 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under a + * Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License + * (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB) + * + * File Created @ [Jan 14, 2014, 6:41:23 PM (GMT)] + */ +package vazkii.botania.api.page; + +import net.minecraft.client.gui.GuiScreen; + +/** + * A dummy page. It does absolutely nothing and is only + * existant to make sure everything goes right even if + * Botania isn't loaded. + */ +public class PageDummy extends LexiconPage { + + public PageDummy(String unlocalizedName) { + super(unlocalizedName); + } + + @Override + public void renderScreen(GuiScreen gui, int x, int y) { + // NO-OP + } + +} diff --git a/MODSRC/vazkii/botania/common/core/handler/InternalMethodHandler.java b/MODSRC/vazkii/botania/common/core/handler/InternalMethodHandler.java new file mode 100644 index 000000000..1a4fea7aa --- /dev/null +++ b/MODSRC/vazkii/botania/common/core/handler/InternalMethodHandler.java @@ -0,0 +1,25 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under a + * Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License + * (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB) + * + * File Created @ [Jan 14, 2014, 6:44:59 PM (GMT)] + */ +package vazkii.botania.common.core.handler; + +import vazkii.botania.api.internal.IInternalMethodHandler; +import vazkii.botania.api.page.LexiconPage; +import vazkii.botania.common.page.PageText; + +public class InternalMethodHandler implements IInternalMethodHandler { + + @Override + public LexiconPage textPage(String key) { + return new PageText(key); + } + +} diff --git a/MODSRC/vazkii/botania/common/page/PageText.java b/MODSRC/vazkii/botania/common/page/PageText.java new file mode 100644 index 000000000..41cfdbf63 --- /dev/null +++ b/MODSRC/vazkii/botania/common/page/PageText.java @@ -0,0 +1,28 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under a + * Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License + * (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB) + * + * File Created @ [Jan 14, 2014, 6:45:33 PM (GMT)] + */ +package vazkii.botania.common.page; + +import net.minecraft.client.gui.GuiScreen; +import vazkii.botania.api.page.LexiconPage; + +public class PageText extends LexiconPage { + + public PageText(String unlocalizedName) { + super(unlocalizedName); + } + + @Override + public void renderScreen(GuiScreen gui, int x, int y) { + // TODO + } + +}