That's because I added the rendering stuff directly to that class. I should probably change this...
package com.bedrockminer.magicum.codex.entries;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import com.bedrockminer.magicum.Magicum;
import com.bedrockminer.magicum.client.gui.GuiCodexMagicum;
import com.bedrockminer.magicum.codex.Codex;
import com.bedrockminer.magicum.codex.CodexPage;
import com.bedrockminer.magicum.element.Elements;
import com.bedrockminer.magicum.extendedproperties.PropertiesCodex;
import com.bedrockminer.minersbasic.client.gui.GuiRenderer;
import com.bedrockminer.minersbasic.client.render.Color;
import com.bedrockminer.minersbasic.items.ItemTemplate;
import com.bedrockminer.minersbasic.log.Log;
import com.bedrockminer.minersbasic.position.Point;
import com.google.gson.stream.JsonReader;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class CodexEntry {
/** A unique ID for this Codex Entry */
private final int ID;
/** The internal name of this Codex Entry */
private final String name;
/** These IDs are required to display the Entry */
private int[] requiredIDs = new int[0];
/** X Position on screen */
private final int x;
/** Y Position on Screen */
private final int y;
/** Colour of the Connecting lines */
private int lineColour = Color.BLACK.toInt();
/** List of all Lines. Lines are stored as a List of Control Vertices */
private List<Point[]> lines = new ArrayList<Point[]>();
/** If true the entry has a special symbol */
private boolean hasSpecialLayout = false;
/** If true the Entry has a special research that has to be completed before ready to craft */
private boolean needsResearch = false;
/** List of Items that are shown as a tooltip as help for the Research */
private ItemStack[] researchHelpItems = new ItemStack[0];
/** List of Elements that are shown as a tooltip as help for the Research */
private Elements[] researchHelpElements = new Elements[0];
/** Localized Title of the Entry */
private String title = "";
/** Localized Description of the Entry */
private String desc = "";
/** Localized Pages of the Entry */
private String[] pages = new String[0];
/** Data for the Commands of this Object */
private Object[] command_data = new Object[0];
/** Optional special Text shown when completing a research for this Entry. Not used if equals "" */
private String researchText = "";
/** Optional special Text shown when completing crafting for this Entry. Not used if equals "" */
private String craftingText = "";
/** If true the iconItem is used for rendering, otherwise the coordinates */
private boolean isIconItem = false;
/** Itemstack to show as the entry's Icon */
private ItemStack iconItem = null;
/** Entry's Icon's x coordinate */
private int iconX = 1;
/** Entry's Icon's y coordinate */
private int iconY = 1;
private static GuiRenderer g = GuiRenderer.instance;
protected static ResourceLocation icons = new ResourceLocation(Magicum.MODID, "codex/codex_icons.png");
protected static ResourceLocation labels = new ResourceLocation(Magicum.MODID, "codex/achievement_labels.png");
public CodexEntry(int ID, String name, int x, int y) {
this.ID = ID;
this.title = this.name = name;
this.x = x;
this.y = y;
Codex.registerEntry(this);
}
/** Adds a Line Rendering to this Entry */
public CodexEntry addLine(Point ... vertices) {
this.lines.add(vertices);
return this;
}
/** Adds this Codex Entry to the given CodexPage */
public CodexEntry addToCodexPage(CodexPage page) {
page.add(this);
return this;
}
public void checkDependencies(EntityPlayer player) {
if (PropertiesCodex.get(player).codexList.get(this.getID()) <= (this.needsResearch() ? Codex.HIDDEN : Codex.RESEARCHED)) {
boolean reveal = true;
for (int i : this.getRequiredIDs()) {
if (i == -1 || PropertiesCodex.get(player).codexList.get(i) < Codex.RESEARCHED || (PropertiesCodex.get(player).codexList.get(i) < Codex.COMPLETE && !Codex.entryList.get(i).needsResearch)) {
reveal = false;
break;
}
}
if (reveal) {
if (this.needsResearch())
this.reveal(player);
else
this.completeResearch(player);
}
}
}
/** Sets the given Codex Entry for the given Player to the status {@link Codex#COMPLETE} if it is not completed. */
public void completeCraft(EntityPlayer player) {
if (PropertiesCodex.get(player).codexList.get(this.getID()) < Codex.COMPLETE) {
PropertiesCodex.get(player).codexList.set(this.getID(), Codex.COMPLETE);
if (player instanceof EntityPlayerMP) {
Codex.sendCodexChanges((EntityPlayerMP) player, this);
Codex.publishCompletion((EntityPlayerMP) player, this);
}
Codex.updateCodexDependencies(player);
}
}
/** Sets the given Codex Entry for the given Player to the status {@link Codex#RESEARCHED} if it is only visible or hidden. */
public void completeResearch(EntityPlayer player) {
if (PropertiesCodex.get(player).codexList.get(this.getID()) < Codex.RESEARCHED) {
PropertiesCodex.get(player).codexList.set(this.getID(), Codex.RESEARCHED);
if (player instanceof EntityPlayerMP)
Codex.sendCodexChanges((EntityPlayerMP) player, this);
Codex.updateCodexDependencies(player);
}
}
public Object[] getCommand_data() {
return this.command_data;
}
/**
* @return the ID
*/
public int getID() {
return this.ID;
}
/** Returns the message shown as achievement when completing this codex entry.
* Used in translations with either "text.codex." or "chat.codex.achievement." as prefix*/
public String getMessage() {
return "text.codex.completion.entry_complete";
}
/**
* @return the Name
*/
public String getName() {
return this.name;
}
/**
* @return The localized Pages of this Entry
*/
public String[] getPages() {
return this.pages;
}
/**
* @return the requiredIDs
*/
public int[] getRequiredIDs() {
return this.requiredIDs;
}
/** @return The unlocalized String to show in the tooltip concerning the status of this entry*/
public String getStatusText(byte state) {
if (state < Codex.COMPLETE && !this.needsResearch())
return "text.codex.status.not_completed";
if (state == Codex.RESEARCHED)
return "text.codex.status.researched";
if (state == Codex.COMPLETE)
return "text.codex.status.completed";
return "text.codex.status.needs_research";
}
/**
* @return The localized Title of this Entry
*/
public String getTitle() {
return this.title;
}
public int getX() {
return this.x;
}
public int getY() {
return this.y;
}
@Override
public int hashCode() {
return this.ID;
}
public boolean hasSpecialLayout() {
return this.hasSpecialLayout;
}
public void loadFromAssets(String languageCode) {
ResourceLocation res = new ResourceLocation(Magicum.MODID, "codex/lang/" + languageCode + "/" + this.getName() + ".json");
try {
Minecraft.getMinecraft().getResourceManager().getResource(res);
} catch (IOException e1) {
res = new ResourceLocation(Magicum.MODID, "codex/lang/en_US/" + this.getName() + ".json");
}
try {
JsonReader reader = new JsonReader(new InputStreamReader(Minecraft.getMinecraft().getResourceManager().getResource(res).getInputStream(), "UTF-8"));
reader.beginObject();
while (reader.hasNext()) {
String identifier = reader.nextName();
if (identifier.equals("title")) {
this.title = reader.nextString();
} else if (identifier.equals("desc")) {
this.desc = reader.nextString();
} else if (identifier.equals("icon_item")) {
ItemTemplate temp = ItemTemplate.createFromString(reader.nextString());
if (temp != null) {
this.iconItem = temp.createStack();
this.isIconItem = true;
}
} else if (identifier.equals("icon_x")) {
this.iconX = reader.nextInt();
this.isIconItem = false;
} else if (identifier.equals("icon_y")) {
this.iconY = reader.nextInt();
this.isIconItem = false;
} else if (identifier.equals("pages")) {
reader.beginArray();
List<String> data = new ArrayList<String>();
while (reader.hasNext()) {
data.add(reader.nextString());
}
reader.endArray();
this.pages = new String[data.size()];
data.toArray(this.pages);
} else if (identifier.equals("command_data")) {
reader.beginArray();
List<String> data = new ArrayList<String>();
while (reader.hasNext()) {
data.add(reader.nextString());
}
reader.endArray();
this.command_data = new Object[data.size()];
for (int i = 0; i < data.size(); i ++) {
if (data.get(i).startsWith("resource:")) {
this.command_data[i] = new ResourceLocation(Magicum.MODID, data.get(i).substring(9));
} else if (data.get(i).startsWith("stack:")) {
ItemTemplate tmp = ItemTemplate.createFromString(data.get(i).substring(6));
if (tmp != null)
this.command_data[i] = tmp.createStack();
}
}
} else {
reader.skipValue();
}
}
reader.endObject();
reader.close();
}
catch (FileNotFoundException e) {
Log.warn(Magicum.MODID, "Resource File Missing: %s", res.toString());
}
catch (IOException e) {
Log.error(Magicum.MODID, "Encountered IOException");
e.printStackTrace();
}
}
/**
* @return the needsResearch
*/
public boolean needsResearch() {
return this.needsResearch;
}
@SideOnly(Side.CLIENT)
public void onEntryClicked(GuiCodexMagicum gui, Minecraft mc) {
if (Codex.getStatusFor(mc.thePlayer, this) >= Codex.RESEARCHED)
gui.showEntryPage(this.getID());
}
@SideOnly(Side.CLIENT)
public void renderLinesToCodex(GuiCodexMagicum gui, Minecraft mc, int x0, int y0) {
this.g.reset();
GL11.glLineWidth(gui.scale);
this.g.disableTexture();
if (Codex.getStatusFor(mc.thePlayer, this) <= 1) {
Color c = Color.fromInt(this.lineColour);
c.r /= 3.0;
c.g /= 3.0;
c.b /= 3.0;
if (Codex.getStatusFor(mc.thePlayer, this) == 0)
c.a = 0.15;
this.g.setColor(c);
} else {
this.g.setColor(Color.fromInt(this.lineColour));
}
for (Point[] line : this.lines) {
if (line.length > 2) {
this.g.renderCurve(this.g.controlpoints(line, x0, y0));
} else {
GL11.glBegin(GL11.GL_LINE_STRIP);
GL11.glVertex3d(line[0].x + x0, line[0].y + y0, this.g.zLevel);
GL11.glVertex3d(line[1].x + x0, line[1].y + y0, this.g.zLevel);
GL11.glEnd();
}
}
}
@SideOnly(Side.CLIENT)
public void renderEntry(Minecraft mc, int x, int y) {
if (Codex.getStatusFor(mc.thePlayer, this) > 0) {
this.g.bindTexture(this.icons);
this.g.reset();
if (Codex.getStatusFor(mc.thePlayer, this) == Codex.VISIBLE)
this.g.setColor(new Color(0.25, 0.25, 0.25));
if (Codex.getStatusFor(mc.thePlayer, this) == Codex.RESEARCHED) {
double value = 0.85 + 0.15 * Math.sin(Minecraft.getSystemTime() / 200.0 + this.getID());
this.g.setColor(new Color(value, value, value));
}
this.g.drawTexturedRect(x, y, (Codex.getStatusFor(mc.thePlayer, this) - 1) * 26, this.hasSpecialLayout ? 26 : 0, 26, 26);
this.renderEntryIcon(mc, x + 5, y + 5);
} else {
this.g.bindTexture(this.icons);
this.g.reset();
this.g.setColor(new Color(0.25, 0.25, 0.25, 0.15));
this.g.drawTexturedRect(x, y, 0, this.hasSpecialLayout ? 26 : 0, 26, 26);
}
}
@SideOnly(Side.CLIENT)
public void renderEntryIcon(Minecraft mc, int x, int y) {
if (this.isIconItem) {
this.g.drawItemStack(this.iconItem, x, y, "");
} else {
this.g.bindTexture(this.labels);
this.g.drawTexturedRect(x, y, this.iconX * 16, this.iconY * 16, 16, 16);
}
}
@SideOnly(Side.CLIENT)
public void renderEntryTooltip(GuiCodexMagicum gui, Minecraft mc, int x, int y) {
byte state = Codex.getStatusFor(mc.thePlayer, this);
List<String> strings = new ArrayList<String>();
strings.add(this.title);
strings.add("" + EnumChatFormatting.GRAY + this.desc);
strings.add("" + EnumChatFormatting.DARK_GRAY + EnumChatFormatting.ITALIC + I18n.format(this.getStatusText(state)));
List<ItemStack> items = new ArrayList<ItemStack>();
for (ItemStack s : this.researchHelpItems)
items.add(s);
List<Elements> elements = new ArrayList<Elements>();
for (Elements e : this.researchHelpElements)
elements.add(e);
if (state == Codex.HIDDEN)
return;
if (state == Codex.VISIBLE) {
gui.drawAdvancedTooltip(strings, items, elements, x, y, mc.fontRenderer);
}
if (state >= Codex.RESEARCHED) {
gui.drawAdvancedTooltip(strings, new ArrayList<ItemStack>(), new ArrayList<Elements>(), x, y, mc.fontRenderer);
}
}
/** Sets the given Codex Entry for the given Player to the status {@link Codex#VISIBLE} if it is hidden. */
public void reveal(EntityPlayer player) {
if (PropertiesCodex.get(player).codexList.get(this.getID()) < Codex.VISIBLE) {
PropertiesCodex.get(player).codexList.set(this.getID(), Codex.VISIBLE);
Codex.updateCodexDependencies(player);
if (player instanceof EntityPlayerMP)
Codex.sendCodexChanges((EntityPlayerMP) player, this);
}
}
/** Sets the colour of the lines */
public CodexEntry setLineColour(int lineColour) {
this.lineColour = lineColour;
return this;
}
/** Sets the required IDs to display this Entry.*/
public CodexEntry setRequiredIDs(int... requiredIDs) {
this.requiredIDs = requiredIDs;
return this;
}
/** Activates the Research Requirement for this Entry */
public CodexEntry setResearch(boolean needsResearch) {
this.needsResearch = needsResearch;
return this;
}
/** Sets the help information for this Entry */
public CodexEntry setResearchHelp(Elements... researchHelpElements) {
this.researchHelpElements = researchHelpElements;
return this;
}
/** Sets the help information for this Entry */
public CodexEntry setResearchHelp(ItemStack... researchHelpItems) {
this.researchHelpItems = researchHelpItems;
return this;
}
/** Activates the special layout for this Entry */
public CodexEntry setSpecialLayout(boolean hasSpecialLayout) {
this.hasSpecialLayout = hasSpecialLayout;
return this;
}
public boolean shouldBeAnnounced() {
return true;
}
public boolean shouldShowCompletedOverlay() {
return true;
}
}