OSDN Git Service

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