#Script API General

1 messages Β· Page 104 of 1

halcyon phoenix
#

oh lol

rustic ermine
#

interesting... the first one is called from my main tick loop calling a getter

...
    get isValid(): Boolean {
        return this._player.isValid
    }
...
if (!player || !player.isValid) { this.removePlayer(playerID); continue; }
``` (0.6s per tick, profiler ran for maybe 5 sec), second one is a SINGLE isValid call  from a different function calling the getter for the minecraft Player class, then isValid on that. am I just misinterpreting this? is a single isValid call really that slow?
```ts
        const a = this.entity.isValid

edit: okay, so getters are slow. this.entity.isValid does this

    get entity(): Player {
        return this._player
    }

changing to

        const a = this._player.isValid

brought a single call to 295.73ms. still seems unacceptable for the only safe way to check validity? 0.3s for a single check >_>

shut citrus
#

is java faster than c++/js ?

shrewd relic
#

ong

#

i wwas looking for this

random flint
#

🫑

round bone
unreal cove
#

C++ is significantly faster than Java, not just a "bit"

round bone
rustic ermine
# unreal cove C++ is significantly faster than Java, not just a "bit"

that's not always true or most of the time true. it's actually pretty difficult to write better performing c++ than "regular" java.. meaning it takes a very experienced C++ programmer to write faster code than the average java dev could write. old jvms were pretty slow, maybe before java 8, but modern is extremely fast

#

now if we could just get a package manager for java that didn't suck..

unreal cove
#

yea java did got faster with modern jit/jvm optimization stuff, but native C++ will still outperform it lol, especially for low level/real time tasks, and saying "a bit faster" (<5%) is misleading IMO

rustic ermine
#

it really depends what you are doing. with c++ you can avoid heap allocation to get speed, but that makes the domain map of your program more difficult to reason with

shut citrus
#

Why can java cancel player attack but bedrock can not?

distant tulip
shrewd relic
unreal cove
#

I often avoid using java solely becuase of how slow it is, C++ mops the floor with it and there's no comparison

rustic ermine
#

when was the last time you did a fair comparison though? by fair, I don't mean just making the same program in both languages, I mean doing the same program in both languages the exact same way (avoiding heap for example, iterators, allocations, etc)

rustic ermine
#

also have to think about how much your time is worth lol. recently I wrote a Go program in about half hour that traverses a directory tree of images, gets the sha256 hash of everything, then finds any duplicate images. my brother did a version of the same thing in Rust, it took him the better part of a day, and it was slower than mine because it was very easy to use multiple threads in Go. giving that example because benchmarks really don't show the whole picture

round bone
#

tbh questions like this require much more context

distant tulip
#

It depends on the code itself too, i just searched for a benchmark and found a Reddit post from a person surprised that java is faster, the comments pointed out where he gone wrong in his code

distant tulip
#

brokenBlockPermutation have no property named typeId

round bone
distant tulip
#

I don't think how easy a language is should count in a benchmark, you are comparing the best of what that language is offering, but yeah that might be the problem in the Reddit post i mentioned

round bone
#

C++ might be faster, but Java fits better for some things

round bone
#

you must be talking about extreme cases where is might be actually much slower

granite cape
#

bruh why attachedBlock piston look like this

#

fk this make me crazy

granite cape
#
if(![])world.beforeEvents.playerInteractWithBlock.subscribe(v=> system.run(()=>v.player.onScreenDisplay.setActionBar(`${v.block?.typeId}`)))

function getFrontBlock(block) {
    const facing = block.permutation.getState("facing_direction");
    return 2 === facing
        ? block.north()
        : 3 === facing
        ? block.south()
        : 4 === facing
        ? block.west()
        : 5 === facing
        ? block.east()
        : null;
}

world.afterEvents.leverAction.subscribe(e=>{
  if (e.player && e.isPowered) {
    const twst=world.afterEvents.pistonActivate.subscribe((i) => {
      if(i.isExpanding&&e.dimension===i.dimension)system.run(() => {
        for (const block of i.piston.getAttachedBlocksLocations()) e.player.sendMessage(`${i.dimension.getBlock(block)?.typeId}`)
      })
    })
  }
})
subtle cove
#

typeId got called on block at a few ms delay

#

u can even decalre global block variable, and keep calling it's typeId, and everytime it's changed, u can still call it, and will have the current block's typeId

#

what's not changed is just the x,y,z that's also why stringifying block results like {x,y,z}

dusky flicker
#

everything on java is heap allocated

#

stuff like data driven might not be supported

#

java has got jit but that still is slower than navite and llvm optimizations

#

the unique way java can be faster than C++ is if we are comparing a bad written C++ code with a well written Java code

#

if you use the same kind of datastructure and the optimizations, C++ will be almost always faster

rustic ermine
# dusky flicker everything on java is heap allocated

I'm aware lol. that was a poor example, but the point is to compare apples to apples and not "this is the most hyper-optimized archaic way to get blazing performance that only 1% of people would even know exists"

#

I also believe people care about performance way too much in general when picking the language they use. 99.99999% of everyone's project is not going to get enough use or traffic to warrant spending much more time on something that is faster

dusky flicker
#

at least when talking about work

#

like, i saw a benchmark of backend libs

rustic ermine
#

yeah. I agree there. I was mainly thinking about some of the Rust community thinking everything should be in rust when that is just not true lol

dusky flicker
#

man spring boot was at 99

#

only 13k req per second, while some in rust and C had 68k

rustic ermine
#

13k per second is still an absolutely insane point to reach

dusky flicker
#

i really dont know why people tend to be like that

round bone
#

πŸ”₯

dusky flicker
round bone
#

Bun is not as stable as Fastify with Node.js

dusky flicker
#

i thought it would work on node as well

round bone
#

not really

#

:/

halcyon phoenix
#

how do I search properly for the player class?

cursive fog
#

Is it possible tho change camera posistion using scripts

subtle cove
halcyon phoenix
prisma shard
#

I am sorry, I thought It was off-topic... wtf don't think me as stupid but idk why that happens...Its the first time thinking as wrong channel

subtle cove
halcyon phoenix
subtle cove
halcyon phoenix
subtle cove
#

use Jayly's ;-;

#

kiddin, uhm... on stirante it works on latest section

halcyon phoenix
#

so I tried

distant tulip
gaunt salmonBOT
halcyon phoenix
#

oh

#

you mean I search for methods/properties that returns the player class

distant tulip
#

yeah

round bone
#

Is there any way to provide more usages to a single command?

I would like to implement

  • /dm <player: Player> <msg: string>
  • /dm <player: string> <msg: string>
stark kestrel
#

When is beforeEvents.entityHitEntity coming bruh 😭

halcyon phoenix
stark kestrel
halcyon phoenix
#

it would be a blessing it would come

#

it's like waiting for gta 6

stark kestrel
#

I made my own beforeEvent, but dude, the knockback kills me

warm drum
#

its annoying

prisma shard
#

so thats why he pings you :>

cyan basin
#

i mean yeah, you chose to call yourself that.. expect to be pinged

meager zenith
#

Idk what's wrong but how am I supposed to access the player from the command's paramete

system.beforeEvents.startup.subscribe(cc =>{
    const PlayerSelector = {name: "victim" , type: "PlayerSelector"};
    const view_origin = {
        name : "origins:view_origin",
        description : "Opens the GUI for your origin.",
        cheatsRequired : true,
        permissionLevel : 0,
        optionalParameters : [PlayerSelector]
    }
    cc.customCommandRegistry.registerCommand(view_origin,
        (source, victim) => {
            console.warn(source.sourceEntity.name);
            console.warn(victim.name);
        }
    );
});
warped blaze
#
registerCommand(
    customCommand: CustomCommand,
    callback: (
        origin: CustomCommandOrigin,
        ...args: any[],
    ) => undefined | CustomCommandResult,
): void```
meager zenith
#

omg tysm

#

it makes sense now

subtle cove
#

same thing

untold magnet
#

well well well

#

fixed, i can detect When u load into the world

#

the event will fire AFTER loading the world, not while in the loading screen

sharp elbow
#

Cool. What's the tech?

subtle cove
untold magnet
# sharp elbow Cool. What's the tech?

player,json or entity.json
basically changing an entity property using the playerSpawn component, and apparenlty the event will only trigger after loading the world

subtle cove
# meager zenith Idk what's wrong but how am I supposed to access the player from the command's p...
system.beforeEvents.startup.subscribe(cc =>{
    const PlayerSelector = {name: "victim" , type: "PlayerSelector"};
    const view_origin = {
        name : "origins:view_origin",
        description : "Opens the GUI for your origin.",
        cheatsRequired : true,
        permissionLevel : 0,
        optionalParameters : [PlayerSelector]
    }
    cc.customCommandRegistry.registerCommand(view_origin,
        (source, victims) => {
            console.warn(source.sourceEntity.name);
            console.warn(victims[0].name);
        }
    );
});```
sharp elbow
#

Oh damn, that simple? That's cool, thanks for sharing

untold magnet
#

np, i love finding solution for the impossible things lol

livid elk
#

im trying to make like daily reward system, is there a way to detect real world time?

halcyon phoenix
livid elk
#

bds?

halcyon phoenix
#

bedrock dedicated server

livid elk
#

ahhh

halcyon phoenix
#

there's a few here that knows those stuff

subtle cove
halcyon phoenix
subtle cove
#

Mhm

distant tulip
halcyon phoenix
#

damn my bad

#

too much script API makes you forget JS Objects

subtle cove
#

It can't be localized on other locations tho, like the toLocaleString on client's side won't work accurately

subtle cove
#

Tho the dm usage for PlayerSelector already behaves like "player name", @r

dusky flicker
# halcyon phoenix too much script API makes you forget JS Objects

actually πŸ€“β˜οΈ when entering a loop that never ends, if you try to check the passage of time via system.currentTick, it will always be the same because the engine seems to block the thread and wait for that piece of code to finish to update the engine state, while on using Date.now you can do check because its not bound to the engine itself

round bone
#

Is 2.1.0 newest stable for 1.21.100?

distant tulip
#

Yes

livid elk
#

is it still not possible to update the player attributes using a script? only by using component groups for now?

gaunt salmonBOT
midnight crane
#

Can someone send me the example of the code where if you have a potion effect a command happens

sly valve
grim raft
#

is there an inputPermission methode for players?

#

or entities in general

round bone
grim raft
#

I swear I just checked them how did I miss it 😭

grim raft
round bone
#

I am not sure, spawn a cow and remove it's permissions via command

thorn flicker
round bone
#

Is there any way to provide more usages to a single command?

I would like to implement

  • /dm <player: Player> <msg: string>
  • /dm <player: string> <msg: string>
    -# Asking for 2nd time, beacuse no one has answered
shut vessel
#

what is the api of the last version

north frigate
shut vessel
#

thx

north frigate
#

np

wise raft
#

Is it a bug that you can't run a command as operator on a dedicated server when the permissionLevel is set to Admin?

untold magnet
#

guys, how to add/remove stuff from an array?
like i want to add/remove titles from the array, the array is empty and u have to do something like break a block to add a title to the array, and like place a block to remove the title from the array, how can i do that?

round bone
untold magnet
subtle cove
round bone
#

That's why I would like to provide Player (for faster typing) type, but also a string for sending messages across instances

untold magnet
distant tulip
#

Array.splice(index of the item you want to remove, 1)

untold magnet
# round bone Yes

what about changing the value of an item inside the array?
like instead of removing the previous one and add an updated one?

round bone
midnight ridge
#

someone knwo how to get this default texture?

midnight ridge
round bone
round bone
round bone
untold magnet
untold magnet
round bone
#

Like index 0 is 1st element, index 1 is 2nd element etc.

untold magnet
#

yeah i see

#

so all i have to do is:
set the titles in a specific order, and keep updating their value using titles[1] = 'updatedTitle'?

round bone
untold magnet
untold magnet
#

show me an example, that will save me alot of time

round bone
#
const updateTitle = (oldTitle, newTitle) => {
    const index = titles.findIndex((title) => title === oldTitle)
    if (index !== -1) titles[index] = newTitle
}
untold magnet
untold magnet
#

each time with another title

round bone
#
/**
 * @param newTitles {{ old: string, new: string }}
 */
const updateTitles = (newTitles) => {
    for (let i = 0; i < titles.length; i++) {
        const { old, new: newTitle } = titles[i]
        if (titles[i] === old) titles[i] = newTitle
    }
}
#

Or use this

untold magnet
#

well, i dont want to use any loops on this addon,

#
  • it looks too complicated for my brain to process
round bone
#

Then use my first function, but for loops are easy and good-to-know - you should learn them

untold magnet
#

like if the title starts with test0: it will be detected and keep updating its value

#

like detecting if the oldTitle starts with test0: to replace it with test0:true

slim forum
#

Im doing somethig wrong?

#

Is not moving

wary edge
midnight ridge
round bone
shy leaf
#

guys, quick

#

whats the beta api version

#

nvm found it

#

sob

round bone
shy leaf
#

danke

halcyon phoenix
visual zephyr
#

does player.runcommand work if the world has cheats off

#

i tested it and works

round bone
visual zephyr
visual zephyr
#

yeah i tried scriptevent

#

idk for the others

halcyon phoenix
#

always has been

round bone
#

does it mean I can use Minecraft add-ons to get every achivement?

#

πŸ‘€

halcyon phoenix
#

but I believe they are fixing it

visual zephyr
#

minecrafts gonna patch that

halcyon phoenix
#

there was a post about that last time

#

smokey sent it here

#

I forgot when

round bone
#

I will use it today

#

πŸ˜„

#

joking, I am too busy with coding

granite badger
#

v1.21.100 scriptapi docs are out btw if you use my docs. Seems like mslearn hasn't updated yet (hence the 6hr delay)

livid elk
#

what's the current stable version?

wary edge
#

It's 2.1.0

cunning canyon
#

Is there a way to safely teleport the player to another dimension?

Meaning avoid teleporting them inside a wall or below the map

#

I was thinking in running some checks on the target dimension before teleporting but it seems that I can’t get blocks inside an unloaded dimension :/

halcyon phoenix
#

tickingarea that location you want to teleport then getblock or do what you want with it

cunning canyon
#

Thanks!!!

hushed ravine
#

Where's 2.1.0 for 1.21.100?

round bone
hushed ravine
#

I can't seem to find it

round bone
#

Use this version atm

somber cedar
visual zephyr
#

if i used ticking area in the nether while im in the overworld can I get info on that specific area using script api

visual zephyr
#

is there a limit for a ticking area

halcyon phoenix
visual zephyr
#

ohh nice

round bone
prisma shard
#

uh

#

what do i add to get players front

#

ugh how do i explain

#

like, if we want ground under player, that would be {x: 0, y: -1, z: 0}

#

And for above player's head, {x: 0, y: 1, z: 0}

#

now whats the front?

distant tulip
prisma shard
#

huh

#

i mean what to add to X or Z

#

can someone help

#
system.runInterval(async () => {
    for (const player of world.getPlayers()) {
        const d = player.dimension;
        const l = player.location;
        const h = player.getHeadLocation()
        const raycastResult = player.dimension.getBlockFromRay(
            h,
            { x: 1, y: 0, z: 0 },
            { maxDistance: 3 },
        );
        const b = raycastResult.block.location;
        d.spawnParticle("minecraft:redstone_wire_dust_particle", b)
        //player.onScreenDisplay.setActionBar(`Biome: ${await getBiome(l, d)}`)
    }
})```
#

dis shit not work

#

when spawning particle it either say block undefined or expected type vec3

halcyon phoenix
prisma shard
#

getBlockFromRay is also a thing 🀷

halcyon phoenix
#

I see

prisma shard
#

i mean that also exists

prisma shard
#

I am trying to perform raycast

#

And get the air infront 3 blocks

halcyon phoenix
#

I havne't used getBlockFromRay so I have no idea what's going on

hushed ravine
#

One thing I don't quite like about custom commands is that they don't allow you to use localization keys

prisma shard
round bone
hushed ravine
#

I hope they update it soon!

halcyon phoenix
#

filter the search to coddy's

prisma shard
#

cant

#

I did filter ;-;

granite cape
#

bruh i feel i will be crazy cause Faction SystemπŸ’₯

prisma shard
#
        const headLoc = player.getHeadLocation();
        const viewDir = player.getViewDirection();

        const hit = player.dimension.getBlockFromRay(headLoc, viewDir, {
            maxDistance: 3,
            includePassableBlocks: true
        });
        const targetLoc = hit?.block 
            ? hit.block.center() 
            : {
                x: headLoc.x + viewDir.x * 3,
                y: headLoc.y + viewDir.y * 3,
                z: headLoc.z + viewDir.z * 3
            };
        player.dimension.spawnParticle("minecraft:redstone_wire_dust_particle", targetLoc);
    ```
after a lot testing, i fixed it , here's the solution ^ if anyone need
distant tulip
distant tulip
#

That does the same thing, just so you know

rustic ermine
#
world.beforeEvents.playerBreakBlock.subscribe((e) => {
    e.cancel; return;
})

does nothing? nvm I'm dumb didn't read the docs πŸ˜‰

world.beforeEvents.playerBreakBlock.subscribe((e) => {
    e.cancel = true; return;
})

for discord search reference if anyone else has the same problem "break block before"

prisma shard
#

okay so the maxDistance parameter in Blockraycast options is kinda very buggy

#

Serty, do you have any solutions?

warm mason
prisma shard
#

I tried spawning a particle using Coddy's method to fix the hitLocation, When looking at block. Else, If not looking at block, It would spawn particles infront of 3 blocks, but when I try with maxDistance, The particle doesn't spawn, If looked closer.
If i looked further, That works though

warm mason
#

And then check the distance manually

prisma shard
prisma shard
#

At this line

