Jump to content

Recommended Posts

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

}

Posted

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

×   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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hi everyone, I'm currently developing a Forge 1.21 mod for Minecraft and I want to display a custom HUD overlay for a minigame. My goal: When the game starts, all players should see an item/block icon (from the base game, not a custom texture) plus its name/text in the HUD – similar to how the bossbar overlay works. The HUD should appear centered above the hotbar (or at a similar prominent spot), and update dynamically (icon and name change as the target item changes). What I've tried: I looked at many online tutorials and several GitHub repos (e.g. SeasonHUD, MiniHUD), but most of them use NeoForge or Forge versions <1.20 that provide the IGuiOverlay API (e.g. implements IGuiOverlay, RegisterGuiOverlaysEvent). In Forge 1.21, it seems that neither IGuiOverlay nor RegisterGuiOverlaysEvent exist anymore – at least, I can't import them and they are missing from the docs and code completion. I tried using RenderLevelStageEvent as a workaround but it is probably not intended for custom HUDs. I am not using NeoForge, and switching the project to NeoForge is currently not an option for me. I tried to look at the original minecraft source code to see how elements like hearts, hotbar etc are drawn on the screen but I am too new to Minecraft modding to understand. What I'm looking for: What is the correct way to add a custom HUD element (icon + text) in Forge 1.21, given that the previous overlay API is missing? Is there a new recommended event, callback, or method in Forge 1.21 for custom HUD overlays, or is everyone just using a workaround? Is there a minimal open-source example repo for Forge 1.21 that demonstrates a working HUD overlay without relying on NeoForge or deprecated Forge APIs? My ideal solution: Centered HUD element with an in-game item/block icon (from the base game's assets, e.g. a diamond or any ItemStack / Item) and its name as text, with a transparent background rectangle. It should be visible to the players when the mini game is running. Easy to update the item (e.g. static variable or other method), so it can change dynamically during the game. Any help, code snippets, or up-to-date references would be really appreciated! If this is simply not possible right now in Forge 1.21, it would also help to know that for sure. Thank you very much in advance!
    • The simple answer is there is not an easy way. You would need to know how to program in Java, as well as at least some familiarity with how Forge works so you could port the differences. You would also need the sourcecode for the original mod, and permission from the author to modify it, if they did not use some sort of open source license. So it's not impossible, but it would take some effort, but doing so would open up a whole new world of possibilities for you!
    • Does it still crash if you remove holdmyitems? Looks like that mod doesn't work on a server as far as I can tell from the error.  
    • Crashes the server when trying to start. Error code -1. Log  
  • Topics

  • Who's Online (See full list)

    • There are no registered users currently online
×
×
  • Create New...

Important Information

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