Advertisement
Corosus

Untitled

Nov 23rd, 2012
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 29.12 KB | None | 0 0
  1. package Corobot;
  2.  
  3. import java.lang.reflect.Field;
  4. import java.util.ArrayList;
  5. import java.util.HashMap;
  6. import java.util.LinkedList;
  7. import java.util.List;
  8. import java.util.Random;
  9.  
  10. import CoroAI.PFQueue;
  11. import CoroAI.PathEntityEx;
  12. import CoroAI.PathPointEx;
  13. import CoroAI.entity.EnumActState;
  14. import CoroAI.entity.EnumJob;
  15. import CoroAI.entity.EnumJobState;
  16. import CoroAI.entity.JobManager;
  17. import CoroAI.entity.c_EnhAI;
  18. import CoroAI.entity.c_PlayerProxy;
  19.  
  20. import net.minecraft.client.Minecraft;
  21. import net.minecraft.src.*;
  22.  
  23. import cpw.mods.fml.common.Side;
  24. import cpw.mods.fml.common.asm.SideOnly;
  25. @SideOnly(Side.CLIENT)
  26. public class c_AIP {
  27.    
  28.     public static c_AIP i;
  29.    
  30.     public static Minecraft mc = ModLoader.getMinecraftInstance();
  31.     public EntityPlayer player;
  32.     public static World worldObj;
  33.    
  34.     public EntityPlayer ent;
  35.    
  36.     public Random rand = new Random(System.currentTimeMillis());
  37.     public int dangerLevel;
  38.     public PathEntityEx pathToEntity;
  39.     public EnumActState currentAction;
  40.     public boolean fleeing;
  41.  
  42.     public JobManager job;
  43.     public Entity entityToAttack;
  44.    
  45.     public c_EnumAIPOrders orders = c_EnumAIPOrders.STAY_CLOSE;
  46.     public int lastItemCount;
  47.    
  48.     //walking target
  49.     public int targX;
  50.     public int targY;
  51.     public int targZ;
  52.    
  53.     //follow target
  54.     public Entity followTarget;
  55.    
  56.     //Village fields
  57.     public int homeX;
  58.     public int homeY;
  59.     public int homeZ;
  60.     public double maxDistanceFromHome = 96;
  61.    
  62.     public long checkAreaDelay;
  63.     public long checkRange = 16;
  64.     public int openedChest = 0;
  65.    
  66.     public int maxPFRange = 512;
  67.    
  68.     //Customizable item use vars
  69.     public int cooldown_Melee;
  70.     public int cooldown_Ranged;
  71.     public int slot_Melee;
  72.     public int slot_Ranged;
  73.     public int slot_Food;
  74.     public float maxReach_Melee;
  75.     public float maxReach_Ranged;
  76.     public int itemSearchRange;
  77.     public List wantedItems;
  78.    
  79.     public boolean forcejump;
  80.     public boolean mining;
  81.     public int mineDelay;
  82.     public int noMoveTicks;
  83.     public int curCooldown_Melee;
  84.     public int curCooldown_Ranged;
  85.     public int pfTimeout;
  86.    
  87.     public int cooldown_Pathfind = 20;
  88.     public int curCooldown_Pathfind;
  89.  
  90.     public static boolean enableAI = false;
  91.  
  92.     public boolean wallOfPainToggle = true;
  93.    
  94.     public boolean isUsing = false;
  95.     public int isUsingTicks = 0;
  96.    
  97.     //For blocks
  98.     public boolean dangerZone = false;
  99.    
  100.     //For entities
  101.     public boolean enemyClose = false;
  102.    
  103.     public int walkingTimeout;
  104.    
  105.     public boolean attackPlayers = false;
  106.     public boolean attackAnimals = false;
  107.    
  108.    
  109.     public static List<String> owners = new ArrayList();
  110.    
  111.    
  112.     public c_AIP() {
  113.         i = this;
  114.         player = mc.thePlayer;
  115.         worldObj = mc.theWorld;
  116.  
  117.         job = new JobManager(null);
  118.        
  119.         job.jobTypes.put(EnumJob.PLAYER_SURVIVE, new JobPlayerInventory(job));
  120.         job.jobTypes.put(EnumJob.PLAYER_HUNT, new c_Job_Player_Hunt(job));
  121.         job.jobTypes.put(EnumJob.PLAYER_FOLLOW, new c_Job_Player_Follow(job));
  122.        
  123.         job.addJob(EnumJob.PLAYER_SURVIVE);
  124.         job.addJob(EnumJob.PLAYER_HUNT);
  125.         job.addJob(EnumJob.PLAYER_FOLLOW);
  126.        
  127.         job.setPrimaryJob(EnumJob.PLAYER_SURVIVE);
  128.        
  129.         wantedItems = new LinkedList();
  130.         slot_Melee = 0;
  131.         slot_Ranged = 1;
  132.         slot_Food = 2;
  133.         cooldown_Melee = 1;
  134.         cooldown_Ranged = 40;
  135.         maxReach_Melee = 5F;
  136.         maxReach_Ranged = 22F;
  137.         itemSearchRange = 5;
  138.        
  139.         owners.add("Corosus");
  140.         //owners.add("drfrox");
  141.         //owners.add("medsouz");
  142.         //owners.add("Cojomax99");
  143.         //owners.add("solonox");
  144.         //owners.add("Malqua");
  145.        
  146.     }
  147.    
  148.     public static boolean okToGo() {
  149.         if (worldObj == null) worldObj = mc.theWorld;
  150.         if (i.player == null) i.player = mc.thePlayer;
  151.        
  152.         if (worldObj == null || i.player == null) {
  153.             return false;
  154.         } else {
  155.             return true;
  156.         }
  157.     }
  158.    
  159.     public boolean isEnemy(Entity entity1) {
  160.         if ((entity1 instanceof EntityMob || entity1 instanceof EntitySlime) && !(entity1 instanceof EntityWolf || entity1 instanceof EntityEnderman || entity1 instanceof EntityPigZombie/* || entity1 instanceof EntityCreeper*/)) {
  161.             return true;
  162.         } else {
  163.            
  164.             if (entity1 instanceof EntityEnderman) {
  165.                 if (((EntityEnderman)entity1).func_70823_r()) { //if attacking, client side datawatcher style check
  166.                     return true;
  167.                 }
  168.             }
  169.            
  170.             //animal adjuster (give own job later?)
  171.             if (attackAnimals && entity1 instanceof EntityCow) return true;
  172.            
  173.             if (entity1 instanceof EntityPlayer && attackPlayers) {
  174.                 if (!owners.contains(((EntityPlayer) entity1).username)) {
  175.                     return true;
  176.                 }
  177.             }
  178.            
  179.             return false;
  180.            
  181.         }
  182.     }
  183.    
  184.     public boolean isThreat(Entity entity1) { return isFeared(entity1); }
  185.    
  186.     public boolean isFeared(Entity entity1) {
  187.         if (entity1 instanceof EntityCreeper) {
  188.             return true;
  189.         } else {
  190.             return false;
  191.            
  192.         }
  193.     }
  194.    
  195.     public boolean isMeleeUser(Entity ent) {
  196.         if (ent instanceof EntityMob && !(ent instanceof EntitySkeleton)) {
  197.             return true;
  198.         }
  199.         return false;
  200.     }
  201.    
  202.     public boolean isRangedUser(Entity ent) {
  203.         if (ent instanceof EntitySkeleton || ent instanceof EntityBlaze || ent instanceof EntityGhast) {
  204.             return true;
  205.         }
  206.         return false;
  207.     }
  208.    
  209.     public void setState(EnumActState eka) {
  210.         currentAction = eka;
  211.     }
  212.    
  213.     //returns: -1 = not checking, timeout in progress, 0 = no danger, 1 = found danger
  214.     public int checkSurroundings() {
  215.        
  216.         //Hostile block checking
  217.        
  218.         dangerZone = false;
  219.         int range = 3;
  220.         for (int xx = -range; xx < range; xx++) {
  221.             for (int zz = -range; zz < range; zz++) {
  222.                 int id = player.worldObj.getBlockId((int)player.posX+xx, (int)player.posY, (int)player.posZ+zz);
  223.                 if (id == Block.cactus.blockID) {
  224.                     //System.out.println("DANGER ZONE!");
  225.                     dangerZone = true;                 
  226.                 }
  227.             }
  228.         }
  229.        
  230.        
  231.        
  232.         //if player or some hostile gets close, if not hunter perhaps run back to the village, find a hunter, update his job and have him get it
  233.         if (checkAreaDelay < System.currentTimeMillis()) {
  234.             checkAreaDelay = System.currentTimeMillis() + 1500 + rand.nextInt(1000);
  235.            
  236.             float closest = 9999F;
  237.             Entity clEnt = null;
  238.            
  239.             List list = worldObj.getEntitiesWithinAABBExcludingEntity(player, player.boundingBox.expand(checkRange, checkRange/2, checkRange));
  240.             for(int j = 0; j < list.size(); j++)
  241.             {
  242.                 Entity entity1 = (Entity)list.get(j);
  243.                 if(isEnemy(entity1))
  244.                 {
  245.                     if (((EntityLiving) entity1).canEntityBeSeen(player)) {
  246.                         float dist = player.getDistanceToEntity(entity1);
  247.                         if (dist < closest) {
  248.                             closest = dist;
  249.                             clEnt = entity1;
  250.                         }
  251.                        
  252.                         //break;
  253.                     }
  254.                 }
  255.             }
  256.            
  257.             if (clEnt != null) {
  258.                 //alertHunters(clEnt);
  259.                 return 1;
  260.             } else {
  261.                 return 0;
  262.             }
  263.            
  264.            
  265.         } else {
  266.             return -1;
  267.         }
  268.        
  269.        
  270.        
  271.         //if threat - setstate moving -> village
  272.     }
  273.    
  274.     public boolean checkHealth() {
  275.         //dont flee if attacking player, go relentless
  276.         if (entityToAttack instanceof EntityPlayer) {
  277.             return false;
  278.         }
  279.         if (player.getHealth() < player.getMaxHealth() * 0.65) {
  280.             return true;
  281.         }
  282.         return false;
  283.     }
  284.    
  285.     public void updateJob() {
  286.         //setEntityDead();
  287.        
  288.         //NEW SYSTEM!
  289.         //if (job.curJobs.size() > 0) {
  290.         job.tick();
  291.     }
  292.    
  293.     public boolean eat() {
  294.        
  295.         if(!this.isUsing && player.inventory.mainInventory[this.slot_Food] != null && isFood(player.inventory.mainInventory[this.slot_Food])) {
  296.             this.setCurrentSlot(this.slot_Food);
  297.             rightClickItem();
  298.             return true;
  299.         }
  300.         /*for(int j = 0; j < player.inventory.mainInventory.length; j++)
  301.         {
  302.             if(player.inventory.mainInventory[j] != null && isFood(player.inventory.mainInventory[j]))
  303.             {
  304.                 //inventory.consumeInventoryItem(j);
  305.                 //setCurrentItem(mod_tropicraft.fishingRodTropical.shiftedIndex);
  306.                 this.setCurrentSlot(j);
  307.                
  308.                 //health = fakePlayer.health;
  309.                 return true;
  310.             }
  311.         }*/
  312.         return false;
  313.     }
  314.    
  315.     public boolean isFood(ItemStack itemstack) {
  316.         if (itemstack != null) {
  317.             Item item = itemstack.getItem();
  318.             if (item instanceof ItemFood) {
  319.                 return true;
  320.             }
  321.         }
  322.         return false;
  323.     }
  324.    
  325.    
  326.     public boolean isWantedItemorEXP(Entity ent) {
  327.         if (ent.isInWater()) return false;
  328.         if (ent instanceof EntityItem) {
  329.             if (((EntityItem) ent).age > 60) {
  330.                 return true;
  331.             }
  332.             //if (wantedItems.contains(((EntityItem) ent).item.itemID + 256)) {
  333.                 //return true;
  334.             //}
  335.         }
  336.         if (ent instanceof EntityArrow) {
  337.             if (((EntityArrow) ent).canBePickedUp == 1) return true;
  338.         }
  339.         if (ent instanceof EntityXPOrb) {
  340.             return true;
  341.         }
  342.         return false;
  343.        
  344.     }
  345.    
  346.     public void manageInventory() {
  347.         int count = 0;
  348.         for (int i = 0; i < player.inventory.mainInventory.length; i++) {
  349.             if (player.inventory.mainInventory[i] != null) count++;
  350.         }
  351.        
  352.         if (count != this.lastItemCount) {
  353.             inventoryChanged(count);
  354.             System.out.println("New inv count: " + count);
  355.         }
  356.     }
  357.    
  358.     public void inventoryChanged(int amount) {
  359.         lastItemCount = amount;
  360.        
  361.     }
  362.    
  363.     public void PFCallBackChecker() {
  364.         if (c_CoroAIUtil.newPath) {
  365.             pathToEntity = c_CoroAIUtil.pathToEntity;
  366.             if (pathToEntity != null) {
  367.                 pathToEntity.incrementPathIndex();
  368.             }
  369.             c_CoroAIUtil.newPath = false;
  370.         }
  371.        
  372.     }
  373.    
  374.     public void AIPlayerTick() {
  375.        
  376.         if (!enableAI) return;
  377.        
  378.         PFCallBackChecker();
  379.        
  380.         //debug stuff
  381.         cooldown_Pathfind = 40;
  382.         maxReach_Ranged = 22F;
  383.        
  384.         if (attackPlayers) {
  385.             cooldown_Melee = 1;
  386.             maxReach_Melee = 6F;
  387.         } else {
  388.             cooldown_Melee = 10;
  389.             maxReach_Melee = 5F;
  390.         }
  391.        
  392.         //Cooldowns
  393.         if (curCooldown_Melee > 0) { curCooldown_Melee--; }
  394.         if (curCooldown_Ranged > 0) { curCooldown_Ranged--; }
  395.         if (c_AIP.i.curCooldown_Pathfind > 0) c_AIP.i.curCooldown_Pathfind--;
  396.        
  397.         if (entityToAttack != null && entityToAttack.isEntityAlive()) {
  398.            
  399.             float var2 = this.entityToAttack.getDistanceToEntity(player);
  400.  
  401.             if (entityToAttack instanceof EntityLiving && player.canEntityBeSeen(this.entityToAttack))
  402.             {
  403.                 //mc.playerController.attackEntity(player, entityToAttack)
  404.                 attackEntity(this.entityToAttack, var2);
  405.             }
  406.             else
  407.             {
  408.                 //player.attackBlockedEntity(this.entityToAttack, var2);
  409.             }
  410.         }
  411.        
  412.         dangerLevel = 0;
  413.         if (checkSurroundings() == 1) dangerLevel = 1;
  414.         if (checkHealth()) dangerLevel = 2;
  415.         job.getJobClass().checkHunger();
  416.        
  417.         //Safety overrides
  418.         fleeing = false;
  419.         //Safe
  420.         if (dangerLevel == 0) {
  421.             updateJob();
  422.             //this.moveSpeed = oldMoveSpeed;
  423.            
  424.         //Enemy detected? (by alert system?)
  425.         } else if (dangerLevel == 1) {
  426.             //no change for now
  427.             updateJob();
  428.             //this.moveSpeed = oldMoveSpeed;
  429.            
  430.         //Low health, avoid death
  431.         } else if (dangerLevel == 2) {
  432.            
  433.             //If nothing to avoid
  434.             if (!job.getJobClass().avoid(true)) {
  435.                 fleeing = false;
  436.                 //no danger in area, try to continue job
  437.                 updateJob();
  438.                 //this.moveSpeed = oldMoveSpeed;
  439.             } else {
  440.                 fleeing = true;
  441.                 job.getJobClass().onLowHealth();
  442.                
  443.                 //code to look ahead 1 node to speed up the pathfollow escape - WARNING, THIS BREAKS CAREFULL NAV AROUND PITS!!! also cactuses
  444.                 /*if (pathToEntity != null && pathToEntity.points != null) {
  445.                     int pIndex = pathToEntity.pathIndex+1;
  446.                     if (pIndex < pathToEntity.points.length) {
  447.                         if (worldObj.rayTraceBlocks(Vec3D.createVector((double)pathToEntity.points[pIndex].xCoord + 0.5D, (double)pathToEntity.points[pIndex].yCoord + 1.5D, (double)pathToEntity.points[pIndex].zCoord + 0.5D), Vec3D.createVector(player.posX, player.posY + (double)player.getEyeHeight(), player.posZ)) == null) {
  448.                             pathToEntity.pathIndex++;
  449.                         }
  450.                     }
  451.                 }*/
  452.                
  453.                 //this.moveSpeed = fleeSpeed;
  454.             }
  455.         }
  456.        
  457.         wallOfPain();
  458.        
  459.         //Aiming fixing depending on using charge or pathfinding
  460.         if (isUsingTicks < cooldown_Ranged-4) {
  461.             if (pathToEntity != null) {
  462.                 //System.out.println("pathing + " + pathToEntity.pathLength);
  463.                 pathFollow();
  464.                 player.rotationPitch = 0F;
  465.             } else {
  466.                 //System.out.println("not pathing");
  467.             }
  468.             if (this.entityToAttack instanceof EntityItem && player.getDistanceToEntity(entityToAttack) < 3F) {
  469.                 player.faceEntity(entityToAttack , 1F, 1F);
  470.                 player.moveFlying(0F, -player.rotationPitch, 0.25F);
  471.             }
  472.            
  473.         } else {
  474.             //pathFollow();
  475.             if (this.entityToAttack != null) player.faceEntity(this.entityToAttack, 180, 180);
  476.             player.rotationPitch -= 3F;
  477.         }
  478.        
  479.         updateItemCharge();
  480.         manageInventory();
  481.        
  482.         if (player.isInWater()) player.motionY += 0.03D;
  483.        
  484.         if (currentAction == EnumActState.IDLE && job.getJobState() == EnumJobState.IDLE) {
  485.            
  486.             job.getJobClass().onIdleTick();
  487.            
  488.             if (orders == c_EnumAIPOrders.WANDER) {
  489.                 this.updateWanderPath(32);
  490.             }
  491.            
  492.             //Anti clump code
  493.             if (pathToEntity != null && pathToEntity.points != null && pathToEntity.points.length > 0) {
  494.                 walkingTimeout--;
  495.                 if (walkingTimeout <= 0) {
  496.                     //PFQueue.getPath(this, (int)targX, (int)targY, (int)targZ, maxPFRange);
  497.                     //PFQueue.getPath(var0, var1, MaxPFRange);
  498.                     //setState(EnumActState.WALKING);
  499.                     this.pathToEntity = null;
  500.                     System.out.println("path reset idle out");
  501.                     //walkingTimeout = 600;
  502.                 }
  503.             }
  504.            
  505.         } else if (currentAction == EnumActState.FIGHTING) {
  506.             actFight();
  507.         } else if (currentAction == EnumActState.WALKING) {
  508.             actWalk();
  509.         } else if (currentAction == EnumActState.FOLLOWING) {
  510.             actFollow();
  511.         }
  512.     }
  513.    
  514.     public void actFight() {
  515.         //a range check maybe, but why, strafing/dodging techniques or something, lunging forward while using dagger etc...
  516.         if (entityToAttack == null || entityToAttack.isDead) {
  517.             entityToAttack = null;
  518.             setState(EnumActState.IDLE);
  519.         }
  520.     }
  521.    
  522.     public void actWalk() {
  523.         walkingTimeout--;
  524.         //System.out.println(this.getDistance(targX, targY, targZ));
  525.         if (player.getDistance(targX, targY, targZ) < 1F || i.pathToEntity == null) {
  526.             curCooldown_Pathfind = 0;
  527.             this.setPathToEntity((PathEntityEx)null);
  528.             setState(EnumActState.IDLE);
  529.         } else if (walkingTimeout <= 0) {
  530.             setState(EnumActState.IDLE);
  531.         }
  532.     }
  533.    
  534.     public void setPathToEntity(PathEntityEx pathEntityEx) {
  535.         pathToEntity = pathEntityEx;
  536.         // TODO Auto-generated method stub
  537.        
  538.     }
  539.  
  540.     //old code, remake entirely
  541.     public void actFollow() {
  542.         //temp
  543.         EntityLiving entityplayer = null;
  544.         followTarget = entityplayer;
  545.        
  546.         if (followTarget != null) {        
  547.             //Player follow logic
  548.             if(entityplayer != null && rand.nextInt(30) < 3)
  549.             {
  550.                 float f = entityplayer.getDistanceToEntity(player);
  551.                 if(f > 10F)
  552.                 {
  553.                     getPathOrWalkableBlock(entityplayer, f);
  554.                 }
  555.             }
  556.         }
  557.     }
  558.    
  559.     public void getPathOrWalkableBlock(Entity entity, float f)
  560.     {
  561.         PathEntityEx pathentity = null;//worldObj.getPathToEntity(this, entity, 16F, false, false, false, false);
  562.         if(pathentity == null && f > 12F)
  563.         {
  564.             int i = MathHelper.floor_double(entity.posX) - 2;
  565.             int j = MathHelper.floor_double(entity.posZ) - 2;
  566.             int k = MathHelper.floor_double(entity.boundingBox.minY);
  567.             for(int l = 0; l <= 4; l++)
  568.             {
  569.                 for(int i1 = 0; i1 <= 4; i1++)
  570.                 {
  571.                     if((l < 1 || i1 < 1 || l > 3 || i1 > 3) && worldObj.isBlockNormalCube(i + l, k - 1, j + i1) && !worldObj.isBlockNormalCube(i + l, k, j + i1) && !worldObj.isBlockNormalCube(i + l, k + 1, j + i1))
  572.                     {
  573.                         //replace this with op powered teleport if it is to be used
  574.                         player.setLocationAndAngles((float)(i + l) + 0.5F, k, (float)(j + i1) + 0.5F, player.rotationYaw, player.rotationPitch);
  575.                         return;
  576.                     }
  577.                 }
  578.  
  579.             }
  580.  
  581.         } else
  582.         {
  583.             setPathToEntity(pathentity);
  584.         }
  585.     }
  586.    
  587.     //hmmmmmmm\\
  588.    
  589.     public void updateWanderPath(int range)
  590.     {
  591.         //Profiler.startSection("stroll");
  592.         boolean flag = false;
  593.         int i = -1;
  594.         int j = -1;
  595.         int k = -1;
  596.         float f = -99999F;
  597.         for (int l = 0; l < 10; l++)
  598.         {
  599.             int i1 = MathHelper.floor_double((player.posX + (double)rand.nextInt(range)) - range/2);
  600.             int j1 = MathHelper.floor_double((player.posY + (double)rand.nextInt(range/2)) - range/4);
  601.             int k1 = MathHelper.floor_double((player.posZ + (double)rand.nextInt(range)) - range/2);
  602.             float f1 = 0F;//player.getBlockPathWeight(i1, j1, k1);
  603.             if (f1 > f)
  604.             {
  605.                 f = f1;
  606.                 i = i1;
  607.                 j = j1;
  608.                 k = k1;
  609.                 flag = true;
  610.             }
  611.         }
  612.  
  613.         if (flag)
  614.         {
  615.             walkTo(player, i, j, k, this.maxPFRange, 600);
  616.         }
  617.         //Profiler.endSection();
  618.     }
  619.    
  620.     public HashMap<EntityLiving, Long> lastHitTime = new HashMap();
  621.  
  622.    
  623.    
  624.     public void wallOfPain() {
  625.        
  626.         float range = 3.5F;
  627.         float cooldown = 500;
  628.         int hurtTimeMin = 0;
  629.        
  630.         if (attackPlayers) {
  631.             range = 5.5F;
  632.             cooldown = 100;
  633.             hurtTimeMin = 3;
  634.         }
  635.        
  636.         if (wallOfPainToggle/* && hitCooldown == 0*/) {
  637.             List list = player.worldObj.getEntitiesWithinAABBExcludingEntity(player, player.boundingBox.expand(range, range, range));
  638.  
  639.             for(int count = 0; count < list.size(); ++count) {
  640.                Entity var5 = (Entity)list.get(count);
  641.  
  642.                if (var5 instanceof EntityLiving) {
  643.                    
  644.                    //System.out.println(var5 + ": " + ((EntityLiving)var5).getAttackTarget());
  645.                    if(isEnemy(var5)/* && !isFeared(var5)*/ /*&& !(var5 instanceof EntityPlayer) */&& ((EntityLiving) var5).hurtTime <= hurtTimeMin) {
  646.    
  647.                         if (!lastHitTime.containsKey(((EntityLiving) var5)) || System.currentTimeMillis() - lastHitTime.get(((EntityLiving) var5)).longValue() > cooldown) {
  648.                             //System.out.println(var5 + ": " + ((EntityLiving) var5).hurtTime);
  649.                             //hitCooldown = 10;
  650.                             lastHitTime.put(((EntityLiving) var5), System.currentTimeMillis());
  651.                            
  652.                             //if (!this.isUsing) {
  653.                                 this.setCurrentSlot(this.slot_Melee);
  654.                             //}
  655.                             mc.playerController.attackEntity(player, var5);
  656.                             player.swingItem();
  657.                         }
  658.                    }
  659.                }
  660.             }
  661.         }
  662.     }
  663.    
  664.     public void pathFollow() {
  665.        
  666.         PathEntityEx path = pathToEntity;
  667.         EntityPlayer theplayer = player;
  668.        
  669.         theplayer = ModLoader.getMinecraftInstance().thePlayer;
  670.    
  671.         Vec3 var5 = path.getPosition(theplayer);
  672.        
  673.         double minDistToNode = (double)(theplayer.width * 1.2F);
  674.  
  675.         //????
  676.         dangerZone = true;
  677.        
  678.         if (dangerZone) minDistToNode = (double)(theplayer.width * 0.9F);
  679.        
  680.         while(var5 != null && squareDistanceToXZ(theplayer.posX, theplayer.posZ, var5.xCoord, var5.zCoord) < minDistToNode * minDistToNode) {
  681.             path.incrementPathIndex();
  682.  
  683.             if(path.isFinished()) {
  684.                 System.out.println("path end");
  685.                 curCooldown_Pathfind = 0;
  686.                 var5 = null;
  687.                 path = null;
  688.             } else {
  689.                 var5 = path.getPosition(theplayer);
  690.             }
  691.         }
  692.        
  693.         if (path != null) {
  694.             if (path.pathIndex >= path.pathLength || player.isDead) {
  695.                 pathToEntity = null;
  696.                 curCooldown_Pathfind = 0;
  697.                 System.out.println("path remove");
  698.             }
  699.         }
  700.  
  701.         int var21 = MathHelper.floor_double(theplayer.boundingBox.minY + 0.5D);
  702.         float angle = 0F;
  703.  
  704.         if(var5 != null) {
  705.             double var8 = var5.xCoord - theplayer.posX;
  706.             double var10 = var5.zCoord - theplayer.posZ;
  707.             double var12 = var5.yCoord - (double)var21;
  708.             float var14 = (float)(Math.atan2(var10, var8) * 180.0D / 3.1415927410125732D) - 90.0F;
  709.             float var15 = var14 - theplayer.rotationYaw;
  710.  
  711.             for(angle = 0.7F; var15 < -180.0F; var15 += 360.0F) {
  712.                 ;
  713.             }
  714.  
  715.             while(var15 >= 180.0F) {
  716.                 var15 -= 360.0F;
  717.             }
  718.  
  719.             float max = 80F;
  720.             if (dangerZone) max = 160F;
  721.            
  722.             if(var15 > max) {
  723.                 var15 = max;
  724.             }
  725.  
  726.             if(var15 < -max) {
  727.                 var15 = -max;
  728.             }
  729.  
  730.             theplayer.rotationYaw += var15;
  731.  
  732.             if(var12 > 0.0D || theplayer.handleWaterMovement() || theplayer.handleLavaMovement()) {
  733.                 theplayer.isJumping = true;
  734.             }
  735.  
  736.             if (theplayer.isJumping) {
  737.                 //this.A
  738.                 if (theplayer.onGround) {
  739.                     jump(theplayer);
  740.                     //theplayer.jump();
  741.                     //performMove(keys[4], false, false);
  742.                 }
  743.             }
  744.         }
  745.  
  746.         //float speed = theplayer.cg;
  747.         //theplayer.cg = 0.1F;
  748.         //theplayer.moveEntityWithHeading(0F,angle);
  749.        
  750.         float speed = 0.15F;
  751.        
  752.         if (theplayer.onGround) {
  753.             if (fleeing) {
  754.                 speed = 0.2F;
  755.             } else {
  756.                
  757.             }
  758.         } else {
  759.             speed = 0.02F;
  760.         }
  761.        
  762.         if (theplayer.isInWater()) {
  763.             speed *= 2F;
  764.         }
  765.        
  766.         theplayer.moveFlying(0F, angle, speed);
  767.        
  768.         if (theplayer.onGround && theplayer.isCollidedHorizontally) {
  769.             jump(theplayer);
  770.         }
  771.        
  772.         //theplayer.moveEntityWithHeading(0F,angle);
  773.         //theplayer.cg = speed;
  774.     }
  775.    
  776.     public void jump(EntityPlayer theplayer) {
  777.        
  778.         theplayer.motionY = 0.4F;
  779.         theplayer.isAirBorne = true;
  780.     }
  781.    
  782.     public double squareDistanceToXZ(double par1, double par5, double x, double z)
  783.     {
  784.         double var7 = par1 - x;
  785.         double var11 = par5 - z;
  786.         return var7 * var7 + var11 * var11;
  787.     }
  788.    
  789.     public void huntTarget(Entity ent, int pri) {
  790.         //PFQueue.getPath(this, ent, maxPFRange, pri);
  791.         if (PFQueue.instance == null) {
  792.             new PFQueue(ent.worldObj);
  793.         }
  794.         //c_AIP.i.pathToEntity = PFQueue.instance.createEntityPathTo(player, ent, 256.0F);
  795.         PFQueue.getPath(player, ent, 256.0F, pri);
  796.         /*c_AIP.i.pathToEntity = PFQueue.instance.convertToPathEntityEx(player.worldObj.getPathEntityToEntity(player, ent, maxPFRange, true, true, true, true));
  797.         PathPointEx var11 = new PathPointEx(MathHelper.floor_float(player.width + 1.0F), MathHelper.floor_float(player.height + 1.0F), MathHelper.floor_float(player.width + 1.0F));
  798.         c_AIP.i.pathToEntity = PFQueue.instance.simplifyPath(c_AIP.i.pathToEntity, var11);*/
  799.         //System.out.println("pl huntTarget call: " + ent.getDistanceToEntity(player) + " - " + ent);
  800.         this.entityToAttack = ent;
  801.         setState(EnumActState.FIGHTING);
  802.     }
  803.    
  804.     public void huntTarget(Entity ent) {
  805.         huntTarget(ent, 0);
  806.     }
  807.    
  808.     public void aimAtEnt(Entity ent) {
  809.         player.faceEntity(ent, 30, 30);
  810.     }
  811.    
  812.     public void setCurrentSlot(int slot) {
  813.         if (player.inventory == null) { return; }
  814.         player.inventory.currentItem = slot;
  815.         //sync();
  816.     }
  817.    
  818.     public boolean shouldUseArrow(Entity target) {
  819.         if (target instanceof EntitySkeleton) return true;
  820.         if (isThreat(target)) return true;
  821.         return false;
  822.     }
  823.    
  824.     protected void attackEntity(Entity var1, float var2) {
  825.         //sync();
  826.         //aimAtEnt(var1);
  827.         //if (isAimedAtTarget(var1)) {
  828.        
  829.         /*https://gist.github.com/fc60ef90e1a192d37efc
  830.         double var6;
  831.  
  832.         if (facee instanceof EntityLiving) {
  833.         EntityLiving var10 = (EntityLiving) facee;
  834.         var6 = facer.posY + (double) facer.getEyeHeight() - (var10.posY + (double) var10.getEyeHeight());
  835.         } else {
  836.         var6 = (facee.boundingBox.minY + facee.boundingBox.maxY) / 2.0D - (facer.posY + (double) facer.getEyeHeight());
  837.         }
  838.    
  839.         double var14 = (double) MathHelper.sqrt_double(var4 * var4 + var8 * var8);
  840.         float var12 = (float) (Math.atan2(var8, var4) * 180.0D / Math.PI) - 90.0F;
  841.         float var13 = (float) (-(Math.atan2(var6, var14) * 180.0D / Math.PI));
  842.         float yMod = 0F;
  843.         double dist = facer.getDistanceToEntity(facee);
  844.         if(facee.posY > facer.posY){
  845.         double diff = facee.posY - facer.posY;
  846.         yMod -= (((diff/8)*dist)/8)-2;
  847.         }
  848.         facer.rotationPitch = updateRotation(facer.rotationPitch, -var13+yMod, vSpeed);
  849.         facer.rotationYaw = updateRotation(facer.rotationYaw, var12, hSpeed);   */
  850.            
  851.        
  852.             if (var2 < maxReach_Melee && var1.boundingBox.maxY > player.boundingBox.minY && var1.boundingBox.minY < player.boundingBox.maxY) {
  853.                 if (curCooldown_Melee <= 0) {
  854.                     setCurrentSlot(slot_Melee);
  855.                     leftClickItem(var1);
  856.                     this.curCooldown_Melee = cooldown_Melee;
  857.                 }
  858.             } else if (var2 < maxReach_Ranged) {
  859.                 //System.out.println("contemplate ranged");
  860.                 if (shouldUseArrow(var1) && curCooldown_Ranged <= 0) {
  861.                     setCurrentSlot(slot_Ranged);
  862.                     rightClickItem();
  863.                     //System.out.println("try ranged");
  864.                     this.curCooldown_Ranged = cooldown_Ranged;
  865.                 }
  866.             }
  867.         //}
  868.     }
  869.    
  870.     public void leftClickItem(Entity var1) {
  871.         try {
  872.             //player.attackTargetEntityWithCurrentItem(var1);
  873.             mc.playerController.attackEntity(player, var1);
  874.             player.swingItem();
  875.         } catch (Exception ex) {
  876.             //ex.printStackTrace();
  877.         }
  878.     }
  879.    
  880.     public void rightClickItem() {
  881.         ItemStack var10 = player.inventory.getCurrentItem();
  882.  
  883.         if (var10 != null && mc.playerController.sendUseItem(player, worldObj, var10))
  884.         {
  885.            
  886.         }
  887.        
  888.         //System.out.println(isUsingTicks);
  889.         if (!isUsing) {
  890.             isUsing = true;
  891.             //System.out.println("charge");
  892.            
  893.         } else {
  894.             //System.out.println("release");
  895.            
  896.         }
  897.     }
  898.    
  899.     public void updateItemCharge() {
  900.         if (isUsing) {
  901.             isUsingTicks++;
  902.            
  903.             mc.gameSettings.keyBindUseItem.pressed = true;
  904.         } else {
  905.             isUsingTicks = 0;
  906.         }
  907.        
  908.         if (player.getCurrentEquippedItem() != null) {
  909.             if (player.getCurrentEquippedItem().getItem() instanceof ItemBow || player.getCurrentEquippedItem().getItem() instanceof ItemFood) {
  910.                 if (isUsingTicks > cooldown_Ranged-2) {
  911.                     isUsing = false;
  912.                     isUsingTicks = 0;
  913.                     mc.gameSettings.keyBindUseItem.pressed = false;
  914.                     if (this.entityToAttack != null) {
  915.                         //this.aimAtEnt(entityToAttack);
  916.                         player.faceEntity(entityToAttack, 180, 180);
  917.                     }
  918.                     mc.playerController.onStoppedUsingItem(player);
  919.                 }
  920.             } else if (player.getCurrentEquippedItem().getItem() instanceof ItemFishingRod) {
  921.                 isUsing = false;
  922.                 isUsingTicks = 0;
  923.                 mc.gameSettings.keyBindUseItem.pressed = false;
  924.                 mc.playerController.onStoppedUsingItem(player);
  925.             } else {
  926.                 isUsing = false;
  927.                 isUsingTicks = 0;
  928.                 mc.gameSettings.keyBindUseItem.pressed = false;
  929.                 mc.playerController.onStoppedUsingItem(player);
  930.             }
  931.         } else {
  932.             isUsing = false;
  933.             isUsingTicks = 0;
  934.             mc.gameSettings.keyBindUseItem.pressed = false;
  935.             mc.playerController.onStoppedUsingItem(player);
  936.         }
  937.        
  938.     }
  939.    
  940.     public void walkTo(Entity var1, int x, int y, int z, float var2, int timeout) {
  941.         walkTo(var1, x, y, z, var2, timeout, 0);
  942.     }
  943.    
  944.     public void walkTo(Entity var1, int x, int y, int z, float var2, int timeout, int priority) {
  945.        
  946.         if (c_AIP.i.curCooldown_Pathfind <= 0) {
  947.             c_AIP.i.curCooldown_Pathfind = c_AIP.i.cooldown_Pathfind;
  948.             PFQueue.getPath(var1, x, y, z, maxPFRange, priority);
  949.             /*c_AIP.i.pathToEntity = null;//PFQueue.instance.createEntityPathTo(var1, x, y, z, maxPFRange);
  950.             if (c_AIP.i.pathToEntity == null) {
  951.                 //System.out.println("failllll");
  952.                 c_AIP.i.pathToEntity = PFQueue.instance.convertToPathEntityEx(var1.worldObj.getEntityPathToXYZ(var1, x, y, z, maxPFRange, true, true, true, true));
  953.                 PathPointEx var11 = new PathPointEx(MathHelper.floor_float(var1.width + 1.0F), MathHelper.floor_float(var1.height + 1.0F), MathHelper.floor_float(var1.width + 1.0F));
  954.                 c_AIP.i.pathToEntity = PFQueue.instance.simplifyPath(c_AIP.i.pathToEntity, var11);
  955.             }*/
  956.             c_AIP.i.setState(EnumActState.WALKING);
  957.             walkingTimeout = timeout;
  958.             c_AIP.i.targX = x;
  959.             c_AIP.i.targY = y;
  960.             c_AIP.i.targZ = z;
  961.         }
  962.     }
  963.    
  964.     public void walkTo(Entity var1, Entity target, float var2, int timeout, int priority) {
  965.         if (c_AIP.i.curCooldown_Pathfind <= 0) {
  966.             c_AIP.i.curCooldown_Pathfind = c_AIP.i.cooldown_Pathfind;
  967.             PFQueue.getPath(var1, target, maxPFRange, priority);
  968.             /*c_AIP.i.pathToEntity = null;//PFQueue.instance.createEntityPathTo(var1, x, y, z, maxPFRange);
  969.             if (c_AIP.i.pathToEntity == null) {
  970.                 //System.out.println("failllll");
  971.                 c_AIP.i.pathToEntity = PFQueue.instance.convertToPathEntityEx(var1.worldObj.getEntityPathToXYZ(var1, x, y, z, maxPFRange, true, true, true, true));
  972.                 PathPointEx var11 = new PathPointEx(MathHelper.floor_float(var1.width + 1.0F), MathHelper.floor_float(var1.height + 1.0F), MathHelper.floor_float(var1.width + 1.0F));
  973.                 c_AIP.i.pathToEntity = PFQueue.instance.simplifyPath(c_AIP.i.pathToEntity, var11);
  974.             }*/
  975.             c_AIP.i.setState(EnumActState.WALKING);
  976.             walkingTimeout = timeout;
  977.             c_AIP.i.targX = (int)target.posX;
  978.             c_AIP.i.targY = (int)target.posY;
  979.             c_AIP.i.targZ = (int)target.posZ;
  980.            
  981.             //System.out.println("walk to: ");
  982.         }
  983.     }
  984.    
  985.    
  986.    
  987.    
  988. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement