Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

LazyOptional


yuckyh
 Share

Recommended Posts

So I have some problems, which is

1. I don't understand what this thing does

2. I want to return LazyOptional in my capability provider, but it gives me the cast error because idk how

3. I want to get the type of the LazyOptional(get T from LazyOptional<T>)

 

Please help me out, if there's a necessity to post my code then I will edit this post

Link to comment
Share on other sites

I think you should post your code

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.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)

Link to comment
Share on other sites

  • 3 months later...
 
 
0
 Advanced issues found
 
 
 
On 4/2/2019 at 7:02 AM, Cadiboo said:

I think you should post your code

^Why? (Almost think you're stupid. No offense)

 

1. From what I understand, it keeps from returning null without the dev knowing.

2. LazyOptional.of((NonNullSupplier<T>) Optional.fromNullable("your capability  instance here"));

3. Use .orElse in LazyOptional and set null as the argument. If you get null and not a capability then the LazyOptional is empty.

 

Took me literally weeks to find the answer for 2. :/

 

And take at me mod source for guidance:

Github

Link to comment
Share on other sites

Somehow my post doesn't display properly.

 

Here is a redo:

On 4/2/2019 at 7:02 AM, Cadiboo said:

I think you should post your code

^Why (I Almost think you're stupid. No offense)

 

1. From what I understand, it keeps from returning null without the dev knowing.

2. 

LazyOptional.of((NonNullSupplier<T>) Optional.fromNullable("Your capability instance here"));

3. Use .orElse in LazyOptional and set null as the argument. If you get null and not a capability instance then the LazyOptional is empty.

 

Took me literally weeks to find the answer for 2. :/

And take a look at my mod source for guidance:

https://github.com/WotblitzMC/FEUniversial

Edited by WOTBLITZ
Link to comment
Share on other sites

You should return LazyOptional.of(() -> yourCapabilityInstance).cast(); in getCapability, or even better, store LazyOptional.of(() -> yourCapabilityInstance) in a field to reduce the number of objects that you create.

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.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)

Link to comment
Share on other sites

  • 1 month later...
  • Thanks 1

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.