Skip to content

Instantly share code, notes, and snippets.

@BlockAfterBlock
Created May 16, 2011 03:35
Show Gist options
  • Select an option

  • Save BlockAfterBlock/973889 to your computer and use it in GitHub Desktop.

Select an option

Save BlockAfterBlock/973889 to your computer and use it in GitHub Desktop.
Mobs swarm and pretend to attack :(
package net.minecraft.src;
import java.util.List;
public class LMHNative1 extends EntityMob
{
public LMHNative1(World world)
{
super(world);
health = 26; //13 Hearts
texture = "/LMH/Native1.png";
//Note: Texture from sioux-six-four, improved by Evader
}
//Drops//////////////////////////
protected void dropFewItems()
{
int i = rand.nextInt(2);
for(int j = 0; j < i; j++){dropItem(Item.porkRaw.shiftedIndex, 1);}
i = rand.nextInt(3);
for(int k = 0; k < i; k++){dropItem(Item.bone.shiftedIndex, 1);}
i = rand.nextInt(3);
for(int r = 0; r < i; r++){dropItem(Item.arrow.shiftedIndex, 1);}
}
//Item Held////////////////////////
public ItemStack getHeldItem(){return defaultHeldItem;}
private static final ItemStack defaultHeldItem;
static{defaultHeldItem = new ItemStack(Item.bow, 1);}
//Sound//////////////////////////
/*
protected String getLivingSound(){return "mob.skeleton";}
protected String getHurtSound(){return "mob.skeletonhurt";}
protected String getDeathSound(){return "mob.skeletonhurt";}
*/
//Spawning/////////////////////////
public boolean getCanSpawnHere()
{
/*
int i = MathHelper.floor_double(posX);
int j = MathHelper.floor_double(boundingBox.minY);
int k = MathHelper.floor_double(posZ);
int spawnBlock = worldObj.getBlockId(i, j - 1, k);
*/
int rarity = 4;//12
if(rand.nextInt(rarity)== 0){
return worldObj.checkIfAABBIsClear(boundingBox) && worldObj.getCollidingBoundingBoxes(this, boundingBox).size() == 0 && !worldObj.getIsAnyLiquid(boundingBox);
// && (spawnBlock == Block.cobblestone.blockID || spawnBlock == Block.grass.blockID);
} else
return false;
}
public int getMaxSpawnedInChunk()
{
return 3;
}
//Attacking/////////////////////////
public boolean attackEntityFrom(Entity entity,int i)
{
seekProtectionFrom(entity);
if(entity instanceof LMHNative1 || entity instanceof LMHNative2 || entity instanceof LMHFemaleNative || entity instanceof LMHChiefNative)
{
return false;
} else
{
return super.attackEntityFrom(entity,i);
}
}
public void seekProtectionFrom(Entity entity)
{
List list = worldObj.getEntitiesWithinAABBExcludingEntity(this, boundingBox.expand(32D, 32D, 32D));
for(int j = 0; j < list.size(); j++)
{
Entity entity1 = (Entity)list.get(j);
if(entity1 instanceof LMHNative1)
{
LMHNative1 lmhnative1 = (LMHNative1)entity1;
lmhnative1.playerToAttack = entity;
this.playerToAttack = entity;
}
Entity entity2 = (Entity)list.get(j);
if(entity2 instanceof LMHNative2)
{
LMHNative2 lmhnative2 = (LMHNative2)entity2;
lmhnative2.playerToAttack = entity;
this.playerToAttack = entity;
}
Entity entity3 = (Entity)list.get(j);
if(entity3 instanceof LMHFemaleNative)
{
LMHFemaleNative lmhfemalenative = (LMHFemaleNative)entity3;
lmhfemalenative.playerToAttack = entity;
this.playerToAttack = entity;
}
Entity entity4 = (Entity)list.get(j);
if(entity4 instanceof LMHChiefNative)
{
LMHChiefNative lmhchiefnative = (LMHChiefNative)entity4;
lmhchiefnative.playerToAttack = entity;
this.playerToAttack = entity;
}
}
}
protected Entity findPlayerToAttack()
{
return null;
}
public EntityLiving getClosestTarget(Entity entity, double d)
{
double d1 = -1D;
EntityLiving entityliving = null;
for(int i = 0; i < worldObj.loadedEntityList.size(); i++)
{
Entity entity1 = (Entity)worldObj.loadedEntityList.get(i);
if(entity1 instanceof LMHBarbarian || entity1 instanceof LMHFemaleBarbarian || (entity1 instanceof EntityAnimal) && !(entity1 instanceof EntityWolf))
{
continue;
}
double d2 = entity1.getDistanceSq(entity.posX, entity.posY, entity.posZ);
if((d < 0.0D || d2 < d * d) && (d1 == -1D || d2 < d1) && ((EntityLiving)entity1).canEntityBeSeen(entity))
{
d1 = d2;
entityliving = (EntityLiving)entity1;
}
}
return entityliving;
}
protected void attackEntity(Entity entity, float f)
{
if(f < 10F)
{
double d = entity.posX - posX;
double d1 = entity.posZ - posZ;
if(attackTime == 0)
{
EntityArrow entityarrow = new EntityArrow(worldObj, this);
entityarrow.posY += 1.3999999761581421D;
double d2 = entity.posY - 0.20000000298023224D - entityarrow.posY;
float f1 = MathHelper.sqrt_double(d * d + d1 * d1) * 0.2F;
worldObj.playSoundAtEntity(this, "random.bow", 1.0F, 1.0F / (rand.nextFloat() * 0.4F + 0.8F));
worldObj.entityJoinedWorld(entityarrow);
entityarrow.setArrowHeading(d, d2 + (double)f1, d1, 0.6F, 12F);
attackTime = 40;
}
rotationYaw = (float)((Math.atan2(d1, d) * 180D) / 3.1415927410125732D) - 90F;
hasAttacked = true;
}
}
public double targetDistance;
protected int attackStrength;
//Other Stuff//////////////////////////
public void onUpdate()
{
super.onUpdate();
//noSelfHarm();
makeMobsTargetThis();
ticktimer--;
if(ticktimer == 0)
{
ticktimer = 1200;
mobTrigger = true;
}
}
private int ticktimer = 1200;
private boolean mobTrigger = true;
public void makeMobsTargetThis()
{
List targets = worldObj.getEntitiesWithinAABBExcludingEntity(this, boundingBox.expand(32, 32, 32));
for (int j = 0; j < targets.size(); j++)
{
Entity ent = (Entity) targets.get(j);
if (ent instanceof LMHBarbarian && canEntityBeSeen(ent))
{
LMHBarbarian lmhbarbarian = (LMHBarbarian)ent;
lmhbarbarian.playerToAttack = this;
} else if (ent instanceof LMHFemaleBarbarian && canEntityBeSeen(ent))
{
LMHFemaleBarbarian lmhfemalebarbarian = (LMHFemaleBarbarian)ent;
lmhfemalebarbarian.playerToAttack = this;
}
}
}
public void noSelfHarm()
{
if (playerToAttack == this)
{
playerToAttack = null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment