#Getting Item.of() item quantity, pushing elements to an array

26 messages · Page 1 of 1 (latest)

sand bronze
#

How would I get the quantity of Item.of('minecraft:dirt',12)?

What is the proper way of pushing elements to an array?

I need to split quantities of items greater than 64 into multiple stacks of items less than 65, for context.

strong echoBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

earnest moat
#

.count

grand holly
#

array.push(<element>)

earnest moat
#

i missed that part heh

#

im not sure if you can have an Item.of() with a count higher than 64

sand bronze
#

I tested it, you can

#

Also tyvm I'll test this out now

#

How would I get 'minecraft:dirt'?

earnest moat
#

wdym by "get" hmmm

sand bronze
#
const assemblifyInputs = function (items){
    
    let newItems = [];        // new input list
    let currentCount = 0;
    
    items.forEach( item => {    // loop through the input array
        currentCount = item.count;    // get the count of current item
        do {    // if item count is larger than max stack size, split it into multiple "item stacks"
            newItems.push(Item.of(item,currentCount))
            currentCount -= item.maxStackSize;
        }
        while(currentCount > item.maxStackSize) // push at least once in case it's not over the max stack size
    })
    
    return newItems;
}```
earnest moat
#

thats one way to define a function worry

sand bronze
#

What's the best way in 1.20?

earnest moat
#

mc version doesnt matter, its just plain JS
usually you go

function whatever() {...}

or the newer way of doing it

let whatever = () => {...}
sand bronze
#

Ah I have it as a global variable so I thought const (constant) was best

earnest moat
#

add some highlighting to your codeblock by typing js after the first 3 ```

#

```js

sand bronze
#

Nice!! Tyvm for that

earnest moat
#

much easier to read SCpatpat

#

im still a bit confused about your question hmmm

sand bronze
#

It's good, I think you've helped a lot with your feedback

earnest moat
#

i wanna help im just not sure how to interpret your question

sand bronze
#

I was interpreting it as getting the first argument part of Item.of (the item ID) which I assume is a String

earnest moat
#

yeah you just type that, or depending on how you want to use this, get it from somewhere else

sand bronze
#

I gotcha, thanks for clarifying!