OSDN Git Service

いろいろした
[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.EnumLoggingType;
16 import pcc.chemicraft.base.creativetab.CreativeTabAtomOres;
17 import pcc.chemicraft.base.gen.WorldGenAtomsOre;
18 import pcc.chemicraft.base.system.CommonProxy;
19 import pcc.chemicraft.base.system.PacketHandler;
20 import pcc.chemicraft.core.ChemiCraftAPI;
21 import pcc.chemicraft.core.ChemiCraftCore;
22 import cpw.mods.fml.common.Loader;
23 import cpw.mods.fml.common.Mod;
24 import cpw.mods.fml.common.ModContainer;
25 import cpw.mods.fml.common.LoaderState.ModState;
26 import cpw.mods.fml.common.Mod.Instance;
27 import cpw.mods.fml.common.Mod.PostInit;
28 import cpw.mods.fml.common.Mod.PreInit;
29 import cpw.mods.fml.common.SidedProxy;
30 import cpw.mods.fml.common.event.FMLInitializationEvent;
31 import cpw.mods.fml.common.event.FMLPostInitializationEvent;
32 import cpw.mods.fml.common.event.FMLPreInitializationEvent;
33 import cpw.mods.fml.common.network.NetworkMod;
34 import cpw.mods.fml.common.registry.GameRegistry;
35
36 @Mod(modid = "ChemiCraftBase", name = "ChemiCraftBase", version = "beta1")
37 @NetworkMod(clientSideRequired = true, serverSideRequired = true, versionBounds = "1.4.7", channels = "chemicraftbase", packetHandler = PacketHandler.class)
38 public class ChemiCraftBase extends ChemiCraft {
39
40         /**
41          * this is ChemiCraft instance.
42          */
43         @Instance("ChemiCraftBase")
44         public static ChemiCraftBase instance;
45
46         /**
47          * proxy of ChemiCraft.
48          */
49         @SidedProxy(clientSide = "pcc.chemicraft.base.client.ClientProxy", serverSide = "pcc.chemicraft.base.system.CommonProxy")
50         public static CommonProxy proxy;
51
52         /**
53          * API Instance.
54          */
55         public ChemiCraftAPI api = ChemiCraftAPI.instance();
56         public ChemiCraftBaseAPI apiBase = ChemiCraftBaseAPI.instance();
57
58         /**
59          * CreativeTab of ChemiCraft.
60          */
61         public static final CreativeTabs creativeTabAtomsOre = new CreativeTabAtomOres("AtomsOre");
62
63         /**
64          * the ItemID.
65          */
66         public int atomGrenadeID;
67         public int blackSmokeID;
68         public int dustID;
69         public int radiationGunID;
70         public int radiationBalletID;
71
72         /**
73          * the BlockID.
74          */
75         public int[] atomOresID = new int[4];
76
77         /**
78          * Variables of Block type.
79          */
80         public Block[] blockAtomOres = new Block[atomOresID.length];
81
82         /**
83          * Variables of Item type.
84          */
85         public Item itemAtomGrenade;
86         public Item itemBlackSmoke;
87         public Item itemDust;
88         public Item itemRadiationGun;
89         public Item itemRadiationBallet;
90
91         /**
92          * the Register Instances.
93          */
94         public ChemiCraftRegister registerCompounds;
95         public ChemiCraftRegister registerCompoundsHandler;
96         public ChemiCraftRegister registerItem;
97         public ChemiCraftRegister registerChemicalRecipe;
98         public ChemiCraftRegister registerBlock;
99         public ChemiCraftRegister registerRecipe;
100         public ChemiCraftRegister registerEntitys;
101
102         public ChemiCraftBase() {
103                 this.registerCompounds = new ChemiCraftRegisterCompounds(this);
104                 this.registerCompoundsHandler = new ChemiCraftRegisterCompoundsHandler(this);
105                 this.registerItem = new ChemiCraftRegisterItem(this);
106                 this.registerChemicalRecipe = new ChemiCraftRegisterChemicalRecipe(this);
107                 this.registerBlock = new ChemiCraftRegisterBlock(this);
108                 this.registerRecipe = new ChemiCraftRegisterBaseRecipe(this);
109                 this.registerEntitys = new ChemiCraftRegisterEntitys(this);
110         }
111
112         @PostInit
113         public void chemiPostLoadMethod(final FMLPostInitializationEvent event) {
114                 this.thread = new Thread(this);
115                 this.event = event;
116                 this.thread.start();
117
118                 try {
119                         this.thread.join();
120                 } catch (InterruptedException e) {
121                         e.printStackTrace();
122                 }
123
124                 proxy.registerRenderInformation();
125                 Thread.yield();
126         }
127
128         @Override
129         public void run() {
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.POSTINITIALIZED) {
146                                                 ChemiCraftCore.logger.write("ChemiCraftBase>APIProcessing", EnumLoggingType.INFO);
147                                                 apiProcessing((FMLPostInitializationEvent) event);
148                                                 break;
149                                         }
150                                 }
151                         }
152                 };
153                 loadCheckThread.start();
154
155         }
156
157         /**
158          * PreInit:<br>
159          * Configをロードします。
160          * @param event アノテーション呼び出しにより呼び出す必要なし
161          */
162         @PreInit
163         public void chemiPreLoadMethod(final FMLPreInitializationEvent event) {
164                 Configuration cfg = new Configuration(event.getSuggestedConfigurationFile());
165                 cfg.load();
166
167                 Property baseBlockID = cfg.get("BlockID", "Base of Block ID", 2500);
168                 Property baseItemID = cfg.get("ItemID", "Base of Item ID", 25500);
169
170                 ChemiCraftConfiguration ccfgBlock = new ChemiCraftConfiguration(baseBlockID.getInt());
171                 ChemiCraftConfiguration ccfgItem = new ChemiCraftConfiguration(baseItemID.getInt());
172
173                 for (int i = 0; i < atomOresID.length; i++) {
174                         this.atomOresID[i] = ccfgBlock.additionID();
175                 }
176
177                 this.atomGrenadeID = ccfgItem.additionID();
178                 this.dustID = ccfgItem.additionID();
179                 this.radiationGunID = ccfgItem.additionID();
180                 this.radiationBalletID = ccfgItem.additionID();
181                 this.blackSmokeID = ccfgItem.additionID();
182
183                 cfg.save();
184         }
185
186         protected void settingProcessing(FMLPostInitializationEvent event) {
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                         for (int j = 0; j < apiBase.getAtomOresName().sizeElementsList(apiBase.getAtomOresName().getKeyList(i)); j++) {
200                                 ChemiCraftCore.logger.write("OreAddName:" + "Name-" + apiBase.getAtomOresName().get(apiBase.getAtomOresName().getKeyList(i), j) +
201                                                 "/Lang-" + apiBase.getAtomOresLanguage().get(apiBase.getAtomOresName().getKeyList(i), j),
202                                                 EnumLoggingType.INFO);
203
204                                 this.nameAuxiliary.addName(
205                                                 new ItemStack(
206                                                                 blockAtomOres[i / 16], 0, i - i / 16 * 16),
207                                                                 apiBase.getAtomOresLanguage().get(apiBase.getAtomOresName().getKeyList(i), j),
208                                                                 apiBase.getAtomOresName().get(apiBase.getAtomOresName().getKeyList(i), j));
209                                 OreDictionary.registerOre("ore" + apiBase.getAtomOresName().getKeyList(i),
210                                                 new ItemStack(blockAtomOres[i / 16], 1, i - i / 16 * 16));
211                                 GameRegistry.registerWorldGenerator(apiBase.getAtomOres().get(i));
212                         }
213                 }
214         }
215
216 }