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