Made word count reload when reloadoing resources

This commit is contained in:
Ellpeck 2016-01-16 23:14:10 +01:00
parent 3397632e87
commit 720f80160b
3 changed files with 45 additions and 27 deletions

View file

@ -19,6 +19,7 @@ import de.ellpeck.actuallyadditions.mod.booklet.button.BookmarkButton;
import de.ellpeck.actuallyadditions.mod.booklet.button.IndexButton; import de.ellpeck.actuallyadditions.mod.booklet.button.IndexButton;
import de.ellpeck.actuallyadditions.mod.booklet.button.TexturedButton; import de.ellpeck.actuallyadditions.mod.booklet.button.TexturedButton;
import de.ellpeck.actuallyadditions.mod.booklet.entry.BookletEntryAllSearch; import de.ellpeck.actuallyadditions.mod.booklet.entry.BookletEntryAllSearch;
import de.ellpeck.actuallyadditions.mod.proxy.ClientProxy;
import de.ellpeck.actuallyadditions.mod.util.*; import de.ellpeck.actuallyadditions.mod.util.*;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiButton;
@ -169,10 +170,10 @@ public class BookletUtils{
} }
//Renders the amount of words and chars the book has //Renders the amount of words and chars the book has
else{ else{
String wordCountString = StringUtil.localizeFormatted("booklet."+ModUtil.MOD_ID_LOWER+".amountOfWords", InitBooklet.wordCount); String wordCountString = StringUtil.localizeFormatted("booklet."+ModUtil.MOD_ID_LOWER+".amountOfWords", ClientProxy.bookletWordCount);
booklet.getFontRenderer().drawString(EnumChatFormatting.ITALIC+wordCountString, booklet.guiLeft+booklet.xSize-booklet.getFontRenderer().getStringWidth(wordCountString)-15, booklet.guiTop+booklet.ySize-18-booklet.getFontRenderer().FONT_HEIGHT, 0); booklet.getFontRenderer().drawString(EnumChatFormatting.ITALIC+wordCountString, booklet.guiLeft+booklet.xSize-booklet.getFontRenderer().getStringWidth(wordCountString)-15, booklet.guiTop+booklet.ySize-18-booklet.getFontRenderer().FONT_HEIGHT, 0);
String charCountString = StringUtil.localizeFormatted("booklet."+ModUtil.MOD_ID_LOWER+".amountOfChars", InitBooklet.charCount); String charCountString = StringUtil.localizeFormatted("booklet."+ModUtil.MOD_ID_LOWER+".amountOfChars", ClientProxy.bookletCharCount);
booklet.getFontRenderer().drawString(EnumChatFormatting.ITALIC+charCountString, booklet.guiLeft+booklet.xSize-booklet.getFontRenderer().getStringWidth(charCountString)-15, booklet.guiTop+booklet.ySize-18, 0); booklet.getFontRenderer().drawString(EnumChatFormatting.ITALIC+charCountString, booklet.guiLeft+booklet.xSize-booklet.getFontRenderer().getStringWidth(charCountString)-15, booklet.guiTop+booklet.ySize-18, 0);
} }
} }

View file

