OSDN Git Service

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