OSDN Git Service

I with OWATA
[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.entity.Entity;
7 import net.minecraft.item.Item;
8 import net.minecraft.item.ItemStack;
9 import net.minecraft.world.World;
10 import cpw.mods.fml.common.registry.LanguageRegistry;
11
12 public class Auxiliary {
13
14         /**
15          * 補助クラス
16          * @author mozipi
17          *
18          */
19         public static class NameAuxiliary {
20
21                 /**
22                  * 名前を設定します
23                  * @param object
24                  * @param Name
25                  */
26                 public void addName(Object object,Object name){
27                         LanguageRegistry.addName(object, (String) name);
28                 }
29
30
31
32                 /**
33                  * 名前を設定します(ItemStack版)
34                  * @param object
35                  * @param name
36                  * @param meta
37                  */
38                 public void addName(ItemStack itemstack,Object name){
39                         LanguageRegistry.addName(itemstack, (String) name);
40                 }
41
42
43
44                 /**
45                  * 指定言語にそって名前を追加します
46                  * @param object
47                  * @param lang
48                  * @param name
49                  */
50                 public void addName(Object object,String lang,Object name){
51                         LanguageRegistry.instance().addNameForObject(object, lang, (String) name);
52                 }
53
54
55
56                 /**
57                  * 指定言語にそって名前を追加します(ItemStack版)
58                  * @param object
59                  * @param lang
60                  * @param name
61                  */
62                 public void addName(ItemStack object,String lang,Object name){
63                         LanguageRegistry.instance().addNameForObject(object, lang, (String) name);
64                 }
65
66
67
68                 /**
69                  * メタデータごとに名前を追加します(Block版)
70                  * @param object
71                  * @param name
72                  */
73                 public void addName(Block object,Object[] name){
74                         for(int i=0;i<name.length;i++){
75                                 LanguageRegistry.addName(new ItemStack(object,0,i), (String) name[i]);
76                         }
77                 }
78
79
80
81                 /**
82                  * メタデータごとに名前を追加します(Item版)
83                  * @param object
84                  * @param name
85                  */
86                 public void addName(Item object,Object[] name){
87                         for(int i=0;i<name.length;i++){
88                                 LanguageRegistry.addName(new ItemStack(object,0,i), (String) name[i]);
89                         }
90                 }
91
92
93
94                 /**
95                  * 指定された言語にそってメタデータごとに名前を設定します(Block版)
96                  * @param object
97                  * @param name
98                  */
99                 public void addName(Block object,String lang,Object[] name){
100                         for(int i=0;i<name.length;i++){
101                                 LanguageRegistry.instance().addNameForObject(new ItemStack(object,0,i), lang, (String) name[i]);
102                         }
103                 }
104
105
106
107                 /**
108                  * 指定された言語にそってメタデータごとに名前を設定します(Item版)
109                  * @param object
110                  * @param name
111                  */
112                 public void addName(Item object,String lang, Object[] name){
113                         for(int i=0;i<name.length;i++){
114                                 LanguageRegistry.instance().addNameForObject(new ItemStack(object,0,i), lang, (String) name[i]);
115                         }
116                 }
117
118                 /**
119                  * 指定された言語にそってメタデータごとに名前を設定します(Block版)
120                  * また、配列の前に任意の文字列を追加できます。
121                  * @param object
122                  * @param name
123                  */
124                 public void addName(Block object,String lang, String string, Object[] name){
125                         for(int i=0;i<name.length;i++){
126                                 LanguageRegistry.instance().addNameForObject(new ItemStack(object,0,i), lang, string + (String) name[i]);
127                         }
128                 }
129
130
131
132                 /**
133                  * 指定された言語にそってメタデータごとに名前を設定します(Item版)
134                  * また、配列の前に任意の文字列を追加できます。
135                  * @param object
136                  * @param name
137                  */
138                 public void addName(Item object,String lang, String string, Object[] name){
139                         for(int i=0;i<name.length;i++){
140                                 LanguageRegistry.instance().addNameForObject(new ItemStack(object,0,i), lang, string + (String) name[i]);
141                         }
142                 }
143
144                 /**
145                  * 指定された言語にそってメタデータごとに名前を設定します(Block版)
146                  * また、配列の後ろに任意の文字列を追加できます。
147                  * @param object
148                  * @param name
149                  */
150                 public void addName(Block object,String lang, Object[] name, String string){
151                         for(int i=0;i<name.length;i++){
152                                 LanguageRegistry.instance().addNameForObject(new ItemStack(object,0,i), lang, (String) name[i] + string);
153                         }
154                 }
155
156
157
158                 /**
159                  * 指定された言語にそってメタデータごとに名前を設定します(Item版)
160                  * また、配列の後ろに任意の文字列を追加できます。
161                  * @param object
162                  * @param name
163                  */
164                 public void addName(Item object,String lang, Object[] name, String string){
165                         for(int i=0;i<name.length;i++){
166                                 LanguageRegistry.instance().addNameForObject(new ItemStack(object,0,i), lang, (String) name[i] + string);
167                         }
168                 }
169
170         }
171
172         public static class ArrayAuxiliary{
173
174                 public static ItemStack[] deleteNull(ItemStack[] array){
175                         int count = 0;
176                         ItemStack[] arrayCopy;
177                         for(int i = 0;i < array.length;i++){
178                                 if(array[array.length - 1 - i] == null){
179                                         count++;
180                                 }else{
181                                         break;
182                                 }
183                         }
184                         arrayCopy = new ItemStack[array.length - count];
185                         for(int i = 0;i < arrayCopy.length;i++){
186                                 arrayCopy[i] = array[i];
187                         }
188                         array = arrayCopy.clone();
189                         return array;
190                 }
191
192         }
193
194         public static class Probability {
195
196                 /**
197                  * Return probability(0,1,2,etc...).
198                  */
199                 public int getProbability(double... par1){
200                         ArrayList<Double> var1 = new ArrayList<Double>();
201                         for (int var2 = 0; var2 < par1.length; var2++) {
202                                 var1.add(par1[var2]);
203                         }
204                         return getProbability(var1);
205                 }
206
207                 public int getProbability(ArrayList<Double> par1){
208
209                         double var1 = 0;
210
211                         for (int i = 0; i < par1.size(); i++){
212                                 var1 += par1.get(i);
213                         }
214
215                         double var2 = 0;
216                         double var3 = Math.random();
217
218                         for (int j = 0; j < par1.size(); j++){
219                                 double var4 = par1.get(j) / var1;
220                                 var2 += var4;
221                                 if (var2 >= var3){
222                                         return j;
223                                 }else{
224                                         continue;
225                                 }
226                         }
227                         return -1;
228                 }
229
230         }
231
232         public static class MathAuxiliary {
233
234                 public static ArrayList<Entity> getTriangleEntitysByPlayer(World par1World,
235                                 double par2, double par3, double par4,
236                                 double yaw,
237                                 double pitch,
238                                 double angle,
239                                 double rad) {
240
241                         ArrayList<Entity> entitys = (ArrayList<Entity>) par1World.loadedEntityList;
242                         ArrayList<Entity> result = new ArrayList<Entity>();
243                         for (int i = 0; i < entitys.size(); i++) {
244                                 String a = "";
245                                 Entity entity = entitys.get(i);
246                                 double x = entity.posX;
247                                 double y = entity.posY;
248                                 double z = entity.posZ;
249                                 double bx = par2;
250                                 double by = par3;
251                                 double bz = par4;
252                                 double look = Math.sin(Math.toRadians(yaw)) * 180;
253                                 double lookPitch = Math.abs(pitch);
254                                 double playerToEntityAngleXZ = Math.sin(Math.atan2(bx - x, bz - z)) * 180;
255                                 double playerToEntityAngleY = Math.toDegrees(Math.atan(y - by));
256                                 double length =
257                                                 Math.sqrt(
258                                                                 Math.pow(Math.abs(bx - x), 2) +
259                                                                 Math.pow(Math.abs(by - y), 2) +
260                                                                 Math.pow(Math.abs(bz - z), 2));
261
262                                 if (look + angle/2 > playerToEntityAngleXZ && look - angle/2 < playerToEntityAngleXZ) {
263                                         if (length < rad) {
264                                                 result.add(entity);
265                                         }
266                                 }
267
268                         }
269
270                         return result;
271                 }
272
273                 public static ArrayList<Entity> getTriangleEntitys(World par1World,
274                                 double par2, double par3, double par4,
275                                 double yaw,
276                                 double pitch,
277                                 double angle,
278                                 double rad) {
279
280                         ArrayList<Entity> entitys = (ArrayList<Entity>) par1World.loadedEntityList;
281                         ArrayList<Entity> result = new ArrayList<Entity>();
282                         for (int i = 0; i < entitys.size(); i++) {
283                                 String a = "";
284                                 Entity entity = entitys.get(i);
285                                 double x = entity.posX;
286                                 double y = entity.posY;
287                                 double z = entity.posZ;
288                                 double bx = par2;
289                                 double by = par3;
290                                 double bz = par4;
291                                 double playerToEntityAngleXZ = Math.sin(Math.atan2(bx - x, bz - z)) * 180;
292                                 double playerToEntityAngleY = Math.toDegrees(Math.atan(y - by));
293                                 double length =
294                                                 Math.sqrt(
295                                                                 Math.pow(Math.abs(bx - x), 2) +
296                                                                 Math.pow(Math.abs(by - y), 2) +
297                                                                 Math.pow(Math.abs(bz - z), 2));
298
299                                 if (playerToEntityAngleXZ + angle/2 > playerToEntityAngleXZ && playerToEntityAngleXZ - angle/2 < playerToEntityAngleXZ) {
300                                         if (length < rad) {
301                                                 result.add(entity);
302                                         }
303                                 }
304
305                         }
306
307                         return result;
308                 }
309
310         }
311
312 }