const hit = player.dimension.getBlockFromRay({ ...head, y: head.y + 0.1 }, viewDir);```
When I add maxDistance,
```js
const hit = player.dimension.getBlockFromRay({ ...head, y: head.y + 0.1 }, viewDir, { maxDistance: 3 });```
It gets buggy
warm mason
prisma shard
#

Huh

#

Let me see..

warm mason
#

How long has Block.canPlace been around?...

prisma shard
#

what the-

warm mason
#

Why are they talking about methods that don't even exist?

#

or they exist, but they are simply not written about anywhere except changelog... well... in the style of mojang

open urchin
#

I assume it's referring to .amount = 1

warm mason
#

πŸ‘€

subtle cove
#

-# cant let ai know bout these just yet

prisma shard
#

I am using stirante's and well I cant find 2.1.0 stable wtf

open urchin
#

it hasn't released on npm yet

prisma shard
#

Ah

subtle cove
#

whats the latest mc version?

warm mason
warm mason
#

1.21.100 (release)

prisma shard
#

Where did you see that? I am comparing latest beta, Can't find anything.

#

Nothing related Blockraycast Options

subtle cove
#

hmm, my launcher doesnt have "update" button yet. im at v1.21.93 atm

prisma shard
subtle cove
#

mc store has an update btw

prisma shard
#

u mean ms store

warm mason
prisma shard
#

also what diff between systemShutdown and playerLeave ;-; Is it like you can get player in playerLeave but you cant get player in systemShutdown thats it

warm mason
#

I got a quadrillion errors and not one about which versions to use...

warm mason
prisma shard
#

ohh

warped blaze
#

what's new on the api for 1.21.100? for some reason i can't access the changelog website.

untold magnet
round bone
subtle cove
#
const head = player.getHeadLocation();
head.y += 0.1;
const viewDir = player.getViewDirection();
const hit = player.dimension.getBlockFromRay(head, viewDir, { maxDistance: 3 });
let targetLoc = hit
    ? fixFaceLocation(hit.block.location, hit?.faceLocation, hit?.face, 2)
    : {
        x: head.x + viewDir.x * 3,
        y: head.y + viewDir.y * 3,
        z: head.z + viewDir.z * 3
    };
player.dimension.spawnParticle("minecraft:redstone_wire_dust_particle", targetLoc);
untold magnet
#

if (!hasTitle) {smth}?

round bone
#

yeah

#
if (!hasTitle("some title")) {
    // smth
}
untold magnet
#

yeah i see

round bone
#

you can use a class with static methods to group them together

sharp elbow
#

You could use any of these methods too:

  • titles.includes (returns a boolean, for simple text matches)
  • titles.indexOf (returns a number or -1, for simple text matches)
  • titles.some (returns a boolean, takes a comparison function)
sharp elbow
subtle cove
#

item.getRawLore() wew

untold magnet
halcyon phoenix
#

what's poppin

#

new version of beta came out

#

2.2.0-beta

round bone
#

you have to re-declare titles array then

untold magnet
round bone
#
const newTitles = removeTitles("some-title")
untold magnet
#

ill pause working on the script for now and start remaking the hydration ui

wise raft
#

Why is args.length = 1 even tough I have two arguments? (Custom Commands)

wise raft
# round bone can you show us a code?
    event.customCommandRegistry.registerCommand(
        {
            name: "money:pay",
            description: "Give money to another player",
            permissionLevel: Minecraft.CommandPermissionLevel.Any,
            mandatoryParameters: [
                {
                    name: "player",
                    type: Minecraft.CustomCommandParamType.PlayerSelector
                },
                {
                    name: "amount",
                    type: Minecraft.CustomCommandParamType.Integer
                }
            ]
        },
        (origin, args) => {console.log(args.length)```
round bone
#

...args instead args

#

in function declaration

subtle cove
#

Imagine it's result like what getPlayers() returns

#

(origin, paramResult1, paramResult2, ...rest)

round bone
#

yeah

wise raft
#

OHHHH

#

thanks

north frigate
#

is there a way to ignite tnt

round bone
north frigate
stark kestrel
distant gulch
#

Why when i transfer a player to a server it says that is outdated

#

Even if i can join trough the server ui

round bone
#

wait, what's outdated?

#

client/server?

distant gulch
#

this show up

#

but if i join in the normal way

#

i can.

round bone
#

outdated client probably

distant gulch
#

i think its a problem in the script

#

yep it is

woven loom
#

Hmm

gaunt salmonBOT
buoyant canopy
#

is scripAPI 2.1.0 not released or is stirante not updated?

wary edge
visual zephyr
#

can i use localization in script api

#

like player.onScreenDisplay.setActionBar(some.text.iwant)

#

then on lang files
some.text.iwant=Some Text I want

sly valve
round bone
round bone
sly valve
round bone
sly valve
unreal cove
sly valve
#

No Problem?

gaunt salmonBOT
fervent topaz
#

