mirror of
https://github.com/GTNewHorizons/Mantle.git
synced 2026-11-26 23:03:15 +00:00
Reformat book code
This commit is contained in:
1 parent
ebd2ad2675
commit
13e1a8f981
39 files changed
+560
-348
No files matched your search
@@ -1,17 +1,18 @@
|
||||
package slimeknights.mantle.client.book;
|
||||
|
||||
import java.util.Arrays;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class BookHelper {
|
||||
|
||||
public static String getSavedPage(ItemStack item) {
|
||||
if (item != null && item.hasTagCompound()) {
|
||||
if(item != null && item.hasTagCompound()) {
|
||||
NBTTagCompound mantleBook = item.getTagCompound().getCompoundTag("mantle").getCompoundTag("book");
|
||||
|
||||
if (mantleBook.hasKey("page", Arrays.asList(NBTBase.NBT_TYPES).indexOf("STRING"))) {
|
||||
if(mantleBook.hasKey("page", Arrays.asList(NBTBase.NBT_TYPES).indexOf("STRING"))) {
|
||||
return mantleBook.getString("page");
|
||||
}
|
||||
}
|
||||
@@ -22,8 +23,9 @@ public class BookHelper {
|
||||
public static void writeSavedPage(ItemStack item, String page) {
|
||||
NBTTagCompound compound = item.getTagCompound();
|
||||
|
||||
if (compound == null)
|
||||
if(compound == null) {
|
||||
compound = new NBTTagCompound();
|
||||
}
|
||||
|
||||
NBTTagCompound mantle = compound.getCompoundTag("mantle");
|
||||
NBTTagCompound book = mantle.getCompoundTag("book");
|
||||
|
||||
@@ -2,7 +2,7 @@ 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;
|
||||
@@ -13,6 +13,9 @@ import net.minecraft.util.EnumHand;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import slimeknights.mantle.Mantle;
|
||||
import slimeknights.mantle.client.book.action.StringActionProcessor;
|
||||
import slimeknights.mantle.client.book.action.protocol.ProtocolGoToPage;
|
||||
@@ -42,7 +45,8 @@ import slimeknights.mantle.network.book.PacketUpdateSavedPage;
|
||||
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();
|
||||
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<>();
|
||||
@@ -84,8 +88,9 @@ public class BookLoader implements IResourceManagerReloadListener {
|
||||
* @RecommendedInvoke init
|
||||
*/
|
||||
public static void registerPageType(String name, Class<? extends PageContent> clazz) {
|
||||
if (typeToContentMap.containsKey(name))
|
||||
if(typeToContentMap.containsKey(name)) {
|
||||
throw new IllegalArgumentException("Page type " + name + " already in use.");
|
||||
}
|
||||
|
||||
typeToContentMap.put(name, clazz);
|
||||
}
|
||||
@@ -127,10 +132,12 @@ public class BookLoader implements IResourceManagerReloadListener {
|
||||
|
||||
books.put(name.contains(":") ? name : Loader.instance().activeModContainer().getModId() + ":" + name, info);
|
||||
|
||||
if (appendIndex)
|
||||
if(appendIndex) {
|
||||
info.addTransformer(new BookTransformer.IndexTranformer());
|
||||
if (appendContentTable)
|
||||
}
|
||||
if(appendContentTable) {
|
||||
info.addTransformer(new BookTransformer.ContentTableTransformer());
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
@@ -146,8 +153,9 @@ public class BookLoader implements IResourceManagerReloadListener {
|
||||
}
|
||||
|
||||
public static void updateSavedPage(EntityPlayer player, ItemStack item, String page) {
|
||||
if (player.getHeldItem(EnumHand.MAIN_HAND) == null)
|
||||
if(player.getHeldItem(EnumHand.MAIN_HAND) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
BookHelper.writeSavedPage(item, page);
|
||||
wrapper.network.sendToServer(new PacketUpdateSavedPage(page));
|
||||
@@ -161,10 +169,10 @@ public class BookLoader implements IResourceManagerReloadListener {
|
||||
Mantle.logger.info("Started loading books...");
|
||||
long time = System.nanoTime();
|
||||
|
||||
for (BookData book : books.values()) {
|
||||
for(BookData book : books.values()) {
|
||||
try {
|
||||
book.load();
|
||||
} catch (Exception e) {
|
||||
} catch(Exception e) {
|
||||
book.sections.clear();
|
||||
SectionData section = new SectionData(true);
|
||||
section.name = "errorenous";
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package slimeknights.mantle.client.book;
|
||||
|
||||
import net.minecraft.stats.StatFileWriter;
|
||||
|
||||
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;
|
||||
@@ -31,14 +33,15 @@ public abstract class BookTransformer {
|
||||
|
||||
List<SectionData> visibleSections = parent.getVisibleSections(writer);
|
||||
|
||||
if (visibleSections.isEmpty())
|
||||
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++) {
|
||||
for(int i = 0; i < pages.length; i++) {
|
||||
pages[i] = new PageData(true);
|
||||
|
||||
pages[i].name = "page" + (i + 1);
|
||||
@@ -46,7 +49,7 @@ public abstract class BookTransformer {
|
||||
ContentSectionList content = new ContentSectionList();
|
||||
pages[i].content = content;
|
||||
|
||||
for (int j = i * 9; j - i * 9 < 9 && j < visibleSections.size(); j++) {
|
||||
for(int j = i * 9; j - i * 9 < 9 && j < visibleSections.size(); j++) {
|
||||
content.addSection(visibleSections.get(j));
|
||||
}
|
||||
}
|
||||
@@ -66,30 +69,34 @@ public abstract class BookTransformer {
|
||||
public void transform(BookData book) {
|
||||
final int ENTRIES_PER_PAGE = 24;
|
||||
|
||||
for (SectionData section : book.sections) {
|
||||
if (section.name.equals("index"))
|
||||
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)
|
||||
if(genPages == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
PageData[] pages = new PageData[genPages];
|
||||
|
||||
for (int i = 0; i < pages.length; i++) {
|
||||
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());
|
||||
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--) {
|
||||
for(int i = pages.length - 1; i >= 0; i--) {
|
||||
section.pages.add(0, pages[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
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;
|
||||
|
||||
@@ -11,23 +12,27 @@ public class StringActionProcessor {
|
||||
private static final HashMap<String, ActionProtocol> protocols = new HashMap<>();
|
||||
|
||||
public static void registerProtocol(ActionProtocol protocol) {
|
||||
if (protocol == null || protocol.protocol == null || protocol.protocol.isEmpty())
|
||||
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))
|
||||
}
|
||||
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))
|
||||
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))
|
||||
if(protocols.containsKey(protoId)) {
|
||||
protocols.get(protoId).processCommand(book, protoParam);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,8 @@ public class ProtocolGoToPage extends ActionProtocol {
|
||||
public void processCommand(GuiBook book, String param) {
|
||||
int pageNum = book.book.findPageNumber(param);
|
||||
|
||||
if (pageNum >= 0)
|
||||
if(pageNum >= 0) {
|
||||
book.openPage(pageNum, returner);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
package slimeknights.mantle.client.book.data.content;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import slimeknights.mantle.client.book.data.BookData;
|
||||
import slimeknights.mantle.client.gui.book.element.BookElement;
|
||||
|
||||
|
||||
+8
-5
@@ -1,6 +1,7 @@
|
||||
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;
|
||||
@@ -10,6 +11,7 @@ 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 {
|
||||
@@ -35,22 +37,23 @@ public class ContentBlockInteraction extends PageContent {
|
||||
int x = GuiBook.PAGE_WIDTH / 2 - IMG_SMITHING.width / 2 - 10;
|
||||
int y = TITLE_HEIGHT;
|
||||
|
||||
if (title == null || title.isEmpty())
|
||||
if(title == null || title.isEmpty()) {
|
||||
y = 0;
|
||||
else
|
||||
} 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("")) {
|
||||
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("")) {
|
||||
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) {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
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;
|
||||
@@ -10,6 +11,7 @@ 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 {
|
||||
@@ -45,13 +47,13 @@ public class ContentCrafting extends PageContent {
|
||||
tdTitle.underlined = true;
|
||||
list.add(new ElementText(0, 0, GuiBook.PAGE_WIDTH, 9, new TextData[]{tdTitle}));
|
||||
|
||||
if (grid_size.equalsIgnoreCase("small")) {
|
||||
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")) {
|
||||
} 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));
|
||||
@@ -59,20 +61,25 @@ public class ContentCrafting extends PageContent {
|
||||
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(""))
|
||||
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));
|
||||
}
|
||||
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) {
|
||||
if(result != null) {
|
||||
list.add(new ElementItem(resultX, resultY, ITEM_SCALE, result.getItems(), result.action));
|
||||
}
|
||||
|
||||
if (description != null && description.length > 0) {
|
||||
if(description != null && description.length > 0) {
|
||||
list.add(new ElementText(0, height + 5, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT - height - 5, description));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package slimeknights.mantle.client.book.data.content;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import slimeknights.mantle.client.book.data.BookData;
|
||||
import slimeknights.mantle.client.gui.book.element.BookElement;
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package slimeknights.mantle.client.book.data.content;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import slimeknights.mantle.client.book.data.BookData;
|
||||
import slimeknights.mantle.client.book.data.element.TextData;
|
||||
import slimeknights.mantle.client.gui.book.GuiBook;
|
||||
@@ -33,12 +35,13 @@ public class ContentError extends PageContent {
|
||||
text[0].color = "dark_red";
|
||||
text[0].underlined = true;
|
||||
|
||||
if (exception != null) {
|
||||
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] = new TextData(exception.getMessage() != null ? exception.getMessage() : exception.getClass()
|
||||
.getSimpleName());
|
||||
text[2].color = "dark_red";
|
||||
text[2].paragraph = true;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package slimeknights.mantle.client.book.data.content;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import slimeknights.mantle.client.book.data.BookData;
|
||||
import slimeknights.mantle.client.book.data.element.ImageData;
|
||||
import slimeknights.mantle.client.gui.book.GuiBook;
|
||||
@@ -19,14 +21,16 @@ public class ContentImage extends PageContent {
|
||||
public void build(BookData book, ArrayList<BookElement> list) {
|
||||
int y = TITLE_HEIGHT;
|
||||
|
||||
if (title == null || title.isEmpty())
|
||||
if(title == null || title.isEmpty()) {
|
||||
y = 0;
|
||||
else
|
||||
} else {
|
||||
addTitle(list, title);
|
||||
}
|
||||
|
||||
if (image != null && image.location != null)
|
||||
if(image != null && image.location != null) {
|
||||
list.add(new ElementImage(0, y, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT - y, image));
|
||||
else
|
||||
} else {
|
||||
list.add(new ElementImage(ImageData.MISSING));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
package slimeknights.mantle.client.book.data.content;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
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.TextData;
|
||||
@@ -22,17 +24,20 @@ public class ContentImageText extends PageContent {
|
||||
public void build(BookData book, ArrayList<BookElement> list) {
|
||||
int y = TITLE_HEIGHT;
|
||||
|
||||
if (title == null || title.isEmpty())
|
||||
if(title == null || title.isEmpty()) {
|
||||
y = 0;
|
||||
else
|
||||
} else {
|
||||
addTitle(list, title);
|
||||
}
|
||||
|
||||
if (image != null && image.location != null)
|
||||
if(image != null && image.location != null) {
|
||||
list.add(new ElementImage(0, y, GuiBook.PAGE_WIDTH, 100, image));
|
||||
else
|
||||
} else {
|
||||
list.add(new ElementImage(0, y, 32, 32, ImageData.MISSING));
|
||||
}
|
||||
|
||||
if (text != null && text.length > 0)
|
||||
if(text != null && text.length > 0) {
|
||||
list.add(new ElementText(0, y + 105, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT - 105 - y, text));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
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;
|
||||
@@ -19,7 +20,7 @@ public class ContentSectionList extends PageContent {
|
||||
int width = (ElementSection.WIDTH + 5) * 3 - 5;
|
||||
int height = (ElementSection.HEIGHT + 5) * 3 - 5;
|
||||
|
||||
for (int i = 0; i < sections.size(); i++) {
|
||||
for(int i = 0; i < sections.size(); i++) {
|
||||
int ix = i % 3;
|
||||
int iy = (int) Math.floor(i / 3F);
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
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 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;
|
||||
@@ -13,6 +15,7 @@ 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 {
|
||||
@@ -44,17 +47,17 @@ public class ContentSmelting extends PageContent {
|
||||
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("")) {
|
||||
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("")) {
|
||||
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) {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
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;
|
||||
@@ -10,6 +11,7 @@ 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 {
|
||||
@@ -37,26 +39,27 @@ public class ContentSmithing extends PageContent {
|
||||
int x = GuiBook.PAGE_WIDTH / 2 - IMG_SMITHING.width / 2;
|
||||
int y = TITLE_HEIGHT;
|
||||
|
||||
if (title == null || title.isEmpty())
|
||||
if(title == null || title.isEmpty()) {
|
||||
y = 0;
|
||||
else
|
||||
} 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("")) {
|
||||
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("")) {
|
||||
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("")) {
|
||||
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) {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package slimeknights.mantle.client.book.data.content;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import slimeknights.mantle.client.book.BookLoader;
|
||||
import slimeknights.mantle.client.book.data.BookData;
|
||||
import slimeknights.mantle.client.book.data.element.BlockData;
|
||||
@@ -23,13 +25,15 @@ public class ContentStructure extends PageContent {
|
||||
public void load() {
|
||||
BookRepository repo = parent.source;
|
||||
|
||||
if (data == null || data.isEmpty())
|
||||
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);
|
||||
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;
|
||||
@@ -40,13 +44,15 @@ public class ContentStructure extends PageContent {
|
||||
@Override
|
||||
public void build(BookData book, ArrayList<BookElement> list) {
|
||||
int y = TITLE_HEIGHT;
|
||||
if (title == null || title.isEmpty())
|
||||
if(title == null || title.isEmpty()) {
|
||||
y = 0;
|
||||
else
|
||||
} else {
|
||||
addTitle(list, title);
|
||||
}
|
||||
|
||||
if (size != null && size.length == 3 && structure != null && structure.length > 0)
|
||||
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"));
|
||||
}
|
||||
|
||||
+8
-4
@@ -1,7 +1,9 @@
|
||||
package slimeknights.mantle.client.book.data.content;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import slimeknights.mantle.client.book.data.BookData;
|
||||
import slimeknights.mantle.client.book.data.element.TextData;
|
||||
import slimeknights.mantle.client.gui.book.GuiBook;
|
||||
@@ -22,14 +24,16 @@ public class ContentTableOfContents extends PageContent {
|
||||
public void build(BookData book, ArrayList<BookElement> list) {
|
||||
int y = 0;
|
||||
|
||||
if (title != null && !title.trim().isEmpty()) {
|
||||
if(title != null && !title.trim().isEmpty()) {
|
||||
addTitle(list, title);
|
||||
y += TITLE_HEIGHT;
|
||||
}
|
||||
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
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}));
|
||||
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}));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
package slimeknights.mantle.client.book.data.content;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import slimeknights.mantle.client.book.data.BookData;
|
||||
import slimeknights.mantle.client.book.data.element.TextData;
|
||||
import slimeknights.mantle.client.gui.book.GuiBook;
|
||||
@@ -19,12 +21,14 @@ public class ContentText extends PageContent {
|
||||
public void build(BookData book, ArrayList<BookElement> list) {
|
||||
int y = TITLE_HEIGHT;
|
||||
|
||||
if (title == null || title.isEmpty())
|
||||
if(title == null || title.isEmpty()) {
|
||||
y = 0;
|
||||
else
|
||||
} else {
|
||||
addTitle(list, title);
|
||||
}
|
||||
|
||||
if (text != null && text.length > 0)
|
||||
if(text != null && text.length > 0) {
|
||||
list.add(new ElementText(0, y, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT - y, text));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
package slimeknights.mantle.client.book.data.content;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
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.TextData;
|
||||
@@ -22,22 +24,26 @@ public class ContentTextImage extends PageContent {
|
||||
public void build(BookData book, ArrayList<BookElement> list) {
|
||||
int y = TITLE_HEIGHT;
|
||||
|
||||
if (title == null || title.isEmpty())
|
||||
if(title == null || title.isEmpty()) {
|
||||
y = 0;
|
||||
else
|
||||
} else {
|
||||
addTitle(list, title);
|
||||
}
|
||||
|
||||
if (title == null || title.isEmpty())
|
||||
if(title == null || title.isEmpty()) {
|
||||
y = 0;
|
||||
else
|
||||
} else {
|
||||
addTitle(list, title);
|
||||
}
|
||||
|
||||
if (text != null && text.length > 0)
|
||||
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)
|
||||
if(image != null && image.location != null) {
|
||||
list.add(new ElementImage(0, y + GuiBook.PAGE_HEIGHT - 100, GuiBook.PAGE_WIDTH, 100 - y, image));
|
||||
else
|
||||
} else {
|
||||
list.add(new ElementImage(0, y + GuiBook.PAGE_HEIGHT - 100, GuiBook.PAGE_WIDTH, 100 - y, ImageData.MISSING));
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
-7
@@ -1,8 +1,10 @@
|
||||
package slimeknights.mantle.client.book.data.content;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
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.TextData;
|
||||
@@ -23,20 +25,24 @@ public class ContentTextLeftImage extends PageContent {
|
||||
public void build(BookData book, ArrayList<BookElement> list) {
|
||||
int y = TITLE_HEIGHT;
|
||||
|
||||
if (title == null || title.isEmpty())
|
||||
if(title == null || title.isEmpty()) {
|
||||
y = 0;
|
||||
else
|
||||
} else {
|
||||
addTitle(list, title);
|
||||
}
|
||||
|
||||
if (image != null && image.location != null)
|
||||
if(image != null && image.location != null) {
|
||||
list.add(new ElementImage(0, y, 50, 50, image));
|
||||
else
|
||||
} else {
|
||||
list.add(new ElementImage(0, y, 50, 50, ImageData.MISSING));
|
||||
}
|
||||
|
||||
if (text1 != null && text1.length > 0)
|
||||
if(text1 != null && text1.length > 0) {
|
||||
list.add(new ElementText(55, y, GuiBook.PAGE_WIDTH - 55, 50, text1));
|
||||
}
|
||||
|
||||
if (text2 != null && text2.length > 0)
|
||||
if(text2 != null && text2.length > 0) {
|
||||
list.add(new ElementText(0, y + 55, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT - 55 - y, text2));
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
-7
@@ -1,8 +1,10 @@
|
||||
package slimeknights.mantle.client.book.data.content;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
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.TextData;
|
||||
@@ -23,20 +25,24 @@ public class ContentTextRightImage extends PageContent {
|
||||
public void build(BookData book, ArrayList<BookElement> list) {
|
||||
int y = TITLE_HEIGHT;
|
||||
|
||||
if (title == null || title.isEmpty())
|
||||
if(title == null || title.isEmpty()) {
|
||||
y = 0;
|
||||
else
|
||||
} else {
|
||||
addTitle(list, title);
|
||||
}
|
||||
|
||||
if (text1 != null && text1.length > 0)
|
||||
if(text1 != null && text1.length > 0) {
|
||||
list.add(new ElementText(0, y, GuiBook.PAGE_WIDTH - 55, 50, text1));
|
||||
}
|
||||
|
||||
if (image != null && image.location != null)
|
||||
if(image != null && image.location != null) {
|
||||
list.add(new ElementImage(GuiBook.PAGE_WIDTH - 50, y, 50, 50, image));
|
||||
else
|
||||
} else {
|
||||
list.add(new ElementImage(GuiBook.PAGE_WIDTH - 50, y, 50, 50, ImageData.MISSING));
|
||||
}
|
||||
|
||||
if (text2 != null && text2.length > 0)
|
||||
if(text2 != null && text2.length > 0) {
|
||||
list.add(new ElementText(0, y + 55, GuiBook.PAGE_WIDTH, GuiBook.PAGE_HEIGHT - 55 - y, text2));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
package slimeknights.mantle.client.book.data.content;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import slimeknights.mantle.client.book.data.BookData;
|
||||
import slimeknights.mantle.client.book.data.PageData;
|
||||
import slimeknights.mantle.client.book.data.element.TextData;
|
||||
|
||||
+9
-6
@@ -4,23 +4,26 @@ 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())
|
||||
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()) {
|
||||
} else if(json.isJsonPrimitive() && json.getAsJsonPrimitive().isString()) {
|
||||
try {
|
||||
String s = json.getAsString();
|
||||
|
||||
if (s.toLowerCase().startsWith("0b"))
|
||||
if(s.toLowerCase().startsWith("0b")) {
|
||||
return Integer.parseInt(s.substring(2), 2);
|
||||
else if (s.toLowerCase().startsWith("0x"))
|
||||
} else if(s.toLowerCase().startsWith("0x")) {
|
||||
return Integer.parseInt(s.substring(2), 16);
|
||||
} catch (NumberFormatException ignored) {
|
||||
}
|
||||
} catch(NumberFormatException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
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;
|
||||
@@ -12,6 +13,7 @@ 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;
|
||||
|
||||
@@ -28,19 +30,20 @@ public class ItemStackData {
|
||||
public JsonObject nbt;
|
||||
|
||||
public ItemStack[] getItems() {
|
||||
if (itemListLocation != null && source.resourceExists(itemListLocation)) {
|
||||
if(itemListLocation != null && source.resourceExists(itemListLocation)) {
|
||||
try {
|
||||
ItemsList itemsList = BookLoader.GSON.fromJson(source.resourceToString(source.getResource(itemListLocation)), ItemsList.class);
|
||||
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++) {
|
||||
for(int i = 0; i < itemsList.items.length; i++) {
|
||||
items[i] = itemsList.items[i].getItem();
|
||||
}
|
||||
|
||||
this.action = itemsList.action;
|
||||
|
||||
return items;
|
||||
} catch (Exception ignored) {
|
||||
} catch(Exception ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,26 +55,26 @@ public class ItemStackData {
|
||||
boolean isMissingItem = false;
|
||||
try {
|
||||
item = CommandGive.getItemByText(null, id);
|
||||
} catch (NumberInvalidException e) {
|
||||
} catch(NumberInvalidException e) {
|
||||
item = Item.getItemFromBlock(Blocks.barrier);
|
||||
isMissingItem = true;
|
||||
}
|
||||
|
||||
if (item == null) {
|
||||
if(item == null) {
|
||||
item = Item.getItemFromBlock(Blocks.barrier);
|
||||
isMissingItem = true;
|
||||
}
|
||||
|
||||
ItemStack itemStack = new ItemStack(item, amount, damage);
|
||||
|
||||
if (nbt != null) {
|
||||
if(nbt != null) {
|
||||
try {
|
||||
itemStack.setTagCompound(JsonToNBT.getTagFromJson(filterJsonQuotes(nbt.toString())));
|
||||
} catch (NBTException ignored) {
|
||||
} catch(NBTException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
if (isMissingItem) {
|
||||
if(isMissingItem) {
|
||||
NBTTagCompound display = itemStack.getSubCompound("display", true);
|
||||
display.setString("Name", "\u00A7rUnknown Item");
|
||||
NBTTagList lore = new NBTTagList();
|
||||
@@ -92,7 +95,7 @@ public class ItemStackData {
|
||||
data.id = Item.itemRegistry.getNameForObject(stack.getItem()).toString();
|
||||
data.amount = (byte) stack.stackSize;
|
||||
data.damage = (short) stack.getItemDamage();
|
||||
if (!ignoreNbt && stack.getTagCompound() != null) {
|
||||
if(!ignoreNbt && stack.getTagCompound() != null) {
|
||||
data.nbt = BookLoader.GSON.toJsonTree(stack.getTagCompound(), NBTTagCompound.class).getAsJsonObject();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package slimeknights.mantle.client.book.repository;
|
||||
|
||||
import java.util.List;
|
||||
import net.minecraft.client.resources.IResource;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import slimeknights.mantle.client.book.data.SectionData;
|
||||
|
||||
public abstract class BookRepository {
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package slimeknights.mantle.client.book.repository;
|
||||
|
||||
import java.util.List;
|
||||
import net.minecraft.client.resources.IResource;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import slimeknights.mantle.client.book.data.SectionData;
|
||||
|
||||
public class DummyRepository extends BookRepository {
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
package slimeknights.mantle.client.book.repository;
|
||||
|
||||
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 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;
|
||||
|
||||
@@ -23,92 +26,103 @@ public class FileRepository extends BookRepository {
|
||||
|
||||
@Override
|
||||
public List<SectionData> getSections() {
|
||||
return new ArrayList<>(Arrays.asList(BookLoader.GSON.fromJson(resourceToString(getResource(getResourceLocation("index.json"))), SectionData[].class)));
|
||||
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)
|
||||
if(path == null) {
|
||||
return safe ? new ResourceLocation("") : null;
|
||||
if (!path.contains(":")) {
|
||||
}
|
||||
if(!path.contains(":")) {
|
||||
String langPath = Minecraft.getMinecraft().getLanguageManager().getCurrentLanguage().getLanguageCode();
|
||||
String defaultLangPath = "en_US";
|
||||
|
||||
ResourceLocation res = new ResourceLocation(location + "/" + langPath + "/" + path);
|
||||
if (resourceExists(res))
|
||||
if(resourceExists(res)) {
|
||||
return res;
|
||||
}
|
||||
res = new ResourceLocation(location + "/" + defaultLangPath + "/" + path);
|
||||
if (resourceExists(res))
|
||||
if(resourceExists(res)) {
|
||||
return res;
|
||||
}
|
||||
res = new ResourceLocation(location + "/" + path);
|
||||
if (resourceExists(res))
|
||||
if(resourceExists(res)) {
|
||||
return res;
|
||||
}
|
||||
return safe ? new ResourceLocation("") : null;
|
||||
} else {
|
||||
ResourceLocation res = new ResourceLocation(path);
|
||||
if (resourceExists(res))
|
||||
if(resourceExists(res)) {
|
||||
return res;
|
||||
}
|
||||
return safe ? new ResourceLocation("") : null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IResource getResource(ResourceLocation loc) {
|
||||
if (loc == null)
|
||||
if(loc == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return Minecraft.getMinecraft().getResourceManager().getResource(loc);
|
||||
} catch (IOException e) {
|
||||
} catch(IOException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean resourceExists(ResourceLocation location) {
|
||||
if (location == null)
|
||||
if(location == null) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
Minecraft.getMinecraft().getResourceManager().getResource(location);
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
} catch(IOException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String resourceToString(IResource resource, boolean skipCommments) {
|
||||
if (resource == null)
|
||||
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()) {
|
||||
while(iterator.hasNext()) {
|
||||
String s = ((String) iterator.next()).trim() + "\n";
|
||||
|
||||
// Comment skipper
|
||||
if (skipCommments) {
|
||||
if (isLongComment) {
|
||||
if (s.endsWith("*/"))
|
||||
if(skipCommments) {
|
||||
if(isLongComment) {
|
||||
if(s.endsWith("*/")) {
|
||||
isLongComment = false;
|
||||
}
|
||||
continue;
|
||||
} else {
|
||||
if (s.startsWith("/*")) {
|
||||
if(s.startsWith("/*")) {
|
||||
isLongComment = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (s.startsWith("//"))
|
||||
if(s.startsWith("//")) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
builder.append(s);
|
||||
}
|
||||
|
||||
return builder.toString().trim();
|
||||
} catch (IOException e) {
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
@@ -19,17 +19,19 @@ public class BoxRenderer {
|
||||
|
||||
int sx = x, sy = y;
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
for(int i = 0; i < 3; i++) {
|
||||
int sgW = width - segW * 2;
|
||||
|
||||
if (i % 2 == 0)
|
||||
if(i % 2 == 0) {
|
||||
sgW = segW;
|
||||
}
|
||||
|
||||
for (int j = 0; j < 3; j++) {
|
||||
for(int j = 0; j < 3; j++) {
|
||||
int sgH = height - segH * 2;
|
||||
|
||||
if (j % 2 == 0)
|
||||
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);
|
||||
|
||||
@@ -6,6 +6,7 @@ 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)
|
||||
@@ -31,7 +32,7 @@ public class GuiArrow extends GuiButton {
|
||||
|
||||
@Override
|
||||
public void drawButton(Minecraft mc, int mouseX, int mouseY) {
|
||||
if (this.visible) {
|
||||
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;
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
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;
|
||||
@@ -16,8 +13,15 @@ import net.minecraft.network.play.client.CPacketClientStatus;
|
||||
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 java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import slimeknights.mantle.client.book.BookHelper;
|
||||
import slimeknights.mantle.client.book.BookLoader;
|
||||
import slimeknights.mantle.client.book.action.StringActionProcessor;
|
||||
@@ -25,6 +29,7 @@ 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;
|
||||
|
||||
@@ -67,10 +72,13 @@ public class GuiBook extends GuiScreen implements IProgressMeter {
|
||||
}
|
||||
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -79,16 +87,18 @@ public class GuiBook extends GuiScreen implements IProgressMeter {
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
FontRenderer font = mc.fontRendererObj;
|
||||
|
||||
if (loadingAchievements) {
|
||||
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);
|
||||
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) {
|
||||
if(debug) {
|
||||
drawRect(0, 0, font.getStringWidth("DEBUG") + 4, font.FONT_HEIGHT + 4, 0x55000000);
|
||||
font.drawString("DEBUG", 2, 2, 0xFFFFFFFF);
|
||||
}
|
||||
@@ -97,7 +107,7 @@ public class GuiBook extends GuiScreen implements IProgressMeter {
|
||||
GlStateManager.enableBlend();
|
||||
|
||||
// The books are unreadable at Gui Scale set to small, so we'll double the scale
|
||||
if (mc.gameSettings.guiScale == 1) {
|
||||
if(mc.gameSettings.guiScale == 1) {
|
||||
GlStateManager.scale(2F, 2F, 2F);
|
||||
|
||||
mouseX /= 2;
|
||||
@@ -113,14 +123,14 @@ public class GuiBook extends GuiScreen implements IProgressMeter {
|
||||
|
||||
TextureManager render = this.mc.renderEngine;
|
||||
|
||||
if (page == -1) {
|
||||
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()) {
|
||||
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();
|
||||
@@ -132,7 +142,7 @@ public class GuiBook extends GuiScreen implements IProgressMeter {
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
|
||||
if (!book.appearance.subtitle.isEmpty()) {
|
||||
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);
|
||||
@@ -146,7 +156,7 @@ public class GuiBook extends GuiScreen implements IProgressMeter {
|
||||
|
||||
GlStateManager.color(1F, 1F, 1F);
|
||||
|
||||
if (page != 0) {
|
||||
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();
|
||||
@@ -154,16 +164,18 @@ public class GuiBook extends GuiScreen implements IProgressMeter {
|
||||
|
||||
GlStateManager.scale(PAGE_SCALE, PAGE_SCALE, 1F);
|
||||
|
||||
if (book.appearance.drawPageNumbers) {
|
||||
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);
|
||||
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++) {
|
||||
for(int i = 0; i < leftElements.size(); i++) {
|
||||
BookElement element = leftElements.get(i);
|
||||
|
||||
GlStateManager.color(1F, 1F, 1F, 1F);
|
||||
@@ -171,7 +183,7 @@ public class GuiBook extends GuiScreen implements IProgressMeter {
|
||||
}
|
||||
|
||||
// Not foreach to prevent conmodification crashes
|
||||
for (int i = 0; i < leftElements.size(); i++) {
|
||||
for(int i = 0; i < leftElements.size(); i++) {
|
||||
BookElement element = leftElements.get(i);
|
||||
|
||||
GlStateManager.color(1F, 1F, 1F, 1F);
|
||||
@@ -186,7 +198,8 @@ public class GuiBook extends GuiScreen implements IProgressMeter {
|
||||
// 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)) {
|
||||
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();
|
||||
@@ -194,16 +207,18 @@ public class GuiBook extends GuiScreen implements IProgressMeter {
|
||||
|
||||
GlStateManager.scale(PAGE_SCALE, PAGE_SCALE, 1F);
|
||||
|
||||
if (book.appearance.drawPageNumbers) {
|
||||
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);
|
||||
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++) {
|
||||
for(int i = 0; i < rightElements.size(); i++) {
|
||||
BookElement element = rightElements.get(i);
|
||||
|
||||
GlStateManager.color(1F, 1F, 1F, 1F);
|
||||
@@ -211,7 +226,7 @@ public class GuiBook extends GuiScreen implements IProgressMeter {
|
||||
}
|
||||
|
||||
// Not foreach to prevent conmodification crashes
|
||||
for (int i = 0; i < rightElements.size(); i++) {
|
||||
for(int i = 0; i < rightElements.size(); i++) {
|
||||
BookElement element = rightElements.get(i);
|
||||
|
||||
GlStateManager.color(1F, 1F, 1F, 1F);
|
||||
@@ -232,23 +247,27 @@ public class GuiBook extends GuiScreen implements IProgressMeter {
|
||||
}
|
||||
|
||||
public int openPage(int page, boolean returner) {
|
||||
if (loadingAchievements)
|
||||
if(loadingAchievements) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (page < 0)
|
||||
if(page < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int bookPage;
|
||||
if (page == 1)
|
||||
if(page == 1) {
|
||||
bookPage = 0;
|
||||
else if (page % 2 == 0)
|
||||
} else if(page % 2 == 0) {
|
||||
bookPage = (page - 1) / 2 + 1;
|
||||
else
|
||||
} else {
|
||||
bookPage = (page - 2) / 2 + 1;
|
||||
}
|
||||
|
||||
if (bookPage >= -1 && bookPage < book.getFullPageCount(statFile)) {
|
||||
if (returner)
|
||||
if(bookPage >= -1 && bookPage < book.getFullPageCount(statFile)) {
|
||||
if(returner) {
|
||||
oldPage = this.page;
|
||||
}
|
||||
|
||||
_setPage(bookPage);
|
||||
}
|
||||
@@ -262,16 +281,17 @@ public class GuiBook extends GuiScreen implements IProgressMeter {
|
||||
}
|
||||
|
||||
public int getPage(int side) {
|
||||
if (page == 0 && side == 0)
|
||||
if(page == 0 && side == 0) {
|
||||
return -1;
|
||||
else if (page == 0 && side == 1)
|
||||
} else if(page == 0 && side == 1) {
|
||||
return 0;
|
||||
else if (side == 0)
|
||||
} else if(side == 0) {
|
||||
return (page - 1) * 2 + 1;
|
||||
else if (side == 1)
|
||||
} else if(side == 1) {
|
||||
return (page - 2) * 2 + 2;
|
||||
else
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public int getPage_() {
|
||||
@@ -283,8 +303,9 @@ public class GuiBook extends GuiScreen implements IProgressMeter {
|
||||
}
|
||||
|
||||
public void openCover() {
|
||||
if (loadingAchievements)
|
||||
if(loadingAchievements) {
|
||||
return;
|
||||
}
|
||||
|
||||
_setPage(-1);
|
||||
|
||||
@@ -298,47 +319,54 @@ public class GuiBook extends GuiScreen implements IProgressMeter {
|
||||
}
|
||||
|
||||
private void buildPages() {
|
||||
if (loadingAchievements)
|
||||
if(loadingAchievements) {
|
||||
return;
|
||||
}
|
||||
|
||||
leftElements.clear();
|
||||
rightElements.clear();
|
||||
|
||||
if (page == -1)
|
||||
if(page == -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (page == 0) {
|
||||
if(page == 0) {
|
||||
PageData page = book.findPage(0, statFile);
|
||||
|
||||
if (page != null)
|
||||
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)
|
||||
if(leftPage != null) {
|
||||
leftPage.content.build(book, leftElements);
|
||||
if (rightPage != null)
|
||||
}
|
||||
if(rightPage != null) {
|
||||
rightPage.content.build(book, rightElements);
|
||||
}
|
||||
}
|
||||
|
||||
for (BookElement element : leftElements)
|
||||
for(BookElement element : leftElements) {
|
||||
element.parent = this;
|
||||
for (BookElement element : rightElements)
|
||||
}
|
||||
for(BookElement element : rightElements) {
|
||||
element.parent = this;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
if (loadingAchievements) {
|
||||
if(loadingAchievements) {
|
||||
this.mc.getNetHandler().addToSendQueue(new CPacketClientStatus(CPacketClientStatus.State.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) {
|
||||
if(mc.gameSettings.guiScale == 1) {
|
||||
width /= 2F;
|
||||
height /= 2F;
|
||||
}
|
||||
@@ -360,21 +388,23 @@ public class GuiBook extends GuiScreen implements IProgressMeter {
|
||||
public void updateScreen() {
|
||||
super.updateScreen();
|
||||
|
||||
if (loadingAchievements)
|
||||
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) {
|
||||
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();
|
||||
indexArrow.visible = book.findSection("index") != null && (page - 1) * 2 + 2 > book.findSection("index")
|
||||
.getPageCount();
|
||||
}
|
||||
|
||||
previousArrow.yPosition = height / 2 + 75;
|
||||
@@ -391,27 +421,31 @@ public class GuiBook extends GuiScreen implements IProgressMeter {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(GuiButton button) {
|
||||
if (loadingAchievements)
|
||||
if(loadingAchievements) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (button instanceof GuiBookmark) {
|
||||
if(button instanceof GuiBookmark) {
|
||||
openPage(book.findPageNumber(((GuiBookmark) button).data.page, statFile));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (button == previousArrow) {
|
||||
if(button == previousArrow) {
|
||||
page--;
|
||||
if (page < -1)
|
||||
if(page < -1) {
|
||||
page = -1;
|
||||
} else if (button == nextArrow) {
|
||||
}
|
||||
} else if(button == nextArrow) {
|
||||
page++;
|
||||
if (page > book.getFullPageCount(statFile) - (book.getPageCount(statFile) % 2 != 0 ? 0 : 1))
|
||||
if(page > book.getFullPageCount(statFile) - (book.getPageCount(statFile) % 2 != 0 ? 0 : 1)) {
|
||||
page = book.getFullPageCount(statFile) - 1;
|
||||
} else if (button == backArrow) {
|
||||
if (oldPage >= -1)
|
||||
}
|
||||
} else if(button == backArrow) {
|
||||
if(oldPage >= -1) {
|
||||
page = oldPage;
|
||||
} else if (button == indexArrow) {
|
||||
}
|
||||
} else if(button == indexArrow) {
|
||||
openPage(book.findPageNumber("index.page1"));
|
||||
}
|
||||
|
||||
@@ -423,10 +457,11 @@ public class GuiBook extends GuiScreen implements IProgressMeter {
|
||||
protected void keyTyped(char typedChar, int keyCode) throws IOException {
|
||||
super.keyTyped(typedChar, keyCode);
|
||||
|
||||
if (loadingAchievements)
|
||||
if(loadingAchievements) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (keyCode) {
|
||||
switch(keyCode) {
|
||||
case Keyboard.KEY_LEFT:
|
||||
case Keyboard.KEY_A:
|
||||
actionPerformed(previousArrow);
|
||||
@@ -443,23 +478,27 @@ public class GuiBook extends GuiScreen implements IProgressMeter {
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
|
||||
if (loadingAchievements)
|
||||
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);
|
||||
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);
|
||||
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++) {
|
||||
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);
|
||||
@@ -468,18 +507,21 @@ public class GuiBook extends GuiScreen implements IProgressMeter {
|
||||
|
||||
@Override
|
||||
public void onGuiClosed() {
|
||||
if (loadingAchievements)
|
||||
if(loadingAchievements) {
|
||||
return;
|
||||
}
|
||||
|
||||
PageData page = this.page == 0 ? book.findPage(0, statFile) : book.findPage((this.page - 1) * 2 + 1, statFile);
|
||||
|
||||
if (page == null)
|
||||
if(page == null) {
|
||||
page = book.findPage((this.page - 1) * 2 + 2, statFile);
|
||||
}
|
||||
|
||||
if (this.page == -1)
|
||||
if(this.page == -1) {
|
||||
BookLoader.updateSavedPage(mc.thePlayer, item, "");
|
||||
else if (page != null && page.parent != null)
|
||||
} else if(page != null && page.parent != null) {
|
||||
BookLoader.updateSavedPage(mc.thePlayer, item, page.parent.name + "." + page.name);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -5,6 +5,7 @@ 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 {
|
||||
@@ -30,7 +31,7 @@ public class GuiBookmark extends GuiButton {
|
||||
|
||||
@Override
|
||||
public void drawButton(Minecraft mc, int mouseX, int mouseY) {
|
||||
if (visible) {
|
||||
if(visible) {
|
||||
int tex_y = TEX_Y + HEIGHT * type;
|
||||
|
||||
mc.renderEngine.bindTexture(TEX_BOOK);
|
||||
@@ -42,13 +43,14 @@ public class GuiBookmark extends GuiButton {
|
||||
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);
|
||||
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")) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import slimeknights.mantle.client.book.data.element.TextData;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@@ -26,15 +27,16 @@ public class TextDataRenderer {
|
||||
|
||||
float prevScale = 1.F;
|
||||
|
||||
for (TextData item : data) {
|
||||
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())
|
||||
if(item.text == null || item.text.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (item.paragraph) {
|
||||
if(item.paragraph) {
|
||||
atX = x;
|
||||
atY += fr.FONT_HEIGHT * 2 * prevScale;
|
||||
}
|
||||
@@ -45,16 +47,21 @@ public class TextDataRenderer {
|
||||
|
||||
modifiers += TextFormatting.getValueByName(item.color);
|
||||
|
||||
if (item.bold)
|
||||
if(item.bold) {
|
||||
modifiers += TextFormatting.BOLD;
|
||||
if (item.italic)
|
||||
}
|
||||
if(item.italic) {
|
||||
modifiers += TextFormatting.ITALIC;
|
||||
if (item.underlined)
|
||||
}
|
||||
if(item.underlined) {
|
||||
modifiers += TextFormatting.UNDERLINE;
|
||||
if (item.strikethrough)
|
||||
}
|
||||
if(item.strikethrough) {
|
||||
modifiers += TextFormatting.STRIKETHROUGH;
|
||||
if (item.obfuscated)
|
||||
}
|
||||
if(item.obfuscated) {
|
||||
modifiers += TextFormatting.OBFUSCATED;
|
||||
}
|
||||
|
||||
String[] split = cropStringBySize(item.text, modifiers, boxWidth, boxHeight - (atY - y), boxWidth - (atX - x), fr, item.scale);
|
||||
|
||||
@@ -63,8 +70,8 @@ public class TextDataRenderer {
|
||||
box2X = x;
|
||||
box2W = x + boxWidth;
|
||||
|
||||
for (int i = 0; i < split.length; i++) {
|
||||
if (i == split.length - 1) {
|
||||
for(int i = 0; i < split.length; i++) {
|
||||
if(i == split.length - 1) {
|
||||
box3X = atX;
|
||||
box3Y = atY;
|
||||
}
|
||||
@@ -72,25 +79,26 @@ public class TextDataRenderer {
|
||||
String s = split[i];
|
||||
drawScaledString(fr, modifiers + s, atX, atY, 0, false, item.scale);
|
||||
|
||||
if (i < split.length - 1) {
|
||||
if(i < split.length - 1) {
|
||||
atY += fr.FONT_HEIGHT;
|
||||
atX = x;
|
||||
}
|
||||
|
||||
if (i == 0) {
|
||||
if(i == 0) {
|
||||
box2Y = atY;
|
||||
|
||||
if (atX == x)
|
||||
if(atX == x) {
|
||||
box1W = x + boxWidth;
|
||||
else
|
||||
} else {
|
||||
box1W = atX;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
box2H = atY;
|
||||
|
||||
atX += fr.getStringWidth(split[split.length - 1]) * item.scale;
|
||||
if (atX - x >= boxWidth) {
|
||||
if(atX - x >= boxWidth) {
|
||||
atX = x;
|
||||
atY += fr.FONT_HEIGHT * item.scale;
|
||||
}
|
||||
@@ -98,43 +106,46 @@ public class TextDataRenderer {
|
||||
box3W = atX;
|
||||
box3H = (int) (atY + fr.FONT_HEIGHT * item.scale);
|
||||
|
||||
if (item.tooltip != null && item.tooltip.length > 0) {
|
||||
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)) {
|
||||
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)) {
|
||||
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) {
|
||||
if(atY >= y + boxHeight) {
|
||||
fr.drawString("...", atX, atY, 0, false);
|
||||
break;
|
||||
}
|
||||
y = atY;
|
||||
}
|
||||
|
||||
if (GuiBook.debug && action != null && !action.isEmpty()) {
|
||||
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++)
|
||||
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] = TextFormatting.GRAY + "Action: " + action;
|
||||
}
|
||||
|
||||
if (drawLabel != null) {
|
||||
if(drawLabel != null) {
|
||||
drawHoveringText(drawLabel, mouseX, mouseY, fr);
|
||||
}
|
||||
|
||||
@@ -149,15 +160,17 @@ public class TextDataRenderer {
|
||||
int curWidth = 0;
|
||||
int curHeight = (int) (fr.FONT_HEIGHT * scale);
|
||||
|
||||
for (int i = 0; i < s.length(); i++) {
|
||||
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)) {
|
||||
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) != ' ')
|
||||
while(i >= 0 && s.charAt(i) != ' ') {
|
||||
i--;
|
||||
if (i <= 0)
|
||||
}
|
||||
if(i <= 0) {
|
||||
i = oldI;
|
||||
}
|
||||
|
||||
s = s.substring(0, i) + "\r" + s.substring(i + (i == oldI ? 0 : 1));
|
||||
|
||||
@@ -165,8 +178,9 @@ public class TextDataRenderer {
|
||||
curWidth = 0;
|
||||
curHeight += fr.FONT_HEIGHT * scale;
|
||||
|
||||
if (curHeight >= height)
|
||||
if(curHeight >= height) {
|
||||
return s.substring(0, i).split("\r");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,14 +189,14 @@ public class TextDataRenderer {
|
||||
|
||||
//BEGIN METHODS FROM GUI
|
||||
private static void drawHoveringText(String[] textLines, int x, int y, FontRenderer font) {
|
||||
if (textLines.length > 0) {
|
||||
if(textLines.length > 0) {
|
||||
GlStateManager.disableDepth();
|
||||
int i = 0;
|
||||
|
||||
for (String s : textLines) {
|
||||
for(String s : textLines) {
|
||||
int j = font.getStringWidth(s);
|
||||
|
||||
if (j > i) {
|
||||
if(j > i) {
|
||||
i = j;
|
||||
}
|
||||
}
|
||||
@@ -191,15 +205,15 @@ public class TextDataRenderer {
|
||||
int i2 = y - 12;
|
||||
int k = 8;
|
||||
|
||||
if (textLines.length > 1) {
|
||||
if(textLines.length > 1) {
|
||||
k += 2 + (textLines.length - 1) * 10;
|
||||
}
|
||||
|
||||
if (l1 + i > GuiBook.PAGE_WIDTH) {
|
||||
if(l1 + i > GuiBook.PAGE_WIDTH) {
|
||||
l1 -= 28 + i;
|
||||
}
|
||||
|
||||
if (i2 + k + 6 > GuiBook.PAGE_HEIGHT) {
|
||||
if(i2 + k + 6 > GuiBook.PAGE_HEIGHT) {
|
||||
i2 = GuiBook.PAGE_HEIGHT - k - 6;
|
||||
}
|
||||
|
||||
@@ -216,11 +230,11 @@ public class TextDataRenderer {
|
||||
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) {
|
||||
for(int k1 = 0; k1 < textLines.length; ++k1) {
|
||||
String s1 = textLines[k1];
|
||||
font.drawStringWithShadow(s1, (float) l1, (float) i2, -1);
|
||||
|
||||
if (k1 == 0) {
|
||||
if(k1 == 0) {
|
||||
i2 += 2;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
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 javax.annotation.Nullable;
|
||||
|
||||
import slimeknights.mantle.client.book.data.BookData;
|
||||
import slimeknights.mantle.client.gui.book.BoxRenderer;
|
||||
import slimeknights.mantle.client.gui.book.GuiBook;
|
||||
@@ -19,8 +21,9 @@ public class GuiBookEditor extends GuiScreen {
|
||||
private int side;
|
||||
|
||||
public GuiBookEditor(@Nullable BookData book) {
|
||||
if (book == null)
|
||||
if(book == null) {
|
||||
book = new BookData();
|
||||
}
|
||||
|
||||
innerUi = new GuiBook(book, null, null);
|
||||
innerUi.mc = Minecraft.getMinecraft();
|
||||
@@ -35,21 +38,24 @@ public class GuiBookEditor extends GuiScreen {
|
||||
|
||||
TextureManager render = this.mc.renderEngine;
|
||||
|
||||
if (mc.gameSettings.guiScale == 1) {
|
||||
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);
|
||||
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) {
|
||||
if(innerUi.getPage_() == -1) {
|
||||
GlStateManager.pushMatrix();
|
||||
if (mc.gameSettings.guiScale == 1)
|
||||
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);
|
||||
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);
|
||||
@@ -70,7 +76,7 @@ public class GuiBookEditor extends GuiScreen {
|
||||
innerUi.width = width + SIDEBAR_WIDTH * (mc.gameSettings.guiScale == 1 ? 2 : 1);
|
||||
innerUi.height = height;
|
||||
|
||||
if (mc.gameSettings.guiScale == 1) {
|
||||
if(mc.gameSettings.guiScale == 1) {
|
||||
width /= 2F;
|
||||
height /= 2F;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
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;
|
||||
@@ -10,6 +9,9 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import slimeknights.mantle.client.gui.book.GuiBook;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@@ -40,8 +42,8 @@ public abstract class BookElement extends Gui {
|
||||
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) {
|
||||
for(int i = 0; i < list.size(); ++i) {
|
||||
if(i == 0) {
|
||||
list.set(i, stack.getRarity().rarityColor + list.get(i));
|
||||
} else {
|
||||
list.set(i, TextFormatting.GRAY + list.get(i));
|
||||
@@ -53,14 +55,14 @@ public abstract class BookElement extends Gui {
|
||||
}
|
||||
|
||||
public void drawHoveringText(List<String> textLines, int x, int y, FontRenderer font) {
|
||||
if (!textLines.isEmpty()) {
|
||||
if(!textLines.isEmpty()) {
|
||||
GlStateManager.disableDepth();
|
||||
int i = 0;
|
||||
|
||||
for (String s : textLines) {
|
||||
for(String s : textLines) {
|
||||
int j = font.getStringWidth(s);
|
||||
|
||||
if (j > i) {
|
||||
if(j > i) {
|
||||
i = j;
|
||||
}
|
||||
}
|
||||
@@ -69,15 +71,15 @@ public abstract class BookElement extends Gui {
|
||||
int i2 = y - 12;
|
||||
int k = 8;
|
||||
|
||||
if (textLines.size() > 1) {
|
||||
if(textLines.size() > 1) {
|
||||
k += 2 + (textLines.size() - 1) * 10;
|
||||
}
|
||||
|
||||
if (l1 + i > GuiBook.PAGE_WIDTH) {
|
||||
if(l1 + i > GuiBook.PAGE_WIDTH) {
|
||||
l1 -= 28 + i;
|
||||
}
|
||||
|
||||
if (i2 + k + 6 > GuiBook.PAGE_HEIGHT) {
|
||||
if(i2 + k + 6 > GuiBook.PAGE_HEIGHT) {
|
||||
i2 = GuiBook.PAGE_HEIGHT - k - 6;
|
||||
}
|
||||
|
||||
@@ -94,11 +96,11 @@ public abstract class BookElement extends Gui {
|
||||
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) {
|
||||
for(int k1 = 0; k1 < textLines.size(); ++k1) {
|
||||
String s1 = textLines.get(k1);
|
||||
font.drawStringWithShadow(s1, (float) l1, (float) i2, -1);
|
||||
|
||||
if (k1 == 0) {
|
||||
if(k1 == 0) {
|
||||
i2 += 2;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ 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)
|
||||
@@ -28,16 +29,21 @@ public class ElementImage extends SizedBookElement {
|
||||
|
||||
this.image = image;
|
||||
|
||||
if (image.x != -1)
|
||||
if(image.x != -1) {
|
||||
x = image.x;
|
||||
if (image.y != -1)
|
||||
}
|
||||
if(image.y != -1) {
|
||||
y = image.y;
|
||||
if (image.width != -1)
|
||||
}
|
||||
if(image.width != -1) {
|
||||
width = image.width;
|
||||
if (image.height != -1)
|
||||
}
|
||||
if(image.height != -1) {
|
||||
height = image.height;
|
||||
if (image.colorMultiplier != 0xFFFFFF)
|
||||
}
|
||||
if(image.colorMultiplier != 0xFFFFFF) {
|
||||
colorMultiplier = image.colorMultiplier;
|
||||
}
|
||||
|
||||
this.x = x == -1 ? 0 : x;
|
||||
this.y = y == -1 ? 0 : y;
|
||||
|
||||
@@ -7,6 +7,7 @@ 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)
|
||||
@@ -50,12 +51,13 @@ public class ElementItem extends BookElement {
|
||||
public void draw(int mouseX, int mouseY, float partialTicks) {
|
||||
renderTick++;
|
||||
|
||||
if (renderTick > ITEM_SWITCH_TICKS) {
|
||||
if(renderTick > ITEM_SWITCH_TICKS) {
|
||||
renderTick = 0;
|
||||
currentItem++;
|
||||
|
||||
if (currentItem >= itemCycle.length)
|
||||
if(currentItem >= itemCycle.length) {
|
||||
currentItem = 0;
|
||||
}
|
||||
}
|
||||
|
||||
RenderHelper.enableGUIStandardItemLighting();
|
||||
@@ -63,26 +65,28 @@ public class ElementItem extends BookElement {
|
||||
GlStateManager.translate(x, y, 0);
|
||||
GlStateManager.scale(scale, scale, 1.0F);
|
||||
|
||||
if (currentItem < itemCycle.length)
|
||||
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) {
|
||||
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)
|
||||
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
|
||||
} else {
|
||||
parent.itemClicked(itemCycle[currentItem]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,13 @@
|
||||
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.text.TextFormatting;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import slimeknights.mantle.client.book.data.SectionData;
|
||||
|
||||
public class ElementSection extends BookElement {
|
||||
@@ -29,12 +30,12 @@ public class ElementSection extends BookElement {
|
||||
boolean unlocked = section.isUnlocked(parent.statFile);
|
||||
boolean hover = mouseX > x && mouseY > y && mouseX < x + WIDTH && mouseY < y + HEIGHT;
|
||||
|
||||
if (section.icon != null) {
|
||||
if(section.icon != null) {
|
||||
renderEngine.bindTexture(section.icon.location);
|
||||
|
||||
if (unlocked)
|
||||
if(unlocked) {
|
||||
GlStateManager.color(1F, 1F, 1F, hover ? 1F : 0.5F);
|
||||
else {
|
||||
} 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;
|
||||
@@ -44,21 +45,25 @@ public class ElementSection extends BookElement {
|
||||
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);
|
||||
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) {
|
||||
if(section != null && !section
|
||||
.isUnlocked(parent.statFile) && mouseX > x && mouseY > y && mouseX < x + WIDTH && mouseY < y + HEIGHT) {
|
||||
List<String> l = new ArrayList<>();
|
||||
l.add(TextFormatting.RED + "Locked");
|
||||
l.add("Requirements:");
|
||||
|
||||
for (String requirement : section.requirements) {
|
||||
for(String requirement : section.requirements) {
|
||||
Achievement achievement = SectionData.findAchievement(requirement);
|
||||
if (achievement != null)
|
||||
l.add((SectionData.requirementSatisfied(requirement, parent.statFile) ? TextFormatting.GREEN : TextFormatting.RED) + TextFormatting
|
||||
.getTextWithoutFormattingCodes(achievement.getStatName().getFormattedText()));
|
||||
if(achievement != null) {
|
||||
l.add((SectionData
|
||||
.requirementSatisfied(requirement, parent.statFile) ? TextFormatting.GREEN : TextFormatting.RED) + TextFormatting
|
||||
.getTextWithoutFormattingCodes(achievement.getStatName().getFormattedText()));
|
||||
}
|
||||
}
|
||||
|
||||
drawHoveringText(l, mouseX, mouseY, Minecraft.getMinecraft().fontRendererObj);
|
||||
@@ -66,7 +71,9 @@ public class ElementSection extends BookElement {
|
||||
}
|
||||
|
||||
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)
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
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;
|
||||
@@ -17,19 +15,20 @@ import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.client.renderer.texture.TextureUtil;
|
||||
import net.minecraft.init.Biomes;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.JsonToNBT;
|
||||
import net.minecraft.nbt.NBTException;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.WorldType;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
import net.minecraftforge.fml.common.registry.GameData;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import slimeknights.mantle.client.book.data.element.BlockData;
|
||||
import slimeknights.mantle.client.book.data.element.ItemStackData;
|
||||
|
||||
@@ -53,11 +52,12 @@ public class ElementStructure extends SizedBookElement {
|
||||
super(x, y, width, height);
|
||||
world = new BlockAccess(size, structure);
|
||||
|
||||
if (size.length == 3) {
|
||||
if(size.length == 3) {
|
||||
scale = size[0] > size[1] ? width / size[0] - 10F : height / size[1] - 10F;
|
||||
|
||||
if (scale * size[0] > width)
|
||||
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;
|
||||
@@ -111,25 +111,27 @@ public class ElementStructure extends SizedBookElement {
|
||||
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++) {
|
||||
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().getModelForState(state);
|
||||
|
||||
Block block = state.getBlock();
|
||||
|
||||
if (block == Blocks.air)
|
||||
if(block == Blocks.air) {
|
||||
continue;
|
||||
}
|
||||
|
||||
GlStateManager.pushMatrix();
|
||||
|
||||
GlStateManager.enableDepth();
|
||||
mc.renderEngine.bindTexture(TextureMap.locationBlocksTexture);
|
||||
|
||||
if (block == null)
|
||||
if(block == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
int color = blockColors.colorMultiplier(state, world, pos, 0);
|
||||
float red = (color >> 16 & 255) / 255.0F;
|
||||
@@ -147,7 +149,7 @@ public class ElementStructure extends SizedBookElement {
|
||||
int i = blockColors.colorMultiplier(state, world, pos, 0);
|
||||
GlStateManager.rotate(90F, 0, 1, 0);
|
||||
|
||||
if (EntityRenderer.anaglyphEnable) {
|
||||
if(EntityRenderer.anaglyphEnable) {
|
||||
i = TextureUtil.anaglyphColor(i);
|
||||
}
|
||||
|
||||
@@ -186,15 +188,15 @@ public class ElementStructure extends SizedBookElement {
|
||||
boolean flag = color == -1;
|
||||
int i = 0;
|
||||
|
||||
for (int j = quads.size(); i < j; ++i) {
|
||||
for(int j = quads.size(); i < j; ++i) {
|
||||
BakedQuad bakedquad = quads.get(i);
|
||||
int k = color;
|
||||
|
||||
if (flag && bakedquad.hasTintIndex()) {
|
||||
if(flag && bakedquad.hasTintIndex()) {
|
||||
Block block = world.getBlockState(pos).getBlock();
|
||||
k = blockColors.colorMultiplier(world.getBlockState(pos), world, pos, 0);
|
||||
|
||||
if (EntityRenderer.anaglyphEnable) {
|
||||
if(EntityRenderer.anaglyphEnable) {
|
||||
k = TextureUtil.anaglyphColor(k);
|
||||
}
|
||||
|
||||
@@ -218,31 +220,34 @@ public class ElementStructure extends SizedBookElement {
|
||||
blocks = new int[size[0]][size[1]][size[2]];
|
||||
meta = new byte[size[0]][size[1]][size[2]];
|
||||
|
||||
for (BlockData block : structure) {
|
||||
for(BlockData block : structure) {
|
||||
Block tile = Block.getBlockFromName(block.block);
|
||||
if (tile == null)
|
||||
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])
|
||||
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) {
|
||||
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) {
|
||||
if(block.nbt != null) {
|
||||
try {
|
||||
te.readFromNBT(JsonToNBT.getTagFromJson(ItemStackData.filterJsonQuotes(block.nbt.toString())));
|
||||
} catch (NBTException e) {
|
||||
} catch(NBTException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -256,8 +261,9 @@ public class ElementStructure extends SizedBookElement {
|
||||
|
||||
@Override
|
||||
public TileEntity getTileEntity(BlockPos pos) {
|
||||
if (!isValid(pos))
|
||||
if(!isValid(pos)) {
|
||||
return null;
|
||||
}
|
||||
return tileEntityMap.get(new Integer[]{pos.getX(), pos.getY(), pos.getZ()});
|
||||
}
|
||||
|
||||
@@ -268,11 +274,13 @@ public class ElementStructure extends SizedBookElement {
|
||||
|
||||
@Override
|
||||
public IBlockState getBlockState(BlockPos pos) {
|
||||
if (!isValid(pos))
|
||||
if(!isValid(pos)) {
|
||||
return Blocks.air.getDefaultState();
|
||||
}
|
||||
Block block = Block.getBlockById(blocks[pos.getX()][pos.getY()][pos.getZ()]);
|
||||
if (block == null)
|
||||
if(block == null) {
|
||||
return Blocks.air.getDefaultState();
|
||||
}
|
||||
|
||||
return block.getActualState(block.getStateFromMeta(meta[pos.getX()][pos.getY()][pos.getZ()]), this, pos);
|
||||
}
|
||||
@@ -294,8 +302,9 @@ public class ElementStructure extends SizedBookElement {
|
||||
|
||||
@Override
|
||||
public int getStrongPower(BlockPos pos, EnumFacing direction) {
|
||||
if (!isValid(pos))
|
||||
if(!isValid(pos)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
IBlockState iblockstate = this.getBlockState(pos);
|
||||
return iblockstate.getBlock().getStrongPower(iblockstate, this, pos, direction);
|
||||
@@ -308,8 +317,9 @@ public class ElementStructure extends SizedBookElement {
|
||||
|
||||
@Override
|
||||
public boolean isSideSolid(BlockPos pos, EnumFacing side, boolean _default) {
|
||||
if (!this.isValid(pos))
|
||||
if(!this.isValid(pos)) {
|
||||
return _default;
|
||||
}
|
||||
|
||||
return getBlockState(pos).getBlock().isSideSolid(this.getBlockState(pos), this, pos, side);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ 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;
|
||||
@@ -27,7 +28,7 @@ public class ElementText extends SizedBookElement {
|
||||
public void draw(int mouseX, int mouseY, float partialTicks) {
|
||||
String action = TextDataRenderer.drawText(x, y, width, height, text, mouseX, mouseY);
|
||||
|
||||
if (doAction) {
|
||||
if(doAction) {
|
||||
doAction = false;
|
||||
StringActionProcessor.process(action, parent);
|
||||
}
|
||||
@@ -35,7 +36,8 @@ public class ElementText extends SizedBookElement {
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
|
||||
if (mouseButton == 0)
|
||||
if(mouseButton == 0) {
|
||||
doAction = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user