OSDN Git Service

Merge branch 'master' of https://scm.sourceforge.jp/gitroot/chemicraft/chemicraft
[chemicraft/ChemiCraftNext.git] / common / pcc / chemicraft / util / Auxiliary.java
1 package pcc.chemicraft.util;
2 <<<<<<< HEAD:common/pcc/chemicraft/util/Auxiliary.java
3
4 import java.util.ArrayList;
5 import java.util.Random;
6 =======
7 >>>>>>> a5e4a5c40b9001657f1e36ece533651f63183fbe:common/pcc/chemicraft/util/Auxiliary.java
8
9 import net.minecraft.block.Block;
10 import net.minecraft.item.Item;
11 import net.minecraft.item.ItemStack;
12 import cpw.mods.fml.common.registry.LanguageRegistry;
13
14 public class Auxiliary {
15
16         /**
17          * 補助クラス
18          * @author mozipi
19          *
20          */
21         public static class NameAuxiliary {
22
23                 /**
24                  * 名前を設定します
25                  * @param object
26                  * @param Name
27                  */
28                 public void addName(Object object,Object name){
29                         LanguageRegistry.addName(object, (String) name);
30                 }
31
32
33
34                 /**
35                  * 名前を設定します(ItemStack版)
36                  * @param object
37                  * @param name
38                  * @param meta
39                  */
40                 public void addName(ItemStack itemstack,Object name){
41                         LanguageRegistry.addName(itemstack, (String) name);
42                 }
43
44
45
46                 /**
47                  * 指定言語にそって名前を追加します
48                  * @param object
49                  * @param lang
50                  * @param name
51                  */
52                 public void addName(Object object,String lang,Object name){
53                         LanguageRegistry.instance().addNameForObject(object, lang, (String) name);
54                 }
55
56
57
58                 /**
59                  * 指定言語にそって名前を追加します(ItemStack版)
60                  * @param object
61                  * @param lang
62                  * @param name
63                  */
64                 public void addName(ItemStack object,String lang,Object name){
65                         LanguageRegistry.instance().addNameForObject(object, lang, (String) name);
66                 }
67
68
69
70                 /**
71                  * メタデータごとに名前を追加します(Block版)
72                  * @param object
73                  * @param name
74                  */
75                 public void addName(Block object,Object[] name){
76                         for(int i=0;i<name.length;i++){
77                                 LanguageRegistry.addName(new ItemStack(object,0,i), (String) name[i]);
78                         }
79                 }
80
81
82
83                 /**
84                  * メタデータごとに名前を追加します(Item版)
85                  * @param object
86                  * @param name
87                  */
88                 public void addName(Item object,Object[] name){
89                         for(int i=0;i<name.length;i++){
90                                 LanguageRegistry.addName(new ItemStack(object,0,i), (String) name[i]);
91                         }
92                 }
93
94
95
96                 /**
97                  * 指定された言語にそってメタデータごとに名前を設定します(Block版)
98                  * @param object
99                  * @param name
100                  */
101                 public void addName(Block object,String lang,Object[] name){
102                         for(int i=0;i<name.length;i++){
103                                 LanguageRegistry.instance().addNameForObject(new ItemStack(object,0,i), lang, (String) name[i]);
104                         }
105                 }
106
107
108
109                 /**
110                  * 指定された言語にそってメタデータごとに名前を設定します(Item版)
111                  * @param object
112                  * @param name
113                  */
114                 public void addName(Item object,String lang, Object[] name){
115                         for(int i=0;i<name.length;i++){
116                                 LanguageRegistry.instance().addNameForObject(new ItemStack(object,0,i), lang, (String) name[i]);
117                         }
118                 }
119
120                 /**
121                  * 指定された言語にそってメタデータごとに名前を設定します(Block版)
122                  * また、配列の前に任意の文字列を追加できます。
123                  * @param object
124                  * @param name
125                  */
126                 public void addName(Block object,String lang, String string, Object[] name){
127                         for(int i=0;i<name.length;i++){
128                                 LanguageRegistry.instance().addNameForObject(new ItemStack(object,0,i), lang, string + (String) name[i]);
129                         }
130                 }
131
132
133
134                 /**
135                  * 指定された言語にそってメタデータごとに名前を設定します(Item版)
136                  * また、配列の前に任意の文字列を追加できます。
137                  * @param object
138                  * @param name
139                  */
140                 public void addName(Item object,String lang, String string, Object[] name){
141                         for(int i=0;i<name.length;i++){
142                                 LanguageRegistry.instance().addNameForObject(new ItemStack(object,0,i), lang, string + (String) name[i]);
143                         }
144                 }
145
146                 /**
147                  * 指定された言語にそってメタデータごとに名前を設定します(Block版)
148                  * また、配列の後ろに任意の文字列を追加できます。
149                  * @param object
150                  * @param name
151                  */
152                 public void addName(Block object,String lang, Object[] name, String string){
153                         for(int i=0;i<name.length;i++){
154                                 LanguageRegistry.instance().addNameForObject(new ItemStack(object,0,i), lang, (String) name[i] + string);
155                         }
156                 }
157
158
159
160                 /**
161                  * 指定された言語にそってメタデータごとに名前を設定します(Item版)
162                  * また、配列の後ろに任意の文字列を追加できます。
163                  * @param object
164                  * @param name
165                  */
166                 public void addName(Item object,String lang, Object[] name, String string){
167                         for(int i=0;i<name.length;i++){
168                                 LanguageRegistry.instance().addNameForObject(new ItemStack(object,0,i), lang, (String) name[i] + string);
169                         }
170                 }
171
172         }
173
174         public static class ArrayAuxiliary{
175
176                 public ItemStack[] deleteNull(ItemStack[] array){
177                         int count = 0;
178                         ItemStack[] arrayCopy;
179                         for(int i = 0;i < array.length;i++){
180                                 if(array[array.length - 1 - i] == null){
181                                         count++;
182                                 }else{
183                                         break;
184                                 }
185                         }
186                         arrayCopy = new ItemStack[array.length - count];
187                         for(int i = 0;i < arrayCopy.length;i++){
188                                 arrayCopy[i] = array[i];
189                         }
190                         array = arrayCopy.clone();
191                         return array;
192                 }
193
194         }
195
196         public static class Probability {
197
198                 /**
199                  * Return probability(0,1,2,etc...).
200                  */
201                 public int getProbability(double... par1){
202                         ArrayList<Double> var1 = new ArrayList<Double>();
203                         for (int var2 = 0; var2 < par1.length; var2++) {
204                                 var1.add(par1[var2]);
205                         }
206                         return getProbability(var1);
207                 }
208
209                 public int getProbability(ArrayList<Double> par1){
210                         for (int i = 0; i < par1.size(); i++){
211                                 double var1 = par1.get(i) / 100;
212                                 double var2 = Math.random();
213                                 if (var1 <= var2){
214                                         return i;
215                                 }else{
216                                         continue;
217                                 }
218                         }
219                         return -1;
220                 }
221
222         }
223
224 }