|
| 1 | +package pl.asie.computronics.oc.manual; |
| 2 | + |
| 3 | +import li.cil.oc.api.Manual; |
| 4 | +import li.cil.oc.api.manual.PathProvider; |
| 5 | +import li.cil.oc.api.manual.TabIconRenderer; |
| 6 | +import li.cil.oc.api.prefab.ItemStackTabIconRenderer; |
| 7 | +import li.cil.oc.api.prefab.ResourceContentProvider; |
| 8 | +import li.cil.oc.api.prefab.TextureTabIconRenderer; |
| 9 | +import net.minecraft.block.Block; |
| 10 | +import net.minecraft.item.ItemStack; |
| 11 | +import net.minecraft.util.ResourceLocation; |
| 12 | +import net.minecraft.world.World; |
| 13 | +import pl.asie.computronics.Computronics; |
| 14 | + |
| 15 | +import java.util.ArrayList; |
| 16 | +import java.util.Collections; |
| 17 | + |
| 18 | +/** |
| 19 | + * @author Vexatos |
| 20 | + */ |
| 21 | +public class ComputronicsPathProvider implements PathProvider { |
| 22 | + |
| 23 | + public static void initialize() { |
| 24 | + Manual.addProvider(new ComputronicsPathProvider()); |
| 25 | + Manual.addProvider(new ResourceContentProvider("computronics", "doc/computronics/")); |
| 26 | + Manual.addTab(findTabIconRenderer(), |
| 27 | + "tooltip.computronics.manual.tab.blocks", "%LANGUAGE%/block/index.md"); |
| 28 | + Manual.addTab(new TextureTabIconRenderer(new ResourceLocation("computronics", "textures/items/tape_greg.png")), |
| 29 | + "tooltip.computronics.manual.tab.items", "%LANGUAGE%/item/index.md"); |
| 30 | + } |
| 31 | + |
| 32 | + private static TabIconRenderer findTabIconRenderer() { |
| 33 | + ArrayList<Block> blocks = new ArrayList<Block>(); |
| 34 | + Collections.addAll(blocks, |
| 35 | + Computronics.tapeReader, |
| 36 | + Computronics.camera, |
| 37 | + Computronics.chatBox, |
| 38 | + Computronics.ironNote, |
| 39 | + Computronics.cipher, |
| 40 | + Computronics.radar, |
| 41 | + Computronics.cipher_advanced, |
| 42 | + Computronics.colorfulLamp); |
| 43 | + |
| 44 | + for(Block block : blocks) { |
| 45 | + if(block != null) { |
| 46 | + return new ItemStackTabIconRenderer(new ItemStack(block)); |
| 47 | + } |
| 48 | + } |
| 49 | + return new TextureTabIconRenderer(new ResourceLocation("computronics", "textures/blocks/tape_drive_front.png")); |
| 50 | + } |
| 51 | + |
| 52 | + @Override |
| 53 | + public String pathFor(ItemStack stack) { |
| 54 | + if(stack == null || stack.getItem() == null) { |
| 55 | + return null; |
| 56 | + } |
| 57 | + if(stack.getItem() instanceof IItemWithDocumentation) { |
| 58 | + return makePath("item", |
| 59 | + stack.getItem() instanceof IItemWithPrefix ? |
| 60 | + ((IItemWithPrefix) stack.getItem()).getPrefix(stack) |
| 61 | + + ((IItemWithDocumentation) stack.getItem()).getDocumentationName(stack) |
| 62 | + : ((IItemWithDocumentation) stack.getItem()).getDocumentationName(stack)); |
| 63 | + } |
| 64 | + return null; |
| 65 | + } |
| 66 | + |
| 67 | + @Override |
| 68 | + public String pathFor(World world, int x, int y, int z) { |
| 69 | + if(world == null) { |
| 70 | + return null; |
| 71 | + } |
| 72 | + Block block = world.getBlock(x, y, z); |
| 73 | + if(block != null && block instanceof IBlockWithDocumentation) { |
| 74 | + return makePath("block", |
| 75 | + block instanceof IBlockWithPrefix ? |
| 76 | + ((IBlockWithPrefix) block).getPrefix(world, x, y, z) |
| 77 | + + ((IBlockWithDocumentation) block).getDocumentationName(world, x, y, z) |
| 78 | + : ((IBlockWithDocumentation) block).getDocumentationName(world, x, y, z)); |
| 79 | + } |
| 80 | + return null; |
| 81 | + } |
| 82 | + |
| 83 | + private String makePath(String type, String documentationName) { |
| 84 | + return "%LANGUAGE%/" + type + "/" + documentationName + ".md"; |
| 85 | + } |
| 86 | +} |
0 commit comments