#Script API General
1 messages ยท Page 46 of 1
So whats your code?
I'll send an ss brb
the event you use doesn't matter, what you are doing inside of the event does
for (let i = 0; i < inv.size; i++) {
let item1 = inv.getItem(i), item2 = cachedInv[player.id][i];
}
That code snippet Be like:
"Am i a joke to you?"
just 1 loop xd
Personally, i avoid commands and anything in the entity files as much as i possibly can, but effect @s clear i believe is much faster than looping in the whole effects & clearing them, other than that, i have not used one singular command in my whole blissSMP addon, while yes, scriptevent & playSound are commands, these were only for the hit cancelation & stuff
Fr
So ima tell you the native representation of your code
I'm looping, a bit cleaner in my opinion
using native existing methods instead runCommand
Lemme get you all the native player methods rq...
yeah I know about docs
No no, I'm telling them, you're good.
atm the only things I have to do via commands is /kick
most of commands are already implemented or result can be achieved by another way
Also just note, commands in script api can't have "/" if you still dont wanna use native methods for some reason.
yeah I know
Dude, I'm sure you know. I'm telling the person.
Converting over to a Map versus an array would speed this up just a little since the lookup time is quicker and it would eliminate the nested loop in your include methods. But aside from that, this is probably about as good as you are gonna get my friend. Unless your use case changes. Then you might be able to adjust the pattern but that's neither here nor there at the moment.
That's never the answer to give.
"Forget optimizing your code. Just run it. It doesn't matter".
Lazy reply bro.
Even though the loops are written separately, the includes method checks every slot in the other inventory for each item. This makes it equivalent to a nested loop with O(n^2) complexity.
And yet you are wrong.
Lol
still, it doesn't work
What's the error?
wait 5 minute
[Scripting][error]-TypeError: cannot read property 'damage' of null at projetil (wg/commands.js:51)
at <anonymous> (main.js:60)
And show me these lines
Show me line 51 only, actually.
Show me the line above it, and itself & the one below it.
So it means
You are accessing damage of null
Teste is null unless the entity has that propery, according to your tenary operator
And logging the property damage of teste (which is null) will throw an error
Because that property does not exist.
but the entity has the property "wesl3y:jutsu" equal to "fire_ball"
Try logging the teste variable. (Only, dont log damage or other things so it doesn't throw an error)
like this?
Then its probably an issue with the Jutsus object.
It probably doesn't have the fire_ball property
I don't know what I did, but now it works, thanks.
You're welcome.
since player.removeLevel() doesnt exist, any ideas?
thanks
You're welcome.
It writes this error and does not open UI what to do?
Show me your manifest.json
What version are you on?
1.21.51
Huh
This is okay
Never seen that log in my whole life so ig you are right.
You just enabled messages from the "information" level debugger
Ah
Show the code that should open the form
Right now
Are you sure that the item id is correct?
Yes
how U change mt manager themes
Or is there anyway to customize code colour and autosuggest in Mt manager?
Alr thx
I don't know about that, sorry
Nvm
Glad to help
I still haven't gotten an answer why isnt my item working ๐ญ
I do not have a theme option
Do you have the original?
Send code to debug playground and debug it
Wdym
What debug playground
Here is how to use the bot
I can't the code is on my PC and I'm on my phone
Also I can just help U when I have time not atm
Uhm copy it with type first
It's a Chromebook
Download from here https://pan.mt2.cn/dl/MT2.17.1.apk This is the official website
Maybe I'm not updated my Mt manager yet
If you downloaded it not from the official site, then I advise you to delete it and download it from the official site
I downloaded it from Google play store
I downloaded it from the site, but it's not in my Google Play Store
** i know right ** but he was just overthinking that a lot. He was talking about notations and performance because he would have to run nested loops but that wasn't true, he would just have to run one loop and that's why i said that.
i didn't say anything where i can be wrong ๐คทโโ๏ธ
why u typing so much bro it's not that deep
You affirmed Nanopoison's response when he tried to correct Asteroid about the complexity in y'alls discussion.
I replied to them explaining that the complexity was in fact just that due to the usage of the includes method and then proceeded to correct you. Asteroid knew what they were talking about but you both tried to tell the person otherwise.
I spoke up because I saw the blind leading the blind and there is nothing productive in that.
wth bro do u even speak english?
Yea, do you read it or do you come in here flexing?
Bro i'm a software engineer with a degree how come i can be a "blind leading a blind". I'm not like 99% devs here that are just kids trying to learn javascript to create addons for their servers.
Your message was very bad structured.
That's why i said that
you look like a non-native speaker
Then you wouldn't have blindly called out Asteroid in the manner you did, then reaffirm Nanopoison's response because you would have known after looking at the code Asteroid shared that it was infact a complexity of O(n^2). More importantly, you would have understood why because of the includes method inside the for loop.
it's not a problem tho it was a good try
Don't act intellectual. Either you are or you aren't. If you make a mistake, then own it. Bro got their ego damaged and wants to fight about it.
imma be honest i didn't even read the code i just looked at the case
but
Asteroid isn't right
Then you had no business kicking off the conversation in the manner you did. That's just crazy.
I couldn't care less about kids yapping at me
but alr whatever u say
I care when chumps like you who come in here yapping like they know a thing or two, but really don't.
You have no idea what I do ๐
Dream your dreams ๐
ok
I'm probably gonna just do a object of type id and amount and add and subtract from each other to see if there's more or less
Way simplier
Someone's mad & got ego.
Add and subtract? Bruh why not just compare amount instantly?
Less work on the device that runs the code
So I can find out how much changed so I can log it....
You are very picky about solutions ๐ญ
???
let equivalent = true
for (let i = 0; i < inventory.length; i++)
if (inventory[i] != previousInventory[i])
equivalent == false
that is just not O(n^2)?
what I'm saying is the solution he SHOULD have had is not O(n^2) sorry
Two adults fighting over English and a js? You just got corrected and you got mad? Damn
Ah, then must be a misunderstanding on my part. I was referencing the loop that used the includes method. ๐
To be fair I didn't explain it the best haha. I was just trying to explain to him that he didn't need two loops if he wanted to validate if they were equivalent inventories
No worries. I appreciate you clearing that up for me.
i guess you talking bout you
Haha
"Missunderstanding"
Did I stutter?
I already looked you up with your ID. I'm not impressed kid.
I suppose you aren't as bright as you claim.
Think whatever u wanna think
i didnt study years to get a software engineering degree for a kid to tell me im not what i claim to be
I believe this should be continued in #off-topic . Otherwise I'm moving on.
i dont care about this conversation so im just leaving
It was easily misunderstandable, we got it cleared up. Not that big of a deal bro, you were trying to defend what I said but you just got an ego trip for some reason lol.
What visual impact said was inherently correct because my wording was bad and made it sound like I was just correcting him on his big o notation
I'm gonna need you to chill out. Your ego and attitude needs some adjustments.
๐คฃ๐คฃ๐คฃ๐คฃ๐คฃ
who the hell does this guy think he is
oh no im so afraid of a random!
let's chill out
๐ฟ ๐
Exercise that statement please. Less talk, more action.
someone staying mad
The only one upset is the one raging with the comments. I'm at work, and chill right now. Where is your mindset?
I do wish Discord offered a better method for blocking people versus "hiding" their comments.
no brackets is a war crime tbh xd
I mean, they're not required in this case but I feel so weird when I don't see them
wrote it on my phone lmao I had to do spaces and everything
coding on phone is such a pain
yea I don't understand how people unironically do it
stay mad
I did it bcz I was too lazy to do it on a computer
I love using no brackets when not needed
Using brackets on one liners is my pet peeve personaly
I mean, yeah, but it feels pretty weird if you have this nested like that
You're like a leech. ๐
same, but tbh I probably needed more than just equivalent for it to work lmao
xD
it's so longer to type on phone
also harder to use types inside enviroment
k
- running it all is much slower
I've been using brackets for so many years that I actually find it unnatural when doing it with JS. I have exercised with it some, to try and loosen up. Still looks weird to me.
Personal preference on how people cope lol.
if(x) {return}
this feel like a crime
all I'm saying is if I had to start every function with
if (!a) {
return;
}
if (!b) {
return;
}
I would probably be less happy of an individual
obviously a simple case here where I could've done an && but still
You can... Just one line it.
that looks cursed as hell
would be probably easier to read
when you have a lot of those in your code it start to get annoying scrolling up and down
i am confused where this discussion started lol
.
i kinda hate a code where if the things inside the bracket are alone or no other things... They'd still put it in a bracket like this.
Tho it still depends on situation
I code like that though
yeah
it looks weird in that case
it's only ok for objects imo
-# you should instead put it as else if
yeah for returns
how is that cursed
no not I'm talking about the return only... When you're separating the two just use else if
not in general, but the
if (!a) {
return;
} else if (!b) {
return;
}
that feels even worse some how
if (!a) {
return;
}
else if (!b) {
return;
}
omg
nah this not sitting right with my ocd or whatever i have
if (!a || !b) return;
```
thats only valid if they want the same thing to happen for a and b.
yeah the example was simplified, but some cases u can't do that
I kinda like this but (1) it consumes space (2) the readability is ๐
better readability for me.
so idc
I mean in certain return statements if I need more than just return I will obviously use brackets slol
like if I need to send a warning or smth

a || (b || (() => {})());
server.system.afterEvents.scriptEventReceive.subscribe((event) => {
if (event.sourceEntity.typeId !== "minecraft:player") return;
if (event.id !== "test:test") return;
// conditions met
});
but for events like this, imo this is just too nice to pass up (random example lol)
what the hell
10/10 readability
system.afterEvents.scriptEventReceive.subscribe((event) => {
if (event.sourceEntity.typeId === "minecraft:player") {
if (event.id === "test:test") {
// code
}
}
});
I prefer doing this.
lol
it is valid
same
preference
server.system.afterEvents.scriptEventReceive.subscribe((event) => {
(!a) ? () => { return; } : (!b) ? () => { return; } : () => {
// run function
}
});
lmfao
damn
imagine LMAO
I do nested code since I'm doing other things other than that, I do return if I'm doing one thing or simple things
That looks shit asf
its amazing wdym
Who needs encryption when your code looks like that
I will put you on fire instead.
true, i should from now on only write conditionals like this
lol, new challenge
only write in ternary
you see that programming language that you write with whitespace only?
Personally I name all my variables after mozart compositions
Can setType be used to place/replace blocks
anyone know if it's possible to add infinite time to effects with addEffect method?
Do you mean with sound/particle?
yes?
No.
wait new encryption idea just dropped wtf... using mozart compositions as your encryption key
thats the point of the method.
or, you can just use /effect
that is fair
A simple single line... That's it
ik
same.
yeah but no intellisense :(
if (a) { if (b) { } }
just a simple line
still forgot a } lol
I just realized that is not possible to hide particles if you use infinite time
this is how much it hurts my eyes
cant even type it correctly
huh
are you sure
that sounds dumb
Huh? You must be tripping
it works perfectly fine with me.
hahaha
if (1) if (2) if (3) if (4) if (5) if (6) if (7) if (8) if (9) return 5; else return 2; else return 7; else return 1; else return 8; else return 4; else return 9; else return 6; else return 3;
least confusing statement
no
NO
Just use for loop
Why bother
lol
โ ๏ธ
๐คท
obviously if 1 and 2 and 3 and 4 and 5 and 6 and 7 and 8 but not 9 you return 2, not 8
forEach or for loop
const conditions = [1, 2, 3, 4, 5, 6, 7, 8, 9];
const returns = [3, 6, 9, 4, 8, 1, 7, 2, 5];
return conditions.findIndex(c => !c) === -1 ? returns[conditions.length - 1] : returns[conditions.findIndex(c => !c)];
yeah but that's not one line
const conditions = [1, 2, 3, 4, 5, 6, 7, 8, 9];
const returns = [3, 6, 9, 4, 8, 1, 7, 2, 5];
for (let i = 0; i < conditions.length; i++) { if (!conditions[i]) { return returns[i]; }} return returns[conditions.length - 1];
^ I'm talking about this.
close enough
I'm not talking about one lining it
return conditions.findIndex(c => !c) === -1 ? returns[conditions.length - 1] : returns[conditions.findIndex(c => !c)];
My learnings about for loop, indexes, for of pays off... rahhh
Interesting read lol
perfect
normal programming behaviour rn.
Everyone is enjoying their culture I see lol.
Still getting used to not using brackets. I might be old fashioned when it comes to that. ๐
Wait... even simpler?
return [3, 6, 9, 4, 8, 1, 7, 2, 5][[1, 2, 3, 4, 5, 6, 7, 8, 9].findIndex(c => !c) || 9 - 1];
-# If I'm gonna be honest with you, I literally need to search for stack overflow lmao
and this all is equal to a || b
I would consider using sets atp
a bit faster
hold up wait
From this if statement to mine
mine runs faster
Nah
did you just used a list instead num - 1
It's not particularly configurable, but I would expect this to run faster
you got me such a nice headache xD
not configurable at all in fact
Yessir
(() => {})() is a IIFE (immediately invoked function expression) that does nothing
ik
it returns void
falsy value
yeah
it would also always do the same thing
I waste my time searching stack overflow when I have a deadline for my thesis
do you all have some sort of competition to confuse some people like me while making fun of javascript?
I was just making cursed code idk
same
Are the numbers here literal? Or just placeholders for other conditions
syntax error expreting ; at line 29412789
atp it was just literal lmao
literal
just literal lmao that's why I used findIndex instead because we don't have a condition just nunber
... So this is equivalent:
function findValue(i) {
return 5;
}
the art of javascript is to type in terminal npm install -g typescript and npx tsc init
findIndex ๐คข
the true answer
we got there eventually
deadline is in 2h so i will do it the next hour
At least do some of it now, like 1/3 of it, you will thank yourself later
I will literally do it today, I can't Speedrun it tomorrow oof
weren't you an admin here some time ago?
oh yeah you have role xD
they owned this server once
yeah I remember
I just wasn't sure it was him
Does anyone know if there is a molang function to prevent the animated object from touching the floor?
not script api related
#1067869022273667152
i know
why are you asking here then
And why are you writing this here?
...........
#1067869022273667152
But I have nothing to do if the molang channel is dead
why are you sending the entities channel tho
Then figure it out for yourself, we have scripts here
there's a molang channel
Animations are only available in entities
yes, but his question is molang related.
I kinda forget that molang channel existed
me too.
It's a molang problem ๐ฆ
+++
Ask in #1067869318383157430 (but you said it's dead) or in #1067869590400544869 instead
#add-ons
I'm just saying what the options are
can i get help for my manifest.json
{
"format_version": 2,
"header": {
"name": "ElysiumMinage",
"description": "ElysiumMinage Script Pack",
"uuid": "7983f147-4ba9-4b0e-81b6-08202c43b8b1",
"version": [1, 0, 0],
"min_engine_version": [1, 20, 0]
},
"metadata": {
"authors": ["shadowbubble"],
"generated_with": {
"blockbench_item_wizard": ["1.1.0"],
"blockbench_block_wizard": ["1.2.2"]
}
},
"modules": [
{
"type": "script",
"entry": "scripts/main.js",
"uuid": "072153b0-0716-43a7-9ebe-1118953fe17e",
"version": [0, 1, 0]
}
],
"dependencies": [
{
"module_name": "@minecraft/server",
"version": "1.21.51"
},
{
"module_name": "@minecraft/server-ui",
"version": "1.21.51"
}
]
}
That's not how you add the version for the server and server ui.
for server it's kinda like 1.13.0 to 1.17.0-beta
for server ui it's 1.3.0 or 1.4.0-beta
Wdym by compress it?
like how its displayed on my sidebar
for example
Frost Bite
$1.3K
INSTEAD OF
Frost Bite
$1300
is the 1300 a scoreboard value or something
yes
You can divide the amount by 1000
function formatCurrency(amount) {
return `${(amount / 1000).toFixed(1)}K`;
}```
im using that score tho to find if the player has the correct amount
Then you can't shorten it? You'll be losing data (specifically the last 2 digits) if you compress it
You need to use some other method of storing their currency
to achieve that effect
okay thank you for that!
when a player hits a entity how can I run a command on the entity hit if that players has a score
I don't think so unless what he did is just to display it as that the value of it is still the same, the display just is formatted
it's formatted but if he's reading the scoreboard to get their currency, it will be read as 1.3K instead of 13XX, meaning the last 2 digits are lost
Maybe I'm tripping here but could you not just have both an actual value and a display value? 1 formatted and the other isn't
it's just display....
did you read my message?
the display doesn't interfere with the original value he still can get the original value
no... For example I have a value 1500 and we format it with the function I gave, that doesn't interfere with the original value so it means the value is still the same
const obj = world.scoreboard.getObjective('test');
const score = obj.getScore(player); //Assume the score is 1300;
console.error((score / 100).toFixed(1)); //1.3
console.error(score); 1300```
Oh wait I missed the original context, I thought he was asking about making the scoreboard value 1.3k instead of 1300
Not showing it on UI
export const metricNumbers = (value: number): number | string => {
const types = ["", "k", "M", "B", "T", "P", "E", "Z", "Y"], selectType = Math.log10(value) / 3 | 0;
if(selectType == 0) return value;
let scaled = value / Math.pow(10, selectType * 3);
return scaled.toFixed(1) + types[selectType];
}
That's why I'm confused as hell why'd you say the last 2 values are lost.... ๐คฆ
Yeah I read context above it but the real important one was behind a massive wall of code and didn't realize it lmfao
those are quadrillions
yeah but u have it listed as P in types
Yeah peta can be also used
so just throw this in and my scores that are displayed will be compressed?
interesting I have never seen nor heard of P instead of Q
Yeah
just do metricNumbers(number)
metricNumbers(2000000) -> 2.0M
How do you display it on the screen?
.button("ยงsSharpness\nยงc$" + world.scoreboard.getObjective('SharpnessPrice').getScore(player), "textures/shopUI/sharpness")```
function metricNumbers(value) {
const types = ["", "k", "M", "B", "T", "P", "E", "Z", "Y"];
const exponent = Math.floor(Math.log10(value));
const selectType = Math.min(Math.floor(exponent / 3), types.length - 1);
return value < 1000 ? value.toString() : `${(value / Math.pow(10, selectType * 3)).toFixed(1)}${types[selectType]}`;
}```
That is typescript here's the javascript
okay so i added it into my code with 0 errors
but its not displaying the scores compressed
do I have to change something in there to myt scoreboard?
.button("ยงsSharpness\nยงc$" + metricNumbers(world.scoreboard.getObjective('SharpnessPrice').getScore(player)), "textures/shopUI/sharpness")```
Like this.
okay thank you! its working now but some of my other js isnt working
my sidebar stopped popping up
No errors?
nope
Nah. I'm talking about YOU. Not me.
womp womp
See what i said?
Mad as shit and ego is high as it.
I could go on to argue with a dumbass high ego 13 year old thinking he is better than everyone. But no i haven't gotten good sleep this month and its 2:37am. So i dont have the fucking power to argue with you.
yeye cry all you want buddy
I'm greatful not to be in your place. I'm greatful i dont have high ego that blinds me from seeing bugs or errors and hating feedback or anyone that doesn't agree with me. Basically I'm greatful i dont mind people having opinions, unlike you. Now if you wish to keep fucking yourself, go ahead. I had a shitty day and i have had a shitty sleep schedule this month and i ain't gonna continue this useless conversation with someone who is Basically Blind, but the only difference is, they chose to be blind, and not forced to be blind.
womp womp
u funny lil bro
Scripters being toxic once again... sigh

This is mad crazy.
Classic
It's always the programming communities for kids too lmao. I rarely see this toxicity in modding, library servers or open source projects
Personally I've seen this toxicity in any server that includes coding just in different levels
Hopefully no one has any opinions of if chatSend is a viable workaround for commands
There is scriptevent.
How do some people display blocks or items above the crate after it has been opened?
Do they use particles?
I obviously would appreciate some sort of built in auto complete but I just use server forms for any needs like that haha
What's the error?
Error:
[Scripting][error]-TypeError: not a function at <anonymous> (chakra.orb.js:23)
Code:
mc.system.runInterval(() => {
for (const dimensions of ['overworld', 'the_end', 'nether']) {
const dimension = mc.world.getDimension(dimensions);
const entities = dimension.getEntities({ type: "shin:chakra_orb" });
const players = mc.world.getPlayers();
for (const entity of entities) {
for (const player of players) {
const playerPos = player.location;
const orbPos = entity.location;
const distance = Math.sqrt(
Math.pow(playerPos.x - orbPos.x, 2) +
Math.pow(playerPos.y - orbPos.y, 2) +
Math.pow(playerPos.z - orbPos.z, 2)
);
if (distance <= 5) {
const dx = (playerPos.x - orbPos.x) * 0.2;
const dy = (playerPos.y + 1 - orbPos.y) * 0.2;
const dz = (playerPos.z - orbPos.z) * 0.2;
`LINE 23 -->` entity.setVelocity({ x: dx, y: dy, z: dz });
}
}
}
}
}, 1);
setVelocity? Have you tried applyImpulse
@neat hazel
yeah setVelocity doesn't seem to be a real thing?
Thnk
How to apply impulse to the entity so that it goes towards the player?
grab the location of the entity and player
Thnk
How do I make a command run until the player no longer has a tag?
That means that if a player gets a tag, a command is being executed repeatedly until he no longer has it.
Here are two simple ways that I would do it (I would probably would use the first)
-
Use a map and store players who have the tag (you can store it when u add the tag), run command on all players in the map every tick, and check them if the tag has been removed (or remove them from the map when u delete the tag).
-
Every tick check every player for if they have the tag or not, then run the command on them
I wanted to do it with scripts
Yes you would do that with a script
system.runInterval(() => {
for (const player of world.getPlayers()) {
if (player.hasTag('test')) {
player.runCommand();
}
}
});```
Is this what you mean or nah?
If this is the case, just use tick.json and a Minecraft function.
BP/functions/loop.mcfunction
execute if entity @a[tag=test] run <command>
BP/functions/tick.json
{
"values": [
"loop"
]
}
execute as @a[tag=test] at @s run say hi
the command is only executed once.
Not sure I understand. Do you need the command to execute once, if the player has the tag?
So it will not repeatedly execute if a player has that tag?
it can be set to just execute it once per check or executed in a loop if it has the tag .
loop meaning untill the tag is gone
or something else overrides that
tag @a[tag=!test] remove command
execute as @a[tag=test,tag=!command] at @s run say hi
tag @a[tag=test] add command
I got it
Now I need to detect if the item is still there and if it is no longer there, the tag should be added again.
How do some people display blocks or items above the crate after it has been opened?
I would guess using entities or using a fox with a item in its mouth to get something akin to block displays that java has
or just create a custom entity?
That's what I was referring to when saying using entities but I quickly looked through the discord and saw someone mention using a method with a fox
But yes I would just use a custom entity over anything like that you are right
I mean it also depends
If this is pure commands either use fox or armor stand
But if it's an addon just create custom entities..m why bother
I checked the videos on the post and it's kinda scuffed imo
I definitely can't disagree
There is, in fact, a way to programmatically set an item frame's contents, or fake it at least, but it's super jank.
You can pre-generate an mcstructure file for every item in the game (1 file for each permutation of item, item rotation, frame facing direction), and pair it with StructureManager to place.
The disk usage and subsequent add-on load time... oof! Like I said, super jank.
Needless to say, this really shouldn't be done, but if you're going to do it anyway, keep it server side.
Ask me how I know!
I feel like it's kinda resource intensive
It's also evil.
How to make a double hit anti ?
Set a timeout when the player hits ,then detect if the player hits again within the timeout
Like give player a state
And set a timeout that remove state
If a player is hit with state then represents that player already hitted
Make some functions when detected second hit and also remove the state
How do i remove an item from player inventory using script
player.getComponent(EntityComponentTypes.Inventory).container.setItem(slotIndex, undefined); // undefined removed item
ty
is it possible to apply knockback to an item
How do I actually use the event in script since it doesnt follow the common world.after/beforeEvents....subscribe logic
It involves custom components, check out https://learn.microsoft.com/en-us/minecraft/creator/documents/customcomponents?view=minecraft-bedrock-experimental and https://jaylydev.github.io/scriptapi-docs/features/custom-components.html#item-custom-components
very helpful, reacting โ to a question instead of pinging/explaining why
.applyImpluse()
(You are gonna need some calculations to turn the knockback into impluse)
hi there, do someone know if the cap of 256 buttons also apply for modal forms? like text fields or dropdowns?
Probably
has anyone managed to get interacts to work on flowing water?
I haven't tried but I might have an idea. Might be possible to use itemUse, get the player's view direction, then getBlock from ray and include passables? If that's what you meant anyways
Not sure if I misunderstood though
guess the answers no, that doesn't work lol
Why itemUse when itemUseOn exist
Because he said it didn't work lol
where? I don't see it. All I see is this.
Or I guess he implied it didn't work
Nvm
itemUseOn will only let you get "minecraft:water"
flowing water? Nope not possible
blockFromRay for whatever reason does not get flowing water
Yeah, I was about to say that...
really was hoping block from ray would work lmao
Does liquid clipped not work?
yeah I just said passable I forgot which one it was lmao
Cat ๐บ
-# random
My guess if includeLiquid doesn't work is that it might just be a collision box that doesn't work with rays
I remember testing that one, the issue is that there's no way to communicate that to the script
even if it were to detect flowing water
Hi guys, How do I declare the block type in the function getBlocks?
(I believe I did it wrong in the following code since it returns unidentified.)
I checked the website to look for an example but couldn't find
const volume = new BlockVolume({x: block.location.x + 2, y: block.location.y + 1, z: block.location.z + 2},{x: block.location.x - 2, y: block.location.y - 1, z: block.location.z - 2});
const btarget = block.dimension.getBlocks(volume, { BlockPermutation: { type: "brs:batimcycle_generatorswitch" } })
Try this
const volume = new BlockVolume(
{ x: block.location.x + 2, y: block.location.y + 1, z: block.location.z + 2 },
{ x: block.location.x - 2, y: block.location.y - 1, z: block.location.z - 2 }
);
const blockPermutation = new BlockPermutation("brs:batimcycle_generatorswitch");
const btarget = block.dimension.getBlocks(volume, blockPermutation);
Tysm, but I found a workaround ๐
-# Probably will be helpful in the future
no worries just dm me if you need any help soon
Alright!, Tysm for you kindness!
#1322880895656525856 can someone help ?
Adding bodies to my procedural spider.
Previous Videos:
2. https://youtu.be/r70xJytj0sw
All my links:
https://heledron.com/links/
Source Code:
https://github.com/TheCymaera/minecraft-spider
World Download:
Spider Garden: https://www.planetminecraft.com/project/spider-garden/
Ambertry Forest: https://www.planet...
how to make this with scripting?
Same thing as asking โhow to create the same addon as X modโ. This is a fairly large project, so there is no answer to your question. And itโs unlikely that anyone will write the code for you, if only because it will take weeks, or even months.
guys, how much lag does ticking cause? is it very bad?
how about systemRunInterval is it any better?
That is primarily dependent on the code being executed within the loop.
I've a title bar that calcs the TPS to see if it's causing lag but it doesn't really matter what I do it always stays at a value between 19-21, is it really that hard to cause server lag on bedrock? because I see people talking about lag caused by ticking but when I try to replicate placing or generating a lot of blocks that tick, the TPS value doesn't go UP
could you elaborate, please?
Code executes synchronously if not specifically setup to be asynchronous. So line by line your code inside the loop executes. The lag you are asking about between each loop will be dependent on the lines of code being executed and the time it takes to execute them.
another thing: Is there anyway I could make so breaking the top part of a custom double plant instantly or at least almost instantly breaks the bottom part of the double plant? because currently everything I tried resulted in a little delay but I'm also not sure if that's it and there's nothing I could do about this
i think, there's no way to make custom heads placeable like vanilla heads without using scripts to rotate the custom head right?
import { turnModIntoAddOn } from "@minecraft/server";
const addon = turnModIntoAddOn('https://youtu.be/PSnPOYeTW-0?si=5DMZRfBmO1DhjAoo');
addon.start();
what are the advantages for MC too make code asynchronous?
There's a template for custom heads on dev resources
send the link
an entity with an animation that aligns it would be the only alternative
hell nah, no entities, only blocks
Why do you avoid scripts?
A lot of advantages. By offloading tasks to asynchronous operations, the main game loop running on the primary single core can run more efficiently. This is particularly useful for tasks that involve I/O operations, network requests, or other time-consuming processes. Asynchronous code allows the server to continue processing other tasks while waiting for an asynchronous operation to complete. This prevents the server from being blocked by long-running tasks if implemented and managed correctly.
i will not avoid scripting
its not that useful ig
thats very very interesting!!but in this case why would I ever want to make something synchronous?
well, in this case I honestly would go for scripting
Asynchrony is not always necessary
detect the player facing direction with 8 cardinal directions
Asynchrony is needed for complex tasks, and it essentially just divides them into small synchronous tasks
#1322880895656525856 can someone help me?
i will use some scripts and a custom item ( wrench ) to fully customise the head block rotation
is it possible to make ticking or systemRunInterval asynchronous?
By default JavaScript is synchronous.
how?
system.runInterval((async function() {
// code
await system.waitTicks(1)
// code
}), 3)
Another example:
import { system } from "@minecraft/server";
async function performAsyncTask() {
// Simulate a delay to represent an asynchronous task (e.g., fetching data)
await new Promise(resolve => setTimeout(resolve, 2000));
console.log("Asynchronous task completed");
}
function scheduledTask() {
console.log("Scheduled task started");
// Call the asynchronous function
performAsyncTask().then(() => {
console.log("Scheduled task completed");
});
}
// Schedule the task to run every 100 ticks (5 seconds)
system.runInterval(scheduledTask, 100);
Donโt forget that asynchrony is only needed in resource-intensive code. For example, if you just need to scan the inventory of one player, then asynchrony is not very necessary
how about a function that gets executed every tick?
to detect if a player is in contact with a block to then cause damage (a cactus, for example)
Make it execute every 2 ticks
async or sync?
And it would be nice if you showed the code, it will be easier to understand how to optimize it
it currently looks bad because I was messing a lot with it to test a few things but wait a second, I'll grab it
the most powerful script method
I removed the part that checks if the block has a specific tag while I was testing but I'll add that back once I get the thing that detects which axis is the block in front of the player to work properly
The code doesn't look complicated, but it can be made asynchronous by putting this instead of runInterval:
const playerPerTick = 1
async function asyncInterval() {
for (let i = 0; i < world.getAllPLayers().length; i++) {
climb(world.getAllPlayers()[i])
if (i % playerPerTick == 0) await system.waitTicks(1)
}
asyncInterval()
}
The more playerPerTick the more operations will be performed synchronously, you need to configure this so that the time for a synchronous operation is approximately 30 MS
how can I calculate the time for a sync operation?
also thank you very much!
record the time before executing the climb function (let time = new Date().getTime()) and after executing this function. The difference will be = time after execution - time before execution. Then 30/time difference and round that number down, putting the final value in playerPerTick.
thank you very much for all the wonderful help and teaching me!
btw, do you know if there's a better way I could make the player stay still in the air? I'm currently using knockback but idk if there's a better way
probably have to use player.json to add / remove components
if that works.. i haven't really tried to disable player physics etc.
component groups*
maybe based on a tag...
Is it possible to clear the inventory on only items with a specific tag?
yes
if (inv.getItem(slot).hasTag('your tag')) {
inv.setItem(slot,null)
}
inv.setItem(slot, null)
nvm
And to add tag to the item is: inv.getItem(slot).addTag('your tag') ??
item tags are not dynamic
.
item tags != entity tags
i mean if you add a tag you have to replace it no? like lore
Tags for items and blocks can only be set in json
those are item tags
script api can't edit them
๐ง โ
use lore or dynamic property
But there is no way to check the TAG via API?
bruh is it hard to check auto completions?
if (item.hasTag('tag'))
hasTag
but as i said the tag here is not what you are thinking
not all tools/devices offer that
Anyone who has a script to check someone his inventory and enderchest
You cannot get an Ender Chest inventory through the API.
const chessboardPlains = [];
for (let row = 0; row < 8; row++) for (let col = 0; col < 8; col++) chessboardPlains.push({ origin: [col * 2, row * 2], size: [2, 2], name: `${String.fromCharCode(65 + col)}${8 - row}`, });```
Should I store it as a map instead of an object?
-# ignore the one lining...
Depends on how you going to use them
as the above msg said, it depends
Is there a script that stops a player from hitting another player
@untold magnet i believe using the shell rotations is what you want. Just look up custom shell block and you'll find it.
Is the correct method for storing player statistics scoreboards, dynamic properties, or something else?
Like I want 10+ statistics
I have question, does anyone can help me? I started using ChestFormUI and I have issue iwth latest "durability" idea in the script. Even if there is no durability set in button there is this 'dur#00' text. How can I get rid of it?
Also I found out that typeIDs are not working for me (in Edu), someone had this issue too?
if (durability && durability > 0) {
displayDurability(durability);
} else {
hideDurabilityText();
}
I should then make function to get rid of the text, right?
Oki, thanks!
Let me know if it fixed it
I found string of this durability part dur#${Math.min(Math.max(data?.durability, 0) || 0, 99).toString().padStart(2, '0')}
So I removed that from main script and it worked
But thanks for trying tho
How change this
title(text) {
this.#titleText += text;
return this;
}```
To the exported title text from rawtext? Like in ActionForm (this still is question for ChestFormUI code)
example: I would like to make this working in ChestFormUI: .title({ rawtext: [{ translate: 'main_menu.title', "with": ["\n"] }] })
That's my bling
Should i store some player data in cache with some type of collection like Map, or should i just retrieve the dynamic property when i need it and work with an array? ๐
I need an idea, what do you think is the best way to simulate players tied by their feet to each other?
I appreciate the suggestions
Maybe try playing with the newer input permissions, and teleport them facing the same direction, and make both of those players input effect which way they both get knockbacked sideways forward backwards etc..
Or have them both ride something with 2 seats and add input permissions to control that entity they are sitting in
Yeah, we could detect WASD... But it's beta rn
is it?
oof I forgot I'm on 1.21.60.21 lol
That's why I said beta
wadahel
stable in preview
so...
disable input
check input vector
if the tow are moving in the same direction move them together
Update here we go
This is a good idea
Thanks
the message below it
Why? Are you saying it's not possible?
bold for you to assume it's not possible without even trying
then make it...
๐
Why are you ordering me?
my understanding is that you can use multiple entities acting as bones for IK to make it work, but I could be wrong
Not the most trivial task that's for sure
You are correct but more entities = more tps drop
yep, but it's a solution
Oh fiddlesticks, what now
Wouldn't it be theoretically possible to code the IK via molang? Then you could just pass the position of the legs through actor properties in a single entity
maybe yeah, haven't tried it
Erm
My God, itโs Mr. Script API himself
anyone can help me with block stuff
the block help section is so dead

plz
@warm drum Use the proper channels please.
Herobrine saying "sowwy" is new to me lmao
๐
Nya~
alright bro put down the phone
No.
There's no limit on the number of dynamic properties right? (Just the value stored ? ? ?)
yeah
thanks!
wtf does this mean
system.runInterval(()=>{
let property = "jay:health_upgrade";
let player = "player"
for (let entity of world.getDimension("overworld").getEntities()) {
if (entity.typeId === "jay:health_upgrade") {
let dynamicProperty = entity.getDynamicProperty(property);
if (dynamicProperty === undefined) {
entity.setDynamicProperty(property, world.scoreboard.getObjective('HealthCost').getScore(player))
} else
if (dynamicProperty > 0) {
entity.setDynamicProperty(property, dynamicProperty - 1);
}
entity.nameTag = `ยงa$${entity.getDynamicProperty(property)}`
}
}
}, 20)
it means exactly what it says. server-ui 1.4.0-beta is requesting server 1.17.0-beta, but you have 1.16.0 in your manifest, so it's promoting the version up to 1.17.0-beta
so if you wanna get rid of it, then change your @minecraft/server version in your manifest to 1.17.0-beta
"dependencies": [
{
"version": [
1,
0,
0
],
"uuid": "13293fe7-f502-41bc-b9c9-1144f06a2153"
},
{
"module_name": "@minecraft/server-ui",
"version": "1.4.0-beta"
},
{
"module_name": "@minecraft/server",
"version": "1.17.0-beta"
}
]
}
i already have 1.17 in it
well it looks like you have multiple of the same addon enabled somehow,
make sure the other ones are removed or fixed
I have been coding for around 10 hours straight now trying to get my stupid indexedDB to work so i can store images and jwt and other stuff in it and its hard to do this & encrypt & decrypt it at the same time... and i just randomly remembered an error in my custom commands script and i decided to see if it was an actual error and it was an error i had no idea about and i fixed... without even seeing the script i knew there was an error on a certain line and certain column ๐
(Basically i was coding the server website and just got an insight in the middle of the session about an error in the server's scripting api addon..., my brain has telepathy or smth), is this normal?
Its normal
Above normal, I'd say
The thing is i literally didn't remember the line's code nah, i remembered line column and row...
I didn't even know what the error was
The insight progress triggered sth related to that code. Which how I usually map my memories
Wha?
Like remembering a word from a conversation yrs ago
So is that some kind of syndrome or great memory or what exactly?... (I'm asking you (a software engineer) a doctor's question... lol)
Uhm, I see it as "cool weird network"
"Remember M9" suiting name
Fr
Welp ig its cool lol
Btw does anyone have a working example of retrieving a value from an indexedDB?
indexedDB?
Is this NoSQL?
Nah
Its kinda like sql
Its relatation
But its like
One sec
IndexedDB is a low-level API for client-side storage of significant amounts of structured data, including files/blobs. This API uses indexes to enable high-performance searches of this data. While Web Storage is useful for storing smaller amounts of data, it is less useful for storing larger amounts of structured data. IndexedDB provides a solut...
just make a class for db management...
Yeah thats the thing
It doesn't work lmao
Basically it does work but uhh it show null when i retrieve
Nvm got it to work lol.. all that was happening was i didn't clear cache lmfao
I can't believe i forgor about it
if (!entity.isValid()) return;
You're welcome.
Does anyone know how to make it so if i have the tag Owner for example it puts this above my head
[Owner]
player.nameTag = ''
tho changing the name tag of the player doesn't affect the chat so you'll use another even listener for that
From what I understand you want a way of detecting if the player had the tag and also the ability to display it in him.
If(player.hasTag(โexampleโ) === true) {}
Useless
True, just do (player.hasTag()) or (!player.hasTag())
Yeah, but I just wrote it anyway
how do you display it above the head?
^ this.
i already did, but it's so so glitched for some reason
is it possible to cahnge the biome of a specified area like in java?
something that can cahnge the grass/foliage tone?
like i want to create seasons for my addon
Guys... I'm kinda confused with this one.
world.beforeEvents.worldInitialize.subscribe(({ blockComponentRegistry }) => {
blockComponentRegistry.registerCustomComponent('chess:board', {
onPlace({ block, previousBlock, dimension }) {
if (previousBlock.type.id !== 'chess:board') world.setDynamicProperty(`chessBoard:${dimension.id}:${block.location.x},${block.location.y},${block.location.z}`, initialChessPieces); <-- line 117
}
});
});```
```[Scripting][error]-TypeError: Native variant type conversion failed. Interface property ['z'] expected type: number (failed parsing interface to Function argument [1]) at onPlace (main.js:117)```
Try doing console.error(block.location); & console.error(block.location.x); & console.error(typeof block.location.z);
that's the fun part no error... It shows normal
It isn't supposed to test it, its supposed to debug the value.
what? As I said when logging it doesn't throw an error but when I put it as the name of dynamic property
Me personally i do:
let blockKey = `${block.dimension.id}|${Object.values(block.location).reverse().join(' ')}`;
Lemme try this... And if it doesn't work then... I'm losing my mind here.
Nope didn't freaking work
NVM
I'm just stupid
This stupid error is because of this.
const initialChessPieces = {
a1: 'rook', b1: 'knight', c1: 'bishop', d1: 'queen', e1: 'king', f1: 'bishop', g1: 'knight', h1: 'rook',
a2: 'pawn', b2: 'pawn', c2: 'pawn', d2: 'pawn', e2: 'pawn', f2: 'pawn', g2: 'pawn', h2: 'pawn',
a8: 'rook', b8: 'knight', c8: 'bishop', d8: 'queen', e8: 'king', f8: 'bishop', g8: 'knight', h8: 'rook',
a7: 'pawn', b7: 'pawn', c7: 'pawn', d7: 'pawn', e7: 'pawn', f7: 'pawn', g7: 'pawn', h7: 'pawn'
};```
The games think I am giving a Vector3, which I'm not. So I need to stringify it
you can only store strings, numbers or Vector3 in dynamic properties**
And objects
const object = { name: 'Coddy', age: Infinity };
world.setDynamicProperty('test', JSON.stringify(object));|```
thats an string
what?
JSON.stringify
Bro is infinity years old ๐
you can't store objects in dynamic properties afaik. so i recommend parsing them first into strings and back
That's what json.stringify does
Hello there it's been awhile since I saw you.. and I know how to use them...
Thank you Mr. Obvious.
Yes I know I was telling the guy who told u to parse it into a string not you
Because you already did that
was replying to this. just to clarify
i mean I phrased it wrong... so it's my fault I guess lol
but im more concerned with how you passed chessBoard:${dimension.id}:${block.location.x},${block.location.y},${block.location.z} as the dynamicProperty name. that should be static, no?
Huh?
i feel like the dimension, and block location should be mapped in a global scope first
ie., it should be stored in as a value, not in the name
that's not what I want.
so I put a dimension with the location since... When I go to the nether and I change in that location in the other dimension it's also affected
If i were you I'd make a class for managing these locations.
รทใ Disappears Into The Darknessใรท
I'm not gonna bother making it I'm just gonna use it once.
like what?
world.getDynamicPropertyIds:
Am i a joke to you?
Also I used dp for debugging because I didn't add states on my block yet
And idk honestly how you are using it
seeing dp and it not being dynamic programming feels wrong
Like i said
It looks normal to me
not my problem :)
Y'all just don't like ugly code and perfect outcome.
im implying that you should make a block database and store all instances of chessboard pieces inside there, instead of making multiple dynamic properties
Nah.
He's doing it correctly how we are supposed to.
realistically you should only have one dynamic property for one chess board, as long as you can fit it within the character constraint
is what im saying
but I think that's what he is doing?
it looks like he is storing the origin as chessboard:dimension:coordinate
by passing chessBoard:${dimension.id}:${block.location.x},${block.location.y},${block.location.z} as an arg, you're making multiple instances of dynamic properties though, are you not?
Yes he is
yeah but thats the name
Y'all just leave bro alone fr. He ain't like those people using commands when native methods exist
And i think this personally is better in every aspect.
With all due respect plz let this go fr
i dont think it is though. overtime, its gonna fill up the allocated dynamic property size. on the other hand, if you have a controlled database, not only you can monitor it, but also theoretically fit more block data
The size for dynamic properties is on the dynamic property itself, not the amount of them
Also stringifying makes them have more useless characters so its worse
you can significantly reduce it though. dude its literally java script, just import an npm that compresses strings or something. or better yet compress it yourself
bruh
^
Or you could just do world.getDynamicPropertyIds for having so called "control" that you "never had".
Instead of parsing and compressing and stringifiying.
For God sake guys, stop because I don't plan on using dp in final
I will rely on states of the block
WTF
@dim tusk do u have a dynamic property for each chessboard block, or just one for the origin? (just curious)
anyways back to the original dilemma, i would like to ask if changing the chessBoard:${dimension.id}:${block.location.x},${block.location.y},${block.location.z} to something simple and static like chessBoard:data would yield different results.
:sigh:
You want me to store all locations in one dp?
yeah that's rlly bad
there is a combined limit of 32kb
for now
which you won't hit at all
nah just test it and revert it back
nope, unlimited amount, each dynamic property is 32kb
no difference at all.. why?
yo
32kb limit, 32k chars per dp, stringifying adds unnecessary chars like extra " and what not.
Not infinite at all but you won't hit the limit unless you spam it shit
it doesnt work for some reason
import { system, world } from "@minecraft/server";
system.runInterval(() => {
for (const player of world.getAllPlayers()) {
player.onScreenDisplay.setTitle(`[health_bar_0]`)
}
})```
thats the whole file
Whaa
manifest problem?
What tf do you plan on doin with it?
Also what is the error?
this is just a test to see if it actually work
Do you have it imported? (If you use a multiple folder system like me)
import { system, world } from "@minecraft/server";
system.runInterval(() => {
for (const player of world.getAllPlayers()) {
player.onScreenDisplay.setTitle(`[health_bar_${Math.round(player.getComponent("health").currentValue / player.getComponent("health").effectiveMax * 24)}]`)
}
})```
Is your manifest.json valid?
yea
no
does it have a module with the latest server version though?
Wydm by no?
Not needed, health comp alr out.
stringifying does increase the size, but you can still compress it. and decompress when accessing data, vice versa..
is this error related to it?
I know. But you are increasing the chars, therefor closer to hit the chars limit.
Yeah basically manifest.json
Why'd you tell me the manifest.json was valid then?
cuz I thought it was
the real point here is you're more likely to reach the 32k character limit if you have many chessboards, than the actual limit of dynamic properties if you have each chessboard location saved.
{
"format_version": 2,
"metadata": {
"authors": [
"TheFennec"
],
"generated_with": {
"bridge": [
"2.7.42"
],
"dash": [
"0.11.7"
]
}
},
"header": {
"name": "pack.name",
"description": "pack.description",
"min_engine_version": [
1,
21,
0
],
"uuid": "e475ba8c-2c66-48b0-907e-d05530a85f34",
"version": [
1,
0,
0
]
},
"modules": [
{
"type": "data",
"uuid": "e7935e60-ddfa-409f-bb5c-6422130f874e",
"version": [
1,
0,
0
]
},
{
"type": "script",
"language": "javascript",
"uuid": "0f351690-4277-4fdd-a968-8478eccb7ae8",
"entry": "scripts/main.js",
"version": [
1,
0,
0
]
}
],
"dependencies": [
{
"uuid": "4b6432bd-d96c-458a-8615-abb6c49fd606",
"version": [
1,
0,
0
]
},
{
"module_name": "@minecraft/server",
"version": "1.16.0"
}
]
}```
Not the manifest.json and nor this snippet.
Is it possible that it's happening before the player fully loads in the world and the game doesn't know how to run it lol
Well system.runInterval doesn't break
It would keep throwing errors instead of stopping the whole script.
there are no errors
Because it doesn't have any and the script doesn't even work
bruh
my point is storing multiple chessboards in a single instance (e.g., map), and then saving that map into dp. but not necessarily just one dp, it's to be splitted in 32kb characters, across multiple dps. this is what im implying as a centralized database.
it's hard to reach that at all if I'm gonna be honest
there arent
any
just 1 file
well if it is a server with 1000 chessboard, 32 characters per chessboard already would reach the limit
There is no possible way for me to know, without full context and all of the log.
send the bp
later after talking u said u just wanted 1 so it's fine
Good bye world it would lag because I have a lot of states in a block
if you plan that
no?
what block states would you use aside from the obvious cardinal/facing direction
sorry ur right 33 my bad
who said only cardinal directions?
you are forgetting that the key can also be any char long
"x" to "x"*32k + every other combination
yes, if you need to render pieces you definitely need 2 block at least, because I calculated it yesterday lmfao
if it still doesnt work then the problem is in my json ui
what if instead of using block states, you fake the render of chess pieces using entities :o
that's my plan because using block states ain't worth + lag
1,219,760,487,635,835,700,138,573,862,562,971,820,755,615,294,131,238,401
This is the total permutation of a block if every position has 5 state values, empty, pawn, etc.
nah thats no good lol
Crazy
try logging like do console.error()
forgot that exist
good luck with that
(the game break)
2 blocks having maximum states
Nuh uh
we can say that we are storing objects but the api just accepts "plain text", we parse the object to "plain text" to save it
Yeah yeah
I phrased it wrong that's why. LMFAO
try to run the bp alone
it shouldnt look like that
OH NVM I FIXED IT
forgot smth in my hud_screen
mb guys
the script works
Does anyone know how to make a capture the flag system?
My tini tiny finger hurts now
syetem.runInterval & damage sensors incase you wanna disable team damage and add a tag to players using some randomization algorithm and add the map or whatever.
Lol
i actually implemented the pawn now wohoo after 1 hou
Crazy lol but i bet there is like a thousand checks and not to mention the amount of permutations right?
I am thinking about my website and trying to think about script api but i can't so yeah im sorry for taking long to type lmao
But you are displaying stuff using multiple print statements and using multiple nested if statements i believe.
Me personally i could make chess without manually doing anything at all on html & js and a tiny bit of css.
And idk I'll find some chess playing algorithm and implement it to play against me lol
But doing this on mc and not using forms nah. Using block permutations.
Kinda mad fr
Imagine
The only possible way i see coddy finishing this project is to auto generate the permutations.

