[Answered/Solved] Making custom mobs fly
3 posters
MC Modding :: Modding :: Singleplayer Modding :: Requests
Page 1 of 1
[Answered/Solved] Making custom mobs fly
a lot of people (including me) do not know the code to throw in the entity file to make a mob be a flying mob therefore it will be really useful
Last edited by Ranga179 on Sat Nov 26, 2011 7:56 am; edited 1 time in total
Ranga179- Member
- Posts : 9
Join date : 2011-10-19
Age : 28
Re: [Answered/Solved] Making custom mobs fly
yes someone plz help him (and me)
megahostile123- Member
- Posts : 4
Join date : 2011-11-06
ikke009- Member
- Posts : 65
Join date : 2011-10-24
Age : 30
Location : The netherlands
Re: [Answered/Solved] Making custom mobs fly
i have figured it out, i don't know how to explain too well, i just had a look at the code from another mod and searched for the correct part but anyways: here is my full files code:
and the part the makes it fly and do damage when you are close is this bit:
you guys should be able to figureout what the rest does. and if you use this code you will need to change some names of course
- Spoiler:
- Code:
package net.minecraft.src;
public class rangcraft_EntityLeviProtector extends EntityMob
{
public rangcraft_EntityLeviProtector(World world)
{
super(world);
texture = "/RangCraft/mobs/LeviProtector.png";
moveSpeed = 0.5F;
attackStrength = 6;
isImmuneToFire = false;
health = 16;
size=4.5F;
}
protected int getDropItemId()
{
return mod_RangCraft.LeviFrag.shiftedIndex;
}
public boolean attackEntityFrom(DamageSource damagesource, int i)
{
if(super.attackEntityFrom(damagesource, i))
{
Entity entity = damagesource.getEntity();
if(riddenByEntity == entity || ridingEntity == entity)
{
return true;
}
if(entity != this && entity != null)
{
entityToAttack = entity;
}
return true;
} else
{
return false;
}
}
public void onLivingUpdate()
{
super.onLivingUpdate();
groundDistance = distanceToGround();
if(isEntityAlive())
{
if(!flying)
{
if(groundDistance > 5)
{
motionY = -0.01D;
}
flyTime = rand.nextInt(100) + 100;
if(posY < 110D && entityToAttack == null)
{
motionY = 0.02D;
}
} else
{
flyTime--;
motionY = 0.02D;
if(posY > 128D)
{
flying = false;
}
if(flyTime <= 0)
{
flying = false;
}
}
if(rand.nextInt(30) == 0)
{
flying = true;
}
if(groundDistance < 5)
{
motionY = 0.20000000000000001D;
}
moveEntityWithHeading(moveSpeed, moveSpeed);
}
if(entityToAttack != null)
{
motionY = -0.01D;
flying = false;
if(groundDistance < 2)
{
motionY = 0.001D;
}
}
}
protected void attackEntity(Entity entity, float f)
{
if(f < 4F && rand.nextInt(20) == 0)
{
entity.attackEntityFrom(DamageSource.causeMobDamage(this), 6);
entity.motionY = 0.080000000000000002D;
}
}
protected void fall(float f)
{
}
public int distanceToGround()
{
int i = (int)posX;
int j = (int)posY;
int k = (int)posZ;
int l = 0;
for(int i1 = 0; i1 <= 20; i1++)
{
if(worldObj.isAirBlock(i, j - 1, k))
{
l++;
j--;
}
}
return l;
}
public int groundDistance;
public int flyTime;
public boolean flying;
public float size;
}
and the part the makes it fly and do damage when you are close is this bit:
- Code:
public void onLivingUpdate()
{
super.onLivingUpdate();
groundDistance = distanceToGround();
if(isEntityAlive())
{
if(!flying)
{
if(groundDistance > 5)
{
motionY = -0.01D;
}
flyTime = rand.nextInt(100) + 100;
if(posY < 110D && entityToAttack == null)
{
motionY = 0.02D;
}
} else
{
flyTime--;
motionY = 0.02D;
if(posY > 128D)
{
flying = false;
}
if(flyTime <= 0)
{
flying = false;
}
}
if(rand.nextInt(30) == 0)
{
flying = true;
}
if(groundDistance < 5)
{
motionY = 0.20000000000000001D;
}
moveEntityWithHeading(moveSpeed, moveSpeed);
}
if(entityToAttack != null)
{
motionY = -0.01D;
flying = false;
if(groundDistance < 2)
{
motionY = 0.001D;
}
}
}
protected void attackEntity(Entity entity, float f)
{
if(f < 4F && rand.nextInt(20) == 0)
{
entity.attackEntityFrom(DamageSource.causeMobDamage(this), 6);
entity.motionY = 0.080000000000000002D;
}
}
protected void fall(float f)
{
}
public int distanceToGround()
{
int i = (int)posX;
int j = (int)posY;
int k = (int)posZ;
int l = 0;
for(int i1 = 0; i1 <= 20; i1++)
{
if(worldObj.isAirBlock(i, j - 1, k))
{
l++;
j--;
}
}
return l;
}
public int groundDistance;
public int flyTime;
public boolean flying;
you guys should be able to figureout what the rest does. and if you use this code you will need to change some names of course
Ranga179- Member
- Posts : 9
Join date : 2011-10-19
Age : 28
Similar topics
» (unanswered)Can there be a custom model for an itme
» Making a Furnace-like Block
» block pick requirements (solved)
» [unanswered] making new materials and tools
» Request: Custom Block Models
» Making a Furnace-like Block
» block pick requirements (solved)
» [unanswered] making new materials and tools
» Request: Custom Block Models
MC Modding :: Modding :: Singleplayer Modding :: Requests
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum