#Set setItem as undefined

1 messages · Page 1 of 1 (latest)

plush ferry
#

@drifting coral

drifting coral
#

what's the nullChecker?

plush ferry
#

that's what I use to check if a slot has nothing in it'

#

which would then lead to that slot being cleared with however it works

#

returns true when there is no item and returns false when there is an item

plush ferry
#

managed to get it to work

#

I switched to using commands and I ain't getting any errors throwing

drifting coral
#

try this


export function EnableCombatMode(player) {
    const { dimension, headLocation, name } = player
    const query = {location: headLocation, tags: [name], closest: 1};
    const [invStore] = Array.from(dimension.getEntities(query));
    if (!invStore) return;
    const container = player.getComponent('inventory').container;
    const inv = invStore.getComponent('inventory').container;
    const voidItem = new ItemStack(MinecraftItemTypes.dirt,0);
    for (let i = 0; i < 9; i++) {
        if (!container.swapItems(i, i, inv)){
            const myItem = container.getItem(i) ?? voidItem;
            const invItem = inv.getItem(i) ?? voidItem;
            container.setItem(i, invItem);
            inv.setItem(i, myItem);
        }
    }
};
#

also, import ItemStack and MinecraftItemTypes

plush ferry
#

ight

#

doesn't seem to work

drifting coral
#

is the entity following the player?

#

does it message that enable part?

plush ferry
#

I've managed to get it working with my original code taking new ItemStack(MinecraftItemTypes.dirt,0);

drifting coral
#

ok

plush ferry
#

but probs not most efficient

#

I'll stick with my code for now as I understand it

drifting coral
#

works fine for me tho

#

cursed, but yeh

plush ferry
#

nvm that does work

#

my bad'

drifting coral
#

cool

plush ferry
#

thanks for the help man

drifting coral
#

w

plush ferry
#

:)

#

have a good one