#Script API General
1 messages · Page 68 of 1
And also you can't have any world-based api calls at the base level anymore lol
they didnt even do anything with isvalid they just removed the braaces
system.run spam!!
I am not immune 😛
oh man
i forgot that exists
await null; spam
we meet again 😭
I think I might be making a separate class to deal with this kinda stuff...
aight guys need yalls help rq
Honestly glad they axed it, I had gotten lazy lol
yeah all mine are broken too it keeps giving me errors saying unexpected format and missing namespace in identifier so idk what happend lol
having to update my dependancies myself so I can update quicker 😍
[Scripting][error]-ReferenceError: Native constructor for [MolangVariableMap] does not have required privileges. at MolangVariableMap (native)
at <anonymous> (avatar/utils.js:13)
how can i gain "privileges" ive looked over at the documentation but cant find anything relevant to that
system.run
System.run won't do it anymore
you need world.afterEvents.worldLoad
system.run still works right??
me?
Everyone needs to watch this lmao
//reload is needed to stop crashes
reload = reload + 1;
if (reload > 1) return;
for (const comp of blockComponents){
//register the component
blockComponentRegistry.registerCustomComponent(comp.id, comp.code);
}
});
Error
blockComponentRegistry.registerCustomComponent(comp.id, comp.code);
is not a function
welp
waittt runcommandasync hooked 💀 ?
use runcommand it removed
can anyone help
bet
what do i replace system.run with
It's not a direct replacement
if anyone knows why it's giving error
what do i do then
Maybe learn javascript first haha
System.run will be fine getting out of EarlyExecution on beforeEvents I think, but the big change is that all your setup code essentially doesn't have access to world data anymore unless you use the worldLoad event, which triggers after the very first tick once everything is loaded.
Alrighty, time to move stuff over lol
wait i dont need to change my code
You 10000% should
sounds nice - dying over here
Yeah, I have a pretty big server codebase that I need to refactor now 😭
good that my every file looks like someone who doesnt know how to script made it
such is life using beta script api
real
wait why do i even use beta?
I always tell myself "This beta version wont change its feature set much... I can use this." then its flips 180.
🤔
happend to me also
rah im just deeping how im gonna edit so many files 😭
I mean I started using beta in august -- it's been like uber stable from what i've used lol
i opened discord and saw everyone saying i will update my addon is 3 days💀
I just started using beta last week and im pretty deep into reworking stuff with this new update
very small portion of what might have to be refactored
my code is just that bad that i dont even need to change it
oh my
💀
thats uhh a pretty interesting way to do it
what are you trying to do ?
yes ik i didn't use switch case somethin
ikr lol
Uhhh. (({ blockComponentRegistry }))
this is the right format.
system.beforeEvents.startup.subscribe(({ blockComponentRegistry }) => {
blockComponentRegistry.registerCustomComponent('<id>', {
// ...
});
});```
ook
Is destructuring absolutely needed, or is mine just buggered for realsies
It's not necessary tho, I just did that since it makes the code long (not at all) lmao
-# I can just use ev lmaooo
world.afterEvents.worldLoad.subscribe how do i use this for a molang variable map?
MolangVariableMap? You can only use it in particles tho.
k cos im getting privileges issues
Send code and which line.
[Scripting][error]-ReferenceError: Native constructor for [MolangVariableMap] does not have required privileges. at MolangVariableMap (native) at <anonymous> (avatar/utils.js:13)
Where's the code? Did you use it beforeEvents?
import { system, world, Player, MolangVariableMap } from "@minecraft/server";
import { ActionFormData, ModalFormData } from "@minecraft/server-ui";
import { PLAYER_DATA_MAP, WORLD_SETTINGS } from "./index.js";
import { chooseBendingMenu } from "./core/scroll/chooseBending.js";
import { chooseSlotsMenu } from "./core/scroll/chooseSlots.js";
import { showSkillTreeMenu } from "./core/scroll/skillTree.js";
import { chooseSettingsMenu } from "./core/scroll/chooseSettings.js";
import { statsInfoMenu } from "./core/scroll/statsInfo.js";
import { teamsMenu } from "./core/scroll/teams.js";
import { clear } from "./core/player/hud.js";
const map = new MolangVariableMap();
export const autoSmeltItems = {
"minecraft:cod": "minecraft:cooked_cod",
"minecraft:beef": "minecraft:cooked_beef",`
ahh then you probably need it then.
And why put it as global variable?
Can't you put it in the event listener itself?
yh your right tbf
hmmm whats the reason behind runCommandAsync removing
they felt like it
channelog exists. Read it.
smokey said that it'll be out tomorrow
yep, i did heard
ig some ppl will stop yapping about "i saw someone make custom slash commands, how are they making it?!?!"
oh
My yapping asking when custom commands will be added paid off lol
fr
how much delay is there between the .startup and .worldLoad event?
I think not a big delay, if the v1.0.0 scripts running in the middle is not very heavy
oh wait
huh
i didn't know async runs before runJob
Depends on your pc and the world you're trying to load and more
await system.waitTicks(0); // not possible in v1, but now possible in v2
wtf
there is no meaning to waiting 0 ticks
(still trying to understand docs ahh)
i think its made it so that you can adjust the ticks or just skip it
thank the lord our stuff was only 2 errors 💔 🙏
This is a mojang bug lol
oh
At least from what I’ve seen so far
bro discord had a huge update along minecraft too
Looks ass, but #off-topic
Channelog said Soo 🤷
playerInteractWithBlock? playerInteractWithEntity? or ItemUse has a custom component
what error?
Player use item to activate event
Cannot read property
hmm
I have claim land system
show manifest.. script version?
When player use an item, it will start the event to record starting position
i know but
^
Already update to 2.0.0
// Land Claim by Item
const CooldownSet = {}
world.events.itemUseOn.subscribe(data => {
if (data.cancel) return
const { source } = data
if (data.itemStack.typeId == Server.Setting.get("itemClaimLand")) {
const Cooldown = CooldownSet[source.name] ?? Date.now()
data.cancel = true
if (Cooldown > Date.now()) return
if (data.source.isSneaking) {
EndPos(data.source, data.block.location)
} else {
StartPos(data.source, data.block.location)
}
CooldownSet[source.name] = Date.now() + 500
}
})
This is the code
world.events?? its .afterEvents or .beforeEvents
I need to change those?
Worldevent to before/after event?
yes
Whats the difference between those? Before and after
beforeEvent allows cancellation of the event
and afterEvent just runs code after using the item
Same line
wait, your canceilling in the code
you have to use beforeEvents
Ahh
Same error hahaha damn this is so frustrating
Failed to import command | TypeError : cannot read property subscribe of undefined
does isValid() work now
most of the isValid() has changed to isValid
making it read-only
that makes sense
so for blockVolume.getBlockLocationIterator() what order are the blocks in?
is it possible to to do an import of a file such as
Import "file.js"
after a worldLoad event ?
"the BlockLocationIterator will iterate over a 3D space in the order of increasing X, followed by increasing Z followed by increasing Y. (Effectively stepping across the XZ plane, and when all the locations in that plane are exhausted, increasing the Y coordinate to the next XZ slice)"
Documentation for @minecraft/server
at my block's location
wow there are more docs websites
thanks a lot
np
// Execute the /structure command to load the chosen tree at the sapling's location plus the offset
block.dimension.runCommandAsync(`/structure load ${structure} ${x + offset.x} ${y + offset.y} ${z + offset.z}`);
}```
Error not a function
Changelog:
Removed Dimension.runCommandAsync as most commands did not actually run asynchronously. If you are looking to run a function asynchronously, please investigate using Jobs via System.runJob.
nvm
you just wrote the changelog and sent the error along? does that mean your asking for solution? or gave solution?
I dk for
now when I sent the msg I didn't read the changelog 😅
also remove the slash/ inside runCommand
it works even if it's their
🤷
{
"format_version": 2,
"header": {
"name": "§bInsanity MC V1.1",
"description": "§sMade By Dynamic!",
"min_engine_version": [1, 20, 0],
"uuid": "c6bd08e4-9223-4b69-9f4a-0cfecfa321fd",
"version": [1, 0, 0]
},
"modules": [
{
"type": "data",
"uuid": "8942c0d5-efcf-42c0-a104-9e5c424f7f63",
"version": [1, 0, 0]
},
{
"type": "script",
"language": "javascript",
"uuid": "1a75456f-8a5a-4ce3-807e-2131f2cd0709",
"entry": "index.js",
"version": [1, 0, 0]
}
],
"capabilities": [
"world_builder",
"ui",
"scripting.privileged"
],
"dependencies": [
{
"module_name": "@minecraft/server",
"version": "1.18.0-beta"
},
{
"module_name": "@minecraft/server-ui",
"version": "2.0.0-alpha"
}
],
"metadata": {
"generated_with": {
"blockbench_entity_wizard": ["1.6.0"]
}
}
}
What i do wrong
Server needs to be 2.0.0-beta
i stupid lol i didnt update mc
{
"format_version": 2,
"header": {
"name": "§bInsanity MC V1.2",
"description": "§sMade By Dynamic!",
"min_engine_version": [1, 20, 0],
"uuid": "446dec93-559a-430a-a1af-97d4be714f4b",
"version": [1, 0, 0]
},
"modules": [
{
"type": "data",
"uuid": "9d822fb9-a3b8-41af-8ff0-8ac332b3ec8a",
"version": [1, 0, 0]
},
{
"type": "script",
"language": "javascript",
"uuid": "3d290939-a59d-47a8-8dd9-3c692cf08f4c",
"entry": "index.js",
"version": [1, 0, 0]
}
],
"capabilities": [
"world_builder",
"ui",
"scripting.privileged"
],
"dependencies": [
{
"module_name": "@minecraft/server",
"version": "2.0.0-beta"
},
{
"module_name": "@minecraft/server-ui",
"version": "3.0.0-alpha"
}
],
"metadata": {
"generated_with": {
"blockbench_entity_wizard": ["1.6.0"]
}
}
}
what i do now lol
use server-ui 2.0.0-beta
Oh
don't use itemUseOn use playerinteractwithBlock and use beforeEvents too
thats what i said before
So it will be like this?
// Land Claim by Item
const CooldownSet = {}
world.beforeEvents.playerinteractwithBlock.subscribe(data => {
if (data.cancel) return
const { source } = data
if (data.itemStack.typeId == Server.Setting.get("itemClaimLand")) {
const Cooldown = CooldownSet[source.name] ?? Date.now()
data.cancel = true
if (Cooldown > Date.now()) return
if (data.source.isSneaking) {
EndPos(data.source, data.block.location)
} else {
StartPos(data.source, data.block.location)
}
CooldownSet[source.name] = Date.now() + 500
}
})
^
hell naw
playerInteractWithBlock not playerinteractwithBlock
Why detect if its canceled or not?
The player will right click endrod to start the event
Ahhh
end rod isn't interactable in the first place.
Alright its golden_shovel
huh???
Right click golden shovel to start the event
world.beforeEvents.playerInteractWithBlock.subscribe((ev, { block, player, itemStack } = ev) => {
if (block.typeId === 'minecraft:end_rod') {
if (itemStack?.typeId === 'minecraft:golden_shovel') {
// ...
} else {
// ...
}
}
});```
I have import another js to read the item by using Server.Setting.get(“itemClaimLand”)
Im not sure what could go wrong
But i can try use yours
As long as it returns the right id it would work
How to detect blocks at a block's location every 500 ticks?
what do you mean by "blocks at a block's location"
do you mean the blocks around the block's location?
Yes
Use BlockVolume and get all locations from point1 to point2 and sue in getBlock()
i still havent ported all my scripts to 2.0.0-beta lol
Can you give an example?
const volume = new BlockVolume({ x: 0, y: 0, z: 0 }, { x: 10, y: 10, z: 10 });
const blocks = Dimension.getBlocks(volume, {}, true);
for (const coord of blocks.getBlockLocationIterator()) {
const block = Dimension.getBlock(coord);
}```
if you dont need the filter for getBlocks, just use blockVolume alone
I'm still confused as to why startup event doesn't work for some people
I tried everything and it worked for me
I added that since I need to add the unloaded chunk thingy
i didn't add it yet lol since my discord keeps crashing
Why does this not work?
import { world } from "@minecraft/server";
{
world.afterEvents.entitySpawn.subscribe(({ entity }) => {
try {
if (entity.typeId === 'luv:phase2_akuma') {
const entities = entity.dimension.getEntities({ type: 'luv:phase2_akuma' });
if (entities.length > 1) {
entity.remove();
console.warn("Only one 'luv:phase2_akuma' entity can exist at a time!");
}
}
} catch (error) {
console.error("Error in entitySpawn event for luv:phase2_akuma (duplicate check):", error);
}
});
gotcha
random bracket above
Oof right
lol
WorldLoad event
I think so.
🔥
Quick suggestion for anyone wanting a quick dirty fix for their beta scripts.
- Rename your
main.js(or equivalent) to something likeold_main.js - Create a new
main.js, and the add this
import { world } from "@minecraft/server"
world.afterEvents.worldLoad.subscribe(() => {
import("./old_main")
})
This should fix any required privilege errors
lol
i guess that works
That's...
No comment.
-# (insert meme)
good no comment or bad no comment
good lol
so now you cant import scripts if the world isnt fully loaded?
I'm addicted to using lol and lmfao
It make the conversation not dry or make my response don't sound bad or angry.
do we have the same brain
you see how me adding . sounds mad lol
again, do we have the same brain?
I dunno.
I dunno.
nah but really, its not that deep.
I ain't mad.... LoL
We're getting off topic.
I still need a fix for the registering custom compoents, saddly I cannot run my server without it and I believe moving to 1.18.0 will also not work many of my functions =\
That's not the case...
Yeah
@unique acorn
Maybe you can help?
I asked him already, but nothing worked. I still cannot believe it is a bug otherwise many ppl would be asking here and the few that asked said it was fixed but dont say how it was, I tried many ways including your suggestions I saw in some conversations.
new errors with every reload
updating gonna take a few minutes
now i need to update my global dimension variable
i just have this line after my imports export const dimension = world.getDimension("overworld")
it is not possible to register custom components on world.afterEvents.worldLoad?
it might be bugged
Custom components neeed to register in world start up, no?
the problem is that the startup is not even executing and cannot register custom components
Same problem here
What is going?
that is a tought question, I have several functions and I had no control what is beta or not, but I m sure many things would be beta
i forgor to turn off my embeds for my local server 🤯
uh just read on script api 2.0.0 or watch the video
Ok
wait are you using this?
https://jaylydev.github.io/scriptapi-docs/1.21.70/classes/_minecraft_server.BlockComponentRegistry.html
You may want to look into moving to stable or wait for a hot fix
since world.playSound is gone... what did it really do? did it play the sound across all the dimensions?
i used it before
i moved my 11.5k lines project to 2.0.0 in under an hour well i havent bug tested it yet
All players, it still needs a dimension arg
ah
Yeah, what is he supposed to use?
wait so they just broke it completely
In stable release I guess? I use the preview version of 1.21.70 as of now and never had that problem
I'll update to 1.21.80 or to any update tomorrow
i just use the beta version on stable cuz updating every week on preview versions is too tiring
Or just dont use beta.
This is a mojang bug Sean
my addon uses custom component and it works
2/3 of my packs work, 1 does not
I will go back to 1.18.0
Would you mind sending me the pack in dm
using a version with no chatSend before event is impossible
but are you on beta stable?
Just wait for custom commands. Higher chance of being stable than chatSend.
today right?
Yours is work, i put the ? after itemStack
One day!
Navi could just be fucking with us and delay it till 1.21.90 or 1.22.
Whichever is next.
😭 noooooo
i just have a string function map so updating it should be easy well we have no idea how they will look but it cant be that bad
You could use scriptevent
Will it lag out if I run 70 of these all at the same time in the 500th tick? Also I need blocks from the whole overworld
1.21 🤯
wait what will we get after 1.21.90
1.21.100?
assuming they wont move to 1.22
Never saw 100s anymore
only in 1.16
yes.
Who knows. Historically in modern era, we never even reach .90.
ItemStack can return undefined if you're not holding an item when interacting, the purpose of ? is to somewhat or at least suppress that error
Then is there a way to get its location through custom components?
Custom components is for custom blocks tho.
And items
I am using custom blocks
Whyyyy
lol... moved back to 1.18.0 and also world.beforeEvents.worldInitialize.subscribe is not being executed
so that is it, sit and wait for the fix =\
Player leave after event wasn’t… terribly useful, to be fair
🙏 Before Shutdown.
Though tbf, it can be useful for decreasing waves in a mob wave gamemode.
Very niche 😛

i use it
i have an array and instead of getting players each tick i add them when they join or leave
They renamed it.
wait what version is this
I am literally using playerLeave and playerJoin/Spawn no issues
you need to run it inside something like worldLoad
insert the code in world.afterevents.worldload and try
oh someone already told you😅
deepseek told Me the to do that
and it worked for me
Im doing right now
My luck is that I keep all my scripts organized so I can correct them more easily
nice.
whoa flat world customization
anyone having issues with transferPlayer working in 2.0.0?
it just doesn't do anything
Did you make server admin 2.0.0-beta?
If you did- don't
Hmm
I'll test it when I get home

lmao
anything special u can do with the @minecraft/server alpha?
which u cant do with beta
im do lazy to read
Did they change before Event world initiliaze?
Yes
system.beforeEvents.startup.subscribe()
this is now what you use to register custom components
allows you to run code right before the world is closed
which is (of course) in read mode only
They removed runCommandAsync?
Ye
yep
can anyone explain what's happening here?
change @minecraft/server-ui to 2.0.0-beta
how this make sense
{
"format_version": 2,
"header": {
"description": "§l§bCustom Commands By §l§3InsanityMC",
"name": "§l§bCustom Commands V1.1",
"uuid": "863a0f3c-c988-4aa2-ba5b-2333c9926b2e",
"version": [1, 0, 0],
"min_engine_version": [1, 21, 62]
},
"modules": [
{
"description": "Custom Commands",
"entry": "scripts/help.js",
"type": "script",
"uuid": "3819b6af-4bd1-4d59-8ef3-51b107c3b500",
"version": [1, 0, 0]
}
],
"dependencies": [
{
"module_name": "@minecraft/server",
"version": "2.0.0-beta"
},
{
"module_name": "@minecraft/server-ui",
"version": "2.0.0-beta"
}
]
}
did you leave and rejoin the world
I did bro and this is the result
Your pack isn't updating properly, then
it says the ui module is requesting some non existant version lmao
yeah
then restart your game completly

were you replying to me? if so, plese explain what you mean?
Your game is saying the pack is using old versions
The pack's manifest is using the latest versions
So the game isn't reading your changes properly
same here lol
Are you using dev folders
yes
no
Use dev packs, old version of pack is cached to your world
The correct way to create addons is by using the development_behavior_packs and development_resource_packs folders. Storing your addons here will allow you to reload the world to see addon changes, and will prevent pack caching issues.
You can work directly in the world, or in behavior_packs/resource_packs, but you need an understanding of manifest-versions and caching to avoid issues.
We highly recommend using the development_*_packs folders.
Yours is just that both ui & server have to use 2.0.0-beta
i forgot to lol ik how to do it
Because that's what is needed 
lol
does anyone know how to get the aux / numerical id of custom blocks
I mean I was using the stable version of ui module just fine up until this .70 so what happened now?
mc messes packs up
Scripts v2 happened
ofcourse, I'm the idiot for thinking that stable versions are going to be stable
i heard / commands could be done soon enough
Already can, as of today
dam i need to get that done
Server 2.0.0-beta needs server-ui 2.0.0-beta as well
All stable or none stable.
my dev packs not loading the file for commands stupid mc
The lore limit got increased right?
Yes
whats the lore limit now?
const overworld = world.getDimension("overworld"),
nether = world.getDimension("nether"),
end = world.getDimension("the end");
Privilege error in world.getDimension
overworld is broke for me lol
dam
100 lines
well
what is the fix for dimensions etc now
let overworld;
let nether;
let end;
world.afterEvents.worldLoad.subscribe(() => {
overworld = world.getDimension("overworld")
nether = world.getDimension("nether")
end = world.getDimension("the_end")
})
that seems hacky but damn ill take it 😭
Thank you I'm going to try
it may look hacky but, not sure if theres a better solution either
btw uhh you put ,s in there
like an array
I just copied that part from Felipe's message lol
I'm still a little confused as to where to put this, I have a pretty big coadbase, is there a spot where I can put this where it would work throughout?
didnt notice it
await null 🗿
so you just do
await null
const dimension = world.getDimension(...)
that wouldn't work
really?
wait lemme try
How to change the name of an already spawned entity without name tags?
You done? Cus I tested it, and it work
is there anyway I could get an early view at how custom component parameters will work?
like is it on preview or something
yep it worked
do I have to put that inside every async function that uses world.getDimension
Microsoft docs has its experimental stuff sync with the preview stuff
import { thing } from "./blablabla";
await null;
//your old code below
that easy?
yep
😭
that easy
that feels so cheap
If you don't want to deal with earlyPrivilage stuff, thats the simple solution
I'm so tempted to fix it the right way but I have so much code to fix 😭
where? I've never checked preview before xd
if I do it with await null; I know its gonna make it so I can't use the command system, because bedrock commands load very early into world load
dimension.getEntities(QueryOptions)
.forEach(entity=>{
entity.nameTag = "Grumm"
})
Also did world.getDimension get broken in the latest update?
New privilege system, "early execution"
You can't use most methods from the world class, except certain ones like the system class. (Basically new timings!)
Only happens if you call it outside any event.subscribe() or function scope.
import { stuff } from "module";
//Early Execution scope
world.sendMessage("UwU") //Privilage Error here
world.getDimension("overworld") //Privilage Error here
world.afterEvents.itemUse.subscribe((e)=>{
//code is fine here
})
system.runInterval(()=>{
//safe here too
})
Bruhh
function stopSound(player, sound) {
if (player?.isValid()) {
player.runCommand(`stopsound @s "${sound}"`).catch(error => {
console.warn(`Failed to stop '${sound}' for ${player?.name || "unknown"}: ${error.message}`);
});
}
}```
in a function like this, how would we rework it so "isValid" works properly again?
its not a boolean value
or is it just isValid() -> isValid
do .isValid instead of .isValid() iirc
Thats def the most interesting change out of all of this
so if runCommandAsync wasn't even async... runCommand should be ok?
Ye
I know theres a method for sounds, but when I tried to use it it played in the left or right ear when I played them on the player
kinda bugged
Yeah, sounds have always been janky
thats the only reason im using runCommand guys 😭 don't kill me
Never had a pleasant experience with sounds, unless they're omnidirectional
What they change here?
😭
system.beforeEvents.startup.subscribe(....
Thanks
so like one thing i dont understand with runJob is that it finishes but i still have slowdowns in job queue for like a few seconds after
Could I not theoretically CTRL+F my codebase and replace the old before/after events with the new startup stuff or is the underlying format different?
It's pretty much the same, just be careful
does anyone have a list of minecraft blocks by how often they appear in a world
It takes some time to cool down
- Air
- maybe some dirt
- maybe some dirt
- The Rot
- well maybe someone knows how to save a large area of blocks to an array
- blockVolume
that iterates over locations
Yes now think
Maybe perhaps you could call getBlock for all of those locations and store them in an array
Just a theory
you know how demanding millions of getBlock calls is?
Yes but thats what you want lol, theres no other way except for external tools which probably is your way to go
public* blockVolumeToBlockTypeIdArray(blockVolume: BlockVolume) {
const span = blockVolume.getSpan()
const totalSize = span.x*span.y*span.z
let i = 0;
for (const id of blockById) {
i++
for (const location of dimension.getBlocks(blockVolume, { includeTypes: [id] }).getBlockLocationIterator()) {
this.vectorTypeIdArray.push({ blockId: id, position: location })
yield;
}
if(totalSize==this.vectorTypeIdArray.length) break;
}
console.log(`Found ${this.vectorTypeIdArray.length} blocks out of ${totalSize} in ${i} iterations`)
const uniqueIds = [...new Set(this.vectorTypeIdArray.map(item => item.blockId))];
console.log(`Unique block IDs: ${uniqueIds.join(", ")}`);
}
this is faster assuming i hit all the blocks early
How to get block location of my custom block through custom component? Do I do it through blockontick?
In a nutshell, ye
why tf is the id for the stairs rotation state "weirdo_direction"
stairs are weirdo
That's what MCPE devs called the non slab part of the stair.
Weird am I right?
custom commands requiring namespaces is odd
It is needed to prevent a more likely collision.
There's a whole discussion in #1354481778278273246 if you wanna catch up.
thanks
how
Nah, I'd await null; 🗿
Two questions.
Does the structure manager have access to structures in the BP, and do I need a ticking area to place structure with the structure manager.
Using Server 2.0.0-beta
Yes to both.
Is this new to 2.0.0? @wary edge
Not to my knowledge.
I still have to get used to the script startup and timing stuff
I remeber you can make an entity that ticks the world around it using minecraft:tick_world, basically unlimited ticking area
Every update is just gonna confuse newbies even more
I'm newbies
why am I getting this error:
Version conflict for module @minecraft/server.
2.0.0-beta requested by (pack name) - 1.0.0
1.3.0 requested by @minecraft/server-ui 1.3.0
tf do you mean "how" i literally explained everything
Both needs to use beta.
@minecraft/server-ui needs to be 2.0.0-beta
Yeah I thought before and after events was bad 😭
my bad jit
doesn't sound like something you should rely on
Please pass the new manifest
just put 2.0.0-beta in your "@minecraft/server" dependency
Thanks
I updated my 400 line script with no errors 🙂
i did re-write 600 line of code but the part related to the update is not much
was using an open source script that i finally decided to write my own
"world.beforeEvents.itemUseOn.subscribe" what is the new sintax?
playerInteractWithBlock
remains as a beforeEvent?
yes
there is an itemStack property there
Beta & Preview - 1.21.80.22
ㅤ
Experimental Technical Updates
Custom Commands
- Added support for custom commands authored in script. The new CustomCommandRegistry is provided when listening to ModuleStartupEvent. More APIs in the area will come in the coming weeks.
so i don't need to use the before chatSend 😄
It's still in preview
so I can't summon a "ticking" entity to a chunk thats unloaded?
I made an entity that acts as a ticking area but I can't even place it in the location I need it 😭
try tp
teleport the entity there?
yep
😭
try summon with commands first
I can't most of my code expects async
idk something is really bugged, I think it has to do with runCommand being wierd now
Is it just not possible with scripts to decrease a player's LEVEL?
I can decrease the total xp just fine
But it will not, no matter what I do, push it below the player's current level and level them down
yeah custom slash commands :D
Never mind it does work my logic was just wrong
player.runCommandAsync('execute at @s anchored eyes positioned ^^0.8^ run particle minecraft:basic_flame_particle');
what is the new sintax?
runCommandAsync got removed?
yeah
gotta use runCommand (non-async)
the original wasn't async to begin with anyways
it was broken
ok ty
Okay can someone please re-write this script for me cuz I'm stupid and this js const expLoss = (body.getTotalXp() / 10) const expHad = body.xpEarnedAtCurrentLevel if (expHad < expLoss) { system.run(() => { body.addLevels(-1) system.run(() => { body.addExperience(body.xpEarnedAtCurrentLevel - (Math.abs(expHad - expLoss))) }) }) } else { body.addExperience(-expLoss) }
...doesn't work fully. "Body" here is the dead entity and I want players to lose 10% of their total xp when they die.
The issue is that scripts won't decrease the player's LEVEL when it reaches that threshold and the logic I have doesn't work to simulate it.
how do i fix this?
const overworld = world.getDimension('overworld');
seems to struggle
?
should this work if its in the worldLoad afterEvents?
ok haha thx
There is no world since world isnt loaded.
I have an entity that does not have this component, even doing this gives an error in the log:
let markVariant = projectile?.getComponent("mark_variant").value ?? null
projectile?.getComponent()?.value ?? undefined
so now all the code has to be inside the worldLoadAfterEvent?
I didn't quite understand all that stuff
Yeah.
[Scripting][error]-Error: Failed to call function 'getComponent' due to the Entity being invalid (has the Entity been removed?). at <anonymous> (projectileHitEntity.js:10)
other events like itemUse and chatSend included inside the worldLoad?
No
Then the entity is invalid.
You use projectileHitEntity? Or Block?
alr thx
projectileHitEntity
Custom projectile?
just remove the destroy on hit thing
And remove the projectile manually in the event listener using projectile.remove()
and download the npm
Yeah the entity is gone.
I already told you the solution, remove the remove_on_hit thingy in your projectile and do projectile.remove() instead in the scripts
Projectile api don't have that?
okay
what?
I'm having a Mandela effect or something?
a projectile is an entity, so why wouldnt remove() work?
I dunno... I just woke up lol
Everything is floaty rn
?
im confused about what minato said too
im not questioning your logic or anything
The problem is that there are projects that must have this, how can I prevent the error?
that must have what?
projectiles dont require remove_on_hit
wdym
also I think it would be better just to give the projectile the instant despawn component through component groups, triggered from on_hit
no scripts needed
Just asking a question, What's confusing about it?
Does projectile api have a removeOnHit property or not
Sorry, I was a bit floaty earlier
doesnt seem like there is
i just read something different seconds ago
Lol
Did they remove CustomComponent from API 2.0? Is there no other alternative without me having to use an older version?
No.
Do I have to use an old version then?
No.
Smokey most used reply
No.
No
Same deal, just registered in system.beforeEvents.startup
the startup doesn't return anything
It’s an event
Please send an example
I did it, thanks
What was the problem you were having
that event wasn't firing for me
never seen before
It is now?
eh..... no
Idk how it doesn't work.
But Jayly said it's because of the overhead I have on initialization, so the event doesn't fire until after it's supposed to... somehow that makes logical sense
I should test that out too
disguise, I forgot to put the beta in the manifest
Waiter! Waiter! More v2 nonsense, please!
How do I solve this? @valid ice
system.beforeEvents.startup.subscribe(ev => {
ev.blockComponentRegistry.registerCustomComponent("dz:tick", {
onTick: ((dz) => {
const { block, dimension } = dz;
if (block) {
callback(block, dimension);
}
})
});
});```
Make sure you're on 2.0.0-beta n' 1.21.70
dev packs?
That's the event that registers custom components, so yes
Jayly said what the problem was lol
Speaking of fixing stuff, I've fixed my code and refined it so much more now so it's easily expandable
try {
for (let i = 1; i <= 20; i++) {
let tall_wedge = `tall_wedge${i}`
camoState = getCamoState(blockType, tall_wedge)
if (camoState){
blockKey = tall_wedge
break;
}
}
} catch (error) {
console.log("An error has occurred:", error)
}``` Instead of
```js
const tall_wedges = ["tall_wedge1", "tall_wedge2", "tall_wedge3", "tall_wedge4","tall_wedge5", "tall_wedge6", "tall_wedge7", "tall_wedge8", "tall_wedge9", "tall_wedge10", "tall_wedge11", "tall_wedge12", "tall_wedge13", "tall_wedge14", "tall_wedge15", "tall_wedge16", "tall_wedge17"]
for (const tall_wedge of tall_wedges) {
camoState = getCamoState(blockType, tall_wedge)
if (camoState){
blockKey = tall_wedge
break;
}
};
if (!camoState) return;```
It's so much better xD

neat
although, I might change the 20 in for (let i = 1; i <= 20; i++) to a const to make it easier to read
When I put it on mcpedl or wherever, I do want people to be able to add their own blocks to it, so I need to work a lot more on the easy editing
how would it make it easier to read
I'd like to have the variables that need changing near the top of the file, so it's all in 1 place
I thought you meant change let to const
oh no lol
Just the ceiling
You're grand, man
No worries 👍
And when I'm done with the tall, medium and small wedges, Imma start working on a custom lantern frame block
They all use the same Map array for their textures and states across the different types
what's the difference between world load and system startup
aww man, I was about to send it.

it thats why world dynamic and scorboard need to be add to worldLoad or system.run ?
Yes, if they are in a scope that excute before the world actually load
Someone to help me my database the new version of minecraft is damaged :/
yes
anyone able to help on this issue im having
do you know how to fix this
[Scripting][error]-TypeError: Incorrect number of arguments to function. Expected 2, received 4 at <anonymous> (Epics/Pokemon Battles/main.js:80)
below is the line it refers to with the error
hitter.applyKnockback(direction.x, direction.z, -2, 0.5);
hitter.applyKnockback({x:direction.x*-2, z:direction.z*-2}, 0.5);
thank you
Note the changes :)
Hoe hand can you help me fix a database please@valid ice
such a ridiculous change imo but im still new to scripts
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
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]
wy?
[Scripting][error]-Plugin [Test All Addons - 1.0.0] - failed to create context.
[Scripting][error]-Plugin [Test All Addons] - version conflict for module [@minecraft/server].
[2.0.0-beta] requested by [Test All Addons - 1.0.0],
[1.3.0] requested by [@minecraft/server-ui - 1.3.0]
[Scripting][error]-Plugin [Test All Addons - 1.0.0] - run failed, no runtime or context available.
{
"format_version": 2,
"metadata": {
"authors": [
"IIBl4z3MasterII"
],
"generated_with": {
"bridge": [
"2.7.44"
],
"dash": [
"0.11.7"
]
}
},
"header": {
"name": "Test All Addons",
"description": "Test All Addon By: IIBl4z3MasterII",
"min_engine_version": [
1,
21,
70
],
"uuid": "d9e585e4-5aa9-47f2-9b7d-1fdfe73d4a5e",
"version": [
1,
0,
0
]
},
"modules": [
{
"type": "data",
"uuid": "667c1f9e-adfa-400e-ad6b-29156aa577b5",
"version": [
1,
0,
0
]
},
{
"type": "script",
"language": "javascript",
"uuid": "01ea94d3-f0a6-46eb-9222-c939e95ca9f8",
"entry": "scripts/index.js",
"version": [
1,
0,
0
]
}
],
"dependencies": [
{
"uuid": "5fdaa6a1-ac4d-47e0-9335-b30dc92e6281",
"version": [
1,
0,
0
]
},
{
"module_name": "@minecraft/server",
"version": "2.0.0-beta"
},
{
"module_name": "@minecraft/server-ui",
"version": "1.3.0"
}
]
}
version":"1.3.0" = version":"2.0.0"-beta"
thanks
Did the addon achievements change make it so all addons now allow achievements or how does that work?
It is being patched by MS...but yes. So long it doesnt use experimental.
Wdym it's being patched lol
It will only work for Marketplace.
So currently it's all, but in the future it will be marketplace only
Ye.
☹️
[Scripting] LocationInUnloadedChunkError: Trying to access location (-502.0, 11.0, 9.0) which is not in a chunk currently loaded and ticking. at <anonymous>
system.runInterval(() => {
world.sendMessage({ translate: "server.texto_2" })
}, 5500)
You sure that is the affected call? That has little to do with a location
its possible to get client camera movement?
NOOOOOOOOOOO
Someone to help me my database the new version of minecraft is damaged :/ Someone help me
Not the database, most likely the code needs to be wrapped in the worldLoad event
Other code
Database will send errors but it's the new 2.0.0-beta change that's messing with it
Makes sense tbh
You sent the wrong code btw
And it's saying that the chunk you're trying to search at those coordinates, isn't loaded
no
Yes, that doesn't look like it has anything to even do with chunks
Or anything about locating
in server forms, does divider, label and header also count in formValues?
the log says that the error is there
Where does it indicate that?
world.sendMessage({ translate: "server.texto_2" })
[Scripting] LocationInUnloadedChunkError: Trying to access location (-502.0, 11.0, 9.0) which is not in a chunk currently loaded and ticking. at <anonymous> (principal.js:4)
import { world, system } from "@minecraft/server";
system.runInterval(() => {
world.sendMessage({ translate: "server.texto_1" })
}, 6500)
Thank you
just need to ask for the file name
ofc it wouldnt, nvm
if your in afterEvents it will work, but for beforeEvents, you can await null
we're way past 100k
Hi, how to make custom name for minecraft:paper ?
I want to make sure player got custom name that I set for that paper
My code is
{ item = "paper" , quantity= 3}
So it will
runCommand(`give @s ${item} ${quantity})
Nvm it's setLore
mfw player.getComponent("inventory")
https://youtu.be/cXfMwcDg1Lo
no more custom prefix
With 1.21.80.22 Preview versions of Minecraft, you can create your own script commands! Find out how in this video.
Documentation: https://learn.microsoft.com/minecraft/creator/documents/customcommands
Code sample used in this video: https://github.com/microsoft/minecraft-scripting-samples/tree/main/custom-commands
so now world.getDimension() requires to be ran in system.run()
Not really, it require the world to fully load
that's really annoying why didnt they just made that scripts get loaded after the world fully loads
They can't delay a function execution just like that
tfw i have to change every Date.now() to system.currentTick because of game pause feature
this seems good enough
Is the namespace required for every command?
wow
i mean the creator:, do we need to add that?
is this pause feature preview or 1.21.70
nope
you can have any namespace you want
different
ye but can we not add it?
not using identifier
no, namespace is required
wait
doesn't it need a prefix?
huh
/namespace:command
1.21.70
Navi said they might look into ways to allow the use of custom commands without namespace but still make it a requirement for marketplace content
The one time making a server is a good thing 😭
const healthComp = player.getComponent("health");
if (healthComp) {
healthComp.currentValue = Math.min(healthComp.value, healthComp.currentValue + recovered);
}
error: currentValue is read-only
or how to heal player?
without effects
setCurrentValue?
can you show an example?
healthComp.value isnt a thing
const current = healthComp.currentValue;
healthComp.setCurrentValue(current + recovered)?
yes
Yeah this would be game changing haha
fr
This hurts for real
perhaps mention why and suggest a better way
runCommandAsync() removed ;-;
good old "runCommand" from now on since not alot of commands ingame are native
world.afterEvents.worldLoad.subscribe(ev => {
await null;
world.getDimension("overworld").runCommand(`scoreboard players add @p playjoined 1`);
world.getDimension("overworld").runCommand(`scoreboard players set @p kit 0`);
world.getDimension("overworld").runCommand(`function firstjoin`);
}```
code look different but the result is same
you dont need await null there
he use runTimeout see the code
await null is also a delay
why did you open discord inside your french class
(jk)
peak
?
How to remove durability from player armor?
anyone ever get errors for things that just don't exist in their code?
oh, the content log error is just spitting out misinfo 😔 figured it out
[Scripting][error]-ReferenceError: Native property getter [World::scoreboard] does not have required privileges. at <anonymous> (modulo/all_class/database/ScoreboardAapi.js:2)
[Scripting][error]-Plugin [script expansion - 1.0.0] - [main.js] ran with error: [ReferenceError: Native property getter [World::scoreboard] does not have required privileges. at <anonymous> (modulo/all_class/database/ScoreboardAapi.js:2)
Does anyone know how to resolve this error in the new stable beta version?
let scoreboard;
world.afterEvents.worldLoad.subscribe(() => {
scoreboard = world.scoreboard;
})
What would I have to do to make this variable global?
using this?
yeah
I tested it and couldn't do it, can you include this in the code for me?
is my using TypeScript
import { Entity, ScoreboardIdentity, ScoreboardObjective, world } from "@minecraft/server";
let scoreboard;
world.afterEvents.worldLoad.subscribe(() => {
scoreboard = world.scoreboard;
})
class Scoreboard {
objectiveId: string;
objectiveDisplayName: string;
objective: ScoreboardObjective | undefined;
constructor(objectiveId: string, objectiveDisplayName: string = objectiveId) {
this.objectiveId = objectiveId;
this.objectiveDisplayName = objectiveDisplayName;
if (!Scoreboard.hasObjective(objectiveId)) {
Scoreboard.addObjective(objectiveId, objectiveDisplayName);
}
this.objective = Scoreboard.getObjective(this.objectiveId);
this.objectiveDisplayName = this.objective?.displayName || objectiveDisplayName;
}
static getObjective(objectiveId: string): ScoreboardObjective | undefined {
return scoreboard.getObjective(objectiveId);
}
static getParticipants(): ScoreboardIdentity[] {
return scoreboard.getParticipants();
}
static getObjectives(): ScoreboardObjective[] {
return scoreboard.getObjectives();
}
static addObjective(objectiveId: string, displayName: string = objectiveId): ScoreboardObjective {
return scoreboard.addObjective(objectiveId, displayName);
}
static removeObjective(objectiveId: string): boolean {
return scoreboard.removeObjective(objectiveId);
}
static hasObjective(objectiveId: string): boolean {
return scoreboard.getObjective(objectiveId) !== undefined;
}
getObjectiveInfo(): object | undefined {
const objective = this.objective;
return objective ? { ...objective, size: this.size } : undefined;
}
getScore(participant: string | Entity | ScoreboardIdentity): number | undefined {
return this.objective?.getScore(participant);
}
setScore(participant: string | Entity | ScoreboardIdentity, score: number): number | undefined {
this.objective?.setScore(participant, score);
return this.getScore(participant);
}
clearParticipants(): void {
scoreboard.getParticipants().forEach(participant => {
this.removeParticipant(participant.displayName);
});
}
hasParticipant(participant: string | Entity | ScoreboardIdentity): boolean {
return this.objective?.hasParticipant(participant) || false;
}
getParticipants(): ScoreboardIdentity[] | undefined {
return scoreboard.getObjective(this.objectiveId)?.getParticipants();
}
removeParticipant(participant: string | Entity | ScoreboardIdentity): boolean {
return this.objective?.removeParticipant(participant) || false;
}
get size(): number {
return this.objective?.getParticipants().length || 0;
}
}
export {
Scoreboard
};
is there a reliable way to detect the host of a realm?
man, I'm screwed, the amount of coding I did
why?
"[Scripting][warning]-Error sending world message: ReferenceError: Native function [World::sendMessage] does not have required privileges."
function safeSendMessage(message) {
try {
world.sendMessage(message);
} catch (error) {
console.warn("Error sending world message:", error);
}
}
-
Send code in a code block using the back tick (`):
```
code here...
``` -
You need to put the world.sendMessage(...) into system.run(()=>{ here }) like
function safeSendMessage(message) {
try {
system.run(()=>{
world.sendMessage(message);
})
} catch (error) {
console.warn("Error sending world message:", error);
}
}
@elder heath
Is anyone excited for custom commands??
I certainly am
Unfortunately I don't know how to use typescript lol
Is there a way to get an item's number ID using scripts? I only know of using a utility mod to get the ID number, but not a "legit" way
how do you make a simple custom cmd without typescript?
Woah
It's in preview right now and they have a tutorial on the docs
Can't right now, I think
oh, ty
you can use javascript too
Oh shoot
I found out there was custom commands from the Minecraft Creator Channel
Which used typescript
And typescript feels "non-standard" to me so I just automatically assumed it was ts only
minecraft can't even read typescript in the first place
they just compile their code to js
Well now I need to figure out how to make them, whether or whether not there's autocompletions in Bridge
you compile to js so minecraft can read it, so you can use js only. If they show typescript, just do some simple changes and it will be js
Sounds good to me then
Although it's very new and unstable (probably) and I'll need to update the scripts when the next update drops :/
system.beforeEvents.startup.subscribe((data) => {
data.customCommandRegistry.registerCommand({
name: "cen:sayhello",
description: "says hi",
permissionLevel: CustomCommandPermissionLevel.Any
}, () => {
world.sendMessage("hi!")
return {
status: 0
}
})
})
this is an example
/cen:sayhello
I'll use the docs for more in-depth tutorials, thanks, and things like parameters and outputs are gonna be a bit of learning
Shouldn't be too hard though
Note: The namespace (cen:sayhello) is required. It can be a: or reallylongnamespaceidkwhy: but it needs one
just use the docs
Yeah
and remember it's only in preview right now
also status: 0 means success
status: 1 is failure
And new, unlike chatSend
chatSend seems pretty stable to me by now
Good to know
yes, I don't know what really is still "beta" about it
Gah, the docs have the tutorials in typescript
Why does typescript even exist as a scripting option if it's just an alternative JavaScript that Minecraft can't even read on its own?
minecraft isn't the only one using javascript or typescript
typescript has more features ig
even tho I don't use it
It still gets compiled into JavaScript
Which means it has to have the same features
Typescript is amazing for larger projects and for types safety.
Not exactly sure what you mean by "types safety" but ok
look it up
Typescript shows and uses types more than javascript, so you can specify, basically, what type you want variables and stuff to be, what type a function returns, etc.
Oh ok
Just because it gets compiled in minecraft doesn't mean it's useless
It's basically like having a function. Why not just copy and paste all the function code into everywhere it's needed instead of just calling the function?
Because you don't want to, or it wouldn't be right
It's helpful and in some cases can solve issues that may not work in javascript alone, or help beginners so they don't have to remember complex tasks
Do what is best for you, and that for us is typescript
Oh, sorry, and thanks too.
let objective = world.scoreboard.getObjective("teste") ?? world.scoreboard.addObjective("Teste", "");
does not have required privileges.
I haven't been able to use worldLoad so far
use system.run()
but then my global variables don't work in functions and other things
noo that's not how simple it is.
it's a global variable right?
let obj;
world.afterEvents.worldLoad.subscribe(() => {
obj = world.scoreboard....
});```
I defined the variable first, empty, then set the value of it in system run, then (if needed) export it after
like shown above
and how do you do this for a class that uses world?
You should be able to do system.run in the class. Otherwise, provide context for better help please
Does anyone have a "legit" way to get block/item number IDs?
I'm using a class that creates a database using a scoreboard, but every time I call it, I get that privilege error.
.
try surrounding code with system.run(()=>{...})
typeId?
or numberId
number ID:
There is a website where they provide this
There probably is, but I need it for custom items as well
Well, I've never seen a code that takes the ID as a number
You won't understand if you don't try it... With javascript you will have a lot of errors that you'll need to fix AFTER you execute the code in minecraft and the console yells at you. With typescript you avoid most TypeErrors and even some logical errors while coding.
Which specific site would you be referring to?
How do I load the class so this shit stops returning an error?
Someone help me fix a problem
❌
Ummm
Or check the Microsoft docs
you have to specify the id in the object and get it later
That is what I have but the typeIds list is not updated as of right now.
whats with the x
"Someone help me" without any code or real question is no bounds for help.
an OA act, you don't need to "X" it just for that, just say give the code.
I was not trying to show disrespect or rudeness
there's more respectful ways
What you did is kinda rude ngl.
on the other side, they couldive actually asked
I don't know what the problem is
Okay I do apologize, it was not meant to say anything like you don't deserve or get help.
Nariz, casi inglés
you may have put the const name wrong
br?
?
Are you sure the file you're editing is the right one?
Is HomeSystem defined in your main file? Imported?
which country are you from
I've already checked several times aaaaa
As I can see the HomeSystem is in the same file, I don't think it should throw isn't defined error.
what if it is const?
HomeSystem is in sethome.js not main


