OSDN Git Service

エラー大半修正
[chemicraft/chemicraft.git] / common / pcc / addon / crops / ChemicalCrops.java
1 package pcc.addon.crops;
2
3 import java.awt.Canvas;
4 import java.io.IOException;
5
6 import pcc.addon.crops.blocks.BlockChemicalCrops1;
7 import pcc.addon.crops.util.MultiBlockDataStream;
8 import pcc.addon.crops.util.WorldEventHandler;
9
10 import net.minecraft.block.Block;
11 import net.minecraft.block.material.Material;
12 import net.minecraft.client.Minecraft;
13 import net.minecraftforge.common.Configuration;
14 import net.minecraftforge.common.MinecraftForge;
15 import cpw.mods.fml.common.Mod;
16 import cpw.mods.fml.common.Mod.Init;
17 import cpw.mods.fml.common.Mod.Instance;
18 import cpw.mods.fml.common.Mod.PreInit;
19 import cpw.mods.fml.common.SidedProxy;
20 import cpw.mods.fml.common.event.FMLInitializationEvent;
21 import cpw.mods.fml.common.event.FMLPreInitializationEvent;
22 import cpw.mods.fml.common.network.NetworkMod;
23 import cpw.mods.fml.common.registry.GameRegistry;
24
25 @Mod(modid="ChemicalCrops", name="ChemicalCrops(ChemiCraft-Addon)", version="v1.0.0")
26 @NetworkMod(clientSideRequired = true, serverSideRequired = false)
27 public class ChemicalCrops {
28
29         @Instance("ChemicalCrops")
30         public static ChemicalCrops instance;
31
32         @SidedProxy(clientSide = "pcc.addon.crops.ClientProxy", serverSide = "pcc.addon.crops.CommonProxy")
33         public static CommonProxy proxy;
34
35         /**
36          * CropsのBlockID
37          */
38         public int crops1ID;
39
40         /**
41          * ChemicalCropsの変数。<br>
42          * ここに入るインスタンスはBlockChemicalCropsと保証されます。
43          */
44         private Block blockCrops1;
45
46         /**
47          * プラントデータ書き込み&読み込みのストリーム
48          */
49         public static final MultiBlockDataStream dataStream = new MultiBlockDataStream(System.getProperty("user.dir") + "/saves/", "ChemicalCrops.dat");
50
51         /**
52          * Texture Domain.
53          */
54         public static final String TEXTURE = "ChemicalCrops:";
55
56         /**
57          * プラントデータ自動セーブ用のスレッド
58          */
59         private Thread thread;
60
61         public ChemicalCrops() {
62                 this.thread = new Thread() {
63                         @Override
64                         public void run() {
65                                 while (true) {
66                                         try {
67                                                 dataStream.createDataOutputStream();
68                                                 dataStream.write();
69                                         } catch (IOException e1) {
70                                                 e1.printStackTrace();
71                                         }
72                                         try {
73                                                 Thread.sleep(2000);
74                                         } catch (InterruptedException e) {
75                                                 e.printStackTrace();
76                                         }
77                                 }
78                         }
79                 };
80
81         }
82
83         @PreInit
84         public void preInit(FMLPreInitializationEvent event) {
85                 Configuration cfg = new Configuration(event.getSuggestedConfigurationFile());
86                 cfg.load();
87                 this.crops1ID = cfg.getBlock("CropsID", 2700).getInt();
88                 cfg.save();
89         }
90
91         @Init
92         public void init(FMLInitializationEvent event) {
93                 //イベント登録
94                 MinecraftForge.EVENT_BUS.register(new WorldEventHandler());
95
96                 //Blockのインスタンス作成
97                 this.blockCrops1 = new BlockChemicalCrops1(this.crops1ID, Material.glass).setUnlocalizedName("BlockCrops");
98
99                 //Minecraftに登録
100                 GameRegistry.registerBlock(this.blockCrops1, "BlockCrops");
101         }
102
103         /**
104          * プラントデータ自動セーブを開始します。<br>
105          * すでに停止している場合はNullPointerExceptionをスローします。
106          */
107         public void startAutoSave() {
108                 try {
109                         this.thread.start();
110                 } catch (IllegalThreadStateException e) {
111                 }
112         }
113
114         /**
115          * プラントデータ自動セーブを停止します。<br>
116          * 開始していない、もしくはすでに停止している場合はNullPointerExceptionをスローします。
117          */
118         public void stopAutoSave() {
119                 this.thread.stop();
120         }
121
122 }