Posted 21 July 2014 - 06:12 PM
Hello, Today I will show you how to make your own IMount, that mounts when you attach a peripheral
Needed before tutorial:
com.tattyseal.dlua.DownloadFiles
A Peripheral
A webhost with a ZIP File with LUA files inside, for an example see this
To start off, you want to make a new file and call it whatever you want, implement IMount and implement all the needed methods, you want it to look like this
In your Peripherals attach method you want to add
In your Peripherals detach method you want to add
Run minecraft and in the /mods folder you should see a folder called tutorial with a lua.zip and lua folder, if not check the location of the ZIP file.
If it errors, reply to the thread with your code and the crash error, if there was one!
Place down a computer and turn it on, place your peripheral next to it, and it type ls, it should have a rom folder, and a tutorial folder
If this helped, reply to the thread and link it if you relase a mod using this method! And you can include the DownloadFiles.java in your mod, its ok :)/>
Needed before tutorial:
com.tattyseal.dlua.DownloadFiles
A Peripheral
A webhost with a ZIP File with LUA files inside, for an example see this
To start off, you want to make a new file and call it whatever you want, implement IMount and implement all the needed methods, you want it to look like this
package com.tattyseal.tutorial;
import dan200.computercraft.api.filesystem.IMount;import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
/**
* * @package com.tattyseal.pp.cc
* * @author tattyseal
* *
*/
public class TutorialMount implements IMount
{
public InputStream stream;
public TutorialMount()
{
try
{
stream = new FileInputStream("./mods/tutorial/lua");
}
catch(Exception e)
{
e.printStackTrace();
}
}
@Override
public boolean exists(String path) throws IOException
{
return new File("./mods/tutorial/lua/" + path).exists();
}
@Override
public boolean isDirectory(String path) throws IOException
{
return new File("./mods/tutorial/lua/" + path).isDirectory();
}
@Override
public void list(String path, List<String> contents) throws IOException
{
File file = new File("./mods/tutorial/lua");
for(File f : file.listFiles())
{
contents.add(f.getName());
}
}
@Override
public long getSize(String path) throws IOException
{
return new File("./mods/tutorial/lua/" + path).getTotalSpace();
}
@Override
public InputStream openForRead(String path) throws IOException
{
return new FileInputStream(new File("./mods/tutorial/lua/" + path));
}
}
In your Peripherals attach method you want to add
computerAccess.mount("/tutorial", new TutorialMount());
In your Peripherals detach method you want to add
computerAccess.unmount("/tutorial");
Run minecraft and in the /mods folder you should see a folder called tutorial with a lua.zip and lua folder, if not check the location of the ZIP file.
If it errors, reply to the thread with your code and the crash error, if there was one!
Place down a computer and turn it on, place your peripheral next to it, and it type ls, it should have a rom folder, and a tutorial folder
If this helped, reply to the thread and link it if you relase a mod using this method! And you can include the DownloadFiles.java in your mod, its ok :)/>
Edited on 21 July 2014 - 04:21 PM