Jump to content

Player Motion [Potential mappings/project issue][1.20]


Recommended Posts

Posted

I have years of experience programming, even have a degree in computer science, but the whole gradle thing is quite new to me.

My objective is to create a "moon-like" gravity. Slow falling, bigger jumps, etc.
I have never done anything with forge prior to this, so I did lots of reading of the documentation and have a decent general understanding of things.

I am able to do things such as,

 

@SubscribeEvent
public void onJump(LivingEvent.LivingJumpEvent event) {
        
    if(event.getEntity() instanceof Player) {
            
        Player player = (Player) event.getEntity();
        player.setHealth(player.getHealth() - 1);
            
    }

}


Reading the docs I see a player#setMotion

I would like to do this - which should be possible based on docs

 player.setMotion(player.getMotion().x, player.getMotion().y * MOON_GRAVITY_FACTOR, player.getMotion().z);



but this method, and some other classes and methods do not appear to exist.

At first I thought it was a version related issue, but that was proven untrue when I went back all the way to 1.17.1 and the issues persisted.

This project is on 1.20.2 and the only thing I did in the project was changing the mod id and versions. Nothing to do with mappings or anything of the sort.

Is there changes that I am unaware of?
or is there an issue with my project setup?

It is currently a default project straight from the website.

I really am entirely confused, I am sure it is something simple. I tried my hardest to find the answer prior to asking.

Posted (edited)

It wasnt mappings issue, I was reading fabric and not forge. Fabric has PlayerEntity while forge has Player. Through a mixin I was able to change the player's velocity so that there is a sort of slow-motion type movement. Only issue is that jumping seems to be handled separately. Changing that velocity only makes the jump lower, not slower. Unsure how to increase the duration in which a jump happens.

 

@Mixin(LivingEntity.class)
public abstract class ExampleMixin extends Entity {
	
	public ExampleMixin(EntityType<?> type, World world) {
		super(type, world);
	}

	@Inject(method = "tickMovement", at = @At("HEAD"))
	private void onTickMovement(CallbackInfo ci) {
		// Access the player entity
		LivingEntity entity = (LivingEntity)(Object)this;

		// Modify player's acceleration by applying a force in the opposite direction
		double slowdownFactor = 0.75; // Adjust as needed
		entity.setVelocity(entity.getVelocity().multiply(1, slowdownFactor, 1));
	}

}

 

Edited by Saday

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.