Posted January 20, 20232 yr Hello, I'm trying to store data in the block's nbt data, but i have no idea how to do this, apparently im supposed to use capabilities but there's so little documentation, and I have no idea how to do this, can someone please provide me some example code? This is my signature. I don't really too much know about java but i try to help and i try to get help from others too. Thank you!
January 20, 20232 yr You only need a capability if it is not your BlockEntity. https://forge.gemwire.uk/wiki/Capabilities (includes a simple example at the bottom but for a serializable Entity capability rather than a BlockEntity - same principle applies). If it is your BlockEntity https://forge.gemwire.uk/wiki/Block_Entities#Storing_Data_within_your_BlockEntity 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.
January 21, 20232 yr Author Hey I did all that, tbh i've been struggling the last hour trying to make the thing, I did everything but now I'm trying to add the capability to the block and then set it when it is placed down, this is the code: @NotNull @Override public <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap, @Nullable Direction side) { return LazyOptional.of(ATMCapability::new).cast(); } @Override public void onPlace(BlockState state, Level world, BlockPos pos, BlockState blockState, boolean p_60570_) { world.getCapability(ATMCapability.INSTANCE).ifPresent((cap) -> { cap.setPrivateKey("test"); cap.setAtmId("test"); }); System.out.println("ATM created!"); System.out.println("Private key: " + world.getCapability(ATMCapability.INSTANCE).orElseThrow(NullPointerException::new).getPrivateKey()); System.out.println("ATM ID: " + world.getCapability(ATMCapability.INSTANCE).orElseThrow(NullPointerException::new).getAtmId()); } I have no idea if this is even correct, but i dont know what else to do, it keeps giving me the nullpointerexception which means that its not being saved This is my signature. I don't really too much know about java but i try to help and i try to get help from others too. Thank you!
January 21, 20232 yr Read the part about attaching capabilities on the wiki. 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.
January 21, 20232 yr Author Yes, but I don't understand the AttachCapabilitiesEvent<Entity>, how does that attach it to the atm block, I tried subscribing and all of that, changing code i dont know what to do, can you please explain it? This is my signature. I don't really too much know about java but i try to help and i try to get help from others too. Thank you!
January 21, 20232 yr Replace Entity with BlockEntity then check if you want to attach to that BlockEntity using instanceof e.g. https://github.com/MehVahdJukaar/WIPsuppMULTI/blob/cff33b050cf564d4fffb2ecfff8cd888528fe82d/forge/src/main/java/net/mehvahdjukaar/supplementaries/common/capabilities/forge/CapabilityHandler.java or one of the other examples from this search: https://github.com/search?l=&p=3&q=AttachCapabilitiesEvent+BlockEntity&ref=advsearch&type=Code 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.
January 21, 20232 yr Author Hey, yeah i did that and made a blockentity and now im getting this error class ...atm.capability.ATMCapability cannot be cast to class ...atm.capability.ATMCapabilityInterface Edited January 21, 20232 yr by Anonomys This is my signature. I don't really too much know about java but i try to help and i try to get help from others too. Thank you!
January 21, 20232 yr If you don't know what that error means you are in the wrong forum. You want a "learning java" forum. 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.
January 21, 20232 yr Author Yes but its not being cast to that anywhere, ive looked through everything This is my signature. I don't really too much know about java but i try to help and i try to get help from others too. Thank you!
January 21, 20232 yr Huh? A capability implementation must implement its own interface. You don't even show the full stacktrace of the error which will tell you where the cast occurs (maybe implicitly inserted by the compiler because of generics?). If you want further help, you need to show everything you are doing. Posting snippets of code out of context and truncated error messages just means your question unanswerable and will probably just mean your question gets ignored. We are not going to waste our time chasing you for relevant information. It is you that wants help. Edited January 21, 20232 yr by warjort 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.
January 21, 20232 yr Author I found where the error was, in the blockentity class the getCapability was returning the ATMCapability.INSTANCE instead of the ATMCapabilityImplementation. Sorry for taking your time This is my signature. I don't really too much know about java but i try to help and i try to get help from others too. Thank you!
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.