And some more API work, with Internal Handlers and Lexicon Pages.

This commit is contained in:
Vasco Lavos committed 2014-01-14 18:46:33 +00:00
1 parent 24a1a3c697
commit 0305f7db93
9 files changed
+188 -6

No files matched your search

+18
View File
@@ -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<LexiconCategory> categories = new ArrayList();
private static List<LexiconEntry> 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<LexiconCategory> 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);
@@ -16,11 +16,17 @@ import java.util.List;
public final class LexiconCategory {
public final String tag;
public final String unlocalizedName;
public final List<LexiconEntry> 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;
}
}
+15 -3
View File
@@ -21,21 +21,33 @@ import vazkii.botania.api.page.LexiconPage;
public class LexiconEntry {
public final String id;
public final String unlocalizedName;
public List<LexiconPage> 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;
}
@@ -0,0 +1,28 @@
/**
* This class was created by <Vazkii>. 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);
}
}
@@ -0,0 +1,27 @@
/**
* This class was created by <Vazkii>. 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);
}
@@ -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() {
@@ -0,0 +1,32 @@
/**
* This class was created by <Vazkii>. 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
}
}
@@ -0,0 +1,25 @@
/**
* This class was created by <Vazkii>. 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);
}
}
@@ -0,0 +1,28 @@
/**
* This class was created by <Vazkii>. 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
}
}