Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I have made a mob and I can mount it, but I can't make it be controlled by the player. I have looked for tutorials and looked at the horse, minecart and pig classes, yet found nothing. Can you please tell me how?

Well to adequitly be able to help, you would need to share your source. My guess is that you are not extending EntityRideable. I have not done anything with being able to ride mobs myself but im sure that you should be extending it.

  • Author

...Already tried. It don't exist therefore I can't extend it. That is why i went here cause I found NOTHING ON CONTROLLING THE MOBS YOU ARE RIDING

  • Author

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;
}


}

*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;
    }

  • Author

Umm... That just gives a speed boost to the pig. That doesn't control it, it just checks if it is controlling it

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.

  • Author

Can someone tell me how to packet handle, I haven't used it and the tutorials I am using don't have anything for updating mob location

And this... is why you need to know basic Java.

 

To send packets:

You got to learn what to send, you don't just look at a tutorial and copy it.

 

Let me see what I can find to help you out.

  • Author

I try my best to comprehend what I am reading and copying. So can you please tell me what packet to send?

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.