|
| 1 | +package com.gml.openeeprom; |
| 2 | + |
| 3 | +import net.minecraft.item.ItemStack; |
| 4 | +import net.minecraftforge.fml.common.Mod; |
| 5 | +import net.minecraftforge.fml.common.SidedProxy; |
| 6 | +import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; |
| 7 | + |
| 8 | +import java.io.File; |
| 9 | +import java.io.FileInputStream; |
| 10 | +import java.io.IOException; |
| 11 | +import java.util.Properties; |
| 12 | + |
| 13 | +@Mod( |
| 14 | + modid = OpenEEPROM.MODID, |
| 15 | + name = "OpenEEPROM", |
| 16 | + version = "1.0-SNAPSHOT", |
| 17 | + dependencies = "after:OpenComputers" |
| 18 | +) |
| 19 | +public class OpenEEPROM { |
| 20 | + |
| 21 | + public static final String MODID = "openeeprom"; |
| 22 | + |
| 23 | + @Mod.Instance(MODID) |
| 24 | + public static OpenEEPROM INSTANCE; |
| 25 | + |
| 26 | + public static Config cfg = null; |
| 27 | + |
| 28 | + @SidedProxy(clientSide = "com.gml.openeeprom.ClientProxy", serverSide = "com.gml.openeeprom.CommonProxy") |
| 29 | + public static CommonProxy proxy; |
| 30 | + |
| 31 | + @Mod.EventHandler |
| 32 | + public void preinit(FMLPreInitializationEvent event) { |
| 33 | + try { |
| 34 | + listFilesForFolder(new File(proxy.getBaseFolder().toString() + "\\mods\\openeeprom\\lua\\")); |
| 35 | + } catch (IOException e) { |
| 36 | + e.printStackTrace(); |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + public void listFilesForFolder(final File folder) throws IOException { |
| 41 | + File[] files = folder.listFiles(); |
| 42 | + if (files != null) { |
| 43 | + for (final File fileEntry : files) { |
| 44 | + if (fileEntry.isDirectory()) { |
| 45 | + if (new File(fileEntry+"/.eeprom.cfg").isFile()) { |
| 46 | + cfg = new Config(fileEntry + "\\.eeprom.cfg"); |
| 47 | + String name = cfg.getString("name", fileEntry.getName()); |
| 48 | + Boolean isReadOnly = cfg.getBool("isReadOnly", "true"); |
| 49 | + if (new File(fileEntry+"/code.lua").isFile()) { |
| 50 | + FileInputStream fl = new FileInputStream(new File(fileEntry+"/code.lua")); |
| 51 | + byte[] code = new byte[(int)new File(fileEntry+"/code.lua").length()]; |
| 52 | + fl.read(code); |
| 53 | + fl.close(); |
| 54 | + ItemStack eeprom = li.cil.oc.api.Items.registerEEPROM(name, code, new byte[255], isReadOnly); |
| 55 | + eeprom.setStackDisplayName(name); |
| 56 | + |
| 57 | + System.out.println("Registering a eeprom with name " + name); |
| 58 | + } |
| 59 | + } else { |
| 60 | + System.out.println("Not an eeprom"); |
| 61 | + } |
| 62 | + } |
| 63 | + } |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + class Config |
| 68 | + { |
| 69 | + Properties configFile; |
| 70 | + public Config(String path) |
| 71 | + { |
| 72 | + configFile = new java.util.Properties(); |
| 73 | + try { |
| 74 | + configFile.load(new FileInputStream(path)); |
| 75 | + }catch(Exception eta){ |
| 76 | + eta.printStackTrace(); |
| 77 | + } |
| 78 | + } |
| 79 | + public String getString(String key, String defultVal) { |
| 80 | + String value = this.configFile.getProperty(key, defultVal); |
| 81 | + return value; |
| 82 | + } |
| 83 | + public Boolean getBool(String key, String defultVal) { |
| 84 | + String value = this.configFile.getProperty(key, defultVal); |
| 85 | + return Boolean.parseBoolean(value); |
| 86 | + } |
| 87 | + } |
| 88 | +} |
0 commit comments