use of slimeknights.mantle.client.screen.book.element.ItemElement in project TinkersConstruct by SlimeKnights.
the class ContentMaterialSkull method addPrimaryDisplayItems.
@Override
protected void addPrimaryDisplayItems(List<ItemElement> displayTools, MaterialVariantId materialId) {
displayTools.add(new TinkerItemElement(TinkerToolParts.repairKit.get().withMaterialForDisplay(materialId)));
super.addPrimaryDisplayItems(displayTools, materialId);
// add skull recipe to display items
IDisplayableCastingRecipe skullRecipe = getSkullRecipe();
if (skullRecipe != null) {
// add repair kit
List<ItemStack> casts = skullRecipe.getCastItems();
if (!casts.isEmpty()) {
ItemElement elementItem = new TinkerItemElement(0, 0, 1, casts);
elementItem.tooltip = ImmutableList.of(new TranslatableComponent(SKULL_FROM, casts.get(0).getHoverName()));
displayTools.add(elementItem);
}
}
}
use of slimeknights.mantle.client.screen.book.element.ItemElement in project TinkersConstruct by SlimeKnights.
the class ContentPageIconList method build.
@Override
public void build(BookData book, ArrayList<BookElement> list, boolean rightSide) {
int yOff = 0;
if (this.title != null) {
this.addTitle(list, this.title, false);
yOff = getTitleHeight();
}
if (this.subText != null) {
int height = this.addText(list, this.subText, false, 0, yOff);
yOff = height + 16;
}
int offset = 15;
int x = offset;
int y = yOff;
int pageW = BookScreen.PAGE_WIDTH - 2 * offset;
int pageH = BookScreen.PAGE_HEIGHT - yOff;
float scale = this.maxScale;
int scaledWidth = this.width;
int scaledHeight = this.height;
boolean fits = false;
while (!fits && scale > 1f) {
scale -= 0.25f;
scaledWidth = (int) (this.width * scale);
scaledHeight = (int) (this.height * scale);
int rows = pageW / scaledWidth;
int cols = pageH / scaledHeight;
fits = rows * cols >= this.elements.size();
}
for (PageIconLinkElement element : this.elements) {
element.x = x;
element.y = y;
element.displayElement.x = x + (int) (scale * (this.width - element.displayElement.width) / 2);
element.displayElement.y = y + (int) (scale * (this.height - element.displayElement.height) / 2);
element.width = scaledWidth;
element.height = scaledHeight;
if (element.displayElement instanceof ItemElement) {
((ItemElement) element.displayElement).scale = scale;
}
list.add(element);
x += scaledWidth;
if (x > BookScreen.PAGE_WIDTH - offset - scaledWidth) {
x = offset;
y += scaledHeight;
// do not draw over the page
if (y > BookScreen.PAGE_HEIGHT - scaledHeight) {
break;
}
}
}
}
use of slimeknights.mantle.client.screen.book.element.ItemElement in project TinkersConstruct by SlimeKnights.
the class AbstractMaterialSectionTransformer method transform.
@Override
public void transform(BookData book, SectionData sectionData) {
sectionData.source = BookRepository.DUMMY;
sectionData.parent = book;
List<IMaterial> materialList = MaterialRegistry.getMaterials().stream().filter(this::isValidMaterial).toList();
if (materialList.isEmpty()) {
return;
}
// calculate pages needed
List<ContentPageIconList> listPages = ContentPageIconList.getPagesNeededForItemCount(materialList.size(), sectionData, book.translate(this.sectionName), book.strings.get(String.format("%s.subtext", this.sectionName)));
ListIterator<ContentPageIconList> iter = listPages.listIterator();
ContentPageIconList overview = iter.next();
for (IMaterial material : materialList) {
MaterialId materialId = material.getIdentifier();
ContentMaterial contentMaterial = this.getPageContent(materialId);
PageData page = this.addPage(sectionData, materialId.toString(), ContentMaterial.ID, contentMaterial);
SizedBookElement icon = new ItemElement(0, 0, 1f, contentMaterial.getDisplayStacks());
while (!overview.addLink(icon, contentMaterial.getTitleComponent(), page)) {
overview = iter.next();
}
}
}
Aggregations