Posted June 25, 20196 yr 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 June 26, 20196 yr by Cyborgmas
June 25, 20196 yr 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).
June 25, 20196 yr 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 June 25, 20196 yr by Cyborgmas
June 26, 20196 yr 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 June 26, 20196 yr by Cyborgmas
June 26, 20196 yr 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 Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.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)
June 26, 20196 yr 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 June 26, 20196 yr 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.