#Script API General

1 messages · Page 19 of 1

winter plaza
#
export function tick_block(block, player) {
  const entities = block.dimension.getEntities({maxDistance:10,location:block.location,type:"minecraft:player"});
  for (sla of entities) {
    block.dimension.runCommandAsync("execute as @p run say sla");
  }
}
#

I tested it like this and it didn't work

glacial widget
#
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

distant tulip
distant tulip
unreal cove
glacial widget
#

Thank you

glacial widget
shy leaf
#

is there a calculation of getting how far applyKnockback can push in block distance

distant gulch
#

can i make targeting skill ?

tiny tartan
#

what is maxDistance limit in getEntities method

subtle cove
#

no limit..., dunno test it out

#

it only gets the loaded entities

shut citrus
celest fable
wary edge
subtle cove
#

its similar to @e

wary edge
#

So then sim dist yeah

subtle cove
#

whatever's loaded

umbral stag
#

is there any we can stop player attacking a specific player

#

like team

shy leaf
#

not really script api related though

inland merlin
shadow lark
#

does anyone know how I can get the values of a state of a block?

alpine ibex
#

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)
sharp elbow
#

For each dimension, use the getEntities method. You may want to filter out some entities for better performance

sharp elbow
#

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

alpine ibex
#

You gotta explain everything dawg

sharp elbow
#

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

#

Let me know if you have any other questions about that

alpine ibex
#

How do I add this to my current setup...

#

Man I'm stoopid

#

Hohoho

lone thistle
devout dune
#

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?

cold grove
#

You need to set that the block ticks in the JSON

winter plaza
#
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

devout dune
deep plank
#

Unfortunately, placement_filter is very limited 😕

cold grove
#

So

devout dune
#

scripting was just my first thought

umbral scarab
#

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

wary edge
random flint
umbral scarab
#

ah yes tyty

empty quail
#

Am I stupid or is Bridge buggy?

fallow rivet
#

How can I use before event explosion?

#

Is there a sample code?

fallow rivet
#

I deleted Gametest

#

I don't use

past blaze
#

Is there a way to detect when the world closes?

unique dragon
#

nah

distant tulip
past blaze
distant tulip
#

for hosted worlds it dose

past blaze
distant tulip
#

no just me

distant tulip
#

system.waitTicks
when did this get added

#

memory issues

oblique heath
#

Is there a way to check if a block is opaque?

distant tulip
#

isSolid

oblique heath
#

That's only in beta 🥲

wary edge
#

Yeah...its unlikely for it to be in stable due to the recent qna. Theyre gonna split up solidity

wanton ocean
#

nooo

empty quail
#

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

oblique heath
#

xd

thorn flicker
empty quail
thorn flicker
empty quail
#

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

deep plank
empty quail
deep plank
#

Yes

umbral scarab
#

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?

empty quail
#

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

umbral scarab
#

how so?

deep plank
empty quail
deep plank
thorn flicker
empty quail
umbral scarab
#

Still having the same issue where the enchant doesn't apply

#

no error messages in log

thorn flicker
empty quail
#

Ok I believe I understand, thank you

thorn flicker
#

I wonder why getAllPlayers exists then if that's the case

empty quail
#

One moment

umbral scarab
#

no change

valid ice
thorn flicker
#

you can just not use the filter in getPlayers.

valid ice
#

well yea

umbral scarab
#

I put warns around it and both are running so I literally have no clue lol

empty quail
#

Wait I may have it, gotta do with mapping

deep plank
empty quail
#

That's what I was thinking; no errors now. Thanks!

umbral scarab
strong oar
#

can i ask how to fix this, facing opposite in creative inventory?

slow walrus
#

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

past blaze
oblique heath
#

is there a way to get block and entity bounding boxes?

wise raft
#

Is it possible to set the Items in the lower Inventory with Chest UI?

wise raft
#

or did someone else did that?

fast wind
#

For some reason the dropdown gets duplicated, it sometimes happens but I don't understand why

