#Script API General

1 messages · Page 87 of 1

warm mason
#

?

dusty temple
#

Nevermind it does, I just realized it has to be set in place, can't add it dynamically

nova flame
#

This is why ur bad at json ui

fallow minnow
#

U barely know JavaScript so

warm mason
#

🍿 bao_foxxo_sunglasses

nova flame
warm mason
nova flame
#

Serty dont get involved before i beat u up boy

prisma shard
#

What does this do?

warm mason
prisma shard
#

bruh

warm mason
#

Minato just forgot that ItemTypes.getAll() returns ItemType[] and not String[]

distant tulip
#

.

distant tulip
halcyon phoenix
#

is it possible to do ui with just script and no json ui?

sly valve
halcyon phoenix
sly valve
halcyon phoenix
#

awright thanks for the help neko

halcyon phoenix
sly valve
#

Not really, maybe try reading the docs

thorn flicker
#

you can use titles to display mana, and use dynamics properties for the mana values.

#

if you want to make the titles look a different way, you will need learn a little bit of #1067869374410657962

thorn flicker
gilded shadow
#

does Player.id changes when the playereave and rejoins the game?

#

I'm currently using it to store data about the player on world dynamic properties.

#

so i wanna be sure if its safe

distant tulip
#

it is server side only, so yeah it is save

halcyon phoenix
worldly heath
gilded shadow
#

also is there a way to check dynamic properties saved in a world outside of minecraft?

halcyon phoenix
#

I dont it once but it's a hell of a hole

#

I didn't udnerstand a single part

worldly heath
halcyon phoenix
#

made a custom cooldown bar

halcyon phoenix
thorn flicker
#

custom emojis you can create and use in a title

sly valve
thorn flicker
sly valve
#

Oh alright

dusky flicker
#

you can hash data

#

im used to write with neovim, cant use vscode anymore

#

i simply think coding with it is too slow

#

maybe if you parse the function

#

but you would need to parse a lot of things

#

and then based on the ast rewrite the function

#

ast is just a recursive tree, so as long as it's defined using objects, you can use JSON with them

sterile epoch
dusky flicker
#

its cuz the one couldnt get used to the keybinds

#

how do this suck bro? im running neovim in terminal and i've got a terminal inside it

#

i dont even need to use the mouse

#

but yeah its confused as hell on the first time

#

i remember when i was switching from vscode, i got confused to exit it

halcyon phoenix
#

and once you get used to it you don't even have to move your hands away from the keyboard

halcyon phoenix
sly valve
dusky flicker
#

by the way, thanks, its working

#

i thought i'd have troubles to debug within linux and running with an unnoficial launcher

halcyon phoenix
#

loading content from url...

#

is this normal?

#

dang this looks cool

short iron
#

I think I've asked this a few days ago but got busy with rl family. My question is does anyone know how to detect when a player gets the "unlock" for recipes. Like when you mine a diamond for the first time it shows you what you can craft now? I'm looking at running some events on it if possible.

halcyon phoenix
#

DUDE WHY WAS NO ONE SUGGESTING ME MCTOOLS BEFORE

#

Dang all my past problems could have been solved by this

#

it has a builtin VSCode editor

#

anybody know what's wrong here? modules version error?

sterile epoch
#

why would anyone care abt not having to use a mouse

#

just seems extra for no reason

dusky flicker
#

and more customizable

#

and uses less ram

remote oyster
#

The ones that talk bad about it are the majority who couldn't master it lol.

#

Which is why other alternatives exist, such as Nano, to name one.

halcyon phoenix
#

some stuff like this can't be answered by questions, you gotta feel it

sterile epoch
#

you legit js write code

#

and save it, and boom you're done

dusky flicker
sterile epoch
halcyon phoenix
uncut lynx
#

Yo guys i might have just cooked

#

so i used firstly claude ai to clean up that shi and use graph system

#

and after that i implemented a lot of stuff

final ocean
#

[Scripting][error]-Unhandled promise rejection: TypeError: not a function at <anonymous> (index.js:56)

Code:

  const form = new ActionFormData()
    .title("§aWarp Menu")
    .body("§fSelect warp")
    .button("Mine §aA")
    .button("Mine §aB")
    .button("Mine §aC")
    .button("Mine §aD")
    .button("Mine §aE")
    .button("Mine §aF")
    .button("Mine §aG")
    .button("Mine §aH")
    .button("Mine §aI")
    .button("Mine §aJ");

  form.show(player).then(response => {
    if (response.canceled) {
      showMainMenu(player);
      return;
    }

    const destinations = [
      { rank: 0, coords: "7 67 20" },
      { rank: 1, coords: "49 67 20" },
      { rank: 2, coords: "91 67 20" },
      { rank: 3, coords: "133 67 20" },
      { rank: 4, coords: "175 67 20" },
      { rank: 5, coords: "217 67 20" },
      { rank: 6, coords: "259 67 20" },
      { rank: 7, coords: "301 67 20" },
      { rank: 8, coords: "343 67 20" },
      { rank: 9, coords: "379 67 20" },
    ];

    const selected = destinations[response.selection];
    if (!selected) {
      showMainMenu(player);
      return;
    }

    const rankObjective = world.scoreboard.getObjective("rank");
    const playerRank = rankObjective?.getScore(player) ?? 0;

    if (playerRank < selected.rank) {
      player.sendMessage(`§cYou need rank §e${selected.rank}§c or more to enter this area!`);
      showMainMenu(player);
      return;
    }

    const overworld = world.getDimension("overworld");
    overworld.runCommandAsync(`tp "${player.name}" ${selected.coords}`);
    player.sendMessage(`§aYou Tp To §bMine ${String.fromCharCode(65 + response.selection)}`);
    showMainMenu(player);
  });
}```

This is the error code extracted from a complete file.
uncut lynx
#

with some corrections ofc from ai

#

i'mma send the vid rq

final ocean
#

Help Me

uncut lynx
prisma shard
#

bruh

warm mason
#

BRUH

dusky flicker
prisma shard
#

a function for generating sphere with blocks would be block-utils? dimension-utils? math-utils?

#

pls someone help me categorize

prisma shard
#

thank u ig

prisma shard
#

No

#

Thats different qeustion

#

i said how can i create the function itself in the post

#

i am just asking for a idea where would i put it

thorn flicker
#

ohh

prisma shard
#

mmmmm

thorn flicker
#

yeah

dusky flicker
#

i dont know why it would be dimension, block or math(please just dont put it here)

sly valve
prisma shard
#

another question

sly valve
#

Go ahead

prisma shard
#
dimension.runCommand(`setblock ${location.x} ${location.y} ${location.z} air destroy`);```
this drops the loot of the block too. How can i make it not drop the loot of the block?
sly valve
#

Dont even use runCommand

thorn flicker
sly valve
prisma shard
thorn flicker
#

welp

#

you cant do that

prisma shard
thorn flicker
#

you have no other option then.

prisma shard
#

aw

sly valve
#

Well

#

You can

prisma shard
#

well

sly valve
#

Somehow

prisma shard
#

kill those items right

thorn flicker
#

let me guess, remove the item

prisma shard
#

lmao

#

wait

thorn flicker
#

that could go wrong

prisma shard
#

the hell

prisma shard
prisma shard
#

gamerule loot drop false

#

gamerule loot drop false

distant tulip
#

preview

prisma shard
#

does it exist

thorn flicker
#

is there a method to play the particle

prisma shard
warm mason
thorn flicker
#

so why did you suggest it

#

if you didnt know

#

bruh

warm mason
#

The result is a useless component.

prisma shard
thorn flicker
#

yeah theres no method

warm mason
prisma shard
#

bruh

thorn flicker
#

lol

sly valve
#

There always is one

prisma shard
distant tulip
#

make your own particle

sly valve
#

No, it means its a bad idea

thorn flicker
#

no, it means it's not recommended

warm mason
thorn flicker
prisma shard
#

ye

distant tulip
thorn flicker
warm mason
distant tulip
thorn flicker
#

is it worth it

warm mason
prisma shard
#

bao_bee_angry I am just gonna use gameule 👎 👎 👎 👎 bye

#

xd

distant tulip
thorn flicker
#

yeah and cause a bunch of issues

#

good luck

prisma shard
thorn flicker
prisma shard
#

i'd just set it to true again after breaking

warm mason
distant tulip
warm mason
#

How do you know the UV coordinates?

prisma shard
thorn flicker
#

if molangvariablemap had a string variable option, and we could use molang for the texture in the particle...

#

wouldnt that be awesome?

distant tulip
prisma shard
#

ok guys thank you for the help i am just gonna kill those items

thorn flicker
warm mason
prisma shard
#

uh doesnt the items drop in a x-0.5 y-0.5 z-0.5 from the block

thorn flicker
#

you might be onto something

distant tulip
thorn flicker
#

what if you drop your diamonds on accident

warm mason
thorn flicker
#

well then again you'll check for the item type

distant tulip
prisma shard
#

men i am stuck

#

oki i made my decision just to not do it

#

remove the destry

thorn flicker
#

but still, what if you drop your cobblestone you mined into the cobblestone being destroyed

#

and poof

#

there goes your cobblestone

#

with the gamerule method, what if someone is mining?

prisma shard
#

ok oko k ok

distant tulip
prisma shard
#

can someone refer to json-ui channel i need sum help there

thorn flicker
#

I dont know json ui

warm mason
#

Dimension.fillBlocks would be a better option

thorn flicker
warm mason
thorn flicker
#

dimension.setBlockType

warm mason
thorn flicker
#

unless its being iterated

distant tulip
thorn flicker
#

oh

warm mason
#

It is quite possible that the shape is not square.

prisma shard
#

ppffft

#

block is a square

thorn flicker
#

ah yes

#

a block is a sphere

#

ik ik

#

im joking

prisma shard
thorn flicker
#

where's your post

warm mason
uncut lynx
#

i compressed it from 400mib sorry for the quality

prisma shard
# warm mason +2000% slowdown from entities

bruh? He is making his replay addon, he just sent his method for the break particles, does he have another way to display those particles? thats the only option for him, even if being aware of slowdown

distant tulip
distant tulip
distant tulip
prisma shard
uncut lynx
#

already i do every 15 degrees

prisma shard
uncut lynx
prisma shard
thorn flicker
#

better for performance

uncut lynx
#

Ya

thorn flicker
#

lol

uncut lynx
#

Also i am planning on doin 1:1 port not some create-likey thingy so i dont really look at other "create" addons

thorn flicker
#

well actually it wont be that more performant

#

the block is ticking

uncut lynx
#

i changed it

prisma shard
thorn flicker
#

huh

distant tulip
thorn flicker
distant tulip
#

one way or the other

uncut lynx
#

alright im sendin u my code

#

then

uncut lynx
#

not 1000x ticking

thorn flicker
#

which is ticking

uncut lynx
#

look at my code rq

#

also half of that code is claude ai LMFAO

thorn flicker
#

okay

#

less impressive

uncut lynx
#

yeah

thorn flicker
#

im no longer interested

distant tulip
misty dagger
#

I was having the same issue, and I went to look for the relevant support thread since somebody was sure to have the same question.

uncut lynx
misty dagger
#

But nobody answered it. 😩

thorn flicker
prisma shard
#

bruh i am making this functions:
breakBlocksWithDropLoot()
breakBlocksWithoutDropLoot()
that name is too descriptive 😭 and seems AI how else do i name it, i am making a utils file, otherwise if i name it breakBlocks(), the users wouldnt get the difference, how do i name the both? lol

misty dagger
#

No, I went to look for someone else's existing post, and saw that it had no answers.

#

So now I am sad.

uncut lynx
#

i used ai since i am currently busy.

misty dagger
#

That post already exists, and it is asking functionally the same question. It would just be a duplicate.

prisma shard
thorn flicker
#

but hey, do what you want

uncut lynx
thorn flicker
#

yup, just did

uncut lynx
#

and i did too ^^

thorn flicker
#

free speech is awesome

#

🤝

uncut lynx
#

yes

warm mason
#

-# In anticipation of a question like "why doesn't this fictitious AI function work?"

thorn flicker
#

-# "guys, fix this code it aint working, btw I used chatGPT"

misty dagger
#

It is highly recommended that you don't use AI-generated answers for help chats, especially for something as niche as Bedrock add-on development. Most of the code that the LLMs ate up is outdated and probably doesn't even work. 😂

uncut lynx
#

facts though, i mainly used claude ai to refactor my code.

thorn flicker
#

or use your own intelligence

#

if you dont have time to be developing, dont

