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 am creating a Mars mod that simulates the gravity of Mars.  Mars has about a quarter the gravity of Earth.  Any suggestions on my plan of attack?

 

Things I know already:  I think each item, block and player has a function to handle their own gravity.  I want to be able to have the adjusted 'gravity' from the moment the mod loads (no travelling to other dimensions, like with Galacticraft.)  How do I adjust the fall rate of each item, block and player?  Is there a tutorial for doing a similar universal change withing Minecraft Forge?

I want to be able to have the adjusted 'gravity' from the moment the mod loads (no travelling to other dimensions, like with Galacticraft.)

You mean, before the world or any entity is loaded ? That isn't possible.

 

As you said, each entity handles its own gravity. Meaning "gravity" only operates in game ticks.

You might be interested in the LivingFallEvent and LivingJumpEvent.

 

I kinda want to point out that Minecraft gravity isn't close to the Earth's.

In some ticking method;

	int dimension = YOUR_DIMENSION_ID;
	World world = DimensionManager.getWorld(dimension);
	if (world==null) return;
	List list = world.loadedEntityList;
	for(Iterator<EntityLiving> entity = list.iterator(); entity.hasNext(){
		EntityLiving living = entity.next();
		living.jumpMovementFactor = ??;//I haven't worked with this before, but should be able to help you out, I guess.
	}

  • Author

Galacticraft is open source.

 

Yes.  I've been looking through to source to see how it handles gravity.  From what I can work out, it's clever but not straight forward.  Because each item has its own downward motion, there is a function called getGravity() that figures out what that downward motion is, and then somewhere else changes it in relation to the world the player is on.  I think.

 

I'm still unsure how to change this motion in my mod.

  • Author

I want to be able to have the adjusted 'gravity' from the moment the mod loads (no travelling to other dimensions, like with Galacticraft.)

You mean, before the world or any entity is loaded ? That isn't possible.

 

As you said, each entity handles its own gravity. Meaning "gravity" only operates in game ticks.

You might be interested in the LivingFallEvent and LivingJumpEvent.

 

I kinda want to point out that Minecraft gravity isn't close to the Earth's.

 

What I mean is, I don't want to create a 'Mars' as another dimension, and have the player travel there.  And yeah, Minecraft's gravity isn't Earth, true.  But I would like to reduce the MC gravity to about 1/4 to give a (relative) experience of being on Mars.

 

Okay, I'll check out those functions.  Cheers!

  • Author

In some ticking method;

 

Thanks.  I don't know enough about ticking methods, atm.  Is there a tutorial that anyone can point out?

I'm not sure if this is the best way, but you could do this:

1. Set up a tick event for players

2. Check if they're in the air/jumping

3. Add to motionY

 

 

To make a tick event handler thing:

1. Create class

2. Create method with TickEvent.PlayerTickEvent as an argument

3. Add the SubscribeEvent annotation

4. Register the class in FMLCommonHandler

Kain

  • Author

For those who came after me to find out how to do gravity: The tl:dr is that each item, block, entity handles it's own downward motion. 

 

What I did (for jumping entities) was to make a function that would be called on a jumping event:

 

public class GenericJumpEvent 
{
    @SubscribeEvent
    public void onLivingJumpEvent(LivingJumpEvent event)
    {
        double addY = 1.38D; // change to the entity's Y motion.
        event.entity.motionY *= addY;
        event.entity.velocityChanged = true;
    }
}

 

I then needed to register this event in public void load(FMLInitializationEvent event) in my mod base class.

 

MinecraftForge.EVENT_BUS.register(new GenericJumpEvent());

 

The effect of this code is that the player and all the other entities now jump a little higher.

 

Questions?  Comments?  Observations?

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.