Skip to content

Instantly share code, notes, and snippets.

@BlockAfterBlock
Created May 20, 2011 01:00
Show Gist options
  • Save BlockAfterBlock/982130 to your computer and use it in GitHub Desktop.
Save BlockAfterBlock/982130 to your computer and use it in GitHub Desktop.
Entity Base
package net.minecraft.src;
import java.util.List;
public class LMHEntityBase extends EntityMob
{
public LMHEntityBase(World world)
{
super(world);
attackStrength = 2; //1 Heart per Hit
health = 20; //10 Hearts
// wayofattack = ("bow", "spear", "gun");
}
protected String wayofattack;
//Attacking
protected Entity findPlayerToAttack()
{
return null;
}
public boolean attackEntityFrom(Entity entity,int i)
{
seekProtectionFrom(entity);
{
return super.attackEntityFrom(entity,i);
}
}
//wayofattack ("bow", "spear", "gun")
protected void attackEntity(Entity entity, float f)
{
if(wayofattack == "bow")
{
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;
}
}
if(wayofattack == "spear")
{
if(f < 10F)
{
double d = entity.posX - posX;
double d1 = entity.posZ - posZ;
if(attackTime == 0)
{
LMHEntitySpear lmhentityspear = new LMHEntitySpear(worldObj, this);
lmhentityspear.posY += 1.3999999761581421D;
double d2 = entity.posY - 0.20000000298023224D - lmhentityspear.posY;
float f1 = MathHelper.sqrt_double(d * d + d1 * d1) * 0.2F;
worldObj.entityJoinedWorld(lmhentityspear);
lmhentityspear.setSpearHeading(d, d2 + (double)f1, d1, 0.6F, 12F);
attackTime = 90;
}
rotationYaw = (float)((Math.atan2(d1, d) * 180D) / 3.1415927410125732D) - 90F;
hasAttacked = true;
}
}
if(wayofattack == "gun")
{
if(f < 10F)
{
double d = entity.posX - posX;
double d1 = entity.posZ - posZ;
if(attackTime == 0)
{
LMHEntityBullet lmhentitybullet = new LMHEntityBullet(worldObj, this);
motionX = -MathHelper.sin((rotationYaw / 180F) * 3.141593F) * MathHelper.cos((rotationPitch / 180F) * 3.141593F);
motionZ = MathHelper.cos((rotationYaw / 180F) * 3.141593F) * MathHelper.cos((rotationPitch / 180F) * 3.141593F);
motionY = -MathHelper.sin((rotationPitch / 180F) * 3.141593F);
worldObj.playSoundAtEntity(this, "GunShot", 1.0F, 1.0F / (rand.nextFloat() * 0.4F + 0.8F));
worldObj.entityJoinedWorld(lmhentitybullet);
lmhentitybullet.setBulletHeading(motionX, motionY, motionZ, 20.0F, 0.000000001F);
attackTime = 100;
}
rotationYaw = (float)((Math.atan2(d1, d) * 180D) / 3.1415927410125732D) - 90F;
hasAttacked = true;
}
}
else
{
if ((double) f < 2D && entity.boundingBox.maxY > boundingBox.minY && entity.boundingBox.minY < boundingBox.maxY)
{
swingArm = true;
attackTime = 40;
if (entity instanceof EntityPlayer)
{
entity.attackEntityFrom(this, attackStrength);
}
}
}
}
//Update
public void onUpdate()
{
super.onUpdate();
noSelfHarm();
makeMobsTargetThis();
ticktimer--;
if(ticktimer == 0)
{
ticktimer = 1200;
mobTrigger = true;
}
}
public int ticktimer = 1200;
public boolean mobTrigger = true;
//noSelfHarm()
public void noSelfHarm()
{
if (playerToAttack == this)
{
playerToAttack = null;
}
}
//Arm Swing
public void onLivingUpdate()
{
super.onLivingUpdate();
if (swingArm) {
swingTick++;
if (swingTick == 8) {
swingTick = 0;
swingArm = false;
}
} else
{
swingTick = 0;
}
swingProgress = (float) swingTick / 8F;
}
public boolean swingArm = false;
public int swingTick = 0;
//Make Mobs Target This
public void makeMobsTargetThis()
{
if(this instanceof LMHNative1 || this instanceof LMHNative2 || this instanceof LMHChiefNative || this instanceof LMHFemaleNative)
{
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 lmhba = (LMHBarbarian)ent;
lmhba.playerToAttack = this;
}
if (ent instanceof LMHFemaleBarbarian && canEntityBeSeen(ent))
{
LMHFemaleBarbarian lmhfb = (LMHFemaleBarbarian)ent;
lmhfb.playerToAttack = this;
}
}
}
}
//Get Protection
public void seekProtectionFrom(Entity ent)
{
List list = worldObj.getEntitiesWithinAABBExcludingEntity(this, boundingBox.expand(32D, 32D, 32D));
for(int j = 0; j < list.size(); j++)
if(this instanceof LMHNative1 || this instanceof LMHNative2 || this instanceof LMHChiefNative || this instanceof LMHFemaleNative)
{
Entity ent1 = (Entity)list.get(j);
if(ent1 instanceof LMHNative1)
{
LMHNative1 lmhn1 = (LMHNative1)ent1;
lmhn1.playerToAttack = ent;
this.playerToAttack = ent;
}
Entity ent2 = (Entity)list.get(j);
if(ent2 instanceof LMHNative2)
{
LMHNative2 lmhn2 = (LMHNative2)ent2;
lmhn2.playerToAttack = ent;
this.playerToAttack = ent;
}
Entity ent3 = (Entity)list.get(j);
if(ent3 instanceof LMHFemaleNative)
{
LMHFemaleNative lmhfn = (LMHFemaleNative)ent3;
lmhfn.playerToAttack = ent;
this.playerToAttack = ent;
}
Entity ent4 = (Entity)list.get(j);
if(ent4 instanceof LMHChiefNative)
{
LMHChiefNative lmhcn = (LMHChiefNative)ent4;
lmhcn.playerToAttack = ent;
this.playerToAttack = ent;
}
}
for(int i = 0; i < list.size(); i++)
if(this instanceof LMHBarbarian || this instanceof LMHFemaleBarbarian)
{
Entity ent1 = (Entity)list.get(i);
if(ent1 instanceof LMHBarbarian)
{
LMHBarbarian lmhba = (LMHBarbarian)ent1;
lmhba.playerToAttack = ent;
this.playerToAttack = ent;
}
Entity ent2 = (Entity)list.get(i);
if(ent2 instanceof LMHFemaleBarbarian)
{
LMHFemaleBarbarian lmhfb = (LMHFemaleBarbarian)ent2;
lmhfb.playerToAttack = ent;
this.playerToAttack = ent;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment