Jump to content

Rideable Mobs Help [1.6.2]


MrNegaBlox

Recommended Posts

Thank you so much! It moves when I tell it, just one problem. When I move, I let go of the key and the mob teleports back to its origin. Here is my code:

 

Mob Code:

package bettermc.test.phoenixmob;

import net.minecraft.entity.EntityAgeable;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.ai.EntityAIControlledByPlayer;
import net.minecraft.entity.passive.EntityAnimal;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.DamageSource;
import net.minecraft.world.World;

public class EntityPhoenix extends EntityAnimal
{


private boolean leap;
public String myName;

public EntityPhoenix(World par1World)
{
         super(par1World);
         this.setSize(0.6F, 1.8F);
         Name = "Jeep";
         stationary = false;
}
String Name;
protected void updateEntityActionState()
{
        
}

public boolean isAIEnabled()
{
         return true;
}

protected void updateAITasks()
{
         super.updateAITasks();
}


public int getMaxHealth()
{
         return 50;
}

/**
         * returns true if all the conditions for steering the entity are met. For pigs, this is true if it is being ridden
         * by a player and the player is holding a carrot-on-a-stick
         */
public boolean canBeSteered()
{
         return true;
}


public void updateRidden()
{
         if(ridingEntity.isDead)
         {
                 ridingEntity = null;
                 return;
         }
         motionX = 0.0D;
         motionZ = 0.0D;
         motionY = 0.0D;
         onUpdate();
         //onUpdate();
         if(ridingEntity == null)
         {
                 return;
         }
}



public boolean interact(EntityPlayer entityplayer)
{
         if(riddenByEntity != null && (riddenByEntity instanceof EntityPlayer) && riddenByEntity != entityplayer)
         {
                 return true;
         }
         if(!worldObj.isRemote)
         {
                 entityplayer.mountEntity(this);
         }
         ItemStack itemstack = entityplayer.getCurrentEquippedItem();
         if (itemstack != null && itemstack.itemID == bettermc.test.Main.Oore.itemID)
         {
         if (!worldObj.isRemote)
         {
         EntityLiving entitytalljake = new EntityPhoenix(worldObj);
         entitytalljake.setLocationAndAngles(posX, posY, posZ, rotationYaw, rotationPitch);
         worldObj.spawnEntityInWorld(entitytalljake);
         setDead();
         itemstack.stackSize--;
         }
         return true;
         }
return leap;
}
/**
         * Called when the mob's health reaches 0.
         */
public void onDeath(DamageSource par1DamageSource)
{

         }


public void moveEntity(double d, double d1, double d2)
{
if(riddenByEntity != null)
         {
                         stationary = true;
                         motionX += riddenByEntity.motionX*10; // * 0.20000000000000001D;
                         motionZ += riddenByEntity.motionZ*10; // * 0.20000000000000001D;
                         if(isCollidedHorizontally)
                         {
        
                                                 if(onGround)                            //else not fly
                                                 {
                                                         motionY += 0.5F;//let it try to jump over obstacle
                                        
                                                 }
                         }
                         super.moveEntity(motionX, motionY, motionZ);
         }else
         {
                         super.moveEntity(d, d1, d2);
                         stationary = true;
         }
                
}
protected boolean isMovementCeased()
{
                 return stationary;
}

public void writeEntityToNBT(NBTTagCompound nbttagcompound)
{
         super.writeEntityToNBT(nbttagcompound);
}

public void readEntityFromNBT(NBTTagCompound nbttagcompound)
{
         super.readEntityFromNBT(nbttagcompound);
}

protected String getLivingSound()
{
         return "none";
}

protected String getHurtSound()
{
         return "none";
}

protected String getDeathSound()
{
         return "none";
}



protected void playStepSound(int par1, int par2, int par3, int par4)
{
         this.func_85030_a("mob.irongolem.walk", 1.0F, 1.0F);
}

private void func_85030_a(String string, float f, float g) {
// TODO Auto-generated method stub

}
public boolean stationary;

protected float getSoundVolume()
{
         return 0.4F;
}


@Override
public EntityAgeable createChild(EntityAgeable entityageable) {
// TODO Auto-generated method stub
return null;
}


}

Link to comment
Share on other sites

*hours later*

I actually found how a Pig gets controlled by the player.

You don't look in EntityPig, you look at ItemCarrotOnAStick

 

And. This... is what I found.

    public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
    {
        if (par3EntityPlayer.isRiding() && par3EntityPlayer.ridingEntity instanceof EntityPig)
        {
            EntityPig var4 = (EntityPig)par3EntityPlayer.ridingEntity;

            if (var4.getAIControlledByPlayer().isControlledByPlayer() && par1ItemStack.getMaxDamage() - par1ItemStack.getItemDamage() >= 7)
            {
                var4.getAIControlledByPlayer().boostSpeed();
                par1ItemStack.damageItem(7, par3EntityPlayer);

                if (par1ItemStack.stackSize == 0)
                {
                    ItemStack var5 = new ItemStack(Item.fishingRod);
                    var5.setTagCompound(par1ItemStack.stackTagCompound);
                    return var5;
                }
            }
        }

        return par1ItemStack;
    }

Link to comment
Share on other sites

when you are moving the pig on your screen you never tell the server that its position is different so when you stop the server tries to sync with client and teleports you back so you need to send a packet from the client to the server telling the server you are in a new position.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.