use of com.teamwizardry.librarianlib.features.gui.components.ComponentStack 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;
}
Aggregations