@ -12,8 +12,6 @@ package de.ellpeck.actuallyadditions.mod.booklet;
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
import de.ellpeck.actuallyadditions.api.booklet.BookletPage; import de.ellpeck.actuallyadditions.api.booklet.BookletPage;
import de.ellpeck.actuallyadditions.api.booklet.IBookletChapter;
import de.ellpeck.actuallyadditions.api.booklet.IBookletEntry;
import de.ellpeck.actuallyadditions.mod.blocks.InitBlocks; import de.ellpeck.actuallyadditions.mod.blocks.InitBlocks;
import de.ellpeck.actuallyadditions.mod.blocks.metalists.TheColoredLampColors; import de.ellpeck.actuallyadditions.mod.blocks.metalists.TheColoredLampColors;
import de.ellpeck.actuallyadditions.mod.blocks.metalists.TheMiscBlocks; import de.ellpeck.actuallyadditions.mod.blocks.metalists.TheMiscBlocks;
@ -40,9 +38,6 @@ import java.util.ArrayList;
public class InitBooklet{ public class InitBooklet{
public static int wordCount;
public static int charCount;
public static BookletChapter chapterIntro; public static BookletChapter chapterIntro;
public static void preInit(){ public static void preInit(){
@ -58,7 +53,6 @@ public class InitBooklet{
public static void postInit(){ public static void postInit(){
initChapters(); initChapters();
countWords();
} }
private static void initChapters(){ private static void initChapters(){
@ -148,21 +142,4 @@ public class InitBooklet{
new BookletChapter("waterRemovalRing", ActuallyAdditionsAPI.entryItemsRF, new ItemStack(InitItems.itemWaterRemovalRing), new PageCrafting(1, ItemCrafting.recipeWaterRing)); new BookletChapter("waterRemovalRing", ActuallyAdditionsAPI.entryItemsRF, new ItemStack(InitItems.itemWaterRemovalRing), new PageCrafting(1, ItemCrafting.recipeWaterRing));
new BookletChapter("batteries", ActuallyAdditionsAPI.entryItemsRF, new ItemStack(InitItems.itemBatteryTriple), new PageTextOnly(1), new PageCrafting(2, ItemCrafting.recipeBattery).setNoText(), new PageCrafting(3, ItemCrafting.recipeBatteryDouble).setNoText(), new PageCrafting(4, ItemCrafting.recipeBatteryTriple).setNoText(), new PageCrafting(5, ItemCrafting.recipeBatteryQuadruple).setNoText(), new PageCrafting(6, ItemCrafting.recipeBatteryQuintuple).setNoText()); new BookletChapter("batteries", ActuallyAdditionsAPI.entryItemsRF, new ItemStack(InitItems.itemBatteryTriple), new PageTextOnly(1), new PageCrafting(2, ItemCrafting.recipeBattery).setNoText(), new PageCrafting(3, ItemCrafting.recipeBatteryDouble).setNoText(), new PageCrafting(4, ItemCrafting.recipeBatteryTriple).setNoText(), new PageCrafting(5, ItemCrafting.recipeBatteryQuadruple).setNoText(), new PageCrafting(6, ItemCrafting.recipeBatteryQuintuple).setNoText());
} }
private static void countWords(){
for(IBookletEntry entry : ActuallyAdditionsAPI.bookletEntries){
for(IBookletChapter chapter : entry.getChapters()){
for(BookletPage page : chapter.getPages()){
if(page.getText() != null){
wordCount += page.getText().split(" ").length;
charCount += page.getText().length();
}
}
wordCount += chapter.getLocalizedName().split(" ").length;
charCount += chapter.getLocalizedName().length();
}
wordCount += entry.getLocalizedName().split(" ").length;
charCount += entry.getLocalizedName().length();
}
}
} }

View file

@ -11,6 +11,10 @@
package de.ellpeck.actuallyadditions.mod.proxy; package de.ellpeck.actuallyadditions.mod.proxy;
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
import de.ellpeck.actuallyadditions.api.booklet.BookletPage;
import de.ellpeck.actuallyadditions.api.booklet.IBookletChapter;
import de.ellpeck.actuallyadditions.api.booklet.IBookletEntry;
import de.ellpeck.actuallyadditions.mod.blocks.InitBlocks; import de.ellpeck.actuallyadditions.mod.blocks.InitBlocks;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues; import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
import de.ellpeck.actuallyadditions.mod.event.InitEvents; import de.ellpeck.actuallyadditions.mod.event.InitEvents;
@ -20,6 +24,9 @@ import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import de.ellpeck.actuallyadditions.mod.util.playerdata.PersistentClientData; import de.ellpeck.actuallyadditions.mod.util.playerdata.PersistentClientData;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.IReloadableResourceManager;
import net.minecraft.client.resources.IResourceManager;
import net.minecraft.client.resources.IResourceManagerReloadListener;
import net.minecraft.client.resources.model.ModelBakery; import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.client.resources.model.ModelResourceLocation; import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.item.Item; import net.minecraft.item.Item;
@ -36,7 +43,6 @@ import java.util.Calendar;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@SuppressWarnings("unused")
public class ClientProxy implements IProxy{ public class ClientProxy implements IProxy{
private static Map<ItemStack, ResourceLocation> modelLocationsForRegistering = new HashMap<ItemStack, ResourceLocation>(); private static Map<ItemStack, ResourceLocation> modelLocationsForRegistering = new HashMap<ItemStack, ResourceLocation>();
@ -46,6 +52,9 @@ public class ClientProxy implements IProxy{
public static boolean jingleAllTheWay; public static boolean jingleAllTheWay;
public static boolean bulletForMyValentine; public static boolean bulletForMyValentine;
public static int bookletWordCount;
public static int bookletCharCount;
@Override @Override
public void preInit(FMLPreInitializationEvent event){ public void preInit(FMLPreInitializationEvent event){
ModUtil.LOGGER.info("PreInitializing ClientProxy..."); ModUtil.LOGGER.info("PreInitializing ClientProxy...");
@ -65,9 +74,18 @@ public class ClientProxy implements IProxy{
for(Map.Entry<Item, ResourceLocation[]> entry : modelVariantsForRegistering.entrySet()){ for(Map.Entry<Item, ResourceLocation[]> entry : modelVariantsForRegistering.entrySet()){
ModelBakery.registerItemVariants(entry.getKey(), entry.getValue()); ModelBakery.registerItemVariants(entry.getKey(), entry.getValue());
} }
this.registerCustomFluidBlockRenderer(InitBlocks.fluidCanolaOil); this.registerCustomFluidBlockRenderer(InitBlocks.fluidCanolaOil);
this.registerCustomFluidBlockRenderer(InitBlocks.fluidOil); this.registerCustomFluidBlockRenderer(InitBlocks.fluidOil);
IResourceManager manager = Minecraft.getMinecraft().getResourceManager();
if(manager instanceof IReloadableResourceManager){
((IReloadableResourceManager)manager).registerReloadListener(new IResourceManagerReloadListener(){
@Override
public void onResourceManagerReload(IResourceManager resourceManager){
countBookletWords();
}
});
}
} }
/** /**
@ -112,6 +130,8 @@ public class ClientProxy implements IProxy{
ModUtil.LOGGER.info("PostInitializing ClientProxy..."); ModUtil.LOGGER.info("PostInitializing ClientProxy...");
SpecialRenderInit.init(); SpecialRenderInit.init();
countBookletWords();
} }
@Override @Override
@ -123,4 +143,24 @@ public class ClientProxy implements IProxy{
public void addRenderVariant(Item item, ResourceLocation... location){ public void addRenderVariant(Item item, ResourceLocation... location){
modelVariantsForRegistering.put(item, location); modelVariantsForRegistering.put(item, location);
} }
private static void countBookletWords(){
bookletWordCount = 0;
bookletCharCount = 0;
for(IBookletEntry entry : ActuallyAdditionsAPI.bookletEntries){
for(IBookletChapter chapter : entry.getChapters()){
for(BookletPage page : chapter.getPages()){
if(page.getText() != null){
bookletWordCount += page.getText().split(" ").length;
bookletCharCount += page.getText().length();
}
}
bookletWordCount += chapter.getLocalizedName().split(" ").length;
bookletCharCount += chapter.getLocalizedName().length();
}
bookletWordCount += entry.getLocalizedName().split(" ").length;
bookletCharCount += entry.getLocalizedName().length();
}
}
} }