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