Guest User

Untitled

a guest
Jun 13th, 2015
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.28 KB | None | 0 0
  1. package com.ikingssgc.core.entity;
  2.  
  3. import java.util.List;
  4.  
  5. import scala.collection.generic.BitOperations.Int;
  6. import net.minecraft.client.Minecraft;
  7. import net.minecraft.entity.Entity;
  8. import net.minecraft.entity.EntityAgeable;
  9. import net.minecraft.entity.EntityLiving;
  10. import net.minecraft.entity.EntityLivingBase;
  11. import net.minecraft.entity.monster.EntityMob;
  12. import net.minecraft.entity.passive.EntityTameable;
  13. import net.minecraft.entity.player.EntityPlayer;
  14. import net.minecraft.util.DamageSource;
  15. import net.minecraft.util.Vec3;
  16. import net.minecraft.world.World;
  17.  
  18. import com.ikingssgc.client.gui.GuiK9;
  19.  
  20. public class EntityK9 extends EntityTameable {
  21.  
  22. public int powerLevel, maxPowerLevel;
  23. public int k9State = 0;
  24. public float stateTick = 0;
  25. public float velocityYaw = 0;
  26.  
  27. public boolean isFiring;
  28. public int lazerRenderCounter;
  29.  
  30. public EntityK9(World world) {
  31. super(world);
  32.  
  33. setSize(0.9375F, 0.9375F);
  34.  
  35.  
  36. ignoreFrustumCheck = true;
  37.  
  38.  
  39.  
  40. powerLevel = maxPowerLevel = 20;
  41. powerLevel = 10;
  42.  
  43. }
  44.  
  45. @Override
  46. protected void entityInit() {
  47. super.entityInit();
  48. this.dataWatcher.addObject(25, (isFiring) ? 1 : 0);
  49. }
  50.  
  51. public static final int k9Broken = 1200;
  52. public static final int k9NoPower = 1201;
  53. public static final int k9ModeMaxPower = 1202;
  54. public static final int k9ModeMaxDefense = 1203;
  55.  
  56. public void onUpdate(){
  57. super.onUpdate();
  58.  
  59. //System.out.println("K9 UPDATING:"+ticksExisted);
  60. if(k9State == this.k9ModeMaxDefense){
  61. stateTick++;
  62.  
  63. if(this.getAttackTarget() != null){
  64. faceEntity(this.getAttackTarget(), 100F, 100F);
  65. Vec3 vec3d = getLook(1.0F).normalize();
  66. Vec3 vec3d1 = Vec3.createVectorHelper(posX - this.getAttackTarget().posX,
  67. ((boundingBox.minY + (double)(height / 2.0F)) - this.getAttackTarget().posY),
  68. posZ - this.getAttackTarget().posZ);
  69. //double d = vec3d1.lengthVector();
  70. vec3d1 = vec3d1.normalize();
  71. double d1 = vec3d.dotProduct(vec3d1)*-1;
  72.  
  73.  
  74.  
  75. if(d1 > (getDistanceToEntity(this.getAttackTarget()) < 4 ? .9 : 0.7)){
  76. isFiring = true;
  77. lazerRenderCounter += (Math.abs(Math.sin(ticksExisted*0.1))+1)*5;
  78. this.getAttackTarget().attackEntityFrom(DamageSource.causeMobDamage(this), rand.nextInt(2)+2);
  79.  
  80. } else {
  81. isFiring = false;
  82.  
  83. }
  84. if(!canAttackEntity(this.getAttackTarget())){
  85. this.setAttackTarget(null);
  86. }
  87.  
  88.  
  89. this.dataWatcher.updateObject(25, (isFiring) ? 1 : 0);
  90.  
  91.  
  92. } else {
  93. if(stateTick > 20 && rand.nextInt(35) == 0){
  94. velocityYaw = (10 + rand.nextFloat()*4)*(rand.nextBoolean()?1:-1);
  95. }
  96. rotationYaw += velocityYaw;
  97. /*while(rotationYaw > 360) {
  98. rotationYaw -= 360;
  99. }
  100. while(rotationYaw < 0) {
  101. rotationYaw += 360;
  102. }*/
  103.  
  104. if(ticksExisted % 4 == 0){
  105. List<EntityLivingBase> list = worldObj.getEntitiesWithinAABB(EntityMob.class, boundingBox.expand(8, 8, 8));
  106. for(EntityLivingBase e : list){
  107.  
  108. if(canAttackEntity(e)){
  109. this.setAttackTarget(e);
  110. break;
  111. }
  112. }
  113. }
  114. }
  115. renderYawOffset = rotationYaw;
  116. }
  117.  
  118. double absSpeed = Math.abs(motionX)+Math.abs(motionY)+Math.abs(motionZ);
  119. for(int i = (int)(absSpeed*20)+(onGround?0:1); i > 0; i--){
  120. worldObj.spawnParticle("smoke", posX+rand.nextDouble()-.5, posY, posZ+rand.nextDouble()-.5,
  121. motionX*-.5, motionY*-.5-.07, motionZ*-.5);
  122. }
  123. if(motionY < 0){
  124. motionY *= .6;
  125. }
  126. }
  127.  
  128. public void putK9OnHead(EntityPlayer player, boolean flag) {
  129. if(flag) {
  130. this.mountEntity(player);
  131.  
  132. } else {
  133. this.mountEntity(null);
  134. }
  135.  
  136. }
  137.  
  138. public boolean canAttackEntity(Entity entity){
  139. return !entity.isDead && canEntityBeSeen(entity) && getDistanceToEntity(entity) <= 8 && ridingEntity == null && entity != Minecraft.getMinecraft().thePlayer && entity instanceof EntityMob;
  140. }
  141.  
  142.  
  143.  
  144. public void setState(int state){
  145. stateTick = 0;
  146. velocityYaw = 0;
  147. isFiring = false;
  148. lazerRenderCounter = 0;
  149. k9State = state;
  150. }
  151.  
  152. public void recharge(int amount){
  153. if(powerLevel >= maxPowerLevel){
  154. return;
  155. }
  156. powerLevel += amount;
  157. if(powerLevel >= maxPowerLevel){
  158. powerLevel = maxPowerLevel;
  159. }
  160. for(int i = 0; i < 7; i++)
  161. {
  162. double d = rand.nextGaussian() * 0.02D;
  163. double d1 = rand.nextGaussian() * 0.02D;
  164. double d2 = rand.nextGaussian() * 0.02D;
  165. worldObj.spawnParticle("crit", (posX + (double)(rand.nextFloat() * width * 2.0F)) - (double)width, posY + 0.3D + (double)(rand.nextFloat() * height), (posZ + (double)(rand.nextFloat() * width * 2.0F)) - (double)width, d, d1, d2);
  166. }
  167. }
  168.  
  169. public double getYOffset()
  170. {
  171. if(this.ridingEntity != null){
  172. return -1.13;
  173. }
  174. return (double)yOffset;
  175. }
  176.  
  177. public boolean attackEntityFrom(DamageSource damagesource, int i)
  178. {
  179. if(damagesource == DamageSource.inWall && ridingEntity != null) return false;
  180.  
  181. return super.attackEntityFrom(damagesource, (int) (i-rand.nextDouble()*i*.75));
  182. }
  183.  
  184. public boolean isInRangeToRenderVec3D(Vec3 vec3d)
  185. {
  186. return true;
  187. }
  188.  
  189. public boolean interact(EntityPlayer entityplayer)
  190. {
  191.  
  192. Minecraft.getMinecraft().displayGuiScreen(new GuiK9(this, entityplayer));
  193. return true;
  194. }
  195.  
  196. @Override
  197. public EntityAgeable createChild(EntityAgeable p_90011_1_) {
  198. // TODO Auto-generated method stub
  199. return null;
  200. }
  201. }
Advertisement
Add Comment
Please, Sign In to add comment