Advertisement
Corosus

EntityHooks

Aug 26th, 2011
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 18.69 KB | None | 0 0
  1. package net.minecraft.src;
  2.  
  3. import java.util.List;
  4.  
  5. // Referenced classes of package net.minecraft.src:
  6. //            Entity, Vec3D, StepSound, AxisAlignedBB,
  7. //            World, MathHelper, Material, NBTTagCompound,
  8. //            Block, MovingObjectPosition, ItemStack
  9.  
  10. public abstract class EntityHooks extends EntityLiving {
  11.    
  12.     private static boolean sdkGrapplingHookNotFound = false;
  13.     private static int sdkBlockRopeId = -1;
  14.    
  15.     public int uID;
  16.     public int mobtype;
  17.     public int team;
  18.     public int orders;
  19.     public int guardX;
  20.     public int guardY;
  21.     public int guardZ;
  22.     public int enhanced;
  23.     public int guardEntID;
  24.     public int mountEntID;
  25.     public int kills;
  26.    
  27.    
  28.     public Entity guardEnt;
  29.     public Entity attackingEnt;
  30.     public int state;
  31.     public int maxhealth;
  32.     public int AIDelay;
  33.     public int mineDelay;
  34.     public int PFDelay;
  35.     public float curBlockDmg;
  36.     public int curBlockX;
  37.     public int curBlockZ;
  38.     public boolean mining;
  39.     public boolean forcejump;
  40.     public int noMoveTicks;
  41.     public float info;
  42.     public String info2;
  43.     public int nearbyMinerCount;
  44.     public boolean canSwitchTarget;
  45.     public boolean noTick;
  46.    
  47.     public float pathFollowDist = 2.0F;
  48.    
  49.     public int noSeeTicks = 0;
  50.     public int pathfindDelay = 0;
  51.     public float plDist;
  52.    
  53.     public boolean swingArm = false;
  54.     public int swingTick = 0;
  55.    
  56.     public int lastNodeTimer;
  57.     public int lastNode;
  58.    
  59.     public PathfinderEnh pf;
  60.    
  61.     public EntityHooks(World world)
  62.     {
  63.         super(world);
  64.        
  65.         //
  66.         uID = -1;
  67.         mobtype = 0;
  68.         team = 0;
  69.         orders = 0;
  70.         guardX = -1;
  71.         guardY = -1;
  72.         guardZ = -1;
  73.         enhanced = 0;
  74.         guardEntID = -1;
  75.         mountEntID = -1;
  76.         guardEnt = null;
  77.         attackingEnt = null;
  78.         maxhealth = 0;
  79.         noTick = false;
  80.         pathFollowDist = 1.2F;
  81.        
  82.         pf = new PathfinderEnh(world);
  83.         //
  84.        
  85.         EntAPI.RunHooks_Init((EntityCreature)this,world);
  86.     }
  87.    
  88.    
  89.    
  90.    
  91.     //Main Hooks
  92.    
  93.     public void onUpdate()
  94.     {
  95.         EntAPI.RunHooks_onUpdate_pre((EntityCreature)this);
  96.         super.onUpdate();
  97.         EntAPI.RunHooks_onUpdate_post((EntityCreature)this);
  98.        
  99.     }
  100.    
  101.     public boolean canClimb() {
  102.         if (/*this instanceof EntityCreeper || */this instanceof EntityCreeper && false) {
  103.             return true;
  104.         }
  105.         return false;
  106.     }
  107.    
  108.     public boolean isOnLadder() {
  109.         if (canClimb() && this.isCollidedHorizontally) {
  110.             return true;
  111.         }
  112.         return false;
  113.     }
  114.    
  115.     public boolean attackEntityFrom(Entity entity, int i)
  116.     {
  117.         if (EntAPI.RunHooks_AttackEntityFrom((EntityCreature)this, entity, i)) {
  118.             return super.attackEntityFrom(entity, i);
  119.         }
  120.         return false;
  121.     }
  122.    
  123.     public void writeEntityToNBT(NBTTagCompound nbttagcompound)
  124.     {
  125.         nbttagcompound.setShort("uID", (short)this.uID);
  126.         nbttagcompound.setShort("MobType", (short)this.mobtype);
  127.         nbttagcompound.setShort("Team", (short)this.team);
  128.         nbttagcompound.setShort("Orders", (short)this.orders);
  129.         nbttagcompound.setShort("guardX", (short)this.guardX);
  130.         nbttagcompound.setShort("guardY", (short)this.guardY);
  131.         nbttagcompound.setShort("guardZ", (short)this.guardZ);
  132.         nbttagcompound.setShort("enhanced", (short)this.enhanced);
  133.         nbttagcompound.setShort("guardEntID", (short)this.guardEntID);
  134.         nbttagcompound.setShort("mineDelay", (short)this.mineDelay);
  135.         nbttagcompound.setShort("kills", (short)this.kills);
  136.        
  137.  
  138.        
  139.        
  140.         super.writeEntityToNBT(nbttagcompound);
  141.         EntAPI.RunHooks_Saved((EntityCreature)this, nbttagcompound);
  142.     }
  143.    
  144.     public void readEntityFromNBT(NBTTagCompound nbttagcompound)
  145.     {
  146.         this.uID = nbttagcompound.getShort("uID");
  147.         this.mobtype = nbttagcompound.getShort("MobType");
  148.         this.team = nbttagcompound.getShort("Team");
  149.         this.orders = nbttagcompound.getShort("Orders");
  150.         this.guardX = nbttagcompound.getShort("guardX");
  151.         this.guardY = nbttagcompound.getShort("guardY");
  152.         this.guardZ = nbttagcompound.getShort("guardZ");
  153.         this.enhanced = nbttagcompound.getShort("enhanced");
  154.         this.guardEntID = nbttagcompound.getShort("guardEntID");
  155.         this.mountEntID = nbttagcompound.getShort("mountEntID");
  156.         this.mineDelay = nbttagcompound.getShort("mineDelay");
  157.         this.kills = nbttagcompound.getShort("kills");
  158.  
  159.         if(this instanceof EntityMob) {
  160.             this.maxhealth = 20;
  161.         /*} else if(this instanceof EntityPlayer) {
  162.             this.maxhealth = 20;
  163.             firstTick = true;
  164.             this.team = playerTeamInit;*/
  165.         } else if(this instanceof EntityAnimal) {
  166.             this.maxhealth = 10;
  167.         }
  168.  
  169.         if(this.health > this.maxhealth) {
  170.             this.maxhealth = this.health;
  171.         }
  172.  
  173.         if(mod_AITools.isGuardian(this)) {
  174.             this.noTick = true;
  175.         }
  176.        
  177.         super.readEntityFromNBT(nbttagcompound);
  178.         EntAPI.RunHooks_Loaded((EntityCreature)this, nbttagcompound);
  179.     }
  180.    
  181.     public void setEntityDead() {
  182.         //System.out.println("hmmm!");
  183.         if (deathTime < 1 && team == 1) { return; }
  184.         super.setEntityDead();
  185.     }
  186.    
  187.     public void onDeath(Entity var1) {
  188.         EntAPI.RunHooks_Killed((EntityCreature)this, var1);
  189.           if(this instanceof EntityAnimal) {
  190.              mod_PathingActivated.spawnScent(this);
  191.           }
  192.  
  193.           super.onDeath(var1);
  194.        }
  195.    
  196.     protected void tryAttackEntity(Entity var1, float var2) {
  197.        
  198.         if (EntAPI.RunHooks_TryAttackEntity(this, var1, var2)) {
  199.             this.attackEntity(var1, var2);
  200.         }
  201.     }
  202.    
  203.     protected Entity tryFindPlayer() {
  204.         Entity ent = findPlayerToAttack();
  205.         if (mod_PathingActivated.sameTeam(this, ent)) {
  206.             return null;
  207.         } else {
  208.             return ent;
  209.         }
  210.        
  211.     }
  212.    
  213.     protected Entity findPlayerToAttack() {
  214.         return null;
  215.     }
  216.    
  217.    
  218.     protected void attackEntity(Entity var1, float var2) {}
  219.    
  220.     public int getTalkInterval()
  221.     {
  222.         if (team == 1) {
  223.             return 400;
  224.         }
  225.         return 80;
  226.     }
  227.    
  228.     //Entity creature stuff
  229.    
  230.     protected void updatePlayerActionState() {
  231.         super.updatePlayerActionState();
  232.     }
  233.    
  234.     public Entity getTarget() {
  235.         return null;
  236.     }
  237.    
  238.     public boolean shouldFaceTarget() {
  239.        
  240.         //if (mod_PathingActivated.hasPetMod) {
  241.             //System.out.println(state);
  242.             (new StringBuilder()).append("state - ").append(state).toString();
  243.             if(state != 1) {
  244.                 if((state == 3 || state == 4) && getTarget() != null) {
  245.                     if(state == 3) {
  246.                        
  247.                         if (this.guardEnt != null && this.getDistanceToEntity(this.guardEnt) > 32.0F) {
  248.                             if (teleportToTarget(this.guardEnt)) {
  249.                                 setPathToEntity(null);
  250.                             }
  251.                         }
  252.                        
  253.                         if (this.guardEnt != null && isSolidPath(this.guardEnt)) {
  254.                             setPathToEntity(null);
  255.                            
  256.                            
  257.                             this.moveForward = this.moveSpeed;
  258.                             faceEntity(this.guardEnt, 30.0F, 30.0F);
  259.                             //faceEntity(getTarget(), 30.0F, 30.0F);
  260.                             //System.out.println(getTarget());
  261.                             return true;
  262.                         }
  263.                        
  264.                         //faceEntity(this.guardEnt, 30.0F, 30.0F);
  265.                         return false;
  266.                         /*d1 = guardEnt.posX - posX;
  267.                         d2 = guardEnt.posZ - posZ;
  268.                         double d5 = guardEnt.posY - (double)i;*/
  269.                     } else if(state == 4) {
  270.                         if (getTarget() != null && (isSolidPath(getTarget()) || this.getPath() == null)) {
  271.                             this.moveForward = this.moveSpeed;
  272.                             faceEntity(getTarget(), 30.0F, 30.0F);
  273.                             setPathToEntity(null);
  274.                             return true;
  275.                         }
  276.                         return false;
  277.                         /*d1 = playerToAttack.posX - posX;
  278.                         d2 = playerToAttack.posZ - posZ;
  279.                         double d6 = playerToAttack.posY - (double)i;*/
  280.                     }
  281.                 } else if(state == 2) {
  282.                     return false;
  283.                     //this code is depreciated, pet mod needs to try to pathfind to this spot
  284.                     //d1 = (double)guardX - posX;
  285.                     //d2 = (double)guardZ - posZ;
  286.                     //double d7 = (double)guardY - (double)i;
  287.                 }
  288.             }
  289.            
  290.            
  291.         //} else {
  292.            
  293.             if(this.isCollidedHorizontally) {
  294.                 this.isJumping = true;
  295.              }
  296.        
  297.             /*if (((EntityCreature)this).getTarget() != null && (isSolidPath(((EntityCreature)this).getTarget()) || this.getPath() == null)) {
  298.                 return true;
  299.             }*/
  300.        
  301.         //}
  302.        
  303.         return false;
  304.     }
  305.    
  306.    
  307.  
  308.    public boolean shouldTarget(Entity var1) {
  309.        if (mod_PathingActivated.sameTeam(this, var1)) {
  310.            /*if (getDistanceToEntity(var1) < 5.0F) {
  311.                return false;
  312.            }*/
  313.            return false;
  314.        }
  315.       if(mod_PathingActivated.useEnt(this) && !(this instanceof EntityWolf)) {
  316.          if(mod_PathingActivated.OmnipotentHostiles.get().booleanValue()) {
  317.             return true;
  318.          } else {
  319.             float var2 = (float)mod_PathingActivated.AwarenessRange.get().intValue();
  320.             this.plDist = this.getDistanceToEntity(var1);
  321.             return this.plDist <= var2 && (this.canEntityBeSeen(var1) || mod_PathingActivated.XRayVision.get());
  322.          }
  323.       } else {
  324.          return false;
  325.       }
  326.    }
  327.    
  328.    public boolean isSolidPath(Entity var1) {
  329.        if (this.team != 1 && !mod_PathingActivated.useEnt(this)) { return true; }
  330.        if (this.getDistanceToEntity(var1) > mod_PathingActivated.MaxPFRange.get()) { return true; }
  331.       return this.canEntityBeSeen(var1) && (this.getDistanceToEntity(var1) < 5.0F) && Math.abs(this.posY - (double)this.yOffset - (var1.posY - (double)var1.yOffset)) <= 3.5D;
  332.    }
  333.    
  334.    public boolean shouldPath() {
  335.       return mod_PathingActivated.useEnt(this);
  336.    }
  337.    
  338.    public boolean tryPath(Entity var1, float var2) {
  339.        return tryPath(var1, var2, false);
  340.    }
  341.  
  342.    public boolean tryPath(Entity var1, float var2, boolean pet) {
  343.        if (pathfindDelay > 0) { return false; }
  344.        
  345.        if (mod_PathingActivated.hasPetMod) {
  346.            if (mod_PathingActivated.sameTeam(this, var1) && !pet) {
  347.                return false;
  348.            }
  349.        }
  350.        
  351.       if((this.shouldPath() || pet) && var1 != null) {
  352.          float var3 = this.getDistanceToEntity(var1);
  353.          if(var3 > var2) {
  354.             return false;
  355.          } else {
  356.              //mod_MovePlus.displayMessage((new StringBuilder()).append("PFCount: ").append(mod_PathingActivated.PFCount++).toString());
  357.              pathfindDelay = (int)var2*2 + rand.nextInt(100);
  358.              setPathToEntity(pf.getPathToEntity(this, var1, var2, canClimb()));
  359.              //System.out.println(this);
  360.              //setPathToEntity(this.worldObj.getPathToEntity(this, var1, var2));
  361.              if(this.getPath() == null)
  362.              {
  363.                  pathfindDelay = (int)var2*2 + rand.nextInt(200);
  364.              }
  365.              
  366.             return true;
  367.          }
  368.       } else {
  369.          return false;
  370.       }
  371.    }
  372.  
  373.    public boolean tryPathXYZ(int x, int y, int z, float var2) {
  374.        if (pathfindDelay > 0) { return false; }
  375.        
  376.          float var3 = (float)this.getDistance((double)x, (double)y, (double)z);
  377.          if(var3 > var2) {
  378.             return false;
  379.          } else {
  380.              //mod_MovePlus.displayMessage((new StringBuilder()).append("PFCount: ").append(mod_PathingActivated.PFCount++).toString());
  381.              //System.out.println("path XYZ");
  382.              pathfindDelay = (int)var2*2 + rand.nextInt(100);
  383.              setPathToEntity(this.worldObj.getEntityPathToXYZ(this, x, y, z, var2));
  384.              if(this.getPath() == null)
  385.              {
  386.                  pathfindDelay = (int)var2*2 + rand.nextInt(200);
  387.              }
  388.             return true;
  389.          }
  390.          //return false;
  391.      
  392.    }
  393.    
  394.    public PathEntity getPath() {
  395.        return null;
  396.    }
  397.    
  398.    public void setPathToEntity(PathEntity var1) {
  399.      
  400.    }
  401.  
  402.    public float getPathDist() {
  403.       float var1 = this.plDist + 32.0F;
  404.       if(var1 > (float)mod_PathingActivated.MaxPFRange.get()) {
  405.          var1 = (float)mod_PathingActivated.MaxPFRange.get();
  406.       }
  407.  
  408.       if((float)mod_PathingActivated.MaxPFRange.get().intValue() > 0.0F) {
  409.          var1 = (float)mod_PathingActivated.MaxPFRange.get().intValue();
  410.       }
  411.  
  412.       return var1;
  413.    }
  414.  
  415.    public static boolean notMoving(EntityLiving var0, float var1) {
  416.       double var2 = var0.prevPosX - var0.posX;
  417.       double var4 = var0.prevPosZ - var0.posZ;
  418.       float var6 = (float)Math.sqrt(var2 * var2 + var4 * var4);
  419.       return var6 < var1;
  420.    }
  421.  
  422.    public float getXZDistanceToEntity(Entity var1) {
  423.       float var2 = (float)(this.posX - var1.posX);
  424.       float var3 = (float)(this.posZ - var1.posZ);
  425.       return (float)Math.sqrt((double)(var2 * var2 + var3 * var3));
  426.    }
  427.  
  428.    
  429.  
  430.    public void onLivingUpdate() {
  431.        
  432.       if (mod_PathingActivated.hasNMMode) {
  433.           if (mod_NMMode.entFireImmune(this)) {
  434.               this.fire = 0;
  435.           }
  436.       }
  437.      
  438.       if (mod_PathingActivated.hasPetMod) {
  439.           if (this.team == 1) {
  440.               this.fire = 0;
  441.           }
  442.       }
  443.  
  444.       super.onLivingUpdate();
  445.      
  446.       if(swingArm) {
  447.             if (swingTick > 3 && swingTick < 9) {
  448.                 swingTick+=2;
  449.             } else {
  450.                 swingTick++;
  451.             }
  452.  
  453.             if(swingTick >= 24) {
  454.                 swingTick = 0;
  455.                 swingArm = false;
  456.             }
  457.         } else {
  458.             swingTick = 0;
  459.         }
  460.  
  461.         if (swingTick <= 16) {
  462.             swingProgress = (float)swingTick / 8F;
  463.         } else {
  464.             swingProgress = 0F;
  465.         }
  466.    }
  467.    
  468.    
  469.     //Feature extra overrides
  470.    
  471.     public void moveEntity(double d, double d1, double d2) {
  472.         //AI Added
  473.         if(orders != 2) {
  474.             if(enhanced == 1) {
  475.                 if(!mod_PathingActivated.freezePets || team != 1) {
  476.                     super.moveEntity(motionX * (double)mod_PathingActivated.enhPetSpeedMultiplier, motionY, motionZ * (double)mod_PathingActivated.enhPetSpeedMultiplier);
  477.                 }
  478.             } else if(!mod_PathingActivated.freezePets || team != 1) {
  479.                 super.moveEntity(motionX, motionY, motionZ);
  480.             }
  481.         } else {
  482.             super.moveEntity(0.0D, motionY, 0.0D);
  483.         }
  484.     }
  485.    
  486.     protected boolean canDespawn()
  487.     {
  488.         //AI Modded
  489.         if (team != 1 && orders == 0) {
  490.             return true;
  491.         } return false;
  492.     }
  493.    
  494.     public boolean isInRangeToRenderVec3D(Vec3D vec3d) {
  495.         if(mod_PathingActivated.unlimitedEntityRenderRange) {
  496.             return true;
  497.         } else {
  498.             double d = posX - vec3d.xCoord;
  499.             double d1 = posY - vec3d.yCoord;
  500.             double d2 = posZ - vec3d.zCoord;
  501.             double d3 = d * d + d1 * d1 + d2 * d2;
  502.             return isInRangeToRenderDist(d3);
  503.         }
  504.     }
  505.    
  506.     public void applyEntityCollision(Entity entity) {
  507.         if(entity.riddenByEntity == this || entity.ridingEntity == this) {
  508.             return;
  509.         }
  510.  
  511.         double d = entity.posX - posX;
  512.         double d1 = entity.posY - posY;
  513.         double d2 = entity.posZ - posZ;
  514.         double d3 = MathHelper.abs_max(d, d2);
  515.         d3 = MathHelper.abs_max(d, d1);
  516.  
  517.         if(d3 >= 0.0099999997764825821D) {
  518.             d3 = MathHelper.sqrt_double(d3);
  519.             d /= d3;
  520.             d1 /= d3;
  521.             d2 /= d3;
  522.             double d4 = 1.0D / d3;
  523.  
  524.             if(d4 > 1.0D) {
  525.                 d4 = 1.0D;
  526.             }
  527.  
  528.             d *= d4;
  529.             d1 *= d4;
  530.             d2 *= d4;
  531.             d *= 0.05000000074505806D;
  532.             d1 *= 0.05000000074505806D;
  533.             d2 *= 0.05000000074505806D;
  534.             d *= 1.0F - entityCollisionReduction;
  535.             d2 *= 1.0F - entityCollisionReduction;
  536.            
  537.             if (!mod_PathingActivated.VerticalCollision) {
  538.                 d1 = 0;
  539.             }
  540.  
  541.             if(mod_PathingActivated.NothingPushesPlayer) {
  542.                 /*if(!(this instanceof EntityPlayer)) {
  543.                     addVelocity(-d, -d1, -d2);
  544.                 }*/
  545.                 addVelocity(-d, -d1, -d2);
  546.                 if(!(entity instanceof EntityPlayer)) {
  547.                     entity.addVelocity(d, d1, d2);
  548.                 }
  549.             } else {
  550.                 addVelocity(-d, -d1, -d2);
  551.                 entity.addVelocity(d, d1, d2);
  552.             }
  553.         }
  554.     }
  555.    
  556.     public boolean isEntityInsideOpaqueBlock()
  557.     {
  558.        
  559.         if (this.ridingEntity != null) {
  560.             return false;
  561.         }
  562.        
  563.         for(int i = 0; i < 8; i++)
  564.         {
  565.             float f = ((float)((i >> 0) % 2) - 0.5F) * width * 0.9F;
  566.             float f1 = ((float)((i >> 1) % 2) - 0.5F) * 0.1F;
  567.             float f2 = ((float)((i >> 2) % 2) - 0.5F) * width * 0.9F;
  568.             int j = MathHelper.floor_double(posX + (double)f);
  569.             int k = MathHelper.floor_double(posY + (double)getEyeHeight() + (double)f1);
  570.             int l = MathHelper.floor_double(posZ + (double)f2);
  571.             if(worldObj.isBlockNormalCube(j, k, l))
  572.             {
  573.                 return true;
  574.             }
  575.         }
  576.  
  577.         return false;
  578.     }
  579.    
  580.     public boolean teleportToTarget(Entity var1) {
  581.            int var4 = MathHelper.floor_double(var1.posX) - 2;
  582.            int var5 = MathHelper.floor_double(var1.posZ) - 2;
  583.            int var6 = MathHelper.floor_double(var1.boundingBox.minY);
  584.  
  585.            for(int var7 = 0; var7 <= 4; ++var7) {
  586.               for(int var8 = 0; var8 <= 4; ++var8) {
  587.                  if((var7 < 1 || var8 < 1 || var7 > 3 || var8 > 3) &&
  588.                          this.worldObj.isBlockNormalCube(var4 + var7, var6 - 1, var5 + var8) &&
  589.                          !this.worldObj.isBlockNormalCube(var4 + var7, var6, var5 + var8) &&
  590.                          !this.worldObj.isBlockNormalCube(var4 + var7+1, var6, var5 + var8) &&
  591.                          !this.worldObj.isBlockNormalCube(var4 + var7, var6, var5 + var8+1) &&
  592.                          !this.worldObj.isBlockNormalCube(var4 + var7+1, var6, var5 + var8+1) &&
  593.                          
  594.                          !this.worldObj.isBlockNormalCube(var4 + var7, var6 + 1, var5 + var8) &&
  595.                          !this.worldObj.isBlockNormalCube(var4 + var7+1, var6 + 1, var5 + var8) &&
  596.                          !this.worldObj.isBlockNormalCube(var4 + var7, var6 + 1, var5 + var8+1) &&
  597.                          !this.worldObj.isBlockNormalCube(var4 + var7+1, var6 + 1, var5 + var8+1)) {
  598.                     this.setLocationAndAngles((double)((float)(var4 + var7) + 0.5F), (double)var6, (double)((float)(var5 + var8) + 0.5F), this.rotationYaw, this.rotationPitch);
  599.                     return true;
  600.                  }
  601.               }
  602.            }
  603.            
  604.            return false;
  605.  
  606.      }
  607. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement