#Script API General
1 messages Β· Page 104 of 1
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 >_>
is java faster than c++/js ?
π«‘
C++ is a bit faster than Java (<5%)
Java and C++ are much faster than JS
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..
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
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
Why can java cancel player attack but bedrock can not?
Benchmarks show larger difference than that
now, how am i gonna use this brokenBlockPermutation? since i was expecting block.typeId.includes/startsWith()π
I often avoid using java solely becuase of how slow it is, C++ mops the floor with it and there's no comparison
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)
benchmarks posted on the common sites don't show the whole picture though, because often the 'faster' one is hyper-optimized and not something the average person would know how to do
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
tbh questions like this require much more context
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
brokenBlockPermutation have no property named typeId
also it's easier to use multithreading in Java, it really depeds on skills and context (of an application, software etc.)
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
it really depends on code quality, software type etc.
C++ might be faster, but Java fits better for some things
Java is not that slow to avoid it
you must be talking about extreme cases where is might be actually much slower
i want to solved duplicated bug, but why this not accurated
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}`)
})
})
}
})
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}
man hell no
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
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
that is actually not true, in general people tend to get languages that have a good support for something instead of it being fast
at least when talking about work
like, i saw a benchmark of backend libs
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
man spring boot was at 99
only 13k req per second, while some in rust and C had 68k
13k per second is still an absolutely insane point to reach
i code in rust but i dont understand the community im in actually
i really dont know why people tend to be like that
start using Fastify with clustering
π₯
fastify is still slower, slower than elysia by the way
Elysia is really fast, but it's only for Bun
Bun is not as stable as Fastify with Node.js
isnt bun node compatible?
i thought it would work on node as well
how do I search properly for the player class?
Is it possible tho change camera posistion using scripts
yeah
Player...
Documentation for @minecraft/server
nope it ain't showing
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
W
im using Jaylys
im using stirante
known player properties
like InputInfo or getPlayers (then click player[])
Installation for @minecraft/server
Latest API module install:
npm i @minecraft/[email protected]
Beta API module install:
npm i @minecraft/[email protected]
Preview API module install:
npm i @minecraft/[email protected]
Preview Beta API module install:
npm i @minecraft/[email protected]
sorry but I do not understand
oh
you mean I search for methods/properties that returns the player class
yeah
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>
When is beforeEvents.entityHitEntity coming bruh π
ask @warm drum
._.
everybody's waiting for it
it would be a blessing it would come
it's like waiting for gta 6
I made my own beforeEvent, but dude, the knockback kills me
could u please stop pinging me
its annoying
well technically, you are the script api
so thats why he pings you :>
i mean yeah, you chose to call yourself that.. expect to be pinged
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);
}
);
});
victim.name always returns undefined
victim is an Array.
registerCommand(
customCommand: CustomCommand,
callback: (
origin: CustomCommandOrigin,
...args: any[],
) => undefined | CustomCommandResult,
): void```
same thing
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
Cool. What's the tech?
its more like victims so do victims[0]
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
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);
}
);
});```
Oh damn, that simple? That's cool, thanks for sharing
np, i love finding solution for the impossible things lol
im trying to make like daily reward system, is there a way to detect real world time?
I believe you need BDS for that
bds?
bedrock dedicated server
ahhh
there's a few here that knows those stuff
Using Date should be enuf for that use-case
wait you can get date through system?
Mhm
It can't be localized on other locations tho, like the toLocaleString on client's side won't work accurately
Not possible for now
Tho the dm usage for PlayerSelector already behaves like "player name", @r
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
Is 2.1.0 newest stable for 1.21.100?
Yes
is it still not possible to update the player attributes using a script? only by using component groups for now?
Installation for @minecraft/server
Latest API module install:
npm i @minecraft/[email protected]
Beta API module install:
npm i @minecraft/[email protected]
Preview API module install:
npm i @minecraft/[email protected]
Preview Beta API module install:
npm i @minecraft/[email protected]
Can someone send me the example of the code where if you have a potion effect a command happens
Look in the docs. There is an before or after event is a effect got add
Yes, check docs
I swear I just checked them how did I miss it π
it doesnt work for entities right?
I am not sure, spawn a cow and remove it's permissions via command
only players
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
what is the api of the last version
2.1.0
thx
np
Is it a bug that you can't run a command as operator on a dedicated server when the permissionLevel is set to Admin?
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?
Push, pop, shift and unshift methods
thanks, now i understand wtf is .pop used for
Exclusively one, so no for now
But that use case already works like @r "Player name"
I'll have shards, and I would like to have a feature to send a message to player between BDS instances
That's why I would like to provide Player (for faster typing) type, but also a string for sending messages across instances
wait, is it possible to remove a specific item from the array or only the first or the last one?
Array.splice(index of the item you want to remove, 1)
Yes
what about changing the value of an item inside the array?
like instead of removing the previous one and add an updated one?
If you know it's index, just override it:
someArray[index] = "some value"
-# explain
someone knwo how to get this default texture?
yep split the message by space and get the parts
I know how arguments work, I was curious if you can use 2 types as a 1 argument
Find it in bedrock-samples
Are you talking about a certain item, or in-generalM
like where the title thing is saved at? (1 or 2 etc)
just an array to save some titles and keep updating all of them
Index is the place where title thing is saved
Like index 0 is 1st element, index 1 is 2nd element etc.
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'?
Yes, or you can make a function to find some title's index first, then simply update it by their index
like searching inside the index for a specific title and get its index value to update it?
Yes
show me an example, that will save me alot of time
const updateTitle = (oldTitle, newTitle) => {
const index = titles.findIndex((title) => title === oldTitle)
if (index !== -1) titles[index] = newTitle
}
good but, will i be able to update multiple titles at the same time?
like i can just use this function 3 times to search for 3 titles and update them
Call function 3 times
each time with another title
/**
* @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
well, i dont want to use any loops on this addon,
- it looks too complicated for my brain to process
Then use my first function, but for loops are easy and good-to-know - you should learn them
Interesting, thanks
but wait, how am i going to update the updated one? like making the oldTitle detects any item inside the array that starts with a specific text
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
Need to set the molang first and then spawn the particle with the molang.
Like this?
a way to make the throw system better?
nvm i did it
It's 2 AM for me, I am barely awake xD
2.2.0-beta
danke
physics
works, you just can only run commands that are enabled without cheats
actually i tried it with commands that require cheats and still works
wait, really?
yeah
but I believe they are fixing it
minecrafts gonna patch that
v1.21.100 scriptapi docs are out btw if you use my docs. Seems like mslearn hasn't updated yet (hence the 6hr delay)
what's the current stable version?
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 :/
run a tickingarea there
tickingarea that location you want to teleport then getblock or do what you want with it
Oooh sounds interesting, Iβll try that
Thanks!!!
Where's 2.1.0 for 1.21.100?
In documentation or in npmjs registry?
The registry
I can't seem to find it
Contains many types related to manipulating a Minecraft world, including entities, blocks, dimensions, and more.. Latest version: 2.0.0, last published: 2 months ago. Start using @minecraft/server in your project by running npm i @minecraft/server. There are 74 other projects in the npm registry using @minecraft/server.
Use this version atm
npm i @minecraft/[email protected]
docs:https://jaylydev.github.io/scriptapi-docs/latest/modules/_minecraft_server.html
if i used ticking area in the nether while im in the overworld can I get info on that specific area using script api
yes
is there a limit for a ticking area
yeah
ohh nice
10 ticking areas per world/dimension
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?
getViewDirection
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
isn't it supposed to be getblockviewfromdirection?
getBlockFromRay is also a thing π€·
I see
i mean that also exists
But actually i'm not getting the block
I am trying to perform raycast
And get the air infront 3 blocks
I havne't used getBlockFromRay so I have no idea what's going on
One thing I don't quite like about custom commands is that they don't allow you to use localization keys
OMG i've been finding for so long but can anyone get the coddy's post which he showed a fix for hitLocation π
pretty sad, you have to stick with constant description
I hope they update it soon!
it's here
filter the search to coddy's
bruh i feel i will be crazy cause Faction Systemπ₯
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
Use
getViewDirection add it to your head location and you get coords 1 block Infront of you
That does the same thing, just so you know
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"
okay so the maxDistance parameter in Blockraycast options is kinda very buggy
Serty, do you have any solutions?
Increase it by a couple of units... because as I understand it, some "other" distance is calculated there, which is somewhat less than expected
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
And then check the distance manually
uhh I dont understand, can you look at my script a bit
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
in the latest stable it says that they somehow fixed hitLocation... so I need to download it and check how it will work there... and I will not deal with this on lower versions because why?
How long has Block.canPlace been around?...
what the-
I cant find the changelogs
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
I assume it's referring to .amount = 1
π
-# cant let ai know bout these just yet
it hasn't released on npm yet
Ah
whats the latest mc version?
:/
Where did you see that? I am comparing latest beta, Can't find anything.
Nothing related Blockraycast Options
hmm, my launcher doesnt have "update" button yet. im at v1.21.93 atm
@subtle cove By any chance, Do you know why this is happening?
mc store has an update btw
u mean ms store
dunno, wdym "buggy"
bruh
I am trying to spawn particle but when I add the maxDistance in raycast options, The particle doesn't spawn, If i look close
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
I got a quadrillion errors and not one about which versions to use...
you forgot about the existence of multiplayer, BDS and Realms
ohh
what's new on the api for 1.21.100? for some reason i can't access the changelog website.
anyways, how am i going to see if the titles array has a specific title or not?
like if the array diesnt have the title 'test0' it will do something,
const hasTitle = (title) => {
return titles.find((iterator) => iterator === title)
}
idk if this would even make any diff
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);
another function?
if (!hasTitle) {smth}?
yeah i see
you can use a class with static methods to group them together
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)
Have you tried using getBlockFromRay with water? The faceLocation can return absolute coordinates sometimes
uhm still a relative location to the block's idk which edge
item.getRawLore() wew
well, one last thing, removing the title from the array if it was there
const removeTitle = (title) => {
return titles.filter((iterator) => iterator !== title)
}
you have to re-declare titles array then
like re-position other titles?
const newTitles = removeTitles("some-title")
ill pause working on the script for now and start remaking the hydration ui
Why is args.length = 1 even tough I have two arguments? (Custom Commands)
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)```
Imagine it's result like what getPlayers() returns
(origin, paramResult1, paramResult2, ...rest)
yeah
is there a way to ignite tnt
you can spawn a TNT and replace block with an air
hmm that's actually a good idea
erm is someone free? If yes, can u check my post, had to ask here, been like 2 days since no replies https://discord.com/channels/523663022053392405/1401976111771947088
Why when i transfer a player to a server it says that is outdated
Even if i can join trough the server ui
you have to update your BDS server
wait, what's outdated?
client/server?
outdated client probably
Hmm
Installation for @minecraft/server
Latest API module install:
npm i @minecraft/[email protected]
Beta API module install:
npm i @minecraft/[email protected]
Preview API module install:
npm i @minecraft/[email protected]
Preview Beta API module install:
npm i @minecraft/[email protected]
Installation for @minecraft/server-ui
Latest API module install:
npm i @minecraft/[email protected]
Beta API module install:
npm i @minecraft/[email protected]
Preview API module install:
npm i @minecraft/[email protected]
Preview Beta API module install:
npm i @minecraft/[email protected]
Installation for @minecraft/server-gametest
Beta API module install:
npm i @minecraft/[email protected]
Preview Beta API module install:
npm i @minecraft/[email protected]
is scripAPI 2.1.0 not released or is stirante not updated?
It just released today.
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
Afaik you gotta use rawtext to do that.
Use RawMessage interface
It's called RawMessage
Mb
No problem, just a minor mistake
My life might be a major ond
np
No Problem?
Installation for @minecraft/server
Latest API module install:
npm i @minecraft/[email protected]
Beta API module install:
npm i @minecraft/[email protected]
Preview API module install:
npm i @minecraft/[email protected]
Preview Beta API module install:
npm i @minecraft/[email protected]
when is jayly gonna update his stuff man :(
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?
heyyo, I'm back guys...
Are you the real coddy or the doppelganger
Checking my about me answers that.
Ohh, you're the doppelganger
Ohhhhhh, I thought the older account was the non-doppleganger
as u can see here
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
is there a way to control entity animations with something like molang, where i can change the values through a script?
like detect something and then play that animation?
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?
Hello again:-: what s up ?
Entity properties.
What is new with script api ?
hi kiro
what's the difference between dynamicproperty and property?
property is inside the entity.json whilst dynamic property is in scripts
and properties are readable through molang whilst dynamic property can't be read by molang
you mean, you have a variable inside the animation for example a variable for scale and you want to control that variable?
yeah
ahh i see
yeah molangs do that I don't know how though but in FMBE they do that to scale and rotate stuff
it's useful but I gave up learning it
thanks!
the amount of custom properties lol
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
he deleted it lol
beh?
behavior pack entity json files
i did lol, they do have dynamic methods which is cool
i just would totally convert it to a script lol, would be cool
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
yeah I tried too but it's too tedious
What's the issue again?
when spawning an entity in a direction/facing
seems like the beh files override this still
setRotation/head rotation isn't working on spawn
summoning an entity, i think entity json overrides the script
it just spawns in one direction every time
not inherit previous entities
Counter it with runInterval....
can you explain more what you mean
Just for a one/two ticks
hmm, so instead of one attempt?
yeah...
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
I don't think you really can do anything about it...
yeah, i think the json components are fighting scripts
ill probably have to check the components on spawn or something
just need that "entitySpawn" before event
would probably solve my issue
and some slight modification to the entity json
as they def clash
RIP
since PlayerInventoryItemChangeAfterEvent has been added in 1.21.100, how can i detect if user crafted specific item?
Crafting? You cannot.
itemCompleteUse?
Damn wtf everyone is back at same time?
We got sugger back
Coddy comes again
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
And also kiro is back
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
The issue is that you can drop things into players inventory so its hard to figure out crafting.
Hmm yeah
Wonder how expensive it is to even hook in to that event. Wouldn't imagine it being performant with a few players
I would just wait for official support.
its like tracking the very existence of the item
it's probably like a runInterval that's scanning every single player inventory and comparing it
speaking of inventory, itemChange event triggers when player joins
only the slots with items
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.
Good morning
await (11).hrs && 'gud am'
Sir, ya forgot the console.log
And (11) is not a valid function call
try it
What about the property hrs, i hope it returns a Promise
hrs property is undefined tho
You all aren't defining global constant/alias for 11??
unless Number.prototype Β§k
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
Best way to do it tbh
Ik ik
Just for loop over each string byte and try to build a function call out of patterns
why log when u can let it run in the void π
I often use while (true) loops for perfomance
I actually did have to do a while loop recently. Can't recall the last time I legitimately did one
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
Why not using formulas, so you would not need any loops
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.
Example 1.
total_xp = start_xp**level
Or use
XP(n) = a Γ n Γ logβ(n + 1)
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
Alr
Thank you for the example though, sometimes forget you can assign a type like that
I find it a win-win to me.
Been thinking if I sould post kinda inventory manager in script-res with it
Regarding to itemStack, can you compare items now at least it still no?
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
Thanks for that but I've known that since BETA release, what I mean by compare is literally compare them like how you compare a native JSON object.
Will we aever be able to read json files.. i mean just like
const json = JSONReader.read("PATH TO JSON FILE")
// will throw error if file is out of bounds or not a .json
Why is it soo hard for Microsoft to do something we want
someone discussed this a long time ago and one of it is privacy...
-# ok I genuinely forgot Microsoft also handles Minecraft
Privacy? wdym
Like to prevent reading datas we should not read
Like accessing json files outside of behavior packs BLA BLA BLA...
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.
lol it isnt that hard to make it safe
async function JSONReader(relativePath: string): Promise<Object> {
if (OutOfBounds(relativePath)) throw new PathError(...);
// idk something to check if its a vlaid path
}
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
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?
Uh, eating
Nothing, thinking, and nothing
maybe training my Uma
wtf, you showed up randomly bruh
He was stalking us
Let's do something inappropriate...
Let's do HTML here
Yeah? tell me...
i am watching
<!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
It's a bit weird to register script on top but okay...
what does it do...
Was my first time
Catgirl counter
rlly??
Yes, why?
Nothing I just asked lol
interesting
It is
Installation for @minecraft/server
Latest API module install:
npm i @minecraft/[email protected]
Beta API module install:
npm i @minecraft/[email protected]
Preview API module install:
npm i @minecraft/[email protected]
Preview Beta API module install:
npm i @minecraft/[email protected]
Other than isStackableWith & components/lore/properties compare, who knows
Is it... 
i like to watch
does it get you off?
in case someone need help

understandable
I need help.
How to be happy and motivated again?
find your interests
that's how I get out of burn out
is there a way to automatically run something when I change the slider value without having to confirm it?
no
why though?
Is it possible thru jayson yu-ai?
im trying to change my entity variant using that slider
do something that you love doing, if you are burnt out from it take a break and do some random shit, join some old servers you used to talk in, take a walk outside and that sorta of thing
no
nope since server form is literally server side, you need to send it to server to confirm it.
^
that's why the loading animation of UI exists.
-# thanks you arx for explaining it to me way way back lol
ahhh i see
is there something like itemUse that keeps running a command until i release right click?
I loathe datshi
you can use itemStartUse and itemReleaseUse, thus starting and stopping the interval, but you need a component that helps "long use" of the item, like "food" or "throwable"
or you can use a custom component + onUse + minecraft:cooldown, but I'm not sure if that will work now
is bundle component still in beta in 1.21.100?
yao uh, what should i use to remove all titles from the array?
dont encourage that tbh, self motivation is a skill that a person needs to learn eventually
burn outs are inevitable
you mean clear the array?
just do like
let array = [1,2,3];
array = [];```
idk what u mean
yeah I know but if you don't prevent that you might lose something, that's why I motivate my self via interests, hobbies or interaction.
I have heard this works
array.length = 0
looks like it shouldn't work
Imagine this will cause memory leaks
hmmm
hrmm
hurmmm
it works...
Lol
oh yesnt
Oh !no
bugrock memory is weird
ok skibidi
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
yes it works
brr brr patapim
-# beware of ram m9 footprint
M9 is outdated, M14 is in
more like random names starting with M
-# she
and what's the point?
why molang in scripts?
i mean not necessarily simplified but like more readable
it's like
const script = "console.log(1 + 1)";
eval(script);
like, why?
btw, system.runInterval without a world.getALlPlayers will cause input lag right?
even if it runs every 1s?
????
what?
depends on what's done in the function there
just making sure it wont cause input lag

calling the world.getPlayers every tick will cause input lag
afaik*
anyways
what is the input lag? Input of what?
maybe you wanted to say slowing down scripts and as a result reducing TPS?
well, any script does this
Just buffer online players instead of re-getting them
Add some to the buffer on join, remove when they leave
Ez
titles.length = 0
// OR
titles.splice(0, titles.length)
// OR
titles.filter(() => false)
// OR
while (titles.length > 0) titles.pop()
thats what im doing in only one addon, all of the other addons wont have any intervals
whre is that LOL
MolangParser....
titles.splice(0, titles.lenght) looks good for me
the first two sound like the most effective but the third one won't work
why it won't work?
it'll just return an empty array
filter's argument is a function that returns a boolean
Why ;-;
because Array.filter returns a new array and does NOT touch the current one
oh, then you can assign result to a new variable
Ideally it should mutate the original array so that would not be necessary
oh boi
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
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);
For a tuple, sure. Though I'm assuming t17x is using an array just to hold data, not unlike a record or map
let array = []; // no, too easy
let array = new Array(99999).fill(123).filter(n => false); // maybe still too easy
he is using a global array
const titles = [];
I am not talking about cases like this
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);
If setting length to 0 works, I'd do that.
then just do titles.length = 0 if you want to clear the array
length is also most efficient
ill use titles.splice(0, titles.length); just bec it looks good
not so effective, but ok
his code, his rights I think
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
We wont allow you
It's a concern about code readability more than anything.
@sharp elbow @round bone β€οΈ
I will allow him, beacuse he is a future competitior on job market
.-.
the code structure is applicable in python, if i might add
-# none can stop me
-# dont be so sure
also if I can spread missinformation here, PHP is the most valuable language for next years
try
and PocketMine-MP is the best software for survival servers
π fr
:(
-# || the splice method gives 0.0002 ms more slowdown ||
remember that it calls .length also
in setLore, .length is also called in mc
nah this chanel makes a simple thing too complicated
.length still more gooddddd
yeah i like slowing down the game by 0.0002%
Says the right one
Too much.
Imagine everyone would do this.
are we roasting him beacuse he is using a bit worse solution or we have moved onto another topic?
Dont be stupid
switch topic bruh
Be smrt
this array stuff has gone out of hand
we doin swinggs of moods
if u really love array.length = 0, then just use it on ur own scripts
I hope your script Crashes
no, in my scripts I only use #1067535608660107284 message
better than .length = 0
you forgot anti in the variable name
What does array buffer do?
interesting what is this?
you need to get some memory for yourself
Small
-# small
oh my poor brain cell
oh π
BIG
Discord needs a lot of memory, so we need too
-# It's not beacuse they use ScyllaDB - fast (and fat-memory) database
this is the most geeked out conversation I have seen in this thread
Like my not existing best piece
optimize discord too
clear an array using array = []? no way use this instead
a bit slower + his array is constant
A small Bit
const a = [];
while (true) {
a.push(new Uint8Array(1000000));
}```
clear an array? delete the .js file that contains the array
Even better
nice
Or just remove system32, clears up useless garbage
just switch to JVM languages at this point
π±
needs to be moved to #1067535712372654091
can't wait for april again just to post this. LMAO
java is in 8 BILLION DEVICES!!! why are you not using it?
I also like it
Java is a solid language
I really love this line while installing Java
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?
NO
that's why it is 8 billion devices
larger companies are still using Java, beacuse their entire codebase is written in it
you can make a potion but you can't set the data
k guys pls quit shit cuz ppl wanting for help the msg is getting flooded
but tbh I still like Java, strongly OOP language
How?
ItemStack.createPotion
but I am not sure
youre so right thank you
yeah it's incredibly reliable somehow
but this has changed for latest preview, so be aware of updating it again
https://discord.com/channels/523663022053392405/1365770249835909272
we can using dis
Did they add data support in the preview?
check in a changelog
no
Where can I find the patch notes?
you flash my screen like discord white theme π
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.
you can use structures or create an entity with inventory, add those items there and just manage it
it's a but nire wirj
unless runcommand, container.getItem, list.push(item)
That's crazy roundabout for a billion dollar corporation.
when will equippable be a component for entities...
When I die.
And when entityHurtBeforeEvent..
skill issue.
when I'm reborn.
hmph. you believe in reborn?
lets just kill this guy... whistle.
No.
sir, do us a favor, will ya?
I'm not going to.
block.getComponents() when
let's ask @warm drum
he can atleast use 1 for the greater good of humanity, no?
when you die
one already spent on Player.applyImpulse
what did the humankind did for me? Nothing right?
why WOULD I do it for them?
im sorry, philosophy aint my territory lol.
another one is spent on custom commands.
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.
and that thing isn't even worth cause of rubberbanding
in 1.21.100 it works quite well
ima try and do some kinematics with it
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
How are you wanting it to swim? There may be some nebulous combination of behaviors for that
Floats on top of the water?
Yeah yea
I made it float using behaviour JSON. but just need to apply the knockback to make it swim using scripts.
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
Is it possible to slow down a player without affecting its FOV with script?
is there a way to reduce damage from entity attack? like extra armor effect
You can tell people to disable that option in thesettings.
Can I disable it through script?
No.
Damn it
ever tried minecraft:transform yet?
Can u explain how this might work for the rotation?
you could just apply a camera set_fov command/api to counter the fov from that movement maybe?
the transform event looks like it retains the previous target
Awh yes
tho Im not sure of when it dies
Ill look into that ty
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.
uh I just checked I already have the component
i dont see this ever comes out, can u get the blocks component on java? if u can then there is a hope,
What does Java have to do with anything?
we are keep getting features from java to bedrock, so thats why i mentioned java there
I mean there is a workaround but yeah that would be consistent.
Thats for gameplay. Technical parity is never the goal.
btw, can the entityLoad component detects when the world is fully loaded? like detecting the player entity when it gets loaded or it only works for other entities?
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
counter it using setFov
Thanks for the flash grenade
do they have a dark theme?
Event Trigger: https://learn.microsoft.com/en-us/minecraft/creator/scriptapi/minecraft/server/entityhitentityaftereventsignal?view=minecraft-bedrock-stable
runCommand: https://learn.microsoft.com/en-us/minecraft/creator/scriptapi/minecraft/server/entity?view=minecraft-bedrock-stable#runcommand
Hold up, I can change the player's FOV?? That's Amazing, only one thing remains, what is the FOV's default value
I have
import { world } from "@minecraft/server";
world.afterEvents.entityHitEntity.subscribe((event) => {
const { damagingEntity, hitEntity } = event;
if (damagingEntity.typeId !== "minecraft:player") return;
hitEntity.runCommand(`say i was hit by ${damagingEntity.name}`);
});
Lets trigger people by setting it always to the min
in beta, it is recent
oh.
beta...
I think I will leave addon developing until the beta un-beta its betaness to be non-beta (if that makes sense)
Thanks
@warm mason hey~
may you HELP ME OUT RQ?
That might be soon or never lol.
I'll read these eventually learning js is just a lot rn π
true
new functions get stable fast, but some old stuff get forgotten
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/
That's nice to hear
You will
You should ask anyone about this, but not me.
@low flicker
you trying to run node js packages in script api or what
Alright Serty
More like Can I use external scripts which are also cjs
if I have a folder via git
Multiple CJs from gta san andreas duh
as long as they use what quickjs uses and as long as they are inside your addon
So I need to add them into my src / scripts folder?
at C:\Users\?????\javascript-algorithms
bp/scripts/...
Can you make it so the command runs if you hit an entity with a specific weapon
Read.the.docs
I mean I thought its possible to use external scripts or to access them
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}`);
});
If this continues you will make his whole addon
nah, that sound dangerous
lol
np, didn't do much
"can you make so that it saves all the hit entites in a database"
why are we using runCommandAsync to say a message
you are seeing things
.
why are we using runCommand
Some people like useles things
does sendMessage no longer exist?
caught
Lmao
you said command lil bro
I didn't say anything little baby
lol
You said lil fetus
all these zygotes yapping in my ear
that one Koala is still eating his children..
OKAY
is gone
like my dad
Time to learn HTML
it is great for hacking
i can just inspect the changelog and BOOM, released chatSend to 2.0.2
Oh I don't need this but thanks for sending it but nowI'm getting experimental
html for hacking?
yeah, it is great programing language
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
[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
Actually it isnt a programming language..
HTML stands for Hyper Tetra Mega Language.
Maybe main is a file and it tries to load it
Try removing the async syntax maybe
I have already tried with just a console.log
Btw how did you got that cool console***
CO SOLE
console****
I hate phone keyboard..
i was obviously joking...
.. have you read what i wrote
Its a custom wrapper
Oh okay
i read until hyper
...
Hypertext markup language π€ βοΈ
guns.lol in the bio, this guy isnt even worth arguing with
What about it? I mean its free
First stigmatize and then say nothing, or what?
"this guy isnt even worth arguing with" π
what's wrong with it?
a simple portal for creating linktrees
probably a process loader
Stigmatization by association.
Imo stupidity
noted
I am using similar thing for my server
Thats cool.
I want to be as good as you are
consider leaving home and trying to use the best time of your life instead spending it on coding
Coding isnt the reason for my isolation
Its just the thing I do to forget
Its good because its hurts more than the Stress
tbh by just writing a code you can learn new things
Average JS experience
I have learned a lot by just writing a code
Also true, I often use AI just to learn
Im doing a World Edit atm.
I will learn alot
I was learning back in 2021-2022 much more
I see
Is there any way to detect if a chest is a double chest? Something like which side is connected?
that's the joke...
jokin? π€¨
it depends on your habits
if you spend an hour per day to simply do calisthenics
you will notice things get better