#Supplier with varargs as return
1 messages · Page 1 of 1 (latest)
how would you use such supplier ?
Currently there are two ways i would use this supplier:
For multiple Z's it would be this call
ModBlocks.getBlocksOfType(filterClass).toArray(Block[]::new);
which gives a array of Block (which is the Z in my case)
For a single Z it looks like this
ModBlocks.SPECIFIC_BLOCK.get()
which returns a single block.
Detected code, here are some useful tools:
ModBlocks.getBlocksOfType(filterClass).toArray(Block[]::new);
which gives a array of Block(which is the Z in mycase ) For a single Z it looks likethis
Block[]::new corresponds to IntFunction<Bock[]>(aka what's present in Stream#toArray or Function<Integer, Block[]>
Actually, it's a Function<Integer, Block[]> (or any functional interface with a matching signature) . The array constructor takes in a size
Ah yes my bad
Or IntFunction actually
I fixed my message
When i do this
wouldnt work, because this gives back a single block (not in an array)
why are you using varargs if you dont need an array?
you can introduce your own interface
why can't you use what I said earlier ?
.toArray(Block[]::new)
with IntFunction<Bock[]>
@carmine tide
Your question has been closed due to inactivity.
If it was not resolved yet, feel free to just post a message below
to reopen it, or create a new thread.
Note that usually the reason for nobody calling back is that your
question may have been not well asked and hence no one felt confident
enough answering.
When you reopen the thread, try to use your time to improve the quality
of the question by elaborating, providing details, context, all relevant code
snippets, any errors you are getting, concrete examples and perhaps also some
screenshots. Share your attempt, explain the expected results and compare
them to the current results.
Also try to make the information easily accessible by sharing code
or assignment descriptions directly on Discord, not behind a link or
PDF-file; provide some guidance for long code snippets and ensure
the code is well formatted and has syntax highlighting. Kindly read through
https://stackoverflow.com/help/how-to-ask for more.
With enough info, someone knows the answer for sure 👍
Sorry, didnt have time for anything this weekend.
I think i dont understand correctly. I'm, probably just too stupid. I try to explain it again.
There exists this method which i call (from a library):
entitySupplier,
validBlocks.get();```
The **of** method takes an Supplier (entitySupplier) which is no problem, and varargs (validBlocks.get() in my case).
I want to put this method in a separate method that i can call. Basically like this:
{
return registerBlockEntity(name,
() -> BlockEntityType.Builder.of(
entitySupplier,
validBlocks.get()
).build(null));
}```
My problem is, that i want to call this newly created method **registerBlockEntityType** with either a single Block or an array of Blocks:
ModBlocks.SPECIFIC_BLOCK.get(), which returns a single block
ModBlocks.getBlocksOfType(filterClass).toArray(Block[]::new), which returns an array
I want to use a supplier for those, because both of them are not initialized at registering. So directly calling the get and the getBlocksOfType would result in a crash.
So, using Supplier<Block> validBlocks only allows me to create a supplier with a single Block return.
Using Supplier<Block[]> only allows me to use it with a array return.
What would i need to do to use both (a single block return and an array return) like in varargs in a supplier?