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 a custom Vehicle and havent been able to get it to jump. I have been trying for a long time and am stuck. This is my class. I have no idea what the issue is, everything else about this vehicle works perfectly except jumping. when the space bar is pressed nothing happens

 

public class EntityVehicle extends EntityAnimal {

public float animationPedalAngle = 0.0f;	//used clientside by VehicleModelVehicle
public float animationHandlebarAngle = 0.0f;
protected boolean VehicleJumping;
protected float jumpPower;
protected float vehicleMovementSpeedMultiplier = 0.5f; // Since moveForward is defined in EntityLivingBase to = 0.98F this multiplier is used to change the Bikes speed


public EntityVehicle(World par1World) {
	super(par1World);
	this.setSize(1.4F, 1.6F);

}

public EntityVehicle(World par1World, double par2, double par4, double par6) {
	this(par1World);
	this.setPosition(par2, par4 + (double) this.yOffset, par6);

}


public boolean isVehicleJumping() {
	return this.VehicleJumping;
}

public void setVehicleJumping(boolean par1) {
	this.VehicleJumping = par1;
}


/**
 * Returns true if this entity should push and be pushed by other entities
 * when colliding.
 */
public boolean canBePushed() {
	return this.riddenByEntity == null;
}

/**
 * Called when the mob is falling. Calculates and applies fall damage.
 */
protected void fall(float par1) {
	if (par1 > 1.0F) {
		this.playSound("mob.Vehicle.land", 0.4F, 1.0F);
	}

	int i = MathHelper.ceiling_float_int(par1 * 0.5F - 3.0F);

	if (i > 0) {

		Block block = this.worldObj.getBlock(
				MathHelper.floor_double(this.posX),
				MathHelper.floor_double(this.posY - 0.2D
						- (double) this.prevRotationYaw),
						MathHelper.floor_double(this.posZ));

		if (block.getMaterial() != Material.air) {
			Block.SoundType soundtype = block.stepSound;
			this.worldObj.playSoundAtEntity(this,
					soundtype.getStepResourcePath(),
					soundtype.getVolume() * 0.5F,
					soundtype.getPitch() * 0.75F);
		}
	}
}

/**
 * Called when a player interacts with a mob.
 */
public boolean interact(EntityPlayer par1EntityPlayer) {
	ItemStack itemstack = par1EntityPlayer.inventory.getCurrentItem();

	if (itemstack != null && itemstack.getItem() == Items.spawn_egg) {
		return super.interact(par1EntityPlayer);
	}

	if (this.riddenByEntity == null) {
		if (itemstack != null
				&& itemstack.interactWithEntity(par1EntityPlayer, this)) {
			return true;
		} else {
			this.onPlayerMounted(par1EntityPlayer);
			return true;
		}
	} else {
		return super.interact(par1EntityPlayer);
	}
}

//called when player mounts this entity
private void onPlayerMounted(EntityPlayer par1EntityPlayer) {
	par1EntityPlayer.rotationYaw = this.rotationYaw;
	par1EntityPlayer.rotationPitch = this.rotationPitch;

	if (!this.worldObj.isRemote) {
		par1EntityPlayer.mountEntity(this);
	}
}

/**
 * Called frequently so the entity can update its state every tick as
 * required. For example, zombies and skeletons use this to react to
 * sunlight and start to burn.
 */
public void onLivingUpdate() {
	super.onLivingUpdate();
}

/**
 * Called to update the entity's position/logic.
 */
public void onUpdate() {
	super.onUpdate();
}

private double getVehicleJumpPower(){
	return 1.0f;
}

/**
 * Moves the entity based on the specified heading. Args: strafe, forward
 */
public void moveEntityWithHeading(float moveStrafing, float moveForward) {
	if (this.riddenByEntity != null) {
		this.rotationYaw = this.riddenByEntity.rotationYaw;
		this.prevRotationYaw = this.riddenByEntity.prevRotationYaw;
		this.rotationPitch = this.riddenByEntity.rotationPitch * 0.5F;
		this.setRotation(this.rotationYaw, this.rotationPitch);
		this.rotationYawHead = this.renderYawOffset = this.rotationYaw;
		moveStrafing = 0;	//moveStrafing = strafing. Should be 0, since we don't want the bike to move side to side.
		moveForward = ((EntityLivingBase) this.riddenByEntity).moveForward* vehicleMovementSpeedMultiplier;

		if (moveForward <= 0.0F) {
			moveForward *= 0.25F;	//you move 1/4 of the speed when going backwards

		}

		if(this.onGround){
			this.jumpPower = 0.0f;//(float)this.getVehicleJumpPower();
		}
		if (this.jumpPower > 0.0F && !this.isVehicleJumping() && this.onGround) {

			this.motionY = this.jumpPower;	//getVehicleJumpPower()

			System.out.println("JUMPING");
			this.onGround = false;
			this.isAirBorne = true;
			//System.out.println("jumpPower: "+jumpPower+" if (this.jumpPower > 0.0F && !this.isVehicleJumping() && this.onGround)");

			if (moveForward > 0.0F) {
				float f2 = MathHelper.sin(this.rotationYaw * (float) Math.PI / 180.0F);
				float f3 = MathHelper.cos(this.rotationYaw * (float) Math.PI / 180.0F);
				this.motionX += (double) (-0.4F * f2 * this.jumpPower);
				this.motionZ += (double) (0.4F * f3 * this.jumpPower);
				this.playSound("mob.Vehicle.jump", 0.4F, 1.0F);
				//System.out.println("jumpPower: "+jumpPower+" if (moveForward > 0.0F)");
		}

			this.jumpPower = 0.0F;
			//System.out.println("jumpPower: "+jumpPower+" if (this.jumpPower > 0.0F && !this.isVehicleJumping() && this.onGround)");
		}

		this.stepHeight = 1.0F;
		this.jumpMovementFactor = this.getAIMoveSpeed() * 0.1F;

		if (!this.worldObj.isRemote) {
			this.setAIMoveSpeed((float) this.getEntityAttribute(
					SharedMonsterAttributes.movementSpeed)
					.getAttributeValue());
			//System.out.println("moveStrafing: "+moveStrafing+" moveForward: "+moveForward);
			super.moveEntityWithHeading(moveStrafing, moveForward);
		}

		if (this.onGround) {
			this.jumpPower = 0.0F;
			this.setVehicleJumping(false);
			//System.out.println("jumpPower: "+jumpPower+" if (this.onGround)");
		}

	} else {
		this.stepHeight = 0.5F;
		this.jumpMovementFactor = 0.02F;
		super.moveEntityWithHeading(moveStrafing, moveForward);
	}
}

public EntityAgeable createChild(EntityAgeable par1EntityAgeable) {
	return new EntityVehicle(this.worldObj);
}

/**
 * Returns true if the newer Entity AI code should be run
 */
protected boolean isAIEnabled() {
	return true;
}

public void setJumpPower(int par1) {
	System.out.println("setJumpPower: "+jumpPower);
	if (par1 < 0) {
		par1 = 0;
		//System.out.println("jumpPower: "+jumpPower+" if (par1 < 0)");
	}

	if (par1 >= 90) {
		this.jumpPower = 1.0F;
		//System.out.println("jumpPower: "+jumpPower+" if (par1 >= 90)");
	} else {
		this.jumpPower = 0.4F + 0.4F * (float) par1 / 90.0F;
		//System.out.println("jumpPower: "+jumpPower+"  else {this.jumpPower = 0.4F + 0.4F * (float) par1 / 90.0F;");
	}
}

@Override
public double getMountedYOffset(){
	return 1.0;
}


@Override
public void updateRiderPosition() {
	super.updateRiderPosition();
}

@Override
public boolean isOnLadder() {
	return false;
}

}

Check EntityPlayerSP#onLivingUpdate and EntityPlayerSP#sendHorseJump

I think horse jumping is done by checking somewhere that ridden entity is instance of EntityHorse and otherwise Minecraft just ignores space pressing when trying to jump while riding. I had same kind of problem when I tried to set specific state for entity when space was pressed and I solved it by subscribe of KeyInputEvent and checking there if Minecraft.getMinecraft().gameSettings.keyBindJump.isPressed() and if so, client sends packet to server. Packet is received by server side packet handler and it gets EntityPlayerMP from MessageContext and if EntityPlayerMP#ridingEntity is not null and its instanceof my entity that uses space to set state, it sets the state and updates ridingEntity datawatcher.

 

Or you could try to extend EntityHorse instead of EntityAnimal.

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.