#

It works perfectly here

keen folio
#

Someone help me with #1281939985230069761 please

fast wind
#

nvm fixed

fallow rivet
#

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.

tiny tartan
#

was old script api able to cancel entityHit or entityHurt events?

umbral scarab
#

is there a way for me to test if an item has a specific enchant on it?

subtle cove
#

No

umbral scarab
#

I saw it in documentation and couldn't figure it out

subtle cove
umbral scarab
# subtle cove

tyty. I tried searching too but I got completely different results for some reason

#

thank you anyways

cinder shadow
#
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
subtle cove
#

It's rly strange with those differences tbh

cinder shadow
#

I can't use at blockLocation

#

that doesn't allow a range specification

#

haven't tried fromRay yet

sharp elbow
proud saddle
#

#1282033813261652112 message
hmmm
if i just run interval when entity spawned, it break after reload of world

#

so can i pin it reliable

sharp elbow
granite badger
sharp elbow
#
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)
);
fallow rivet
#

Is it possible to teleport the player to another dimension and create an island system like on servers using scripts?

proud saddle
proud saddle
meager pulsar
#

what happens if you try to use getProperty on a property that doesnt exist on the entity?

clear pendant
#

can you make a custom typescript package for your addon so other ppl can use it as an API to call functions in it?

clear pendant
#

how?

wary edge
#

Its just like any normal package. Theyll just need to bundle it with esbuild or smthng

clear pendant
#

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?

shell pike
#

Is there any native method for /dialogue command?

shell pike
#

runCommand moment again

distant tulip
#

the only dialogue thing we have is for scriptevent source

shell pike
#

Thank you

distant tulip
#

ur wlc

clear pendant
rugged tinsel
clear pendant
clear pendant
#

why mc is not doing it then?

clear pendant
#

and other addons should be able to call functions from it

rugged tinsel
#

add-ons cannot directly access other add-ons

clear pendant
#

oof

rugged tinsel
#

if you want to expose certain behaviors, you can use scriptevents

#

other add-ons can use /scriptevent to call things

clear pendant
#

i'll prob do that then

true isle
#

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

rugged tinsel
#

there's already an add-on being worked on that has sets of components for common things called adk-lib

valid ice
#

This but for addons

rugged tinsel
rugged tinsel
valid ice
#

"The methods that I designed will be the new standard for creators!"

true isle
#

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

celest fable
slow walrus
#

though that's for seperate packs

clear pendant
#

thx

slow walrus
#

👍

#

there should be some simple usage stuff on the github

clear pendant
#

ye

slow walrus
scarlet sable
#

hello

#

I'm here again lol

covert grove
scarlet sable
#

the problem isthe message var

scarlet sable
#

idk how to fix it tho

#

I'm not a js coder

wary edge
scarlet sable
wary edge
#
system.run(()=>{
  //code
});
scarlet sable
#

wait that's it?

scarlet sable
scarlet sable
#

idk man I'm confused af

scarlet sable
wary edge
#

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

scarlet sable
#

I've never felt more out of touch lol

#

static run(cmd, dimension = world.getDimension("overworld"))

#

you mean this line?

scarlet sable
#

this is the code i meant to send

distant tulip
scarlet sable
#

oh i think i understand

#

like that?

distant tulip
#

you are still trying to assign new value to it

scarlet sable
#

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)

distant tulip
#

huh where did the event go

scarlet sable
distant tulip
scarlet sable
#

ye it felt wrong

#

even in c that would be wrong

#

am I hurting the sould of every coder rn? 💀

simple zodiac
#

atleast mine.

scarlet sable
#

fair fair

#

sooo is the world.sendMessage placement even right?

distant tulip
#
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

scarlet sable
#

Ty

#

You saved me a 12h js course💀 💀 💀

distant tulip
#

you will come back to that

scarlet sable
#

Ik and that's the funny part

granite cape
#

excludeTags not work why?

oblique heath
#

how do i modify particle velocity from particles spawned with spawnParticle?

granite cape
# granite cape excludeTags not work why?

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?

rose light
#

how do i make a block execute some command in the radius of 5 blocks, ...

celest fable
#

not like typeId or something

turbid delta
#

Hey! Does anyone know how to use @minecraft/server-net to connect to the console of my server host?

turbid delta
#

Its not being hosted locally on my pc, i have a server host.

cold grove
#

Wdym by to the console??

cold grove
#

You can make http request, indeed but, "to the console"?m

turbid delta
#

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

cold grove
#

Yes

turbid delta
#

To use op permission level 4 commands

cold grove
#

Like you want to receive requests in your server from another?

turbid delta
#

Mainly /allowlist, and possibly /transfer

cold grove
#

I dont think its possible

turbid delta
#

To use script api to conect to my server host console?

#

Im not familair with how https works

cold grove
#

Sorry im not catching it, sorry

turbid delta
#

The behavior pack is in the server host I intend to use the console of.

slow walrus
#

make a HTTP request to your console pretty much

#

there might be APIs for your server host, maybe not

cold grove
#

Yeah something like custom software

runic crypt
#

is there a way to make a clickable link in chat ?
(using scripts/addons)

misty pivot
#

using the rideable component can i make the player ride on any entities?

misty pivot
#

alright thanks

runic crypt
#
      "minecraft:generation": {
          "generator_type": "void"

what are the valid generator_type can i use instead of void ??

runic crypt
#

i tried "default"
it didnt work

unreal cove
#

that's not a script api question

#

#1067869232395735130

sudden nest
oblique heath
#

i think its bedtime

lethal crystal
#

Did anyone knows if had a way to make a score for player armor?

#

player.getComponent("health").currentValue

#

Like the health value

abstract cave
#

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

oak lynx
abstract cave
#

thanks, imma try it now

unreal cove
#

Is there anyway to validate a command syntax without actually running it?

distant tulip
#

no

shy leaf
#

you could instead check for items though

scarlet sable
#

How do i live update a script in an addon?

neat hound
scarlet sable
#

Also the dev wiki is kinda bad

#

Is there a better website that explains the bedrock api?

neat hound
scarlet sable
#

Ye

neat hound
scarlet sable
#

Ty

neat hound
#

Just make sure you know which you are looking at as far as latest or preview and stable or beta.

scarlet sable
#

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

scarlet sable
#

I need to know what I'm looking for

neat hound
scarlet sable
#

Yep I would say so

neat hound
scarlet sable
#

Yep

#

The main stuff

#

Vars consts functions

#

Objects

#

Etc

neat hound
scarlet sable
#

This is the official mc script guide?

neat hound
#

It is the Intro that most programmers can take off from fairly easy.. non-progrmmers may need more guidance

drifting ravenBOT
#
Learn JavaScript

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

scarlet sable
#

Tysm

neat hound
shy leaf
#

how do i get how much blocks a player has fallen

shy leaf
#

oh well nvm lmao

#

ty for looking it up but i think ill just take a look at jayly's mace code

scarlet sable
#

weird

unreal cove
#

main.*.*js

scarlet sable
#

.. ?

unreal cove
#

ur filename is main.js

scarlet sable
#

oh

unreal cove
#

and ur manifest seems to be looking for main..js

scarlet sable
#

bro it's just .J

#

but the J is pixelated

#

i fixed the error code but still the code doesn't run

unreal cove
#

can u show ur manifest?

scarlet sable
#

is something wrong?

runic crypt
scarlet sable
#

ye i fixed it

runic crypt
#

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

scarlet sable
#

it's an entity

wary edge
#

The only scripting part is giving you ghe book

runic crypt
#

oh ok

#

do you know of a way to put images in the book tho ?

scarlet sable
#

In a mc book?

#

Like book and quill?

unreal cove
runic crypt
scarlet sable
#

Oh he means that

unreal cove
#

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

neat hound
scarlet sable
#

I believe with editing the emojis you can do close stuff too

scarlet sable
neat hound
scarlet sable
#

ohhhh

#

so that's what this is

#

ye I'm having fun learning this stuff

neat hound
#

yes the versions

scarlet sable
#

a simple time counterbao_icon_entities

static nebula
#

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?

wary edge
winter plaza
#
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

wary edge
winter plaza
winter plaza
#

How do I use this in practice?

granite badger
scarlet sable
#

is there a mistake?

#

it spawns wolfs even tho I'm in the overworld

wary edge
scarlet sable
#

Dimension?

#

Oh

#

Bruh

#

Ye it's minecraft:overworld

#

Ty

winter plaza
#

didn't work

scarlet sable
winter plaza
wary edge
wary edge
scarlet sable
#

It just calls a summon command for a fox

#

playerDimension.spawnEntity("mineraft:fox" , playerLocation);

wary edge
scarlet sable
#

oh

#

Ye it works now

#

That was embarrassing lmao

winter plaza
#

I tested it like this, but it didn't work

remote oyster
#

Yea I don't see anything wrong with that.

winter plaza
#

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

open urchin
#

it's waitTicks

winter plaza
#

ok

remote oyster
#

Oof, missed that haha

winter plaza
#

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");
  }
}
solid stone
#

