Jump to content

[1.12.2] PlayerTickEvent [Solved]


poopoodice

Recommended Posts

I've registered the event using

MinecraftForge.EVENT_BUS.register
	@SubscribeEvent
	public void onPlayerTick(PlayerTickEvent event)
	{
		EntityPlayer player = Minecraft.getMinecraft().player;
        if(player != null)
        {
        	ItemStack itemstack = player.getHeldItemMainhand();
	        if(itemstack.areItemStacksEqual(itemstack, new ItemStack(Items.FEATHER)))
	       	{
	        	this.holding = true;
	      	}
	        if(this.holding && player.isAirBorne)
	        {
	        	event.player.fallDistance = 0.0F;
	        	event.player.motionY *= 0.90D;
	        	player.velocityChanged = true;
	        }
	        this.holding = false;
        }
	}

So basically everything works fine, whenever the player is holding a feather, the player doesn't take any fall damage and the player falls slower as well. But when I quit the game (singleplayer) and rejoin, everything just not working anymore, the player is no longer has a slower falling speed and it now takes fall damage. 

What might cause these?

Edited by poopoodice
Link to comment
Share on other sites

32 minutes ago, poopoodice said:

this.holding = true;

You can't do this in an event class. They are singletons. Just do the areItemStacksEqual check every tick. Also the event parameter has a getPlayer method use that instead of Minecraft.getMinecraft().player because that is client only and thus you are reaching across logical sides.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

2 hours ago, poopoodice said:

I've registered the event using


MinecraftForge.EVENT_BUS.register

	@SubscribeEvent
	public void onPlayerTick(PlayerTickEvent event)
	{
		EntityPlayer player = Minecraft.getMinecraft().player;
        if(player != null)
        {
        	ItemStack itemstack = player.getHeldItemMainhand();
	        if(itemstack.areItemStacksEqual(itemstack, new ItemStack(Items.FEATHER)))
	       	{
	        	this.holding = true;
	      	}
	        if(this.holding && player.isAirBorne)
	        {
	        	event.player.fallDistance = 0.0F;
	        	event.player.motionY *= 0.90D;
	        	player.velocityChanged = true;
	        }
	        this.holding = false;
        }
	}

So basically everything works fine, whenever the player is holding a feather, the player doesn't take any fall damage and the player falls slower as well. But when I quit the game (singleplayer) and rejoin, everything just not working anymore, the player is no longer has a slower falling speed and it now takes fall damage. 

What might cause these?

You're reaching across logical sides. Use PlayerTickEvent#player.

 

Don't use Minecraft::getMinecraft unless you have to (adding client effects, etc.).

Edited by Differentiation
Link to comment
Share on other sites

Solved by removing boolean variable

holding

One thing I want to mention is I need to use

 

Minecraft.getMinecraft().player.velocityChanged = true;

because when I use

event.player.velocityChanged = true;

the player will not be able to move in the air, and that's not what I want

 

Thanks for the replies.

Edited by poopoodice
Link to comment
Share on other sites

2 hours ago, poopoodice said:

Solved by removing boolean variable


holding

One thing I want to mention is I need to use

 


Minecraft.getMinecraft().player.velocityChanged = true;

because when I use


event.player.velocityChanged = true;

the player will not be able to move in the air, and that's not what I want

 

Thanks for the replies.

Well, if you're gonna use that then at least include a check for World#isRemote. Otherwise you'd crash with - I believe - ClassDefNotFoundException on a dedicated server. 

 

Also, what do you mean move in the air?? The client thread does run on that event.

 

Lastly, just use EntityPlayer#getHeldItemMainhand method to check for the item they are holding instead of what you're doing.

Edited by Differentiation
Link to comment
Share on other sites

8 hours ago, Differentiation said:

Well, if you're gonna use that then at least include a check for World#isRemote. Otherwise you'd crash with - I believe - ClassDefNotFoundException on a dedicated server. 

 

Also, what do you mean move in the air?? The client thread does run on that event.

 

Lastly, just use EntityPlayer#getHeldItemMainhand method to check for the item they are holding instead of what you're doing.

Well, it didn't crash or appear any error (I haven't tried it on multiplayer

What I mean by the player can't move in the air is when "player.isAirBorne" and it doesn't really matter.

I was trying to say when using

event.player.velocityChanged = true

the player won't be able to move in x and z direction.

unless change event.player to

Minecraft.getMinecraft().player

I don't know why but it is just like this.

I might record a vd later on to explain this more clearly.

Edited by poopoodice
Link to comment
Share on other sites

9 hours ago, Differentiation said:

Well, if you're gonna use that then at least include a check for World#isRemote. Otherwise you'd crash with - I believe - ClassDefNotFoundException on a dedicated server. 

Sadly that isn't enough. Any reference to Minecraft.getMinecraft() will crash the dedicated server with that exception as soon as the class is loaded. The offending code must be isolated in a separate class and stripped from the server's .jar file using @SideOnly. Careful though, because then the code won't exist at all on the server, so you can still enjoy a crash by referencing a method stripped by @SideOnly. This is why proxies are useful.

52 minutes ago, poopoodice said:

