Theoretikos Posted May 12, 2014 Share Posted May 12, 2014 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? Quote Link to comment Share on other sites More sharing options...
f1rSt1kChannel Posted May 12, 2014 Share Posted May 12, 2014 Galacticraft is open source. Quote Link to comment Share on other sites More sharing options...
GotoLink Posted May 12, 2014 Share Posted May 12, 2014 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. Quote Link to comment Share on other sites More sharing options...
ShaneCraft Posted May 12, 2014 Share Posted May 12, 2014 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. } Quote Link to comment Share on other sites More sharing options...
Theoretikos Posted May 14, 2014 Author Share Posted May 14, 2014 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. Quote Link to comment Share on other sites More sharing options...
Theoretikos Posted May 14, 2014 Author Share Posted May 14, 2014 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! Quote Link to comment Share on other sites More sharing options...
Theoretikos Posted May 14, 2014 Author Share Posted May 14, 2014 In some ticking method; Thanks. I don't know enough about ticking methods, atm. Is there a tutorial that anyone can point out? Quote Link to comment Share on other sites More sharing options...
TLHPoE Posted May 14, 2014 Share Posted May 14, 2014 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 Quote Kain Link to comment Share on other sites More sharing options...
Theoretikos Posted May 19, 2014 Author Share Posted May 19, 2014 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? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.