OSDN Git Service

www
[chemicraft/chemicraft.git] / common / pcc / chemicraft / base / ChemiCraftBase.java
1 package pcc.chemicraft.base;
2
3 import net.minecraft.block.Block;
4 import net.minecraft.creativetab.CreativeTabs;
5 import net.minecraft.item.Item;
6 import net.minecraft.item.ItemStack;
7 import net.minecraftforge.common.Configuration;
8 import net.minecraftforge.common.Property;
9 import net.minecraftforge.oredict.OreDictionary;
10 import pcc.chemicraft.ChemiCraft;
11 import pcc.chemicraft.ChemiCraftConfiguration;
12 import pcc.chemicraft.ChemiCraftRegister;
13 import pcc.chemicraft.base.creativetab.CreativeTabAtomOres;
14 import pcc.chemicraft.base.system.CommonProxy;
15 import pcc.chemicraft.base.system.PacketHandler;
16 import pcc.chemicraft.core.ChemiCraftAPI;
17 import cpw.mods.fml.common.Mod;
18 import cpw.mods.fml.common.Mod.Instance;
19 import cpw.mods.fml.common.Mod.PostInit;
20 import cpw.mods.fml.common.Mod.PreInit;
21 import cpw.mods.fml.common.SidedProxy;
22 import cpw.mods.fml.common.event.FMLPostInitializationEvent;
23 import cpw.mods.fml.common.event.FMLPreInitializationEvent;
24 import cpw.mods.fml.common.network.NetworkMod;
25
26 @Mod(modid = "ChemiCraftBase", name = "ChemiCraftBase", version = "beta")
27 @NetworkMod(clientSideRequired = true, serverSideRequired = true, versionBounds = "1.4.6", channels = "chemicraftbase", packetHandler = PacketHandler.class)
28 public class ChemiCraftBase extends ChemiCraft
29 {
30
31         /**
32          * this is ChemiCraft instance.
33          */
34         @Instance("ChemiCraftBase")
35         public static ChemiCraftBase instance;
36
37         /**
38          * proxy of ChemiCraft.
39          */
40         @SidedProxy(clientSide = "pcc.chemicraft.base.client.ClientProxy", serverSide = "pcc.chemicraft.base.system.CommonProxy")
41         public static CommonProxy proxy;
42
43         /**
44          * API Instance.
45          */
46         public ChemiCraftAPI api = ChemiCraftAPI.instance();
47         public ChemiCraftBaseAPI apiBase = ChemiCraftBaseAPI.instance();
48
49         /**
50          * CreativeTab of ChemiCraft.
51          */
52         public static final CreativeTabs creativeTabAtomsOre = new CreativeTabAtomOres("AtomsOre");
53
54         /**
55          * the ItemID.
56          */
57         public int atomGrenadeID;
58         public int blackSmokeID;
59         public int dustID;
60         public int radiationGunID;
61         public int radiationBalletID;
62
63         /**
64          * the BlockID.
65          */
66         public int[] atomOresID = new int[3];
67
68         /**
69          * Variables of Block type.
70          */
71         public Block[] blockAtomOres = new Block[atomOresID.length];
72
73         /**
74          * Variables of Item type.
75          */
76         public Item itemAtomGrenade;
77         public Item itemBlackSmoke;
78         public Item itemDust;
79         public Item itemRadiationGun;
80         public Item itemRadiationBallet;
81
82         /**
83          * the Register Instances.
84          */
85         public ChemiCraftRegister registerCompounds;
86         public ChemiCraftRegister registerCompoundsHandler;
87         public ChemiCraftRegister registerItem;
88         public ChemiCraftRegister registerChemicalRecipe;
89         public ChemiCraftRegister registerBlock;
90         public ChemiCraftRegister registerRecipe;
91         public ChemiCraftRegister registerEntitys;
92
93         public ChemiCraftBase()
94         {
95                 this.registerCompounds = new ChemiCraftRegisterCompounds(this);
96                 this.registerCompoundsHandler = new ChemiCraftRegisterCompoundsHandler(this);
97                 this.registerItem = new ChemiCraftRegisterItem(this);
98                 this.registerChemicalRecipe = new ChemiCraftRegisterChemicalRecipe(this);
99                 this.registerBlock = new ChemiCraftRegisterBlock(this);
100                 this.registerRecipe = new ChemiCraftRegisterBaseRecipe(this);
101                 this.registerEntitys = new ChemiCraftRegisterEntitys(this);
102         }
103
104         @PostInit
105         public void chemiPostLoadMethod(final FMLPostInitializationEvent event) {
106                 this.thread = new Thread(this);
107                 this.event = event;
108                 this.thread.start();
109
110                 try {
111                         this.thread.join();
112                 } catch (InterruptedException e) {
113                         e.printStackTrace();
114                 }
115
116                 proxy.registerRenderInformation();
117                 Thread.yield();
118         }
119
120         @Override
121         public void run()
122         {
123                 while (true) {
124                         if (proxy != null && instance != null) {
125                                 this.settingProcessing((FMLPostInitializationEvent) event);
126                                 this.apiProcessing((FMLPostInitializationEvent) event);
127                                 break;
128                         }
129                 }
130         }
131
132         /**
133          * PreInit:
134          * Configをロードします。
135          * @param event アノテーション呼び出しにより呼び出す必要なし
136          */
137         @PreInit
138         public void chemiPreLoadMethod(final FMLPreInitializationEvent event) {
139                 Configuration cfg = new Configuration(event.getSuggestedConfigurationFile());
140                 cfg.load();
141
142                 Property baseBlockID = cfg.get("BlockID", "Base of Block ID", 2900);
143                 Property baseItemID = cfg.get("ItemID", "Base of Item ID", 25500);
144
145                 ChemiCraftConfiguration ccfgBlock = new ChemiCraftConfiguration(baseBlockID.getInt());
146                 ChemiCraftConfiguration ccfgItem = new ChemiCraftConfiguration(baseBlockID.getInt());
147
148                 for (int i = 0; i < atomOresID.length; i++) {
149                         this.atomOresID[i] = ccfgBlock.additionID();
150                 }
151
152                 this.atomGrenadeID = ccfgItem.additionID();
153                 this.dustID = ccfgItem.additionID();
154                 this.radiationGunID = ccfgItem.additionID();
155                 this.radiationBalletID = ccfgItem.additionID();
156                 this.blackSmokeID = ccfgItem.additionID();
157
158                 cfg.save();
159         }
160
161         protected void settingProcessing(FMLPostInitializationEvent event)
162         {
163                 this.registerCompounds.start();
164                 this.registerCompoundsHandler.start();
165                 this.registerItem.start();
166                 this.registerBlock.start();
167                 this.registerChemicalRecipe.start();
168                 this.registerRecipe.start();
169                 this.registerEntitys.start();
170         }
171
172         private void apiProcessing(final FMLPostInitializationEvent event) {
173                 // API用の処理
174                 for (int i = 0; i < apiBase.getAtomOresName().sizeKeysList(); i++)
175                 {
176                         for (int j = 0; j < apiBase.getAtomOresName().sizeElementsList(apiBase.getAtomOresName().getKeyList(i)); j++)
177                         {
178                                 this.nameAuxiliary.addName(new ItemStack(blockAtomOres[i / 16], 0, i - i / 16 * 16), apiBase.getAtomOresLanguage().get(apiBase.getAtomOresName().getKeyList(i), j), apiBase.getAtomOresName().get(apiBase.getAtomOresName().getKeyList(i), j));
179                                 OreDictionary.registerOre("ore" + apiBase.getAtomOresName().getKeyList(i), new ItemStack(blockAtomOres[i / 16], 1, i - i / 16 * 16));
180                         }
181                 }
182
183         }
184
185 }