Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.ikingssgc.core.entity;
- import java.util.List;
- import scala.collection.generic.BitOperations.Int;
- import net.minecraft.client.Minecraft;
- import net.minecraft.entity.Entity;
- import net.minecraft.entity.EntityAgeable;
- import net.minecraft.entity.EntityLiving;
- import net.minecraft.entity.EntityLivingBase;
- import net.minecraft.entity.monster.EntityMob;
- import net.minecraft.entity.passive.EntityTameable;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.util.DamageSource;
- import net.minecraft.util.Vec3;
- import net.minecraft.world.World;
- import com.ikingssgc.client.gui.GuiK9;
- public class EntityK9 extends EntityTameable {
- public int powerLevel, maxPowerLevel;
- public int k9State = 0;
- public float stateTick = 0;
- public float velocityYaw = 0;
- public boolean isFiring;
- public int lazerRenderCounter;
- public EntityK9(World world) {
- super(world);
- setSize(0.9375F, 0.9375F);
- ignoreFrustumCheck = true;
- powerLevel = maxPowerLevel = 20;
- powerLevel = 10;
- }
- @Override
- protected void entityInit() {
- super.entityInit();
- this.dataWatcher.addObject(25, (isFiring) ? 1 : 0);
- }
- public static final int k9Broken = 1200;
- public static final int k9NoPower = 1201;
- public static final int k9ModeMaxPower = 1202;
- public static final int k9ModeMaxDefense = 1203;
- public void onUpdate(){
- super.onUpdate();
- //System.out.println("K9 UPDATING:"+ticksExisted);
- if(k9State == this.k9ModeMaxDefense){
- stateTick++;
- if(this.getAttackTarget() != null){
- faceEntity(this.getAttackTarget(), 100F, 100F);
- Vec3 vec3d = getLook(1.0F).normalize();
- Vec3 vec3d1 = Vec3.createVectorHelper(posX - this.getAttackTarget().posX,
- ((boundingBox.minY + (double)(height / 2.0F)) - this.getAttackTarget().posY),
- posZ - this.getAttackTarget().posZ);
- //double d = vec3d1.lengthVector();
- vec3d1 = vec3d1.normalize();
- double d1 = vec3d.dotProduct(vec3d1)*-1;
- if(d1 > (getDistanceToEntity(this.getAttackTarget()) < 4 ? .9 : 0.7)){
- isFiring = true;
- lazerRenderCounter += (Math.abs(Math.sin(ticksExisted*0.1))+1)*5;
- this.getAttackTarget().attackEntityFrom(DamageSource.causeMobDamage(this), rand.nextInt(2)+2);
- } else {
- isFiring = false;
- }
- if(!canAttackEntity(this.getAttackTarget())){
- this.setAttackTarget(null);
- }
- this.dataWatcher.updateObject(25, (isFiring) ? 1 : 0);
- } else {
- if(stateTick > 20 && rand.nextInt(35) == 0){
- velocityYaw = (10 + rand.nextFloat()*4)*(rand.nextBoolean()?1:-1);
- }
- rotationYaw += velocityYaw;
- /*while(rotationYaw > 360) {
- rotationYaw -= 360;
- }
- while(rotationYaw < 0) {
- rotationYaw += 360;
- }*/
- if(ticksExisted % 4 == 0){
- List<EntityLivingBase> list = worldObj.getEntitiesWithinAABB(EntityMob.class, boundingBox.expand(8, 8, 8));
- for(EntityLivingBase e : list){
- if(canAttackEntity(e)){
- this.setAttackTarget(e);
- break;
- }
- }
- }
- }
- renderYawOffset = rotationYaw;
- }
- double absSpeed = Math.abs(motionX)+Math.abs(motionY)+Math.abs(motionZ);
- for(int i = (int)(absSpeed*20)+(onGround?0:1); i > 0; i--){
- worldObj.spawnParticle("smoke", posX+rand.nextDouble()-.5, posY, posZ+rand.nextDouble()-.5,
- motionX*-.5, motionY*-.5-.07, motionZ*-.5);
- }
- if(motionY < 0){
- motionY *= .6;
- }
- }
- public void putK9OnHead(EntityPlayer player, boolean flag) {
- if(flag) {
- this.mountEntity(player);
- } else {
- this.mountEntity(null);
- }
- }
- public boolean canAttackEntity(Entity entity){
- return !entity.isDead && canEntityBeSeen(entity) && getDistanceToEntity(entity) <= 8 && ridingEntity == null && entity != Minecraft.getMinecraft().thePlayer && entity instanceof EntityMob;
- }
- public void setState(int state){
- stateTick = 0;
- velocityYaw = 0;
- isFiring = false;
- lazerRenderCounter = 0;
- k9State = state;
- }
- public void recharge(int amount){
- if(powerLevel >= maxPowerLevel){
- return;
- }
- powerLevel += amount;
- if(powerLevel >= maxPowerLevel){
- powerLevel = maxPowerLevel;
- }
- for(int i = 0; i < 7; i++)
- {
- double d = rand.nextGaussian() * 0.02D;
- double d1 = rand.nextGaussian() * 0.02D;
- double d2 = rand.nextGaussian() * 0.02D;
- 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);
- }
- }
- public double getYOffset()
- {
- if(this.ridingEntity != null){
- return -1.13;
- }
- return (double)yOffset;
- }
- public boolean attackEntityFrom(DamageSource damagesource, int i)
- {
- if(damagesource == DamageSource.inWall && ridingEntity != null) return false;
- return super.attackEntityFrom(damagesource, (int) (i-rand.nextDouble()*i*.75));
- }
- public boolean isInRangeToRenderVec3D(Vec3 vec3d)
- {
- return true;
- }
- public boolean interact(EntityPlayer entityplayer)
- {
- Minecraft.getMinecraft().displayGuiScreen(new GuiK9(this, entityplayer));
- return true;
- }
- @Override
- public EntityAgeable createChild(EntityAgeable p_90011_1_) {
- // TODO Auto-generated method stub
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment