#Script API General
1 messages · Page 19 of 1
const item = new ItemStack("minecraft:bow", 1)
item.getComponent("minecraft:enchantable").addEnchantment({ type: "unbreaking", level: 1 })
inventory.addItem(item)
I always somehow forget the syntex for .addEnchantment notation
could someone help
try
export function tick_block(block, player) {
const entities = block.dimension.getEntities({maxDistance:10,location:block.location,type:"minecraft:player"});
for (sla of entities) {
sla.runCommandAsync("execute as @s run say sla");
}
}
check the docs
that almost what we do all the time someone ask
.addEnchantment({ type: new EnchantmentType("unbreaking"), level: 1 })
Thank you
Yeah i should start more, just a little more learning because its in TS
is there a calculation of getting how far applyKnockback can push in block distance
It didn't work
can i make targeting skill ?
what is maxDistance limit in getEntities method
may be reder distance
so the conclusion is 128 "maybe" the limit
It would be sim fistance likely
its similar to @e
So then sim dist yeah
whatever's loaded
theres damage sensor tutorial for entities based on tags
not really script api related though
Nope, player.json still. Waiting on that before event cancel for entities
does anyone know how I can get the values of a state of a block?
bruh
How do I make it so Entities also gets this?
system.runInterval(() => {
world.getPlayers().forEach((player) => {
if (player.hasTag("kekkizyutuburn")) {
player.setOnFire(100, true)
}
})
}, 1)
For each dimension, use the getEntities method. You may want to filter out some entities for better performance
So I do
world.getEntities?
Key phrase there is "for each dimension". Minecraft doesn't let us grab all entities globally, like it does for players
const Overworld = world.getDimension("overworld");
Overworld.getEntities().forEach();
There's probably a more dynamic way to grab dimensions, via some DimensionTypes class or similar
Wait what does this do
You gotta explain everything dawg
world.getDimension("overworld") stores the Overworld dimension into a variable. That class represents anything you can do in a given dimension—and in this case, we can call the getEntities method. That will grab all entities in the Overworld
Check out the docs for the Dimension class to see more of what it can do: https://learn.microsoft.com/en-us/minecraft/creator/scriptapi/minecraft/server/dimension
Let me know if you have any other questions about that
Might be better if you open a forum in #1067535382285135923
Hello. I am trying to have my custom block, automatically destroy, when the block underneath == "air"
Just like all of the vanilla blocks.
Is there a placement_component for blocks. or something similar that i can tackle in script?
custom_component.tick maybe?
onTick customComponent
You need to set that the block ticks in the JSON
export function tick_block(block, player) {
const entities = block.dimension.getEntities({maxDistance:10,location:block.location,type:"minecraft:player"});
if (entities.length < 1) return;
block.dimension.runCommandAsync("execute as @p run say sla");
}
help
does not work, and does not show error
Damn so custom_component is best way to handle this? There is no placement_filter component? so they auto destroy?
Unfortunately, placement_filter is very limited 😕
You asked for scripting api solutions
So
Yes i did. But i am Hoping for a more direct solution?
scripting was just my first thought
Would anyone know why setScore isn't working? The rest of the code works fine its just not setting the score in that specific section and not sure why because it's in scope
Unless you list out every block aside air for the placement filter componrnt
you forgot break; on the switch statements
ah yes tyty
Am I stupid or is Bridge buggy?
Minecraft server 1.14.0-beta
Minecraft server ui 1.3.0-beta
Gametest idk
I deleted Gametest
I don't use
Is there a way to detect when the world closes?
nah
player leave and player count?
keep in mind this don't work when force closing
Would that work if the player who's leaving is the host and other players are still on?
actually that won't work with servers
let me see if there is another way
for hosted worlds it dose
Wait so you tested it with more than one players in the world?
no just me
Is there a way to check if a block is opaque?
isSolid
That's only in beta 🥲
Yeah...its unlikely for it to be in stable due to the recent qna. Theyre gonna split up solidity
nooo
Received this syntax error with this code. What's up?
if (player.getGameMode === GameMode.creative) continue;
This condition will always return 'false' since the types '() => GameMode' and 'GameMode' have no overlap. (2367)
Oh nvm I'm dumb
Missing two entire parentheses
xd
btw you dont need to import GameMode, you can just use a string.
So just === 'creative'
yes
How can I convert three values into a Vector3 (for teleportation and dynamic properties)? I can do without it but I'd like to learn
If you have vector library you can just use new Vector3(x, y, z). But you can also do {x: x, y: y, z: z}.
I don't think I have a library for it; does the object work in place of Vector3 (such as player.teleport())?
Yes
anyone know why my enchantment isn't showing? All the code is running including the addEnchant but it's not appearing on my item
when I do it with a slot I get this
which was why I did getItem
const inv = player.getComponent("inventory").container;
let slot = inv.size;
while (slot--) {
const itemSlot = inv.getSlot(slot);
if (!itemSlot.hasItem()) continue;
//const item = itemSlot.getItem();
switch (itemSlot.typeId) {
case "minecraft:wooden_sword":
const enchantments = itemSlot?.getComponent("enchantable");
if (enchantments) {
enchantments.addEnchantment({ type: new EnchantmentType("unbreaking"), level: 1 });
}
break;
indentation has gone out the window there lmao
hope thats readable
wouldn't item need to be inside the while loop otherwise it won't update as you search through the inv?
What's the difference between world.getPlayers and world.getAllPlayers? Wiki says it's players vs active players but I don't know what it means
getPlayers are people on the world, all players is everyone ever logged on the world, like scoreboards
how so?
getAllPlayers() will return to an array of all online players in the world. getPlayers() allows you to use EntityQueryOptions, so that you can filter which players to get. If you don't provide an options in getPlayers() it will be the same as getAllPlayers().
How can I use EntityQueryOptions to limit selection to solely online players?
They both get an active players in the wolrd.
well you cannot get offline players in general.
Then what did they mean by [this](#1067535608660107284 message)?
Still having the same issue where the enchant doesn't apply
no error messages in log
That's wrong.
well, I guess they made a mistake.
Ok I believe I understand, thank you
apologies 🥲
This is their differences
I wonder why getAllPlayers exists then if that's the case
I'm trying to get all players and put them in a Modal form but Typescript is complaining that world.getAllPlayers() isn't an array?
One moment
no change
No entity query filter'
you but
you can just not use the filter in getPlayers.
well yea
I put warns around it and both are running so I literally have no clue lol
BP/scripts/main.ts
const allPlayers = world.getAllPlayers();
menu.dropdown("Modify per-player menu:", allPlayers, 0);
Argument of type 'Player[]' is not assignable to parameter of type '(string | RawMessage)[]'.
Type 'Player' is not assignable to type 'string | RawMessage'.
Type 'Player' has no properties in common with type 'RawMessage'.
Wait I may have it, gotta do with mapping
It will return an instance of player, that field requires an array of string. Try this.
const allPlayers = world.getAllPlayers().map(player => player.name)
That's what I was thinking; no errors now. Thanks!
you gotta re-set the item after adding enchants
adding the enchants only modifies the JS item object, not the minecraft item, so you have to set the item to use it's new JS object state
Isn't that more of a question for #1067876857103536159?
is there a way to get block and entity bounding boxes?
no
or did someone else did that?
For some reason the dropdown gets duplicated, it sometimes happens but I don't understand why
It works perfectly here
Someone help me with #1281939985230069761 please
nvm fixed
How can I open a menu on a player's screen?
When player A presses a button, a menu will open on player B's screen.
was old script api able to cancel entityHit or entityHurt events?
is there a way for me to test if an item has a specific enchant on it?
No
hasEnchantment
Can you give me an example syntax?
I saw it in documentation and couldn't figure it out
tyty. I tried searching too but I got completely different results for some reason
thank you anyways
const entities = block.dimension.getEntities({ location: { x: blockLocation.x, y: blockLocation.y, z: blockLocation.z + 1 }, volume: { x: 0, y: 0, z: range - 1 } });
``` Any ideas on how to shrink this volume so it's not a full block size and only around 0.9? Current issue is that this yoinks all entities in an area around 1.2 blocks wide
Use getEntitiesAtBlockLocation
It's rly strange with those differences tbh
I can't use at blockLocation
that doesn't allow a range specification
haven't tried fromRay yet
I suspect the extra width depends on the entity's collision box.
#1282033813261652112 message
hmmm
if i just run interval when entity spawned, it break after reload of world
so can i pin it reliable
With being able to access each entity's precise location, you could simply filter those entities whose locations are out of range.
system runinterval then do a getEntities for loop
function inRange(val, min, max) {
// Assuming min <= max
return min <= val && val <= max;
}
const origin = { x: blockLocation.x, y: blockLocation.y, z: blockLocation.z + 1 };
const entities = block.dimension.getEntities({
location: origin,
volume: { x: 0, y: 0, z: range - 1 }
}).filter(entity =>
inRange(entity.location.x, origin.x, origin.x+0.9) &&
inRange(entity.location.y, origin.y, origin.y+0.9) &&
inRange(entity.location.z, origin.z, origin.z+range-0.1)
);
Is it possible to teleport the player to another dimension and create an island system like on servers using scripts?

are there more optimized options?
i think yes
but in fact you won't be able to use anything other than vanilla dimensions
what happens if you try to use getProperty on a property that doesnt exist on the entity?
Returns undefined
can you make a custom typescript package for your addon so other ppl can use it as an API to call functions in it?
Yes
how?
Its just like any normal package. Theyll just need to bundle it with esbuild or smthng
hmm
i'll try
minecraft can't auto download it, if you set it as a dep, right?
do you have an example of an addon that has an own typescript package?
Is there any native method for /dialogue command?
nope
runCommand moment again
the only dialogue thing we have is for scriptevent source
Thank you
ur wlc
do i have to ship my full addon too or just the type definitions?
to use a package/module, you need to bundle it, which means including all the code for that package in your add-on
so i have to put my addon in the npm pakage?
why mc is not doing it then?
?
i want my addon to be like an API
and other addons should be able to call functions from it
add-ons cannot directly access other add-ons
oof
if you want to expose certain behaviors, you can use scriptevents
other add-ons can use /scriptevent to call things
i'll prob do that then
anyone still getting the "hastag" error?
i mean you could make it compatible with other addons by letting them use the functions in their addon itself. basicly writing things to be used in the addon as like a basic script set for like stairs, saplings,ect which not many are doing atm
any block or item related stuff doesn't need to be used in the add-on itself, that's what custom components are for
there's already an add-on being worked on that has sets of components for common things called adk-lib
This but for addons
we love competing standards 
what "hastag" error? I've never had any issues with it
Yeah my bad hasTag -_-
I keep getting it randomly when in my creative test world. My stair script literally has that in 90% of the lines lol
when button pressed, search for player B
const target = "me"
const playerB = world.getPlayers().find(f => f.name == target)
if (!playerB) return
menu.show(playerB)
you could use this #1277940040688996512
though that's for seperate packs
thx
ye
otherwise you can ask here for more help https://discord.com/channels/494194063730278411/1278357276897574923
idk what im doing wrong, my item is meant to spawn an entity in the center of a block
the problem isthe message var
it's read only
idk how to fix it tho
I'm not a js coder
Wrap it in system.run
idk what that means lmao
system.run(()=>{
//code
});
wait that's it?
all the script?
idk man I'm confused af
.
Actually...i just re-read it...i dont think you can bypass it. What you can do is:
Cancel the message being
World.sendMessage (or player) the new message you want
I've never felt more out of touch lol
static run(cmd, dimension = world.getDimension("overworld"))
you mean this line?
bruh this was broken in the first place
this is the code i meant to send
just cancel the original message and send a new one
ok just to make things clear this an old pack i didn't make I'm just trying to make it work (i litterally know 0 stuff about js)
huh where did the event go
just use this one as a reference
dude
ye it felt wrong
even in c that would be wrong
am I hurting the sould of every coder rn? 💀
atleast mine.
world.beforeEvents.chatSend.subscribe(data => {
const {sender,message} = data
const includeEmoji = Object.keys(emoji).some(e => message.includes(e))
if(includeEmoji){
let editedMessage = message
data.cancel = true
Object.keys(emoji).forEach(e => {
editedMessage = editedMessage.replace(e,emoji[e])
})
world.sendMessage(`<${sender.name}> ${editedMessage}`)
}
})
also you don't want to declare the emojis array each time
put it in your script root
@scarlet sable
you will come back to that
Ik and that's the funny part
excludeTags not work why?
how do i modify particle velocity from particles spawned with spawnParticle?
I'm making logic to accurately protect farmland from jump and falling query players, and the good thing is it works accurately, but there is a little problem in the kill entity section where I can't exclude items in excludeTags, is there perhaps another way to exclude this?
how do i make a block execute some command in the radius of 5 blocks, ...
excludeTags is for some tag that add via .addTag, isn't?
not like typeId or something
Hey! Does anyone know how to use @minecraft/server-net to connect to the console of my server host?
What do you mean??

Like use server-net with script api to make requests to the console of my bds server.
Its not being hosted locally on my pc, i have a server host.
Wdym by to the console??
Can you be more specific? Likeee idk
You can make http request, indeed but, "to the console"?m
The server host console.... i dont know what else there is that is confusing
My server subscription ended so i cant even take a screenshot of the console right now 😭 sorry
Like the console that logs every player join, disconnect, script api console.warns, script errors, resource pack errors, etc
Yes
What do you need in that?
🤔
To use op permission level 4 commands
Like you want to receive requests in your server from another?
Mainly /allowlist, and possibly /transfer
I dont think its possible
To use script api to conect to my server host console?
Im not familair with how https works
This?
Sorry im not catching it, sorry
No, I want to make a request to the server console with script api.
The behavior pack is in the server host I intend to use the console of.
make a HTTP request to your console pretty much
there might be APIs for your server host, maybe not
Yeah something like custom software
is there a way to make a clickable link in chat ?
(using scripts/addons)
using the rideable component can i make the player ride on any entities?
nope
yea
alright thanks
"minecraft:generation": {
"generator_type": "void"
what are the valid generator_type can i use instead of void ??
i tried "default"
it didnt work
https://discord.com/channels/523663022053392405/1282209123445903370
Sorry for cross posting, what's better? A short spike, or just stabled ones, But for an amount of seconds?
i think its bedtime
Did anyone knows if had a way to make a score for player armor?
player.getComponent("health").currentValue
Like the health value
um, anyone know what im doing wrong, im bad at js
const currentLocation = player.location;
if (item.typeId === "dnd:dash_item") {
currentLocation.applyKnockback(0, 1, 0, 1);
}```
this is the code, and it gives this error
```[Scripting][error]-TypeError: not a function at <anonymous> (custom_components/dash.js:15)
For context im trying to applyknockback in the direction the player is facing
player.applyKnockback(direction.x, direction.z, 1, 0.55)
oh, i didnt know they could be used that way
thanks, imma try it now
Is there anyway to validate a command syntax without actually running it?
no
most likely not
you could instead check for items though
How do i live update a script in an addon?
replace the file in the folder and in chat type /reload
Ty
Also the dev wiki is kinda bad
Is there a better website that explains the bedrock api?
There are good references to the classes and interfaces, is that what you mean?
Ye
Ty
Just make sure you know which you are looking at as far as latest or preview and stable or beta.
I need some tips
Even tho ik the basics of js idk where to start when it comes to mc addon scripting
The bedrock wiki dev is a bit too basic and doesn't have the kind of stuff i want
This is the opposite lmao
I need to know what I'm looking for
Then you need the intro?
Yep I would say so
Do you know Javascript?
This is the official mc script guide?
It is the Intro that most programmers can take off from fairly easy.. non-progrmmers may need more guidance
As the Script API is a framework built on JavaScript code, having an understanding of JavaScript is key.
If you are being shown this, then you most likely are a beginner with JS and could use a little guidance.
Videos on Learning JavaScript
Javascript in 1 hour
Javascript Classes in 1 hour
Web Guide:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide
Reference Sites:
https://www.w3schools.com/jsref/default.asp
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference
https://javascript.info
Yep this is what i was looking for
Tysm
Also, if you are interested in some ready-made libs, one of the admin (Llama this week, but SmokeyStack normally) created this.... https://github.com/SmokeyStack/adk-lib/tree/main
it may be useful if you do not want to do some stuff yourself.
how do i get how much blocks a player has fallen
oh that's so useful
I've only ever seen it here... https://jaylydev.github.io/scriptapi-docs/1.21.40.20/classes/_minecraft_server_1_15_0.BlockComponentEntityFallOnEvent.html
now how do i even use this
hmmmm
It is from custom components. Start here and dig down to it. https://jaylydev.github.io/scriptapi-docs/1.21.40.20/classes/_minecraft_server_1_15_0.BlockComponentRegistry.html#registerCustomComponent
oh well nvm lmao
ty for looking it up but i think ill just take a look at jayly's mace code
main.*.*js
.. ?
ur filename is main.js
oh
and ur manifest seems to be looking for main..js
bro it's just .J
but the J is pixelated
i fixed the error code but still the code doesn't run
can u show ur manifest?
doesn't current system tick work only once per world ??
ye i fixed it
anyone know how to make an addon that adds the book seen in marketplace addons (the one that can be placed down and has images)
or is it possible to make a book have images as well as tex
as for why im asking in scripts general
because someone on a different server said that its done by using scripts
The book itself is an entity
it's an entity
The only scripting part is giving you ghe book
since those books are custom entities, you can just make the page have whatever image u want
yea i know that but idk how to :(
Oh he means that
u could also just modify font glyph to add those images, but then this isn't what marketpalce addons do since they aren't allowed to modify anything vanilla
use the current @minecraft/server version
I believe with editing the emojis you can do close stuff too
Oh didn't notice that
or
@minecraft/[email protected]```up each number by 2 if in preview
yes the versions
Can anyone help me? I'm using projectile.shoot() to fire arrows, does anyone know how to increase the damage and speed of the arrow?
That seems like you would need to edit the json file instead
function teste(eventEntity) {
const test1 = mc.system.runTimeout(() => {
console.warn("warn1");
if (test1 == 1.5) {
console.warn("warn2");
}
if (test1 > 2.9) {
mc.system.clearRun(test1);
console.warn("warn3");
}
}, 3);
}
the warning happens all together, there is no interval time like I wanted there to be
this code exectures every 3 ticks, is that what you wanted?
Oh, thnx
no, I want to make it so that it is 3 ticks, but on tick 1, one thing is executed, tick 2 another thing and on tick 3 the tick ends
You should use https://stirante.com/script/server/1.13.0/classes/System.html#waitTicks waitTicks instead
Documentation for @minecraft/server
How do I use this in practice?
https://jaylydev.github.io/scriptapi-docs/latest/classes/_minecraft_server_1_13_0.System.html#waitTicks there's example here
What is world:overworld?
[Scripting][error]-Plugin [Addon test - 1.0.0] - [main.js] ran with error: [SyntaxError: unexpected 'await' keyword at tick.js:15
]
function test(eventEntity) {
await mc.system.waitTick(10);
console.warn("1");
await mc.system.waitTick(20);
console.warn("2");
await mc.system.waitTick(40);
console.warn("3");
}
didn't work
You need the async
await async?
What is on line 33?
The async function declaration creates a binding of a new async function to a given name. The await keyword is permitted within the function body, enabling asynchronous, promise-based behavior to be written in a cleaner style and avoiding the need to explicitly configure promise chains.
The line under the minecraft:overworld
It just calls a summon command for a fox
playerDimension.spawnEntity("mineraft:fox" , playerLocation);
You mispelled minecraft
async function test(eventEntity) {
await mc.system.waitTick(10);
console.warn("1");
await mc.system.waitTick(20);
console.warn("2");
await mc.system.waitTick(40);
console.warn("3");
}
I tested it like this, but it didn't work
it does work for me tho
Yea I don't see anything wrong with that.
I'll show you, just a minute
[Scripting][error]-Unhandled promise rejection: TypeError: not a function
import * as mc from '@minecraft/server';
mc.system.afterEvents.scriptEventReceive.subscribe(event => {
const aa = event.id.split("magic:")[1];
const eventEntity = event.sourceEntity;
switch (aa) {
case "light":
light(eventEntity);
break
}
});
async function light(eventEntity) {
await mc.system.waitTick(10);
console.warn("1");
await mc.system.waitTick(20);
console.warn("2");
await mc.system.waitTick(40);
console.warn("3");
}
when I use "/scriptevent magic:light" that error appears
it's waitTicks
ok
Oof, missed that haha
I'll feel like an idiot if that's the mistake
thanks
It worked
export function tick_block(block) {
const entities = block.dimension.getEntities({maxDistance:10,location:block.location,type:"minecraft:player"});
if (entities.length > 10) return;
block.dimension.runCommandAsync("event entity @e[type=wesl3y:mob,r=11] talk");
block.dimension.runCommandAsync("setblock ~~~ air");
}
}
Hey!
I'm looking for launch a projectile few block forward from player view, someone knows a way to make it? 
Now can you help me with this? It doesn't show any errors, but it doesn't work
huh
as in change the face?
How do I check if an item is a block? Like a stick returns false but dirt returns true?
BlockTypes.get(item.typeId) should work
okay
now that i can understand a bit more of the api can you give me a general rundown of what's happening here?
If the message includes any emoji (by seeing if any keys in the 'emoji' variable are present in the message) then:
- Cancel sending the original message.
- Replace every instance of an emoji's key in the message with the emoji's value.
- Send the modified message out.
This could be optimized a bit further by filtering out those emoji to be replaced, like so:
world.beforeEvents.chatSend.subscribe(data => {
const {sender,message} = data;
const includedEmoji = Object.keys(emoji).filter(e => message.includes(e));
if(includedEmoji.length > 0) {
let editedMessage = message;
data.cancel = true;
includedEmoji.forEach(e => {
editedMessage = editedMessage.replace(e,emoji[e]);
});
world.sendMessage(`<${sender.name}> ${editedMessage}`);
}
});
interesting
Usually that means the event you tried to access does not exist. Is line 7 of emojis.js that world.beforeEvents.chatSend line?
Must be an API version issue. What version of the API are you using? (Look in the behavior pack manifest, it should be in the dependencies array)
beforeChatSend is in beta only
Could it still be in beta ...? If you change that to I think 1.16.0-beta it will begin working
i see
I'll try
1.14.0-beta
I might be thinking of the preview hehe
it is 14
If you are using VSCode for Intellisense, and you have the "@minecraft/server" NPMJS module installed, you'll want to install the 1.14.0-beta version of that to get updated typings
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]
For a sec I thought I pinged you
works like a charm
yep
the pixel art is a bit illegal looking lol
btw I finished the microsoft guide
what's the next step?
i forgot to say ty btw
Have a small project in mind and set your intention to figure it out. A goal usually helps. There are plenty of samples and stuff in #1067535712372654091 .
It is best to search the discord and the API's links I gave you before you ask for help. It should be a last resort, imo. As you get better, help others figure out their challenges... it will make you better.
There are pinned messages in this general post too
and peruse over this link: https://wiki.bedrock.dev/scripting/script-server.html#setup
Ok ty
Hopefully we'll meet again but I'll be the one giving advice 
Looking forward to your growth....
does anyone know how applyKnockback strength works
blazingly fast 
With runJob + caching (100+ blocks)
just runJob (this image is tested with 200 blocks)
is their another way to simulate growing plants when interacting with grass for a custom block?
Wdym?
Like, right click -> lots of plants show up
or
right click -> advance stage
it just sends entities into sky if i set the vertical strength to like
2?
you can even use mace with that
lots of plants when using bonemeal like grass does
i mean i know i can do it with structures but i really want it closer to the actual mechanic of the game so its more random
duh nvm i got it
function destroy(block: Block): number {
world.sendMessage(`${block.typeId}`)
block.dimension.setBlockType(block.location, MinecraftBlockTypes.Air);
return 1;
}
world.beforeEvents.playerBreakBlock.subscribe((event) => {
const { block, player, itemStack } = event;
switch (itemStack?.typeId) {
case MinecraftItemTypes.IronAxe:
// treeCapitation(player, block);
const above = block.above();
if (!above) return;
destroy(above)
break;
default:
break;
}
})
how i replace the block above of the block i break?
you're trying to modify a block while still inside the time frame of a beforeEvent (read-only)
wrap the block.dimension.setBlockType in system.run()
anyone #1282572947718144083 help me
Yo. Anyone know how to properly use airSupply: on a player?
if i wanted to check if spawned entity is item i have to use .getComponent('item') right?
seems like it
Thx
Why does it say I can only have 1 script module in my pack?
duplicate dependencies in the manifest maybe?
I have 2 scripts tho and they do different things but when I reference them in manifest I get that error and only one works
[Scripting][warning]-Plugin [Minecraft Addon - 1.0.0] - skipped, only one script module allowed per pack.
reference one of your files in the manifest.
use import, and import the other file.
import "../folder/code1"
import "./code2"
I'll try thank, thanks!
It worked, thanks man.
np
Yeah still can't replicate the vanilla flower spread
import { world } from '@minecraft/server';
world.beforeEvents.chatSend.subscribe((eventData) => {
const player = eventData.sender;
switch (eventData.message) {
case '!help':
eventData.cancel = true;
player.runCommandAsync('give @s mn:help');
default: break;
}
});```
[Scripting][error]-Plugin [AFK System - 1.0.8] - [index.js] ran with error: [TypeError: cannot read property 'subscribe' of undefined at <anonymous> (index.js:3)
what am I doing wrong?
chatSend is in beta
thanks I solved it
other than playAnimation, probably not
dont remember any
I see
bc I'm trying target location 2 block forward from player is looking for
any direction looking
then thats even easier
i can just build one rq
srry 
Okk
which item
for summon it?
yeah
cc_bu:cannonball_attack
thats the item id?
id
what about the projectile
it's a custom entity
tell
and how fast is it gonna be
alr
I had something like that but I think I miss something
world.afterEvents.itemUse.subscribe((item) => {
const overworld = world.getDimension('overworld')
const player = item.source
const itemstack = item.itemStack
const playermount = player.getComponent(EntityComponentTypes.Riding).entityRidingOn
if ( itemstack.typeId == 'cc_bu:cannonball_attack' && playermount.typeId == 'cc_bu:barrelbot' ) {
let distancia = -2;
const newvector = {
x: player.location.x - player.getViewDirection().x,
y: player.location.y - player.getViewDirection().y,
z: player.location.z - player.getViewDirection().z * distancia
}
const cannonball = overworld.spawnEntity('cc_bu:cannonball_entity',newvector)
const cannonballentity = cannonball.getComponent(EntityComponentTypes.Projectile)
cannonballentity.owner = playermount
cannonballentity.shoot(player.getViewDirection)
}
})
I guess it
Okk thanks 🫡
@solid stone
import { world } from "@minecraft/server";
world.afterEvents.itemUse.subscribe((data) => {
const item = data.itemStack;
const player = data.source;
const launchPower = 1.34;
const uncertainty = 0.0;
const shootFromHead = true;
if (item.typeId === "cc_bu:cannonball_attack") {
const view = player.getViewDirection();
const velocity = { x: view.x * launchPower, y: view.y * launchPower, z: view.z * launchPower };
const projectile = player.dimension.spawnEntity("cc_bu:cannonball_entity", (shootFromHead ? player.getHeadLocation() : player.location));
const projectileComp = projectile?.getComponent('minecraft:projectile');
if (projectileComp) {
projectileComp.owner = player;
projectileComp.shoot(velocity, { uncertainty: uncertainty??0.0 });
}
}
});```
Working very well, just I'll need a thing 
basically I would like summon it ~2 block forward and ~1 to the right
so i'm not sure how I'll be available to make it
you can use my script to anchor the position related to the entity rotation
function anchor(dir, pos) {
const dir_length = Math.sqrt(dir.x * dir.x + dir.y * dir.y + dir.z * dir.z);
const normalizedDir = {x: dir.x / dir_length ,y: dir.y / dir_length ,z: dir.z / dir_length };
const loc_vec = { x: -normalizedDir.z, y: 0, z: normalizedDir.x};
//normalize to avoid different offset depending on the direction
const loc_length = Math.sqrt(loc_vec.x * loc_vec.x + loc_vec.y * loc_vec.y + loc_vec.z * loc_vec.z);
const norm_loc = {x: loc_vec.x / loc_length ,y: loc_vec.y / loc_length ,z: loc_vec.z / loc_length };
//offset distance
const offset = { x: 0.3, y: 0.3, z: 1 };
return {
x: pos.x + norm_loc.x * offset.x + normalizedDir.x * offset.z,
y: pos.y + norm_loc.y * offset.x + offset.y,
z: pos.z + norm_loc.z * offset.x + normalizedDir.z * offset.z
};
}
that one should work
pass the entity view direction and the head/barrel position to it
change this to the offset you want
Do you guys know how to make custom enchantments?
item lore
I see, yeah working perfect thanks y'all 
We cant officially make custom enchantments. However there are workarounds.
Store the "enchantment" as an item lore or dynamic property. Then with ScriptAPI, detect whatever function(entity hit, block mine etc) -> grab the "enchantment" -> execute effects
Tho yes scriptAPI
??
that seems like item lore trick
the attack damage part is above the enchantments in the image
idk if I'm doing something wrong but it isn't relative from which directions is player looking, do u know why or if I did something wrong? 
Yes(?
show the code
function anchorbarrelbot(dir, pos) {
const dir_length = Math.sqrt(dir.x * dir.x + dir.y * dir.y + dir.z * dir.z);
const normalizedDir = {x: dir.x / dir_length ,y: dir.y / dir_length ,z: dir.z / dir_length };
const loc_vec = { x: -normalizedDir.z, y: 0, z: normalizedDir.x};
//normalize to avoid different offset depending on the direction
const loc_length = Math.sqrt(loc_vec.x * loc_vec.x + loc_vec.y * loc_vec.y + loc_vec.z * loc_vec.z);
const norm_loc = {x: loc_vec.x / loc_length ,y: loc_vec.y / loc_length ,z: loc_vec.z / loc_length };
//offset distance
const offset = { x: 0.2, y: 0.3, z: 0.6 };
return {
x: pos.x + norm_loc.x * offset.x + normalizedDir.x * offset.z,
y: pos.y + norm_loc.y * offset.x + offset.y,
z: pos.z + norm_loc.z * offset.x + normalizedDir.z * offset.z
};
}
world.afterEvents.itemUse.subscribe((item) => {
const overworld = world.getDimension('overworld')
const player = item.source
const itemstack = item.itemStack
const playermount = player.getComponent(EntityComponentTypes.Riding).entityRidingOn
if ( itemstack.typeId == 'cc_bu:cannonball_attack' && playermount.typeId == 'cc_bu:barrelbot' ) {
const launchPower = 1.34;
const uncertainty = 1.0;
const shootFromHead = true;
const view = player.getViewDirection();
const velocity = { x: view.x * launchPower, y: view.y * launchPower, z: view.z * launchPower };
const projectile = player.dimension.spawnEntity("cc_bu:cannonball_entity", (shootFromHead ? anchorbarrelbot(player.getHeadLocation(),player.location) : player.location));
const projectileComp = projectile?.getComponent('minecraft:projectile');
if (projectileComp) {
projectileComp.owner = player;
projectileComp.shoot(velocity, { uncertainty: uncertainty??0.0 });
}
}
});
(shootFromHead ? anchorbarrelbot(player.getViewDirection(),player.getHeadLocation()) : player.getHeadLocation())
trying
now seems it doesn't appear anywhere 
🤨
Would anyone know why this isnt working?
worked?
Whats line 374?
getComponent
show full line
Yeah, equippable only works on players
is there a way I can turn the entity into a player? or is there a way to detect for players specifically that get damaged?
Ohhh i figured it out now
that is a player...
unless that is just a name
Nope, JS has no type safety
shouldn't be a name
@umbral scarab damageSource is a https://stirante.com/script/server/1.13.0/interfaces/EntityDamageSource.html
Documentation for @minecraft/server
Its not an entity
You need
event.damageSource.damagingEntity
that is not the error source
Yes it is...
how can you tell
it fixed something lol
Youre passing a damagesource not an entity
Bc i read the code?
this makes sense tbh I didnt realise there was another attribute after
You should use entityhtientity event not entityhurt
I need to track all damage taken (fall damage etc.) so thats why I chose entityHurt
you can use both
Hi
interesting. whats the difference between them then?
just filter entity damage from the entityHurt event to not get duplicate fires
How to fix this?
function durability(player, itemStack, damage) {
let durability = itemStack.getComponent("minecraft:durability");
if (durability.damage >= durability.maxDurability) {
const inventory = player.getComponent("minecraft:inventory").container;
inventory.setItem(player.selectedSlotIndex, undefined);
player.playSound("random.break", player.location);
} else {
durability.damage += damage;
const inventory = player.getComponent("minecraft:inventory").container;
inventory.setItem(player.selectedSlotIndex, itemStack);
}
}
durability(player, item, 50);
I want it to break item if it go over max durability but it says error
Can you send the full error? It'll help people find the issue
you are setting undefined to the player inventory, just don't set it
But how to remove item?
Entityhurt is all damage type as you said. Entotyhitentoty is just when an entoty hits an entoty
entoty👀
It say this exact: "item damage can not be greater then max durability"
uhh, you set it to undefined. wait let me take a closer look
Check if its greater then
Lemme see if i can pull out the script i used for adk lib
I've now got this error
csn you post that line
check if the damage is greater than max, if so, set the item to undefined
^all the code is up here @shy leaf
Im guessing bc the entity is undefined
oh
Check if the damageSource is an enttiy forst
don't worry chat moved fast lol
Yes I do?
Code is that
It is for on use
you could use optional chaining
sean is definitely on a phone 😂
Doesnt matter. The link i sent shows a script to decrease durability
its probably happening when the player doesnt have anything in those slots
Thats not the issue, the issue is entity is undefined
o
Bc hes using damageSource whoch mau or may not have a damaging entoty
hard to tell from here
Immaculate spelling errors
I think its something to do with this. I put log here and it sends nothing to the log at all. So if its undefined, its probably back here which makes me think it's something to do with adding the damagingEntity
Add
if(entity==undefined) return
Underneath const entity
But is same as mine?
Nope
It see if durability damage >= max durability and set undefined item?
Yours checks for damage alone. Mines check for damage + the damage to add
Do console.warn
Is console.warn
oop
Unless youre in preview or using vscode debugger
Sorry am not understand
yeh its undefined
Cool, hoe are you testing this code?
taking fall damage
Thats why, bc fall damage doesnt have a damaging entity. Tada
Now punch the entity and you should get your findGem executed
how can I change it so it tracks all damage taken though like fall damage, fire etc
What is findGem for?
Yknow what, open a post and post your code and what youre trying to achieve. Bc rn all i can adsume is youre checking if an entoty hits an entoty and that entoty has a gem
basically im trying to make it so theres a 15% chance of the damage source being blocked
is not possible
I know I cant cancel the event but im measuring the incoming damage and just simply healing it afterwards
But if player die?
then they die
But you cannot test 15%
ye ik
ok
its intentional feature I want anyways
I've got it figured out now anyways
Ok
Thank you @wary edge and everyone else <3
Can you help
Hey guys is there any way to make custom spawn rules? I want my entity to look for a gap in stone in caves and spawn there or just dig out a random spot between stone near the player and spawn my entity there. Is this possible?
That seems like a #1067869022273667152 question. Using the spawn rules json
But it's not possible using normal spawn rules.
You just want it to spawn undergroudn though right?
No
In between groups of stone in caves for example 9×9 of full stone and near the player and also digging the spot before spawning between stone
Is this possible?
if (entity.is!OnGround) {
!entity.isOnGround
Read the docs and confirm
Docs schmocks
What we really need is a website or database that properly displays this information for us to view for reference
Stirante scripts
Jayly dev
Npm types
So...docs
He was two steps ahead..
That are already the docs
No.. nah..
MS docs are fine, it just takes a bit to get used to their navigation.
Bait used to be believable
We r to dumb now show us step by step for hours until we get it 
Okay I shall stop this tomfoolery at once
It's not suitable for my little microfiber brain
Maybe people are starting his learning curve from too high
Too complicated to do
NPM types alone provide autocompletion, examples for certain things, and typing suggestions
Erm Nah
What Big Black Money?
What.
Big. black. stacks Of Hard money
People want to do a complicate algorythm without the basics, like object oriented progamming
That's what I said
Nanda
So basically I want to light everything on fire on using an item, but the fire can’t be ignited on the user and only other entities within the radius
Feels so ez to do
How do you ignite someone with commands😭
And I was gonna make a exception with tags but it’d go against a bunch of things
It’s as a base for what I want
Finally…

Oh Xd
My mind will lose brain cells if I again try to use those Ms script docu
This method is provided on all the sites
Jayly dev
Stirante scripts
Ms docs
Npm types
Just gotta know where to find it and how to use it
Get all entities in a radius but use excludeNames
Again, I don't get your problem with the docs sites. They have a search bar, you can browse the methods, the descriptions are apt.
No matter what you do, some level of work is required. Such is life.
If you really want, use AI. you will get incorrect methods if you do not train it (which requires work), nut it can do the work for you in that sense.
Hard to tell nowadays
How does a vector work?
A vector is a point in 3D (or 2D) space
Oh so just x y z coords?
Yes
Ty
Also ik it's possible to get player position but can you get player rotation too?
Get rotation returns an x & y vector with the pitch & yaw of the entity
Get view direction returns a normalized x y z vector
can you explain what a callback is pls?
How do I prevent water from flowing into a claim?
Dynamically you have to be very smart to find a way that won't lagg.
Plot systems could easily using invisible custom blocks... but dynamic landclaims it's a little harder.
Best strategy is prevent players from using the buckets in a distance from another claim and or height
Unless they own that claim etc
?
for exemple i want the code to memorize a number of coords
so everytime you use for exemple !coord your coords get saved
but yiu don't want a limit
Like an array of coords to be used for something?
You can easily use a custom script api database to make data persistent.
Anyone here probably has one in an addon somewhere
oh i see
that's intresting
Utilizes custom made classes to allow the script creator to use scoreboards or dynamic properties easier
world.beforeEvents.chatSend.subscribe((event) => { const message = event.message; const player = event.sender
event is a function right?
event is the call for chatSend that you assigned
this code saves the content of the message and it sender
oh
that makes much more sense
it calls this word, which calls chatSend
oh so subscribe is just there as a shortcut right?
Grabs the info/data from that "event" (e.g : player breaks a block) if the event is subscribed to the world it will listen for those things
shorter script i mean
Not sure what you mean
You need subscribe to basically activate it
(Subscribe) For the script to "listen" constantly.
ahh yes let me guess :
end stone brick wall === cobblestone_wall
(just like dirt === coarse_dirt)
🤯
my beloved api
callback is function
in your example
world.beforeEvents.chatSend.subscribe((event) => {})
the callback is ((event) => {}
the api calls the callback function and passes the event object to it which we can use then to retrieve the event arguments
cobblestone have 14 block under the same id
cobblestone_wall*
Is the latest API 1.13.0?
And how do I see which is and which functions/classes I can't use?
pc?
hover over the function in vs code
thank you
sheesh
ty ty
this stuff is low-key fun ngl
There's worse things to spend time on for sure lol
fr lol
btw how come your VS give you descriptions?
npm packages
install node js and the server version you need
oh that's what it's for
cool af
how do i change the bit limit after the dot?
16 is too much
Number.toFixed(decimals)
number.toFixed(amount)
ty
Where decimals is tue number of places to display to
does that mean i can have more than 16?
Note that the value does round, so 179.789 would round to 179.79 if toFixed(2) was used
oh approximation
Yes, but the game only stores to 16, so any added after would just be zeros
Just rounding
makes sense
that is new to me lol
if a constant is null
and you try to give it a value
will it like accept the first value?
or just stay null
Wdym
Yes
if i later in the code try to give it a value will it accept it?
what can a null const be used for tho?

yep let is a var
real
I personally have never used var, nor do I plan on using it
var is the same as let isn't it?
Never found a use for it that other variables haven't been able to do
Var is global scope, let is local
Chest UI & realm packs are public on my github. But I have private addon packs for servers I develop for
you work on the marketplace?
I do not
import { ChestFormData } from './extensions/forms.js';
you made your own library?
Utilizes custom made classes to allow the script creator to use scoreboards or dynamic properties easier
or that
Json ui magic to make a server form look like a chest
And extensions to the vanilla APIs is very much possible, and pretty useful
you recoded a server form with it ui to look like a chest?
LeGend did most of the work in that regard, but yeah that's the idea there
I don't believe in selling packs lol
ads maybe
Anything I think is good enough to sell I keep private
there are lots of ethical ways to profit
i see
var is weird
it can be accessed from outside the scope it is declared on (globally)
btw when i want to give the var a new value i just do varname = value; right?
Yep
ty
Unless it's a const
yep
I'm making a simplified camera command addon
where you set the points using cemrapoint 1 2 3 etc.
And I would recommend against type combining (e.g. setting a variable to a number and then a string later on in the code)
then it compiles the coords and rot for you
nah that sounds like the best way to forget what everything is for
i was going to make one using this https://discord.com/channels/523663022053392405/1167420026291245086
just click it
it is not one? i think?
ease are client side
this video uses it
https://www.youtube.com/watch?v=8veG_RHvA3I
الفيديو عبارة عن تريلر لمود رؤوس الاعبين
شرح كيفية استعمال المود والحصول عليه:
https://youtu.be/5i6QQdQSc9I
but you can work arround it
been so long since i watched a vid in arabic lmao
kinda nostalgic
lol
no arabic there just the title
i translate all my videos
fair
the thing is the bedrock camera is laggy
idk why
even with the vanilla command
btw are the heads costume items?
mhm
i have a bot that generate them from a skin and a name
open {}
oh ye
ty
btw using vars for this one would be stupid
is there a way to make like a data base system?
array
?
? for?
wdym array?
you don't know what array are?
const cameraPointes = []
cameraPointes.push(location1)
cameraPointes.push(location2)
cameraPointes.push(location3)
...
it can store stuff inside
and yo can call them with an index
cameraPointes[0] is location1
each one under is a ceperate const?
oh
is that good bro
Only as good as you make it
nice one
yeah that one return the first element in that array
it's from the microsoft guide ngl
is there an article about it in the microsoft website?
oh everyone else just uses forEach()
it is a javascript thing not a script api
oh ye i saw that
that is unrelated
oh that's much better actually
how comes
to arrays he means i think
yh ur right
no it is array related
but players are a array?
alright time for the bedtime
ohh ye i remember now
forEach is self explanatory
they work like
const potato [1 ,2 ,3] right?
they?
referring to?
potato = [] is a array
yep
potato = {} is a object
just learn javascript first before doing script api, way better
arrays have some cool functions
searching mapping filtering ...
Real
can i make each var in an array into an object?