warm mason
thorn flicker
#

idk

prisma shard
#

yeah

thorn flicker
#

finna dont you use ai

distant tulip
buoyant canopy
#

can we cancel the gui opening interaction of a chest?

thorn flicker
buoyant canopy
#

good

thorn flicker
#

playerInteractWithBlock beforeEvent

warm mason
thorn flicker
warm mason
thorn flicker
#

what do you mean

warm mason
buoyant canopy
#

Thank you, i know this method, i was just wondering whether event.cancel = true will cancel the opening or not

misty dagger
#

Similar question: #1363633290426191942 message
It has no satisfactory answers, but it at least has activity.

thorn flicker
#

lol

buoyant canopy
#

I can't type

thorn flicker
#

just joking

prisma shard
# thorn flicker finna dont you use ai

Lets be honest
some people dont want to understand this
When developing with script api, People just ask AI , and he can give always wrong answers on that, since AI doesn't know about the documentation, even so, feeding the documentation is very hard. But the thing AI is too useful for is basic JS stuff, such as JavaScript logics that doesnt relate with the API, and also either useful if you tell AI to help with bigger things to help with automation that would take so much time such as, "Hey AI, can you please optimize and format the code, and make functions for some part of code, to make the code readable? and please dont add any new methods, just help to refactor the code"

thorn flicker
prisma shard
#

I was not talking about you either

uncut lynx
uncut lynx
#

See?

thorn flicker
thorn flicker
warm mason
prisma shard
uncut lynx
#

I don't use ai for api-specifics

thorn flicker
#

even there were advantages its still lame

#

use your brain, not a robots brain

misty dagger
prisma shard
#

hahah

misty dagger
#

Like right now, for instance.

thorn flicker
urban cairn
#

Are you guys talking about how AI isn't accurate and shouldn't be used to write all your code or something?

misty dagger
#

The onPlayerInteract custom component event seems to absorb all block events, and cancels ordinary events. It's has no filter options (e.g. filter by item used), and it has no cancel option. So applying it to simple blocks that otherwise have no special interaction functionality beyond the one thing I need it to do is really annoying.

#

In this case, making a custom log that you can strip with an axe.

thorn flicker
#

yes

misty dagger
#

(in case there is some officially-supported method for that and I am XY probleming here)

uncut lynx
thorn flicker
misty dagger
urban cairn
#

Ah fair enough.. I actually asked it about JSON UI once and it got everything correct except it wanted to add a file for passing through textures. For how little knowledge there is on JSON UI, I'm surprised it got it correct except for the one file. I also wont lie, I do rely on ChatGPT a lot but most of it is used purely for formatting my code or helping me move existing code into classes, functions and such..

uncut lynx
thorn flicker
#

sad times

urban cairn
#

I also kinda just use AI for being a solo developer too. I'm not even gonna lie about that. It helps for usre

#

I need to stop using it though, I'm not able to learn further since I use it so much

prisma shard
misty dagger
#

The most I can justify using AI for is as a glorified search engine. It's useful for connecting dots and getting some useful terms into my consciousness. But I refuse to use it for writing code as a matter of principle.

prisma shard
#

AI is too helpful when learning about JS.
i learned a lot about Obejct methods and Array methods, AI explained it easily

prisma shard
#

idk really if i did learn

thorn flicker
#

lmao

#

im not a tester

misty dagger
#

AI used to help cheat on exams moment.

#

Just shooting yourself in the foot.

#

You won, but at what cost?

urban cairn
#

I don't really tend to learn unless I'm writing the code which also kinda sucks. I managed to get a grasp on it for the Script API but if I tried typing out C# or python or whatever other language, I'm not going to be able to understand it so it's kind of a mess for how I learn. I don't have a sufficient way of learning

thorn flicker
#

like how is that good

#

at all

prisma shard
#

what does Object.entries() method do?
you need to feel JS code to understand, I really cant explain it how it works, BUT lets say it iterates though all value and keys

distant tulip
#

send a code you used ai on and let us question you

prisma shard
#

okay

#

bet

thorn flicker
#

yes, promote more ai usage

lyric kestrel
thorn flicker
#

pro ai minato

misty dagger
thorn flicker
#

cant believe this

misty dagger
#

Also use TS.

prisma shard
#

lets see my deepseek history

lyric kestrel
#

Oh boy, Deepseek

distant tulip
thorn flicker
prisma shard
#

LMFAO LMAO most of my chat history is just combining database scritpts

-# am i getting leaked

uncut lynx
#

Wft did i start...

thorn flicker
#

ill take the blame.

distant tulip
thorn flicker
lyric kestrel
distant tulip
#

i do use it when my brain is not braining

thorn flicker
#

omg

lyric kestrel
thorn flicker
#

pro-ai minato

#

must unfriend the machine now

distant tulip
#

it*

thorn flicker
#

my bad machine

lyric kestrel
#

I used to use AI a lot, but I've been trying to use it a lot less now. MistralAI was amazing at it. But it has gotten terrible now

thorn flicker
#

practice skills

lyric kestrel
#

fr

thorn flicker
#

its not about skill anymore, its just about result now

#

sadly

distant tulip
#

can't rally use it when my project is 200+ file

lyric kestrel
#

Well

short iron
#

AI it's pretty simple Ask it "what's the date of your last knowledge training" or similar. You'll find out most are about 6 months ago. So it does not know that things like .chatSend before after events don't exist in the current stable like 1.19.0

distant tulip
#

was not supposed to share that screenshot

thorn flicker
#

what was it

lyric kestrel
#

Mistral has a library system where you can add all your files for it to look through and help you with. I have like 30 scripting files in one library in case I'm stuck. And its knowledge is fully up-to-date with 2.0.0-beta

distant tulip
#

cant tell, lol
it is under NDA

i thought it is another workspace

lyric kestrel
#

woop

misty dagger
short iron
#

And you can get ones to query the current version (if has web access) the current versions, and convert the version to actual links to some like unpkg.com for the module and use current data. But that shit eats up tokens

thorn flicker
prisma shard
#

i could find anyhting to send else more, others are maybe privat

thorn flicker
distant tulip
uncut lynx
#

Now nothing is sure

#

Did he save it?

distant tulip
thorn flicker
#

im a lawyer, you see

prisma shard
#

damn

lyric kestrel
#

Impersonating a lawyer could get you into prison and a hefty fine ehappy

prisma shard
prisma shard
#

because now its a offtopic matter

#

XD

thorn flicker
#

not moving to offtopic to continue this joke further lol

remote oyster
#

Prime example of why one should humble themselves. If you know then you know, but when you don't, just say you don't, and either learn more of it, or move on.

#

It's not a competition 🫡

thorn flicker
#

I sensed some passive aggressiveness

distant tulip
#

i don't know how to use it, and i don't want to use it
but man they have some powerful shortcuts

misty dagger
sterile epoch
misty dagger
#

On the topic of VIM, it's super useful if you're SSH'ing into a Linux server backend that has no GUI to speak of. But as an editor, it is frankly painful to use. lol

sterile epoch
#

guys I'm a nerd 🤓☝️☝️

thorn flicker
#

nerds are cool

distant tulip
sterile epoch
#

vscode has shortcuts also

distant tulip
#

not as useful

misty dagger
sterile epoch
#

competitive nerdism

thorn flicker
dusky flicker
sterile epoch
dusky flicker
sterile epoch
#

n neither is vim

dusky flicker
sterile epoch
#

like 5 minutes?

#

I got pinged

wary edge
#

Why are we still talking about this? Move on.

sterile epoch
#

bcuz someone replied to me from a while ago spungbob_sadge

remote oyster
#

Move on

dusky flicker
remote oyster
#

Lol

sterile epoch
misty dagger
#

It would never be my regular IDE, for instance.

dusky flicker
#

actually i tried switching from vscode to nvim about 3 times

#

i got so confused that i simply thought about going back to vscode

remote oyster
#

Just move on. It ain't worth arguing over.

sterile epoch
#

bruh I'm muting this fkn chat stop pinging me holy

shy leaf
remote oyster
shy leaf
#

why do i always come back to this?

sterile epoch
lyric kestrel
dusky flicker
#

damn bro, tsc rewrite using go is so damn fast

#

seriously, it compiles everything in less than a second

lyric kestrel
#

Huh, they haven't updated it yet?

#

It's coming out in 7.00. isn't it?

valid ice
#

An argument? At this time of day, in this discord server, localized entirely within the script general chat?

lyric kestrel
valid ice
#

May I see it?

lyric kestrel
#

Script API General

#

Anyone know any good obfuscators?

valid ice
#

Best one is naturally shitty code Clueless

lyric kestrel
#

😂

#

True dat

remote oyster
dusky flicker
#

normally bundlers in js minify the code

distant tulip
uncut lynx
#

Wtf has happened here

woven loom
#

Can we use beta APIs in realms?

fallow minnow
woven loom
#

How?

fallow minnow
#

What do you mean

#

I believe you just enable the beta apis on the world and then apply the pack

woven loom
#

U sure about that

warm mason
woven loom
#

Hmm

distant tulip
woven loom
#

thx

#

any way to refresh code

distant tulip
#

don't think so

nova wraith
#

How can i summon an entity that already have a nametag?

#

I'm using a form with a list of mobs the player can spawn but I want one of then to spawn with a nametag applied to it

woven loom
#

create enity and change name tag

uncut lynx
#

@thorn flicker thanks, i realized thanks to you that i've been using ai lately way too much and not doing stuff myself.

uncut lynx
#

the api is still very limited tho

#

i think i'mma do it by myself from now on

valid ice
#

If you do both within the same tick, there's absolutely zero difference

#

spawnEntity() returns the Entity it spawned into the world, so you can do:
const entity = Dimension.spawnEntity(...):
entity.nameTag = ...;

#

@nova wraith

uncut lynx
#

For once again, how do i use TypeScript with "bridge. v2"

#

?

distant gulch
#

for entity.playAnimation, is the "controller" required? And is the list of players an Player ID or NameTag

dusty temple
#

Is there anyway I can get an item stack and supply a conditions argument that contains all of the properties of the class Container (In Typescript)

Player.prototype.hasItem = function (item: ItemStack, conditions: <Container properties>) {
  let hasItem = false;
  //Dunno what to do here
  return hasItem;
};

plr.hasItem(item, {amount: 64, nameTag: "dirt"})
// If player has 64 dirt return true, otherwise false
#

Might have to do some very complex typescript typing to get this desirable result 😨

distant tulip
wary edge
nova wraith
valid ice
#

don't use runCommand echsplode

nova wraith
#

That is how it is right now

nova wraith
#

I want to make it spawn with the nametag

valid ice
#
const entity = player.dimension.spawnEntity("goat:steve", player.location):
entity.nameTag = "something";
#

requires a location too

#

edited

distant tulip
#

Also, async runCommand is deprecated in v2, so avoid it

nova wraith
valid ice
#

Don't know nothing = do know something Clueless

nova wraith
#

Maybe

remote oyster
nova wraith
#

Im learning

nova wraith
#

I have another question, how can I detect when the player hit a custom entity with a custom item?

safe stream
#

Is there not a way to access specific slots from hotbar? I'm doing this but EquipmentSlot doesn't seem to have Hotbar or Inventory:

player.getComponent("minecraft:equippable")?.getEquipment(EquipmentSlot.Hotbar, 1)```
wintry bane
#

How do I get an entity's item when they're dead?

#

like the deadEntity

#

from entityDie

distant tulip
wintry bane
#

When I kill a zombie holding a sword, I want to use scripts to drop that sword.

nova wraith
distant tulip
#

Anything that uses beta version will have to migrate

nova wraith
distant tulip
#

Open a post

wintry bane
#

I'm getting undefined from both equippable and inventory

nova wraith
#
    "dependencies": [
        {
            "module_name": "@minecraft/server",
            "version": "1.11.0"
        },
        {
            "module_name": "@minecraft/server-ui",
            "version": "1.1.0"
        }
   ]

That's what I'm using

distant tulip
distant tulip
#

and 1.3.0 for the ui one

nova wraith
#

I will change it, if nothing breaks I will keep it

distant tulip
#

it will not

nova wraith
nova wraith
distant tulip
wintry bane
#

non-player

distant tulip
#

i don't think that possible

wintry bane
distant tulip
#

try getting the inv component from event.deadEntity and see

wintry bane
#

just undefined

distant tulip
#

welp, there is your answer

distant tulip
wintry bane
#

undefined

#

What if
let test = entity.dimension.runCommand(`testfor @s[hasitem=[{item=${i.typeId}, quantity=${amount}..}]]`); if(test.successCount == 1){}

dusty temple
# wary edge That sounds like a filter. And I believe in Beta Container has a findFirst itemS...

Managed to get it working

declare module '@minecraft/server' {
  interface Player {
    hasItem(conditions: {[K in keyof ItemStack]?: ItemStack[K]}): boolean;
  }
}

Player.prototype.hasItem = function (conditions) {
  let hasItem = false;
  for (let i = 0; i < this.inventory.size; i++) {
    const item = this.inventory.getItem(i);
    if (!item) continue;

    for (const key in conditions) {
      if (item[key] !== conditions[key]) continue;
      hasItem = true;
      break;
    }
  }

  return hasItem;
};

console.log(plr.hasItem({typeId: 'minecraft:shroomlight', amount: 64, nameTag: '§vLava Core'})) // True or False
#

Typescript is a hate and love relationship

wary edge
wary edge
echo tinsel
lyric kestrel
#

I really should learn TS

#

Anybody know any good videos for setting up TS properly in VSC?

dusky flicker
#

it hashes a string into a 32bit number

#

it can have collision, but well, it depends on what are your needs

simple zodiac
rose light
#
system.runInterval(() => {
    const random = Math.floor(Math.random() * 3) + 1;
    if (airdrop_config[random]) {
        const location = airdrop_config[random].location as Vector3;
        const overworld = world.getDimension("overworld");
        
        // Adiciona o ticking area para carregar o chunk
        overworld.runCommand(`tickingarea add circle ${location.x} ${location.y} ${location.z} 1 a`);
        
        // Aguarda alguns ticks para garantir que o chunk seja carregado
        system.runTimeout(() => {
            // Agora tenta spawnar a entidade
            overworld.spawnEntity("dz:airdrop", location);
            
            // Remove o ticking area após spawnar – pode ser ajustado conforme necessário
            system.runTimeout(() => {
                overworld.runCommand(`tickingarea remove_all`);
            }, 20);
        }, 10); // Ajuste esse valor se necessário (pode ser 10, 15 ou 20 ticks)
    }
}, 20);
#

I am creating an automatic airdrop spawn system, but I am encountering unloaded chunk errors. How can I resolve this? I have already added tick_world to the entity, but it doesn't allow spawning in unloaded areas.

simple zodiac
rose light
vast grove
#

One way is to calculate when the chunk is loaded. You spawn the airdrop as like an object in memory. You then iterate through all players and check if the player is within a certain range to an airdrop. You then calculate it's start position to the top most block and figure out how high you need to spawn it in order to represent a feeling of the airdrop actually being simulated.

#

No ticking chunks. Just a bit of smart logic and math.

dusky flicker
#

one question, if i'd do something like nosql inside minecraft(not just a class that calls world.setDynamicProperty), would you guys focus performance or memory usage? in case, would it be ok to get a little longer to read/write on it to save memory?

vast grove
#

It'll be more performance than memory. Memory isn't much of an issue unless you're writing literal GB's in which case yeah that might be a problem

valid ice
#

performance is always an issue when it comes to script API, so definitely prioritize that

dusky flicker
#

i think its better making a poll for it

inland merlin
#

did the transfer command get removed?

dusky flicker
inland merlin
#

not showing up in game so im confused

#

used to show up in solo

valid ice
#

wdym by not showing up

inland merlin
#

sorry im stupid

#

nvm

#

lmao

remote oyster
# dusky flicker one question, if i'd do something like nosql inside minecraft(not just a class t...

You can create a balance, but memory in the Minecraft scripting API has its limits, if you exceed them, Watchdog can shut down your world or server (although I haven't experienced this in a long while so I am personally curious if this limitation has been modified). I’d say memory is best used for caching or temporarily loading data blobs, but even then, the size and structure of that data can still be a concern.

Unfortunately, there’s no one size fits all solution in this environment. It really depends on the structure and purpose of your data. A database design that works well for one user may not be ideal for another. What matters most is whether the approach meets the specific needs of the use case. Even if a method seems unconventional, as long as its logic is sound and fits the requirement, it’s valid.

prime zenith
#

Why is subscribe and unsubscribe depreciated in playerJoin event

prime zenith
dusky flicker
fallow minnow
#

ur getting cursed by light mode

dusky flicker
#

i really think having to read about 4kb everytime i want to read data would be bad for performance

#

i cannot do some hackings such understanding the data such as a in memory file and use pointer arithmetic for accessing data faster

remote oyster
dusky flicker
#

so when requested something, it gets it oncr and keeps on ram, but all that is theory, im still thinking about how to make the 'byte array' to store it

dusky flicker
#

i like thinking about performance, so it will probably help me to learn about algorithms and problems i can face when dealing with performance in other scenarios

#

im primarly focusing on backend, but i think working with minecraft in an environment that isnt thst good, and trying to get the best of it can help me on the backend stuff

prime zenith
#

But subscribe being crossed out means depreciated

dusky flicker
remote oyster
# prime zenith

I don't have an answer for this issue other than to be sure you have the right NPM package? Also, it doesn't return a player object. Only the players string name and string id. You will need to use world.getEntity() to get the object using their id string.

prime zenith
#

Oh like inside the player.join?

echo tinsel
remote oyster
echo tinsel
#

Trying to make the hat names shorter, make the numbers whole only, and shorten the stat names without effecting the way they are displayed

remote oyster
echo tinsel
#

I can't even unlock a quarter of the hats without hitting the 32k limot

remote oyster
prime zenith
#

Wait does get all players not work for it

remote oyster
prime zenith
#

Im sorry my heads screaming why at mojang right now

prime zenith
remote oyster
#

Aside from checking if it's their first initial spawn.

echo tinsel
prime zenith
#

I dont need to worry about if its first it will run only if that property doesnt exist

dusky flicker
# dusky flicker yeah, alot of stuff to think

i think that, by now, imma do a basic implementation in rust, so i can understand better how databases work, doing so directly, with the lack of knowledge i have, it would be a total mess and i'd lose my time

prime zenith
#

i still cant get over why its depreciated what are they doing

prime zenith
#

It says it is also whys it not working

wary edge
prime zenith
#

So its temp crossed out ?

remote oyster
# echo tinsel I don't quite understand sorry. Can you laymens it? Lol

Check if the blob of data is exceeding the limitation for its size and if true, split the data into smaller chunks then store it. You will need to add logic to look for a key-value pair with chunks and join them back together of course. Or find some other means to handle the data, such as flattening the objects.

wary edge
prime zenith
#

Player.sendMessage is not sending player there message

#

Console warn below it works fine

remote oyster
prime zenith
#

Do i need to do a timeout console.warn got my name

remote oyster
#

You could try delaying it, yes.

#

Also check your chat messages. It's plausible it's working but because you aren't loaded on screen it doesn't show up but will be there when you open your chat window.

prime zenith
#

Its not in chat window

remote oyster
#

Then you are definitely not loading in fast enough.

prime zenith
#

I set timeout to 20

#

Still nothing

remote oyster
#

20 ticks is 1 second.

prime zenith
#

I know

remote oyster
#

1 second isn't that long.

prime zenith
#

My loading in only apears to take half a sexond ill try 10

#

Hmm well 10 secs worked i was waiting so ima try 5

echo tinsel
remote oyster
prime zenith
#

Console warn got it right away so internalized data wont need to rime out right

#

And idk any better way to fix it i wish player.sendMessage was save til there loaded grr

#

Is there a check for if they are loaded in

#

I could do a recursion function that tries until they are loaded in

#

If theres a check

remote oyster
#

Other option is to listen for their input and see if they move. Once they do, you know they are in and you can show the message.

prime zenith
#

Nope both were true

remote oyster
#

Only downside to that option is whether they are afk when they load in lol. So maybe consider a delay timer to fall back on? Lol

prime zenith
#

Its not really critical since i do get the players properties right away

remote oyster
#

I can't really think of anything else.

prime zenith
#

I may load them in with a custum bametag the purpose us so they can see there id number

#
    const namePart = player.name;
    const timePart = Date.now(); // e.g., 1717035512000
    const randomMs = Math.floor(Math.random() * 1000); // 0–999
    const randomNumber = Math.floor(Math.random() * 100000); // 0–99999

    return `id_${namePart}_${timePart}_${randomMs}_${randomNumber}`;
}

world.afterEvents.playerSpawn.subscribe((event) => {
    const { player } = event;
    if (!player.getDynamicProperty("id")) {
        let id = generateUniquePlayerId(player)
        player.setDynamicProperty("id", id)
    }
    console.warn(`welcome ${player.name} `)

    system.runTimeout(() => {

        player.sendMessage(`welcome ${player.name} `)
    }, 100)

});``` this should work right
#

