Posted January 23, 20205 yr The onBlockActivated method in the class Block (along with many other methods) are deprecated, however I need to call them. I read that I need (or should) use this same method but from the class BlockState instead and not use the deprecated one. However I do not know how to access this method. My own block class is a subclass of Block and therefore cannot also be a subclass of BlockState to access the method . The deprecated method in Block has a BlockState parameter but whenever I try to access onBlockActivated through that parameter the game crashes when I right click on my blocks. I also tried to get the blockstate through getBlock().getDefualtBlockstate() but that also resulted in a crash. Is there a specific way to to this? Or should I just use the deprecated method anyways?
January 23, 20205 yr Author 3 minutes ago, diesieben07 said: If you need to call the method then you need to call the one in BlockState. Show your attempt at doing so if thats what you are doing. If you need to override the method, then thats fine. Mojang abuses @Deprecated in this way. public class ModBlock extends Block { @Override public boolean onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) { return super.onBlockActivated(state, worldIn, pos, player, handIn, hit); //return state.onBlockActivated(worldIn, player, handIn, hit); //return this.getBlock().getDefaultState().onBlockActivated(worldIn, player, handIn, hit); } } Here is the onBlockActivated method in my own block class. The two commented lines are the ones I tried, but they resulted in a crash; java.lang.StackOverflowError: null. I guess it's because the BlockState parameter hasn't been instantiated yet? I just don't know how to access the BlockState method.
January 23, 20205 yr Author 8 minutes ago, diesieben07 said: Well, calling onBlockActivated again from within onBlockActivated will of course result in an infinite loop which causes a stack overflow (onBlockActivated is called, which calls onBlockActivated again, which calls onBlockActivated again, which calls...). What are you trying to achieve? I simply want to set up basic functionality when right clicking on a block. And the infinite loop makes sense, however I have tried to create my own method and call the BlockState method from that but it doesn't work. Probably because my method is never getting called anywhere, so I don't know how to go about this.
January 23, 20205 yr Author 4 minutes ago, diesieben07 said: I don't know what you mean by "basic functionality". To make your block do something when right click you just need to override onBlockActivated and do whatever it is you want it to do in that method. Well I shouldn't use the onBlockActivated from Block as it is deprecated. But at the same time I cannot access and override the one from BlockState because my block class isn't a subclass of BlockState. So how do I override a method I do not have access to?
January 23, 20205 yr Author 3 minutes ago, diesieben07 said: Well sure, I can override the Block method and its fine. But what is the whole deal about using the method from BlockState instead if all we need to do is override the Block one?
January 25, 20205 yr Author On 1/23/2020 at 9:54 PM, diesieben07 said: The point is that if you want to call onBlockActivated you do it on the BlockState. Ah, of course. I'm stupid, sorry. Thanks for the help!
April 29, 20205 yr 9 minutes ago, Aes123 said: Hey im having the same problem, could you send me the code which fixed the issue? On 1/23/2020 at 2:54 PM, diesieben07 said: If you need to call the method then you need to call the one in BlockState. Show your attempt at doing so if thats what you are doing. If you need to override the method, then thats fine. Mojang abuses @Deprecated in this way. On 1/23/2020 at 3:54 PM, diesieben07 said: The point is that if you want to call onBlockActivated you do it on the BlockState. All of the answers are here, if you are still having a problem, it may be something else. I would should start a new thread, and post your code, and probably also debug.log.
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.