#Script API General

1 messages · Page 3 of 1

vocal elbow
#

thanks

distant gulch
amber granite
#
Let object=
{ PI : 3.14 , PI2 : 6.28 }
Let str = JSON.strigify(v)
#

And when u parse it u will get the values that was in the object with their types saved

distant gulch
#

Okay but what when i didnt saved an object

amber granite
#

Won't work

#

Because parse and stringify works specially for objects

distant gulch
#
world.setDynamicProperty(`${databaseId}:${key}`, STRINGIFIED_VALUE);
#

like when i saved a value

#

in dynamicProperties

#

And then my database gets the value to add it to the cache

#

it would work to parse the value

amber granite
#

Nah bro

#

U understood my idea wrongly

distant gulch
#

Okay

amber granite
#

Listen to me

#

1 - first , work on object and put the values on it
2 - strigify that object and
3 - declare new variable as examples : myData
4 - add the strigified object to him

distant gulch
#

so every value i save needs to be an object

amber granite
#

Nooo

#

I ll write and example and send it for u

distant gulch
#

okay..

distant tulip
#

not true

amber granite
#

If u wnat to stringfy something use toString is better

solar dagger
#

How do you clear a slot? Would it be like typescript ...setItem(i, null)?

distant tulip
#

null or undefined
the docs suggest undefined

solar dagger
#

Alr I'll use undefined then

cinder shadow
#

does UIManager.closeAllForms not work?

#

I have UIManager imported from server ui

distant tulip
cinder shadow
distant tulip
#

yeah

cinder shadow
#

should work then

woven loom
#

hm

distant tulip
cinder shadow
#

not a function

distant tulip
#

hm

#

preview?

cinder shadow
#

yes

distant tulip
#

UIManager.closeAllForms(player)
should work

#

this is a wired syntax
they should just make it a player function

near siren
#

How do you check if a variable is a Vector3 or not?

shy leaf
#

i dont think theres a dedicated way for this

amber granite
#

@near siren

shy leaf
#

o

near siren
amber granite
#

Wait a min

#

Did u import the Vector3 Library ?

#

From Minecraft math

near siren
#

Oh from minecraft math?

amber granite
#

Yeah

#

U can also u

#

External module

#

Use external module

#

To not change the manifest

cold grove
amber granite
#

Yesh i think import it from Minecraft math

#

It s better to be compatible with ur code

cold grove
#

You dont really need the vector class if you dont use math operations

near siren
#

I'm trying to see if a variable is a vector3 or a number so I can add them accordingly

amber granite
#

U can use a function

#

And see if this variable has x and y and z propreties

#

If not it will return false

near siren
amber granite
#

Bridge,

#

I don't use bridge

#

I use vsCode

near siren
amber granite
#

Ok import it ur js file

#

import { Vector3 } from 'minec..math idk"

#

Then use instance of

frozen vine
#

How do I increase the block state by 1 point with script?

warm drum
#

when does a block tick?

#

like every tick or when it gets updated

valid ice
warm drum
valid ice
#

not afaik

warm drum
#

why do the onPlace keep getting called with the playerinteract?


initEvent.blockTypeRegistry.registerCustomComponent('wiki:something', {
        onPlayerInteract: (e) => {
                console.warn('Block interact')
        },
        onPlace: (e) => {
                console.warn('Block place')
        }
    });
random flint
shy leaf
#

how do i make a code to repeat for specified ticks

valid ice
#

runInterval?

shy leaf
#

wait thats it?

#

i mean

#

you can specify ticks for runInterval?

tight plume
shy leaf
#

o

warm drum
#

Then, the placeOn event is called too

#

I kinda guess what happening, the onPlayerInteract setPermutation, then it triggers the onPlace

random flint
warm drum
#

i figured it out

#

btw

#

is there a way to change a specific state without changing other block state?

random flint
shy leaf
#

how do i make spawnEntity to not trigger if the entity already exists?

#

tried filtering out by using tags or dynamic properties but it either doesnt work or the first entity wont spawn

amber granite
#

?

#

Elaborate

shy leaf
#

so i have a dummy entity that spawns and teleports to mobs in range when an event triggers

#

the dummy entities teleports via runInterval (and clearRun when the entity dies or disappears)

#

but i cant get the dummy entity to "not spawn when theres already an existing dummy entity on the mobs in range"

#

ill get you a vid

amber granite
#

U know

#

GetEntities array

shy leaf
#

yep

amber granite
#

Use it

#

Use the length proprety

shy leaf
#

i actually never used length property before

#

can you get me an example?

amber granite
#

getEntities({maxDistance : 40, type : "dummy"})

#

Then the length proprety

#

getEntities..length === 1 ?

#

And so on

shy leaf
#

what on the god's green earth is that

amber granite
#

Just put ur max distance

#

And the entity type

shy leaf
#

oh you mean

#

oh yeah no i cant do that

amber granite
#

And then check the length proprety

#

Because getEntities

#

Give u an array

#

Of those entities

shy leaf
#

ill get you a video hold on

#

you can see that the health bar doesnt update but overlaps instead
the health bar disappears when the mob dies

amber granite
#

I don't get it

shy leaf
#

yeah its a bit vague hold on

#

i shouldve tested with armor stand

shy leaf
#

when the event fires, the dummy entity spawns and teleports to affected mobs, updating the mob's health using nametag
but as you can see, the dummy entity spawns even if there's already an entity

