From 16d9b95b5acf24f6971aad486515336f1963ed54 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Thu, 26 May 2016 22:49:47 +0200 Subject: [PATCH] Added a config option to print all of the booklet text to file on startup. For debug purposes. And because it's cool. --- .../mod/config/values/ConfigBoolValues.java | 4 +- .../mod/proxy/ClientProxy.java | 47 ++++++++++++++----- 2 files changed, 38 insertions(+), 13 deletions(-) diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigBoolValues.java b/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigBoolValues.java index 330b6d57a..926dddedc 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigBoolValues.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigBoolValues.java @@ -47,7 +47,9 @@ public enum ConfigBoolValues{ ENABLE_SEASONAL("Seasonal Mode", ConfigCategories.OTHER, true, "If Seasonal Mode is enabled"), DUNGEON_LOOT("Dungeon Loot", ConfigCategories.OTHER, true, "Should Actually Additions Loot spawn in Dungeons"), - GEN_LUSH_CAVES("Generate Lush Caves", ConfigCategories.WORLD_GEN, true, "Should caves with trees and grass randomly generate underground"); + GEN_LUSH_CAVES("Generate Lush Caves", ConfigCategories.WORLD_GEN, true, "Should caves with trees and grass randomly generate underground"), + + BOOKLET_TEXT_TO_FILE("Booklet Text to File", ConfigCategories.OTHER, false, "Should the entire text of the booklet be put into a new file in the Minecraft Folder on startup or resource reload. This is for debug purposes only and shouldn't really ever be needed."); public final String name; public final String category; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/proxy/ClientProxy.java b/src/main/java/de/ellpeck/actuallyadditions/mod/proxy/ClientProxy.java index c344aa0d6..8bb958612 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/proxy/ClientProxy.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/proxy/ClientProxy.java @@ -45,7 +45,9 @@ import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import javax.annotation.Nonnull; +import java.io.BufferedWriter; import java.io.File; +import java.io.FileWriter; import java.util.*; public class ClientProxy implements IProxy{ @@ -56,26 +58,49 @@ public class ClientProxy implements IProxy{ public static int bookletWordCount; public static int bookletCharCount; - private static final List colorProdividingItemsForRegistering = new ArrayList(); - private static final Map modelLocationsForRegistering = new HashMap(); + private static final List COLOR_PRODIVIDING_ITEMS_FOR_REGISTERING = new ArrayList(); + private static final Map MODEL_LOCATIONS_FOR_REGISTERING = new HashMap(); private static void countBookletWords(){ bookletWordCount = 0; bookletCharCount = 0; + String bookletText = ""; for(IBookletEntry entry : ActuallyAdditionsAPI.BOOKLET_ENTRIES){ + bookletWordCount += entry.getLocalizedName().split(" ").length; + bookletCharCount += entry.getLocalizedName().length(); + bookletText+=entry.getLocalizedName()+"\n\n"; + for(IBookletChapter chapter : entry.getChapters()){ + bookletWordCount += chapter.getLocalizedName().split(" ").length; + bookletCharCount += chapter.getLocalizedName().length(); + bookletText+=chapter.getLocalizedName()+"\n"; + for(BookletPage page : chapter.getPages()){ if(page.getText() != null){ bookletWordCount += page.getText().split(" ").length; bookletCharCount += page.getText().length(); + bookletText +=page.getText()+"\n"; } } - bookletWordCount += chapter.getLocalizedName().split(" ").length; - bookletCharCount += chapter.getLocalizedName().length(); + bookletText+="\n"; + + } + bookletText+="\n"; + } + + if(ConfigBoolValues.BOOKLET_TEXT_TO_FILE.isEnabled()){ + File file = new File(Minecraft.getMinecraft().mcDataDir, ModUtil.MOD_ID+"booklettext.txt"); + try{ + file.createNewFile(); + BufferedWriter writer = new BufferedWriter(new FileWriter(file)); + writer.write(bookletText); + writer.close(); + ModUtil.LOGGER.info("Wrote booklet text to file!"); + } + catch(Exception e){ + ModUtil.LOGGER.error("Couldn't write booklet text to file!", e); } - bookletWordCount += entry.getLocalizedName().split(" ").length; - bookletCharCount += entry.getLocalizedName().length(); } } @@ -95,7 +120,7 @@ public class ClientProxy implements IProxy{ PersistentClientData.setTheFile(new File(Minecraft.getMinecraft().mcDataDir, ModUtil.MOD_ID+"data.dat")); - for(Map.Entry entry : modelLocationsForRegistering.entrySet()){ + for(Map.Entry entry : MODEL_LOCATIONS_FOR_REGISTERING.entrySet()){ ModelLoader.setCustomModelResourceLocation(entry.getKey().getItem(), entry.getKey().getItemDamage(), entry.getValue()); } @@ -138,7 +163,7 @@ public class ClientProxy implements IProxy{ //VillagerRegistry.instance().registerVillagerSkin(ConfigIntValues.JAM_VILLAGER_ID.getValue(), new ResourceLocation(ModUtil.MOD_ID, "textures/entity/villager/jamVillager.png")); - for(Item item : colorProdividingItemsForRegistering){ + for(Item item : COLOR_PRODIVIDING_ITEMS_FOR_REGISTERING){ if(item instanceof IColorProvidingItem){ Minecraft.getMinecraft().getItemColors().registerItemColorHandler(((IColorProvidingItem)item).getColor(), item); } @@ -150,17 +175,15 @@ public class ClientProxy implements IProxy{ ModUtil.LOGGER.info("PostInitializing ClientProxy..."); SpecialRenderInit.init(); - - countBookletWords(); } @Override public void addRenderRegister(ItemStack stack, ModelResourceLocation location){ - modelLocationsForRegistering.put(stack, location); + MODEL_LOCATIONS_FOR_REGISTERING.put(stack, location); } @Override public void addColoredItem(Item item){ - colorProdividingItemsForRegistering.add(item); + COLOR_PRODIVIDING_ITEMS_FOR_REGISTERING.add(item); } }