Posted July 10, 201510 yr A while ago I asked if it was possible to turn off gravity for the player, and I was told that it was possible and pretty simple. Well, I'm now ready to give it a try. So, can anyone point me in the right direction? Basically, I want the player to behave as if they were flying in creative mode all the time. Any tutorials to follow? Can anyone at least point me toward the right classes to investigate? Thanks.
July 10, 201510 yr I've been meaning to ask this question, though I really haven't had an immediate reason to yet.
July 10, 201510 yr Basically, I want the player to behave as if they were flying in creative mode all the time. Then make them flying all the time: player.capabilities.allowFlying = true; player.isFlying = true; // this may not work perfectly, as it gets set back to false when they touch the ground You could set up a player tick handler to check if isFlying is false and motionY < 0, then set isFlying to true at that time. Trouble is, motionY is often only accurate on the client side, so you may have to send a packet. http://i.imgur.com/NdrFdld.png[/img]
July 10, 201510 yr I was the one who said it was easy btw. Look here, very nice: https://github.com/micdoodle8/Galacticraft/search?utf8=%E2%9C%93&q=getGravityForEntity And yes - you basically apply "fly up/down" motion. (without flying game rule) 1.7.10 is no longer supported by forge, you are on your own.
July 11, 201510 yr Author Thanks for the help so far. To achieve my desired result, it appears as though I can create a new player class that extends EntityPlayer, and from there override onLivingUpdate(). The part I'm having trouble with now is how to register my new player class and get it to take the place of the normal player. For blocks, items, and tile entities, it is a simple matter of calling GameRegistry.registerXXX, but I don't see any registry for the player. The closest I have found is EntityRegistry.registerModEntity, but that seems to be for mobs only. As usual, any help is appreciated. p.s. I appreciate these forums, but the search function is utterly worthless. I tried searching for "Register Player" and other similar phrases, but the results were nonsensical, unrelated, and restricted to only a single page. Are the operators of this site aware of this?
July 11, 201510 yr Author Does this look right: public class EventHandlerTest { Minecraft mc; public EventHandlerTest() { mc = Minecraft.getMinecraft(); } @SubscribeEvent public void PlayerTickevent(TickEvent.PlayerTickEvent event) { if (event.phase == Phase.END) { EntityPlayerSP player = mc.thePlayer; //do my stuff } } }
July 11, 201510 yr Also.. Seriously? You are saving an instance of Minecraft just to Fall getMinecraft each tick?
July 11, 201510 yr More explanations: Thanks for the help so far. To achieve my desired result, it appears as though I can create a new player class that extends EntityPlayer, and from there override onLivingUpdate(). You probably looked (my guess) into repo I linked - it is using PlayerAPI - which provides additional player class hooks. Additional opinion: Do NOT use this API if you won't utilize its full potential. Most of it can be done with Forge directly. As to problem: TickEvents are FML events that occur: Player - server/client for each player (on client, it will be loaded by you players) Server - server for whole server World - server for each world Client/Render - obviously on client Each event has 2 phases (event.phase) - pick one phase, otherwise code runs twice. Minecraft.class is client only class: * You cannot reference it anythwere i common classes (only in client ones, common-class = one which is accesed by server-sided code). * mc.thePlayer is the player yo uare controlling, literally "you". To run code per-player you use PlayerTickEvent and use 'event.player' as your player. 1.7.10 is no longer supported by forge, you are on your own.
July 11, 201510 yr Author Thanks Ernio. Here is what I have so far. It's not finished, but it at least has the basic functionality I'm looking for. When I press "forward" I don't go toward the front of my body, instead I go in the direction I am looking, including the Y axis. The result is that I "fly" wherever I look. @SubscribeEvent public void PlayerTickevent(TickEvent.PlayerTickEvent event) { if (event.phase == Phase.END) { if (event.player != null) { if (event.player.moveForward != 0) { Vector3 playerPos = new Vector3(event.player); Vec3 look = event.player.getLookVec(); Vector3 look3 = new Vector3(look); look3 = look3.scale(event.player.getAIMoveSpeed()); double motionX = look3.x; double motionY = look3.y; double motionZ = look3.z; event.player.motionX = motionX; event.player.motionY = motionY; event.player.motionZ = motionZ; } else { event.player.motionX = 0d; event.player.motionZ = 0d; if (!event.player.isSneaking()) event.player.motionY = 0; } } } }
July 11, 201510 yr event.player.motionX = motionX; event.player.motionY = motionY; event.player.motionZ = motionZ; That's because you also set the the motionY in the way you are looking. Setting motionY to 0 should fix that. Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/
July 11, 201510 yr So is there anything else you need? You said "it's not finished" but I don't see a question :C 1.7.10 is no longer supported by forge, you are on your own.
July 11, 201510 yr larsgerrits: flying is what I want It's not a bug, it's a feature. Sorry, misread. I thought you didn't want to move in the Y direction and only in the X and Z directions. Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/
July 11, 201510 yr Author So is there anything else you need? You said "it's not finished" but I don't see a question :C Yeah, I need a bunch Mostly, I'm trying to learn it on my own, and just come here when I'm stuck. The last bit of code I posted was just a sanity check. See if you guys see anything just plain wrong in the code.
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.