Hi, I've made a pheonix entity for my mod.
For some reson, it visually falls into the ground (infinitlly).
I know it happends only visually because I can still see the pheonix's shaddow on the ground.
Can someone tell me how to fix it?
My code:
public class ModEntities {
public static final int idWizard = 120;
public static final int idPheonix = 121;
public static void registerEntities() {
registerEntity("wizard", EntityWizard.class, idWizard, 50, 255, 16776960);
registerEntity("pheonix", EntityPheonix.class, idPheonix, 50, 10254636, 15436288);
}
public static void registerEntity(String name, Class<? extends Entity> entity, int id, int range, int eggColor1, int eggColor2) {
EntityRegistry.registerModEntity(new ResourceLocation(myfirstmod.MODID + ":" + name), entity, name, id, myfirstmod.instance, range, 1, true, eggColor1, eggColor2);
}
}
public class ModelPheonix extends ModelBase {
public ModelRenderer body;
public ModelRenderer wingLeft;
public ModelRenderer tail;
public ModelRenderer head1;
public ModelRenderer legRight;
public ModelRenderer wingRight;
public ModelRenderer legLeft;
public ModelRenderer head2;
public ModelRenderer beak1;
public ModelRenderer beak2;
private ModelPheonix.State state = ModelPheonix.State.STANDING;
public ModelPheonix() {
this.textureWidth = 32;
this.textureHeight = 32;
this.wingRight = new ModelRenderer(this, 19, 8);
this.wingRight.setRotationPoint(-1.5F, 16.94F, -2.76F);
this.wingRight.addBox(-0.5F, 0.0F, -1.5F, 1, 5, 3, 0.0F);
this.setRotateAngle(wingRight, -0.6981317007977318F, -3.141592653589793F, 0.08726646259971647F);
this.tail = new ModelRenderer(this, 22, 1);
this.tail.setRotationPoint(0.0F, 21.07F, 1.16F);
this.tail.addBox(-1.5F, -1.0F, -1.0F, 3, 4, 1, 0.0F);
this.setRotateAngle(tail, 1.015083492959902F, 0.0F, 0.0F);
this.legRight = new ModelRenderer(this, 14, 18);
this.legRight.setRotationPoint(-1.0F, 22.0F, -1.05F);
this.legRight.addBox(-0.5F, 0.0F, -0.5F, 1, 2, 1, 0.0F);
this.setRotateAngle(legRight, 0.6682865705886288F, 0.0F, 0.0F);
this.head2 = new ModelRenderer(this, 10, 0);
this.head2.setRotationPoint(0.0F, -2.0F, -1.0F);
this.head2.addBox(-1.0F, -0.5F, -2.0F, 2, 1, 4, 0.0F);
this.body = new ModelRenderer(this, 2, 8);
this.body.setRotationPoint(0.0F, 16.5F, -3.0F);
this.body.addBox(-1.5F, 0.0F, -1.5F, 3, 6, 3, 0.0F);
this.setRotateAngle(body, 0.49375364538919575F, 0.0F, 0.0F);
this.legLeft = new ModelRenderer(this, 14, 18);
this.legLeft.setRotationPoint(1.0F, 22.0F, -1.05F);
this.legLeft.addBox(-0.5F, 0.0F, -0.5F, 1, 2, 1, 0.0F);
this.setRotateAngle(legLeft, 0.6682865705886288F, 0.0F, 0.0F);
this.beak1 = new ModelRenderer(this, 11, 7);
this.beak1.setRotationPoint(0.0F, -0.5F, -1.5F);
this.beak1.addBox(-0.5F, -1.0F, -0.5F, 1, 2, 1, 0.0F);
this.wingLeft = new ModelRenderer(this, 19, 8);
this.wingLeft.setRotationPoint(1.5F, 16.94F, -2.76F);
this.wingLeft.addBox(-0.5F, 0.0F, -1.5F, 1, 5, 3, 0.0F);
this.setRotateAngle(wingLeft, -0.6981317007977318F, -3.141592653589793F, -0.08726646259971647F);
this.beak2 = new ModelRenderer(this, 16, 7);
this.beak2.setRotationPoint(0.0F, -1.75F, -2.45F);
this.beak2.addBox(-0.5F, 0.0F, -0.5F, 1, 2, 1, 0.0F);
this.head1 = new ModelRenderer(this, 2, 2);
this.head1.setRotationPoint(0.0F, 15.69F, -2.76F);
this.head1.addBox(-1.0F, -1.5F, -1.0F, 2, 3, 2, 0.0F);
this.head1.addChild(this.head2);
this.head1.addChild(this.beak1);
this.head1.addChild(this.beak2);
}
@Override
public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5) {
this.wingRight.render(f5);
this.tail.render(f5);
this.legRight.render(f5);
this.body.render(f5);
this.legLeft.render(f5);
this.wingLeft.render(f5);
this.head1.render(f5);
}
/**
* This is a helper function from Tabula to set the rotation of model parts
*/
public void setRotateAngle(ModelRenderer modelRenderer, float x, float y, float z) {
modelRenderer.rotateAngleX = x;
modelRenderer.rotateAngleY = y;
modelRenderer.rotateAngleZ = z;
}
@Override
public void setRotationAngles(float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scaleFactor, Entity entityIn) {
float f = ageInTicks * 0.3F;
this.head1.rotateAngleX = headPitch * 0.017453292F;
this.head1.rotateAngleY = netHeadYaw * 0.017453292F;
this.head1.rotateAngleZ = 0.0F;
this.head1.rotationPointX = 0.0F;
this.body.rotationPointX = 0.0F;
this.tail.rotationPointX = 0.0F;
this.wingRight.rotationPointX = -1.5F;
this.wingLeft.rotationPointX = 1.5F;
if (this.state != ModelPheonix.State.FLYING)
{
if (this.state == ModelPheonix.State.SITTING)
{
return;
}
this.legLeft.rotateAngleX += MathHelper.cos(limbSwing * 0.6662F) * 1.4F * limbSwingAmount;
this.legRight.rotateAngleX += MathHelper.cos(limbSwing * 0.6662F + (float)Math.PI) * 1.4F * limbSwingAmount;
}
this.head1.rotationPointY = 15.69F + f;
this.tail.rotateAngleX = 1.015F + MathHelper.cos(limbSwing * 0.6662F) * 0.3F * limbSwingAmount;
this.tail.rotationPointY = 21.07F + f;
this.body.rotationPointY = 16.5F + f;
this.wingLeft.rotateAngleZ = -0.0873F - ageInTicks;
this.wingLeft.rotationPointY = 16.94F + f;
this.wingRight.rotateAngleZ = 0.0873F + ageInTicks;
this.wingRight.rotationPointY = 16.94F + f;
this.legLeft.rotationPointY = 22.0F + f;
this.legRight.rotationPointY = 22.0F + f;
}
@Override
public void setLivingAnimations(EntityLivingBase entitylivingbaseIn, float limbSwing, float limbSwingAmount, float partialTickTime) {
this.body.rotateAngleX = 0.4937F;
this.wingLeft.rotateAngleX = -((float)Math.PI * 2F / 9F);
this.wingLeft.rotateAngleY = -(float)Math.PI;
this.wingRight.rotateAngleX = -((float)Math.PI * 2F / 9F);
this.wingRight.rotateAngleY = -(float)Math.PI;
this.legLeft.rotateAngleX = -0.0299F;
this.legRight.rotateAngleX = -0.0299F;
this.legLeft.rotationPointY = 22.0F;
this.legRight.rotationPointY = 22.0F;
if (entitylivingbaseIn instanceof EntityPheonix)
{
EntityPheonix entitypheonix = (EntityPheonix)entitylivingbaseIn;
if (entitypheonix.isSitting())
{
float f = 1.9F;
this.head1.rotationPointY = 17.59F;
this.tail.rotateAngleX = 1.5388988F;
this.tail.rotationPointY = 22.97F;
this.body.rotationPointY = 18.4F;
this.wingLeft.rotateAngleZ = -0.0873F;
this.wingLeft.rotationPointY = 18.84F;
this.wingRight.rotateAngleZ = 0.0873F;
this.wingRight.rotationPointY = 18.84F;
++this.legLeft.rotationPointY;
++this.legRight.rotationPointY;
++this.legLeft.rotateAngleX;
++this.legRight.rotateAngleX;
this.state = ModelPheonix.State.SITTING;
}
else if (entitypheonix.isFlying())
{
this.legLeft.rotateAngleX += ((float)Math.PI * 2F / 9F);
this.legRight.rotateAngleX += ((float)Math.PI * 2F / 9F);
this.state = ModelPheonix.State.FLYING;
}
else
{
this.state = ModelPheonix.State.STANDING;
}
this.legLeft.rotateAngleZ = 0.0F;
this.legRight.rotateAngleZ = 0.0F;
}
}
@SideOnly(Side.CLIENT)
static enum State
{
FLYING,
STANDING,
SITTING;
}
}
public class EntityPheonix extends EntityShoulderRiding implements EntityFlying {
private static final Item DEADLY_ITEM = Items.WATER_BUCKET;
private static final Set<Item> TAME_ITEMS = Sets.newHashSet(Items.COOKIE);
public EntityPheonix(World worldIn) {
super(worldIn);
this.setSize(0.7F, 1.1F);
this.moveHelper = new EntityFlyHelper(this);
}
@Override
public EntityAgeable createChild(EntityAgeable ageable) {
return new EntityPheonix(world);
}
@Override
public float getEyeHeight() {
return this.height * 0.6F;
}
@Override
public ITextComponent getDisplayName() {
return new TextComponentTranslation("entity.pheonix.name");
}
@Override
protected void initEntityAI() {
this.aiSit = new EntityAISit(this);
this.tasks.addTask(0, new EntityAIPanic(this, 1.25D));
this.tasks.addTask(0, new EntityAISwimming(this));
this.tasks.addTask(1, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
this.tasks.addTask(2, this.aiSit);
this.tasks.addTask(2, new EntityAIFollowOwnerFlying(this, 1.0D, 5.0F, 1.0F));
this.tasks.addTask(2, new EntityAIWanderAvoidWaterFlying(this, 1.0D));
this.tasks.addTask(3, new EntityAILandOnOwnersShoulder(this));
this.tasks.addTask(3, new EntityAIFollow(this, 1.0D, 3.0F, 7.0F));
}
@Override
protected void applyEntityAttributes() {
super.applyEntityAttributes();
this.getAttributeMap().registerAttribute(SharedMonsterAttributes.FLYING_SPEED);
this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(9.0D);
this.getEntityAttribute(SharedMonsterAttributes.FLYING_SPEED).setBaseValue(0.45D);
this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.24D);
}
@Override
public void onLivingUpdate() {
super.onLivingUpdate();
}
@Override
protected PathNavigate createNavigator(World worldIn) {
PathNavigateFlying pathnavigateflying = new PathNavigateFlying(this, worldIn);
pathnavigateflying.setCanOpenDoors(false);
pathnavigateflying.setCanFloat(true);
pathnavigateflying.setCanEnterDoors(true);
return pathnavigateflying;
}
@Override
public boolean processInteract(EntityPlayer player, EnumHand hand) {
ItemStack itemstack = player.getHeldItem(hand);
if (!this.isTamed() && TAME_ITEMS.contains(itemstack.getItem()))
{
if (!player.capabilities.isCreativeMode)
{
itemstack.shrink(1);
}
if (!this.isSilent())
{
this.world.playSound((EntityPlayer)null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_PARROT_EAT, this.getSoundCategory(), 1.0F, 1.0F + (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F);
}
if (!this.world.isRemote)
{
if (this.rand.nextInt(10) == 0 && !net.minecraftforge.event.ForgeEventFactory.onAnimalTame(this, player))
{
this.setTamedBy(player);
this.playTameEffect(true);
this.world.setEntityState(this, (byte)7);
}
else
{
this.playTameEffect(false);
this.world.setEntityState(this, (byte)6);
}
}
return true;
}
else if (itemstack.getItem() == DEADLY_ITEM)
{
if (!player.capabilities.isCreativeMode)
{
itemstack.shrink(1);
}
this.addPotionEffect(new PotionEffect(MobEffects.POISON, 900));
if (player.isCreative() || !this.getIsInvulnerable())
{
this.attackEntityFrom(DamageSource.causePlayerDamage(player), Float.MAX_VALUE);
}
return true;
}
else
{
if (!this.world.isRemote && !this.isFlying() && this.isTamed() && this.isOwner(player))
{
this.aiSit.setSitting(!this.isSitting());
}
return super.processInteract(player, hand);
}
}
@Override
public boolean isBreedingItem(ItemStack stack) {
return TAME_ITEMS.contains(stack.getItem());
}
@Override
public boolean getCanSpawnHere() {
int i = MathHelper.floor(this.posX);
int j = MathHelper.floor(this.getEntityBoundingBox().minY);
int k = MathHelper.floor(this.posZ);
BlockPos blockpos = new BlockPos(i, j, k);
Block block = this.world.getBlockState(blockpos.down()).getBlock();
return block instanceof BlockLeaves || block == Blocks.GRASS || block instanceof BlockLog || block == Blocks.AIR && this.world.getLight(blockpos) > 8 && super.getCanSpawnHere();
}
@Override
protected boolean makeFlySound() {
return true;
}
@Override
public void fall(float distance, float damageMultiplier) {
}
@Override
protected void updateFallState(double y, boolean onGroundIn, IBlockState state, BlockPos pos) {
}
@Override
public boolean canBePushed() {
return true;
}
@Override
protected void collideWithEntity(Entity entityIn) {
if (!(entityIn instanceof EntityPlayer))
{
super.collideWithEntity(entityIn);
}
}
public boolean isFlying()
{
return false;
}
}
public class RenderPheonix extends RenderLiving<EntityPheonix> {
public static final ResourceLocation TEXTURES = new ResourceLocation(myfirstmod.MODID + ":textures/entity/pheonix.png");
public RenderPheonix(RenderManager manager) {
super(manager, new ModelPheonix(), 0.5F);
}
@Override
protected ResourceLocation getEntityTexture(EntityPheonix entity) {
return TEXTURES;
}
@Override
protected void applyRotations(EntityPheonix entityLiving, float p_77043_2_, float rotationYaw, float partialTicks) {
super.applyRotations(entityLiving, p_77043_2_, rotationYaw, partialTicks);
}
}
public class RenderHandler {
public static void registerEntityRenders() {
RenderingRegistry.registerEntityRenderingHandler(EntityWizard.class, new IRenderFactory<EntityWizard>(){
@Override
public Render<? super EntityWizard> createRenderFor(RenderManager manager) {
return new RenderWizard(manager);
}
});
RenderingRegistry.registerEntityRenderingHandler(EntityPheonix.class, new IRenderFactory<EntityPheonix>() {
@Override
public Render<? super EntityPheonix> createRenderFor(RenderManager manager) {
return new RenderPheonix(manager);
}
});
}
}