OSDN Git Service

I with OWATA
[chemicraft/chemicraft.git] / common / pcc / chemicraft / util / Auxiliary.java
index 309675d..1e1b23f 100644 (file)
@@ -1,8 +1,12 @@
 package pcc.chemicraft.util;
 
+import java.util.ArrayList;
+
 import net.minecraft.block.Block;
+import net.minecraft.entity.Entity;
 import net.minecraft.item.Item;
 import net.minecraft.item.ItemStack;
+import net.minecraft.world.World;
 import cpw.mods.fml.common.registry.LanguageRegistry;
 
 public class Auxiliary {
@@ -167,7 +171,7 @@ public class Auxiliary {
 
        public static class ArrayAuxiliary{
 
-               public ItemStack[] deleteNull(ItemStack[] array){
+               public static ItemStack[] deleteNull(ItemStack[] array){
                        int count = 0;
                        ItemStack[] arrayCopy;
                        for(int i = 0;i < array.length;i++){
@@ -187,4 +191,122 @@ public class Auxiliary {
 
        }
 
+       public static class Probability {
+
+               /**
+                * Return probability(0,1,2,etc...).
+                */
+               public int getProbability(double... par1){
+                       ArrayList<Double> var1 = new ArrayList<Double>();
+                       for (int var2 = 0; var2 < par1.length; var2++) {
+                               var1.add(par1[var2]);
+                       }
+                       return getProbability(var1);
+               }
+
+               public int getProbability(ArrayList<Double> par1){
+
+                       double var1 = 0;
+
+                       for (int i = 0; i < par1.size(); i++){
+                               var1 += par1.get(i);
+                       }
+
+                       double var2 = 0;
+                       double var3 = Math.random();
+
+                       for (int j = 0; j < par1.size(); j++){
+                               double var4 = par1.get(j) / var1;
+                               var2 += var4;
+                               if (var2 >= var3){
+                                       return j;
+                               }else{
+                                       continue;
+                               }
+                       }
+                       return -1;
+               }
+
+       }
+
+       public static class MathAuxiliary {
+
+               public static ArrayList<Entity> getTriangleEntitysByPlayer(World par1World,
+                               double par2, double par3, double par4,
+                               double yaw,
+                               double pitch,
+                               double angle,
+                               double rad) {
+
+                       ArrayList<Entity> entitys = (ArrayList<Entity>) par1World.loadedEntityList;
+                       ArrayList<Entity> result = new ArrayList<Entity>();
+                       for (int i = 0; i < entitys.size(); i++) {
+                               String a = "";
+                               Entity entity = entitys.get(i);
+                               double x = entity.posX;
+                               double y = entity.posY;
+                               double z = entity.posZ;
+                               double bx = par2;
+                               double by = par3;
+                               double bz = par4;
+                               double look = Math.sin(Math.toRadians(yaw)) * 180;
+                               double lookPitch = Math.abs(pitch);
+                               double playerToEntityAngleXZ = Math.sin(Math.atan2(bx - x, bz - z)) * 180;
+                               double playerToEntityAngleY = Math.toDegrees(Math.atan(y - by));
+                               double length =
+                                               Math.sqrt(
+                                                               Math.pow(Math.abs(bx - x), 2) +
+                                                               Math.pow(Math.abs(by - y), 2) +
+                                                               Math.pow(Math.abs(bz - z), 2));
+
+                               if (look + angle/2 > playerToEntityAngleXZ && look - angle/2 < playerToEntityAngleXZ) {
+                                       if (length < rad) {
+                                               result.add(entity);
+                                       }
+                               }
+
+                       }
+
+                       return result;
+               }
+
+               public static ArrayList<Entity> getTriangleEntitys(World par1World,
+                               double par2, double par3, double par4,
+                               double yaw,
+                               double pitch,
+                               double angle,
+                               double rad) {
+
+                       ArrayList<Entity> entitys = (ArrayList<Entity>) par1World.loadedEntityList;
+                       ArrayList<Entity> result = new ArrayList<Entity>();
+                       for (int i = 0; i < entitys.size(); i++) {
+                               String a = "";
+                               Entity entity = entitys.get(i);
+                               double x = entity.posX;
+                               double y = entity.posY;
+                               double z = entity.posZ;
+                               double bx = par2;
+                               double by = par3;
+                               double bz = par4;
+                               double playerToEntityAngleXZ = Math.sin(Math.atan2(bx - x, bz - z)) * 180;
+                               double playerToEntityAngleY = Math.toDegrees(Math.atan(y - by));
+                               double length =
+                                               Math.sqrt(
+                                                               Math.pow(Math.abs(bx - x), 2) +
+                                                               Math.pow(Math.abs(by - y), 2) +
+                                                               Math.pow(Math.abs(bz - z), 2));
+
+                               if (playerToEntityAngleXZ + angle/2 > playerToEntityAngleXZ && playerToEntityAngleXZ - angle/2 < playerToEntityAngleXZ) {
+                                       if (length < rad) {
+                                               result.add(entity);
+                                       }
+                               }
+
+                       }
+
+                       return result;
+               }
+
+       }
+
 }