Jump to content

Recommended Posts

Posted

Hello, i'm new to the forge community..

 

i've been learning and learning how does forge work from a long time ago

 

and now i need some help because i can't really find a event that fire when the player is flying...

 

Any ideas please ?

Posted

There is no PlayerFlying event. List of available events: https://dl.dropboxusercontent.com/s/h777x7ugherqs0w/forgeevents.html (Put together by Vic_)

 

If you want to check if the player is flying, you would need to subscribe to a commonly fired event, like the LivingEvent#LivingUpdateEvent, which is fired on each tick (when the entity updates).

Check if the entity is an instance of EntityPlayer, if so, cast the event#entity to EntityPlayer.

 

Once that has been done, you gain access to EntityPlayer#capabilities#isFlying.

 

I however, strongly urge you to not disable flying, from this event. If a player is flying using other methods, like creative mode, various baubles, spells etc, the event will still disable the flight, breaking the flight, which had nothing to do with your flight mechanic.

If you want to enable/disable flight, especially if based on armour/items, do so through the item's onUpdate methods, or by the LivingEvent#LivingUpdateEvent again, and check the worn armour.

Also previously known as eAndPi.

"Pi, is there a station coming up where we can board your train of thought?" -Kronnn

Published Mods: Underworld

Handy links: Vic_'s Forge events Own WIP Tutorials.

Posted

There is no PlayerFlying event. List of available events: https://dl.dropboxusercontent.com/s/h777x7ugherqs0w/forgeevents.html (Put together by Vic_)

 

If you want to check if the player is flying, you would need to subscribe to a commonly fired event, like the LivingEvent#LivingUpdateEvent, which is fired on each tick (when the entity updates).

Check if the entity is an instance of EntityPlayer, if so, cast the event#entity to EntityPlayer.

 

Once that has been done, you gain access to EntityPlayer#capabilities#isFlying.

 

I however, strongly urge you to not disable flying, from this event. If a player is flying using other methods, like creative mode, various baubles, spells etc, the event will still disable the flight, breaking the flight, which had nothing to do with your flight mechanic.

If you want to enable/disable flight, especially if based on armour/items, do so through the item's onUpdate methods, or by the LivingEvent#LivingUpdateEvent again, and check the worn armour.

Hi.. i tryied it and it didn't work it crashes when i connect to singleplayer world.

 

This is my code :

	@SubscribeEvent
public void onLivingUpdateEvent(LivingUpdateEvent event, EntityPlayer player, Entity entity)
{
	if(entity instanceof EntityPlayer)
	{

	updateMS();
	mc.thePlayer.motionX = 0;
	mc.thePlayer.motionY = 0;
	mc.thePlayer.motionZ = 0;
	mc.thePlayer.jumpMovementFactor = speed;
	if(KeyInputHandler.leJoueurVole == true)
	{
	updateFlyHeight();
	mc.thePlayer.sendQueue
		.addToSendQueue(new C03PacketPlayer(true));

	if(flyHeight <= 290 && hasTimePassedM(500) || flyHeight > 290
		&& hasTimePassedM(100))
	{
		goToGround();                                                                                 
           System.out.println("Test.");
		updateLastMS();
		}
	}
	}
}

what im i doing wrong ?

 

ps : i'm not tying to stop the player from flying.

(sorry for bad language)

Posted

1) you are accessing the "mc" (Minecraft#getMinecraft()) on what is likely both server-side & client-side. Minecraft#getMinecraft() is purely clientside.

 

2) You never cast the entity to EntityPlayer.

 

3) You do not need to get Minecraft#getMinecraft(), to get access to the player's motionx|y|z, see #2

 

4) Always, always provide a crashlog if you want help with fixing a crash issue. I can only guess that the issue is caused by you calling Minecraft#getMinecraft(), and that alone. Might be another issue before, or after this one, entirely.

 

if(entity instanceof EntityPlayer){
EntityPlayer player = (EntityPlayer) entity;
player.motionX =.....
}

Also previously known as eAndPi.

"Pi, is there a station coming up where we can board your train of thought?" -Kronnn

Published Mods: Underworld

Handy links: Vic_'s Forge events Own WIP Tutorials.

Posted

To add to that:

 

Adding parameters to a method doesn't make them get filled in by magic.  The event object contains all the data you will ever get from that event (and guess what: LivingUpdateEvent contains an entity!  The one getting the update!)

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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



×
×
  • Create New...

Important Information

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