i love the effectiveness but hate testing dynamic properties

remote oyster
prime zenith
#

For what im doing i do

#

That id is a key that i need for accessing the grand exchange it will be set to the world dynamic property as a key to your grand exchange

#

It has to be uncopyable unguessable and unfindable

#

By uncopyable i dont mean copy and paste i mean 2 ppl getting the same it has a use like a ssn basicually all world data is tied to it

vast grove
#

The player id is persistent enough though... And the player name can be changed quite easily either by offline profile or spoofing.

#

Also very hard to change without world editing I think

prime zenith
#

There are ways to get the built in id mine adds fluxuation to how my world works

halcyon phoenix
#

what does sampleManager do?

wary edge
halcyon phoenix
dusty temple
#

it would make more sense to deprecate the event itself, not the subscribe method

halcyon phoenix
wary edge
prime zenith
#

Idk im guessing just while they make changes it says depreciated

halcyon phoenix
#

also is this the only UI t he forms only capable? they cannot arrange where it is or change the texture?

halcyon phoenix
#

and then they do this

import SampleManager from "./SampleManager";
import { scriptBox } from "./ScriptBox";

const sm = new SampleManager();

sm.registerSamples({
  scriptBox: [scriptBox],
});
dusty temple
wary edge
halcyon phoenix
#

ohh I see

halcyon phoenix
dusty temple
#

Or you can Ctrl + Click Sample Manager to see the code behind it

#

assuming ur in vscode

silver agate
#

I made this script that was supposed to change block states after interacting with certain items. For some idk, it isnt working. Content log says there is an error on line 53, but i wonder what

dusty temple
#

Use system.beforeEvents.startup

silver agate
#

Im on 1.14.0

wary edge
silver agate
#

Also, it seems to not be a problem, as i got another codes with this that work perfectly

dusty temple
#

Latest "@minecraft/server" version and minecraft version

echo tinsel
#

What is the best way for me to set up block interaction with armor items. Since use on doesn't seem to work for armor since it equips it

wary edge
signal ledge
#

my first time making a custom component can anybody explain why this isn't running 😔

`import { world } from "@minecraft/server";

const ItemIceComponent = {
onHitEntity(event) {
const hitEntity = event.hitEntity;
const attacker = event.attackingEntity;

if (hitEntity && attacker?.runCommand) {

    hitEntity.runCommand('effect @s slowness 1 3 true');
    hitEntity.runCommand('playsound random.glass @a[r=12]')
}
},

};

world.beforeEvents.worldInitialize.subscribe(({ itemComponentRegistry }) => {
itemComponentRegistry.registerCustomComponent("swordssorcery:ice", ItemIceComponent);
});`

dusty temple
dusky flicker
#

or at least something being implemented

prime zenith
#

Rewriting a 600 line file is going to drive me nuts

remote oyster
#

😁

shy leaf
#

only 600 lines

prime zenith
#

I tried suicide but it wasnt hardcore so i only lost my stuff guess i need to write this

#

My grand exchange hurts my brain

nova wraith
#

Is there a way to change the player knockback resistance while in the world?

#

Since yesterday I was able to make the player change from 0 to 2 using events, but today I was editing some scripts and suddenly the knockback event isn't working anymore

#

And none of the scripts had something related to knockback

#

I just don't understand why it stopped working

fallow minnow
#

@valid ice help

#

when i try to use the scoreboard database in custom commands it errors

#

or any functions i call in it

valid ice
#

DMs

cinder shadow
#

how does the source get passed into custom commands? I don't see it present in the object parameters. I can see that I can import CustomCommandSource from server, but the only info I'm really getting from the command is the sourceType

vast grove
#

Be it block or entity?

leaden glade
#

is playerJoin triggered before playerSpawn?

cinder shadow
#

ahh nvm

#

It's there.. the stringify output just doesn't say it for whatever reason

round bone
round bone
#

if you want to achieve a player, use:

#
import { CustomCommandOrigin, CustomCommandResult, Entity, Player } from "@minecraft/server";

const sampleCommandHandle = (origin: CustomCommandOrigin): CustomCommandResult => {
    const player: Entity | undefined = origin.sourceEntity
    if (!(player instanceof Player)) {
        return {
            status: CustomCommandStatus.Failure,
        }
    }
    // player variable has `Player` type here.

    return {
        status: CustomCommandStatus.Succes,
    }
}
cinder shadow
round bone
#

ohh an argument

#

you're using EntityType as an argument?

dusky flicker
uncut lynx
#

hey btw is it possible to (without manually storing it via onPlace), check the number of ticks that've passed after the block'd been placed?

#

Also why is this chat dead

halcyon phoenix
uncut lynx
halcyon phoenix
uncut lynx
halcyon phoenix
#

can't you just currentTick - placeTick?

uncut lynx
#

i can but i wonder if i can omit using placeTick at all

halcyon phoenix
halcyon phoenix
halcyon phoenix
#

yeah

#

welp I guess minato or neko might know somthin

acoustic basin
#

hey guys, so i'm trying to figure out the custom components v2.0, i'm making progress, made some components for the block, but now i'm trying to make an array component with objects, so when item was consumed, player would get each effect, but i'm getting error that native conversion failed for first argument of addEffect. what am i doing wrong, and how do i access the parameters of this custom component?

"v360:food_effects": [
                {
                    "effect": "absorption",
                    "duration": 120,
                    "amplifier": 0,
                    "particles": true
                },
                {
                    "effect": "regeneration",
                    "duration": 5,
                    "amplifier": 2,
                    "particles": true
                },
                {
                    "effect": "night_vision",
                    "duration": 120,
                    "amplifier": 0,
                    "particles": true
                }
            ]```

```js
onConsume({ source }, { params }) {
        source.addEffect(params.effect, params.duration, { amplifier: params.amplifier, showParticles: params.particles });
    }```
#

i'm sure that the way i'm trying to get parameters right now is wrong, but i don't know how to do it correctly in this case

halcyon phoenix
#

that's an array I believe to access it you gotta params[0].effect that would be absorption and params[1].effect would be regeneration.

halcyon phoenix
prisma shard
#

🗿

uncut lynx
#

Also i think we should stop using the ai altogether

#

those 2000 lines of code from ai are my 600

vast grove
#

I don't think you should ever exceed past 1k lines unless there's a very good reason like source generation...

halcyon phoenix
halcyon phoenix
#

how did you do it before?

prisma shard
#

its just upto yourself whether to use it or not

uncut lynx
#

i mean that ai's 2000 line code fits within my 600 lines

prisma shard
#

Okay

prisma shard
uncut lynx
#

alright i didnt mean it in such way

halcyon phoenix
#

I was baffled

thorn flicker
#

lets never use ai

prisma shard
# thorn flicker lets never use ai

......what? AI is not for replacing us...... i dont think you get it., AI is for helping with hard work, It can help us really, Why not use it?

nova wraith
# halcyon phoenix how did you do it before?

2 component_groups, one with 0 resistance and other with 2, I used events to change the component_groups, but for some reason it stopped working, the player can't receive knockback even if I manually run the events with command

uncut lynx
#

Btw bridge auto compiles ts into js ^^

thorn flicker
prisma shard
#

mh Okay

vast grove
#

AI can help if you use it correctly. Most of the time it's BS

uncut lynx
#

AI at most is really helpful for explaining something (but not doing it itself !!!!)

thorn flicker
#

my point is not about it being helpful or not

prisma shard
#

i just might be bad at english xd i see

uncut lynx
#

also ts is SOOOO good

thorn flicker
#

so ive heard.

vast grove
#

Type safety.

#

not like strongly typed languages also exist

uncut lynx
#

(ts compared to js)

#

i mainly code in C++

vast grove
#

C# is my main

halcyon phoenix
remote oyster
#

AI is just another tool and like any other tool it has its pros and cons. It can also be used improperly just like any other tool.

round bone
#

it's better sometimes to search smth by yourself

remote oyster
#

Been doing benchmarks with different packages and so far JSON.stringify() and JSON.parse() have had the fastest read/write cycles when handling data structures. So I'm just gonna stick to using that and not worry about anything else right now. Thought I would share my experience.

-# An explicitly custom serializer and de-serializer would clearly have much faster results but not recommended for open source projects projecting to share resources with strict limitations.

halcyon phoenix
uncut lynx
round bone
uncut lynx
round bone
#

they're not readonly

uncut lynx
round bone
uncut lynx
#

Slower duh

round bone
#

??

#

not that slow

uncut lynx
#

... if you can have full-ass class, then why bother with some singular-value properties?

remote oyster
uncut lynx
#

Yeah u can deserialize & serialize

remote oyster
#

Huh

round bone
#

static properties are better for your case

uncut lynx
remote oyster
#

I don't even know what this conversation is about anymore.

round bone
#

I don't think that he is familiar with OOP xd

uncut lynx
#

I use (censored) classes duh

#

I'll send u my code the second i finish it

round bone
#

it does not mean that you know OOP that much

uncut lynx
#

I know oop bruh i've made in C++ countless 2000+ line classes

remote oyster
#

I just made a comment regarding my experience with benchmarking data and this took a different turn haha.

round bone
#

then why you want to create a single instance of a class?

#

just use static atp

uncut lynx
#

Because it is nicer ?

round bone
#

???

uncut lynx
#

I don't make global namespace full of trash that way

round bone
#

it's slower

uncut lynx
#

a tiny bit

round bone
#

still slower

uncut lynx
#

correct

round bone
#

and more memory usage

uncut lynx
#

In minecraft stuff happens every 1 tick (1/20 second)

#

idc bout losing microseconds

round bone
#

still a bad practise

uncut lynx
#

True, i'd love to have

namespace shit {};```
in js
round bone
#

?????

uncut lynx
#

Also if there exists such then please tell me

dawn zealot
#

[Scripting][error]-Unhandled promise rejection: TypeError: cannot read property 'addEnchantment' of undefined at buyPickaxe (ui/pickaxe_shop.js:79)
at <anonymous> (ui/pickaxe_shop.js:145)

const item = new ItemStack(itemId, 1);