Hey! hi I'm looking for launch a projectile few block forward from player view, someone knows a way to make it? think

winter plaza
chilly fractal
#

Yo yall

#

Is there a way to get and set a block's face?

distant tulip
wintry bane
#

How do I check if an item is a block? Like a stick returns false but dirt returns true?

unreal cove
wintry bane
#

okay

scarlet sable
sharp elbow
scarlet sable
#

oh

#

nice i got it right

#

i need to learn more about the subscribe function

sharp elbow
#

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}`);
    }
});
scarlet sable
sharp elbow
#

Usually that means the event you tried to access does not exist. Is line 7 of emojis.js that world.beforeEvents.chatSend line?

scarlet sable
#

yep

#

oh i think ik the problem

#

1 min

#

nah still not working

sharp elbow
#

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)

scarlet sable
#

1.13.0

#

the latest

wary edge
#

beforeChatSend is in beta only

sharp elbow
#

Could it still be in beta ...? If you change that to I think 1.16.0-beta it will begin working

scarlet sable
sharp elbow
#

I might be thinking of the preview hehe

scarlet sable
#

lol

thorn flicker
#

1.14.0

#

lol

#

honestly idk anymore

#

didnt we jump an update or something

scarlet sable
#

it is 14

sharp elbow
#

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

gaunt salmonBOT
sharp elbow
#

For a sec I thought I pinged you

scarlet sable
#

works like a charm

#

the pixel art is a bit illegal looking lol

#

btw I finished the microsoft guide

#

what's the next step?

scarlet sable
neat hound
# scarlet sable what's the next step?

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

scarlet sable
#

Hopefully we'll meet again but I'll be the one giving advice bao_ext_toldyouso

neat hound
shy leaf
#

does anyone know how applyKnockback strength works

sudden nest
#

blazingly fast bao_comm_hatchi_spin

#

With runJob + caching (100+ blocks)

#

just runJob (this image is tested with 200 blocks)

true isle
#

is their another way to simulate growing plants when interacting with grass for a custom block?

wary edge
#

Like, right click -> lots of plants show up
or
right click -> advance stage

shy leaf
#

smokey

#

how on earth does strength for applyKnockback work

shy leaf
#

it just sends entities into sky if i set the vertical strength to like

#

2?

#

you can even use mace with that

true isle
#

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

hazy yoke
#
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?

random flint
keen folio
#

anyone #1282572947718144083 help me

mystic mortar
#

Yo. Anyone know how to properly use airSupply: on a player?

tiny tartan
#

if i wanted to check if spawned entity is item i have to use .getComponent('item') right?

tiny tartan
#

Thx

still sorrel
#

Why does it say I can only have 1 script module in my pack?

random flint
#

duplicate dependencies in the manifest maybe?

still sorrel
#

[Scripting][warning]-Plugin [Minecraft Addon - 1.0.0] - skipped, only one script module allowed per pack.

random flint
still sorrel
#

I'll try thank, thanks!

random flint
#

np

true isle
#

Yeah still can't replicate the vanilla flower spread

tardy wraith
#
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?

tardy wraith
solid stone
#

Are queries available on script?

shy leaf
#

dont remember any

solid stone
#

bc I'm trying target location 2 block forward from player is looking for

#

any direction looking

shy leaf
#

sounds like a very easy thing to do in js

#

are ya trying to get block or entity

solid stone
#

just cords

#

bc I want spawn from there a projectile

shy leaf
#

then thats even easier

solid stone
#

fck

#

then I'm dumb

#

idk

shy leaf
#

i can just build one rq

solid stone
#

srry peepoFlushed

solid stone
shy leaf
#

it takes like

#

5 mins

solid stone
#

will help a lot pepeHeart

#

npp

shy leaf
#

which item

solid stone
#

for summon it?

shy leaf
#

yeah

solid stone
#

cc_bu:cannonball_attack

shy leaf
#

thats the item id?

solid stone
#

id

shy leaf
#

what about the projectile

solid stone
#

it's a custom entity

shy leaf
#

tell

solid stone
#

cc_bu:cannonball_entity

shy leaf
#

and how fast is it gonna be

solid stone
#

1.34

#

power

shy leaf
#

alr

solid stone
# shy leaf 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)
    }

})
shy leaf
#

yeah thats a bit off

#

ill jsut make one from scratch

solid stone
solid stone
shy leaf
#

@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 });
        }
    }
});```
solid stone
#

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

distant tulip
#

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
    };
}
shy leaf
#

that one should work

distant tulip
#

pass the entity view direction and the head/barrel position to it

#

change this to the offset you want

alpine ibex
#

Do you guys know how to make custom enchantments?

distant tulip
#

item lore

solid stone
wary edge
# alpine ibex Do you guys know how to make custom enchantments?

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

cold grove
shy leaf
#

the attack damage part is above the enchantments in the image

solid stone
cold grove
solid stone
#
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 });
            }
        }
    });
distant tulip
solid stone
#

now seems it doesn't appear anywhere hmm

distant tulip
#

🤨

umbral scarab
#

Would anyone know why this isnt working?

solid stone
#

and thanks

distant tulip
wary edge
umbral scarab
#

getComponent

distant tulip
#

show full line

umbral scarab
wary edge
#

Yeah, equippable only works on players

umbral scarab
#

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?

solid stone
#

i'm still figuring out offsets

#

but yeh

wary edge
#

Ohhh i figured it out now

distant tulip
wary edge
umbral scarab
#

shouldn't be a name

wary edge
#

Its not an entity

#

You need
event.damageSource.damagingEntity

distant tulip
#

that is not the error source

wary edge
umbral scarab
distant tulip
#

how can you tell

umbral scarab
#

it fixed something lol

wary edge
#

Youre passing a damagesource not an entity

wary edge
distant tulip
#

oh yeah

#

lol

umbral scarab
wary edge
umbral scarab
buoyant canopy
#

you can use both

shrewd wedge
#

Hi

umbral scarab
buoyant canopy
shrewd wedge
#

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

umbral scarab
buoyant canopy
#

you are setting undefined to the player inventory, just don't set it

shrewd wedge
wary edge
distant tulip
#

entoty👀

shrewd wedge
buoyant canopy
wary edge
#

Lemme see if i can pull out the script i used for adk lib

shrewd wedge
#

">=" greater then or equal to

shy leaf
buoyant canopy
umbral scarab
wary edge
shy leaf
#

oh

wary edge
#

Check if the damageSource is an enttiy forst

umbral scarab
shy leaf
buoyant canopy
wary edge
shy leaf
wary edge
shy leaf
#

o

wary edge
#

Bc hes using damageSource whoch mau or may not have a damaging entoty

shy leaf
#

hard to tell from here

wary edge
#

Immaculate spelling errors

umbral scarab
#

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

wary edge
#

Underneath const entity

shrewd wedge
wary edge
shrewd wedge
#

It see if durability damage >= max durability and set undefined item?

wary edge
#

Yours checks for damage alone. Mines check for damage + the damage to add

umbral scarab
#

very confused

wary edge
shrewd wedge
#

Is console.warn

umbral scarab
#

oop

wary edge
#

Unless youre in preview or using vscode debugger

shrewd wedge
umbral scarab
wary edge
umbral scarab
#

taking fall damage

wary edge
#

Thats why, bc fall damage doesnt have a damaging entity. Tada

#

Now punch the entity and you should get your findGem executed

umbral scarab
#

how can I change it so it tracks all damage taken though like fall damage, fire etc

wary edge
#

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

umbral scarab
#

basically im trying to make it so theres a 15% chance of the damage source being blocked

umbral scarab
#

I know I cant cancel the event but im measuring the incoming damage and just simply healing it afterwards

shrewd wedge
#

But if player die?

umbral scarab
#

then they die

shrewd wedge
#

But you cannot test 15%

umbral scarab
#

ye ik

shrewd wedge
#

ok

umbral scarab
#

its intentional feature I want anyways

shrewd wedge
#

Oh

#

What is your error?

umbral scarab
#

I've got it figured out now anyways

shrewd wedge
#

Ok

umbral scarab
#

Thank you @wary edge and everyone else <3

shrewd wedge
#

Can you help

ivory bough
#

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?

wary edge
ivory bough
wary edge
ivory bough
#

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

alpine ibex
#

Is this possible?

if (entity.is!OnGround) {
wary edge
alpine ibex
#

Just confirming

cold grove
wanton ocean
#

What we really need is a website or database that properly displays this information for us to view for reference

valid ice
#

Stirante scripts
Jayly dev
Npm types

wanton ocean
#

Don’t say it.

#

My WiFi was too slow

wanton ocean
#

He was two steps ahead..

wanton ocean
valid ice
#

MS docs are fine, it just takes a bit to get used to their navigation.

wanton ocean
#

Bait used to be believable

alpine ibex
#

We r to dumb now show us step by step for hours until we get it bao_comm_hatchi_spin

wanton ocean
#

Okay I shall stop this tomfoolery at once

valid ice
#

What’s your problem with the options we’ve provided?

alpine ibex
cold grove
alpine ibex
#

Too complicated to do

valid ice
#

NPM types alone provide autocompletion, examples for certain things, and typing suggestions

alpine ibex
#

Erm Nah

wanton ocean
#

Guys

#

I think I found the references we need

#

Stirante scripts
Jayly dev
Npm types

alpine ibex
wanton ocean
#

What.

alpine ibex
#

Big. black. stacks Of Hard money

cold grove
alpine ibex
#

That's what I said

valid ice
#

What are you looking for

#

What do you require from a docs site

alpine ibex
#

Also I tried to replicate Dummmmmmmy from Java edition

#

And is 40% successful

wanton ocean
wanton ocean
#

So I did set block at first

#

With commands

#

But it still ignited the user

alpine ibex
#

How do you ignite someone with commands😭

wanton ocean
#

And I was gonna make a exception with tags but it’d go against a bunch of things

cold grove
#

Youre using commands in scripting

wanton ocean
wanton ocean
#

Finally…

cold grove
#

Oh Xd

wanton ocean
#

My mind has expanded ten fold

#

I can now light my friends on fire with ease

alpine ibex
valid ice
#

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

cold grove
valid ice
#

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.

wanton ocean
#

Doc sites are cool

#

I was just joking

valid ice
#

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

scarlet sable
#

How does a vector work?

valid ice
#

A vector is a point in 3D (or 2D) space

scarlet sable
#

Oh so just x y z coords?

valid ice
scarlet sable
#

Ty

#

Also ik it's possible to get player position but can you get player rotation too?

scarlet sable
#

I forgot that was a thing lmao

#

Th

#

Ty*

valid ice
#

Get rotation returns an x & y vector with the pitch & yaw of the entity
Get view direction returns a normalized x y z vector

distant tulip
#

getRotatioon()

#

nvm didn't see herobrine message

scarlet sable
#

Lol

#

Ty tho

scarlet sable
#

can you explain what a callback is pls?

fallow rivet
#

How do I prevent water from flowing into a claim?

scarlet sable
#

the addon can read your head rotation bao_icon_particles

inland merlin
#

Best strategy is prevent players from using the buckets in a distance from another claim and or height

#

Unless they own that claim etc

scarlet sable
#

is it possible to make a digital suite?

#

using js of course

inland merlin
scarlet sable
#

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

inland merlin
#

You can easily use a custom script api database to make data persistent.

#

Anyone here probably has one in an addon somewhere

lyric kestrel
#

I think I'm going to try make add-ons again

#

Haven't done that in ages

scarlet sable
#

that's intresting

inland merlin
scarlet sable
#

world.beforeEvents.chatSend.subscribe((event) => { const message = event.message; const player = event.sender

lyric kestrel
#

event is the call for chatSend that you assigned

scarlet sable
scarlet sable
#

that makes much more sense

lyric kestrel
#

it calls this word, which calls chatSend

scarlet sable
#

oh so subscribe is just there as a shortcut right?

inland merlin
scarlet sable
inland merlin
#

Not sure what you mean

lyric kestrel
inland merlin
#

(Subscribe) For the script to "listen" constantly.

last latch
#

ahh yes let me guess :
end stone brick wall === cobblestone_wall
(just like dirt === coarse_dirt)

inland merlin
#

🤯

last latch
#

my beloved api

distant tulip
# scarlet sable can you explain what a callback is pls?

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

distant tulip
#

cobblestone_wall*

lyric kestrel
#

Is the latest API 1.13.0?

#

And how do I see which is and which functions/classes I can't use?

distant tulip
#

pc?

lyric kestrel
#

ye

#

I can't find Jayly's site

distant tulip
#

hover over the function in vs code

distant tulip
lyric kestrel
#

thank you

scarlet sable
#

ty ty

#

this stuff is low-key fun ngl

valid ice
#

There's worse things to spend time on for sure lol

scarlet sable
#

fr lol

scarlet sable
distant tulip
#

install node js and the server version you need

scarlet sable
#

oh that's what it's for

#

cool af

#

how do i change the bit limit after the dot?

#

16 is too much

valid ice
#

Number.toFixed(decimals)

distant tulip
#

number.toFixed(amount)

scarlet sable
#

ty

valid ice
#

Where decimals is tue number of places to display to

scarlet sable
#

does that mean i can have more than 16?

valid ice
#

Note that the value does round, so 179.789 would round to 179.79 if toFixed(2) was used

scarlet sable
#

oh approximation

valid ice
valid ice
scarlet sable
#

if a constant is null

#

and you try to give it a value

#

will it like accept the first value?

#

or just stay null

valid ice
#

Wdym

scarlet sable
#

let's say you define
const X;

#

it's rn null

#

it has no value

valid ice
#

Yes

scarlet sable
#

if i later in the code try to give it a value will it accept it?

valid ice
#

It will not, as constants cannot be changed

#

If you use let, it will work, yes

scarlet sable
#

what can a null const be used for tho?

valid ice
scarlet sable
scarlet sable
valid ice
#

I personally have never used var, nor do I plan on using it

scarlet sable
#

var is the same as let isn't it?

valid ice
#

Never found a use for it that other variables haven't been able to do

#

Var is global scope, let is local

scarlet sable
#

oh that's useful

#

what are your projects btw?

#

like done addons

valid ice
#

Chest UI & realm packs are public on my github. But I have private addon packs for servers I develop for

scarlet sable
#

you work on the marketplace?

valid ice
#

I do not

scarlet sable
#

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

valid ice
#

Json ui magic to make a server form look like a chest

scarlet sable
#

wtf 💀

#

my brain

valid ice
#

And extensions to the vanilla APIs is very much possible, and pretty useful

scarlet sable
#

you recoded a server form with it ui to look like a chest?

valid ice
#

LeGend did most of the work in that regard, but yeah that's the idea there

scarlet sable
#

mind blowing

#

I'm even more surprised you do that for free

valid ice
#

I don't believe in selling packs lol

scarlet sable
#

ads maybe

valid ice
#

Anything I think is good enough to sell I keep private

scarlet sable
#

there are lots of ethical ways to profit

distant tulip
scarlet sable
#

btw when i want to give the var a new value i just do varname = value; right?

valid ice
#

Yep

scarlet sable
#

ty

valid ice
#

Unless it's a const

scarlet sable
#

yep

#

I'm making a simplified camera command addon

#

where you set the points using cemrapoint 1 2 3 etc.

valid ice
#

And I would recommend against type combining (e.g. setting a variable to a number and then a string later on in the code)

scarlet sable
#

then it compiles the coords and rot for you

scarlet sable
scarlet sable
#

unknown

distant tulip
#

just click it

scarlet sable
#

damn

#

I'm not planning on making new easing functions

distant tulip
#

it is not one? i think?
ease are client side

scarlet sable
#

and the particles are unnecessary for me

#

ye i think so

distant tulip
scarlet sable
#

but you can work arround it

scarlet sable
#

kinda nostalgic

distant tulip
#

lol
no arabic there just the title
i translate all my videos

scarlet sable
#

fair

#

the thing is the bedrock camera is laggy

#

idk why

#

even with the vanilla command

scarlet sable
distant tulip
#

item and block and attachable

scarlet sable
#

mhm

distant tulip
#

i have a bot that generate them from a skin and a name

scarlet sable
#

why is the first const an error?

distant tulip
#

open {}

scarlet sable
#

oh ye

#

ty

#

btw using vars for this one would be stupid

#

is there a way to make like a data base system?

distant tulip
#

array

scarlet sable
#

?

distant tulip
#

? for?

scarlet sable
#

wdym array?

distant tulip
#

you don't know what array are?

#

const cameraPointes = []

cameraPointes.push(location1)
cameraPointes.push(location2)
cameraPointes.push(location3)
...

scarlet sable
#

nope that's new for me

#

sounds like the perfect tool

distant tulip
#

it can store stuff inside
and yo can call them with an index
cameraPointes[0] is location1

scarlet sable
#

oh

scarlet sable
#

like allPlayer[0]

#

like this one?

valid ice
glacial widget
glacial widget
distant tulip
scarlet sable
#

is there an article about it in the microsoft website?

glacial widget
distant tulip
scarlet sable
distant tulip
scarlet sable
glacial widget
scarlet sable
glacial widget
distant tulip
glacial widget
#

alright time for the bedtime

scarlet sable
#

ohh ye i remember now

distant tulip
#

forEach is self explanatory

scarlet sable
#

they work like
const potato [1 ,2 ,3] right?

distant tulip
#

they?

scarlet sable
#

it

#

whatever lol

distant tulip
#

referring to?

glacial widget
scarlet sable
#

yep

glacial widget
#

potato = {} is a object

scarlet sable
#

ye i remembered

#

it's pretty cool

#

still not what i meant

glacial widget
#

just learn javascript first before doing script api, way better

distant tulip
#

arrays have some cool functions
searching mapping filtering ...

valid ice
#

Real

scarlet sable
#

can i make each var in an array into an object?