Well, it didn't crash or appear any error

52 minutes ago, poopoodice said:

I haven't tried it on multiplayer

Like Differentiation said, it crashes a dedicated server. (take a look at this)

 

58 minutes ago, poopoodice said:

the player won't be able to move in x and z direction.

Not exactly sure why this is, since you're not modifying x/z motion, but my guess would be all the reaching across logical sides that you're doing, which can cause some seemingly weird bugs.

  • Like 1

Fancy 3D Graphing Calculator mod, with many different coordinate systems.

Lightweight 3D/2D position/vector transformations library, also with support for different coordinate systems.

Link to comment
Share on other sites

1 hour ago, poopoodice said:

Well, it didn't crash or appear any error (I haven't tried it on multiplayer

What I mean by the player can't move in the air is when "player.isAirBorne" and it doesn't really matter.

I was trying to say when using


event.player.velocityChanged = true

the player won't be able to move in x and z direction.

unless change event.player to


Minecraft.getMinecraft().player

I don't know why but it is just like this.

I might record a vd later on to explain this more clearly.

I don't really understand what you're trying to do here...

 

You have to understand that Minecraft::getMinecraft is a method only on the client thread. And the Minecraft class is only a class on the client thread. You cannot reference these on the running server thread. This will undoubtedly crash a dedicated server.

Link to comment
Share on other sites

After all, I notice that player.velocityChanged was not necessary

and I decided to move code from the eventhandler to an itemclass ( in onUpdate() )

	@Override
	public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) 
	{
		if(isSelected && entityIn instanceof EntityPlayer)
		{
			EntityPlayer player = (EntityPlayer) entityIn;
        	player.fallDistance = 0.0F;
        	player.motionY *= 0.90D;
		}
	}

I just want to know if this fixes all the problems?

Or I will still need some checkings and even more things to solve the client-server issue?

Link to comment
Share on other sites

12 minutes ago, poopoodice said:

After all, I notice that player.velocityChanged was not necessary

and I decided to move code from the eventhandler to an itemclass ( in onUpdate() )


	@Override
	public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) 
	{
		if(isSelected && entityIn instanceof EntityPlayer)
		{
			EntityPlayer player = (EntityPlayer) entityIn;
        	player.fallDistance = 0.0F;
        	player.motionY *= 0.90D;
		}
	}

I just want to know if this fixes all the problems?

Or I will still need some checkings and even more things to solve the client-server issue?

You're good. Now its solved.

 

