mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-22 23:28:35 +01:00
Added page sorting for the booklet
This commit is contained in:
parent
b57da71627
commit
39a72e176b
18 changed files with 148 additions and 17 deletions
|
@ -31,7 +31,7 @@ public final class ActuallyAdditionsAPI{
|
|||
|
||||
public static final String MOD_ID = "actuallyadditions";
|
||||
public static final String API_ID = MOD_ID+"api";
|
||||
public static final String API_VERSION = "30";
|
||||
public static final String API_VERSION = "31";
|
||||
|
||||
public static final List<CrusherRecipe> CRUSHER_RECIPES = new ArrayList<CrusherRecipe>();
|
||||
public static final List<BallOfFurReturn> BALL_OF_FUR_RETURN_ITEMS = new ArrayList<BallOfFurReturn>();
|
||||
|
|
|
@ -27,4 +27,6 @@ public interface IBookletChapter{
|
|||
String getIdentifier();
|
||||
|
||||
int getPageIndex(IBookletPage page);
|
||||
|
||||
int getSortingPriority();
|
||||
}
|
||||
|
|
|
@ -29,4 +29,6 @@ public interface IBookletEntry{
|
|||
|
||||
@SideOnly(Side.CLIENT)
|
||||
List<IBookletChapter> getChaptersForDisplay(String searchBarText);
|
||||
|
||||
int getSortingPriority();
|
||||
}
|
||||
|
|
|
@ -66,4 +66,6 @@ public interface IBookletPage{
|
|||
IBookletPage addTextReplacement(String key, float value);
|
||||
|
||||
IBookletPage addTextReplacement(String key, int value);
|
||||
|
||||
int getSortingPriority();
|
||||
}
|
||||
|
|
|
@ -53,4 +53,14 @@ public interface IMethodHandler{
|
|||
IBookletPage generateFurnacePage(int id, ItemStack input, ItemStack result);
|
||||
|
||||
IBookletChapter generateBookletChapter(String identifier, IBookletEntry entry, ItemStack displayStack, IBookletPage... pages);
|
||||
|
||||
IBookletPage generateTextPage(int id, int priority);
|
||||
|
||||
IBookletPage generatePicturePage(int id, ResourceLocation resLoc, int textStartY, int priority);
|
||||
|
||||
IBookletPage generateCraftingPage(int id, int priority, IRecipe... recipes);
|
||||
|
||||
IBookletPage generateFurnacePage(int id, ItemStack input, ItemStack result, int priority);
|
||||
|
||||
IBookletChapter generateBookletChapter(String identifier, IBookletEntry entry, ItemStack displayStack, int priority, IBookletPage... pages);
|
||||
}
|
||||
|
|
|
@ -137,7 +137,7 @@ public class ActuallyAdditions{
|
|||
LensRecipeHandler.init();
|
||||
EmpowererHandler.init();
|
||||
|
||||
InitBooklet.init();
|
||||
InitBooklet.postInit();
|
||||
proxy.postInit(event);
|
||||
|
||||
ModUtil.LOGGER.info("PostInitialization Finished.");
|
||||
|
|
|
@ -45,15 +45,15 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
public final class InitBooklet{
|
||||
|
||||
public static BookletChapter[] chaptersIntroduction = new BookletChapter[9];
|
||||
|
||||
public static void preInit(){
|
||||
ActuallyAdditionsAPI.allAndSearch = new BookletEntryAllItems("allAndSearch").setImportant();
|
||||
|
||||
ActuallyAdditionsAPI.entryGettingStarted = new BookletEntry("gettingStarted").setImportant();
|
||||
ActuallyAdditionsAPI.entryReconstruction = new BookletEntry("reconstruction");
|
||||
ActuallyAdditionsAPI.entryLaserRelays = new BookletEntry("laserRelays").setSpecial();
|
||||
|
@ -64,10 +64,9 @@ public final class InitBooklet{
|
|||
ActuallyAdditionsAPI.entryItemsRF = new BookletEntry("itemsRF");
|
||||
ActuallyAdditionsAPI.entryMisc = new BookletEntry("misc");
|
||||
ActuallyAdditionsAPI.entryUpdatesAndInfos = new BookletEntry("updatesAndInfos").setSpecial();
|
||||
ActuallyAdditionsAPI.allAndSearch = new BookletEntryAllItems("allAndSearch").setImportant();
|
||||
}
|
||||
|
||||
public static void init(){
|
||||
public static void postInit(){
|
||||
initChapters();
|
||||
|
||||
int chapCount = 0;
|
||||
|
@ -98,6 +97,31 @@ public final class InitBooklet{
|
|||
}
|
||||
}
|
||||
|
||||
Collections.sort(ActuallyAdditionsAPI.BOOKLET_ENTRIES, new Comparator<IBookletEntry>(){
|
||||
@Override
|
||||
public int compare(IBookletEntry entry1, IBookletEntry entry2){
|
||||
Integer prio1 = entry1.getSortingPriority();
|
||||
Integer prio2 = entry2.getSortingPriority();
|
||||
return prio2.compareTo(prio1);
|
||||
}
|
||||
});
|
||||
Collections.sort(ActuallyAdditionsAPI.ALL_CHAPTERS, new Comparator<IBookletChapter>(){
|
||||
@Override
|
||||
public int compare(IBookletChapter chapter1, IBookletChapter chapter2){
|
||||
Integer prio1 = chapter1.getSortingPriority();
|
||||
Integer prio2 = chapter2.getSortingPriority();
|
||||
return prio2.compareTo(prio1);
|
||||
}
|
||||
});
|
||||
Collections.sort(ActuallyAdditionsAPI.BOOKLET_PAGES_WITH_ITEM_OR_FLUID_DATA, new Comparator<IBookletPage>(){
|
||||
@Override
|
||||
public int compare(IBookletPage page1, IBookletPage page2){
|
||||
Integer prio1 = page1.getSortingPriority();
|
||||
Integer prio2 = page2.getSortingPriority();
|
||||
return prio2.compareTo(prio1);
|
||||
}
|
||||
});
|
||||
|
||||
ModUtil.LOGGER.info("Registered a total of "+chapCount+" booklet chapters, where "+infoCount+" out of "+pageCount+" booklet pages contain information about items or fluids!");
|
||||
}
|
||||
|
||||
|
|
|
@ -24,13 +24,19 @@ public class BookletChapter implements IBookletChapter{
|
|||
public final IBookletEntry entry;
|
||||
public final ItemStack displayStack;
|
||||
private final String identifier;
|
||||
private final int priority;
|
||||
public TextFormatting color;
|
||||
|
||||
public BookletChapter(String identifier, IBookletEntry entry, ItemStack displayStack, IBookletPage... pages){
|
||||
this(identifier, entry, displayStack, 0, pages);
|
||||
}
|
||||
|
||||
public BookletChapter(String identifier, IBookletEntry entry, ItemStack displayStack, int priority, IBookletPage... pages){
|
||||
this.pages = pages;
|
||||
this.identifier = identifier;
|
||||
this.entry = entry;
|
||||
this.displayStack = displayStack;
|
||||
this.priority = priority;
|
||||
this.color = TextFormatting.RESET;
|
||||
|
||||
this.entry.addChapter(this);
|
||||
|
@ -79,6 +85,11 @@ public class BookletChapter implements IBookletChapter{
|
|||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSortingPriority(){
|
||||
return this.priority;
|
||||
}
|
||||
|
||||
public BookletChapter setImportant(){
|
||||
this.color = TextFormatting.DARK_GREEN;
|
||||
return this;
|
||||
|
|
|
@ -31,11 +31,17 @@ import java.util.Locale;
|
|||
public class BookletEntry implements IBookletEntry{
|
||||
|
||||
private final String identifier;
|
||||
private final int priority;
|
||||
private final List<IBookletChapter> chapters = new ArrayList<IBookletChapter>();
|
||||
private TextFormatting color;
|
||||
|
||||
public BookletEntry(String identifier){
|
||||
this(identifier, 0);
|
||||
}
|
||||
|
||||
public BookletEntry(String identifier, int prio){
|
||||
this.identifier = identifier;
|
||||
this.priority = prio;
|
||||
ActuallyAdditionsAPI.addBookletEntry(this);
|
||||
|
||||
this.color = TextFormatting.RESET;
|
||||
|
@ -129,6 +135,11 @@ public class BookletEntry implements IBookletEntry{
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSortingPriority(){
|
||||
return this.priority;
|
||||
}
|
||||
|
||||
public BookletEntry setImportant(){
|
||||
this.color = TextFormatting.DARK_GREEN;
|
||||
return this;
|
||||
|
|
|
@ -18,7 +18,7 @@ import java.util.List;
|
|||
public class BookletEntryAllItems extends BookletEntry{
|
||||
|
||||
public BookletEntryAllItems(String identifier){
|
||||
super(identifier);
|
||||
super(identifier, -Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -32,13 +32,19 @@ public class BookletPage implements IBookletPage{
|
|||
|
||||
protected final HashMap<String, String> textReplacements = new HashMap<String, String>();
|
||||
protected final int localizationKey;
|
||||
private final int priority;
|
||||
private final List<ItemStack> itemsForPage = new ArrayList<ItemStack>();
|
||||
private final List<FluidStack> fluidsForPage = new ArrayList<FluidStack>();
|
||||
protected IBookletChapter chapter;
|
||||
protected boolean hasNoText;
|
||||
|
||||
public BookletPage(int localizationKey){
|
||||
this(localizationKey, 0);
|
||||
}
|
||||
|
||||
public BookletPage(int localizationKey, int priority){
|
||||
this.localizationKey = localizationKey;
|
||||
this.priority = priority;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -174,4 +180,9 @@ public class BookletPage implements IBookletPage{
|
|||
public BookletPage addTextReplacement(String key, int value){
|
||||
return this.addTextReplacement(key, Integer.toString(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSortingPriority(){
|
||||
return this.priority;
|
||||
}
|
||||
}
|
|
@ -37,13 +37,22 @@ public class PageCrafting extends BookletPage{
|
|||
private String recipeTypeLocKey;
|
||||
private boolean isWildcard;
|
||||
|
||||
public PageCrafting(int localizationKey, List<IRecipe> recipes){
|
||||
super(localizationKey);
|
||||
public PageCrafting(int localizationKey, int priority, List<IRecipe> recipes){
|
||||
super(localizationKey, priority);
|
||||
this.recipes = recipes;
|
||||
}
|
||||
|
||||
public PageCrafting(int localizationKey, List<IRecipe> recipes){
|
||||
this(localizationKey, 0, recipes);
|
||||
}
|
||||
|
||||
public PageCrafting(int localizationKey, IRecipe... recipes){
|
||||
this(localizationKey, Arrays.asList(recipes));
|
||||
this(localizationKey, 0, recipes);
|
||||
}
|
||||
|
||||
|
||||
public PageCrafting(int localizationKey, int priority, IRecipe... recipes){
|
||||
this(localizationKey, priority, Arrays.asList(recipes));
|
||||
}
|
||||
|
||||
public BookletPage setWildcard(){
|
||||
|
|
|
@ -62,4 +62,9 @@ public class PageEmpowerer extends BookletPage{
|
|||
list.add(this.recipe.output);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSortingPriority(){
|
||||
return 20;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,11 @@ public class PageFurnace extends BookletPage{
|
|||
private final ItemStack output;
|
||||
|
||||
public PageFurnace(int localizationKey, ItemStack output){
|
||||
super(localizationKey);
|
||||
this(localizationKey, output, 0);
|
||||
}
|
||||
|
||||
public PageFurnace(int localizationKey, ItemStack output, int priority){
|
||||
super(localizationKey, priority);
|
||||
this.output = output;
|
||||
this.input = getInputForOutput(output);
|
||||
}
|
||||
|
|
|
@ -21,6 +21,12 @@ public class PagePicture extends BookletPage{
|
|||
private final ResourceLocation resLoc;
|
||||
private final int yTextOffset;
|
||||
|
||||
public PagePicture(int localizationKey, ResourceLocation resLoc, int yTextOffset, int priority){
|
||||
super(localizationKey, priority);
|
||||
this.resLoc = resLoc;
|
||||
this.yTextOffset = yTextOffset;
|
||||
}
|
||||
|
||||
public PagePicture(int localizationKey, ResourceLocation resLoc, int yTextOffset){
|
||||
super(localizationKey);
|
||||
this.yTextOffset = yTextOffset;
|
||||
|
|
|
@ -57,4 +57,9 @@ public class PageReconstructor extends BookletPage{
|
|||
list.add(this.recipe.outputStack);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSortingPriority(){
|
||||
return 20;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,10 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
|||
|
||||
public class PageTextOnly extends BookletPage{
|
||||
|
||||
public PageTextOnly(int localizationKey, int priority){
|
||||
super(localizationKey, priority);
|
||||
}
|
||||
|
||||
public PageTextOnly(int localizationKey){
|
||||
super(localizationKey);
|
||||
}
|
||||
|
|
|
@ -247,26 +247,51 @@ public class MethodHandler implements IMethodHandler{
|
|||
|
||||
@Override
|
||||
public IBookletPage generateTextPage(int id){
|
||||
return new PageTextOnly(id);
|
||||
return this.generateTextPage(id, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBookletPage generatePicturePage(int id, ResourceLocation resLoc, int textStartY){
|
||||
return new PagePicture(id, resLoc, textStartY);
|
||||
return this.generatePicturePage(id, resLoc, textStartY, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBookletPage generateCraftingPage(int id, IRecipe... recipes){
|
||||
return new PageCrafting(id, recipes);
|
||||
return this.generateCraftingPage(id, 0, recipes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBookletPage generateFurnacePage(int id, ItemStack input, ItemStack result){
|
||||
return new PageFurnace(id, result);
|
||||
return this.generateFurnacePage(id, input, result, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBookletChapter generateBookletChapter(String identifier, IBookletEntry entry, ItemStack displayStack, IBookletPage... pages){
|
||||
return new BookletChapter(identifier, entry, displayStack, pages);
|
||||
return this.generateBookletChapter(identifier, entry, displayStack, 0, pages);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBookletPage generateTextPage(int id, int priority){
|
||||
return new PageTextOnly(id, priority);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBookletPage generatePicturePage(int id, ResourceLocation resLoc, int textStartY, int priority){
|
||||
return new PagePicture(id, resLoc, textStartY, priority);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBookletPage generateCraftingPage(int id, int priority, IRecipe... recipes){
|
||||
return new PageCrafting(id, priority, recipes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBookletPage generateFurnacePage(int id, ItemStack input, ItemStack result, int priority){
|
||||
return new PageFurnace(id, result, priority);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBookletChapter generateBookletChapter(String identifier, IBookletEntry entry, ItemStack displayStack, int priority, IBookletPage... pages){
|
||||
return new BookletChapter(identifier, entry, displayStack, priority, pages);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue