Search in sources :

Example 1 with Book

use of com.teamwizardry.librarianlib.features.gui.provided.book.hierarchy.book.Book in project Wizardry by TeamWizardry.

the class ComponentSpellRecipe method components.

public static List<PaginationContext> components(GuiBook book) {
    List<PaginationContext> contexts = Lists.newArrayList();
    if (book.getBookItemStack().isEmpty())
        return contexts;
    ItemStack bookStack = book.getBookItemStack();
    if (!NBTHelper.getBoolean(bookStack, "has_spell", false))
        return contexts;
    NBTTagList moduleList = NBTHelper.getList(bookStack, NBTConstants.NBT.SPELL, net.minecraftforge.common.util.Constants.NBT.TAG_STRING);
    if (moduleList == null)
        return contexts;
    List<List<ModuleInstance>> spellModules = SpellUtils.deserializeModuleList(moduleList);
    List<ItemStack> spellItems = SpellUtils.getSpellItems(spellModules);
    spellModules = SpellUtils.getEssentialModules(spellModules);
    FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
    int widthOfSpace = fr.getStringWidth(" ");
    StringBuilder builder = new StringBuilder(LibrarianLib.PROXY.translate("wizardry.book.spell_recipe_structure") + "\n");
    for (List<ModuleInstance> spellModuleList : spellModules) {
        String margin = null;
        for (ModuleInstance module : spellModuleList) {
            if (margin == null) {
                margin = " - ";
                builder.append(margin).append(module.getReadableName()).append("\n");
            } else {
                int realLength = fr.getStringWidth(margin);
                int nbOfSpace = MathHelper.clamp(realLength / widthOfSpace, 0, 17);
                margin = StringUtils.repeat(" ", nbOfSpace) + "|_ ";
                builder.append(margin).append(module.getReadableName()).append("\n");
                if (nbOfSpace >= 16) {
                    builder.append("   ________________|").append("\n");
                    margin = "   ";
                }
            }
        }
    }
    String[] lines = builder.toString().split("\n");
    StringBuilder pageChunk = new StringBuilder();
    int count = 0;
    for (String line : lines) {
        pageChunk.append(line).append("\n");
        if (++count >= 16) {
            count = 0;
            pageFromString(book, contexts, pageChunk);
            pageChunk = new StringBuilder();
        }
    }
    if (count != 0)
        pageFromString(book, contexts, pageChunk);
    Consumer<ComponentVoid> applier = component -> {
    };
    for (int i = 0; i < spellItems.size(); i++) {
        ItemStack stack = spellItems.get(i);
        int index = i;
        applier = applier.andThen(component -> {
            ComponentStack componentStack = new ComponentStack((index % 4) * 32, (index / 4) * 16);
            componentStack.getStack().setValue(stack);
            component.add(componentStack);
            if (index != spellItems.size() - 1 && (index % 4) < 3) {
                ComponentSprite nextItem = new ComponentSprite(book.getHomeSprite(), 32 + (index % 4) * 32, (index / 4) * 16 + 13, 16, 8);
                nextItem.getColor().setValue(book.getBook().getHighlightColor());
                nextItem.getTransform().setRotate(Math.toRadians(180));
                component.add(nextItem);
            }
        });
        if ((index / 4) >= 9) {
            Consumer<ComponentVoid> spellApplier = applier;
            contexts.add(new PaginationContext(() -> {
                ComponentVoid component = new ComponentVoid(16, 16, book.getMainBookComponent().getSize().getXi() - 32, book.getMainBookComponent().getSize().getYi() - 32);
                spellApplier.accept(component);
                return component;
            }));
            applier = component -> {
            };
        }
    }
    Consumer<ComponentVoid> spellApplier = applier;
    contexts.add(new PaginationContext(() -> {
        ComponentVoid component = new ComponentVoid(16, 16, book.getMainBookComponent().getSize().getXi() - 32, book.getMainBookComponent().getSize().getYi() - 32);
        spellApplier.accept(component);
        return component;
    }));
    return contexts;
}
Also used : ComponentStack(com.teamwizardry.librarianlib.features.gui.components.ComponentStack) IBookGui(com.teamwizardry.librarianlib.features.gui.provided.book.IBookGui) LibrarianLib(com.teamwizardry.librarianlib.core.LibrarianLib) StringUtils(org.apache.commons.lang3.StringUtils) ComponentVoid(com.teamwizardry.librarianlib.features.gui.components.ComponentVoid) ItemStack(net.minecraft.item.ItemStack) NBTTagList(net.minecraft.nbt.NBTTagList) Lists(com.google.common.collect.Lists) Minecraft(net.minecraft.client.Minecraft) SpellUtils(com.teamwizardry.wizardry.api.spell.SpellUtils) ComponentSprite(com.teamwizardry.librarianlib.features.gui.components.ComponentSprite) PaginationContext(com.teamwizardry.librarianlib.features.gui.provided.book.context.PaginationContext) ModuleInstance(com.teamwizardry.wizardry.api.spell.module.ModuleInstance) Consumer(java.util.function.Consumer) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Bookmark(com.teamwizardry.librarianlib.features.gui.provided.book.context.Bookmark) FontRenderer(net.minecraft.client.gui.FontRenderer) Book(com.teamwizardry.librarianlib.features.gui.provided.book.hierarchy.book.Book) IBookElement(com.teamwizardry.librarianlib.features.gui.provided.book.hierarchy.IBookElement) MathHelper(net.minecraft.util.math.MathHelper) NBTHelper(com.teamwizardry.librarianlib.features.helpers.NBTHelper) ComponentText(com.teamwizardry.librarianlib.features.gui.components.ComponentText) NBTConstants(com.teamwizardry.wizardry.api.NBTConstants) NotNull(org.jetbrains.annotations.NotNull) ComponentStack(com.teamwizardry.librarianlib.features.gui.components.ComponentStack) ComponentSprite(com.teamwizardry.librarianlib.features.gui.components.ComponentSprite) PaginationContext(com.teamwizardry.librarianlib.features.gui.provided.book.context.PaginationContext) ComponentVoid(com.teamwizardry.librarianlib.features.gui.components.ComponentVoid) NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagList(net.minecraft.nbt.NBTTagList) List(java.util.List) FontRenderer(net.minecraft.client.gui.FontRenderer) ItemStack(net.minecraft.item.ItemStack) ModuleInstance(com.teamwizardry.wizardry.api.spell.module.ModuleInstance)

Example 2 with Book

use of com.teamwizardry.librarianlib.features.gui.provided.book.hierarchy.book.Book in project Wizardry by TeamWizardry.

the class CommonProxy method preInit.

public void preInit(FMLPreInitializationEvent event) {
    directory = new File(event.getModConfigurationDirectory(), Wizardry.MODID);
    if (!directory.exists())
        if (!directory.mkdirs())
            Wizardry.LOGGER.fatal("    > SOMETHING WENT WRONG! Could not create config folder!!");
    new SpellData.DefaultKeys();
    ManifestUpgrader maniUpgrader = ManifestHandler.INSTANCE.startUpgrade(directory);
    maniUpgrader.changeCategoryName("modules", "wizmodules");
    maniUpgrader.finalizeUpgrade();
    ManifestHandler.INSTANCE.loadNewInternalManifest("wizmodules", "fluid_recipes", "fire_recipes");
    ManifestHandler.INSTANCE.loadExternalManifest(directory);
    ManifestHandler.INSTANCE.processComparisons(directory, "wizmodules", "fluid_recipes", "fire_recipes");
    new ModTab();
    ModBlocks.init();
    ModItems.init();
    ModSounds.init();
    ModPotions.init();
    ModEntities.init();
    ModCapabilities.preInit();
    NetworkRegistry.INSTANCE.registerGuiHandler(Wizardry.instance, new GuiHandler());
    Wizardry.underWorld = DimensionType.register("underworld", "_dim", ConfigValues.underworldID, WorldProviderUnderWorld.class, false);
    // Wizardry.torikki = DimensionType.register("torikki", "_dim", ConfigValues.torikkiID, WorldProviderTorikki.class, false);
    DimensionManager.registerDimension(ConfigValues.underworldID, Wizardry.underWorld);
    // DimensionManager.registerDimension(ConfigValues.torikkiID, Wizardry.torikki);
    MinecraftForge.EVENT_BUS.register(ArenaManager.INSTANCE);
    MinecraftForge.EVENT_BUS.register(new WorldProviderUnderWorld());
    MinecraftForge.EVENT_BUS.register(new EventHandler());
    MinecraftForge.EVENT_BUS.register(new AchievementEvents());
    MinecraftForge.EVENT_BUS.register(new ModuleEffectTimeSlow());
    MinecraftForge.EVENT_BUS.register(new ModuleEffectLeap());
    MinecraftForge.EVENT_BUS.register(ModBiomes.BIOME_UNDERWORLD);
    // MinecraftForge.EVENT_BUS.register(ModBiomes.BIOME_TORIKKI);
    // MinecraftForge.EVENT_BUS.register(ModBiomes.BIOME_TORIKKISEA);
    MinecraftForge.EVENT_BUS.register(this);
    WizardryWorldCapability.init();
    WizardryChunkCapability.init();
    PacketHandler.register(PacketSendSpellToBook.class, Side.SERVER);
    PacketHandler.register(PacketRenderSpell.class, Side.CLIENT);
    PacketHandler.register(PacketExplode.class, Side.CLIENT);
    PacketHandler.register(PacketFreezePlayer.class, Side.CLIENT);
    PacketHandler.register(PacketRenderLightningBolt.class, Side.CLIENT);
    PacketHandler.register(PacketSyncCooldown.class, Side.CLIENT);
    PacketHandler.register(PacketDevilDustFizzle.class, Side.CLIENT);
    PageTypes.INSTANCE.registerPageProvider("wizardry_structure", PageWizardryStructure::new);
    ItemBook.BOOK = new Book("book");
    Wizardry.LOGGER.info("Initializing fairy task plugins...");
    for (final WizardryPlugin plugin : ServiceLoader.load(WizardryPlugin.class)) {
        Wizardry.LOGGER.info("Initializing plugin {}", plugin.getClass().getName());
        plugin.onInit(context);
    }
    Wizardry.LOGGER.info("Initialization complete!");
}
Also used : ManifestUpgrader(com.teamwizardry.wizardry.common.core.version.manifest.ManifestUpgrader) ModuleEffectLeap(com.teamwizardry.wizardry.common.module.effects.ModuleEffectLeap) WizardryPlugin(com.teamwizardry.wizardry.api.plugin.WizardryPlugin) EventHandler(com.teamwizardry.wizardry.common.core.EventHandler) GuiHandler(com.teamwizardry.wizardry.client.gui.GuiHandler) WorldProviderUnderWorld(com.teamwizardry.wizardry.common.world.underworld.WorldProviderUnderWorld) PageWizardryStructure(com.teamwizardry.wizardry.client.gui.book.PageWizardryStructure) AchievementEvents(com.teamwizardry.wizardry.common.advancement.AchievementEvents) ItemBook(com.teamwizardry.wizardry.common.item.ItemBook) Book(com.teamwizardry.librarianlib.features.gui.provided.book.hierarchy.book.Book) File(java.io.File) ModuleEffectTimeSlow(com.teamwizardry.wizardry.common.module.effects.ModuleEffectTimeSlow)

Aggregations

Book (com.teamwizardry.librarianlib.features.gui.provided.book.hierarchy.book.Book)2 Lists (com.google.common.collect.Lists)1 LibrarianLib (com.teamwizardry.librarianlib.core.LibrarianLib)1 ComponentSprite (com.teamwizardry.librarianlib.features.gui.components.ComponentSprite)1 ComponentStack (com.teamwizardry.librarianlib.features.gui.components.ComponentStack)1 ComponentText (com.teamwizardry.librarianlib.features.gui.components.ComponentText)1 ComponentVoid (com.teamwizardry.librarianlib.features.gui.components.ComponentVoid)1 IBookGui (com.teamwizardry.librarianlib.features.gui.provided.book.IBookGui)1 Bookmark (com.teamwizardry.librarianlib.features.gui.provided.book.context.Bookmark)1 PaginationContext (com.teamwizardry.librarianlib.features.gui.provided.book.context.PaginationContext)1 IBookElement (com.teamwizardry.librarianlib.features.gui.provided.book.hierarchy.IBookElement)1 NBTHelper (com.teamwizardry.librarianlib.features.helpers.NBTHelper)1 NBTConstants (com.teamwizardry.wizardry.api.NBTConstants)1 WizardryPlugin (com.teamwizardry.wizardry.api.plugin.WizardryPlugin)1 SpellUtils (com.teamwizardry.wizardry.api.spell.SpellUtils)1 ModuleInstance (com.teamwizardry.wizardry.api.spell.module.ModuleInstance)1 GuiHandler (com.teamwizardry.wizardry.client.gui.GuiHandler)1 PageWizardryStructure (com.teamwizardry.wizardry.client.gui.book.PageWizardryStructure)1 AchievementEvents (com.teamwizardry.wizardry.common.advancement.AchievementEvents)1 EventHandler (com.teamwizardry.wizardry.common.core.EventHandler)1