mirror of
https://github.com/GTNewHorizons/Mantle.git
synced 2026-11-27 15:23:12 +00:00
Book section gating
- Added section unlock criteria - Added type adapter for Hex/Binary int String -> int
This commit is contained in:
1 parent
1ac2d95644
commit
b8e0dde333
9 files changed
+221
-105
No files matched your search
@@ -6,6 +6,7 @@ import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.stats.StatFileWriter;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
@@ -90,18 +91,26 @@ public class BookData implements IDataItem {
|
||||
}
|
||||
|
||||
public SectionData findSection(String name) {
|
||||
return findSection(name, null);
|
||||
}
|
||||
|
||||
public SectionData findSection(String name, @Nullable StatFileWriter writer) {
|
||||
for (SectionData section : sections)
|
||||
if (section.name.equals(name.toLowerCase()))
|
||||
return section;
|
||||
return section.isUnlocked(writer) ? section : null;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getFirstPageNumber(SectionData section) {
|
||||
return getFirstPageNumber(section, null);
|
||||
}
|
||||
|
||||
public int getFirstPageNumber(SectionData section, @Nullable StatFileWriter writer) {
|
||||
int pages = 0;
|
||||
for (SectionData sect : sections) {
|
||||
if (section == sect)
|
||||
return pages + 1;
|
||||
return section.isUnlocked(writer) ? pages + 1 : -1;
|
||||
|
||||
pages += sect.getPageCount();
|
||||
}
|
||||
@@ -110,11 +119,18 @@ public class BookData implements IDataItem {
|
||||
}
|
||||
|
||||
public PageData findPage(int number) {
|
||||
return findPage(number, null);
|
||||
}
|
||||
|
||||
public PageData findPage(int number, @Nullable StatFileWriter writer) {
|
||||
if (number < 0)
|
||||
return null;
|
||||
|
||||
int pages = 0;
|
||||
for (SectionData section : sections) {
|
||||
if (!section.isUnlocked(writer))
|
||||
continue;
|
||||
|
||||
if (pages + section.getPageCount() > number)
|
||||
return section.pages.get(number - pages);
|
||||
else
|
||||
@@ -125,10 +141,18 @@ public class BookData implements IDataItem {
|
||||
}
|
||||
|
||||
public PageData findPage(String location) {
|
||||
return findPage(findPageNumber(location));
|
||||
return findPage(location, null);
|
||||
}
|
||||
|
||||
public PageData findPage(String location, @Nullable StatFileWriter writer) {
|
||||
return findPage(findPageNumber(location, writer));
|
||||
}
|
||||
|
||||
public int findPageNumber(String location) {
|
||||
return findPageNumber(location, null);
|
||||
}
|
||||
|
||||
public int findPageNumber(String location, @Nullable StatFileWriter writer) {
|
||||
location = location.toLowerCase();
|
||||
|
||||
int pages = 0;
|
||||
@@ -140,6 +164,9 @@ public class BookData implements IDataItem {
|
||||
String pageName = location.substring(location.indexOf('.') + 1);
|
||||
|
||||
for (SectionData section : sections) {
|
||||
if (!section.isUnlocked(writer))
|
||||
continue;
|
||||
|
||||
if (!sectionName.equals(section.name)) {
|
||||
pages += section.getPageCount();
|
||||
continue;
|
||||
@@ -159,15 +186,23 @@ public class BookData implements IDataItem {
|
||||
}
|
||||
|
||||
public int getPageCount() {
|
||||
return getPageCount(null);
|
||||
}
|
||||
|
||||
public int getPageCount(@Nullable StatFileWriter writer) {
|
||||
int pages = 0;
|
||||
for (SectionData section : sections) {
|
||||
pages += section.getPageCount();
|
||||
pages += section.isUnlocked(writer) ? section.getPageCount() : 0;
|
||||
}
|
||||
return pages;
|
||||
}
|
||||
|
||||
public int getFullPageCount() {
|
||||
return (int) Math.ceil((getPageCount() - 1) / 2F) + 1;
|
||||
return getFullPageCount(null);
|
||||
}
|
||||
|
||||
public int getFullPageCount(@Nullable StatFileWriter writer) {
|
||||
return (int) Math.ceil((getPageCount(writer) - 1) / 2F) + 1;
|
||||
}
|
||||
|
||||
public String getItemAction(ItemStackData item) {
|
||||
@@ -180,8 +215,8 @@ public class BookData implements IDataItem {
|
||||
}
|
||||
|
||||
public void openGui(@Nullable ItemStack item) {
|
||||
if (Minecraft.getMinecraft().currentScreen == null)
|
||||
Minecraft.getMinecraft().displayGuiScreen(new GuiBook(this, item));
|
||||
if (Minecraft.getMinecraft().thePlayer != null)
|
||||
Minecraft.getMinecraft().displayGuiScreen(new GuiBook(this, Minecraft.getMinecraft().thePlayer.getStatFileWriter(), item));
|
||||
}
|
||||
|
||||
public void addRepository(BookRepository repository) {
|
||||
|
||||
Reference in new issue
Block a user