Note: you don't have to make an instance of EntityPlayer, you can just use Entity.

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

    • So i know for a fact this has been asked before but Render stuff troubles me a little and i didnt find any answer for recent version. I have a custom nausea effect. Currently i add both my nausea effect and the vanilla one for the effect. But the problem is that when I open the inventory, both are listed, while I'd only want mine to show up (both in the inv and on the GUI)   I've arrived to the GameRender (on joined/net/minecraft/client) and also found shaders on client-extra/assets/minecraft/shaders/post and client-extra/assets/minecraft/shaders/program but I'm lost. I understand that its like a regular screen, where I'd render stuff "over" the game depending on data on the server, but If someone could point to the right client and server classes that i can read to see how i can manage this or any tip would be apreciated
    • Let me try and help you with love spells, traditional healing, native healing, fortune telling, witchcraft, psychic readings, black magic, voodoo, herbalist healing, or any other service your may desire within the realm of african native healing, the spirits and the ancestors. I am a sangoma and healer. I could help you to connect with the ancestors , interpret dreams, diagnose illness through divination with bones, and help you heal both physical and spiritual illness. We facilitate the deepening of your relationship to the spirit world and the ancestors. Working in partnership with one\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’s ancestors is a gift representing a close link with the spirit realm as a mediator between the worlds.*   Witchdoctors, or sorcerers, are often purveyors of mutis and charms that cause harm to people. we believe that we are here for only one purpose, to heal through love and compassion.*   African people share a common understanding of the importance of ancestors in daily life. When they have lost touch with their ancestors, illness may result or bad luck. Then a traditional healer, or sangoma, is sought out who may prescribe herbs, changes in lifestyle, a career change, or changes in relationships. The client may also be told to perform a ceremony or purification ritual to appease the ancestors.*   Let us solve your problems using powerful African traditional methods. We believe that our ancestors and spirits give us enlightenment, wisdom, divine guidance, enabling us to overcome obstacles holding your life back. Our knowledge has been passed down through centuries, being refined along the way from generation to generation. We believe in the occult, the paranormal, the spirit world, the mystic world.*   The services here are based on the African Tradition Value system/religion,where we believe the ancestors and spirits play a very important role in society. The ancestors and spirits give guidance and counsel in society. They could enable us to see into the future and give solutions to the problems affecting us. We use rituals, divination, spells, chants and prayers to enable us tackle the task before us.*   I have experience in helping and guiding many people from all over the world. My psychic abilities may help you answer and resolve many unanswered questions
    • Let me try and help you with love spells, traditional healing, native healing, fortune telling, witchcraft, psychic readings, black magic, voodoo, herbalist healing, or any other service your may desire within the realm of african native healing, the spirits and the ancestors. I am a sangoma and healer. I could help you to connect with the ancestors , interpret dreams, diagnose illness through divination with bones, and help you heal both physical and spiritual illness. We facilitate the deepening of your relationship to the spirit world and the ancestors. Working in partnership with one\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’s ancestors is a gift representing a close link with the spirit realm as a mediator between the worlds.*   Witchdoctors, or sorcerers, are often purveyors of mutis and charms that cause harm to people. we believe that we are here for only one purpose, to heal through love and compassion.*   African people share a common understanding of the importance of ancestors in daily life. When they have lost touch with their ancestors, illness may result or bad luck. Then a traditional healer, or sangoma, is sought out who may prescribe herbs, changes in lifestyle, a career change, or changes in relationships. The client may also be told to perform a ceremony or purification ritual to appease the ancestors.*   Let us solve your problems using powerful African traditional methods. We believe that our ancestors and spirits give us enlightenment, wisdom, divine guidance, enabling us to overcome obstacles holding your life back. Our knowledge has been passed down through centuries, being refined along the way from generation to generation. We believe in the occult, the paranormal, the spirit world, the mystic world.*   The services here are based on the African Tradition Value system/religion,where we believe the ancestors and spirits play a very important role in society. The ancestors and spirits give guidance and counsel in society. They could enable us to see into the future and give solutions to the problems affecting us. We use rituals, divination, spells, chants and prayers to enable us tackle the task before us.*   I have experience in helping and guiding many people from all over the world. My psychic abilities may help you answer and resolve many unanswered questions
    • Let me try and help you with love spells, traditional healing, native healing, fortune telling, witchcraft, psychic readings, black magic, voodoo, herbalist healing, or any other service your may desire within the realm of african native healing, the spirits and the ancestors. I am a sangoma and healer. I could help you to connect with the ancestors , interpret dreams, diagnose illness through divination with bones, and help you heal both physical and spiritual illness. We facilitate the deepening of your relationship to the spirit world and the ancestors. Working in partnership with one\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’s ancestors is a gift representing a close link with the spirit realm as a mediator between the worlds.*   Witchdoctors, or sorcerers, are often purveyors of mutis and charms that cause harm to people. we believe that we are here for only one purpose, to heal through love and compassion.*   African people share a common understanding of the importance of ancestors in daily life. When they have lost touch with their ancestors, illness may result or bad luck. Then a traditional healer, or sangoma, is sought out who may prescribe herbs, changes in lifestyle, a career change, or changes in relationships. The client may also be told to perform a ceremony or purification ritual to appease the ancestors.*   Let us solve your problems using powerful African traditional methods. We believe that our ancestors and spirits give us enlightenment, wisdom, divine guidance, enabling us to overcome obstacles holding your life back. Our knowledge has been passed down through centuries, being refined along the way from generation to generation. We believe in the occult, the paranormal, the spirit world, the mystic world.*   The services here are based on the African Tradition Value system/religion,where we believe the ancestors and spirits play a very important role in society. The ancestors and spirits give guidance and counsel in society. They could enable us to see into the future and give solutions to the problems affecting us. We use rituals, divination, spells, chants and prayers to enable us tackle the task before us.*   I have experience in helping and guiding many people from all over the world. My psychic abilities may help you answer and resolve many unanswered questions
    • Let me try and help you with love spells, traditional healing, native healing, fortune telling, witchcraft, psychic readings, black magic, voodoo, herbalist healing, or any other service your may desire within the realm of african native healing, the spirits and the ancestors. I am a sangoma and healer. I could help you to connect with the ancestors , interpret dreams, diagnose illness through divination with bones, and help you heal both physical and spiritual illness. We facilitate the deepening of your relationship to the spirit world and the ancestors. Working in partnership with one\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’s ancestors is a gift representing a close link with the spirit realm as a mediator between the worlds.*   Witchdoctors, or sorcerers, are often purveyors of mutis and charms that cause harm to people. we believe that we are here for only one purpose, to heal through love and compassion.*   African people share a common understanding of the importance of ancestors in daily life. When they have lost touch with their ancestors, illness may result or bad luck. Then a traditional healer, or sangoma, is sought out who may prescribe herbs, changes in lifestyle, a career change, or changes in relationships. The client may also be told to perform a ceremony or purification ritual to appease the ancestors.*   Let us solve your problems using powerful African traditional methods. We believe that our ancestors and spirits give us enlightenment, wisdom, divine guidance, enabling us to overcome obstacles holding your life back. Our knowledge has been passed down through centuries, being refined along the way from generation to generation. We believe in the occult, the paranormal, the spirit world, the mystic world.*   The services here are based on the African Tradition Value system/religion,where we believe the ancestors and spirits play a very important role in society. The ancestors and spirits give guidance and counsel in society. They could enable us to see into the future and give solutions to the problems affecting us. We use rituals, divination, spells, chants and prayers to enable us tackle the task before us.*   I have experience in helping and guiding many people from all over the world. My psychic abilities may help you answer and resolve many unanswered questions
  • Topics

×
×
  • Create New...

Important Information

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