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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Sup,i use forge 47.2.30 for 1.20.1 and i got this crash error :  https://pastebin.com/SMxVrV3E May someone help me ? Thank you !
    • 🎰 Mainkan Slot Online dengan Hanya 5 Ribu Via Dana, Proses Cepat! 🎰 Buka pintu ke dunia hiburan tanpa batas di UANG69 Slot Online! Bersiaplah untuk merasakan sensasi kemenangan di ujung jari Anda dengan taruhan serendah 5 ribu rupiah saja, melalui metode pembayaran yang mudah via Dana! ⚡ Proses Cepat, Nikmati Keuntungan dalam Sekejap ⚡ Bergabunglah dengan komunitas slot paling dinamis dan terpanas, dengan puluhan permainan slot yang menakjubkan, serta kesempatan untuk memenangkan jackpot besar! Rasakan gemerlapnya Las Vegas langsung dari kenyamanan rumah Anda sendiri. 🔥 Keunggulan UANG69 Slot Online: 🔥 ✅ Taruhan Serendah 5 Ribu Rupiah ✅ Metode Pembayaran Mudah via Dana ✅ Proses Cepat, Penarikan Lancar ✅ Puluhan Permainan Slot Terbaik ✅ Jackpot Besar Menanti untuk Dimenangkan Bergabunglah dengan UANG69 hari ini dan jadilah bagian dari petualangan slot yang tak terlupakan. Nikmati keseruan, kemenangan, dan hiburan di ujung jari Anda! Jangan lewatkan kesempatan ini, bergabunglah sekarang dan mulailah memenangkan hadiah besar! 💰💎🎉
    • Hello, I am trying to play Minecraft (premium version) with the All Of Create mod from CurseForge. When I launch it from the Minecraft launcher I get an error "The game has stopped working" Error code: 1. I tried to create a modpack, without mods, and launch it (in case there was any incompatibility) but it doesn't work either.... Error with mod: https://paste.ee/p/zzvJY I hope someone can help me. Thanks in advance.
    • Jika Anda mencari maxwin secepat kilat, maka Slot Kilat77 adalah tempatnya! Dengan koleksi slot terbaik yang dirancang untuk memberikan kemenangan instan, setiap putaran di Slot Kilat77 adalah kesempatan untuk memenangkan hadiah besar dalam sekejap. Bergabunglah sekarang dan rasakan sensasi kemenangan kilat di setiap gulungan. Jadi, jangan ragu lagi, mari bergabung dan raih maxwin secepat kilat hanya di Slot Kilat77!
    • Jos77 adalah pilihan terbaik untuk meraih maxwin hari ini! Dengan koleksi permainan slot terbaik dan peluang kemenangan yang tinggi, setiap putaran di Jos77 adalah kesempatan untuk memenangkan hadiah besar. Bergabunglah sekarang dan rasakan sensasi kemenangan yang luar biasa di setiap gulungan. Jadi, jangan lewatkan kesempatan untuk menjadi pemenang hari ini di Jos77 Mulailah petualangan slot Anda sekarang di Jos77 dan temukan sendiri mengapa kami adalah pilihan utama para pencari maxwin. Dengan grafis yang memukau, fitur bonus yang menggiurkan, dan dukungan pelanggan yang luar biasa, kami siap membawa pengalaman bermain Anda ke level berikutnya. Tidak peduli apakah Anda seorang pemula atau ahli slot, Jos77 menyediakan lingkungan yang ramah dan menyenangkan bagi semua pemain. Jadi, bersiaplah untuk meraih maxwin dan nikmati kesuksesan Anda di Jos77 hari ini!  
  • Topics

×
×
  • Create New...

Important Information

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