public ContentTool(ToolCore tool) { this.tool = tool; this.toolName = tool.getIdentifier(); }
@Override public void load() { if(toolName == null) { toolName = parent.name; } if(tool == null) { tool = TinkerRegistry.getTools().stream() .filter(toolCore -> toolName.equals(toolCore.getIdentifier())) .findFirst() .orElseThrow(() -> new RuntimeException("Unknown tool " + toolName)); } if(parts == null) { parts = tool.getToolBuildComponents().stream() .map(PartMaterialType::getPossibleParts) .collect(Collectors.toList()); } }
@Override protected void processPage(BookData book, ContentListing listing, PageData page) { // only add tool pages if the tool exists if(page.content instanceof ContentTool) { String toolName = ((ContentTool) page.content).toolName; Optional<ToolCore> tool = TinkerRegistry.getTools().stream() .filter(toolCore -> toolName.equals(toolCore.getIdentifier())) .findFirst(); tool.ifPresent(toolCore -> listing.addEntry(toolCore.getLocalizedName(), page)); } else { super.processPage(book, listing, page); } } }