amber granite
#

Yeah

#

Why is there Chinese?

shy leaf
#

thats korean

amber granite
#

U mean Chinese

shy leaf
#

🗿 thats korean and im korean

amber granite
#

That explains it

#

North Korean ?

shy leaf
#

🗿🗿

#

no and im glad im not from north

amber granite
#

Oh

#

I ll try something

shy leaf
#
const healthbar = system.runInterval(() => {
// spawnEntity(id).teleport(vector3) goes here...
if (entityded...) {
healthbar.remove()
system.clearRun(healthbar)
}```
#

writing code in discord is painful

#

so yeah thats how the spawnEntity code runs rn

amber granite
#

Hmmm

#

Am little busy

#

Right now

shy leaf
#

take your time

amber granite
#

But i ll try to fix it

#

Because i m working on something too

shy leaf
#

alright

amber granite
#

If u are not need it rn

shy leaf
#

yes its not really urgent, take your time

amber granite
#

Yes

shy leaf
#

ive thought of a workaround:
instead of making entities to summon upon hit by player, make all the entities in range to have a dummy entity without nametag, and then make a new entityHurt event that sets the nametag as health bar

#

it can be performace heavy because it spawns entities to all the mobs in range

#

but i can filter that out with health component

random flint
#

just cache the entity nameTag

#

if (!entity.nameEntity)
entity.nameEntity = dimension.spawnEntity() //No duplicate

shy leaf
#

which is something i cant do anything with

#

thats why im using a dummy entity with custom nameable component for this

#

couldve been more simple if you could make an entity to ride without rideable component
but we cant have nice things isaac_dead

random flint
#

I would suggest still limiting it to a few entities per player.

shy leaf
#

for performance?

random flint
#

And visibility.

shy leaf
#

true

thorn spindle
#

Hey what's the difference between running a command with async and without?

random flint
#

Async return Promise and have a limit per tick

abstract cave
#

is script BP manifest necessary to make custom components or can you do it without

hardy tusk
#

Very likely yes

#

99%

shy leaf
thorn spindle
fading sand
#

How do i check if an entity is invincible and canot take damage from projectiles?

shy leaf
#

if the entity is made invincible via entity json, you can check for the property, i think?

fading sand
#

I mean i need to check for it in script

amber granite
vast grove
#

Promises Something after you request it.

amber granite
#

Nah promises

#

Are just a cllabacks

#

Something like them to handle errors too

#

Like try and catch with asynchronous

vast grove
#

I meant in a literal sense

amber granite
#

Yeah but

#

They are just a handlers

#

Same

vast grove
#

Dawg, english/literal sense. I wasn't commenting on a technological standpoint

amber granite
#

Oh

#

Yeah

#

Because that it called promise

#

Because it s like a contract between u and the language, to get something whatever it takes of time

#

But u will take it finally

#

Wo , u xab playAnimaton ?

thorn spindle
#

will the player.runCommand check if the player is OP or run pretty much every commands?

vast grove
#

It won't check

amber granite
#

Use isOp()

vast grove
#

That's still sortof broken

amber granite
#

Nah

#

Not actually

prisma shard
#

people who born there has 100% of bad luck 💀

prisma shard
tiny fable
#

hello!
How can I open a inventory ui from script?

thorn spindle
#

Any way to detect left click? without animations controllers

amber granite
#

?

fading sand
amber granite
#

Oh

#

Yeah

#

U can use testfor command

#

And turn it into a function

#

And use it to know whether that entity is creative or not

fading sand
thorn spindle
#

Punch

hazy nebula
#
    let container = player.getComponent("minecraft:inventory");
    let item = container.getItem(player.selectedSlot);
    
    const lore = new ModalFormData()
      .title('§a• §fLore §a•')
      .textField('lore', 'Lore (Use (line) to break the line)');
    
    lore.show(player).then(res => {
      if (res.canceled) {
        return;
      }
      let loreText = res.formValues[0];
      if (!loreText) {
        player.sendMessage(`§a•≫ §4Please enter the lore content`);
      } else {
        let loreArray = loreText.split("(line)").map(line => line.trim());
        item.setLore(loreArray);
      }
    });
  }```
#

What wrong with it?

sharp elbow
#

What is it doing (or not doing)?

amber granite
#

@thorn spindle ?

thorn spindle
#

Yep

thorn spindle
amber granite
#

Yes

#

U can

#

There are events for that

ionic kayak
#

Using getBlockFromViewDirection can you also detect air blocks?

amber granite
#

No

woven loom
#

why would you detect that? it makes no sense

turbid oriole
#

I can't find a good Open Source repository to gain experience. Does anyone have anything I can work on? Github.

untold magnet
#

sup, how can i make entities move using scripts? setRotation(?)?

#

any answer?

neat hound
untold magnet
fading sand
#

Anyone got an idea how to check if an entity can take damage from an certain projectile? (Needs to be a way i can check instantly)

untold magnet
shy leaf
#

impulse is the same thing as knockback

neat hound
shy leaf
#

its just that knockback is for both players and entities

#

and impulse is for entities

neat hound
#

doesn't knockback push vertically

shy leaf
#

i think you can set that

distant tulip
#

yeah

neat hound
untold magnet
untold magnet
#

wait i got an idea

#

i better make that move entities & items using applyImpulse, and make another one but for the player

vast grove
untold magnet
#

i mean using both of them,
applyImpulse for items & entities
applyKnockback for the player

#

hmmm, i actually should make it not moving the player, so it will not be annoying

fading sand
wary edge
#

That doesn't seem possible as we don't have access to damage sensors

fading sand
#

And theres no other way arround? Like somehow make it take damage or define something that will become undefined when the entity cant take damage

distant gulch
#

anyone have an updated manifest I can use

wary edge
valid scaffold
#

Can you load a structure from the top down with scripts?

glacial widget
valid scaffold
# glacial widget yeah structure manager

Right, that's what I'm using, and I'm using the StructureAnimationMode to do layer by layer. But it always loads the structure from the bottom to the top. Is there a way to reverse this? There's no options to do so in the StructureManager.
#1207733595746340876 message

glacial widget
fair quarry
#

How do I detect players in a radius of 10 blocks and add a tag to them?

#

I just need to know how do I detect the player

shy leaf
subtle cove
#
player.dimension.getPlayers({ location: player.location, maxDistance: 10, excludeNames: [player.name]})
random flint
#

where is that container slot question

#

where did it go

tiny fable
random flint
#

You can't force UI to pop on the player's client.

This includes containers, furnaces, and crafting.

Except ServerForms. With its mechanic and appearance.

tiny fable
#

Well its a unfortunate truth that I'll have to accept. Thanks!

tiny tartan
#

how to fix this ^

#

as you can see that on right click with axe on plank it spawns stick but it does not load in inventory unless i do right click on stick

hazy nebula
#

anyone have setLore addon?

elder heath
#

a query, how do I give myself a book with an enchantment with js?

woven loom
#

see doc

shy leaf
turbid oriole
#

Is there an add-on for Smash Bros type attacks?

distant gulch
#

Maybe on mcpedl

hazy nebula
#

Invalid Argument Error: Unexepted typed passed to function argument [0]. Expected type: number how to fix this error

sharp elbow
#

@hazy nebula What function? In what context? You need to describe much more for us to be able to answer that. The problem is what it says: You failed to pass a number—but we cannot know why

dense skiff
sharp elbow
#

The simpler filters may have a scripting equivalent (e.g. has_tag, in_overworld, is_sneaking), but for those that do not I'm afraid you would need to modify the entity's definition.

dense skiff
#

yeah I don't think surface_mob has a script equivalent

sharp elbow
#

Although I am curious about what the game calls a "surface mob." If only the description was not so nebulous

dense skiff
#

i would like to use this on literally every mob lol it would bloat so much

#

i'm assuming a surface mob is a mob that spawns as a part of the surface cap instead of the cave cap

#

true for surface cap, false for cave cap

sharp elbow
#

If it is something like "test if the mob exists on the surface of the dimension," a la "around the sea level", that could be emulated by testing for a variety of things like sky exposure, height, biome, and so on

dense skiff
#

that's another reason i think its a test for whether the mob is part of the surface or cave cap-- because other things it could be can be done other ways

#

whether it's a part of the surface or cave cap is essentially a property it has-- it doesnt change caps after spawning no matter where it goes

sharp elbow
#

Perhaps that is something you could assign upon the entity's spawning, to be looked up on at any time thereafter

dense skiff
#

I looked into it

#

there are so many edge cases it would be very hard to maintain

#

it looks like either way of going about this would cause a host of issues when the game updates

warm drum
#

so people dont need to reinvent the wheel

amber granite
#

The third way ?

amber granite
#

...

tight plume
#

(edited)
-# (edited)

random flint
#

ur -# looks like "-#" for me

honest spear
#

hmm wait, update your discord first

prisma shard
#

how

#

editing three times? hmm

#

(edited)

(edited)

(edited)
-# (edited)

#

lmaooo 🤣

#

editing five times

honest spear
astral night
#

How do I make a custom cave vines with script?

amber granite
#

####### (edited)

amber granite
wary edge
#

@hazy nebula no crossposting

distant tulip
#

this cross posting rule is kinda bad
sending "can some one help me here Link"
shouldn't count as cross posting. the only think shouldn't be allowed is posting the same question in different channels

wary edge
#

But also phising for help is hella annoying and shows youre impatient

distant tulip
#

lol
nvm then

wary edge
#

If youre truly irritated by such rules we have #1051300915161858120 for a reason

distant tulip
#

i can see how that will be annoying
you guys are active here more than me
so it is up to you

hazy nebula
warm drum
#

how can we detect player break block then its position?

prisma shard
warm drum
#

all i can find is permutation

prisma shard
# warm drum yeah
import { system, world } from "@minecraft/server";
    world.beforeEvents.playerBreakBlock.subscribe((event) => {
        const {block,player} = event;
        const location = block.location
        if (block.typeId == "minecraft:diamond_block") {
           system.run(() => {
 player.runCommandAsync(`say ${location.x} ${location.y} ${location.z}`);
});
        }
    });```
wary edge
#

I would not recommend using the beforeevent

warm drum
#

player break block before event doesnt have block properties?

warm drum
#

im kinda sick with the microsoft doc

#

sometimes it said a feature is stable, but its not

#

now this....

obsidian coyote
#

What feature?

warm drum
#

nvm

#

it does say extend to block

dense sun
#

are there any alternatives other than runInterval

prisma shard
dense sun
#

because it uses ticks

#

and i want to run in between ticks

#

like 1.5

#

0.5

#

0.6

warm drum
#

isnt it minecraft use tick as the fundemental time scale?

prisma shard
#

}, <tick>)

#

put the tick at the last line there

#

it will run each specefied ticks

#

is this what you wanted?

granite badger
#

hate to break this but they don't support float as a param, they'll just round the number up

dense sun
#

ah so that works?

#

oh damn

#

ye

#

it dosent use float as a param

finite tree
#

How can I add functions in hud elements ??

prisma shard
#

I just copy pasted that from a file

#

i'd use afterEvents if i was on pc

#

whatever lol i just talk too much

warm drum
#

If the item in entity state, they can group together, how can I remove just one item?

crisp surge
#

does anyone know why just recently ive been receiving delay opening mc settings or editing a world/realm?

untold magnet
#

guys, applyKnockback doesn't really work like applyImpulse

#

also i think the teleport thing will make the screen cannot be moved and kinda glitched

#

so is there anything i can use to move the player?

cinder shadow
#

you have to use applyKnockback

prisma shard
prisma shard
untold magnet
amber granite
amber granite
#

.

hasty spindle
#

hi everyone,
i have a question, Is it possible that the result of a TextField of a menu can be written to another file to keep the data ?

distant tulip
hasty spindle
distant tulip
#

and vectors3

distant tulip
amber granite
#

@distant tulip

#

Try to simulate a block like a vault with it

distant tulip
amber granite
#

Works ?

distant tulip
#

working on a building thing

amber granite
#

Only?

distant tulip
amber granite
#

I thought u said building blocks

amber granite
#

S

#

With it

distant tulip
distant tulip
hasty spindle
amber granite
distant tulip
amber granite
#

U can change textures ?

#

Of a block

hasty spindle
#

name is a const item

distant tulip
distant tulip
hasty spindle
amber granite
distant tulip
# hasty spindle so how ?

player.setDynamicProperty(key, value)
key need to be a string
and the value one of the ones i said above
using
name && block.location.x && block.location.y && block.location.z
will just store a boolean and i don't think that what you want
convert the corrds to a string

distant tulip
hasty spindle
distant tulip
hasty spindle
hasty spindle
#

so that can work ?

distant tulip
#

yeah

hasty spindle
#

ok ty

distant tulip
#

but don't use name as key

#

use something that you know
so you can get the dp later

#

player.getDynamicProperty(key)

valid ice
valid ice
#

I would standardize the key across all players, though- no reason to have it different if you're storing standard data.

glacial widget
hasty spindle
woven loom
#

Anyone tried Acode with typings ?

hasty spindle
woven loom
hasty spindle
warm drum
#

Hey, is client side camera a thing?

unique dragon
#

i think this one

hasty spindle
woven loom
hasty spindle
halcyon phoenix
#

how do you change the entity facing?

hasty spindle
valid ice
#

.filter

hasty spindle
halcyon phoenix
#

where is the documentation for spawnEntity?

#

in jayly

halcyon phoenix
#

why stirante?

wary edge
mystic mortar
halcyon phoenix
#

is teleporting the entity the only way to change where it's facing?

wary edge
halcyon phoenix
#

hey uh what does ${} means?

#

like ${foo}

wary edge
halcyon phoenix
#

so it converts it to strings?

mystic mortar
valid ice
#
let value = 54;
console.log('This is multiplication: ' + 54 * 2);
console.log("This is multiplication: " + 54 * 2);
console.log(`This is multiplication: ${54 * 2}`);

All three produce the same results

#

The third is just easier to read, for most folks

hasty spindle
valid ice
#

Not unless you define them beforehand

hasty spindle
valid ice
#
const array = ['name 1', 'name 2', 'whatever'];
array.forEach(name => form.buttom(name))

for instance

hasty spindle
valid ice
#

then you index the array using the selection value to get back the name

hasty spindle
#

so no it's not their name

valid ice
#

You do array[r.selection]

hasty spindle
valid ice
#

yes

hasty spindle
hasty spindle
valid ice
#

No

hasty spindle
mystic mortar
hasty spindle
# valid ice No

i want to test every dynamic property until find one with the same name of my buttons form UI

#

but that don't work

#

how can i do ?

mystic mortar
#

Any help is appreciated.

tight plume
valid ice
valid ice
#

Idk what you’re asking for

hasty spindle
#

jsut one thing before i explain

#

the array for button give me number but i want the name of the buttons

#
let names = [r.selection]```
#

that give me numbers and not names

valid ice
#

You need the array name in front of the brackets

hasty spindle
valid ice
#

Please, learn JavaScript syntax before doing scripts- it makes things easier on yourself and people trying to help

hasty spindle
#

see js let names = [r.selection]

cinder shadow
#

That is literally the same thing you pasted 20 minutes ago

hasty spindle
cinder shadow
#

Then why did you say you did it

hasty spindle
#

can you tell me what he wants

cinder shadow
#

He wants you to watch a video on JS syntax

hasty spindle
#

i think i did what he said

hasty spindle
cinder shadow
#

Then why did you ask what he wants

hasty spindle
hasty spindle
#

what's the difference ?

#

between is reponse and my code

valid ice
#

If you just have a variable in brackets, like you do (With no reference to an array), then it can do a few things.

  1. If the variable is an array, it will return the first element in the array.
  2. If the variable is not an array, it will return the value in an array
hasty spindle
#

how can i resolve the problem ?

valid ice
#

Note the differences

wary edge
#

I would highly recommend stop working on ScriptAPI and learn the basics of JS first. Please. It's frustrating not only for you but others as well

valid ice
#

Also note that array indexing is basic javascript/

hasty spindle
valid ice
#

well... use it then

hasty spindle
#

my english is bad so i understand

hasty spindle
pale terrace
#

I always test the values ​​in minecraft XD

mystic mortar
wary edge
mystic mortar
mystic mortar
mystic mortar
empty grail
#

how can i make player falling faster?

ancient sierra
#

Hello! Was the Vector class removed? I'm trying to import it but it doesn't exist?

ancient sierra
#

Interesting

#

As in the built-in Math global var?

valid ice
#

You can either bundle & import the math module or make your own vector class

valid ice
ancient sierra
#

Ohh I see

valid ice
#

s' like the vanilla data module but for math funcs

ancient sierra
#

I'm gonna try and create it because why not ¯_(ツ)_/¯

ancient sierra
valid ice
#

install & import- it's not included in the base game like server, server-ui, server-gametest and the rest are

chrome flint
ancient sierra
#

Awesome! Thank you so much bao_doggo_happy

woven loom
runic gust
#

how can i pass information from scripts to json ui

chrome flint
prisma shard
distant tulip
#

floats are numbers

random flint
#

Floats are numbers.
Integers are numbers.

random flint
#

You can wear horse armor and get its armor protection value lol

empty grail
#

anyone know how to make player falling faster?

mystic mortar
#

Send them down

random flint
#

Source: Trust me bro

mystic mortar
tiny tartan
woven loom
#

okay surprisingly Acode editor supports typings, atleast locally 🙂

woven loom
#

will do in #1067535712372654091

tiny tartan
#

i can't wait for it bro

woven loom
#

text is enough or video is needed ?

tiny tartan
#

might need video

#

dont tell me you made your own terminal for acode

woven loom
#

nah its simple setup

tiny tartan
#

alr

hazy nebula
#

How to make a piece of code like this: 1 test to see if there is tnt in the player's inventory and amount 2 in the player's hand, does the player hold any amount of tnt?

prisma shard
#

NO WAY

#

npm typing in mobile??

ancient sierra
#

That sounds like a super win for mobile coders

subtle cove
#

\o/

prisma shard
#

we all need it

fallen cape
#

are dynamic imports available rn?

#

oh they are

#

cool

prisma shard
#

uh
can anyone record a video for me?
of a script
like, i want to make a showcase of my script
but i can't record on my pc

prisma shard
fallen cape
#

aaaa

#

why not record it on phone?

prisma shard
#

i dont have rn

#

its urgent

fallen cape
#

well

#

dm

prisma shard
#

thank you bro\

random flint
#

Where is the Block.redstonePulse(power: Number)

distant tulip
#

||that a lie we don't even have the "home" version||

prisma shard
#

lol

halcyon phoenix
#

q.is_baby?1.4:1 what : mean? what operator is it?

ripe swan
#

I'm working on a parity addon for dispensers dispensing armor stands. I'm doing it by subscribing to the entitySpawn afterEvent and checking to see if the entity was an armorstand item and if so, check to see if there's a dispenser around it facing the logically correct version to have dispensed it. If this checks out, then I kill the armor stand item and spawn an armor stand. This is for the most part working fine, , except I'm hitting a few edge cases. When I have a dispenser facing down and the resulting armor stand is broken in such a way that the "loot" armorstand item is spawned in the space below the dispenser, then it automatically changes back to the Armorstand entity.

#

anyone have any thoughts on if there's a better way of doing this or handling this issue?

#

I haven't been able to find a way to detect what spawned the entity that's triggered the event.

#

I'm doing this will all stable api's, I don't want to mess with trying to get experimental stuff to work.

woven loom
#

can u send short video

pseudo timber
#

anyone know where to find res stuff

woven loom
#

what?

ripe swan
woven loom
#

yep

ripe swan
#

Maybe match the triggered_bit to 1 as well?

#

Bah, it doesn't work if the Redstone pulse is too short

subtle cove
warm drum
#

I cant get the onTick to run

#
world.beforeEvents.worldInitialize.subscribe(initEvent => {
    initEvent.blockTypeRegistry.registerCustomComponent('wiki:example', {
        onTick: (e) => {
            console.warn('TICK!');
        }
    });
});


"minecraft:tick":{
    "interval_range": [1, 1],
    "looping": true
}
#

What did I do wrong?

halcyon phoenix
#

can you do location.dimension.getEntities()?

#

can you get the dimension from a location?

halcyon phoenix
#

I see

halcyon phoenix
warm drum
halcyon phoenix
warm drum
halcyon phoenix
#

you also need to add "minecraft:custom_components"

#

that's what you put in the wiki:example

warm drum
halcyon phoenix
#

oh what?

#

oh lol

warm drum
#

The interact works

#

not the onTick

#

thats strange

halcyon phoenix
#

I compared mine and yours there seems to be no problem

warm drum
#

it works now

halcyon phoenix
#

what.....

warm drum
#

Out of no where

#

it just spam my console

halcyon phoenix
#

try increasing the ticks

#

oh lol

warm drum
#

💀

halcyon phoenix
#

it probably was not working cause it's very fast?

warm drum
#

i assume when add the minecraft:tick component, it applies too

amber granite
#

Script API is typing

halcyon phoenix
#

is math bad for minecraft?

valid ice
#

What

halcyon phoenix
valid ice
#

Why would math be bad for the game

halcyon phoenix
#

lag and stuff

#

does it affect the performance?

valid ice
#

Math operations are the last thing that would ever slow down the game

halcyon phoenix
#

ahh I see

#

I was worrying for something dumb

valid ice
#

Any modern code engine can handle metric tons of math operations with blistering speed

#

Unless you are making high-iteration code (in the tens of thousands) or using numerical methods to calculate stuff, you do not ever need to worry about it

halcyon phoenix
#

Thank you for the explanation

#

Trigonometry is fun 🙃

glacial widget
#
import { system, world } from '@minecraft/server';

world.beforeEvents.playerInteractWithBlock.subscribe((ui) =>{
    const {player: source, itemStack, block} = ui
    
    if(block.typeId == "minecraft:diamond_block"){
        console.warn("works")
    }
})

does anyone know why this does not work?

halcyon phoenix
#

also is the player supposed to have colon? or comma?

#

{player, source, itemStack, block}

glacial widget
#

none

glacial widget
#

taht*

#

that*

#

bru

subtle cove
#
const source = ui.player
const { player: source } = ui
halcyon phoenix
#

you need sleep

glacial widget
#
const {player: source, itemStack} = ui
    const block = ui.block
subtle cove
#

the colon is just to rename the variable

halcyon phoenix
#

im confused on the format

glacial widget
subtle cove
#

just practice w/o the {} for now

glacial widget
#

i updated my npms so it cant be that

subtle cove
#

wrong property key then

glacial widget
subtle cove
#

w8 it's right properties there

glacial widget
#

is it probably the block?

subtle cove
#

put the warn just above the if condition

glacial widget
subtle cove
#

just spam em console.warns lol

glacial widget
#

lol

#

still does nothing

subtle cove
#

so file isnt active, BP inst working...

glacial widget
#

na it is

#

i tried itemUse and works fine

#

but playerInteract doesn't

prisma shard
glacial widget
valid ice
prisma shard
glacial widget
subtle cove
#

works fine 4 me :/

glacial widget
#

cuz how

subtle cove
#

.

shy leaf
#

can someone help me with math later
i cant post code rn but ill be here in 10 mins

glacial widget
random flint
#

Try doing it with your empty hand and interact the block

wary edge
#

Use a brush to interact with the block

glacial widget
subtle cove
#

is the file even working?

random flint
#

Logic error perhaps? Or your file isn't imported?

glacial widget
glacial widget
#
import { system, world } from '@minecraft/server';

world.beforeEvents.playerInteractWithBlock.subscribe((ui) =>{
    const {player: source, itemStack} = ui
    const block = ui.block
    
    console.warn("works")
    if(block.typeId == "minecraft:diamond_block"){
        world.sendMessage("hey")
    }
})
#

I see the mistakes nowformally_pumpkin

random flint
#

I don't even know what the mistake is lol

amber granite
#

The mistake is misleading

#

In Oxford's dictionary

glacial widget
misty pivot
#

i used ItemStopUse to detect weather the player stopped using the item before it completely finishes but for some reason it doesn't run, it's kinda like this

world.afterEvents.itemStopUse.subscribe((data) => {
    const useDuration = data.useDuration;
    if (useDuration > 0) {
        ...
    }
})```
valid ice
#

Does it trigger if you have something outside of the useDuration part?

misty pivot
#

nope

#

oh wait, i actually didn't test that

#

nvm it didn't run

hasty spindle
valid ice
valid ice
misty pivot
glacial widget
valid ice
#

That's weird, because my item triggers the event

random flint
subtle cove
#

/reload ?

misty pivot
#

last time i checked the function has no errors aswell

glacial widget
glacial widget
misty pivot
# subtle cove /reload ?

i mean, i did try it in separate worlds multiple times, does reload make a difference? (mb mb, wrong reply)

hasty spindle
random flint
#

Try to rejoin the world then

valid ice
random flint
shy leaf
glacial widget
random flint
shy leaf
#

i mean yeah im using that

#

i should be more specific

#

oh damn wait i think i figured it out

subtle cove
#

oldValue newValue difference

shy leaf
#

yeah im also using that

#

i think i found the issue

dusky cipher
#

Is there a good way to prevent tnt from dropping items

misty pivot
valid ice
dusky cipher
valid ice
#

Do I want to know what you tried?

dusky cipher
#

no

#

lol

valid ice
random flint
#

better than killing the entity tbh, it could risk killing some innocent bystander

cinder shadow
#

whar

valid ice
#

Me when my dog gets .remove()’d

cinder shadow
#

there is a 0.1% chance of killing an innocent bystander

random flint
#

It would be janky to search the correct one

cinder shadow
#

they said they want it to not drop anything

valid ice
#

Then get all entities at block location and filter ones if the item component type ID matches the broken block! bao_ext_aintbutter

#

(This is a joke btw)

dusky cipher
#

i was going to filter items by the typeid by getting the blocks broken

#

which wouldve worked but it wouldve been kinda slow

valid ice
#

Also don’t forget to filter out air blocks from getImpactedBlocks()

random flint
#

it can pickup air?

valid ice
#

It makes the array of blocks much shorter and easier on the engine

#

Yep

#

It can

dusky cipher
#

ok got it thanks

valid ice
#

My code for before explosion was not the fastest thing ever- still isn’t- but removing all air from impacted blocks make a significant difference

random flint
dusky cipher
#

it would jsut be slow

#

but i think i can fix it

valid ice
#

I wish getItemStack() had a parameter for silk touch or something

random flint
dusky cipher
#

yeah it might be, ill try both

#

shouldnt take long

hasty spindle
#

the console log me : Name: undefinied

random flint
honest spear
#

Does anyone has JS challenge quest?

random flint
#

Quest:
Subjugate 5 bugs in your code, I shall give you 5 Copper Points.

honest spear
#

i mean direct JS challange

#

For example this

world.events.playerJoin += function Ya(event){
  //code
}
fading sand
#

anyone knows a way how to check if an entity is invincible

#

?

pale terrace
#

in entity.applyDamage, the option "cause" when I set to "projectile" doesnt work, the log say that projectile doesnt exist, anyone can help me?

pale terrace
valid ice
cinder shadow
#

what a dastardly thing to do

valid ice
#

I am but a little bit devious

cinder shadow
#

when entity.triggerEvent doesn't work

#

wrong one, playAnimation

random flint
honest spear
#

Well, i mean something to related to vanilla JS, not apis or somekind of game

#

but nvm

warm drum
#

can we use script to spawn item?

#

i have a custom block "wiki:test_block" and i want to spawn the block as item

honest spear
#

not related to vanilla JS

warm drum
#

is it possible?

#

or I have to use lootable?

random flint
#

IDK man, I never use JS for other stuff

#

Make that one Spinning donut maybe

honest spear
warm drum
#

i have like 32 block that follow the same format except for the id

honest spear
warm drum
#

and i dont want to make 32 lootable file for each of them

random flint
warm drum
honest spear
#
BlockPermutation.resolve("myblock:yes");
graceful mountain
#

Is it possible to detect entity right click atm with stable api?
or is it not

hasty spindle
#

ty

#

but when i want to compare the name of the button and the dynamic property for the result, that don't work and idk why

#
    if(block.typeId === "minecraft:sand") {
        const tpmenu = new ActionFormData()
        tpmenu.title('Menu de téléportation')
        let privatetp = player.getDynamicPropertyIds().filter((name) => name.startsWith(`@${player.name}`))
        let publictp = player.getDynamicPropertyIds().filter((name) => !name.startsWith('@'))
        privatetp.forEach(tp => {
            tpmenu.button(tp.replace(`@${player.name}`, "§l§5>§r§b") + ' §l§5<§r\n§aCliquez pour vous téléporter')
        })
        publictp.forEach(tp => {
            tpmenu.button(`§l§5>§r§e ` + tp + ` §l§5<§r\n§aCliquez pour vous téléporter`)
        })
        const buttonNames = [privatetp + `,` + publictp];
        tpmenu.button('Supprimer un point de téléportation')
        tpmenu.show(player).then((r) => {
            if(r.canceled) return;
            const selection = [r.selection]
            let privatetpname = buttonNames.filter((name) => name.startsWith(`@${player.name}`))
            privatetpname.forEach(name => { name.replace(`@${player.name}`, "")})
            selection.forEach(search => {
                if(buttonNames === privatetpname) {
                    player.sendMessage('test')
                }
            })
        })
    }```
random flint
#

💀 I'm not patient enough to teach, gtg sleep (time zone)

glacial widget
#
player.teleport(-109.64 92.00 -199.43)

how do i use the tp notation

valid ice
#
player.teleport({x: -109.64, y: 92.00, z: -199.43})
valid ice
#

Has to be passed in as a vector 3- x, y, and z components

glacial widget
valid ice
#

Just what the function needs

#

can't teleport somewhere if you don't know the y coordinate

glacial widget
sharp elbow
#

Using the Vector3 interface across the codebase is convenient. Positions are already stored as Vec3s—that function signature could easily be teleport(x, y, z), but then any call to it would need to "deconstruct" a vector, rather than just passing it directly

valid ice
#

Back in my day we had Location & BlockLocation API classes

sharp elbow
#

Teleporting a player to themselves could be written as the following, but thankfully it is not.
player.teleport(player.location.x, player.location.y, player.location.z)

chrome flint
#

does anyone have a database for saving items

glacial widget
#
import { world, system, Player} from '@minecraft/server';
import { ActionFormData, MessageFormData, ModalFormData, ModalFormResponse } from "@minecraft/server-ui";

const rule = new ActionFormData()
.title("Rules")
.body("Test")


world.beforeEvents.playerInteractWithBlock.subscribe((ui) =>{
    const player = ui.player
    const block = ui.block
    
    console.warn("works")
    if(block.typeId == "minecraft:lectern"){
        player.sendMessage("the rules")
        rule.show(player)
    }
})

i dont understand the error for the actionform not opening, could someone help?

chrome flint
# glacial widget ```js import { world, system, Player} from '@minecraft/server'; import { ActionF...
import { world, system, Player} from '@minecraft/server';
import { ActionFormData, MessageFormData, ModalFormData, ModalFormResponse } from "@minecraft/server-ui";

const rule = new ActionFormData()
.title("Rules")
.body("Test")
.button(`test button`,"textures/ui/arrow_left")


world.beforeEvents.playerInteractWithBlock.subscribe(async (ui) =>{
    const player = ui.player
    const block = ui.block
    
    console.warn("works")
    await null
    if(block.typeId == "minecraft:lectern"){
        player.sendMessage("the rules")
        rule.show(player)
    }
})
fading sand
#

or is it smth different?

cinder shadow
#

I enjoy that as my code gets more complex, I eventually have no idea what I'm doing and I start making miscellaneous variables and doing 100 different things until something works 😔

#

at least it works

fading sand
#

?

cinder shadow
#

no that's what I've already done several times

#

it took me an entire year to finally work on this junk again

#

I'll throw it to chatGPT and see if it says anything reasonable

valid ice
#

“Yeah naw bro just restart”

  • chat GPT
cinder shadow
#

to be fair, these variables are probably necessary

chrome flint
#

but at least it works tho

fading sand
#

how does EntityApplyDamageByProjectile work?

pale terrace
fading sand
pale terrace
#

nvm I will use entityAttack

amber granite
#

Hey anyone here knows translation keys rules ?

fading sand
#

Like entity.applyDamageByProjectile

amber granite
#

So

#

I want to make an algorithm

#

That returns item name based on id

tawny peak
#

does anyone know what this means?

[Scripting] ReferenceError: Native function [HttpClient::get] does not have required privileges.    at <anonymous> (cmd.js:21)```
amber granite
#

Use system.run(()=> {})

tawny peak
#

ohh

amber granite
#

If u use beforeEvents

#

Classes

tawny peak
#

thanks

amber granite
#

Uw

#

Use it on things

#

That need to be written in worlds

#

Like spawnEntity etc...

#

beforeEvents are just for reading

#

And cancelling the events

amber granite
#

?

distant tulip
valid ice
amber granite
wary edge
drifting ravenBOT
#
The format for naming items in .lang changed

Old: item.sirlich:hoe.name=Hoe
New: item.sirlich:hoe=Hoe

Essentially you just need to remove the .name

valid ice
open urchin
#

they want to get the item display name with scripts
it isn't always in that format

#

there's no way currently

amber granite
#

They !

wary edge
valid ice
#

oh I see

amber granite
wary edge
#

YOU

amber granite
#

I am he

#

Ok

#

But

open urchin
#

they is neutral
like you

amber granite
#

Or idj dosen't work

wary edge
amber granite
#

So

#

There is no static format

#

For vanilla's items

wary edge
amber granite
#

Doesn't work

#

On some items

#

Or lot of them

shy leaf
amber granite
#

Finally

shy leaf
#

so the health bar is built like this
the length of health bar depends on effectiveMax (or set value), and outside the health bar code, it gets damage done via getting oldvalue + currentvalue(not newvalue) and stores into entity's dp, named 'health diff'

#

the red part is current value of hp, and the gray part is calculated by removing the amount of hp and 'health diff' dp on health bar length

#

inside runinterval, theres a code that reduces 'health diff' dp that it creates white part in health bar dynamically

#

but since only the empty part is calculated, it cant set the red part

#

which makes the white part to show on gray part (you can notice it if you look closely in the vid)

valid ice
#

I cannot see that

Are white & grey separate things? What do each do?

shy leaf
#

gray is 'empty part of hp bar' and white shows damage done

#

ill record a vid

#

iron golem's hp is way too large so its a bit unnoticable

valid ice
#

If I understand this right:

  • Dark red is missing HP from max
  • Light red is current HP
  • White is damage done
  • Dark red replaces white slowly
shy leaf
#

wait no its not gray

#

its dark red lmao sorry

valid ice
#

ah gotcha

#

So three colors then

shy leaf
#

ye

#

recording rn

valid ice
#

edited understanding there

shy leaf
#

i can post the code if you want, i just have to strip the unrelated code

#

the hp bar wasnt supposed to disappear but since the white part exceeds the hp bar length it just breaks

random flint
#

Can't you just delay it?

amber granite
#

I think i made the best function to retrieve Name based on ID

shy leaf
random flint
#

Is it supposed to disappear when the HP deduction animation is done playing?

shy leaf
#

no its supposed to stay

#

but well its smth i can fix later

random flint
#

What does keeping the HP bar do when the entity representing it already died?

shy leaf
#

well

#

why not, i wanna keep the feeling of one shotting mobs

#

it was kaioga's idea lol

random flint
valid ice
#

^

shy leaf
#

wait what does it do

valid ice
#

Math.min(0, 6) returns 0 as its lower

random flint
#

Chose between numbers which one is smaller or larger

valid ice
#

Math.max(0, 6) returns 6 because it’s higher

shy leaf
#

holy

valid ice
#

Using both, you can “clamp” a number between a min & a max- in your case, between zero and the max HP of the entity

shy leaf
#

i never knew those existed omg

valid ice
shy leaf
#

i can finally get rid of hundreds of if else

valid ice
shy leaf
#

(dont question it please)

valid ice
#

I am scared for your sanity

#

I am questioning it

shy leaf
random flint
#

I mean, it's possible recreating it using if else lol

shy leaf
#

i only started scripting like

#

two? three? weeks ago

valid ice
#

But like, min & max are… pretty basic…

shy leaf
#

in my defense i probably missed those in JS tutorials

valid ice
#

I am scared for what other built in functions you may be missing

shy leaf
#

pain

valid ice
#

I’m sure

amber granite
#

I have no idea

#

What i made

#

But if f up everything 💀