// Add enchantments to the item
if (enchants.length > 0) {
    const enchantsComp = item.getComponent("minecraft:enchantments");
    for (const enchant of enchants) {
        enchantsComp.addEnchantment({ type: enchant.type, level: enchant.level });
    }
}

anyone know why my enchants arent adding to the item?

round bone
#

why would you have to use a namespace

uncut lynx
uncut lynx
#

but i'd prefer to

dawn zealot
round bone
#

it's in .d.ts files

round bone
dawn zealot
#

that dont work

uncut lynx
#

IMO

shy leaf
#

not enchantments

dawn zealot
#

o

shy leaf
#

also iirc if the item is not enchanted, it can return undefined? im not too sure

round bone
#

oh yeah

shy leaf
#

o

#

well, a failsafe should be alright to add here

round bone
#

just getEnchantments method is returning an empty array

dawn zealot
#

[Scripting][error]-Unhandled promise rejection: TypeError: Native type conversion failed. Interface property ['type'] expected type: EnchantmentType (failed parsing interface to Function argument [0]) at buyPickaxe (ui/pickaxe_shop.js:79)
at <anonymous> (ui/pickaxe_shop.js:145)

now im getting this error

shy leaf
#

uh

round bone
#

what's enchants in your code?

shy leaf
#

yeah was about to ask that

dawn zealot
round bone
#

ahh

#

new EnchantmentType(type)

dawn zealot
#

huh

round bone
#
new EnchantmentType("minecraft:unbreaking")
#

this should be your type field

dawn zealot
#

alr

round bone
dawn zealot
#

so like this then

round bone
#

🤷

uncut lynx
#

Does perhaps the api allow levels to exceed normal limits? That'd be cool.

round bone
uncut lynx
#

But look at the chat history

round bone
#

level component

#

check bedrock samples

uncut lynx
#

Ik how to do it manually

round bone
dawn zealot
#

apparently EnchantmentType doesnt have required privileges

uncut lynx
#
system.run(() => { shitHere() });```
dawn zealot
#

gotcha

round bone
#

use worldLoad and loaders

dawn zealot
#

idk what that is

uncut lynx
wary edge
round bone
uncut lynx
#

Why?

wary edge
round bone
#

Marketplace has to serve stable products

#

Beta is changing almost every update

uncut lynx
#

But if i'd want to ship cutting edge thing, then i kinda have to

#

?

shy leaf
#

but

#

theres also a downside where

dawn zealot
#

works 👍

shy leaf
#

you have to look through the whole code for at least once if theres a breaking change

#

every update

#

most of the times its just as simple as changing version in manifest.json

dawn zealot
shy leaf
#

nothing would feel worse than that

dawn zealot
#

ive spent more time updating my code than making it

wary edge
uncut lynx
wary edge
#

There is no cutting edge in Marketplace.

shy leaf
#

im just telling you the reason why ppl dont use it

#

(and they also explained why marketplace doesnt use it)

uncut lynx
#

Ohh okay

#

But i wonder, if i wanted to not only host it on some online website, but on marketplace, then do i have to lose features?

#

Or can i technically put there unstable-api-d mod

shy leaf
#

marketplace doesnt allow any experimental features

uncut lynx
shy leaf
#

mhm

prisma shard
#

hai guys i made this

#

debug screen

dawn zealot
#

also is it a bug that theres like a 10% chance my game crashes when i do /relaod or /reload all

uncut lynx
#

Yeah sometimes happens to me too

#

This is the thing with beta

woven loom
#

it should be fixed

wheat condor
dawn zealot
#

past 2 times ive done /reload all my game crashes

uncut lynx
dawn zealot
#

yeah im using 2.0.0

#

-beta

ancient sierra
#

Hello! Is it possible to spawn an enchanted book with any random enchantments?
Thanks!

uncut lynx
#

for spawning items, you'd have to use structure blocks

#

then i guess make each per enchantment

#

but that is a lot of work

ancient sierra
#

O, does <Dimension>.spawnItem not do that? Or have I interpreted it wrong

warm mason
warm mason
uncut lynx
#

idk much bout the api so i am not an expert

ancient sierra
uncut lynx
#

anyways the goal is to have enchantment(s) on it

uncut lynx
#

or maybe spawn some random madeup entity, do /enchant on it's item and kill it

ancient sierra
#

I see, I would like to use APIs in this case so I'll try a different approach

Thank you though!
I'll also see if I can make a way for it

uncut lynx
uncut lynx
#

But serty prolly knows better method

warm mason
#
import { ItemStack, EnchantmentTypes } from "@minecraft/server"
/**
 * @param {import("@minecraft/server").Dimension} dimension
 * @param {import("@minecraft/server").Vector3} location
 * @param {String} itemId
 * @param {Number} enchantmentsAmount
 */
function spawnItemWithRandomEnchantments(dimension, location, itemId, enchantmentsAmount = 10) {
  const item = new ItemStack(itemId, 1);
  const enchantable = item.getComponent('enchantable');
  if (enchantable == undefined) return false;

  let types = EnchantmentTypes.getAll()
  types.sort(() => Math.random() - Math.random())
  for (let type of types) {
    if (enchantmentsAmount <= 0) break;
    if (!enchantable.canAddEnchantment({ level: type.maxLevel, type: type })) continue;
    
    enchantable.addEnchantment({ type: type, level: Math.floor(Math.random() * type.maxLevel) + 1 });
    enchantmentsAmount--
  }

  dimension.spawnItem(item, location);
  return true
}

@ancient sierra

uncut lynx
#

i knew it

#

serty be helpful guy

ancient sierra
#

Awesome! Thank you so much!

uncut lynx
#

is there any way to enchant above normal limits via script? (i know how to do it via nbt editor.)

uncut lynx
#

So i guess my method of structure blocks is the only real way for that lol

scarlet lynx
#

Hey!

#

I try deleting a dynamic property by setting it to null and it still exists?

wary edge
#

Set it to undefined

scarlet lynx
#

Instead of null>

nova wraith
#

And my character have 100hp (on the json file I had the hp set to 100)

#

Apparently the player informations are stored in the world files

cyan basin
nova wraith
#

If I use components to change hp then it will remain like that

cyan basin
#

Just setting to null will give it that value

nova wraith
#

But what I can't understand is why it was working and now it's not working

scarlet lynx
sly valve
#

Just added AoE, and AoE + Poison abilities.
Got anyone more ideas for cool abilities?

wheat condor
uncut lynx