Posted May 8, 20232 yr Hey all, pretty new here, and pretty new at modding too. I have been toying around with a basic test mod, and I am trying to get an item that, when right clicking on a certain block, explodes it and launches the player in the air. Both of those things work, but -The explosion doesn't trigger block updates. This causes any water source blocks near the explosion to simply hover in the void. -I am still unsure as to what is the propper method to change a player or entity's velocity. I currently use get and setDeltaMovement, but lerpMotion has worked too. Is there a particular method that is bound to cause less problems? Here is the relevant code: @Override public InteractionResult useOn(UseOnContext pContext) { BlockPos positionClicked = pContext.getClickedPos(); Block clickedBlock = pContext.getLevel().getBlockState(positionClicked).getBlock(); Player player = pContext.getPlayer(); Vec3 positionDifference = player.getPosition(0f).subtract(new Vec3(positionClicked.getX()+0.5f, positionClicked.getY()+0.5f, positionClicked.getZ()+0.5f)); if (positionDifference.y>0 && positionDifference.length()<2f && isBadDice(clickedBlock)) { if (pContext.getLevel().isClientSide){ player.setDeltaMovement(player.getDeltaMovement().add(0f,8f,0f)); }else{ pContext.getLevel().explode(null,positionClicked.getX()+0.5f,positionClicked.getY()+0.5f,positionClicked.getZ()+0.5f,30f, Explosion.BlockInteraction.BREAK); } } pContext.getItemInHand().hurtAndBreak(1,pContext.getPlayer(), (argplayer) -> argplayer.broadcastBreakEvent(argplayer.getUsedItemHand())); return super.useOn(pContext); } Thank you for your time! Edited May 8, 20232 yr by Sixela963
May 8, 20232 yr All that code does is modify the client state, it never reaches the server where the real state is stored and where you actually want to make modifications. https://forums.minecraftforge.net/topic/123325-1194-destroying-several-adjacent-blocks/?do=findComment&comment=535976 Or use search for the hundreds of other posts about this "sidedSuccess" FAQ. For the complications in modifying entity velocities: https://forums.minecraftforge.net/topic/119553-1192-solved-cannot-get-passengers-of-an-entity-when-there-are-multiple-instances-of-the-entity-in-the-world/#comment-524427 Boilerplate: If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one. If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install Large files should be posted to a file sharing site like https://gist.github.com You should also read the support forum sticky post.
May 8, 20232 yr Author 14 minutes ago, warjort said: All that code does is modify the client state, it never reaches the server where the real state is stored and where you actually want to make modifications. https://forums.minecraftforge.net/topic/123325-1194-destroying-several-adjacent-blocks/?do=findComment&comment=535976 Or use search for the hundreds of other posts about this "sidedSuccess" FAQ. For the complications in modifying entity velocities: https://forums.minecraftforge.net/topic/119553-1192-solved-cannot-get-passengers-of-an-entity-when-there-are-multiple-instances-of-the-entity-in-the-world/#comment-524427 Thanks for the quick reply! indeed, applying the same solution as in the first linked topic fixed it. However, I don't fully understand why. When returning PASS when ran on the server, does it simply stop running the code and not trigger any further events? Why was it even doing the explosion at all then? It is explicitely in a part of the code that only happens when not client side, supposedly. I did not know about how important sidedness was. Also, thank you for the link regarding velocities. I will look into them.
May 8, 20232 yr 34 minutes ago, warjort said: Or use search for the hundreds of other posts about this "sidedSuccess" FAQ. Instead you come back after less than 20 minutes of research (if you did any at all). This is a support forum. Not a teach me modding forum. But to answer part of your question. The vanilla client has lots of "simulation" code that runs client side so the user sees improved responsiveness. e.g. breaking blocks or predicting where entities will move to If the client's simulation gets it wrong, the server (which is authoratitive) will eventually correct it. Boilerplate: If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one. If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install Large files should be posted to a file sharing site like https://gist.github.com You should also read the support forum sticky post.
May 8, 20232 yr Author Yup, I was a bit hasty in my reply. Sorry about that. Frankly, I tend to learn better in a dialog than browsing old threads. I'm still a bit fuzzy on the details of networking, but I know enough to get by for now. Quoting you from an earlier post for future reference: "PASS means you are not interested in this interaction and so it won't send a network packet to the server, making the other code pointless. Use InteractionResult.sidedSuccess(), e.g. see EggItem.use() for a simple example." Marking the topic as solved, since my code now works as intended. (to be clear: what helped me was indeed replacing the return super in the UseOn method with a "return InteractionResult.sidedSuccess(level.isClientSide)" ) If you happen to know of a place besides the forge doc and forum to learn more about the inner workings and proper use of Forge, I would be happy to learn about it.
May 8, 20232 yr 16 minutes ago, Sixela963 said: If you happen to know of a place besides the forge doc and forum to learn more about the inner workings and proper use of Forge, I would be happy to learn about it. The wiki is here: https://forge.gemwire.uk/wiki/Main_Page which has a section on sides. But the api you are using isnt forge, its vanilla minecraft. Don't expect that to be documented. You need to learn it by looking at vanilla code or at other mods. Boilerplate: If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one. If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install Large files should be posted to a file sharing site like https://gist.github.com You should also read the support forum sticky post.
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.