Jump to content

Recommended Posts

Posted

i have recently created a car entity, but when you are in the car, it randomly jumps up and down. i have reveiwed the code and i really don't know what is causing this.

 

the EntityVehicle class: (code deactivated with // omitted)

package firestarme.fires_cars.common;

import net.minecraft.src.AABBPool;
import net.minecraft.src.AxisAlignedBB;
import net.minecraft.src.DamageSource;
import net.minecraft.src.Entity;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.ModLoader;
import net.minecraft.src.NBTTagCompound;
import net.minecraft.src.World;
import org.lwjgl.input.Keyboard;

public class EntityVehicle extends Entity{

public float speed = 0;
public float maxSpeed;
public float fallSpeed = 0;
public float maxFallSpeed = 0.4F;
public float acceleration;
public float drag;
public float yaw;
public boolean isOffroad = false;
public float climbAcceleration;
public float climb = 0F;
public boolean mounted = false;
public Entity passenger;
public double velocityX;
public double velocityY;
public double velocityZ;


public EntityVehicle(World par1World) {
	super(par1World);
	// TODO Auto-generated constructor stub
}

@Override
protected void entityInit() {
	// TODO Auto-generated method stub

}

@Override
protected void readEntityFromNBT(NBTTagCompound var1) {
	// TODO Auto-generated method stub

}

@Override
protected void writeEntityToNBT(NBTTagCompound var1) {
	// TODO Auto-generated method stub

}



     

     }

public void addSpeed(float Sp){
	if(speed < maxSpeed){
		speed = speed + Sp;
	}
}

public void addfallSpeed(float Fsp){
	if(fallSpeed < maxFallSpeed){
		fallSpeed = fallSpeed + Fsp;
	}
}

public void applyDrag(){

	if(speed > 0.01){
		this.addSpeed(-drag);
	}else if(speed < 0.01){
		this.speed = 0;
	}else{
		speed = 0;
	}

}

   public boolean attackEntityFrom(DamageSource par1DamageSource, int par2)
    {
        if (this.func_85032_ar())
        {
            return false;
        }
        else if (!this.worldObj.isRemote && !this.isDead)
        {

                this.dropItemWithOffset(fires_carsMain.Car.shiftedIndex, 1, 0.0F);
                this.setDead();
            }

            return true;
     }

   
  public void onUpdate(){
   
	if(this.riddenByEntity != null){

		 this.motionX += this.riddenByEntity.motionX;
             this.motionZ += this.riddenByEntity.motionZ;

	}
	move();
   }

   public void move()
       {
               if(riddenByEntity != null)
               {
                       velocityZ = Math.cos(rotationYaw * 0.0174532925) * speed;
                       velocityX = Math.sin(rotationYaw* 0.0174532925) * -speed;
                       if(isCollidedHorizontally)             
                       {
                               velocityY = -fallSpeed;               
                       }
                       velocityZ = 0.0002;
                       this.addVelocity(velocityX, velocityY, velocityZ);
                       this.moveEntity(this.motionX, this.motionY, this.motionZ);
               }
       }       

               

   public boolean interact(EntityPlayer par1EntityPlayer)
    {
        if (this.riddenByEntity != null && this.riddenByEntity instanceof EntityPlayer && this.riddenByEntity != par1EntityPlayer)
        {
            return true;
        }
        else
        {
            if (!this.worldObj.isRemote)
            {
                par1EntityPlayer.mountEntity(this);
            }

            return true;
        }
    }
   
   
   
    public AxisAlignedBB getCollisionBox(Entity par1Entity)
    {
        return par1Entity.boundingBox;
    }


    public AxisAlignedBB getBoundingBox()
    {
        return this.boundingBox;
    }
}


 

and yes, i know its a bit of a mess at the moment, but i will clean it up when it is finished.

Posted

I believe that that is a action that is inherited from the Entity class when you extend it. Bt don't quote me on that, I'm not sure. Take a look around the code for Entity and look at other Entity tutorials to see if you cant find something there.

Creator and co-author of the mod Essencraft: https://github.com/defiant810/Essencraft

 

Please, dear God, learn Java before trying to mod. It saves ALL of us time.

Posted

This may be caused by a low tick rate that has the Fall speed set to negative when you lag downward into a block and therefore creating a jumping effect, an easy way to test this is do a System.out.println(FallSpeed) and see if that changes anything

The Korecraft Mod

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.