OSDN Git Service

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