Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

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

Featured Replies

Posted

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

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).

 

  • Author

ah ok, I'll try that but once i check, how do i then specify that i want to send it to the server side only?

Edited by Cyborgmas

  • Author

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

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)

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.