Jump to content

[1.14.3] SOLVED onPlayerDestroy playing twice + how to send msg in chat


Recommended Posts

Posted (edited)

Hi,

 

in my custom block class I am overidding the onplayerdestroy to detect when the player destroys his first block of this type - it works with the exception that the system prints it twice. I have no idea why it would do that since the normal onPlayerDestroy does nothing. 

 

Also, I would want to send a message in the chat to the player when the block is destroyed instead of a simple println - I have no idea how though. 


Thanks for your help - here is the block class containing the overidden onPlayerDestroy:
 

https://github.com/Cyborgmas/ZodiacGemMod-1.14.2/blob/master/src/main/java/com/cyborgmas/zodiacgemmod/block/ZodiacGemBlock.java

Edited by Cyborgmas
Posted

It's called twice (once on server, once on client). If u want to run some code only once, you have to decide which side.

If you want to send a message to a player, you need to run it on server side.

To restrict code only to server side use world.isRemote check.

It returns true for client worlds and false for server.

And for sending messages to a player, I'm not sure if it wasn't changed in 1.14, but in previous versions it was EntityPlayer#sendMessage(ITextComponent).

 

Posted (edited)

Ok never mind my other question, i figured that out, now I'm trying to get the sending messages part going but I'm not finding anything.

In  1.14 it's now PlayerEntity instead of EntityPlayer, but I can't find anything that requires an ITextComponent

 

Edit:

My problem is that I am in a static context ... don't know how to make it work

 

Updated the git repo here is my class

https://github.com/Cyborgmas/ZodiacGemMod-1.14.2/blob/master/src/main/java/com/cyborgmas/zodiacgemmod/block/ZodiacGemBlock.java

Edited by Cyborgmas
Posted
1 hour ago, Cyborgmas said:

My problem is that I am in a static context ... don't know how to make it work

Post your updated code

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted (edited)

So you need to get the entity of your player, but the method onPlayerDestroy does not come with this parameter. You can get the player only using world and get entities... but it is not accurate.

You should use other method, try to override method called removedByPlayer, it comes with PlayerEntity as parameter.

Keep in mind though, that you need to call the super method when overriding this, or your block will not be set to air.

 

So sending the message should look like this:

player.sendMessage(new StringTextComponent("your message"));

 

Edited by Dipo

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.