when is jayly gonna update his stuff man :(

snow knoll
#

Question:
I'm using an animation that is only negative values of the regular player movement animations for walking and running to cancel the base ones and make a custom one play
Performance wise, is this a bad idea?

jagged gazelle
#

heyyo, I'm back guys...

snow knoll
jagged gazelle
#

Checking my about me answers that.

snow knoll
#

Ohh, you're the doppelganger

jagged gazelle
#

the Connections lol

snow knoll
#

Ohhhhhh, I thought the older account was the non-doppleganger

untold magnet
#

all i used is this:
world.afterEvents.playerSpawn.subscribe(({player}) => {const spawned = player?.getProperty('xcore:player_spawned'); if (spawned === false) player?.setProperty('xcore:player_spawned', true)});;

#

along with a tiny runInterval to detect whenever it gets true to do the console.warn and player?.setProperty('xcore:player_spawned', false);

#

requires modifying the player.json or spawning a custom entity and change its property

#

the property will never change until the world is fully loaded

livid elk
#

is there a way to control entity animations with something like molang, where i can change the values through a script?

halcyon phoenix
livid elk
#

for example, if i have something like y_sample in the scale part of entity animation, is there a way to control the value of y_sample using a script?

amber granite
#

Hello again:-: what s up ?

amber granite
#

What is new with script api ?

stark kestrel
livid elk
#

what's the difference between dynamicproperty and property?

halcyon phoenix
#

and properties are readable through molang whilst dynamic property can't be read by molang

halcyon phoenix
halcyon phoenix
#

it's useful but I gave up learning it

livid elk
#

thanks!

jagged gazelle
#

the amount of custom properties lol

inland merlin
#

is it just me, or does "setRotation" still have issues?

#

when spawning an entity in a direction/facing

#

seems like the beh files override this still

#

fyi, using my own custom entity

halcyon phoenix
#

he deleted it lol

halcyon phoenix
inland merlin
inland merlin
#

i just would totally convert it to a script lol, would be cool

inland merlin
# halcyon phoenix beh?

struggling with this, as i have an entity that is summoned right after its killed with stack -amount usually -1 amount

#

stacked entities an old pack i have, im tryn to solve issues its had for a while

#

visual for you

#

i have block spawners, and the issue is the stack of entities here, only spawn in one direction on being spawned in, so trying to inherit the old entity that died, head rotation/ body rotation

#

but it doesn't work in scripts it seems on spawn

halcyon phoenix
jagged gazelle
#

What's the issue again?

halcyon phoenix
inland merlin
#

summoning an entity, i think entity json overrides the script

#

it just spawns in one direction every time

#

not inherit previous entities

jagged gazelle
#

Counter it with runInterval....

inland merlin
jagged gazelle
#

Just for a one/two ticks

inland merlin
#

hmm, so instead of one attempt?

jagged gazelle
inland merlin
#

the issue i see is we "see" the rotating of the entity after it spawns

#

so it looks funky

#

i was hoping for a solution on "summon" spawn

#

without the animation of setRotation

#

it seems

#

i could be wrong

jagged gazelle
inland merlin
#

yeah, i think the json components are fighting scripts

#

ill probably have to check the components on spawn or something

inland merlin
#

would probably solve my issue

#

and some slight modification to the entity json

#

as they def clash

#

RIP

leaden elbow
#

since PlayerInventoryItemChangeAfterEvent has been added in 1.21.100, how can i detect if user crafted specific item?

leaden elbow
#

oh well

#

anyways

#

how can i use itemcomponentconsume

#

event

subtle cove
#

itemCompleteUse?

prisma shard
#

Damn wtf everyone is back at same time?

prisma shard
prisma shard
cinder shadow
# wary edge Crafting? You cannot.

I did ask this in the last Q&A we had with mojangsters and the one who responded said she had actually looked at it because she needed something like this and knows that that information is saved

#

hopefully that comes soon

prisma shard
rustic ermine
# wary edge Crafting? You cannot.

It's pretty flexible.. probably a way to do it. For example, can detect equipment by checking if the afterItemStack is undefined, then check if beforeStack has equippable component or against a Map of known equipment, then checking if equipment slot it goes in matches typeId, then apply custom stats etc. might be able to do similar with crafting

wary edge
rustic ermine
#

Hmm yeah

#

Wonder how expensive it is to even hook in to that event. Wouldn't imagine it being performant with a few players

wary edge
#

I would just wait for official support.

subtle cove
#

its like tracking the very existence of the item

halcyon phoenix
subtle cove
#

speaking of inventory, itemChange event triggers when player joins

#

only the slots with items

rustic ermine
#

Once 2.1 is stable, and tbh even currently it is pretty insane how much we can do now with some creative thinking. I was working on some of my java server plugins last night and just was not feeling it lol. Having attachables/blocks/entities natively and easy tooling goes so far. Never thought I'd admit I enjoy add-ons more than working with paper or forge.

sly valve
#

Good morning

subtle cove
#

await (11).hrs && 'gud am'

sly valve
subtle cove
#

try it

sly valve
#

What about the property hrs, i hope it returns a Promise

subtle cove
#

hrs property is undefined tho

rustic ermine
#

You all aren't defining global constant/alias for 11??

subtle cove
#

unless Number.prototype Β§k

sly valve
#

No, i define for each char one variable in a map, like ```js
chars.set("letter:a_lowercase", "a")

#

And with that I build Texts or messages

sly valve
rustic ermine
#

Just for loop over each string byte and try to build a function call out of patterns

subtle cove
sly valve
rustic ermine
#

I actually did have to do a while loop recently. Can't recall the last time I legitimately did one

sly valve
#

Lol

#

Last time I did a really cool system

function a() {
  a()
}

The tps limiter

#

Or server unloader

#

Really good if I want to quit the world

rustic ermine
#

To avoid stack overflow from recursion lol

sly valve
rustic ermine
#

Got an example for a better way? I have a habit of just getting things to work then doing maybe one optimize / strict type pass then calling it good lol.

sly valve
#

Or use

XP(n) = a Γ— n Γ— logβ‚‚(n + 1)
rustic ermine
#

Ahh true, if I remember right it was done that way specifically because it's hard to do it without recursion otherwise in my case. The old one looked much better but got a stack overflow if you gave the player more than like 5k XP lol

#

Now can just either give any amount of XP or set the level to anything and it just figures it out

sly valve
#

Alr

rustic ermine
#

Thank you for the example though, sometimes forget you can assign a type like that

jagged gazelle
subtle cove
jagged gazelle
rustic ermine
#

you get a beforeItemStack that represents the slot you clicked on, then afterItemStack to show what the slot you dropped the item on now is, or undefined if the item was dropped/consumed/equipped

#

takes some tinkering to see exactly how it works. I just did console.log(${event.beforeItemStack.typeId} -> ${event.afterItemStack.typeId ?? "Item Gone"}) and did a few basic tests to see what was going on

jagged gazelle
sly valve
#

Why is it soo hard for Microsoft to do something we want

jagged gazelle
#

-# ok I genuinely forgot Microsoft also handles Minecraft

sly valve
#

Like to prevent reading datas we should not read

jagged gazelle
#

I can't speak or say anything about it a lot but that's one of the main points of why it's not added YET.

sly valve
jagged gazelle
#
const hit = player?.dimension?.getBlockFromRay(head, dir, { maxDistance: dist });
const ray = hit ? null : player?.dimension?.getEntitiesFromRay(head, dir, { maxDistance: dist })?.[0];
const distance = hit ? null : ray?.distance ?? dist;
const target = hit 
  ? fixFaceLocation(hit.block?.location, hit.faceLocation, hit.face, 2)
  : Object.fromEntries(Object.entries(head)?.map(([axis, val]) => [axis, val + (dir?.[axis] ?? 0) * distance]));```


Damn, I like this format lol
jagged gazelle
# sly valve pretty

eurt... it's a lil bit redundant in my taste if I do this.js const target = hit ? fixFaceLocation(hit.block?.location, hit.faceLocation, hit.face, 2) : ray ? Object.fromEntries(Object.entries(head)?.map(([axis, val]) => [axis, val + (dir?.[axis] ?? 0) * ray.distance])) : Object.fromEntries(Object.entries(head)?.map(([axis, val]) => [axis, val + (dir?.[axis] ?? 0) * dist]));

#

anyways....

#

What you guys doing rn?

distant tulip
#

Uh, eating

sly valve
#

maybe training my Uma

jagged gazelle
sly valve
jagged gazelle
#

Let's do HTML here

sly valve
distant tulip
sly valve
# jagged gazelle Let's do HTML here
<!DOCTYPE html>
<html>
  <head>
    <script src="main.js"></script>
    <title>Counter</title>
    <style>
      body {
        background-color: rgb(47, 47, 47);
      }
      h1 {
        color: rgb(255, 230, 230);
      }
      p {
        color: white;
      }
    </style>
  </head>
  <body>
    <div>
      <h1>Counter</h1>
      <button id="counter_increment">Increment</button>
      <button id="counter_decrement">Decrement</button>
      <button id="counter_reset">Reset</button>
    </div>
    <br>
    <br>
    <div id="counter_output"></div>
  </body>
</html>

@jagged gazelle look at my first thingy I made

jagged gazelle
#

what does it do...

sly valve
sly valve
jagged gazelle
sly valve
jagged gazelle
#

Nothing I just asked lol

unreal cove
sly valve
gaunt salmonBOT
subtle cove
halcyon phoenix
#

in every way

subtle cove
#

Is it... bao_panda_insomniac

distant tulip
#

i like to watch

halcyon phoenix
distant tulip
#

in case someone need help

halcyon phoenix
halcyon phoenix
jagged gazelle
#

How to be happy and motivated again?

halcyon phoenix
#

that's how I get out of burn out

livid elk
#

is there a way to automatically run something when I change the slider value without having to confirm it?

subtle cove
#

Is it possible thru jayson yu-ai?

livid elk
#

im trying to change my entity variant using that slider

distant tulip
distant tulip
jagged gazelle
#

nope since server form is literally server side, you need to send it to server to confirm it.

jagged gazelle
#

that's why the loading animation of UI exists.

#

-# thanks you arx for explaining it to me way way back lol

livid elk
#

ahhh i see

#

is there something like itemUse that keeps running a command until i release right click?

halcyon phoenix
warm mason
#

or you can use a custom component + onUse + minecraft:cooldown, but I'm not sure if that will work now

wheat condor
#

is bundle component still in beta in 1.21.100?

untold magnet
stuck ibex
#

burn outs are inevitable

prisma shard
#

just do like

let array = [1,2,3];

array = [];``` 
idk what u mean
halcyon phoenix
stuck ibex
#

wym lose something?

#

ig thats person by person

sly valve
prisma shard
#

ye this also works

#

but for let

#

not const

warm mason
prisma shard
#

length property is modifiable

sly valve
#

Imagine this will cause memory leaks

warm mason
#

hmmm

subtle cove
#

hrmm

prisma shard
#

hurmmm

warm mason
#

it works...

sly valve
#

See

#

Lol

sly valve
#

Lol

subtle cove
sly valve
#

Oh !no

subtle cove
#

bugrock memory is weird

sly valve
#

Really?

#

Sigma is outdated

prisma shard
#

ok skibidi

halcyon phoenix
# stuck ibex wym lose something?

got burnt out once took a rest and probably too long of a rest, I forgot how script api works and it's like discovering new stuff I've learned

untold magnet
prisma shard
subtle cove
#

-# beware of ram m9 footprint

sly valve
prisma shard
#

this guy claims molang is a proper language now

subtle cove
#

more like random names starting with M

warm mason
prisma shard
#

idk

#

i mean like how will that help?

stuck ibex
#

like json ui -> ore

warm mason
prisma shard
#

imagine if we can do ore ui with html :>

#

wlel probably we cna in future

stuck ibex
#

i mean not necessarily simplified but like more readable

warm mason
#

like, why?

untold magnet
# subtle cove -# she

btw, system.runInterval without a world.getALlPlayers will cause input lag right?
even if it runs every 1s?

subtle cove
#

depends on what's done in the function there

untold magnet
#

just changing one dynamic property

#

nothing else

prisma shard
#

bru-

#

what does this have to do with world.getPlayers

untold magnet
#

just making sure it wont cause input lag

warm mason
untold magnet
#

anyways

warm mason
#

maybe you wanted to say slowing down scripts and as a result reducing TPS?

warm mason
sly valve
#

Just buffer online players instead of re-getting them

#

Add some to the buffer on join, remove when they leave

#

Ez

round bone
untold magnet
halcyon phoenix
halcyon phoenix
untold magnet
warm mason
round bone
#

it'll just return an empty array

#

filter's argument is a function that returns a boolean

warm mason
round bone
sly valve
#

Why...

#

You gotta add a proxy instead

sharp elbow
#

Ideally it should mutate the original array so that would not be necessary

subtle cove
#

oh boi

round bone
#

let's say, if we have a constant array, the best practise is to NOT modify it, just copy it and work with it's copy

sly valve
# warm mason ```js array.length = 0; ```

Thats useless overhead.
Use that:

function clearArrayRecursively(arr) {
  // Unnecessary helper function using closure and Promises
  function asyncClear(index) {
    return new Promise((resolve) => {
      setTimeout(() => {
        if (index >= arr.length) {
          resolve();
        } else {
          // pointless operation before removal
          arr[index] = undefined;
          arr.splice(index, 1); // actually remove element

          // Recursive call wrapped in Promise chain with closure
          resolve(asyncClear(index));
        }
      }, Math.random() * 10); // random delay for maximum overhead
    });
  }

  // Another pointless construct: a generator to verify the array is *really* empty
  function* confirmEmpty() {
    while (arr.length > 0) {
      yield false;
    }
    yield true;
  }

  // Begin the nonsense
  asyncClear(0).then(() => {
    const checker = confirmEmpty();
    let result = checker.next();
    while (!result.value) {
      console.log("Waiting... array is still not empty enough.");
      result = checker.next();
    }
    console.log("Array has been cleared... somehow.");
  });
}

// Example usage:
const myArray = [1, 2, 3, 4, 5];
clearArrayRecursively(myArray);
sharp elbow
warm mason
round bone
sly valve
# untold magnet `const titles = [];`

Do

function clearArrayRecursively(arr) {
  // Unnecessary helper function using closure and Promises
  function asyncClear(index) {
    return new Promise((resolve) => {
      setTimeout(() => {
        if (index >= arr.length) {
          resolve();
        } else {
          // pointless operation before removal
          arr[index] = undefined;
          arr.splice(index, 1); // actually remove element

          // Recursive call wrapped in Promise chain with closure
          resolve(asyncClear(index));
        }
      }, Math.random() * 10); // random delay for maximum overhead
    });
  }

  // Another pointless construct: a generator to verify the array is *really* empty
  function* confirmEmpty() {
    while (arr.length > 0) {
      yield false;
    }
    yield true;
  }

  // Begin the nonsense
  asyncClear(0).then(() => {
    const checker = confirmEmpty();
    let result = checker.next();
    while (!result.value) {
      console.log("Waiting... array is still not empty enough.");
      result = checker.next();
    }
    console.log("Array has been cleared... somehow.");
  });
}

// Example usage:
const myArray = [1, 2, 3, 4, 5];
clearArrayRecursively(myArray);
sharp elbow
#

If setting length to 0 works, I'd do that.

warm mason
round bone
#

length is also most efficient

untold magnet
warm mason
round bone
#

his code, his rights I think

sharp elbow
#

It's better if you need the results of the array. splice shifts elements around, and it returns the deleted results; if you intend to immediately discard those results, this isn't very useful

sharp elbow
#

It's a concern about code readability more than anything.

warm mason
round bone
#

I will allow him, beacuse he is a future competitior on job market

warm mason
#

.-.

subtle cove
#

the code structure is applicable in python, if i might add

untold magnet
sly valve
round bone
#

also if I can spread missinformation here, PHP is the most valuable language for next years

untold magnet
round bone
#

and PocketMine-MP is the best software for survival servers

sly valve
warm mason
round bone
subtle cove
#

in setLore, .length is also called in mc

prisma shard
#

nah this chanel makes a simple thing too complicated

sly valve
untold magnet
sly valve
sly valve
round bone
#

are we roasting him beacuse he is using a bit worse solution or we have moved onto another topic?

sly valve
#

Dont be stupid

prisma shard
#

switch topic bruh

sly valve
#

Be smrt

halcyon phoenix
#

this array stuff has gone out of hand

untold magnet
sly valve
warm mason
round bone
#
const optimizationTrick = new ArrayBuffer(2_000_000_000_000)
#

use this

warm mason
sly valve
prisma shard
round bone
round bone
#

a small 2TB in this case

sly valve
#

Small

warm mason
#

-# small

subtle cove
#

oh my poor brain cell

prisma shard
#

oh πŸ’€

warm mason
round bone
#

Discord needs a lot of memory, so we need too
-# It's not beacuse they use ScyllaDB - fast (and fat-memory) database

halcyon phoenix
#

this is the most geeked out conversation I have seen in this thread

sly valve
halcyon phoenix
round bone
sly valve
prisma shard
#
 const a = [];
  while (true) {
    a.push(new Uint8Array(1000000)); 
}```
halcyon phoenix
#

clear an array? delete the .js file that contains the array

prisma shard
#

nice

sly valve
#

Or just remove system32, clears up useless garbage

round bone
#

😱

warm mason
halcyon phoenix
halcyon phoenix
prisma shard
#

not again ts vs js 😭

#

get a job

round bone
#

Java is a solid language

halcyon phoenix
noble ibex
#

Is there any way to construct an itemStack that contains item data? Like if I were trying to construct a potion item to give to the player?

warm mason
halcyon phoenix
round bone
warm mason
prisma shard
round bone
#

but tbh I still like Java, strongly OOP language

round bone
#

but I am not sure

noble ibex
#

youre so right thank you

halcyon phoenix
round bone
noble ibex
round bone
#

check in a changelog

noble ibex
#

Where can I find the patch notes?

warm mason
prisma shard
#

you flash my screen like discord white theme 😭

round bone
#

I have Discord open on my MacBook screen, so it's not that big

#

πŸ˜ƒ

noble ibex
#

So I take it theres no way to construct tipped arrows or other items that require data? Unless those just use identifiers and Im an idiot.

round bone
#

it's a but nire wirj

subtle cove
#

unless runcommand, container.getItem, list.push(item)

noble ibex
#

That's crazy roundabout for a billion dollar corporation.

halcyon phoenix
#

when will equippable be a component for entities...

jagged gazelle
prisma shard
#

And when entityHurtBeforeEvent..

jagged gazelle
prisma shard
floral timber
#

lets just kill this guy... whistle.

jagged gazelle
floral timber
#

sir, do us a favor, will ya?

jagged gazelle
subtle cove
#

block.getComponents() when

halcyon phoenix
halcyon phoenix
#

he got 9 lives

floral timber
#

he can atleast use 1 for the greater good of humanity, no?

jagged gazelle
warm mason
jagged gazelle
#

why WOULD I do it for them?

floral timber
#

im sorry, philosophy aint my territory lol.

jagged gazelle
#

I'm saving the remaining ones for breeding component

#

-# pls ffs add it already...

#

the yawning is lowkey annoying, I feel like you're mocking someone.

halcyon phoenix
warm mason
halcyon phoenix
prisma shard
#

I am making my duck entity. I tried a lot but finally came to that, making the entity swim isn't possible with Behaviour JSON.
so i think i'd try to applyImpulse to make it swim. But I have no ideas about the knockback value.. Can anyone help? I want to make it realistically swim, so will I really have to create whole pathfinding AI for it ;-; bruh

sharp elbow
#

How are you wanting it to swim? There may be some nebulous combination of behaviors for that

prisma shard
#

uh

#

Like a duck?

#

xD

sharp elbow
#

Floats on top of the water?

prisma shard
#

Yeah yea

#

I made it float using behaviour JSON. but just need to apply the knockback to make it swim using scripts.

sharp elbow
#

I would try a navigation component with "can_path_over_water": true combined with the buoyant component; the latter is finicky to get right though

prisma shard
#

I'm not really good with entities behaviour ;-;

#

aw

loud brook
#

Is it possible to slow down a player without affecting its FOV with script?

livid elk
#

is there a way to reduce damage from entity attack? like extra armor effect

wary edge
loud brook
wary edge
#

No.

loud brook
#

Damn it

subtle cove
inland merlin
unreal cove
subtle cove
inland merlin
#

Awh yes

subtle cove
#

tho Im not sure of when it dies

inland merlin
#

Ill look into that ty

inland merlin
# subtle cove tho Im not sure of when it dies

Probably make the custom entity unkillable, and then just lower the nameTag value on calculated entities max health reset the health or whatever, and then spawn a simialr entity and kill it for the animation, or simulate a death animation

#

Def alot of extra work on the side, but sounds like it may just work.

prisma shard
#

uh I just checked I already have the component

untold magnet
wary edge
untold magnet
wary edge
wary edge
untold magnet
#

i see, im just trying to give him a little hope, and now the hope is gone

#

lol

untold magnet
midnight crane
#

Can someone send me the script to make it so when you hit an entity with an item the entity that is hit runs a command

distant tulip
sly valve
warm mason
loud brook
sly valve
distant tulip
sly valve
loud brook
#

beta...

#

I think I will leave addon developing until the beta un-beta its betaness to be non-beta (if that makes sense)

sly valve
#

@warm mason hey~
may you HELP ME OUT RQ?

wary edge
midnight crane
loud brook
distant tulip
sly valve
# warm mason ?

If I have something globally installed like a NPM or git.
Can I use them in a script and they will work? or do I need to move the files into my src/

warm mason
distant tulip
sly valve
sly valve
#

if I have a folder via git

distant tulip
#

whats cjs

#

common js?

loud brook
distant tulip
# sly valve yes

as long as they use what quickjs uses and as long as they are inside your addon

sly valve
sly valve
distant tulip
#

bp/scripts/...

midnight crane
sly valve
distant tulip
# midnight crane Can you make it so the command runs if you hit an entity with a specific weapon
import { world, EquipmentSlot } from "@minecraft/server";

world.afterEvents.entityHitEntity.subscribe((event) => {
  const { damagingEntity, hitEntity } = event;
  if (damagingEntity.typeId !== "minecraft:player") return;
  const heldItem = damagingEntity.getComponent("equippable").getEquipment(EquipmentSlot.Mainhand);
  if (!heldItem || heldItem.typeId !== "minecraft:stick") return;
  hitEntity.runCommand(`say I was hit with a stick by ${damagingEntity.name}`);
});
sly valve
distant tulip
distant tulip
sly valve
#

still thanks Minato

distant tulip
#

np, didn't do much

sly valve
cinder shadow
#

why are we using runCommandAsync to say a message

distant tulip
#

you are seeing things

cinder shadow
#

why are we using runCommand

sly valve
cinder shadow
#

does sendMessage no longer exist?

sly valve
#

caught

distant tulip
#

ah shit

distant gulch
#

Lmao

loud brook
cinder shadow
#

I didn't say anything little baby

distant tulip
#

lol

sly valve
cinder shadow
#

all these zygotes yapping in my ear

sly valve
#

that one Koala is still eating his children..

distant tulip
#

what

#

delete that and i will hack mojang and release chatSend

sly valve
#

is gone

#

like my dad

distant tulip
#

Time to learn HTML
it is great for hacking

#

i can just inspect the changelog and BOOM, released chatSend to 2.0.2

midnight crane
dusky flicker
distant tulip
#

yeah, it is great programing language

full idol
#

Through the scripting API, can I make my custom minecart object act like a minecart? I mean, sure, it's probably possible to detect rails and stuff, but more easily I mean. I'm currently using a real minecart to just teleport and rotate with, however you can't make minecarts invisible so I'm having issues

snow jungle
#

[2025-08-07 17:22:09:218 ERROR] [Scripting] Plugin [Server Addon - 1.0.0] - [index.js] could not load main.

Anyone see this error before?

#

Even with a empty file it still shows up

sly valve
sly valve
snow jungle
#

No

#

It is not

#

There is no file with the name main.js

sly valve
snow jungle
#

I have already tried with just a console.log

sly valve
#

Hmm

#

That is pretty weird

#

Pretty pretty weird

sly valve
#

CO SOLE

#

console****

#

I hate phone keyboard..

sly valve
snow jungle
sly valve
distant tulip
sly valve
#

...

sly valve
snow jungle
#

guns.lol in the bio, this guy isnt even worth arguing with

sly valve
sly valve
snow jungle
#

"this guy isnt even worth arguing with" πŸ‘

sly valve
#

Now I see..

#

My bad

round bone
#

a simple portal for creating linktrees

round bone
sly valve
sly valve
round bone
#

I am using similar thing for my server

sly valve
#

Thats cool.
I want to be as good as you are

round bone
sly valve
#

Its just the thing I do to forget

round bone
#

and you learn JavaScript in this time

#

😭

sly valve
#

Not really learning it actively

#

Just writing

#

I done really learn anything

sly valve
round bone
round bone
#

I have learned a lot by just writing a code

sly valve
#

Im doing a World Edit atm.
I will learn alot

round bone
#

I was learning back in 2021-2022 much more

sly valve
#

I see

round bone
#

I see a connection in my life

#

The more I know how to code, the life gets worse

sly valve
#

Haha, stop coding

#

Dont destroy your live

#

You only have one
Afaik

north rapids
#

Is there any way to detect if a chest is a double chest? Something like which side is connected?

dusky flicker
dusky flicker
#

if you spend an hour per day to simply do calisthenics

#

you will notice things get better