mirror of
https://github.com/GTNewHorizons/Mantle.git
synced 2026-11-19 03:39:18 +00:00
Merge branch '1.8_books' into 1.9
This commit is contained in:
commit
3f5459c134
91 files changed
+4457
-167
No files matched your search
@@ -4,6 +4,7 @@ import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.Mod.Instance;
|
||||
import net.minecraftforge.fml.common.SidedProxy;
|
||||
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@@ -31,4 +32,9 @@ public class Mantle {
|
||||
/* Proxies for sides, used for graphics processing */
|
||||
@SidedProxy(clientSide = "slimeknights.mantle.client.ClientProxy", serverSide = "slimeknights.mantle.common.CommonProxy")
|
||||
public static CommonProxy proxy;
|
||||
|
||||
@Mod.EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event){
|
||||
proxy.preInit();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,11 @@
|
||||
package slimeknights.mantle.client;
|
||||
|
||||
import slimeknights.mantle.client.book.BookLoader;
|
||||
import slimeknights.mantle.common.CommonProxy;
|
||||
|
||||
public class ClientProxy extends CommonProxy {
|
||||
@Override
|
||||
public void preInit() {
|
||||
new BookLoader();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package slimeknights.mantle.client.book;
|
||||
|
||||
import java.util.Arrays;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class BookHelper {
|
||||
|
||||
public static String getSavedPage(ItemStack item) {
|
||||
if (item != null && item.hasTagCompound()) {
|
||||
NBTTagCompound mantleBook = item.getTagCompound().getCompoundTag("mantle").getCompoundTag("book");
|
||||
|
||||
if (mantleBook.hasKey("page", Arrays.asList(NBTBase.NBT_TYPES).indexOf("STRING"))) {
|
||||
return mantleBook.getString("page");
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
public static void writeSavedPage(ItemStack item, String page) {
|
||||
NBTTagCompound compound = item.getTagCompound();
|
||||
|
||||
if (compound == null)
|
||||
compound = new NBTTagCompound();
|
||||
|
||||
NBTTagCompound mantle = compound.getCompoundTag("mantle");
|
||||
NBTTagCompound book = mantle.getCompoundTag("book");
|
||||
|
||||
book.setString("page", page);
|
||||
|
||||
mantle.setTag("book", book);
|
||||
compound.setTag("mantle", mantle);
|
||||
item.setTagCompound(compound);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
package slimeknights.mantle.client.book;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import java.util.HashMap;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.resources.IReloadableResourceManager;
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
import net.minecraft.client.resources.IResourceManagerReloadListener;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import slimeknights.mantle.Mantle;
|
||||
import slimeknights.mantle.client.book.action.StringActionProcessor;
|
||||
import slimeknights.mantle.client.book.action.protocol.ProtocolGoToPage;
|
||||
import slimeknights.mantle.client.book.data.BookData;
|
||||
import slimeknights.mantle.client.book.data.PageData;
|
||||
import slimeknights.mantle.client.book.data.SectionData;
|
||||
import slimeknights.mantle.client.book.data.content.ContentBlank;
|
||||
import slimeknights.mantle.client.book.data.content.ContentBlockInteraction;
|
||||
import slimeknights.mantle.client.book.data.content.ContentCrafting;
|
||||
import slimeknights.mantle.client.book.data.content.ContentError;
|
||||
import slimeknights.mantle.client.book.data.content.ContentImage;
|
||||
import slimeknights.mantle.client.book.data.content.ContentImageText;
|
||||
import slimeknights.mantle.client.book.data.content.ContentSmelting;
|
||||
import slimeknights.mantle.client.book.data.content.ContentSmithing;
|
||||
import slimeknights.mantle.client.book.data.content.ContentStructure;
|
||||
import slimeknights.mantle.client.book.data.content.ContentText;
|
||||
import slimeknights.mantle.client.book.data.content.ContentTextImage;
|
||||
import slimeknights.mantle.client.book.data.content.ContentTextLeftImage;
|
||||
import slimeknights.mantle.client.book.data.content.ContentTextRightImage;
|
||||
import slimeknights.mantle.client.book.data.content.PageContent;
|
||||
import slimeknights.mantle.client.book.data.deserializer.HexStringDeserializer;
|
||||
import slimeknights.mantle.client.book.repository.BookRepository;
|
||||
import slimeknights.mantle.network.NetworkWrapper;
|
||||
import slimeknights.mantle.network.book.PacketUpdateSavedPage;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class BookLoader implements IResourceManagerReloadListener {
|
||||
|
||||
/** GSON object to be used for book loading purposes */
|
||||
public static final Gson GSON = new GsonBuilder().registerTypeAdapter(int.class, new HexStringDeserializer()).create();
|
||||
|
||||
/** Maps page content presets to names */
|
||||
private static final HashMap<String, Class<? extends PageContent>> typeToContentMap = new HashMap<>();
|
||||
|
||||
/** Internal registry of all books for the purposes of the reloader, maps books to name */
|
||||
private static final HashMap<String, BookData> books = new HashMap<>();
|
||||
|
||||
private static final NetworkWrapper wrapper = new NetworkWrapper("mantle:books");
|
||||
|
||||
public BookLoader() {
|
||||
((IReloadableResourceManager) Minecraft.getMinecraft().getResourceManager()).registerReloadListener(this);
|
||||
|
||||
wrapper.registerPacketServer(PacketUpdateSavedPage.class);
|
||||
|
||||
// Register page types
|
||||
registerPageType("blank", ContentBlank.class);
|
||||
registerPageType("text", ContentText.class);
|
||||
registerPageType("image", ContentImage.class);
|
||||
registerPageType("image with text below", ContentImageText.class);
|
||||
registerPageType("text with image below", ContentTextImage.class);
|
||||
registerPageType("text with left image etch", ContentTextLeftImage.class);
|
||||
registerPageType("text with right image etch", ContentTextRightImage.class);
|
||||
registerPageType("crafting", ContentCrafting.class);
|
||||
registerPageType("smelting", ContentSmelting.class);
|
||||
registerPageType("smithing", ContentSmithing.class);
|
||||
registerPageType("block interaction", ContentBlockInteraction.class);
|
||||
registerPageType("structure", ContentStructure.class);
|
||||
|
||||
// Register action protocols
|
||||
StringActionProcessor.registerProtocol(new ProtocolGoToPage());
|
||||
StringActionProcessor.registerProtocol(new ProtocolGoToPage(true, "-rtn"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a type of page prefabricate
|
||||
*
|
||||
* @param name The name of the page type
|
||||
* @param clazz The PageContent class for this page type
|
||||
* @RecommendedInvoke init
|
||||
*/
|
||||
public static void registerPageType(String name, Class<? extends PageContent> clazz) {
|
||||
if (typeToContentMap.containsKey(name))
|
||||
throw new IllegalArgumentException("Page type " + name + " already in use.");
|
||||
|
||||
typeToContentMap.put(name, clazz);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a type of page prefabricate by name
|
||||
*
|
||||
* @param name The name of the page type
|
||||
* @return The class of the page type, ContentError.class if page type not registered
|
||||
*/
|
||||
public static Class<? extends PageContent> getPageType(String name) {
|
||||
return typeToContentMap.get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a book to the loader, and returns a reference object
|
||||
* Be warned that the returned BookData object is not immediately populated, and is instead populated when the resources are loaded/reloaded
|
||||
*
|
||||
* @param name The name of the book, modid: will be automatically appended to the front of the name unless that is already added
|
||||
* @param repositories All the repositories the book will load the sections from
|
||||
* @return The book object, not immediately populated
|
||||
*/
|
||||
public static BookData registerBook(String name, BookRepository... repositories) {
|
||||
return registerBook(name, true, true, repositories);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a book to the loader, and returns a reference object
|
||||
* Be warned that the returned BookData object is not immediately populated, and is instead populated when the resources are loaded/reloaded
|
||||
*
|
||||
* @param name The name of the book, modid: will be automatically appended to the front of the name unless that is already added
|
||||
* @param appendIndex Whether an index should be added to the front of the book using a BookTransformer
|
||||
* @param appendContentTable Whether a table of contents should be added to the front of each section using a BookTransformer
|
||||
* @param repositories All the repositories the book will load the sections from
|
||||
* @return The book object, not immediately populated
|
||||
*/
|
||||
public static BookData registerBook(String name, boolean appendIndex, boolean appendContentTable, BookRepository... repositories) {
|
||||
BookData info = new BookData(repositories);
|
||||
|
||||
books.put(name.contains(":") ? name : Loader.instance().activeModContainer().getModId() + ":" + name, info);
|
||||
|
||||
if (appendIndex)
|
||||
info.addTransformer(new BookTransformer.IndexTranformer());
|
||||
if (appendContentTable)
|
||||
info.addTransformer(new BookTransformer.ContentTableTransformer());
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a book by its name
|
||||
*
|
||||
* @param name The name of the book, prefixed with modid:
|
||||
* @return The instance of the book data, or null if the book is not registered
|
||||
*/
|
||||
public static BookData getBook(String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void updateSavedPage(EntityPlayer player, ItemStack item, String page) {
|
||||
if (player.getHeldItem() == null)
|
||||
return;
|
||||
|
||||
BookHelper.writeSavedPage(item, page);
|
||||
wrapper.network.sendToServer(new PacketUpdateSavedPage(page));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads all the books, called when the resource manager reloads, such as when the resource pack or the language is changed
|
||||
*/
|
||||
@Override
|
||||
public void onResourceManagerReload(IResourceManager resourceManager) {
|
||||
Mantle.logger.info("Started loading books...");
|
||||
long time = System.nanoTime();
|
||||
|
||||
for (BookData book : books.values()) {
|
||||
try {
|
||||
book.load();
|
||||
} catch (Exception e) {
|
||||
book.sections.clear();
|
||||
SectionData section = new SectionData(true);
|
||||
section.name = "errorenous";
|
||||
PageData page = new PageData(true);
|
||||
page.name = "errorenous";
|
||||
page.content = new ContentError("Failed to load the book due to an unexpected error.", e);
|
||||
section.pages.add(page);
|
||||
book.sections.add(section);
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
Mantle.logger.info("Book loading completed in " + ((System.nanoTime() - time) / 1000000000D) + " seconds.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package slimeknights.mantle.client.book;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import net.minecraft.stats.StatFileWriter;
|
||||
import slimeknights.mantle.client.book.data.BookData;
|
||||
import slimeknights.mantle.client.book.data.PageData;
|
||||
import slimeknights.mantle.client.book.data.SectionData;
|
||||
import slimeknights.mantle.client.book.data.content.ContentSectionList;
|
||||
import slimeknights.mantle.client.book.data.content.ContentTableOfContents;
|
||||
import slimeknights.mantle.client.book.data.element.TextData;
|
||||
|
||||
public abstract class BookTransformer {
|
||||
|
||||
/**
|
||||
* Called when all the sections within the book are loaded.
|
||||
*
|
||||
* @param book The object to the book to be transformed
|
||||
*/
|
||||
public abstract void transform(BookData book);
|
||||
|
||||
protected static class IndexTranformer extends BookTransformer {
|
||||
|
||||
@Override
|
||||
public void transform(BookData book) {
|
||||
SectionData index = new SectionData(true) {
|
||||
@Override
|
||||
public void update(StatFileWriter writer) {
|
||||
pages.clear();
|
||||
|
||||
List<SectionData> visibleSections = parent.getVisibleSections(writer);
|
||||
|
||||
if (visibleSections.isEmpty())
|
||||
return;
|
||||
|
||||
visibleSections.remove(0);
|
||||
|
||||
PageData[] pages = new PageData[(int) Math.ceil(visibleSections.size() / 9F)];
|
||||
|
||||
for (int i = 0; i < pages.length; i++) {
|
||||
pages[i] = new PageData(true);
|
||||
|
||||
pages[i].name = "page" + (i + 1);
|
||||
|
||||
ContentSectionList content = new ContentSectionList();
|
||||
pages[i].content = content;
|
||||
|
||||
for (int j = i * 9; j - i * 9 < 9 && j < visibleSections.size(); j++) {
|
||||
content.addSection(visibleSections.get(j));
|
||||
}
|
||||
}
|
||||
|
||||
this.pages = new ArrayList<>(Arrays.asList(pages));
|
||||
}
|
||||
};
|
||||
|
||||
index.name = "index";
|
||||
book.sections.add(0, index);
|
||||
}
|
||||
}
|
||||
|
||||
protected static class ContentTableTransformer extends BookTransformer {
|
||||
|
||||
@Override
|
||||
public void transform(BookData book) {
|
||||
final int ENTRIES_PER_PAGE = 24;
|
||||
|
||||
for (SectionData section : book.sections) {
|
||||
if (section.name.equals("index"))
|
||||
continue;
|
||||
|
||||
int genPages = (int) Math.ceil(section.getPageCount() * 1.F / ENTRIES_PER_PAGE);
|
||||
|
||||
if (genPages == 0)
|
||||
continue;
|
||||
|
||||
PageData[] pages = new PageData[genPages];
|
||||
|
||||
for (int i = 0; i < pages.length; i++) {
|
||||
pages[i] = new PageData(true);
|
||||
pages[i].name = "tableofcontents" + i;
|
||||
TextData[] text = new TextData[i > pages.length - 1 ? ENTRIES_PER_PAGE : section.getPageCount() - (genPages - 1) * ENTRIES_PER_PAGE];
|
||||
for (int j = 0; j < text.length; j++) {
|
||||
text[j] = new TextData((i * ENTRIES_PER_PAGE + j + 1) + ". " + section.pages.get(i * ENTRIES_PER_PAGE + j).getTitle());
|
||||
text[j].action = "go-to-page-rtn:" + section.name + "." + section.pages.get(i * ENTRIES_PER_PAGE + j).name;
|
||||
}
|
||||
|
||||
pages[i].content = new ContentTableOfContents(i == 0 ? section.getTitle() : "", text);
|
||||
}
|
||||
|
||||
for (int i = pages.length - 1; i >= 0; i--) {
|
||||
section.pages.add(0, pages[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package slimeknights.mantle.client.book.action;
|
||||
|
||||
import java.util.HashMap;
|
||||
import slimeknights.mantle.client.book.action.protocol.ActionProtocol;
|
||||
import slimeknights.mantle.client.gui.book.GuiBook;
|
||||
|
||||
public class StringActionProcessor {
|
||||
|
||||
public static final String PROTOCOL_SEPARATOR = ":";
|
||||
|
||||
private static final HashMap<String, ActionProtocol> protocols = new HashMap<>();
|
||||
|
||||
public static void registerProtocol(ActionProtocol protocol) {
|
||||
if (protocol == null || protocol.protocol == null || protocol.protocol.isEmpty())
|
||||
throw new IllegalArgumentException("Protocol must be defined and must not have an empty protocol identifier.");
|
||||
if (protocols.containsKey(protocol.protocol))
|
||||
throw new IllegalArgumentException("Protocol " + protocol.protocol + " already registered.");
|
||||
|
||||
protocols.put(protocol.protocol, protocol);
|
||||
}
|
||||
|
||||
//Format: action://param
|
||||
public static void process(String action, GuiBook book) {
|
||||
if (!action.contains(PROTOCOL_SEPARATOR))
|
||||
return;
|
||||
|
||||
String protoId = action.substring(0, action.indexOf(PROTOCOL_SEPARATOR));
|
||||
String protoParam = action.substring(action.indexOf(PROTOCOL_SEPARATOR) + PROTOCOL_SEPARATOR.length());
|
||||
|
||||
if (protocols.containsKey(protoId))
|
||||
protocols.get(protoId).processCommand(book, protoParam);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package slimeknights.mantle.client.book.action.protocol;
|
||||
|
||||
import slimeknights.mantle.client.gui.book.GuiBook;
|
||||
|
||||
public abstract class ActionProtocol {
|
||||
|
||||
public final String protocol;
|
||||
|
||||
public ActionProtocol(String protocol) {
|
||||
this.protocol = protocol;
|
||||
}
|
||||
|
||||
public abstract void processCommand(GuiBook book, String param);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package slimeknights.mantle.client.book.action.protocol;
|
||||
|
||||
import slimeknights.mantle.client.gui.book.GuiBook;
|
||||
|
||||
public class ProtocolGoToPage extends ActionProtocol {
|
||||
|
||||
private final boolean returner;
|
||||
|
||||
public ProtocolGoToPage() {
|
||||
this(false, "");
|
||||
}
|
||||
|
||||
public ProtocolGoToPage(boolean returner, String suffix) {
|
||||
super("go-to-page" + suffix);
|
||||
|
||||
this.returner = returner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCommand(GuiBook book, String param) {
|
||||
int pageNum = book.book.findPageNumber(param);
|
||||
|
||||
if (pageNum >= 0)
|
||||
book.openPage(pageNum, returner);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package slimeknights.mantle.client.book.data;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class AppearanceData implements IDataItem {
|
||||
|
||||
public int coverColor = 0x8B4631;
|
||||
public int arrowColor = 0xFFFFD3;
|
||||
public int arrowColorHover = 0xFF541C;
|
||||
public int lockedSectionColor = 0x000000;
|
||||
public String title = "";
|
||||
public String subtitle = "";
|
||||
public boolean drawPageNumbers = true;
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,292 @@
|
||||
package slimeknights.mantle.client.book.data;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.stats.StatFileWriter;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import slimeknights.mantle.client.book.BookLoader;
|
||||
import slimeknights.mantle.client.book.BookTransformer;
|
||||
import slimeknights.mantle.client.book.data.content.ContentError;
|
||||
import slimeknights.mantle.client.book.data.element.ItemStackData;
|
||||
import slimeknights.mantle.client.book.repository.BookRepository;
|
||||
import slimeknights.mantle.client.gui.book.GuiBook;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class BookData implements IDataItem {
|
||||
|
||||
public transient int unnamedSectionCounter = 0;
|
||||
public transient ArrayList<SectionData> sections = new ArrayList<>();
|
||||
public transient AppearanceData appearance = new AppearanceData();
|
||||
public transient ArrayList<ItemStackData.ItemLink> itemLinks = new ArrayList<>();
|
||||
public transient HashMap<String, String> strings = new HashMap<>();
|
||||
|
||||
protected final transient ArrayList<BookTransformer> transformers = new ArrayList<>();
|
||||
|
||||
private ArrayList<BookRepository> repositories;
|
||||
|
||||
public BookData(BookRepository... repositories) {
|
||||
this.repositories = new ArrayList<>(Arrays.asList(repositories));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
sections.clear();
|
||||
appearance = new AppearanceData();
|
||||
itemLinks.clear();
|
||||
|
||||
for (BookRepository repo : repositories) {
|
||||
try {
|
||||
List<SectionData> repoContents = repo.getSections();
|
||||
sections.addAll(repoContents);
|
||||
|
||||
for (SectionData section : repoContents) {
|
||||
section.source = repo;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
SectionData error = new SectionData();
|
||||
error.name = "errorenous";
|
||||
PageData page = new PageData(true);
|
||||
page.name = "errorenous";
|
||||
page.content = new ContentError("Failed to load repository " + repo.toString() + ".", e);
|
||||
error.pages.add(page);
|
||||
sections.add(error);
|
||||
}
|
||||
|
||||
ResourceLocation appearanceLocation = repo.getResourceLocation("appearance.json");
|
||||
|
||||
if (repo.resourceExists(appearanceLocation))
|
||||
try {
|
||||
appearance = BookLoader.GSON.fromJson(repo.resourceToString(repo.getResource(appearanceLocation)), AppearanceData.class);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
||||
appearance.load();
|
||||
|
||||
ResourceLocation itemLinkLocation = repo.getResourceLocation("items.json");
|
||||
|
||||
if (repo.resourceExists(itemLinkLocation)) {
|
||||
try {
|
||||
itemLinks = new ArrayList<>(Arrays.asList(BookLoader.GSON.fromJson(repo.resourceToString(repo.getResource(itemLinkLocation)), ItemStackData.ItemLink[].class)));
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
ResourceLocation languageLocation = repo.getResourceLocation("language.lang");
|
||||
|
||||
if (repo.resourceExists(languageLocation)) {
|
||||
try {
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(repo.getResource(languageLocation).getInputStream()));
|
||||
|
||||
String next = br.readLine();
|
||||
|
||||
while (next != null) {
|
||||
if (!next.startsWith("//") && next.contains("=")) {
|
||||
String key = next.substring(0, next.indexOf('='));
|
||||
String value = next.substring(next.indexOf('=') + 1);
|
||||
|
||||
strings.put(key, value);
|
||||
}
|
||||
|
||||
next = br.readLine();
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (SectionData section : sections) {
|
||||
if (section.source == null)
|
||||
section.source = BookRepository.DUMMY;
|
||||
|
||||
section.parent = this;
|
||||
section.load();
|
||||
}
|
||||
|
||||
for (BookTransformer transformer : transformers)
|
||||
transformer.transform(this);
|
||||
|
||||
// Loads orphaned sections, unless something went wrong, that would only be sections added by a transformer
|
||||
for (SectionData section : sections) {
|
||||
if (section.source == null)
|
||||
section.source = BookRepository.DUMMY;
|
||||
|
||||
if (section.parent == null) {
|
||||
section.parent = this;
|
||||
section.load();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public SectionData findSection(String name) {
|
||||
return findSection(name, null);
|
||||
}
|
||||
|
||||
public SectionData findSection(String name, @Nullable StatFileWriter writer) {
|
||||
for (SectionData section : sections) {
|
||||
section.update(writer);
|
||||
|
||||
if (section.name.equals(name.toLowerCase()))
|
||||
return section.isUnlocked(writer) ? section : null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getFirstPageNumber(SectionData section) {
|
||||
return getFirstPageNumber(section, null);
|
||||
}
|
||||
|
||||
public int getFirstPageNumber(SectionData section, @Nullable StatFileWriter writer) {
|
||||
int pages = 0;
|
||||
for (SectionData sect : sections) {
|
||||
sect.update(writer);
|
||||
|
||||
if (section == sect)
|
||||
return section.isUnlocked(writer) ? pages + 1 : -1;
|
||||
|
||||
if (!sect.isUnlocked(writer))
|
||||
continue;
|
||||
|
||||
pages += sect.getPageCount();
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public PageData findPage(int number) {
|
||||
return findPage(number, null);
|
||||
}
|
||||
|
||||
public PageData findPage(int number, @Nullable StatFileWriter writer) {
|
||||
if (number < 0)
|
||||
return null;
|
||||
|
||||
int pages = 0;
|
||||
for (SectionData section : sections) {
|
||||
section.update(writer);
|
||||
|
||||
if (!section.isUnlocked(writer))
|
||||
continue;
|
||||
|
||||
if (pages + section.getPageCount() > number)
|
||||
return section.pages.get(number - pages);
|
||||
else
|
||||
pages += section.getPageCount();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public PageData findPage(String location) {
|
||||
return findPage(location, null);
|
||||
}
|
||||
|
||||
public PageData findPage(String location, @Nullable StatFileWriter writer) {
|
||||
return findPage(findPageNumber(location, writer));
|
||||
}
|
||||
|
||||
public int findPageNumber(String location) {
|
||||
return findPageNumber(location, null);
|
||||
}
|
||||
|
||||
public int findPageNumber(String location, @Nullable StatFileWriter writer) {
|
||||
location = location.toLowerCase();
|
||||
|
||||
int pages = 0;
|
||||
|
||||
if (!location.contains("."))
|
||||
return -1;
|
||||
|
||||
String sectionName = location.substring(0, location.indexOf('.'));
|
||||
String pageName = location.substring(location.indexOf('.') + 1);
|
||||
|
||||
for (SectionData section : sections) {
|
||||
section.update(writer);
|
||||
|
||||
if (!section.isUnlocked(writer))
|
||||
continue;
|
||||
|
||||
if (!sectionName.equals(section.name)) {
|
||||
pages += section.getPageCount();
|
||||
continue;
|
||||
}
|
||||
|
||||
for (PageData page : section.pages) {
|
||||
if (!pageName.equals(page.name)) {
|
||||
pages++;
|
||||
continue;
|
||||
}
|
||||
|
||||
return pages + 1;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int getPageCount() {
|
||||
return getPageCount(null);
|
||||
}
|
||||
|
||||
public int getPageCount(@Nullable StatFileWriter writer) {
|
||||
int pages = 0;
|
||||
for (SectionData section : sections) {
|
||||
section.update(writer);
|
||||
|
||||
pages += section.isUnlocked(writer) ? section.getPageCount() : 0;
|
||||
}
|
||||
return pages;
|
||||
}
|
||||
|
||||
public int getFullPageCount() {
|
||||
return getFullPageCount(null);
|
||||
}
|
||||
|
||||
public int getFullPageCount(@Nullable StatFileWriter writer) {
|
||||
return (int) Math.ceil((getPageCount(writer) - 1) / 2F) + 1;
|
||||
}
|
||||
|
||||
public String getItemAction(ItemStackData item) {
|
||||
for (ItemStackData.ItemLink link : itemLinks) {
|
||||
if (item.id.equals(link.item.id) && (!link.damageSensitive || item.damage == link.item.damage))
|
||||
return link.action;
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
public List<SectionData> getVisibleSections(StatFileWriter writer) {
|
||||
List<SectionData> visible = new ArrayList<>();
|
||||
|
||||
for (SectionData section : sections) {
|
||||
if (section.isUnlocked(writer) || !section.hideWhenLocked)
|
||||
visible.add(section);
|
||||
}
|
||||
|
||||
return visible;
|
||||
}
|
||||
|
||||
public void openGui(@Nullable ItemStack item) {
|
||||
if (Minecraft.getMinecraft().thePlayer != null)
|
||||
Minecraft.getMinecraft().displayGuiScreen(new GuiBook(this, Minecraft.getMinecraft().thePlayer.getStatFileWriter(), item));
|
||||
}
|
||||
|
||||
public void addRepository(BookRepository repository) {
|
||||
if (repository != null && !this.repositories.contains(repository))
|
||||
this.repositories.add(repository);
|
||||
}
|
||||
|
||||
public void addTransformer(BookTransformer transformer) {
|
||||
if (transformer != null && !transformers.contains(transformer))
|
||||
transformers.add(transformer);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package slimeknights.mantle.client.book.data;
|
||||
|
||||
public class BookmarkData {
|
||||
|
||||
public String text = "";
|
||||
public int color = 0x464646; // Index bookmark : 0x1ED400
|
||||
public String page = "";
|
||||
|
||||
public BookmarkData() {
|
||||
this("");
|
||||
}
|
||||
|
||||
public BookmarkData(String page) {
|
||||
this(page, "");
|
||||
}
|
||||
|
||||
public BookmarkData(String page, String text) {
|
||||
this.page = page;
|
||||
this.text = text;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package slimeknights.mantle.client.book.data;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public interface IDataItem {
|
||||
|
||||
void load();
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
package slimeknights.mantle.client.book.data;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import net.minecraft.client.resources.IResource;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import slimeknights.mantle.client.book.BookLoader;
|
||||
import slimeknights.mantle.client.book.data.content.ContentError;
|
||||
import slimeknights.mantle.client.book.data.content.PageContent;
|
||||
import slimeknights.mantle.client.book.data.element.BlockData;
|
||||
import slimeknights.mantle.client.book.data.element.DataLocation;
|
||||
import slimeknights.mantle.client.book.data.element.ItemStackData;
|
||||
import slimeknights.mantle.client.book.repository.BookRepository;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class PageData implements IDataItem {
|
||||
|
||||
private static final transient ArrayList<ValueHotswap> hotswaps = new ArrayList<>();
|
||||
|
||||
public String name = null;
|
||||
public String type = "";
|
||||
public String data = "";
|
||||
|
||||
public transient SectionData parent;
|
||||
public transient BookRepository source;
|
||||
public transient PageContent content;
|
||||
|
||||
public PageData() {
|
||||
this(false);
|
||||
}
|
||||
|
||||
public PageData(boolean custom) {
|
||||
if (custom)
|
||||
data = "no-load";
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void load() {
|
||||
if (name == null)
|
||||
name = "page" + parent.unnamedPageCounter++;
|
||||
|
||||
name = name.toLowerCase();
|
||||
|
||||
if (!data.equals("no-load")) {
|
||||
IResource pageInfo = source.getResource(source.getResourceLocation(data));
|
||||
if (pageInfo != null) {
|
||||
String data = source.resourceToString(pageInfo);
|
||||
if (!data.isEmpty()) {
|
||||
Class<? extends PageContent> ctype = BookLoader.getPageType(type);
|
||||
|
||||
try {
|
||||
content = BookLoader.GSON.fromJson(data, ctype);
|
||||
} catch (Exception e) {
|
||||
content = new ContentError(ctype == null ? "Failed to create a page of type \"" + type + "\", perhaps the type is not registered?" : "Failed to create a page of type \"" + type + "\", perhaps the page file \"" + this.data + "\" is missing or invalid?", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (content == null) {
|
||||
try {
|
||||
content = BookLoader.getPageType(type).newInstance();
|
||||
} catch (InstantiationException | IllegalAccessException | NullPointerException e) {
|
||||
content = new ContentError("Failed to create a page of type \"" + type + "\", perhaps the type is not registered?");
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
content.parent = this;
|
||||
content.load();
|
||||
} catch (Exception e) {
|
||||
content = new ContentError("Failed to load page " + parent.name + "." + name + ".", e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
content.source = source;
|
||||
|
||||
for (Field f : content.getClass().getFields()) {
|
||||
if (Modifier.isTransient(f.getModifiers()) || Modifier.isStatic(f.getModifiers()) || Modifier.isFinal(f.getModifiers()))
|
||||
continue;
|
||||
|
||||
try {
|
||||
if (f.get(content) == null)
|
||||
continue;
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
for (ValueHotswap swap : hotswaps) {
|
||||
Class<?> c = f.getType();
|
||||
|
||||
if (c.isArray() && c.getComponentType().isAssignableFrom(swap.t))
|
||||
try {
|
||||
f.setAccessible(true);
|
||||
Object[] o = (Object[]) f.get(content);
|
||||
|
||||
for (Object ob : o)
|
||||
swap.swap(source, ob);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
else if (swap.t.isAssignableFrom(c)) {
|
||||
try {
|
||||
f.setAccessible(true);
|
||||
Object o = f.get(content);
|
||||
|
||||
swap.swap(source, o);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void addSwap(Class<?> t, Class<? extends ValueHotswap> swap) {
|
||||
try {
|
||||
ValueHotswap hotswap = swap.newInstance();
|
||||
hotswap.t = t;
|
||||
|
||||
hotswaps.add(hotswap);
|
||||
} catch (InstantiationException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
String title = parent.parent.strings.get(parent.name + "." + name);
|
||||
return title == null ? name : title;
|
||||
}
|
||||
|
||||
static {
|
||||
addSwap(DataLocation.class, new ValueHotswap<DataLocation>() {
|
||||
@Override
|
||||
public void swap(BookRepository source, DataLocation object) {
|
||||
object.location = source.getResourceLocation(object.file, true);
|
||||
}
|
||||
}.getClass());
|
||||
addSwap(ItemStackData.class, new ValueHotswap<ItemStackData>() {
|
||||
@Override
|
||||
public void swap(BookRepository source, ItemStackData object) {
|
||||
object.source = source;
|
||||
object.itemListLocation = source.getResourceLocation(object.itemList);
|
||||
|
||||
if (object.itemListLocation != null)
|
||||
object.id = "->itemList";
|
||||
}
|
||||
}.getClass());
|
||||
addSwap(BlockData.class, new ValueHotswap<BlockData>() {
|
||||
@Override
|
||||
public void swap(BookRepository source, BlockData object) {
|
||||
if (object.endPos == null)
|
||||
object.endPos = object.pos;
|
||||
}
|
||||
}.getClass());
|
||||
}
|
||||
|
||||
public static abstract class ValueHotswap<T> {
|
||||
|
||||
protected Class<?> t;
|
||||
|
||||
public abstract void swap(BookRepository source, T object);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
package slimeknights.mantle.client.book.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.client.resources.IResource;
|
||||
import net.minecraft.stats.Achievement;
|
||||
import net.minecraft.stats.AchievementList;
|
||||
import net.minecraft.stats.StatFileWriter;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import slimeknights.mantle.client.book.BookLoader;
|
||||
import slimeknights.mantle.client.book.data.content.ContentError;
|
||||
import slimeknights.mantle.client.book.data.element.ImageData;
|
||||
import slimeknights.mantle.client.book.repository.BookRepository;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class SectionData implements IDataItem {
|
||||
|
||||
public String name = null;
|
||||
public ImageData icon = new ImageData();
|
||||
public String[] requirements = new String[0];
|
||||
public boolean hideWhenLocked = false;
|
||||
public String data = "";
|
||||
|
||||
public transient int unnamedPageCounter = 0;
|
||||
public transient BookData parent;
|
||||
public transient BookRepository source;
|
||||
public transient ArrayList<PageData> pages = new ArrayList<>();
|
||||
|
||||
public SectionData() {
|
||||
this(false);
|
||||
}
|
||||
|
||||
public SectionData(boolean custom) {
|
||||
if (custom)
|
||||
data = "no-load";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
if (name == null)
|
||||
name = "section" + parent.unnamedSectionCounter++;
|
||||
|
||||
name = name.toLowerCase();
|
||||
|
||||
if (!data.equals("no-load")) {
|
||||
IResource pagesInfo = source.getResource(source.getResourceLocation(data));
|
||||
if (pagesInfo != null) {
|
||||
String data = source.resourceToString(pagesInfo);
|
||||
if (!data.isEmpty())
|
||||
try {
|
||||
pages = new ArrayList<>(Arrays.asList(BookLoader.GSON.fromJson(data, PageData[].class)));
|
||||
} catch (Exception e) {
|
||||
pages = new ArrayList<>();
|
||||
PageData pdError = new PageData(true);
|
||||
pdError.name = "errorrenous";
|
||||
pdError.content = new ContentError("Failed to load section " + name + ".", e);
|
||||
pages.add(pdError);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (PageData page : pages) {
|
||||
page.parent = this;
|
||||
page.source = source;
|
||||
page.load();
|
||||
}
|
||||
|
||||
icon.location = source.getResourceLocation(icon.file, true);
|
||||
}
|
||||
|
||||
public void update(@Nullable StatFileWriter writer) {
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
String title = parent.strings.get(name);
|
||||
return title == null ? name : title;
|
||||
}
|
||||
|
||||
public int getPageCount() {
|
||||
return pages.size();
|
||||
}
|
||||
|
||||
public boolean isUnlocked(StatFileWriter writer) {
|
||||
if (writer == null || requirements == null || requirements.length == 0)
|
||||
return true;
|
||||
|
||||
for (String achievement : requirements) {
|
||||
if (!requirementSatisfied(achievement, writer))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean requirementSatisfied(String requirement, StatFileWriter writer) {
|
||||
if (writer == null)
|
||||
return true;
|
||||
|
||||
Achievement achievement = findAchievement(requirement);
|
||||
|
||||
return achievement == null || writer.hasAchievementUnlocked(achievement);
|
||||
|
||||
}
|
||||
|
||||
public static Achievement findAchievement(String name) {
|
||||
if (name == null || name.isEmpty())
|
||||
return null;
|
||||
|
||||
for (Achievement achievement : AchievementList.achievementList) {
|
||||
if (achievement.statId.equals(name))
|
||||
return achievement;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package slimeknights.mantle.client.book.data.content;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import slimeknights.mantle.client.book.data.BookData;
|
||||
import slimeknights.mantle.client.gui.book.element.BookElement;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class ContentBlank extends PageContent {
|
||||
|
||||
@Override
|
||||
public void build(BookData book, ArrayList<BookElement> list) {
|
||||
}
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
package slimeknights.mantle.client.book.data.content;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import slimeknights.mantle.client.book.data.BookData;
|
||||
import slimeknights.mantle.client.book.data.element.ImageData;
|
||||
import slimeknights.mantle.client.book.data.element.ItemStackData;
|
||||
import slimeknights.mantle.client.book.data.element.TextData;
|
||||
import slimeknights.mantle.client.gui.book.GuiBook;
|
||||
import slimeknights.mantle.client.gui.book.element.BookElement;
|
||||
import slimeknights.mantle.client.gui.book.element.ElementImage;
|
||||
import slimeknights.mantle.client.gui.book.element.ElementItem;
|
||||
import slimeknights.mantle.client.gui.book.element.ElementText;
|
||||
import static slimeknights.mantle.client.gui.book.Textures.TEX_MISC;
|
||||
|
||||
public class ContentBlockInteraction extends PageContent {
|
||||
|
||||
public static final transient int TEX_SIZE = 512;
|
||||
public static final transient ImageData IMG_SMITHING = new ImageData(TEX_MISC, 0, 0, 88, 55, TEX_SIZE, TEX_SIZE);
|
||||
|
||||
public static final transient int INPUT_X = 6;
|
||||
public static final transient int INPUT_Y = 18;
|
||||
public static final transient int BLOCK_X = 40;
|
||||
public static final transient int BLOCK_Y = 26;
|
||||
|
||||
public static final transient float ITEM_SCALE = 2.0F;
|
||||
public static final transient float BLOCK_SCALE = 5.0F;
|
||||
|
||||
public String title = "Block Interaction";
|
||||
public ItemStackData input;
|
||||
public ItemStackData block;
|
||||
public TextData[] description;
|
||||
|
||||
@Override
|
||||
public void build(BookData book, ArrayList<BookElement> list) {
|
||||
int x = GuiBook.PAGE_WIDTH / 2 - IMG_SMITHING.width / 2 - 10;
|
||||
int y = TITLE_HEIGHT;
|
||||
|
||||
if (title == null || title.isEmpty())
|
||||
y = 0;
|
||||
else
|
||||
addTitle(list, title);
|
||||
|
||||
list.add(new ElementImage(x, y, IMG_SMITHING.width, IMG_SMITHING.height, IMG_SMITHING, book.appearance.coverColor));
|
||||
|
||||
if (input != null && !input.id.equals("")) {
|
||||
list.add(new ElementItem(x + INPUT_X, y + INPUT_Y, ITEM_SCALE, input.getItems(), input.action));
|
||||
}
|
||||
|
||||
if (block != null && !block.id.equals("")) {
|
||||
list.add(new ElementItem(x + BLOCK_X, y + BLOCK_Y, BLOCK_SCALE, block.getItems(), block.action));
|
||||
}
|
||||
|
||||
if (description != null && description.length > 0) {
|
||||
list.add(new ElementText(0, IMG_SMITHING.height + y + 50, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT - IMG_SMITHING.height - y - 50, description));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package slimeknights.mantle.client.book.data.content;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import slimeknights.mantle.client.book.data.BookData;
|
||||
import slimeknights.mantle.client.book.data.element.ImageData;
|
||||
import slimeknights.mantle.client.book.data.element.ItemStackData;
|
||||
import slimeknights.mantle.client.book.data.element.TextData;
|
||||
import slimeknights.mantle.client.gui.book.GuiBook;
|
||||
import slimeknights.mantle.client.gui.book.element.BookElement;
|
||||
import slimeknights.mantle.client.gui.book.element.ElementImage;
|
||||
import slimeknights.mantle.client.gui.book.element.ElementItem;
|
||||
import slimeknights.mantle.client.gui.book.element.ElementText;
|
||||
import static slimeknights.mantle.client.gui.book.Textures.TEX_CRAFTING;
|
||||
|
||||
public class ContentCrafting extends PageContent {
|
||||
|
||||
public static final transient int TEX_SIZE = 256;
|
||||
public static final transient ImageData IMG_CRAFTING_LARGE = new ImageData(TEX_CRAFTING, 0, 0, 183, 114, TEX_SIZE, TEX_SIZE);
|
||||
public static final transient ImageData IMG_CRAFTING_SMALL = new ImageData(TEX_CRAFTING, 0, 114, 155, 78, TEX_SIZE, TEX_SIZE);
|
||||
|
||||
public static final transient int X_RESULT_SMALL = 118;
|
||||
public static final transient int Y_RESULT_SMALL = 23;
|
||||
public static final transient int X_RESULT_LARGE = 146;
|
||||
public static final transient int Y_RESULT_LARGE = 41;
|
||||
|
||||
public static final transient float ITEM_SCALE = 2.0F;
|
||||
public static final transient int SLOT_MARGIN = 5;
|
||||
public static final transient int SLOT_PADDING = 4;
|
||||
|
||||
public String title = "Crafting";
|
||||
public String grid_size = "large";
|
||||
public ItemStackData[][] grid;
|
||||
public ItemStackData result;
|
||||
public TextData[] description;
|
||||
|
||||
@Override
|
||||
public void build(BookData book, ArrayList<BookElement> list) {
|
||||
int x = 0;
|
||||
int y = 16;
|
||||
int height = 100;
|
||||
int resultX = 100;
|
||||
int resultY = 50;
|
||||
|
||||
TextData tdTitle = new TextData(title);
|
||||
tdTitle.underlined = true;
|
||||
list.add(new ElementText(0, 0, GuiBook.PAGE_WIDTH, 9, new TextData[]{tdTitle}));
|
||||
|
||||
if (grid_size.equalsIgnoreCase("small")) {
|
||||
x = GuiBook.PAGE_WIDTH / 2 - IMG_CRAFTING_SMALL.width / 2;
|
||||
height = y + IMG_CRAFTING_SMALL.height;
|
||||
list.add(new ElementImage(x, y, IMG_CRAFTING_SMALL.width, IMG_CRAFTING_SMALL.height, IMG_CRAFTING_SMALL, book.appearance.coverColor));
|
||||
resultX = x + X_RESULT_SMALL;
|
||||
resultY = y + Y_RESULT_SMALL;
|
||||
} else if (grid_size.equalsIgnoreCase("large")) {
|
||||
x = GuiBook.PAGE_WIDTH / 2 - IMG_CRAFTING_LARGE.width / 2;
|
||||
height = y + IMG_CRAFTING_LARGE.height;
|
||||
list.add(new ElementImage(x, y, IMG_CRAFTING_LARGE.width, IMG_CRAFTING_LARGE.height, IMG_CRAFTING_LARGE, book.appearance.coverColor));
|
||||
resultX = x + X_RESULT_LARGE;
|
||||
resultY = y + Y_RESULT_LARGE;
|
||||
}
|
||||
|
||||
if (grid != null)
|
||||
for (int i = 0; i < grid.length; i++) {
|
||||
for (int j = 0; j < grid[i].length; j++) {
|
||||
if (grid[i][j].id.equals(""))
|
||||
continue;
|
||||
list.add(new ElementItem(x + SLOT_MARGIN + (SLOT_PADDING + Math.round(ElementItem.ITEM_SIZE_HARDCODED * ITEM_SCALE)) * j, y + SLOT_MARGIN + (SLOT_PADDING + Math.round(ElementItem.ITEM_SIZE_HARDCODED * ITEM_SCALE)) * i, ITEM_SCALE, grid[i][j].getItems(), grid[i][j].action));
|
||||
}
|
||||
}
|
||||
|
||||
if (result != null) {
|
||||
list.add(new ElementItem(resultX, resultY, ITEM_SCALE, result.getItems(), result.action));
|
||||
}
|
||||
|
||||
if (description != null && description.length > 0) {
|
||||
list.add(new ElementText(0, height + 5, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT - height - 5, description));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package slimeknights.mantle.client.book.data.content;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import slimeknights.mantle.client.book.data.BookData;
|
||||
import slimeknights.mantle.client.gui.book.element.BookElement;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class ContentDummy extends PageContent {
|
||||
|
||||
@Override
|
||||
public void build(BookData book, ArrayList<BookElement> list) {
|
||||
//TODO load from JSON
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package slimeknights.mantle.client.book.data.content;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import slimeknights.mantle.client.book.data.BookData;
|
||||
import slimeknights.mantle.client.book.data.element.TextData;
|
||||
import slimeknights.mantle.client.gui.book.GuiBook;
|
||||
import slimeknights.mantle.client.gui.book.element.BookElement;
|
||||
import slimeknights.mantle.client.gui.book.element.ElementText;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class ContentError extends PageContent {
|
||||
|
||||
private String errorStage;
|
||||
private Exception exception;
|
||||
|
||||
public ContentError(String errorStage) {
|
||||
this.errorStage = errorStage;
|
||||
}
|
||||
|
||||
public ContentError(String errorStage, Exception e) {
|
||||
this(errorStage);
|
||||
this.exception = e;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(BookData book, ArrayList<BookElement> list) {
|
||||
addTitle(list, "Error");
|
||||
|
||||
TextData[] text = new TextData[1 + (exception != null ? 2 : 0)];
|
||||
text[0] = new TextData(errorStage);
|
||||
text[0].color = "dark_red";
|
||||
text[0].underlined = true;
|
||||
|
||||
if (exception != null) {
|
||||
text[1] = new TextData("The following error has occured: ");
|
||||
text[1].color = "dark_red";
|
||||
text[1].paragraph = true;
|
||||
|
||||
text[2] = new TextData(exception.getMessage() != null ? exception.getMessage() : exception.getClass().getSimpleName());
|
||||
text[2].color = "dark_red";
|
||||
text[2].paragraph = true;
|
||||
}
|
||||
|
||||
list.add(new ElementText(0, TITLE_HEIGHT, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT - TITLE_HEIGHT, text));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package slimeknights.mantle.client.book.data.content;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import slimeknights.mantle.client.book.data.BookData;
|
||||
import slimeknights.mantle.client.book.data.element.ImageData;
|
||||
import slimeknights.mantle.client.gui.book.GuiBook;
|
||||
import slimeknights.mantle.client.gui.book.element.BookElement;
|
||||
import slimeknights.mantle.client.gui.book.element.ElementImage;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class ContentImage extends PageContent {
|
||||
|
||||
public String title = null;
|
||||
public ImageData image;
|
||||
|
||||
@Override
|
||||
public void build(BookData book, ArrayList<BookElement> list) {
|
||||
int y = TITLE_HEIGHT;
|
||||
|
||||
if (title == null || title.isEmpty())
|
||||
y = 0;
|
||||
else
|
||||
addTitle(list, title);
|
||||
|
||||
if (image != null && image.location != null)
|
||||
list.add(new ElementImage(0, y, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT - y, image));
|
||||
else
|
||||
list.add(new ElementImage(ImageData.MISSING));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package slimeknights.mantle.client.book.data.content;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import slimeknights.mantle.client.book.data.BookData;
|
||||
import slimeknights.mantle.client.book.data.element.ImageData;
|
||||
import slimeknights.mantle.client.book.data.element.TextData;
|
||||
import slimeknights.mantle.client.gui.book.GuiBook;
|
||||
import slimeknights.mantle.client.gui.book.element.BookElement;
|
||||
import slimeknights.mantle.client.gui.book.element.ElementImage;
|
||||
import slimeknights.mantle.client.gui.book.element.ElementText;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class ContentImageText extends PageContent {
|
||||
|
||||
public String title = null;
|
||||
public ImageData image;
|
||||
public TextData[] text;
|
||||
|
||||
@Override
|
||||
public void build(BookData book, ArrayList<BookElement> list) {
|
||||
int y = TITLE_HEIGHT;
|
||||
|
||||
if (title == null || title.isEmpty())
|
||||
y = 0;
|
||||
else
|
||||
addTitle(list, title);
|
||||
|
||||
if (image != null && image.location != null)
|
||||
list.add(new ElementImage(0, y, GuiBook.PAGE_WIDTH, 100, image));
|
||||
else
|
||||
list.add(new ElementImage(0, y, 32, 32, ImageData.MISSING));
|
||||
|
||||
if (text != null && text.length > 0)
|
||||
list.add(new ElementText(0, y + 105, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT - 105 - y, text));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package slimeknights.mantle.client.book.data.content;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import slimeknights.mantle.client.book.data.BookData;
|
||||
import slimeknights.mantle.client.book.data.SectionData;
|
||||
import slimeknights.mantle.client.gui.book.element.BookElement;
|
||||
import slimeknights.mantle.client.gui.book.element.ElementSection;
|
||||
|
||||
public class ContentSectionList extends PageContent {
|
||||
|
||||
protected ArrayList<SectionData> sections = new ArrayList<>();
|
||||
|
||||
public boolean addSection(SectionData data) {
|
||||
return sections.size() < 9 && sections.add(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(BookData book, ArrayList<BookElement> list) {
|
||||
int width = (ElementSection.WIDTH + 5) * 3 - 5;
|
||||
int height = (ElementSection.HEIGHT + 5) * 3 - 5;
|
||||
|
||||
for (int i = 0; i < sections.size(); i++) {
|
||||
int ix = i % 3;
|
||||
int iy = (int) Math.floor(i / 3F);
|
||||
|
||||
int x = ix * (ElementSection.WIDTH + 5);
|
||||
int y = iy * (ElementSection.HEIGHT + 5);
|
||||
|
||||
list.add(new ElementSection(x, y, sections.get(i)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package slimeknights.mantle.client.book.data.content;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import slimeknights.mantle.client.book.data.BookData;
|
||||
import slimeknights.mantle.client.book.data.element.ImageData;
|
||||
import slimeknights.mantle.client.book.data.element.ItemStackData;
|
||||
import slimeknights.mantle.client.book.data.element.TextData;
|
||||
import slimeknights.mantle.client.gui.book.GuiBook;
|
||||
import slimeknights.mantle.client.gui.book.element.BookElement;
|
||||
import slimeknights.mantle.client.gui.book.element.ElementImage;
|
||||
import slimeknights.mantle.client.gui.book.element.ElementItem;
|
||||
import slimeknights.mantle.client.gui.book.element.ElementText;
|
||||
import static slimeknights.mantle.client.gui.book.Textures.TEX_SMELTING;
|
||||
|
||||
public class ContentSmelting extends PageContent {
|
||||
|
||||
public static final transient int TEX_SIZE = 128;
|
||||
public static final transient ImageData IMG_SMELTING = new ImageData(TEX_SMELTING, 0, 0, 110, 114, TEX_SIZE, TEX_SIZE);
|
||||
|
||||
public static final transient int INPUT_X = 5;
|
||||
public static final transient int INPUT_Y = 5;
|
||||
public static final transient int RESULT_X = 74;
|
||||
public static final transient int RESULT_Y = 41;
|
||||
public static final transient int FUEL_X = 5;
|
||||
public static final transient int FUEL_Y = 77;
|
||||
|
||||
public static final transient float ITEM_SCALE = 2.0F;
|
||||
|
||||
public String title = "Smelting";
|
||||
public ItemStackData input;
|
||||
public ItemStackData result;
|
||||
public TextData[] description;
|
||||
|
||||
@Override
|
||||
public void build(BookData book, ArrayList<BookElement> list) {
|
||||
int x = GuiBook.PAGE_WIDTH / 2 - IMG_SMELTING.width / 2;
|
||||
int y = TITLE_HEIGHT;
|
||||
|
||||
TextData tdTitle = new TextData(title);
|
||||
tdTitle.underlined = true;
|
||||
list.add(new ElementText(0, 0, GuiBook.PAGE_WIDTH, 9, new TextData[]{tdTitle}));
|
||||
list.add(new ElementImage(x, y, IMG_SMELTING.width, IMG_SMELTING.height, IMG_SMELTING, book.appearance.coverColor));
|
||||
|
||||
if (input != null && !input.id.equals("")) {
|
||||
list.add(new ElementItem(x + INPUT_X, y + INPUT_Y, ITEM_SCALE, input.getItems(), input.action));
|
||||
}
|
||||
|
||||
if (result != null && !result.id.equals("")) {
|
||||
list.add(new ElementItem(x + RESULT_X, y + RESULT_Y, ITEM_SCALE, result.getItems(), result.action));
|
||||
}
|
||||
|
||||
list.add(new ElementItem(x + FUEL_X, y + FUEL_Y, ITEM_SCALE, getFuelsList()));
|
||||
|
||||
if (description != null && description.length > 0) {
|
||||
list.add(new ElementText(0, IMG_SMELTING.height + y + 5, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT - y - 5, description));
|
||||
}
|
||||
}
|
||||
|
||||
public ItemStack[] getFuelsList() {
|
||||
//TODO ask JEI for fuel list if it is present
|
||||
|
||||
ItemStack[] fuels = new ItemStack[13];
|
||||
fuels[0] = new ItemStack(Blocks.wooden_slab);
|
||||
fuels[1] = new ItemStack(Blocks.planks);
|
||||
fuels[2] = new ItemStack(Blocks.coal_block);
|
||||
fuels[3] = new ItemStack(Items.wooden_pickaxe);
|
||||
fuels[4] = new ItemStack(Items.wooden_sword);
|
||||
fuels[5] = new ItemStack(Items.wooden_hoe);
|
||||
fuels[6] = new ItemStack(Items.stick);
|
||||
fuels[7] = new ItemStack(Items.coal);
|
||||
fuels[8] = new ItemStack(Items.lava_bucket);
|
||||
fuels[9] = new ItemStack(Blocks.sapling);
|
||||
fuels[10] = new ItemStack(Items.blaze_rod);
|
||||
fuels[11] = new ItemStack(Items.wooden_shovel);
|
||||
fuels[12] = new ItemStack(Items.wooden_axe);
|
||||
|
||||
return fuels;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package slimeknights.mantle.client.book.data.content;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import slimeknights.mantle.client.book.data.BookData;
|
||||
import slimeknights.mantle.client.book.data.element.ImageData;
|
||||
import slimeknights.mantle.client.book.data.element.ItemStackData;
|
||||
import slimeknights.mantle.client.book.data.element.TextData;
|
||||
import slimeknights.mantle.client.gui.book.GuiBook;
|
||||
import slimeknights.mantle.client.gui.book.element.BookElement;
|
||||
import slimeknights.mantle.client.gui.book.element.ElementImage;
|
||||
import slimeknights.mantle.client.gui.book.element.ElementItem;
|
||||
import slimeknights.mantle.client.gui.book.element.ElementText;
|
||||
import static slimeknights.mantle.client.gui.book.Textures.TEX_MISC;
|
||||
|
||||
public class ContentSmithing extends PageContent {
|
||||
|
||||
public static final transient int TEX_SIZE = 512;
|
||||
public static final transient ImageData IMG_SMITHING = new ImageData(TEX_MISC, 88, 0, 210, 42, TEX_SIZE, TEX_SIZE);
|
||||
|
||||
public static final transient int INPUT_X = 5;
|
||||
public static final transient int INPUT_Y = 5;
|
||||
public static final transient int MODIFIER_X = 89;
|
||||
public static final transient int MODIFIER_Y = 5;
|
||||
public static final transient int RESULT_X = 173;
|
||||
public static final transient int RESULT_Y = 5;
|
||||
|
||||
public static final transient float ITEM_SCALE = 2.0F;
|
||||
|
||||
public String title = "Smithing";
|
||||
public ItemStackData input;
|
||||
public ItemStackData modifier;
|
||||
public ItemStackData result;
|
||||
public TextData[] description;
|
||||
|
||||
@Override
|
||||
public void build(BookData book, ArrayList<BookElement> list) {
|
||||
int x = GuiBook.PAGE_WIDTH / 2 - IMG_SMITHING.width / 2;
|
||||
int y = TITLE_HEIGHT;
|
||||
|
||||
if (title == null || title.isEmpty())
|
||||
y = 0;
|
||||
else
|
||||
addTitle(list, title);
|
||||
|
||||
list.add(new ElementImage(x, y, IMG_SMITHING.width, IMG_SMITHING.height, IMG_SMITHING, book.appearance.coverColor));
|
||||
|
||||
if (input != null && !input.id.equals("")) {
|
||||
list.add(new ElementItem(x + INPUT_X, y + INPUT_Y, ITEM_SCALE, input.getItems(), input.action));
|
||||
}
|
||||
|
||||
if (modifier != null && !modifier.id.equals("")) {
|
||||
list.add(new ElementItem(x + MODIFIER_X, y + MODIFIER_Y, ITEM_SCALE, modifier.getItems(), modifier.action));
|
||||
}
|
||||
|
||||
if (result != null && !result.id.equals("")) {
|
||||
list.add(new ElementItem(x + RESULT_X, y + RESULT_Y, ITEM_SCALE, result.getItems(), result.action));
|
||||
}
|
||||
|
||||
if (description != null && description.length > 0) {
|
||||
list.add(new ElementText(0, IMG_SMITHING.height + y + 5, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT - IMG_SMITHING.height - y - 5, description));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package slimeknights.mantle.client.book.data.content;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import slimeknights.mantle.client.book.BookLoader;
|
||||
import slimeknights.mantle.client.book.data.BookData;
|
||||
import slimeknights.mantle.client.book.data.element.BlockData;
|
||||
import slimeknights.mantle.client.book.repository.BookRepository;
|
||||
import slimeknights.mantle.client.gui.book.GuiBook;
|
||||
import slimeknights.mantle.client.gui.book.element.BookElement;
|
||||
import slimeknights.mantle.client.gui.book.element.ElementStructure;
|
||||
import slimeknights.mantle.client.gui.book.element.ElementText;
|
||||
|
||||
public class ContentStructure extends PageContent {
|
||||
|
||||
public String title;
|
||||
public String data;
|
||||
|
||||
public int[] size;
|
||||
public BlockData[] structure;
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
BookRepository repo = parent.source;
|
||||
|
||||
if (data == null || data.isEmpty())
|
||||
return;
|
||||
|
||||
ResourceLocation location = repo.getResourceLocation(data);
|
||||
|
||||
if (location != null && repo.resourceExists(location)) {
|
||||
ContentStructure structure = BookLoader.GSON.fromJson(repo.resourceToString(repo.getResource(location)), ContentStructure.class);
|
||||
structure.parent = parent;
|
||||
structure.load();
|
||||
size = structure.size;
|
||||
this.structure = structure.structure;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(BookData book, ArrayList<BookElement> list) {
|
||||
int y = TITLE_HEIGHT;
|
||||
if (title == null || title.isEmpty())
|
||||
y = 0;
|
||||
else
|
||||
addTitle(list, title);
|
||||
|
||||
if (size != null && size.length == 3 && structure != null && structure.length > 0)
|
||||
list.add(new ElementStructure(0, y, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT - y - 10, size, structure));
|
||||
|
||||
list.add(new ElementText(0, GuiBook.PAGE_HEIGHT - 10, GuiBook.PAGE_WIDTH, 10, "WIP - Not Yet Implemented"));
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package slimeknights.mantle.client.book.data.content;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import slimeknights.mantle.client.book.data.BookData;
|
||||
import slimeknights.mantle.client.book.data.element.TextData;
|
||||
import slimeknights.mantle.client.gui.book.GuiBook;
|
||||
import slimeknights.mantle.client.gui.book.element.BookElement;
|
||||
import slimeknights.mantle.client.gui.book.element.ElementText;
|
||||
|
||||
public class ContentTableOfContents extends PageContent {
|
||||
|
||||
public String title;
|
||||
public TextData[] data;
|
||||
|
||||
public ContentTableOfContents(String title, TextData... contents) {
|
||||
this.title = title;
|
||||
data = contents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(BookData book, ArrayList<BookElement> list) {
|
||||
int y = 0;
|
||||
|
||||
if (title != null && !title.trim().isEmpty()) {
|
||||
addTitle(list, title);
|
||||
y += TITLE_HEIGHT;
|
||||
}
|
||||
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
TextData text = data[i];
|
||||
list.add(new ElementText(0, y + i * (int) (Minecraft.getMinecraft().fontRendererObj.FONT_HEIGHT * text.scale), GuiBook.PAGE_WIDTH, Minecraft.getMinecraft().fontRendererObj.FONT_HEIGHT, new TextData[]{text}));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package slimeknights.mantle.client.book.data.content;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import slimeknights.mantle.client.book.data.BookData;
|
||||
import slimeknights.mantle.client.book.data.element.TextData;
|
||||
import slimeknights.mantle.client.gui.book.GuiBook;
|
||||
import slimeknights.mantle.client.gui.book.element.BookElement;
|
||||
import slimeknights.mantle.client.gui.book.element.ElementText;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class ContentText extends PageContent {
|
||||
|
||||
public String title = null;
|
||||
public TextData[] text;
|
||||
|
||||
@Override
|
||||
public void build(BookData book, ArrayList<BookElement> list) {
|
||||
int y = TITLE_HEIGHT;
|
||||
|
||||
if (title == null || title.isEmpty())
|
||||
y = 0;
|
||||
else
|
||||
addTitle(list, title);
|
||||
|
||||
if (text != null && text.length > 0)
|
||||
list.add(new ElementText(0, y, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT - y, text));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package slimeknights.mantle.client.book.data.content;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import slimeknights.mantle.client.book.data.BookData;
|
||||
import slimeknights.mantle.client.book.data.element.ImageData;
|
||||
import slimeknights.mantle.client.book.data.element.TextData;
|
||||
import slimeknights.mantle.client.gui.book.GuiBook;
|
||||
import slimeknights.mantle.client.gui.book.element.BookElement;
|
||||
import slimeknights.mantle.client.gui.book.element.ElementImage;
|
||||
import slimeknights.mantle.client.gui.book.element.ElementText;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class ContentTextImage extends PageContent {
|
||||
|
||||
public String title = null;
|
||||
public TextData[] text;
|
||||
public ImageData image;
|
||||
|
||||
@Override
|
||||
public void build(BookData book, ArrayList<BookElement> list) {
|
||||
int y = TITLE_HEIGHT;
|
||||
|
||||
if (title == null || title.isEmpty())
|
||||
y = 0;
|
||||
else
|
||||
addTitle(list, title);
|
||||
|
||||
if (title == null || title.isEmpty())
|
||||
y = 0;
|
||||
else
|
||||
addTitle(list, title);
|
||||
|
||||
if (text != null && text.length > 0)
|
||||
list.add(new ElementText(0, y, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT - 105, text));
|
||||
|
||||
if (image != null && image.location != null)
|
||||
list.add(new ElementImage(0, y + GuiBook.PAGE_HEIGHT - 100, GuiBook.PAGE_WIDTH, 100 - y, image));
|
||||
else
|
||||
list.add(new ElementImage(0, y + GuiBook.PAGE_HEIGHT - 100, GuiBook.PAGE_WIDTH, 100 - y, ImageData.MISSING));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package slimeknights.mantle.client.book.data.content;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import slimeknights.mantle.client.book.data.BookData;
|
||||
import slimeknights.mantle.client.book.data.element.ImageData;
|
||||
import slimeknights.mantle.client.book.data.element.TextData;
|
||||
import slimeknights.mantle.client.gui.book.GuiBook;
|
||||
import slimeknights.mantle.client.gui.book.element.BookElement;
|
||||
import slimeknights.mantle.client.gui.book.element.ElementImage;
|
||||
import slimeknights.mantle.client.gui.book.element.ElementText;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class ContentTextLeftImage extends PageContent {
|
||||
|
||||
public String title = null;
|
||||
public ImageData image;
|
||||
public TextData[] text1;
|
||||
public TextData[] text2;
|
||||
|
||||
@Override
|
||||
public void build(BookData book, ArrayList<BookElement> list) {
|
||||
int y = TITLE_HEIGHT;
|
||||
|
||||
if (title == null || title.isEmpty())
|
||||
y = 0;
|
||||
else
|
||||
addTitle(list, title);
|
||||
|
||||
if (image != null && image.location != null)
|
||||
list.add(new ElementImage(0, y, 50, 50, image));
|
||||
else
|
||||
list.add(new ElementImage(0, y, 50, 50, ImageData.MISSING));
|
||||
|
||||
if (text1 != null && text1.length > 0)
|
||||
list.add(new ElementText(55, y, GuiBook.PAGE_WIDTH - 55, 50, text1));
|
||||
|
||||
if (text2 != null && text2.length > 0)
|
||||
list.add(new ElementText(0, y + 55, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT - 55 - y, text2));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package slimeknights.mantle.client.book.data.content;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import slimeknights.mantle.client.book.data.BookData;
|
||||
import slimeknights.mantle.client.book.data.element.ImageData;
|
||||
import slimeknights.mantle.client.book.data.element.TextData;
|
||||
import slimeknights.mantle.client.gui.book.GuiBook;
|
||||
import slimeknights.mantle.client.gui.book.element.BookElement;
|
||||
import slimeknights.mantle.client.gui.book.element.ElementImage;
|
||||
import slimeknights.mantle.client.gui.book.element.ElementText;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class ContentTextRightImage extends PageContent {
|
||||
|
||||
public String title;
|
||||
public TextData[] text1;
|
||||
public TextData[] text2;
|
||||
public ImageData image;
|
||||
|
||||
@Override
|
||||
public void build(BookData book, ArrayList<BookElement> list) {
|
||||
int y = TITLE_HEIGHT;
|
||||
|
||||
if (title == null || title.isEmpty())
|
||||
y = 0;
|
||||
else
|
||||
addTitle(list, title);
|
||||
|
||||
if (text1 != null && text1.length > 0)
|
||||
list.add(new ElementText(0, y, GuiBook.PAGE_WIDTH - 55, 50, text1));
|
||||
|
||||
if (image != null && image.location != null)
|
||||
list.add(new ElementImage(GuiBook.PAGE_WIDTH - 50, y, 50, 50, image));
|
||||
else
|
||||
list.add(new ElementImage(GuiBook.PAGE_WIDTH - 50, y, 50, 50, ImageData.MISSING));
|
||||
|
||||
if (text2 != null && text2.length > 0)
|
||||
list.add(new ElementText(0, y + 55, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT - 55 - y, text2));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package slimeknights.mantle.client.book.data.content;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import slimeknights.mantle.client.book.data.BookData;
|
||||
import slimeknights.mantle.client.book.data.PageData;
|
||||
import slimeknights.mantle.client.book.data.element.TextData;
|
||||
import slimeknights.mantle.client.book.repository.BookRepository;
|
||||
import slimeknights.mantle.client.gui.book.GuiBook;
|
||||
import slimeknights.mantle.client.gui.book.element.BookElement;
|
||||
import slimeknights.mantle.client.gui.book.element.ElementText;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public abstract class PageContent {
|
||||
|
||||
public static final transient int TITLE_HEIGHT = 16;
|
||||
|
||||
public transient PageData parent;
|
||||
public transient BookRepository source;
|
||||
|
||||
public void load() {
|
||||
}
|
||||
|
||||
public abstract void build(BookData book, ArrayList<BookElement> list);
|
||||
|
||||
public void addTitle(ArrayList<BookElement> list, String title) {
|
||||
TextData tdTitle = new TextData(title);
|
||||
tdTitle.underlined = true;
|
||||
addTitle(list, new TextData[]{tdTitle});
|
||||
}
|
||||
|
||||
public void addTitle(ArrayList<BookElement> list, TextData[] title) {
|
||||
list.add(new ElementText(0, 0, GuiBook.PAGE_WIDTH, 9, title));
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package slimeknights.mantle.client.book.data.deserializer;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParseException;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class HexStringDeserializer implements JsonDeserializer<Integer> {
|
||||
|
||||
@Override
|
||||
public Integer deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
if (json.isJsonPrimitive() && json.getAsJsonPrimitive().isNumber())
|
||||
return json.getAsInt();
|
||||
else if (json.isJsonPrimitive() && json.getAsJsonPrimitive().isString()) {
|
||||
try {
|
||||
String s = json.getAsString();
|
||||
|
||||
if (s.toLowerCase().startsWith("0b"))
|
||||
return Integer.parseInt(s.substring(2), 2);
|
||||
else if (s.toLowerCase().startsWith("0x"))
|
||||
return Integer.parseInt(s.substring(2), 16);
|
||||
} catch (NumberFormatException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package slimeknights.mantle.client.book.data.element;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
public class BlockData {
|
||||
|
||||
public int[] pos;
|
||||
public int[] endPos;
|
||||
public String block;
|
||||
public byte meta;
|
||||
public JsonObject nbt;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package slimeknights.mantle.client.book.data.element;
|
||||
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
public class DataLocation {
|
||||
|
||||
public String file;
|
||||
public transient ResourceLocation location;
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package slimeknights.mantle.client.book.data.element;
|
||||
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class ImageData extends DataLocation {
|
||||
|
||||
public static final ImageData MISSING = new ImageData();
|
||||
|
||||
public int u = 0;
|
||||
public int v = 0;
|
||||
public int uw = 256;
|
||||
public int vh = 256;
|
||||
public int texWidth = 256;
|
||||
public int texHeight = 256;
|
||||
public int x = -1;
|
||||
public int y = -1;
|
||||
public int width = -1;
|
||||
public int height = -1;
|
||||
public int colorMultiplier = 0xFFFFFF;
|
||||
|
||||
public ImageData() {
|
||||
}
|
||||
|
||||
public ImageData(ResourceLocation location, int u, int v, int uw, int vh, int texWidth, int texHeight) {
|
||||
this(location, u, v, uw, vh, texWidth, texHeight, uw, vh, 0xFFFFFF);
|
||||
}
|
||||
|
||||
public ImageData(ResourceLocation location, int u, int v, int uw, int vh, int texWidth, int texHeight, int colorMultiplier) {
|
||||
this(location, u, v, uw, vh, texWidth, texHeight, uw, vh);
|
||||
}
|
||||
|
||||
public ImageData(ResourceLocation location, int u, int v, int uw, int vh, int texWidth, int texHeight, int width, int height) {
|
||||
this(location, u, v, uw, vh, texWidth, texHeight, width, height, 0xFFFFFF);
|
||||
}
|
||||
|
||||
public ImageData(ResourceLocation location, int u, int v, int uw, int vh, int texWidth, int texHeight, int width, int height, int colorMultiplier) {
|
||||
this.location = location;
|
||||
this.u = u;
|
||||
this.v = v;
|
||||
this.uw = uw;
|
||||
this.vh = vh;
|
||||
this.texWidth = texWidth;
|
||||
this.texHeight = texHeight;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.colorMultiplier = colorMultiplier;
|
||||
}
|
||||
|
||||
static {
|
||||
MISSING.location = new ResourceLocation("mantle:textures/gui/missingno.png");
|
||||
MISSING.texWidth = 32;
|
||||
MISSING.texHeight = 32;
|
||||
MISSING.uw = 32;
|
||||
MISSING.vh = 32;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
package slimeknights.mantle.client.book.data.element;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.command.CommandGive;
|
||||
import net.minecraft.command.NumberInvalidException;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.JsonToNBT;
|
||||
import net.minecraft.nbt.NBTException;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.nbt.NBTTagString;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import slimeknights.mantle.client.book.BookLoader;
|
||||
import slimeknights.mantle.client.book.repository.BookRepository;
|
||||
|
||||
public class ItemStackData {
|
||||
|
||||
public String itemList = null;
|
||||
public transient BookRepository source;
|
||||
public transient ResourceLocation itemListLocation = null;
|
||||
public transient String action;
|
||||
|
||||
public String id = "";
|
||||
public byte amount = 1;
|
||||
public short damage = 0;
|
||||
public JsonObject nbt;
|
||||
|
||||
public ItemStack[] getItems() {
|
||||
if (itemListLocation != null && source.resourceExists(itemListLocation)) {
|
||||
try {
|
||||
ItemsList itemsList = BookLoader.GSON.fromJson(source.resourceToString(source.getResource(itemListLocation)), ItemsList.class);
|
||||
ItemStack[] items = new ItemStack[itemsList.items.length];
|
||||
|
||||
for (int i = 0; i < itemsList.items.length; i++) {
|
||||
items[i] = itemsList.items[i].getItem();
|
||||
}
|
||||
|
||||
this.action = itemsList.action;
|
||||
|
||||
return items;
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
return new ItemStack[]{getItem()};
|
||||
}
|
||||
|
||||
private ItemStack getItem() {
|
||||
Item item;
|
||||
boolean isMissingItem = false;
|
||||
try {
|
||||
item = CommandGive.getItemByText(null, id);
|
||||
} catch (NumberInvalidException e) {
|
||||
item = Item.getItemFromBlock(Blocks.barrier);
|
||||
isMissingItem = true;
|
||||
}
|
||||
|
||||
if (item == null) {
|
||||
item = Item.getItemFromBlock(Blocks.barrier);
|
||||
isMissingItem = true;
|
||||
}
|
||||
|
||||
ItemStack itemStack = new ItemStack(item, amount, damage);
|
||||
|
||||
if (nbt != null) {
|
||||
try {
|
||||
itemStack.setTagCompound(JsonToNBT.getTagFromJson(filterJsonQuotes(nbt.toString())));
|
||||
} catch (NBTException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
if (isMissingItem) {
|
||||
NBTTagCompound display = itemStack.getSubCompound("display", true);
|
||||
display.setString("Name", "\u00A7rUnknown Item");
|
||||
NBTTagList lore = new NBTTagList();
|
||||
lore.appendTag(new NBTTagString("\u00A7r\u00A7eItem Name:"));
|
||||
lore.appendTag(new NBTTagString("\u00A7r\u00A7e" + id));
|
||||
display.setTag("Lore", lore);
|
||||
}
|
||||
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
public static ItemStackData getItemStackData(ItemStack stack) {
|
||||
return getItemStackData(stack, false);
|
||||
}
|
||||
|
||||
public static ItemStackData getItemStackData(ItemStack stack, boolean ignoreNbt) {
|
||||
ItemStackData data = new ItemStackData();
|
||||
data.id = Item.itemRegistry.getNameForObject(stack.getItem()).toString();
|
||||
data.amount = (byte) stack.stackSize;
|
||||
data.damage = (short) stack.getItemDamage();
|
||||
if (!ignoreNbt && stack.getTagCompound() != null) {
|
||||
data.nbt = BookLoader.GSON.toJsonTree(stack.getTagCompound(), NBTTagCompound.class).getAsJsonObject();
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public static String filterJsonQuotes(String s) {
|
||||
return s.replaceAll("\"(\\w+)\"\\s*:", "$1: ");
|
||||
}
|
||||
|
||||
private static class ItemsList {
|
||||
|
||||
public ItemStackData[] items = new ItemStackData[0];
|
||||
public String action;
|
||||
}
|
||||
|
||||
public static class ItemLink {
|
||||
|
||||
public ItemStackData item = new ItemStackData();
|
||||
public boolean damageSensitive = false;
|
||||
public String action = "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package slimeknights.mantle.client.book.data.element;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class TextData {
|
||||
|
||||
public String text;
|
||||
public String color = "black";
|
||||
public boolean bold = false;
|
||||
public boolean italic = false;
|
||||
public boolean underlined = false;
|
||||
public boolean strikethrough = false;
|
||||
public boolean obfuscated = false;
|
||||
public boolean paragraph = false;
|
||||
public float scale = 1.F;
|
||||
public String action = "";
|
||||
public String[] tooltip = null;
|
||||
|
||||
public TextData() {
|
||||
}
|
||||
|
||||
public TextData(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package slimeknights.mantle.client.book.repository;
|
||||
|
||||
import java.util.List;
|
||||
import net.minecraft.client.resources.IResource;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import slimeknights.mantle.client.book.data.SectionData;
|
||||
|
||||
public abstract class BookRepository {
|
||||
|
||||
public static final BookRepository DUMMY = new DummyRepository();
|
||||
|
||||
public abstract List<SectionData> getSections();
|
||||
|
||||
public ResourceLocation getResourceLocation(String path) {
|
||||
return getResourceLocation(path, false);
|
||||
}
|
||||
|
||||
public abstract ResourceLocation getResourceLocation(String path, boolean safe);
|
||||
|
||||
public abstract IResource getResource(ResourceLocation loc);
|
||||
|
||||
public boolean resourceExists(String location) {
|
||||
return resourceExists(new ResourceLocation(location));
|
||||
}
|
||||
|
||||
public abstract boolean resourceExists(ResourceLocation location);
|
||||
|
||||
public String resourceToString(IResource resource) {
|
||||
return resourceToString(resource, true);
|
||||
}
|
||||
|
||||
public abstract String resourceToString(IResource resource, boolean skipCommments);
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package slimeknights.mantle.client.book.repository;
|
||||
|
||||
import java.util.List;
|
||||
import net.minecraft.client.resources.IResource;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import slimeknights.mantle.client.book.data.SectionData;
|
||||
|
||||
public class DummyRepository extends BookRepository {
|
||||
|
||||
@Override
|
||||
public List<SectionData> getSections() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getResourceLocation(String path, boolean safe) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IResource getResource(ResourceLocation loc) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean resourceExists(ResourceLocation location) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String resourceToString(IResource resource, boolean skipCommments) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
package slimeknights.mantle.client.book.repository;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.resources.IResource;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import org.apache.commons.io.Charsets;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import slimeknights.mantle.client.book.BookLoader;
|
||||
import slimeknights.mantle.client.book.data.SectionData;
|
||||
|
||||
public class FileRepository extends BookRepository {
|
||||
|
||||
public final String location;
|
||||
|
||||
public FileRepository(String location) {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SectionData> getSections() {
|
||||
return new ArrayList<>(Arrays.asList(BookLoader.GSON.fromJson(resourceToString(getResource(getResourceLocation("index.json"))), SectionData[].class)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getResourceLocation(String path, boolean safe) {
|
||||
if (path == null)
|
||||
return safe ? new ResourceLocation("") : null;
|
||||
if (!path.contains(":")) {
|
||||
String langPath = Minecraft.getMinecraft().getLanguageManager().getCurrentLanguage().getLanguageCode();
|
||||
String defaultLangPath = "en_US";
|
||||
|
||||
ResourceLocation res = new ResourceLocation(location + "/" + langPath + "/" + path);
|
||||
if (resourceExists(res))
|
||||
return res;
|
||||
res = new ResourceLocation(location + "/" + defaultLangPath + "/" + path);
|
||||
if (resourceExists(res))
|
||||
return res;
|
||||
res = new ResourceLocation(location + "/" + path);
|
||||
if (resourceExists(res))
|
||||
return res;
|
||||
return safe ? new ResourceLocation("") : null;
|
||||
} else {
|
||||
ResourceLocation res = new ResourceLocation(path);
|
||||
if (resourceExists(res))
|
||||
return res;
|
||||
return safe ? new ResourceLocation("") : null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IResource getResource(ResourceLocation loc) {
|
||||
if (loc == null)
|
||||
return null;
|
||||
try {
|
||||
return Minecraft.getMinecraft().getResourceManager().getResource(loc);
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean resourceExists(ResourceLocation location) {
|
||||
if (location == null)
|
||||
return false;
|
||||
try {
|
||||
Minecraft.getMinecraft().getResourceManager().getResource(location);
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String resourceToString(IResource resource, boolean skipCommments) {
|
||||
if (resource == null)
|
||||
return "";
|
||||
try {
|
||||
Iterator iterator = IOUtils.readLines(resource.getInputStream(), Charsets.UTF_8).iterator();
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
boolean isLongComment = false;
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
String s = ((String) iterator.next()).trim() + "\n";
|
||||
|
||||
// Comment skipper
|
||||
if (skipCommments) {
|
||||
if (isLongComment) {
|
||||
if (s.endsWith("*/"))
|
||||
isLongComment = false;
|
||||
continue;
|
||||
} else {
|
||||
if (s.startsWith("/*")) {
|
||||
isLongComment = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (s.startsWith("//"))
|
||||
continue;
|
||||
}
|
||||
|
||||
builder.append(s);
|
||||
}
|
||||
|
||||
return builder.toString().trim();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package slimeknights.mantle.client.gui.book;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import static slimeknights.mantle.client.gui.book.Textures.TEX_BOX;
|
||||
|
||||
public class BoxRenderer {
|
||||
|
||||
public static final int TEX_SIZE = 128;
|
||||
|
||||
public static void drawBox(int x, int y, int width, int height, int index) {
|
||||
drawBox(x, y, width, height, index, 16, 16, 4, 4, 2, 2);
|
||||
}
|
||||
|
||||
public static void drawBox(int x, int y, int width, int height, int index, int sprW, int sprH, int segW, int segH, int segGW, int segGH) {
|
||||
Minecraft.getMinecraft().renderEngine.bindTexture(TEX_BOX);
|
||||
|
||||
int sx = x, sy = y;
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
int sgW = width - segW * 2;
|
||||
|
||||
if (i % 2 == 0)
|
||||
sgW = segW;
|
||||
|
||||
for (int j = 0; j < 3; j++) {
|
||||
int sgH = height - segH * 2;
|
||||
|
||||
if (j % 2 == 0)
|
||||
sgH = segH;
|
||||
|
||||
int[] matrix = getTextureMatrixCoords(index, sprW, sprH, segW, segH, segGW, segGH, i + j * 3);
|
||||
Gui.drawScaledCustomSizeModalRect(sx, sy, matrix[0], matrix[1], segW, segH, sgW, sgH, TEX_SIZE, TEX_SIZE);
|
||||
|
||||
sy += sgH;
|
||||
}
|
||||
|
||||
sx += sgW;
|
||||
sy = y;
|
||||
}
|
||||
}
|
||||
|
||||
public static int[] getTextureMatrixCoords(int index, int sprW, int sprH, int segW, int segH, int segGW, int segGH, int segId) {
|
||||
int totalWidth = segW * 3 + segGW * 2;
|
||||
int totalHeight = segH * 3 + segGH * 2;
|
||||
|
||||
return getTextureMatrixCoords((index % (256 / sprW) * sprW) + (sprW / 2 - totalWidth / 2), (MathHelper.floor_float(index / (256F / sprH)) * sprH) + (sprH / 2 - totalHeight / 2), segW, segH, segGW, segGH, segId);
|
||||
}
|
||||
|
||||
public static int[] getTextureMatrixCoords(int u, int v, int segW, int segH, int segGW, int segGH, int segId) {
|
||||
int[] coords = new int[4];
|
||||
|
||||
int col = segId % 3;
|
||||
int row = MathHelper.floor_float(segId / 3F);
|
||||
|
||||
coords[0] = u + col * segW + col * segGW;
|
||||
coords[1] = v + row * segH + row * segGH;
|
||||
coords[2] = coords[0] + segW;
|
||||
coords[3] = coords[1] + segH;
|
||||
|
||||
return coords;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package slimeknights.mantle.client.gui.book;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import static slimeknights.mantle.client.gui.book.Textures.TEX_BOOK;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class GuiArrow extends GuiButton {
|
||||
|
||||
private static final int X = 412;
|
||||
|
||||
public static final int WIDTH = 18;
|
||||
public static final int HEIGHT = 10;
|
||||
|
||||
// Appearance
|
||||
public int arrowType;
|
||||
public int color;
|
||||
public int hoverColor;
|
||||
|
||||
public GuiArrow(int buttonId, int x, int y, int arrowType, int color, int hoverColor) {
|
||||
super(buttonId, x, y, WIDTH, HEIGHT, "");
|
||||
|
||||
this.arrowType = arrowType;
|
||||
this.color = color;
|
||||
this.hoverColor = hoverColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawButton(Minecraft mc, int mouseX, int mouseY) {
|
||||
if (this.visible) {
|
||||
mc.getTextureManager().bindTexture(TEX_BOOK);
|
||||
|
||||
this.hovered = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height;
|
||||
|
||||
int color = this.hovered ? this.hoverColor : this.color;
|
||||
|
||||
float r = ((color >> 16) & 0xff) / 255.F;
|
||||
float g = ((color >> 8) & 0xff) / 255.F;
|
||||
float b = (color & 0xff) / 255.F;
|
||||
|
||||
GlStateManager.color(r, g, b);
|
||||
Gui.drawScaledCustomSizeModalRect(xPosition, yPosition, X, HEIGHT * arrowType, WIDTH, HEIGHT, width, height, 512, 512);
|
||||
this.mouseDragged(mc, mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,489 @@
|
||||
package slimeknights.mantle.client.gui.book;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.gui.IProgressMeter;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.texture.TextureManager;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.play.client.C16PacketClientStatus;
|
||||
import net.minecraft.stats.StatFileWriter;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.input.Mouse;
|
||||
import slimeknights.mantle.client.book.BookHelper;
|
||||
import slimeknights.mantle.client.book.BookLoader;
|
||||
import slimeknights.mantle.client.book.action.StringActionProcessor;
|
||||
import slimeknights.mantle.client.book.data.BookData;
|
||||
import slimeknights.mantle.client.book.data.PageData;
|
||||
import slimeknights.mantle.client.book.data.element.ItemStackData;
|
||||
import slimeknights.mantle.client.gui.book.element.BookElement;
|
||||
import static slimeknights.mantle.client.gui.book.Textures.TEX_BOOK;
|
||||
import static slimeknights.mantle.client.gui.book.Textures.TEX_BOOKFRONT;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class GuiBook extends GuiScreen implements IProgressMeter {
|
||||
|
||||
public static boolean debug = false;
|
||||
|
||||
public static final int TEX_SIZE = 512;
|
||||
|
||||
public static final int PAGE_PADDING = 8;
|
||||
public static final int PAGE_MARGIN = 18;
|
||||
|
||||
public static final float PAGE_SCALE = 0.5F;
|
||||
public static final int PAGE_WIDTH_UNSCALED = 206;
|
||||
public static final int PAGE_HEIGHT_UNSCALED = 200;
|
||||
|
||||
// For best results, make sure both PAGE_WIDTH_UNSCALED - (PAGE_PADDING + PAGE_MARGIN) * 2 and PAGE_HEIGHT_UNSCALED - (PAGE_PADDING + PAGE_MARGIN) * 2 divide evenly into PAGE_SCALE (without remainder)
|
||||
public static final int PAGE_WIDTH = (int) ((PAGE_WIDTH_UNSCALED - (PAGE_PADDING + PAGE_MARGIN) * 2) / PAGE_SCALE);
|
||||
public static final int PAGE_HEIGHT = (int) ((PAGE_HEIGHT_UNSCALED - (PAGE_PADDING + PAGE_MARGIN) * 2) / PAGE_SCALE);
|
||||
|
||||
private boolean loadingAchievements = true;
|
||||
private GuiArrow previousArrow, nextArrow, backArrow, indexArrow;
|
||||
|
||||
public final BookData book;
|
||||
private ItemStack item;
|
||||
|
||||
private int page = -1;
|
||||
private int oldPage = -2;
|
||||
private ArrayList<BookElement> leftElements = new ArrayList<>();
|
||||
private ArrayList<BookElement> rightElements = new ArrayList<>();
|
||||
|
||||
public StatFileWriter statFile;
|
||||
|
||||
public GuiBook(BookData book, StatFileWriter statFile, @Nullable ItemStack item) {
|
||||
this.book = book;
|
||||
this.item = item;
|
||||
|
||||
this.statFile = statFile;
|
||||
}
|
||||
|
||||
public void drawerTransform(boolean rightSide) {
|
||||
if (rightSide)
|
||||
GlStateManager.translate(width / 2 + PAGE_PADDING + PAGE_MARGIN, height / 2 - PAGE_HEIGHT_UNSCALED / 2 + PAGE_PADDING + PAGE_MARGIN, 0);
|
||||
else
|
||||
GlStateManager.translate(width / 2 - PAGE_WIDTH_UNSCALED + PAGE_PADDING + PAGE_MARGIN, height / 2 - PAGE_HEIGHT_UNSCALED / 2 + PAGE_PADDING + PAGE_MARGIN, 0);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("ForLoopReplaceableByForEach")
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
FontRenderer font = mc.fontRendererObj;
|
||||
|
||||
if (loadingAchievements) {
|
||||
this.drawDefaultBackground();
|
||||
|
||||
this.drawCenteredString(this.fontRendererObj, I18n.format("multiplayer.downloadingStats"), this.width / 2, this.height / 2, 16777215);
|
||||
this.drawCenteredString(this.fontRendererObj, lanSearchStates[(int) (Minecraft.getSystemTime() / 150L % (long) lanSearchStates.length)], this.width / 2, this.height / 2 + this.fontRendererObj.FONT_HEIGHT * 2, 16777215);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (debug) {
|
||||
drawRect(0, 0, font.getStringWidth("DEBUG") + 4, font.FONT_HEIGHT + 4, 0x55000000);
|
||||
font.drawString("DEBUG", 2, 2, 0xFFFFFFFF);
|
||||
}
|
||||
|
||||
GlStateManager.enableAlpha();
|
||||
GlStateManager.enableBlend();
|
||||
|
||||
// The books are unreadable at Gui Scale set to small, so we'll double the scale
|
||||
if (mc.gameSettings.guiScale == 1) {
|
||||
GlStateManager.scale(2F, 2F, 2F);
|
||||
|
||||
mouseX /= 2;
|
||||
mouseY /= 2;
|
||||
}
|
||||
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.color(1F, 1F, 1F);
|
||||
|
||||
float coverR = ((book.appearance.coverColor >> 16) & 0xff) / 255.F;
|
||||
float coverG = ((book.appearance.coverColor >> 8) & 0xff) / 255.F;
|
||||
float coverB = (book.appearance.coverColor & 0xff) / 255.F;
|
||||
|
||||
TextureManager render = this.mc.renderEngine;
|
||||
|
||||
if (page == -1) {
|
||||
render.bindTexture(TEX_BOOKFRONT);
|
||||
|
||||
GlStateManager.color(coverR, coverG, coverB);
|
||||
drawModalRectWithCustomSizedTexture(width / 2 - PAGE_WIDTH_UNSCALED / 2, height / 2 - PAGE_HEIGHT_UNSCALED / 2, 0, 0, PAGE_WIDTH_UNSCALED, PAGE_HEIGHT_UNSCALED, TEX_SIZE, TEX_SIZE);
|
||||
GlStateManager.color(1F, 1F, 1F);
|
||||
|
||||
if (!book.appearance.title.isEmpty()) {
|
||||
drawModalRectWithCustomSizedTexture(width / 2 - PAGE_WIDTH_UNSCALED / 2, height / 2 - PAGE_HEIGHT_UNSCALED / 2, 0, PAGE_HEIGHT_UNSCALED, PAGE_WIDTH_UNSCALED, PAGE_HEIGHT_UNSCALED, TEX_SIZE, TEX_SIZE);
|
||||
|
||||
GlStateManager.pushMatrix();
|
||||
|
||||
float scale = font.getStringWidth(book.appearance.title) <= 67 ? 2.5F : 2F;
|
||||
|
||||
GlStateManager.scale(scale, scale, 1F);
|
||||
font.drawString(book.appearance.title, (width / 2) / scale + 3 - font.getStringWidth(book.appearance.title) / 2, (height / 2 - font.FONT_HEIGHT / 2) / scale - 4, 0xAE8000, true);
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
|
||||
if (!book.appearance.subtitle.isEmpty()) {
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.scale(1.5F, 1.5F, 1F);
|
||||
font.drawString(book.appearance.subtitle, (width / 2) / 1.5F + 7 - font.getStringWidth(book.appearance.subtitle) / 2, (height / 2 + 100 - font.FONT_HEIGHT * 2) / 1.5F, 0xAE8000, true);
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
} else {
|
||||
render.bindTexture(TEX_BOOK);
|
||||
|
||||
GlStateManager.color(coverR, coverG, coverB);
|
||||
drawModalRectWithCustomSizedTexture(width / 2 - PAGE_WIDTH_UNSCALED, height / 2 - PAGE_HEIGHT_UNSCALED / 2, 0, 0, PAGE_WIDTH_UNSCALED * 2, PAGE_HEIGHT_UNSCALED, TEX_SIZE, TEX_SIZE);
|
||||
|
||||
GlStateManager.color(1F, 1F, 1F);
|
||||
|
||||
if (page != 0) {
|
||||
drawModalRectWithCustomSizedTexture(width / 2 - PAGE_WIDTH_UNSCALED, height / 2 - PAGE_HEIGHT_UNSCALED / 2, 0, PAGE_HEIGHT_UNSCALED, PAGE_WIDTH_UNSCALED, PAGE_HEIGHT_UNSCALED, TEX_SIZE, TEX_SIZE);
|
||||
|
||||
GlStateManager.pushMatrix();
|
||||
drawerTransform(false);
|
||||
|
||||
GlStateManager.scale(PAGE_SCALE, PAGE_SCALE, 1F);
|
||||
|
||||
if (book.appearance.drawPageNumbers) {
|
||||
String pNum = (page - 1) * 2 + 2 + "";
|
||||
font.drawString(pNum, PAGE_WIDTH / 2 - font.getStringWidth(pNum) / 2, PAGE_HEIGHT + 15, 0xFFAAAAAA, false);
|
||||
}
|
||||
|
||||
int mX = (int) ((Mouse.getX() * this.width / this.mc.displayWidth - (width / 2 - PAGE_WIDTH_UNSCALED) - PAGE_PADDING - PAGE_MARGIN) / PAGE_SCALE);
|
||||
int mY = (int) ((this.height - Mouse.getY() * this.height / this.mc.displayHeight - 1 - (height / 2 - PAGE_HEIGHT_UNSCALED / 2) - PAGE_PADDING - PAGE_MARGIN) / PAGE_SCALE);
|
||||
|
||||
// Not foreach to prevent conmodification crashes
|
||||
for (int i = 0; i < leftElements.size(); i++) {
|
||||
BookElement element = leftElements.get(i);
|
||||
|
||||
GlStateManager.color(1F, 1F, 1F, 1F);
|
||||
element.draw(mX, mY, partialTicks);
|
||||
}
|
||||
|
||||
// Not foreach to prevent conmodification crashes
|
||||
for (int i = 0; i < leftElements.size(); i++) {
|
||||
BookElement element = leftElements.get(i);
|
||||
|
||||
GlStateManager.color(1F, 1F, 1F, 1F);
|
||||
element.drawOverlay(mX, mY, partialTicks);
|
||||
}
|
||||
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
|
||||
// Rebind texture as the font renderer binds its own texture
|
||||
render.bindTexture(TEX_BOOK);
|
||||
// Set color back to white
|
||||
GlStateManager.color(1F, 1F, 1F, 1F);
|
||||
|
||||
if ((page < book.getFullPageCount(statFile) - 1 || book.getPageCount(statFile) % 2 != 0) && page < book.getFullPageCount(statFile)) {
|
||||
drawModalRectWithCustomSizedTexture(width / 2, height / 2 - PAGE_HEIGHT_UNSCALED / 2, PAGE_WIDTH_UNSCALED, PAGE_HEIGHT_UNSCALED, PAGE_WIDTH_UNSCALED, PAGE_HEIGHT_UNSCALED, TEX_SIZE, TEX_SIZE);
|
||||
|
||||
GlStateManager.pushMatrix();
|
||||
drawerTransform(true);
|
||||
|
||||
GlStateManager.scale(PAGE_SCALE, PAGE_SCALE, 1F);
|
||||
|
||||
if (book.appearance.drawPageNumbers) {
|
||||
String pNum = (page - 1) * 2 + 3 + "";
|
||||
font.drawString(pNum, PAGE_WIDTH / 2 - font.getStringWidth(pNum) / 2, PAGE_HEIGHT + 15, 0xFFAAAAAA, false);
|
||||
}
|
||||
|
||||
int mX = (int) ((Mouse.getX() * this.width / this.mc.displayWidth - (width / 2) - PAGE_PADDING - PAGE_MARGIN) / PAGE_SCALE);
|
||||
int mY = (int) ((this.height - Mouse.getY() * this.height / this.mc.displayHeight - 1 - (height / 2 - PAGE_HEIGHT_UNSCALED / 2) - PAGE_PADDING - PAGE_MARGIN) / PAGE_SCALE);
|
||||
|
||||
// Not foreach to prevent conmodification crashes
|
||||
for (int i = 0; i < rightElements.size(); i++) {
|
||||
BookElement element = rightElements.get(i);
|
||||
|
||||
GlStateManager.color(1F, 1F, 1F, 1F);
|
||||
element.draw(mX, mY, partialTicks);
|
||||
}
|
||||
|
||||
// Not foreach to prevent conmodification crashes
|
||||
for (int i = 0; i < rightElements.size(); i++) {
|
||||
BookElement element = rightElements.get(i);
|
||||
|
||||
GlStateManager.color(1F, 1F, 1F, 1F);
|
||||
element.drawOverlay(mX, mY, partialTicks);
|
||||
}
|
||||
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
|
||||
public int openPage(int page) {
|
||||
return openPage(page, false);
|
||||
}
|
||||
|
||||
public int openPage(int page, boolean returner) {
|
||||
if (loadingAchievements)
|
||||
return -1;
|
||||
|
||||
if (page < 0)
|
||||
return -1;
|
||||
|
||||
int bookPage;
|
||||
if (page == 1)
|
||||
bookPage = 0;
|
||||
else if (page % 2 == 0)
|
||||
bookPage = (page - 1) / 2 + 1;
|
||||
else
|
||||
bookPage = (page - 2) / 2 + 1;
|
||||
|
||||
if (bookPage >= -1 && bookPage < book.getFullPageCount(statFile)) {
|
||||
if (returner)
|
||||
oldPage = this.page;
|
||||
|
||||
_setPage(bookPage);
|
||||
}
|
||||
|
||||
return page % 2 == 0 ? 0 : 1;
|
||||
}
|
||||
|
||||
public void _setPage(int page) {
|
||||
this.page = page;
|
||||
buildPages();
|
||||
}
|
||||
|
||||
public int getPage(int side) {
|
||||
if (page == 0 && side == 0)
|
||||
return -1;
|
||||
else if (page == 0 && side == 1)
|
||||
return 0;
|
||||
else if (side == 0)
|
||||
return (page - 1) * 2 + 1;
|
||||
else if (side == 1)
|
||||
return (page - 2) * 2 + 2;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int getPage_() {
|
||||
return page;
|
||||
}
|
||||
|
||||
public ArrayList<BookElement> getElements(int side) {
|
||||
return side == 0 ? leftElements : side == 1 ? rightElements : null;
|
||||
}
|
||||
|
||||
public void openCover() {
|
||||
if (loadingAchievements)
|
||||
return;
|
||||
|
||||
_setPage(-1);
|
||||
|
||||
this.leftElements.clear();
|
||||
this.rightElements.clear();
|
||||
buildPages();
|
||||
}
|
||||
|
||||
public void itemClicked(ItemStack item) {
|
||||
StringActionProcessor.process(book.getItemAction(ItemStackData.getItemStackData(item, true)), this);
|
||||
}
|
||||
|
||||
private void buildPages() {
|
||||
if (loadingAchievements)
|
||||
return;
|
||||
|
||||
leftElements.clear();
|
||||
rightElements.clear();
|
||||
|
||||
if (page == -1)
|
||||
return;
|
||||
|
||||
if (page == 0) {
|
||||
PageData page = book.findPage(0, statFile);
|
||||
|
||||
if (page != null)
|
||||
page.content.build(book, rightElements);
|
||||
} else {
|
||||
PageData leftPage = book.findPage((page - 1) * 2 + 1, statFile);
|
||||
PageData rightPage = book.findPage((page - 1) * 2 + 2, statFile);
|
||||
|
||||
if (leftPage != null)
|
||||
leftPage.content.build(book, leftElements);
|
||||
if (rightPage != null)
|
||||
rightPage.content.build(book, rightElements);
|
||||
}
|
||||
|
||||
for (BookElement element : leftElements)
|
||||
element.parent = this;
|
||||
for (BookElement element : rightElements)
|
||||
element.parent = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
if (loadingAchievements) {
|
||||
this.mc.getNetHandler().addToSendQueue(new C16PacketClientStatus(C16PacketClientStatus.EnumState.REQUEST_STATS));
|
||||
return;
|
||||
}
|
||||
|
||||
// The books are unreadable at Gui Scale set to small, so we'll double the scale, and of course half the size so that all our code still works as it should
|
||||
if (mc.gameSettings.guiScale == 1) {
|
||||
width /= 2F;
|
||||
height /= 2F;
|
||||
}
|
||||
|
||||
previousArrow = new GuiArrow(0, -50, -50, 1, book.appearance.arrowColor, book.appearance.arrowColorHover);
|
||||
nextArrow = new GuiArrow(1, -50, -50, 0, book.appearance.arrowColor, book.appearance.arrowColorHover);
|
||||
backArrow = new GuiArrow(2, width / 2 - GuiArrow.WIDTH / 2, height / 2 - GuiArrow.HEIGHT / 2 + PAGE_HEIGHT / 3, 3, book.appearance.arrowColor, book.appearance.arrowColorHover);
|
||||
indexArrow = new GuiArrow(3, width / 2 - PAGE_WIDTH_UNSCALED, height / 2 - PAGE_HEIGHT_UNSCALED / 2 - 3, 3, book.appearance.arrowColor, book.appearance.arrowColorHover);
|
||||
|
||||
buttonList.add(previousArrow);
|
||||
buttonList.add(nextArrow);
|
||||
buttonList.add(backArrow);
|
||||
buttonList.add(indexArrow);
|
||||
|
||||
buildPages();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
super.updateScreen();
|
||||
|
||||
if (loadingAchievements)
|
||||
return;
|
||||
|
||||
previousArrow.visible = page != -1;
|
||||
nextArrow.visible = page < book.getFullPageCount(statFile) - (book.getPageCount(statFile) % 2 != 0 ? 0 : 1);
|
||||
backArrow.visible = oldPage >= -1;
|
||||
|
||||
if (page == -1) {
|
||||
nextArrow.xPosition = width / 2 + 80;
|
||||
indexArrow.visible = false;
|
||||
} else {
|
||||
previousArrow.xPosition = width / 2 - 184;
|
||||
nextArrow.xPosition = width / 2 + 165;
|
||||
|
||||
indexArrow.visible = book.findSection("index") != null && (page - 1) * 2 + 2 > book.findSection("index").getPageCount();
|
||||
}
|
||||
|
||||
previousArrow.yPosition = height / 2 + 75;
|
||||
nextArrow.yPosition = height / 2 + 75;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doneLoading() {
|
||||
loadingAchievements = false;
|
||||
|
||||
initGui();
|
||||
openPage(book.findPageNumber(BookHelper.getSavedPage(item), statFile));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(GuiButton button) {
|
||||
if (loadingAchievements)
|
||||
return;
|
||||
|
||||
if (button instanceof GuiBookmark) {
|
||||
openPage(book.findPageNumber(((GuiBookmark) button).data.page, statFile));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (button == previousArrow) {
|
||||
page--;
|
||||
if (page < -1)
|
||||
page = -1;
|
||||
} else if (button == nextArrow) {
|
||||
page++;
|
||||
if (page > book.getFullPageCount(statFile) - (book.getPageCount(statFile) % 2 != 0 ? 0 : 1))
|
||||
page = book.getFullPageCount(statFile) - 1;
|
||||
} else if (button == backArrow) {
|
||||
if (oldPage >= -1)
|
||||
page = oldPage;
|
||||
} else if (button == indexArrow) {
|
||||
openPage(book.findPageNumber("index.page1"));
|
||||
}
|
||||
|
||||
oldPage = -2;
|
||||
buildPages();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void keyTyped(char typedChar, int keyCode) throws IOException {
|
||||
super.keyTyped(typedChar, keyCode);
|
||||
|
||||
if (loadingAchievements)
|
||||
return;
|
||||
|
||||
switch (keyCode) {
|
||||
case Keyboard.KEY_LEFT:
|
||||
case Keyboard.KEY_A:
|
||||
actionPerformed(previousArrow);
|
||||
break;
|
||||
case Keyboard.KEY_RIGHT:
|
||||
case Keyboard.KEY_D:
|
||||
actionPerformed(nextArrow);
|
||||
break;
|
||||
case Keyboard.KEY_F3:
|
||||
debug = !debug;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
|
||||
if (loadingAchievements)
|
||||
return;
|
||||
|
||||
super.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
|
||||
boolean right = false;
|
||||
|
||||
mouseX = (int) ((Mouse.getX() * this.width / this.mc.displayWidth - (width / 2 - PAGE_WIDTH_UNSCALED) - PAGE_PADDING - PAGE_MARGIN) / PAGE_SCALE);
|
||||
mouseY = (int) ((this.height - Mouse.getY() * this.height / this.mc.displayHeight - 1 - (height / 2 - PAGE_HEIGHT_UNSCALED / 2) - PAGE_PADDING - PAGE_MARGIN) / PAGE_SCALE);
|
||||
|
||||
if (mouseX > PAGE_WIDTH + (PAGE_MARGIN + PAGE_PADDING) / PAGE_SCALE) {
|
||||
mouseX = (int) ((Mouse.getX() * this.width / this.mc.displayWidth - (width / 2) - PAGE_PADDING - PAGE_MARGIN) / PAGE_SCALE);
|
||||
right = true;
|
||||
}
|
||||
|
||||
// Not foreach to prevent conmodification crashes
|
||||
for (int i = 0; right ? i < rightElements.size() : i < leftElements.size(); i++) {
|
||||
BookElement element = right ? rightElements.get(i) : leftElements.get(i);
|
||||
|
||||
element.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGuiClosed() {
|
||||
if (loadingAchievements)
|
||||
return;
|
||||
|
||||
PageData page = this.page == 0 ? book.findPage(0, statFile) : book.findPage((this.page - 1) * 2 + 1, statFile);
|
||||
|
||||
if (page == null)
|
||||
page = book.findPage((this.page - 1) * 2 + 2, statFile);
|
||||
|
||||
if (this.page == -1)
|
||||
BookLoader.updateSavedPage(mc.thePlayer, item, "");
|
||||
else if (page != null && page.parent != null)
|
||||
BookLoader.updateSavedPage(mc.thePlayer, item, page.parent.name + "." + page.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doesGuiPauseGame() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package slimeknights.mantle.client.gui.book;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import slimeknights.mantle.client.book.data.BookmarkData;
|
||||
|
||||
public class GuiBookmark extends GuiButton {
|
||||
|
||||
private static final ResourceLocation TEX_BOOK = new ResourceLocation("mantle:textures/gui/book.png");
|
||||
|
||||
public static final int WIDTH = 31;
|
||||
public static final int HEIGHT = 9;
|
||||
public static final int TEX_X = 0, TEX_Y = 400;
|
||||
public static final int ADD_W = 5, ADD_H = 5, ADD_X = 32, ADD_Y = 402;
|
||||
|
||||
public static final float TEXT_SCALE = 0.5F;
|
||||
|
||||
public int type = 0;
|
||||
|
||||
public final BookmarkData data;
|
||||
|
||||
public GuiBookmark(BookmarkData data) {
|
||||
super(-1337, -500, -500, WIDTH, HEIGHT, "");
|
||||
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawButton(Minecraft mc, int mouseX, int mouseY) {
|
||||
if (visible) {
|
||||
int tex_y = TEX_Y + HEIGHT * type;
|
||||
|
||||
mc.renderEngine.bindTexture(TEX_BOOK);
|
||||
|
||||
float r = ((data.color >> 16) & 0xff) / 255.F;
|
||||
float g = ((data.color >> 8) & 0xff) / 255.F;
|
||||
float b = (data.color & 0xff) / 255.F;
|
||||
|
||||
GlStateManager.color(r, g, b);
|
||||
Gui.drawScaledCustomSizeModalRect(xPosition, yPosition, TEX_X, tex_y, WIDTH, HEIGHT, width, height, 512, 512);
|
||||
|
||||
if (data.text != null && !data.text.isEmpty()) {
|
||||
TextDataRenderer.drawScaledString(mc.fontRendererObj, data.text, xPosition + 1, yPosition + height / 2 - mc.fontRendererObj.FONT_HEIGHT * TEXT_SCALE / 2 + 1, 0xFFFFFFFF, true, TEXT_SCALE);
|
||||
}
|
||||
|
||||
GlStateManager.color(1F, 1F, 1F);
|
||||
|
||||
if (data.page.equals("ADD")) {
|
||||
Gui.drawModalRectWithCustomSizedTexture(xPosition + width / 2 - ADD_W / 2, yPosition + height / 2 - ADD_H / 2, ADD_X, ADD_Y, ADD_W, ADD_H, 512, 512);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,268 @@
|
||||
package slimeknights.mantle.client.gui.book;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.WorldRenderer;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import slimeknights.mantle.client.book.data.element.TextData;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class TextDataRenderer {
|
||||
|
||||
public static String drawText(int x, int y, int boxWidth, int boxHeight, TextData[] data, int mouseX, int mouseY) {
|
||||
String action = "";
|
||||
|
||||
String[] drawLabel = null;
|
||||
|
||||
FontRenderer fr = Minecraft.getMinecraft().fontRendererObj;
|
||||
|
||||
int atX = x;
|
||||
int atY = y;
|
||||
|
||||
float prevScale = 1.F;
|
||||
|
||||
for (TextData item : data) {
|
||||
int box1X, box1Y, box1W = 9999, box1H = y + fr.FONT_HEIGHT;
|
||||
int box2X, box2Y = 9999, box2W, box2H;
|
||||
int box3X = 9999, box3Y = 9999, box3W, box3H;
|
||||
|
||||
if (item.text == null || item.text.isEmpty())
|
||||
continue;
|
||||
|
||||
if (item.paragraph) {
|
||||
atX = x;
|
||||
atY += fr.FONT_HEIGHT * 2 * prevScale;
|
||||
}
|
||||
|
||||
prevScale = item.scale;
|
||||
|
||||
String modifiers = "";
|
||||
|
||||
modifiers += EnumChatFormatting.getValueByName(item.color);
|
||||
|
||||
if (item.bold)
|
||||
modifiers += EnumChatFormatting.BOLD;
|
||||
if (item.italic)
|
||||
modifiers += EnumChatFormatting.ITALIC;
|
||||
if (item.underlined)
|
||||
modifiers += EnumChatFormatting.UNDERLINE;
|
||||
if (item.strikethrough)
|
||||
modifiers += EnumChatFormatting.STRIKETHROUGH;
|
||||
if (item.obfuscated)
|
||||
modifiers += EnumChatFormatting.OBFUSCATED;
|
||||
|
||||
String[] split = cropStringBySize(item.text, modifiers, boxWidth, boxHeight - (atY - y), boxWidth - (atX - x), fr, item.scale);
|
||||
|
||||
box1X = atX;
|
||||
box1Y = atY;
|
||||
box2X = x;
|
||||
box2W = x + boxWidth;
|
||||
|
||||
for (int i = 0; i < split.length; i++) {
|
||||
if (i == split.length - 1) {
|
||||
box3X = atX;
|
||||
box3Y = atY;
|
||||
}
|
||||
|
||||
String s = split[i];
|
||||
drawScaledString(fr, modifiers + s, atX, atY, 0, false, item.scale);
|
||||
|
||||
if (i < split.length - 1) {
|
||||
atY += fr.FONT_HEIGHT;
|
||||
atX = x;
|
||||
}
|
||||
|
||||
if (i == 0) {
|
||||
box2Y = atY;
|
||||
|
||||
if (atX == x)
|
||||
box1W = x + boxWidth;
|
||||
else
|
||||
box1W = atX;
|
||||
}
|
||||
}
|
||||
|
||||
box2H = atY;
|
||||
|
||||
atX += fr.getStringWidth(split[split.length - 1]) * item.scale;
|
||||
if (atX - x >= boxWidth) {
|
||||
atX = x;
|
||||
atY += fr.FONT_HEIGHT * item.scale;
|
||||
}
|
||||
|
||||
box3W = atX;
|
||||
box3H = (int) (atY + fr.FONT_HEIGHT * item.scale);
|
||||
|
||||
if (item.tooltip != null && item.tooltip.length > 0) {
|
||||
// Uncomment to render bounding boxes for event handling
|
||||
/*drawGradientRect(box1X, box1Y, box1W, box1H, 0xFF00FF00, 0xFF00FF00);
|
||||
drawGradientRect(box2X, box2Y, box2W, box2H, 0xFFFF0000, 0xFFFF0000);
|
||||
drawGradientRect(box3X, box3Y, box3W, box3H, 0xFF0000FF, 0xFF0000FF);
|
||||
drawGradientRect(mouseX, mouseY, mouseX + 5, mouseY + 5, 0xFFFF00FF, 0xFFFFFF00);*/
|
||||
|
||||
if ((mouseX >= box1X && mouseX <= box1W && mouseY >= box1Y && mouseY <= box1H && box1X != box1W && box1Y != box1H) || (mouseX >= box2X && mouseX <= box2W && mouseY >= box2Y && mouseY <= box2H && box2X != box2W && box2Y != box2H) || (mouseX >= box3X && mouseX <= box3W && mouseY >= box3Y && mouseY <= box3H && box3X != box3W && box1Y != box3H)) {
|
||||
drawLabel = item.tooltip;
|
||||
}
|
||||
}
|
||||
|
||||
if (item.action != null && !item.action.isEmpty())
|
||||
if ((mouseX >= box1X && mouseX <= box1W && mouseY >= box1Y && mouseY <= box1H && box1X != box1W && box1Y != box1H) || (mouseX >= box2X && mouseX <= box2W && mouseY >= box2Y && mouseY <= box2H && box2X != box2W && box2Y != box2H) || (mouseX >= box3X && mouseX <= box3W && mouseY >= box3Y && mouseY <= box3H && box3X != box3W && box1Y != box3H)) {
|
||||
action = item.action;
|
||||
}
|
||||
|
||||
if (atY >= y + boxHeight) {
|
||||
fr.drawString("...", atX, atY, 0, false);
|
||||
break;
|
||||
}
|
||||
y = atY;
|
||||
}
|
||||
|
||||
if (GuiBook.debug && action != null && !action.isEmpty()) {
|
||||
String[] label = drawLabel;
|
||||
drawLabel = new String[label != null ? label.length + 2 : 1];
|
||||
|
||||
if (label != null)
|
||||
for (int i = 0; i < label.length; i++)
|
||||
drawLabel[i] = label[i];
|
||||
|
||||
drawLabel[drawLabel.length > 1 ? drawLabel.length - 2 : 0] = "";
|
||||
drawLabel[drawLabel.length - 1] = EnumChatFormatting.GRAY + "Action: " + action;
|
||||
}
|
||||
|
||||
if (drawLabel != null) {
|
||||
drawHoveringText(drawLabel, mouseX, mouseY, fr);
|
||||
}
|
||||
|
||||
return action;
|
||||
}
|
||||
|
||||
public static String[] cropStringBySize(String s, String modifiers, int width, int height, FontRenderer fr, float scale) {
|
||||
return cropStringBySize(s, modifiers, width, height, width, fr, scale);
|
||||
}
|
||||
|
||||
public static String[] cropStringBySize(String s, String modifiers, int width, int height, int firstWidth, FontRenderer fr, float scale) {
|
||||
int curWidth = 0;
|
||||
int curHeight = (int) (fr.FONT_HEIGHT * scale);
|
||||
|
||||
for (int i = 0; i < s.length(); i++) {
|
||||
curWidth += fr.getStringWidth(modifiers + Character.toString(s.charAt(i))) * scale;
|
||||
|
||||
if ((curHeight == (int) (fr.FONT_HEIGHT * scale) && curWidth > firstWidth) || (curHeight != (int) (fr.FONT_HEIGHT * scale) && curWidth > width)) {
|
||||
int oldI = i;
|
||||
while (i >= 0 && s.charAt(i) != ' ')
|
||||
i--;
|
||||
if (i <= 0)
|
||||
i = oldI;
|
||||
|
||||
s = s.substring(0, i) + "\r" + s.substring(i + (i == oldI ? 0 : 1));
|
||||
|
||||
i++;
|
||||
curWidth = 0;
|
||||
curHeight += fr.FONT_HEIGHT * scale;
|
||||
|
||||
if (curHeight >= height)
|
||||
return s.substring(0, i).split("\r");
|
||||
}
|
||||
}
|
||||
|
||||
return s.split("\r");
|
||||
}
|
||||
|
||||
//BEGIN METHODS FROM GUI
|
||||
private static void drawHoveringText(String[] textLines, int x, int y, FontRenderer font) {
|
||||
if (textLines.length > 0) {
|
||||
GlStateManager.disableDepth();
|
||||
int i = 0;
|
||||
|
||||
for (String s : textLines) {
|
||||
int j = font.getStringWidth(s);
|
||||
|
||||
if (j > i) {
|
||||
i = j;
|
||||
}
|
||||
}
|
||||
|
||||
int l1 = x + 12;
|
||||
int i2 = y - 12;
|
||||
int k = 8;
|
||||
|
||||
if (textLines.length > 1) {
|
||||
k += 2 + (textLines.length - 1) * 10;
|
||||
}
|
||||
|
||||
if (l1 + i > GuiBook.PAGE_WIDTH) {
|
||||
l1 -= 28 + i;
|
||||
}
|
||||
|
||||
if (i2 + k + 6 > GuiBook.PAGE_HEIGHT) {
|
||||
i2 = GuiBook.PAGE_HEIGHT - k - 6;
|
||||
}
|
||||
|
||||
int l = -267386864;
|
||||
drawGradientRect(l1 - 3, i2 - 4, l1 + i + 3, i2 - 3, l, l);
|
||||
drawGradientRect(l1 - 3, i2 + k + 3, l1 + i + 3, i2 + k + 4, l, l);
|
||||
drawGradientRect(l1 - 3, i2 - 3, l1 + i + 3, i2 + k + 3, l, l);
|
||||
drawGradientRect(l1 - 4, i2 - 3, l1 - 3, i2 + k + 3, l, l);
|
||||
drawGradientRect(l1 + i + 3, i2 - 3, l1 + i + 4, i2 + k + 3, l, l);
|
||||
int i1 = 1347420415;
|
||||
int j1 = (i1 & 16711422) >> 1 | i1 & -16777216;
|
||||
drawGradientRect(l1 - 3, i2 - 3 + 1, l1 - 3 + 1, i2 + k + 3 - 1, i1, j1);
|
||||
drawGradientRect(l1 + i + 2, i2 - 3 + 1, l1 + i + 3, i2 + k + 3 - 1, i1, j1);
|
||||
drawGradientRect(l1 - 3, i2 - 3, l1 + i + 3, i2 - 3 + 1, i1, i1);
|
||||
drawGradientRect(l1 - 3, i2 + k + 2, l1 + i + 3, i2 + k + 3, j1, j1);
|
||||
|
||||
for (int k1 = 0; k1 < textLines.length; ++k1) {
|
||||
String s1 = textLines[k1];
|
||||
font.drawStringWithShadow(s1, (float) l1, (float) i2, -1);
|
||||
|
||||
if (k1 == 0) {
|
||||
i2 += 2;
|
||||
}
|
||||
|
||||
i2 += 10;
|
||||
}
|
||||
|
||||
GlStateManager.enableDepth();
|
||||
}
|
||||
}
|
||||
|
||||
public static void drawScaledString(FontRenderer font, String text, float x, float y, int color, boolean dropShadow, float scale) {
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.translate(x, y, 0);
|
||||
GlStateManager.scale(scale, scale, 1F);
|
||||
font.drawString(text, 0, 0, color, dropShadow);
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
|
||||
private static void drawGradientRect(int left, int top, int right, int bottom, int startColor, int endColor) {
|
||||
float f = (float) (startColor >> 24 & 255) / 255.0F;
|
||||
float f1 = (float) (startColor >> 16 & 255) / 255.0F;
|
||||
float f2 = (float) (startColor >> 8 & 255) / 255.0F;
|
||||
float f3 = (float) (startColor & 255) / 255.0F;
|
||||
float f4 = (float) (endColor >> 24 & 255) / 255.0F;
|
||||
float f5 = (float) (endColor >> 16 & 255) / 255.0F;
|
||||
float f6 = (float) (endColor >> 8 & 255) / 255.0F;
|
||||
float f7 = (float) (endColor & 255) / 255.0F;
|
||||
GlStateManager.disableTexture2D();
|
||||
GlStateManager.disableAlpha();
|
||||
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
|
||||
GlStateManager.shadeModel(7425);
|
||||
Tessellator tessellator = Tessellator.getInstance();
|
||||
WorldRenderer worldrenderer = tessellator.getWorldRenderer();
|
||||
worldrenderer.begin(7, DefaultVertexFormats.POSITION_COLOR);
|
||||
worldrenderer.pos((double) right, (double) top, 0D).color(f1, f2, f3, f).endVertex();
|
||||
worldrenderer.pos((double) left, (double) top, 0D).color(f1, f2, f3, f).endVertex();
|
||||
worldrenderer.pos((double) left, (double) bottom, 0D).color(f5, f6, f7, f4).endVertex();
|
||||
worldrenderer.pos((double) right, (double) bottom, 0D).color(f5, f6, f7, f4).endVertex();
|
||||
tessellator.draw();
|
||||
GlStateManager.shadeModel(7424);
|
||||
GlStateManager.enableAlpha();
|
||||
GlStateManager.enableTexture2D();
|
||||
}
|
||||
//END METHODS FROM GUI
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package slimeknights.mantle.client.gui.book;
|
||||
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
public class Textures {
|
||||
|
||||
public static final ResourceLocation TEX_BOOK = new ResourceLocation("mantle:textures/gui/book/book.png");
|
||||
public static final ResourceLocation TEX_BOOKFRONT = new ResourceLocation("mantle:textures/gui/book/bookfront.png");
|
||||
public static final ResourceLocation TEX_BOX = new ResourceLocation("mantle:textures/gui/box.png");
|
||||
|
||||
public static final ResourceLocation TEX_CRAFTING = new ResourceLocation("mantle:textures/gui/book/crafting.png");
|
||||
public static final ResourceLocation TEX_SMELTING = new ResourceLocation("mantle:textures/gui/book/smelting.png");
|
||||
public static final ResourceLocation TEX_MISC = new ResourceLocation("mantle:textures/gui/book/misc.png");
|
||||
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package slimeknights.mantle.client.gui.book.editor;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.texture.TextureManager;
|
||||
import slimeknights.mantle.client.book.data.BookData;
|
||||
import slimeknights.mantle.client.gui.book.BoxRenderer;
|
||||
import slimeknights.mantle.client.gui.book.GuiBook;
|
||||
import slimeknights.mantle.client.gui.book.Textures;
|
||||
|
||||
public class GuiBookEditor extends GuiScreen {
|
||||
|
||||
private static final int SIDEBAR_WIDTH = 120;
|
||||
|
||||
private GuiBook innerUi;
|
||||
private int side;
|
||||
|
||||
public GuiBookEditor(@Nullable BookData book) {
|
||||
if (book == null)
|
||||
book = new BookData();
|
||||
|
||||
innerUi = new GuiBook(book, null, null);
|
||||
innerUi.mc = Minecraft.getMinecraft();
|
||||
innerUi.doneLoading();
|
||||
|
||||
innerUi._setPage(-1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
GlStateManager.pushMatrix();
|
||||
|
||||
TextureManager render = this.mc.renderEngine;
|
||||
|
||||
if (mc.gameSettings.guiScale == 1) {
|
||||
GlStateManager.scale(2F, 2F, 2F);
|
||||
|
||||
mouseX /= 2;
|
||||
mouseY /= 2;
|
||||
}
|
||||
|
||||
BoxRenderer.drawBox(width / 2 - (GuiBook.PAGE_WIDTH_UNSCALED + SIDEBAR_WIDTH) / 2, height / 2 - (GuiBook.PAGE_HEIGHT_UNSCALED - GuiBook.PAGE_PADDING) / 2, SIDEBAR_WIDTH + GuiBook.PAGE_PADDING + GuiBook.PAGE_MARGIN, GuiBook.PAGE_HEIGHT_UNSCALED - GuiBook.PAGE_PADDING, 0);
|
||||
|
||||
if (innerUi.getPage_() == -1) {
|
||||
GlStateManager.pushMatrix();
|
||||
if (mc.gameSettings.guiScale == 1)
|
||||
GlStateManager.scale(0.5F, 0.5F, 0.5F);
|
||||
innerUi.openCover();
|
||||
innerUi.drawScreen(mouseX * (mc.gameSettings.guiScale == 1 ? 2 : 1), mouseY * (mc.gameSettings.guiScale == 1 ? 2 : 1), partialTicks);
|
||||
GlStateManager.popMatrix();
|
||||
} else {
|
||||
render.bindTexture(Textures.TEX_BOOK);
|
||||
|
||||
GlStateManager.color(1F, 1F, 1F);
|
||||
drawModalRectWithCustomSizedTexture(width / 2 - GuiBook.PAGE_WIDTH_UNSCALED / 2, height / 2 - GuiBook.PAGE_HEIGHT_UNSCALED / 2, 0, GuiBook.PAGE_HEIGHT_UNSCALED, GuiBook.PAGE_WIDTH_UNSCALED - GuiBook.PAGE_MARGIN - GuiBook.PAGE_PADDING, GuiBook.PAGE_HEIGHT_UNSCALED, GuiBook.TEX_SIZE, GuiBook.TEX_SIZE);
|
||||
drawModalRectWithCustomSizedTexture(width / 2 - GuiBook.PAGE_WIDTH_UNSCALED / 2 + GuiBook.PAGE_MARGIN + GuiBook.PAGE_PADDING, height / 2 - GuiBook.PAGE_HEIGHT_UNSCALED / 2, GuiBook.PAGE_WIDTH_UNSCALED + GuiBook.PAGE_MARGIN + GuiBook.PAGE_PADDING, GuiBook.PAGE_HEIGHT_UNSCALED, GuiBook.PAGE_WIDTH_UNSCALED - GuiBook.PAGE_MARGIN - GuiBook.PAGE_PADDING, GuiBook.PAGE_HEIGHT_UNSCALED, GuiBook.TEX_SIZE, GuiBook.TEX_SIZE);
|
||||
}
|
||||
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
buttonList.clear();
|
||||
|
||||
innerUi.width = width + SIDEBAR_WIDTH * (mc.gameSettings.guiScale == 1 ? 2 : 1);
|
||||
innerUi.height = height;
|
||||
|
||||
if (mc.gameSettings.guiScale == 1) {
|
||||
width /= 2F;
|
||||
height /= 2F;
|
||||
}
|
||||
|
||||
innerUi.initGui();
|
||||
innerUi.updateScreen();
|
||||
innerUi.buttonList.clear();
|
||||
|
||||
buttonList.add(new GuiButton(0, 0, height - 20, 50, 20, "Import"));
|
||||
buttonList.add(new GuiButton(1, 55, height - 20, 50, 20, "Export"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
package slimeknights.mantle.client.gui.book.element;
|
||||
|
||||
import java.util.List;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.texture.TextureManager;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import slimeknights.mantle.client.gui.book.GuiBook;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public abstract class BookElement extends Gui {
|
||||
|
||||
public GuiBook parent;
|
||||
|
||||
protected Minecraft mc = Minecraft.getMinecraft();
|
||||
protected FontRenderer fontRenderer = mc.fontRendererObj;
|
||||
protected TextureManager renderEngine = mc.renderEngine;
|
||||
|
||||
public int x, y;
|
||||
|
||||
public BookElement(int x, int y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public abstract void draw(int mouseX, int mouseY, float partialTicks);
|
||||
|
||||
public void drawOverlay(int mouseX, int mouseY, float partialTicks) {
|
||||
}
|
||||
|
||||
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
|
||||
|
||||
}
|
||||
|
||||
public void renderToolTip(FontRenderer fontRenderer, ItemStack stack, int x, int y) {
|
||||
List<String> list = stack.getTooltip(mc.thePlayer, mc.gameSettings.advancedItemTooltips);
|
||||
|
||||
for (int i = 0; i < list.size(); ++i) {
|
||||
if (i == 0) {
|
||||
list.set(i, stack.getRarity().rarityColor + list.get(i));
|
||||
} else {
|
||||
list.set(i, EnumChatFormatting.GRAY + list.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
FontRenderer font = stack.getItem().getFontRenderer(stack);
|
||||
drawHoveringText(list, x, y, (font == null ? fontRenderer : font));
|
||||
}
|
||||
|
||||
public void drawHoveringText(List<String> textLines, int x, int y, FontRenderer font) {
|
||||
if (!textLines.isEmpty()) {
|
||||
GlStateManager.disableDepth();
|
||||
int i = 0;
|
||||
|
||||
for (String s : textLines) {
|
||||
int j = font.getStringWidth(s);
|
||||
|
||||
if (j > i) {
|
||||
i = j;
|
||||
}
|
||||
}
|
||||
|
||||
int l1 = x + 12;
|
||||
int i2 = y - 12;
|
||||
int k = 8;
|
||||
|
||||
if (textLines.size() > 1) {
|
||||
k += 2 + (textLines.size() - 1) * 10;
|
||||
}
|
||||
|
||||
if (l1 + i > GuiBook.PAGE_WIDTH) {
|
||||
l1 -= 28 + i;
|
||||
}
|
||||
|
||||
if (i2 + k + 6 > GuiBook.PAGE_HEIGHT) {
|
||||
i2 = GuiBook.PAGE_HEIGHT - k - 6;
|
||||
}
|
||||
|
||||
int l = -267386864;
|
||||
this.drawGradientRect(l1 - 3, i2 - 4, l1 + i + 3, i2 - 3, l, l);
|
||||
this.drawGradientRect(l1 - 3, i2 + k + 3, l1 + i + 3, i2 + k + 4, l, l);
|
||||
this.drawGradientRect(l1 - 3, i2 - 3, l1 + i + 3, i2 + k + 3, l, l);
|
||||
this.drawGradientRect(l1 - 4, i2 - 3, l1 - 3, i2 + k + 3, l, l);
|
||||
this.drawGradientRect(l1 + i + 3, i2 - 3, l1 + i + 4, i2 + k + 3, l, l);
|
||||
int i1 = 1347420415;
|
||||
int j1 = (i1 & 16711422) >> 1 | i1 & -16777216;
|
||||
this.drawGradientRect(l1 - 3, i2 - 3 + 1, l1 - 3 + 1, i2 + k + 3 - 1, i1, j1);
|
||||
this.drawGradientRect(l1 + i + 2, i2 - 3 + 1, l1 + i + 3, i2 + k + 3 - 1, i1, j1);
|
||||
this.drawGradientRect(l1 - 3, i2 - 3, l1 + i + 3, i2 - 3 + 1, i1, i1);
|
||||
this.drawGradientRect(l1 - 3, i2 + k + 2, l1 + i + 3, i2 + k + 3, j1, j1);
|
||||
|
||||
for (int k1 = 0; k1 < textLines.size(); ++k1) {
|
||||
String s1 = textLines.get(k1);
|
||||
font.drawStringWithShadow(s1, (float) l1, (float) i2, -1);
|
||||
|
||||
if (k1 == 0) {
|
||||
i2 += 2;
|
||||
}
|
||||
|
||||
i2 += 10;
|
||||
}
|
||||
|
||||
GlStateManager.enableDepth();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package slimeknights.mantle.client.gui.book.element;
|
||||
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import slimeknights.mantle.client.book.data.element.ImageData;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class ElementImage extends SizedBookElement {
|
||||
|
||||
public ImageData image;
|
||||
public int colorMultiplier;
|
||||
|
||||
public ElementImage(ImageData image) {
|
||||
this(image, 0xFFFFFF);
|
||||
}
|
||||
|
||||
public ElementImage(ImageData image, int colorMultiplier) {
|
||||
this(image.x, image.y, image.width, image.height, image, colorMultiplier);
|
||||
}
|
||||
|
||||
public ElementImage(int x, int y, int width, int height, ImageData image) {
|
||||
this(x, y, width, height, image, image.colorMultiplier);
|
||||
}
|
||||
|
||||
public ElementImage(int x, int y, int width, int height, ImageData image, int colorMultiplier) {
|
||||
super(x, y, width, height);
|
||||
|
||||
this.image = image;
|
||||
|
||||
if (image.x != -1)
|
||||
x = image.x;
|
||||
if (image.y != -1)
|
||||
y = image.y;
|
||||
if (image.width != -1)
|
||||
width = image.width;
|
||||
if (image.height != -1)
|
||||
height = image.height;
|
||||
if (image.colorMultiplier != 0xFFFFFF)
|
||||
colorMultiplier = image.colorMultiplier;
|
||||
|
||||
this.x = x == -1 ? 0 : x;
|
||||
this.y = y == -1 ? 0 : y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.colorMultiplier = colorMultiplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(int mouseX, int mouseY, float partialTicks) {
|
||||
renderEngine.bindTexture(image.location);
|
||||
|
||||
float r = ((colorMultiplier >> 16) & 0xff) / 255.F;
|
||||
float g = ((colorMultiplier >> 8) & 0xff) / 255.F;
|
||||
float b = (colorMultiplier & 0xff) / 255.F;
|
||||
|
||||
GlStateManager.color(r, g, b);
|
||||
|
||||
drawScaledCustomSizeModalRect(x, y, image.u, image.v, image.uw, image.vh, width, height, image.texWidth, image.texHeight);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package slimeknights.mantle.client.gui.book.element;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import slimeknights.mantle.client.book.action.StringActionProcessor;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class ElementItem extends BookElement {
|
||||
|
||||
public static final int ITEM_SIZE_HARDCODED = 16;
|
||||
public static final int ITEM_SWITCH_TICKS = 90;
|
||||
|
||||
public ItemStack[] itemCycle;
|
||||
public float scale;
|
||||
public String action;
|
||||
|
||||
public int renderTick = 0;
|
||||
public int currentItem = 0;
|
||||
|
||||
public ElementItem(int x, int y, float scale, Item item) {
|
||||
this(x, y, scale, new ItemStack(item));
|
||||
}
|
||||
|
||||
public ElementItem(int x, int y, float scale, Block item) {
|
||||
this(x, y, scale, new ItemStack(item));
|
||||
}
|
||||
|
||||
public ElementItem(int x, int y, float scale, ItemStack item) {
|
||||
this(x, y, scale, new ItemStack[]{item});
|
||||
}
|
||||
|
||||
public ElementItem(int x, int y, float scale, ItemStack[] itemCycle) {
|
||||
this(x, y, scale, itemCycle, null);
|
||||
}
|
||||
|
||||
public ElementItem(int x, int y, float scale, ItemStack[] itemCycle, String action) {
|
||||
super(x, y);
|
||||
|
||||
this.itemCycle = itemCycle;
|
||||
this.scale = scale;
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(int mouseX, int mouseY, float partialTicks) {
|
||||
renderTick++;
|
||||
|
||||
if (renderTick > ITEM_SWITCH_TICKS) {
|
||||
renderTick = 0;
|
||||
currentItem++;
|
||||
|
||||
if (currentItem >= itemCycle.length)
|
||||
currentItem = 0;
|
||||
}
|
||||
|
||||
RenderHelper.enableGUIStandardItemLighting();
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.translate(x, y, 0);
|
||||
GlStateManager.scale(scale, scale, 1.0F);
|
||||
|
||||
if (currentItem < itemCycle.length)
|
||||
mc.getRenderItem().renderItemAndEffectIntoGUI(itemCycle[currentItem], 0, 0);
|
||||
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawOverlay(int mouseX, int mouseY, float partialTicks) {
|
||||
if (mouseX >= x && mouseY >= y && mouseX <= x + ITEM_SIZE_HARDCODED * scale && mouseY <= y + ITEM_SIZE_HARDCODED * scale && currentItem < itemCycle.length) {
|
||||
renderToolTip(fontRenderer, itemCycle[currentItem], mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
|
||||
if (mouseButton == 0 && mouseX >= x && mouseY >= y && mouseX <= x + ITEM_SIZE_HARDCODED * scale && mouseY <= y + ITEM_SIZE_HARDCODED * scale && currentItem < itemCycle.length) {
|
||||
if (action != null)
|
||||
StringActionProcessor.process(action, parent);
|
||||
else
|
||||
parent.itemClicked(itemCycle[currentItem]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package slimeknights.mantle.client.gui.book.element;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.stats.Achievement;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import slimeknights.mantle.client.book.data.SectionData;
|
||||
|
||||
public class ElementSection extends BookElement {
|
||||
|
||||
public static final int IMG_SIZE = 64;
|
||||
|
||||
public static final int WIDTH = 85;
|
||||
public static final int HEIGHT = 85;
|
||||
|
||||
private SectionData section;
|
||||
|
||||
public ElementSection(int x, int y, SectionData section) {
|
||||
super(x, y);
|
||||
|
||||
this.section = section;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(int mouseX, int mouseY, float partialTicks) {
|
||||
boolean unlocked = section.isUnlocked(parent.statFile);
|
||||
boolean hover = mouseX > x && mouseY > y && mouseX < x + WIDTH && mouseY < y + HEIGHT;
|
||||
|
||||
if (section.icon != null) {
|
||||
renderEngine.bindTexture(section.icon.location);
|
||||
|
||||
if (unlocked)
|
||||
GlStateManager.color(1F, 1F, 1F, hover ? 1F : 0.5F);
|
||||
else {
|
||||
float r = ((parent.book.appearance.lockedSectionColor >> 16) & 0xff) / 255.F;
|
||||
float g = ((parent.book.appearance.lockedSectionColor >> 8) & 0xff) / 255.F;
|
||||
float b = (parent.book.appearance.lockedSectionColor & 0xff) / 255.F;
|
||||
GlStateManager.color(r, g, b, 0.75F);
|
||||
}
|
||||
|
||||
drawScaledCustomSizeModalRect(x + WIDTH / 2 - IMG_SIZE / 2, y + HEIGHT / 2 - IMG_SIZE / 2, section.icon.u, section.icon.v, section.icon.uw, section.icon.vh, IMG_SIZE, IMG_SIZE, section.icon.texWidth, section.icon.texHeight);
|
||||
}
|
||||
|
||||
fontRenderer.drawString(section.getTitle(), x + WIDTH / 2 - fontRenderer.getStringWidth(section.getTitle()) / 2, y + HEIGHT - fontRenderer.FONT_HEIGHT, hover ? 0xFF000000 : 0x7F000000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawOverlay(int mouseX, int mouseY, float partialTicks) {
|
||||
if (section != null && !section.isUnlocked(parent.statFile) && mouseX > x && mouseY > y && mouseX < x + WIDTH && mouseY < y + HEIGHT) {
|
||||
List<String> l = new ArrayList<>();
|
||||
l.add(EnumChatFormatting.RED + "Locked");
|
||||
l.add("Requirements:");
|
||||
|
||||
for (String requirement : section.requirements) {
|
||||
Achievement achievement = SectionData.findAchievement(requirement);
|
||||
if (achievement != null)
|
||||
l.add((SectionData.requirementSatisfied(requirement, parent.statFile) ? EnumChatFormatting.GREEN : EnumChatFormatting.RED) + EnumChatFormatting.getTextWithoutFormattingCodes(achievement.getStatName().getFormattedText()));
|
||||
}
|
||||
|
||||
drawHoveringText(l, mouseX, mouseY, Minecraft.getMinecraft().fontRendererObj);
|
||||
}
|
||||
}
|
||||
|
||||
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
|
||||
if (mouseButton == 0 && section != null && section.isUnlocked(parent.statFile) && mouseX > x && mouseY > y && mouseX < x + WIDTH && mouseY < y + HEIGHT)
|
||||
parent.openPage(parent.book.getFirstPageNumber(section, parent.statFile));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,324 @@
|
||||
package slimeknights.mantle.client.gui.book.element;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.BlockModelRenderer;
|
||||
import net.minecraft.client.renderer.EntityRenderer;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.WorldRenderer;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.client.renderer.texture.TextureUtil;
|
||||
import net.minecraft.client.resources.model.IBakedModel;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.nbt.JsonToNBT;
|
||||
import net.minecraft.nbt.NBTException;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.WorldType;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import slimeknights.mantle.client.book.data.element.BlockData;
|
||||
import slimeknights.mantle.client.book.data.element.ItemStackData;
|
||||
|
||||
public class ElementStructure extends SizedBookElement {
|
||||
|
||||
private BlockAccess world;
|
||||
private float scale = 50.0F;
|
||||
private float xTranslate = 0F;
|
||||
private float yTranslate = 0F;
|
||||
|
||||
private float w = 0F;
|
||||
private float h = 0F;
|
||||
|
||||
private float rotX = -11.25F;
|
||||
private float rotY = 45F;
|
||||
private float rotZ = 0F;
|
||||
|
||||
public ElementStructure(int x, int y, int width, int height, int[] size, BlockData[] structure) {
|
||||
super(x, y, width, height);
|
||||
world = new BlockAccess(size, structure);
|
||||
|
||||
if (size.length == 3) {
|
||||
scale = size[0] > size[1] ? width / size[0] - 10F : height / size[1] - 10F;
|
||||
|
||||
if (scale * size[0] > width)
|
||||
scale = width / size[0] - 10F;
|
||||
|
||||
xTranslate = x + width / 2 - (size[0] * scale) / 2;
|
||||
yTranslate = y + height / 2 - (size[1] * scale) / 2;
|
||||
|
||||
w = size[0] * scale;
|
||||
h = size[1] * scale;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(int mouseX, int mouseY, float partialTicks) {
|
||||
GlStateManager.pushMatrix();
|
||||
|
||||
GlStateManager.translate(xTranslate, yTranslate, 500F);
|
||||
|
||||
GlStateManager.cullFace(GL11.GL_FRONT);
|
||||
|
||||
// Prepare stencil
|
||||
GL11.glEnable(GL11.GL_STENCIL_TEST);
|
||||
GL11.glColorMask(false, false, false, false);
|
||||
GL11.glDepthMask(false);
|
||||
GL11.glStencilFunc(GL11.GL_NEVER, 1, 0xFF);
|
||||
GL11.glStencilOp(GL11.GL_REPLACE, GL11.GL_KEEP, GL11.GL_KEEP);
|
||||
|
||||
GL11.glStencilMask(0xFF);
|
||||
GL11.glClear(GL11.GL_STENCIL_BUFFER_BIT);
|
||||
|
||||
GL11.glBegin(GL11.GL_QUADS);
|
||||
GL11.glVertex2i(0, 0);
|
||||
GL11.glVertex2i(0, height);
|
||||
GL11.glVertex2i(width, height);
|
||||
GL11.glVertex2i(width, 0);
|
||||
GL11.glEnd();
|
||||
|
||||
GL11.glColorMask(true, true, true, true);
|
||||
GL11.glDepthMask(true);
|
||||
GL11.glStencilMask(0x00);
|
||||
GL11.glStencilFunc(GL11.GL_EQUAL, 0, 0xFF);
|
||||
|
||||
GlStateManager.color(0F, 1F, 0F, 1F);
|
||||
GL11.glBegin(GL11.GL_QUADS);
|
||||
GL11.glVertex2i(0, 0);
|
||||
GL11.glVertex2i(0, height);
|
||||
GL11.glVertex2i(width, height);
|
||||
GL11.glVertex2i(width, 0);
|
||||
GL11.glEnd();
|
||||
|
||||
GlStateManager.translate(w / 2, h / 2, 0);
|
||||
GlStateManager.rotate(rotX, 1F, 0F, 0F);
|
||||
GlStateManager.rotate(rotY, 0F, 1F, 0F);
|
||||
GlStateManager.rotate(rotZ, 0F, 0F, 1F);
|
||||
GlStateManager.translate(-w / 2, -h / 2, 0);
|
||||
|
||||
for (int x = 0; x < world.getWidth(); x++) {
|
||||
for (int y = 0; y < world.getHeight(); y++) {
|
||||
for (int z = 0; z < world.getDepth(); z++) {
|
||||
BlockPos pos = new BlockPos(x, y, z);
|
||||
IBlockState state = world.getBlockState(pos);
|
||||
IBakedModel model = mc.getBlockRendererDispatcher().getModelFromBlockState(world.getBlockState(pos), world, pos);
|
||||
|
||||
Block block = state.getBlock();
|
||||
|
||||
if (block == Blocks.air)
|
||||
continue;
|
||||
|
||||
GlStateManager.pushMatrix();
|
||||
|
||||
GlStateManager.enableDepth();
|
||||
mc.renderEngine.bindTexture(TextureMap.locationBlocksTexture);
|
||||
|
||||
if (block == null)
|
||||
return;
|
||||
|
||||
int color = block.colorMultiplier(world, pos, 0);
|
||||
float red = (color >> 16 & 255) / 255.0F;
|
||||
float green = (color >> 8 & 255) / 255.0F;
|
||||
float blue = (color & 255) / 255.0F;
|
||||
GlStateManager.color(red, green, blue);
|
||||
|
||||
GlStateManager.scale(scale, scale, scale);
|
||||
|
||||
GlStateManager.translate(x, world.getHeight() - y, z);
|
||||
BlockModelRenderer render = mc.getBlockRendererDispatcher().getBlockModelRenderer();
|
||||
|
||||
int i = block.getRenderColor(block.getStateForEntityRender(state));
|
||||
block.setBlockBoundsBasedOnState(world, pos);
|
||||
|
||||
GlStateManager.rotate(90F, 0, 1, 0);
|
||||
|
||||
if (EntityRenderer.anaglyphEnable) {
|
||||
i = TextureUtil.anaglyphColor(i);
|
||||
}
|
||||
|
||||
float r = (float) (i >> 16 & 255) / 255.0F;
|
||||
float g = (float) (i >> 8 & 255) / 255.0F;
|
||||
float b = (float) (i & 255) / 255.0F;
|
||||
|
||||
render.renderModelBrightnessColor(model, block.colorMultiplier(world, pos, 0), r, g, b);
|
||||
|
||||
GlStateManager.color(1F, 1F, 1F);
|
||||
GlStateManager.popMatrix();
|
||||
renderEngine.getTexture(TextureMap.locationBlocksTexture).restoreLastBlurMipmap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GlStateManager.disableLighting();
|
||||
GlStateManager.cullFace(GL11.GL_BACK);
|
||||
GL11.glDisable(GL11.GL_STENCIL_TEST);
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
|
||||
private void setupGuiTransform(int xPosition, int yPosition) {
|
||||
GlStateManager.translate((float) xPosition, (float) yPosition, 100.0F + this.zLevel);
|
||||
GlStateManager.translate(8.0F, 8.0F, 0.0F);
|
||||
GlStateManager.scale(1.0F, 1.0F, -1.0F);
|
||||
GlStateManager.scale(0.5F, 0.5F, 0.5F);
|
||||
|
||||
GlStateManager.scale(40.0F, 40.0F, 40.0F);
|
||||
GlStateManager.rotate(210.0F, 1.0F, 0.0F, 0.0F);
|
||||
GlStateManager.rotate(-135.0F, 0.0F, 1.0F, 0.0F);
|
||||
GlStateManager.enableLighting();
|
||||
}
|
||||
|
||||
private void renderQuads(WorldRenderer renderer, List<BakedQuad> quads, int color, BlockPos pos) {
|
||||
boolean flag = color == -1;
|
||||
int i = 0;
|
||||
|
||||
for (int j = quads.size(); i < j; ++i) {
|
||||
BakedQuad bakedquad = quads.get(i);
|
||||
int k = color;
|
||||
|
||||
if (flag && bakedquad.hasTintIndex()) {
|
||||
Block block = world.getBlockState(pos).getBlock();
|
||||
k = block.colorMultiplier(world, pos, 0);
|
||||
|
||||
if (EntityRenderer.anaglyphEnable) {
|
||||
k = TextureUtil.anaglyphColor(k);
|
||||
}
|
||||
|
||||
k = k | -16777216;
|
||||
}
|
||||
|
||||
net.minecraftforge.client.model.pipeline.LightUtil.renderQuadColor(renderer, bakedquad, k);
|
||||
}
|
||||
}
|
||||
|
||||
private class BlockAccess implements IBlockAccess {
|
||||
|
||||
private final int[][][] blocks;
|
||||
private final byte[][][] meta;
|
||||
private final int[] size;
|
||||
private HashMap<Integer[], TileEntity> tileEntityMap = new HashMap<>();
|
||||
|
||||
public BlockAccess(int[] size, BlockData[] structure) {
|
||||
this.size = size;
|
||||
|
||||
blocks = new int[size[0]][size[1]][size[2]];
|
||||
meta = new byte[size[0]][size[1]][size[2]];
|
||||
|
||||
for (BlockData block : structure) {
|
||||
Block tile = Block.getBlockFromName(block.block);
|
||||
if (tile == null)
|
||||
continue;
|
||||
byte metadata = block.meta >= 0 && block.meta < 16 ? block.meta : 0;
|
||||
|
||||
if (block.pos != null && block.pos.length == 3 && block.endPos != null && block.endPos.length == 3) {
|
||||
for (int x = block.pos[0]; x <= block.endPos[0]; x++) {
|
||||
for (int y = block.pos[1]; y <= block.endPos[1]; y++) {
|
||||
for (int z = block.pos[2]; z <= block.endPos[2]; z++) {
|
||||
if (x >= size[0] || y >= size[1] || z >= size[2])
|
||||
continue;
|
||||
|
||||
blocks[x][y][z] = Block.getIdFromBlock(tile);
|
||||
meta[x][y][z] = metadata;
|
||||
|
||||
TileEntity te = tile.hasTileEntity(tile.getStateFromMeta(metadata)) ? tile.createTileEntity(Minecraft.getMinecraft().theWorld, tile.getStateFromMeta(metadata)) : null;
|
||||
if (te != null) {
|
||||
te.setPos(new BlockPos(x, y, z));
|
||||
tileEntityMap.put(new Integer[]{x, y, z}, te);
|
||||
|
||||
if (block.nbt != null) {
|
||||
try {
|
||||
te.readFromNBT(JsonToNBT.getTagFromJson(ItemStackData.filterJsonQuotes(block.nbt.toString())));
|
||||
} catch (NBTException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity getTileEntity(BlockPos pos) {
|
||||
if (!isValid(pos))
|
||||
return null;
|
||||
return tileEntityMap.get(new Integer[]{pos.getX(), pos.getY(), pos.getZ()});
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCombinedLight(BlockPos pos, int lightValue) {
|
||||
return 15;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getBlockState(BlockPos pos) {
|
||||
if (!isValid(pos))
|
||||
return Blocks.air.getDefaultState();
|
||||
Block block = Block.getBlockById(blocks[pos.getX()][pos.getY()][pos.getZ()]);
|
||||
if (block == null)
|
||||
return Blocks.air.getDefaultState();
|
||||
|
||||
return block.getActualState(block.getStateFromMeta(meta[pos.getX()][pos.getY()][pos.getZ()]), this, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAirBlock(BlockPos pos) {
|
||||
return !isValid(pos) || Block.getBlockById(blocks[pos.getX()][pos.getY()][pos.getZ()]) == Blocks.air;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeGenBase getBiomeGenForCoords(BlockPos pos) {
|
||||
return BiomeGenBase.jungle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean extendedLevelsInChunkCache() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStrongPower(BlockPos pos, EnumFacing direction) {
|
||||
if (!isValid(pos))
|
||||
return 0;
|
||||
|
||||
IBlockState iblockstate = this.getBlockState(pos);
|
||||
return iblockstate.getBlock().getStrongPower(this, pos, iblockstate, direction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldType getWorldType() {
|
||||
return WorldType.DEFAULT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSideSolid(BlockPos pos, EnumFacing side, boolean _default) {
|
||||
if (!this.isValid(pos))
|
||||
return _default;
|
||||
|
||||
return getBlockState(pos).getBlock().isSideSolid(this, pos, side);
|
||||
}
|
||||
|
||||
public boolean isValid(BlockPos pos) {
|
||||
return pos != null && pos.getX() < size[0] && pos.getY() < size[1] && pos.getZ() < size[2] && pos.getX() >= 0 && pos.getY() >= 0 && pos.getZ() >= 0;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return size[0];
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return size[1];
|
||||
}
|
||||
|
||||
public int getDepth() {
|
||||
return size[2];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package slimeknights.mantle.client.gui.book.element;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import slimeknights.mantle.client.book.action.StringActionProcessor;
|
||||
import slimeknights.mantle.client.book.data.element.TextData;
|
||||
import slimeknights.mantle.client.gui.book.TextDataRenderer;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class ElementText extends SizedBookElement {
|
||||
|
||||
public TextData[] text;
|
||||
|
||||
private boolean doAction = false;
|
||||
|
||||
public ElementText(int x, int y, int width, int height, String text) {
|
||||
this(x, y, width, height, new TextData[]{new TextData(text)});
|
||||
}
|
||||
|
||||
public ElementText(int x, int y, int width, int height, TextData[] text) {
|
||||
super(x, y, width, height);
|
||||
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(int mouseX, int mouseY, float partialTicks) {
|
||||
String action = TextDataRenderer.drawText(x, y, width, height, text, mouseX, mouseY);
|
||||
|
||||
if (doAction) {
|
||||
doAction = false;
|
||||
StringActionProcessor.process(action, parent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
|
||||
if (mouseButton == 0)
|
||||
doAction = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package slimeknights.mantle.client.gui.book.element;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public abstract class SizedBookElement extends BookElement {
|
||||
|
||||
int width, height;
|
||||
|
||||
public SizedBookElement(int x, int y, int width, int height) {
|
||||
super(x, y);
|
||||
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
package slimeknights.mantle.common;
|
||||
|
||||
public class CommonProxy {
|
||||
public void preInit() {
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ public class NetworkWrapper {
|
||||
}
|
||||
|
||||
/**
|
||||
* Packet will be received on both cliend and server side.
|
||||
* Packet will be received on both client and server side.
|
||||
*/
|
||||
public void registerPacket(Class<? extends AbstractPacket> packetClazz) {
|
||||
registerPacketClient(packetClazz);
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package slimeknights.mantle.network.book;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.client.network.NetHandlerPlayClient;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.NetHandlerPlayServer;
|
||||
import net.minecraftforge.fml.common.network.ByteBufUtils;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import slimeknights.mantle.client.book.BookHelper;
|
||||
import slimeknights.mantle.network.AbstractPacket;
|
||||
|
||||
public class PacketUpdateSavedPage extends AbstractPacket {
|
||||
|
||||
private String pageName;
|
||||
|
||||
public PacketUpdateSavedPage() {
|
||||
|
||||
}
|
||||
|
||||
public PacketUpdateSavedPage(String pageName) {
|
||||
this.pageName = pageName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMessage handleClient(NetHandlerPlayClient netHandler) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMessage handleServer(NetHandlerPlayServer netHandler) {
|
||||
if (netHandler.playerEntity != null && pageName != null) {
|
||||
EntityPlayer player = netHandler.playerEntity;
|
||||
|
||||
ItemStack is = player.getHeldItem();
|
||||
|
||||
BookHelper.writeSavedPage(is, pageName);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
pageName = ByteBufUtils.readUTF8String(buf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
ByteBufUtils.writeUTF8String(buf, pageName);
|
||||
}
|
||||
}
|
||||
@@ -210,7 +210,7 @@ public class PulseManager {
|
||||
}
|
||||
|
||||
private void preInit(FMLPreInitializationEvent evt) {
|
||||
if (!blockNewRegistrations) conf.flush(); // First preInit call, so flush config
|
||||
if (!blockNewRegistrations) conf.flush(); // First init call, so flush config
|
||||
blockNewRegistrations = true;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user