Jump to content

[1.7.2] Making the gravity like Mars.


Theoretikos

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.



×
×
  • Create New...

Important Information

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