#Supplier with varargs as return

1 messages · Page 1 of 1 (latest)

tribal parrotBOT
#

<@&987246399047479336> please have a look, thanks.

hollow lance
#

how would you use such supplier ?

carmine tide
#

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.

tribal parrotBOT
hollow lance
gentle dawn
hollow lance
#

I fixed my message

quiet zephyr
#

you can pass arrays to vararg parameters

#

so have the supplier supply an array

carmine tide
quiet zephyr
#

you can introduce your own interface

hollow lance
#

.toArray(Block[]::new)

#

with IntFunction<Bock[]>

tribal parrotBOT
#

@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 👍

carmine tide
# hollow lance why can't you use what I said earlier ?

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?