#Script API General

1 messages · Page 14 of 1

spring dove
#

havent touched script api in 2 weeks, there's any news?

merry ibex
#

Why doesn't this work?

import { world, system } from '@minecraft/server';

// Notify that scripts have been reloaded
world.sendMessage("§l§aqqq");

// Listen for chat messages
world.events.chatSend.subscribe((eventData) => {
const message = eventData.message;
const player = eventData.sender;

// Check if the message is the custom command
if (message == "!help") {
    // Send a help message to the player
    player.sendMessage("§l§a¡aaaaaaaaaaaaaaaaaaaaaaaa");
}

});

valid ice
#

events property on world does not exist

north rapids
#

How do I get the player's hp? Max Hp and damage?

flat barn
#

does this event not work anymore?

chilly moth
#

potions got new components

north rapids
#

Is it possible to test by player hunger?

shy leaf
shy leaf
#

though you can guess some of those but some are just unknowable

chilly moth
#

ok

distant tulip
shy leaf
#

and they didnt even put the list of it in docs

distant tulip
shy leaf
#

i dunno

granite badger
#

It’s in vanilla-data

shy leaf
#

i dunno why they didnt even mention that

#

it was really inconvenient

granite badger
#

well it’s beta so they may change it…? took a while for me to figure out too

distant tulip
#

MinecraftPotionModifierTypes
MinecraftPotionEffectTypes
MinecraftPotionLiquidTypes

shy leaf
#

oml theres no regeneration enum 💀

distant tulip
shy leaf
distant tulip
#

idk
there is also health boost

viscid horizon
#

This scripting sure likes to get on my nerves

#

And so do my parents

#

I had a function containing the thing that needs to activate the said function

#

damn I’m dumb

#

Doesn’t help I deconstructed the whole thing trying to find the whole problem

#

All it took was 1 ‘}’

amber granite
viscid horizon
#

I already fixed it but damn did I feel stupid

amber granite
#

Idk

#

But u should use vscode

#

For that

distant tulip
#

bridge should have syntax errors

cold grove
#

Do not use bridge for scripting

jaunty leaf
#

vsc on top

distant gulch
#

VsCode top!

fallow minnow
#

@granite badger do you have any idea why this happens when i use the new typings?

#

It's neveer happened before

granite badger
#

happens when using server beta and server-ui stable yeah?

distant gulch
#

invalid npm downloads?

fallow minnow
#

this one

#

Could it be because im using ESNext

slow walrus
#

nah

granite badger
#

{
  "overrides": {
    "@minecraft/server": "beta"
  }
}

You need to add the override key, and set beta to whatever version you’re using.

slow walrus
#

in ur package.json add this

"overrides": {
    "@minecraft/server-ui": {
      "@minecraft/server": "$@minecraft/server"
    },
    "@minecraft/server-net": {
      "@minecraft/server": "$@minecraft/server"
    },
    "@minecraft/server-gametest": {
      "@minecraft/server": "$@minecraft/server"
    }
  }
fallow minnow
#

i don't have a package json

#

the typings are global

#

they dont go on my packs

slow walrus
#

that's silly

#

don't use global typings

fallow minnow
#

any way to access the global package json?

slow walrus
#

no

#

don't use global typings

fallow minnow
#

idk how not to 😭

#

it just does it for me

slow walrus
#

just npm install without global??

fallow minnow
#

i never have global

slow walrus
#

you gotta specify the -g thing to do global

fallow minnow
#

i just npm i

granite badger
#

npm init -y to setup package.json first in your addon directory

fallow minnow
#

alright i have that

granite badger
#

reinstall every mc package you need

fallow minnow
#

any way to uninstall the global ones?

#

i got it

shy leaf
#

why does this remind me of everything package

devout hazel
#

has anyone tried creating a perlin noise height map in scripting? would it be possible to use it for custom generation?

distant tulip
#

con master have one i believe

sudden nest
buoyant canopy
#

that's crazy 🤣

distant tulip
#

yeah

shut citrus
#

Mojang pls don't remove entity.target !

distant tulip
#

Mojang pls make it not read only

vivid frost
#

I am wondering whether anyone here would have information about when the @minecraft/server-net API will leave the beta phase and become standard? I have several fun applications for it that I want to try developing, but I don't want to build stuff and learn down the road that the API was removed or that it changed, etc. Thanks for you help! 🙂

remote oyster
vivid frost
remote oyster
#

None at the moment.

#

Considering that it's still on (1.0.0) since it's debut, it may be a while.

vivid frost
# remote oyster Considering that it's still on (1.0.0) since it's debut, it may be a while.

I understand. Thanks for the info.

Do you know if that API is popular among developers? In other words, do people appear to be using it a lot for new types of applications?

I am new to Bedrock development and I am just trying to understand towards what my "experimentation efforts" would be best directed. Obviously, I personally find that API to be pretty interesting because it allows a lot of use cases, but I'm curious to know what other people think about it.

granite badger
#

keep in mind that server-net module is locked behind bedrock server only

remote oyster
# vivid frost I understand. Thanks for the info. Do you know if that API is popular among de...

They released it roughly 2 years ago. Not many use it, because the majority choose Realms over BDS due to "player base". Meaning that they feel it's easier for people to join their Realm on different platforms than a regular server.

Some people do use it, because they realize the potential it has, and think outside the box. However, I believe since it's been out for a couple of years now, it's probably only been within the last 3-4 months that it has begun to pick up popularity.

vivid frost
cold grove
#

I have work with server-net in the past, i used it to comunicate with a discord bot using an rest API i built

#

Player report system and some rank things

vivid frost
unique dragon
#

wondering @minecraft/server-gametest can make simulated players using a custom skin, like choosing a random player of the world, and then set the skin to the simulated player

cold grove
#

I have some things that i can share, maybe i will upldoad them to scripting-resources

shy leaf
unique dragon
vivid frost
unique dragon
#

😉

hazy nebula
#

Is there any way to close the ActionForm without response from the player

hazy nebula
#

How do you do that?

hazy nebula
cold grove
hazy nebula
cold grove
#

Its Beta

celest fable
#

how to make like auto coloring text for certain number?

#

something like this

const colors = {
    0: "§f",
    5: "§7",
    10: "§8",
    15: "§e",
    20: "§6",
    30: "§b",
    40: "§d",
    50: "§5",
    60: "§a",
    70: "§2",
    80: "§c",
    90: "§9",
    100: "§1",
    120: "§4",
    140: "§3",
    160: "§0",
    180: "§l§f",
    200: "§l§7",
    220: "§l§8",
    240: "§l§e",
    260: "§l§6",
    280: "§l§b",
    300: "§l§d",
    325: "§l§5",
    350: "§l§a",
    400: "§l§2",
    450: "§l§c",
    500: "§l§9",
    550: "§l§1",
    600: "§l§4",
    750: "§l§3",
    800: "§l§0",
    850: "§o§f",
    900: "§o§7",
    950: "§o§8",
    1000: "§o§e",
    1050: "§o§6",
    1125: "§o§b",
    1200: "§o§d",
    1275: "§o§5",
    1350: "§o§a",
    1425: "§o§2",
    1500: "§o§c",
    1600: "§o§9",
    1700: "§o§1",
    1800: "§o§4",
    1900: "§o§3",
    2000: "§o§0"
  }

but its automatic selecting the color from color list

hazy nebula
cold grove
#

1.4.0-beta

#

I dont see any reason to not update your game 👀

hazy nebula
remote oyster
# celest fable something like this ```js const colors = { 0: "§f", 5: "§7", 10: "§8...
import { world } from '@minecraft/server';

const colors = {
    0: "§f", 5: "§7", 10: "§8", 15: "§e", 20: "§6", 30: "§b", 40: "§d",
    50: "§5", 60: "§a", 70: "§2", 80: "§c", 90: "§9", 100: "§1", 120: "§4",
    140: "§3", 160: "§0", 180: "§l§f", 200: "§l§7", 220: "§l§8", 240: "§l§e",
    260: "§l§6", 280: "§l§b", 300: "§l§d", 325: "§l§5", 350: "§l§a", 400: "§l§2",
    450: "§l§c", 500: "§l§9", 550: "§l§1", 600: "§l§4", 750: "§l§3", 800: "§l§0",
    850: "§o§f", 900: "§o§7", 950: "§o§8", 1000: "§o§e", 1050: "§o§6", 1125: "§o§b",
    1200: "§o§d", 1275: "§o§5", 1350: "§o§a", 1425: "§o§2", 1500: "§o§c", 1600: "§o§9",
    1700: "§o§1", 1800: "§o§4", 1900: "§o§3", 2000: "§o§0"
};

world.beforeEvents.chatSend.subscribe((event) => {
    const player = event.sender;
    let message = event.message;
    
    // Example condition: color based on message length
    let length = message.length;

    // Find the appropriate color based on the message length
    let closestColorKey = Object.keys(colors).reverse().find(key => length >= parseInt(key));
    
    if (closestColorKey) {
        const colorCode = colors[closestColorKey];
        event.message = `${colorCode}${message}§r`;
    }
});
random flint
# hazy nebula

You don't do new UIManager(), just import { uiManager } from "@minecraft/server-ui"

wary edge
#

Its not useable

keen nymph
#

i'm trying to make the 2d item texture not render using attachables, but i've added the file and it doesnt do anything. no content log, no nothing. i even tried just copypasting like the bow or something and it doesnt render the bow nor does it stop rendering the 2d item texture...

wary edge
#

#1019692489596215388 message

wary edge
keen nymph
#

kk

hazy nebula
#
[Scripting][error]-Unhandled promise rejection: ReferenceError: No constructor for native class 'UIManager'.```
#

What is needed for it to work?

honest spear
#

give me sec

#

yes

buoyant canopy
#

i have a question
i have this module/script that i import data from, there is the categories constant which contains raw data, and 2 functions that process them into the achievements constant,
now does the flat_category function run everytime i import achievements, or does it only run once when the script is validated?

hazy nebula
honest spear
honest spear
hazy nebula
valid ice
#

the ts part isn't needed

honest spear
#

import it not export it

valid ice
#

can just do import {uiManager} from '@minecraft/server-ui'

honest spear
#

yes

valid ice
#

and then uiManager.closeAllForms(player)

honest spear
#

we to pin some tutorials here

valid ice
honest spear
#

like how to import

#

and what object is

valid ice
#

Expanding on the wiki would be good, and getting a stable version of the API on the wiki would be exellent (so people using it don't have stuff break)

honest spear
#

also diference between parameter and argument

honest spear
valid ice
#

I may look into expanding script wiki today

honest spear
#

today?

#

nice

#

let me know about your plans

valid ice
#

I got spare time shrug

honest spear
#

i am on vacation so i dont have much resources to work with, but i may do something

viral plaza
#

Is player.velocity a valid method?

valid ice
#

I can add you to my fork of the wiki

hazy nebula
# valid ice and then `uiManager.closeAllForms(player)`
function spawn(player) {
    const playersInUI = new Set();
    const chestui = new ChestFormData(27);
    chestui.title('§l§d      Event Crates');
    for (let i = 0; i <= 11; i++) {
        chestui.button(i, '', [''], 'minecraft:gray_stained_glass_pane', false);
    }
    for (let i = 15; i <= 26; i++) {
        chestui.button(i, '', [''], 'minecraft:gray_stained_glass_pane', false);
    }
    chestui.show(player).then(response => {
        uiManager.closeAllForms(player)
        return;
    });
}```When I open the form, it doesn't close that form. What is the issue I am facing?
valid ice
#

The response only triggers when the player chooses an option

#

Not when the form opens

honest spear
honest spear
true isle
distant gulch
#

Hello everyone, please tell me how to load a lot of structures quickly. I have 4 64x64 structures and when loading them, the game lags a lot on a powerful computer

honest spear
fallow rivet
#

How do I test which slot a player's item is in?

distant tulip
distant tulip
fallow rivet
#

Translation is sometimes wrong

distant tulip
#

player.selectedSlotIndex

fallow rivet
#

Has ChatSend been removed?

remote oyster
fallow rivet
remote oyster
fallow rivet
#

I think this is it

remote oyster
fallow rivet
#

Ok

#
const encid = enchantments.map((ench) => {
        return {level: ench.level, type: ench.type}
    });
#

Fixed

unique dragon
valid ice
#

ye

unique dragon
#

interesting

fallow rivet
#

How do I add a name to an item using additem?

fallow rivet
valid ice
#

closes all forms

spare fox
#

does interval_range even have an effect to onTick?

spare fox
wary edge
fiery solar
iron jewel
#

why no worky?

{
    "format_version": 2,
    "header": {
        "name": "RPG",
        "description": "TYavaJ's RPG project",
        "min_engine_version": [
            1,
            20,
            80
        ],
        "uuid": "1153bf7a-cb39-4282-b70b-ff10b7120bec",
        "version": [
            1,
            21,
            20
        ]
    },
    "modules": [
        {
            "type": "data",
            "uuid": "cb3a43a5-ae49-4612-b945-fe7469381faf",
            "version": [
                1,
                0,
                27
            ]
        },
        {
            "type": "script",
            "uuid": "59a3b25f-7752-474c-8f90-a948376c6220",
            "entry": "scripts/index.js",
            "version": [
                1,
                0,
                27
            ]
        }
    ],
    "dependencies": [
        {
            "uuid": "0e6331ef-fd94-4a88-8eda-5e1264e197f5",
            "version": [
                1,
                0,
                27
            ]
        },
        {
            "module_name": "@minecraft/server",
            "version": "1.13.0"
        },
        {
            "module_name": "@minecraft/server-ui",
            "version": "1.2.0"
        }
    ]
}```
distant tulip
#

that is not the source of the error

iron jewel
#

tf you mean 💀

cinder shadow
#

Did you read the error?

iron jewel
#

indeed

cinder shadow
#

what does it mean to you

distant tulip
iron jewel
#

well I dunno but I can tell ya that

       {
            "module_name": "@minecraft/server",
            "version": "1.14.0-beta"
        },
        {
            "module_name": "@minecraft/server-ui",
            "version": "2.0.0-alpha"
        }```
doesn't work any more than anything else
cinder shadow
#

You are referencing a module that doesn't exist

#

and then it lists out the versions that do exist

iron jewel
cinder shadow
#

That's because that's not the only problem

#

That's just one of them

iron jewel
#

,_ ,

distant tulip
#

you are using the developer behavior pack folder?

iron jewel
#

yeah

cinder shadow
#

does 2.0.0-alpha even have anything in it?

iron jewel
#

I have no idea

spring dove
#

my addon doesnt work on the new update:(

#

what could be

distant tulip
iron jewel
iron jewel
distant tulip
distant tulip
#

unless the pic you sent was not for the code you sent

cinder shadow
#

I don't think there's anything 2.0.0-alpha

spring dove
#

what

#

some beta feature changed?

distant tulip
#

read

spring dove
#

alright

iron jewel
# cinder shadow I don't think there's anything 2.0.0-alpha

this is the current dependencies section (which does not infact work)

    "dependencies": [
        {
            "uuid": "0e6331ef-fd94-4a88-8eda-5e1264e197f5",
            "version": [
                1,
                0,
                26
            ]
        },
        {
            "module_name": "@minecraft/server",
            "version": "1.14.0-beta"
        },
        {
            "module_name": "@minecraft/server-ui",
            "version": "1.3.0-beta"
        }
    ]```
#

so

cinder shadow
#

Okay, well use that in your manifest

#

then send screenshots of the errors

#

the invalid module ones will be gone

spring dove
#

1.14.0-beta

#

right?

glacial widget
#
function addMoney(player){
    const moneyObj = world.scoreboard.getObjective("Money")

      new ModalFormData()
        .title("Send player")
        .textField("Amount, Has to be atleast 1k", "Enter amount of money")
        .show(player).then(d => {
          const moneyAmount = d.formValues[0];
          if (moneyAmount){
            moneyObj.addScore(player, `${moneyAmount}`)
            player.sendMessage(`HCV KitPvP >> ${player.name} has sent you ${moneyAmount}`)
          }
    });
}
spring dove
#

i just changed it

glacial widget
iron jewel
distant tulip
# spring dove

that will work if none of the stuff you are using got changed

glacial widget
glacial widget
distant tulip
#

there is?
addScore receive number

cinder shadow
# iron jewel

If you're getting those errors, you are not using the development folders

#

or you switched the versions back

thorn flicker
distant tulip
#

or
0+moneyAmount

glacial widget
#

it worked thanks man

cinder shadow
#

stop switching the module versions back to the incorrect ones then, the errors you are getting in content log are specifically mentioning the wrong ones you had, not the correct ones

distant tulip
iron jewel
#

wdym? This BP does not exist in the main folder

spring dove
glacial widget
#

into the main js

distant tulip
iron jewel
#

I did

iron jewel
distant tulip
iron jewel
#

ikr 🔥

distant tulip
cold grove
iron jewel
distant tulip
#

you have something going on there
1.2.0-beta is not the version you are showing us
that mean there is a file somewhere that use that

#

backup your pack and delete it in game

iron jewel
#

I would perfer not to do that but like

iron jewel
#
    "dependencies": [
        {
            "uuid": "0e6331ef-fd94-4a88-8eda-5e1264e197f5",
            "version": [1, 0, 26]
        },
        {
            "module_name": "@minecraft/server",
            "version": "1.14.0-beta"
        },
        {
            "module_name": "@minecraft/server-ui",
            "version": "1.3.0-beta"
        }
    ]```
#

was correct

distant tulip
#

🤷‍♂️

random flint
# iron jewel

Blind moment.

you're using 1.2.0-beta - @minecraft/server-ui. Error stated that module doesn't exist. The latest beta module in your list says 1.3.0-beta, use that instead.

#

For @minecraft/server you're using 1.12.0-beta which doesn't exist.

Use your eyes and look down on that list, and you'll find that 1.14.0-beta is the latest beta module

random flint
random flint
north rapids
#

How can I break a block? Is it only possible using commands?

#

Ty

pale terrace
#

I added custom components to my onPlayerDestroy and onPlace block and it happens that when interacting with the block it makes the swing animation, is that normal?

pale terrace
#

I guess it's a bug to be resolved

somber echo
#

Help i dont understand what is the problem, can someone help me with this?

const color = { red: 0, green: 1, blue: 0 };
const colorMapVar = new MolangVariableMap().setColorRGB("color", color);
world.getDimension('overworld').spawnParticle('minimap:line_particle', {
    x: -53,
    y: 320,
    z: -23
}, colorMapVar);```
gaunt salmonBOT
#

Debug result for [code](#1067535608660107284 message)

Compiler Result

Compiler found 1 errors:

<REPL0>.js:7:4 - error TS2345: Argument of type 'void' is not assignable to parameter of type 'MolangVariableMap'.

7 }, colorMapVar);
     ~~~~~~~~~~~

Lint Result

There are no errors from ESLint.

deep plank
viral plaza
#

How can I do http requests in script api?

shy leaf
fiery solar
viral plaza
#

That’s fine

#

Thanks

pale terrace
#

getTags from a block cant get a custom tag?

subtle cove
#

can...

#

how did u set it up?

pale terrace
#

its returning undefined

subtle cove
#

but minecraft: works, right?

pale terrace
#

aah, it was my mistake, I was trying to get the tag of a destroyed block xd

neat hazel
#

How to use "translate" on ActionForm buttons?

deep plank
hazy nebula
#

How to save structure with script?

neat hazel
shy leaf
valid ice
#

Not all, but most do

shy leaf
#

nice

neat hazel
true isle
#

im super confused as to why my pack wont load. i changed everything to the latest beta and my pack dissapears i changed it back to what it was befor the update and the scripts dont load lol

cold shoal
#

Do dynamic properties actually resets when re-adding an addon? Doesn't happen for me when testing

cold shoal
#

alr, thanks!

fallow minnow
crude bridge
#

it can't be used

north rapids
#

How do I disable the target's shield when attacking?

glacial widget
#

is there anywhere to cancel a players hits?

distant tulip
distant tulip
north rapids
#

Apparently hitting the shield does not count as a trigger for onHitEntity or onDurabilityDamage.

distant tulip
#

you mean before the attack?

north rapids
#

CustomComponents so, yeah

distant tulip
#

get entity from view

#

you can also just subscribe to hit event and apply your own damage

north rapids
#

Ok, I'll see

modest oasis
#

hi, what manifest should I put inorder to run script in 1.21.20?

#

im using this but not working anymore

{
    "format_version": 2,
    "header": {
        "name": "Dokkaebi",
        "description": "script training",
        "uuid": "9a5e17d3-8ca7-4f5c-83c2-c1177ac988ec",
        "version": [0, 0, 1],
        "min_engine_version": [1, 20, 60]
    },
    "modules": [
        {
            "type": "data",
            "uuid": "49da1514-2614-49c2-a5b3-59ae21c85e67",
            "version": [1, 0, 0]
        },
        {
            "type": "script",
            "uuid": "db7397bd-a1a5-4f48-933c-e88d1af1f1fe",
            "entry": "scripts/main.js",
            "version": [1, 0, 0]
        }
    ],
    "dependencies": [
        { "module_name": "@minecraft/server", "version": "1.12.0-beta" },
        { "module_name": "@minecraft/server-gametest", "version": "1.0.0-beta" },
        { "module_name": "@minecraft/server-ui", "version": "1.2.0-beta" }
    ]
}
#

should I also change the min_engine_version?

#

tysm

hazy nebula
#

Is there a way to save a player's enderchest to the database?

distant tulip
celest fable
#

how to start a ride like /ride but with native method?

honest spear
#

There is component as far as i know check docs

celest fable
#

I'm beginner:)

honest spear
#

Oh

#

Do you see docs? there must be some kind of parameters but not sure which one

#

let me look at docs

honest spear
#

i didn't test it tho

hazy nebula
#

What is the error?

#
item.getComponent('enchantable').addEnchantments(items[4].enchantment.id, items[4].enchantment.lvl);```
celest fable
hazy nebula
celest fable
hazy nebula
#
[Scripting][error]-TypeError: must be called with new    at EnchantmentType (native)
    at <anonymous> (Crate.js:254)
valid ice
#

new EnchantmentType()

woven oyster
glacial widget
#
import { world, Player, system, ItemStack, Block} from "@minecraft/server";
import { ModalFormData, ActionFormData } from "@minecraft/server-ui";

world.afterEvents.playerInteractWithBlock.subscribe((e) =>{
    const { block, blockFace, itemStack, player } = e

    if(itemStack.typeId == "minecraft:diamond" && block.typeId == "minecraft:end_portal_frame"){

        system.run(() =>{
            player.runCommand("/clear @s diamond")
            player.sendMessage(`HCV KitPvP >> has sold your diamond for ${itemStack.amount}`)
        })
    }
})

why does this not start?

shy leaf
distant tulip
#

also system.run is not needed

glacial widget
#

still dont start

glacial widget
shy leaf
#

youre using afterEvents for it

#

also please for the love of god, use content logs

glacial widget
#

I always have them on

neat hound
#

How to add a temp property to a player? ( I know it does not stay when they leave)

valid ice
#

player.tempProperty = whatever

neat hound
#

ah I went in too deep

valid ice
#

It does stay when they leave-- just if the world gets closed then they are reset.

#

So singleplayer? Reset
Last one to leave a realm? Reset
BDS? Not reset, unless /reload or world restarts

neat hound
#

the one bit of information I need when a block is placed is only in playerInteractWithBlock types (faceLocation)... I am trying to get where on the block face was clicked.... so I need to save it from use it in custom component

#

for beforeOnPlayerPlace.. so I can do simpler permutaions

valid ice
neat hound
#

I am putting an object in a var called f3... LOL... where I can store current info)

valid ice
#

excellent

prisma shard
#

hi

slim spear
remote oyster
#

What creative ways do any of you have for looking at a projectile arrow and determining the effects it may contain?

Curious to see if anyone came up with any quirky solutions since the API is limited in this area.

prisma shard
#

idk what did i just said

neat hound
# valid ice excellent

Hey , just realized beforeEvents.playerPlaceBlock has faceLocation but blockComponentRegistry.registerCustomComponent beforeOnPlayerPlace DOES NOTwhich makes me have to use a work around of saving the information via dynamic props or to the player.f3 object I made using beforeEvents.playerInteractWithBlock to get it saved (but for all blocks).

Oversight? Requestable to mojang to add? Do I just use the old way instead of the custom component?

#

If they had just added a dang horizontal_half when they did vertical_half.. I'd be set for the permutations I need... this information makes life easier to do stuff based on where clicked on block.

#

Where do we suggest for script api stuff anyway? Anyone?

remote oyster
#

I would need to look really quick.

#

I can't find the information on it 😔. Which is odd

neat hound
#

not sure what to do, this affects how I JSON the block. I can ditch their states and use mine or do a hybrid to permutate the rotation of the block.... but changing state names or adding/deleting on a block in play breaks previous blocks.... I think.... I better fact check that.

remote oyster
#

I'm just baffled that I can't find the source to link you.

distant tulip
remote oyster
#

I was discussing it with someone else just recently and we think that this isn't accessible from an arrow outside of it being an item type. Which means it would be very restrictive.

distant tulip
remote oyster
#

Can't clone it. It's an entity.

distant tulip
remote oyster
#

Not following. I'm talking about an arrow that is being projectiled through the air.

distant tulip
remote oyster
#

Oh, nah, can't do that. Way too expensive.

distant tulip
remote oyster
distant tulip
#

getEffects don't work?

remote oyster
#

Returns []. It's empty.

distant tulip
remote oyster
#

Data values

distant tulip
#

those are for the item
the entity is different
it is nbt data under mobEffects list
can't do anything about both in script api anyway

remote oyster
serene radish
#

😀

tawny peak
#

how do i set an actionbar text

#

thx

#

it says it's "not a function"

distant tulip
#

the code he sent is correct

#

nvm

#

setActionBar

#

uppercase bar

#

most javaScript functions are like that

tawny peak
distant tulip
#

yeah, in game names should be the same

thorn flicker
pliant tiger
#

Who have a code that when the player looks at the entity it stop moving but when he is looking away it moves and attacks him

#

means freeing the entity while looking at it, but when u look around it will start chasing the player just like the horror addon thing

distant tulip
#

that should be implemented mostly without script api

pliant tiger
#

Can you make it for me plss

#

And send it in dm

#

If anyone can

distant tulip
#

no sorry

pliant tiger
#

@distant tulip

distant tulip
pliant tiger
#

Cool me too

#

My name is Ahmed

#

From 🇸🇦

distant tulip
#

that is great
nice to meet you

pliant tiger
#

You cant make the code right

distant tulip
#

it is too much work for just helping someone

pliant tiger
#

Just try

#

I searched alot

distant tulip
#

make the entity and i will help you with the script part

pliant tiger
#

I have it

#

The model

distant tulip
#

i meant the behavior

shut citrus
#

Is typescript and js same?

amber granite
#

Yes

#

Type script is just typed js

distant tulip
#

yes but no

#

typeScript extends JavaScript by adding types to it

celest fable
#

why is this structure of code looks different than the other?

var Something
(function (Something) {
  export function other() {}
  Something.other = other
})(Something || Something = {})
amber granite
#

?

#

Idk if exporting function inside a function is possible

#

But it s not

#
  • the last () is made for passing arguments
amber granite
fallen hearth
#

why doesn't this work?

  initEvent.itemComponentRegistry.registerCustomComponent('blc:on_use', {
    onUse: ev => {
      const player = ev.source;
      const ItemStack = ev.itemStack;
      if (ItemStack.typeId === 'blc:shunpo') {
        source.runCommand('summon cow');
      }
  }});
amber granite
#

Excuse us ? What ?

fallen hearth
#

item is 1.21.10?

amber granite
#

item ?

#

U mean onUse ?

fallen hearth
#

I got the item version wrong, I just saw it

amber granite
#

What the error?

fallen hearth
#

item version

amber granite
#

Ok

fallen hearth
#

thankys

amber granite
#

Thanks for what XD ?

#

I didn't even do a thing

fallen hearth
#

you try to help

amber granite
#

Ok uw

gaunt salmonBOT
#

Latest NPM Types

npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]

Beta APIs NPM Types

npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]

Preview Latest NPM Types

npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]

Preview Beta APIs NPM Types

npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
unique dragon
#

onRandomTicking needs the minecraft:random_ticking component?

iron jewel
#

so I was thinking about making some sort of combo system

#

like you right click and left click the air

#

and it says like "R-L-L" on the screen

#

or something

#

similar to Wynncraft

#

but there's like no way to detect punching the air

celest fable
#

how to create new itemstack for stonetype that use the datafield like granite, andesite, or diorite?

gaunt salmonBOT
#

Latest NPM Types

npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]

Beta APIs NPM Types

npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]

Preview Latest NPM Types

npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]

Preview Beta APIs NPM Types

npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
drifting ravenBOT
unique dragon
#

bro

#

#bot-usage

glass gull
#

ik

unique dragon
#

well, if u know, why u do that

glass gull
#

bc it doesnt have the @gaunt salmon bot

unique dragon
#

#debug-playground

glass gull
#

oh shit its there

#

lol

hazy nebula
#
const newItem = new ItemStack(items[4].id, items[4].amount);
                                    if (items[4].enchantment.id !== '') {
                                        newItem.getComponent('enchantable').addEnchantments([{
                                            type: new EnchantmentType(items[4].enchantment.id),
                                            level: items[4].enchantment.lvl
                                        }]);
                                    }
                                    if (items[4].lore !== '') {
                                        newItem.setLore(items[4].lore);
                                    }
                                    newItem.nameTag = items[4].name;
                                    slot.setItem(newItem);```I cannot set the item if it matches items[4].lore. Is there any way to fix this?
valid ice
#

Can you send what items[4] actually is?

hazy nebula
valid ice
#

No object properties?

hazy nebula
# valid ice No object properties?

Not even when I change it to newItem.setLore('mythic'), it still reports the error [Scripting][error]-TypeError: Native optional type conversion failed. Function argument [0] expected type: string[] | undefined at <anonymous> (Crate.js:414)

valid ice
#

oh, setLore requires an array of strings, not a single string

#
newItem.setLore(['mythic'])
hazy nebula
dense skiff
#

The Minecraft Debugger settings should just be in main menu > settings > Creator right? They seem to have gone missing

dense skiff
#

Yeah

#

It's not there for me lol

unique dragon
#

lol, try to restart

dense skiff
#

I have several times xD

distant tulip
# unique dragon

disable content log file and delete the old ones
they take a lot of storage

#

my log folder was like 5 Gb

pale terrace
#

someone use that files actually?

unique dragon
distant tulip
unique dragon
pale terrace
distant tulip
pale terrace
distant tulip
#

chat gui is limited too

#

and you can't copy

pale terrace
pale terrace
distant tulip
#

depend
maybe you need an exact value from the game
or yo formatted an object and want to copy it for other uses

pale terrace
#

I prefer to keep the debug and the error console separate, otherwise I get confused sometimes

distant tulip
#

yeah
i use chat too some times
tbh i hate the log covering my screen

pale terrace
#

same

misty pivot
#

if i just import a file like

import "./myFile";```
does it also import stuffs that are export? like
```js
export function myFunction()```
slim spear
#

I believe

#

import {myFunction} from "./myFile"

distant tulip
slim spear
#

Another thing

slim spear
distant tulip
slim spear
gaunt salmonBOT
#

Latest NPM Types

npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]

Beta APIs NPM Types

npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]

Preview Latest NPM Types

npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]

Preview Beta APIs NPM Types

npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
npm i @minecraft/[email protected]
distant gulch
#

just needed thm sorry

misty pivot
#

is there some sort of function chain limit or smth like that? because i made a function run a function which runs a few functions, sorta like this

import { function1, function2, function3 } from "./differentFile";
function functionSet() {
    function1()
    function2()
    function3()
}

function myRootFunction() {
    functionSet()
}```
#

and it didn't seem to run

#

for context, im doing this because i wanna group up functions to be able to make some sort of skills system, the "root" function detects whether a specific condition is met which then runs the "set" function/group of functions

remote oyster
misty pivot
#

i forgot, let's say functions 1 to 3 is from a different file and just imported

#

can it still run those?

remote oyster
#

Calling a function from another file will require that function to be exported and imported.

misty pivot
#

yep did that, im not sure what's the problem now

remote oyster
#

Will still run of course.

remote oyster
#

Wait, nevermind. I looked at your syntax wrong.

#

You are in fact calling

misty pivot
#

updated it so the functions 1 to 3 are now called

distant tulip
remote oyster
distant tulip
#

that not a return

#

throw

misty pivot
#

maybe the problem is not the functions, lemme test something

remote oyster
misty pivot
#

ah, so the functions are fine

#

the if statement doesn't run tho

#

i cant explain it well but lemme make an example

#

scripts/differentFile.js

function function1(name) {
    if (name == "bob") {
        ...
    }
}```
main.js
```js
function compiledFunctions(name) {
    function1(name)
    function2(name)
    ...
}

function rootFunction(name) {
    compiledFunctions(name)
}```
#

i have something similar to this but the if statement of function1 doesn't run idk why tho

#

there doesn't seem to be an error aswell

remote oyster
#

I don't know what you are passing to function1 but I would suggest using === versus == for strict type checking. You can do a quick Google search to determine the benefits of that.

Best I can say is to print the variable name in function1 to verify if it's what you are trying to conditionally check against.

misty pivot
#

alright i'll check the values being passed through

#

ah i see, thanks for suggesting me to check the values, it turns out im off by one object in an array

distant tulip
#

when this happen 🤡

static nebula
#

Could someone help me? I'm making a script that if the player looks 100% up or down he gets a boost, But any other angle it gains boost forward or sideways.

honest spear
#

also please explain it in more details what you want to achieve

static nebula
honest spear
#

just display the viewVector and save its Y values then just compare

static nebula
honest spear
#

for example 99.9% should be OK

subtle cove
#
sytem.runInterval(() => {
    for (const p of world.getAllPlayers()) {
        console.warn(p.getHeadRotation().y)
    } 
})
#

Was it headrot, idk correct me if im wrong

static nebula
#

This worked, thank you very much

#

I just have one more question, how do I do it now so that when the player is looking at any other direction it gains boost in a specific direction?

static nebula
shy leaf
#

holy fuck, block with custom components are a real headache

amber granite
shy leaf
#

i need onTick too

valid ice
#

Custom components offer a good variety of features

#

You could use world events, but, eh

amber granite
#

Idk but events are more easier and no need to fix errors 2000 times

#

And after that u realize it was min-version problem

valid ice
#

At least for the tick custom components, you can’t replicate that using world events

tiny tartan
#

player.dimension.spawnEntity(items.projectile, spawnLoc); why does this gives error
Failed to run function

#

does entity need to have is_summonable: true

#

in json

tiny tartan
#

Thx

distant tulip
valid ice
#

A custom implementation of ticking would be… interesting

static nebula
#

@distant tulip Could you help me with my script? If so can I send you a dm?

distant tulip
#

you can send your question here

distant tulip
static nebula
#

And what kind of guy am I trying to make a pig like a helicopter, Then I did that part of the script when he is looking in a direction other than up or down or It only goes forward, which is what I want when I look in a certain direction. So I wanted you to help me fix this.

distant tulip
#

open a post and share your code

static nebula
#

Ok

umbral scarab
#

Would anyone know how to make an item that can't be broken?

subtle cove
#

items are vanilla, but u can copy it and setItem when it's broken

summer walrus
#

can't we just set the item durability to something crazy high

shy leaf
#

i just crashed my game with custom components

remote oyster
#
world.afterEvents.playerSpawn.subscribe((event) => {
    const check = event.player.getDynamicProperties("firstJoin") || false;
    if (event.initialSpawn && !check) {
        console.log(`${event.player.name} has joined for the first time. Welcome!`);
        event.player.setDynamicProperties("firstJoin", true);
    }
});
remote oyster
#

So do you want to know if a player has joined the world for the first time or do you want to know if it's the first time the world has been loaded?

shy leaf
#

no logs either

remote oyster
shy leaf
#

ikr

#

god i hate this

remote oyster
#
world.afterEvents.worldInitialize.subscribe(() => {
    const check = world.getDynamicProperties("firstLoad") || false;
    if (!check) {
        console.log(`First time this world has been loaded!`);
        world.setDynamicProperties("firstLoad", true);
    }
});
tender ocean
#

Why does my friends vscode not show the autocompletion for certain things like entity.getComponent()? it just shows 'isValid', 'entity', 'typeId', while mine show the actual stuff in the component i define

tender ocean
#

JS Stable

#

i made him install the latest stable npms

wary edge
#

Because getComponent just returns a component and in beta they have the type maps. Since intellisense doesnt know what child class getComponent is referring to thats why it only shows the default component's properties

tender ocean
#

so i have to make him install the beta ones?

tender ocean
#

works

iron jewel
#

so I was thinking about making some sort of combo system
like you right click and left click the air
and it says like "R-L-L" on the screen
or something
similar to Wynncraft
but there's like no way to detect punching the air

north rapids
#

How do I get the cardinal direction the player is facing?

wary edge
north rapids
#

getViewDirection(), right?

valid ice
#
function cardinal_direction_2d(angle) {
    if (Math.abs(angle) > 112.5) return 2.0; //North
    if (Math.abs(angle) < 67.5) return 3.0; //South
    if (angle < 157.5 && angle > 22.5) return 4.0; //West
    if (angle > -157.5 && angle < -22.5) return 5.0; //East
    return 6.0; //Undefined
};
``` is what I use for 2d placement
north rapids
#

Ty

chilly moth
#

does the block bench default cardinal don't work?

#

I thought only the pillar state had the issue

shy leaf
#

how do i use getItemStack for blocks

#

i put it inside component registry but it returns undefined

iron jewel
#

ooo

#

so

#

it wouldn't interrupt interactions and stuff

#

but it would still detect

fallow rivet
#

Where are the records recorded by Dynamicproperty stored?

north rapids
# valid ice ```js function cardinal_direction_2d(angle) { if (Math.abs(angle) > 112.5) r...
function getView(vec,type) {
  const x = Math.round(vec.x);
  const y = Math.round(vec.y);
  const z = Math.round(vec.z);
  switch (type) {
    case "direction":
      if (y !== 0) return "vertical";
      if (z !== 0) return "n/s";
      if (x !== 0) return "e/w";
      break;
    case "cardinal":
      if (y > 0) return "up";
      if (y < 0) return "down";
      if (z < 0) return "north";
      if (z > 0) return "south";
      if (x > 0) return "east";
      if (x < 0) return "west"
      break;
    default: break;
  }
};
#

I made this function

tawny peak
#

does anyone know how to get/set an scoreboard value for a fake player?

iron jewel
#

yeah it doesn't really work

#

at least in a way that would be useful

#

only thing I can think of is replacing it with Shift+Right instead of left clicking

#

although I gotta make sure you can detect right clicks without holding anything

fallow rivet
# iron jewel

Well, if there is a block there, can't you rent it?

spring dove
#

its there a key to open content log gui?

valid ice
#

ctrl+h

spring dove
chrome flint
#

how do i apply node modules to a specific pack again?

#

i forgot how to do packages and stuffs

amber granite
#

node js ?

chrome flint
#

yeah

amber granite
#

Are u sure ?

chrome flint
#

idk

#

these ones

amber granite
#

U can't use node js modules inside the game

chrome flint
#

i know, i just need it for typescript completion for a specific pack

amber granite
#

Oh

chrome flint
#

i have beta api installed globally

#

but i need one only for stable

amber granite
#

Cd to ur scripts directory

#

Then
Run command
npm install i guess

#

Or idk too , sorry

chrome flint
#

yeah i did that but it didn't installed it in the directory where i opened the cmd

chrome flint
#

solved it, it just need to have a package.json first by doing "npm init -y" in the directory

true isle
#

how do i exclude a blockstate in a string with other blockstates

amber granite
#

Elaborate

weary umbra
lone thistle
# tawny peak does anyone know how to get/set an scoreboard value for a fake player?
import { world } from "@minecraft/server";

export function getPlayerScore(entity, objective) {
    try {
        return world.scoreboard.getObjective(objective).getScore(entity);
    } catch (e) {
        return 0;
    }
}

export function setPlayerScore(entity, objective, score) {
    try {
        const scoreboard = world.scoreboard;
        const obj = scoreboard.getObjective(objective);

        if (typeof entity === 'string') {
            const player = world.getAllPlayers().find(p => p.name === entity);
            if (player) {
                obj.setScore(player.scoreboardIdentity, score);
            } else {
                obj.setScore(entity, score);
            }
        } else {
            obj.setScore(entity.scoreboardIdentity, score);
        }
    } catch (e) {
        console.warn(`Error setting score: ${e}`);
    }
}
crude bridge
#

Chill

#

Ik

#

Chilllllllllllll

#

I don't know I'm tired

#

For me its 2a.m.

#

Okay alex

lone thistle
#

Always depends on how you're gonna use the functions

#

They asked for a way of getting and setting score values for fake players, I sent two functions that can be used globally so how's that "irrelevant" ?

#

Yeah, that's why typeof entity === 'string' is there

crude bridge
#

I told you to chill

lone thistle
#

Didn't know it looked overcomplicated until you pointed it out, it just catches errors and checks if the returned string is an online player before proceeding

misty pivot
#

i wanna get the entities 2 blocks from the view direction of the player, i used

{x: player.getViewDirection().x*2, y: ..., z: ...}```
but yeah since it's a normalized value (i think) i would say it would be like this `0.4*2` which results in `0.8`, i am aware of local coordinates posted in script-resources but ngl it's a bit complicated for me
#

basically asking for a dumbed down explanation of getting local coordinates

spring dove
misty pivot
#

try const?

spring dove
misty pivot
#

oh i see the problem

spring dove
#

what

misty pivot
#

it wouldn't run because the first if statement negates the second one

spring dove
#

mmm so

misty pivot
#

i'll fix it for you dw, but basically make the if (setup==1 && start==0) inside the system.runInterval instead of outside

spring dove
#

Ok

misty pivot
#
let lobbyPlayerManagement = system.runInterval(() => {
    if(setup==1 && start==0){
        let players = world.getAllPlayers()

        for (const player of players) {
            let {x,y,z} = player.location

            if(y<200){
                player.teleport({x:0,y:260,z:0})
            }
        }
    }
    if(setup==1 && start==1){
        system.clearRun(lobbyPlayerManagement)
    }
},20)```
#

try running it now

spring dove
#

didnt worked

#

but dont worry i think i have another solution

misty pivot
#

oh yeah i forgot

#

put setup and start in the interval aswell

#

might work

spring dove
#

omg my logic didnt got it for a long time

spring dove
misty pivot
#

no problem

misty pivot
strong oar
#

Can I ask if anyone knows or can make a interact on a block when it is clicked by a stick the block will change?

valid ice
#

Is there a file for before events ordering? I know the one for after events exist, but idk if one for before exists.

spring dove
#

men, how do i give players enchanted items, i dont get the item stack working

#

i tried the script api example but isnt working to me

valid ice
#

Do you have the vanilla-data module in your addon?

spring dove
#

where do i put it?

#

which place of the manifest

#

there?

valid ice
#

It's not needed for stuff to function, and it's something that cannot be placed manually in the manifest

spring dove
#

so?

valid ice
#

Must be put in the addon files

spring dove
#

.........

valid ice
#

MinecraftItemTypes -> just use the item type id as a string
MinecraftEnchantmentTypes -> use enchant name as a string

spring dove
#

so i can change it to make it work without changing any file

valid ice
#
import { EnchantmentType, world, ItemStack, Player } from '@minecraft/server';

world.afterEvents.itemUse.subscribe((e) =>{
    if(e.itemStack.typeId === "minecraft:stick") return giveFireSword(e.source)
})

function giveFireSword(player) {
    const ironFireSword = new ItemStack('minecraft:diamond_sword', 1);

    const enchantments = ironFireSword?.getComponent('enchantable');
    if (enchantments) {
        enchantments.addEnchantment({ type: new EnchantmentType('fire_aspect'), level: 1 });
    }

    const inventory = player.getComponent('minecraft:inventory');
    if (inventory === undefined || inventory.container === undefined) {
        return;
    }
    inventory.container.setItem(0, ironFireSword);
}
spring dove
valid ice
spring dove
#

i think its no that file then

#

idk why it keeps throwing that error

#

i reloaded, verified any file

valid ice
#

are you using dev folders?

spring dove
#

yes

valid ice
#

hmm

spring dove
#

im relogging the whole game even if that doesnt makes sense

#

wtff i desactivate that JS file and then the other scripts start working

spring dove
valid ice
#

import errors throw globally

spring dove
#

im stupid, i was editing a file i send you

#
  • and your code worked, ty so much
valid ice
#

👍

prisma shard
#

change "minecraft:stone" with the block typeId that you want

strong oar
prisma shard
prisma shard
strong oar
#

Ohh okay I'm gonna try huh

#

*huhu

strong oar
prisma shard
turbid delta
#

is it possible to equip mobs with equipment in scripts, not players

#

really want to avoid using structures

solar dagger
#

I believe that as long as the entity has the equipment component you should be good

misty pivot
misty pivot
#

what conditions do you speak of tho?

#

what are you planning to do?

turbid delta
#

Doesn't seem to possible to include custom item data, thanks though

strong oar
misty pivot
#

oh so you're talking about the states?

strong oar
#

Yeah

misty pivot
#
block.setPermutation(block.permutation.withState("example:myState", 1))```
#

add this to the if statement

#

just change the state name

strong oar
#

Ohhh and then?

misty pivot
strong oar
#

Ohh then replace it with your code right?

misty pivot
#

yep

strong oar
#

Last man, I forgot to say what if the states range to 0-6 then every tapped will change the value of the states like:

0-1
1-2
2-3
4-5
5-6
6-0

valid ice
#

% 7

misty pivot
#

something like this

#

the else part sets it back to state 0

#

hope it helps

strong oar
#

Thanks man

fallow rivet
#

Do you have any idea how I can make a claim?

strong oar
#

@misty pivot heres what happened

misty pivot
#

may i see the custom component you made? or at least parts of it

#

and also the registry, im not sure because i haven't encountered that problem

strong oar
#

ohh okay in here i removed the registry

#

import { world } from "@minecraft/server";

world.afterEvents.playerInteractWithBlock.subscribe(({ block, itemStack, player }) => {
if (itemStack?.typeId === "minecraft:stick") {
let value = block.permutation.getState("goobli:State");
if (value < 16) {
block.setPermutation(block.permutation.withState("goobli:State", value + 1));
} else {
block.setPermutation(block.permutation.withState("goobli:State", 0)); // or any reset value you prefer
}
}
});

#

when i removed the registry, the only error that shows is this

tiny tartan
strong oar
tiny tartan
#

i mean beta api

strong oar
tiny tartan
#

i think its still in beta api so it wont work

#

i would suggest using custom component

strong oar
tiny tartan
#
world.beforeEvents.worldInitialize.subscribe(event => {
    const {blockComponentRegistry} = event;
    blockComponentRegistry.registerCustomComponent('your:custom_component', {
        onPlayerInteract: data => {
            const {block,player} = data;
            const mainHand = player.getComponent('equippable').getEquipment('Mainhand');
            if (mainHand.typeId == 'minecraft:stick') {
                let value = block.permutation.getState("goobli:State");
                if (value < 16) {
                    block.setPermutation(block.permutation.withState("goobli:State", value + 1));
                } else {
                    block.setPermutation(block.permutation.withState("goobli:State", 0)); // or any reset value you prefer
                }
            }
        }
    });
});```
tiny tartan
#

use this instead

strong oar
#

ohh okay im gonna try it

tiny tartan
strong oar
#

okay thank you

misty pivot
#

damn, mb, i was doin something earlier

strong oar
tiny tartan
#

"minecraft:custom_components": [ "global:change_states" ]"

strong oar
strong oar
#

it doesnt work, maybe you have sample file

celest fable
#

how to clear player inventory with native method?

lone thistle
grave thistle
#

Is there not a method for checking an entity to see if it has a specific component group or behaviour

fading sand
#

Is there any way to check if an different script is active?

#

Like one from an another addon

lone thistle
sage portal
#

can you directly invert an integer variable (i.e. 7 + -example), or do you have to just multiply it by -1?

shy leaf
#

you can directly invert em

#

well both works

sage portal
#

cool, thanks

grave thistle
naive tinsel
#

is there a max amount of dynamic properties?

summer walrus
#

or if you're asking about another thing, no there's no limit only your device's storage size is the limit

naive tinsel
#

ok

#

yeah i was referencing the amount of dynamic properties

#

thx

fading sand
fading sand
#

Im trying to check if an other script file is active

summer walrus
#

so they are different addons

#

console.warn is the simplest n most direct

#

but what are you trying to check?

fading sand
fading sand
distant tulip
summer walrus
#

whats the idea here

distant tulip
summer walrus
#

how about you store it with a tag or a score

fading sand
#

Theres an dublicated code

amber granite
#

What is going here ?

fading sand
fading sand
elder heath
#

It was not easy to do this for the afk system

misty pivot
#

How do i make a function not make an error when it fails to call
(like for example when i use applyKnockback to an entity that cant be knockbacked/is no longer existing)

distant tulip
#

check if entity.isValid()

strong oar
#

Anyone maybe you have a template for block that changes whenever you tap it

honest spear
misty pivot
#

lemme try

#

wait...

#

is "try" part of your suggestion?

#

as in

try {...} catch {}```
distant tulip
misty pivot
#

ah, alright, thanks

#

it worked thanks, i believe catch can also be used to use the errors as objects or smth like that?

distant tulip
distant tulip
#

also try catch is not the best option in your case

if(entity.isValid()){
  entity.apply...
}
misty pivot
honest spear
#

there is no need for patern

misty pivot
shy leaf
#

cant you just exclude by types in entity query options

#

in that case?

misty pivot
#

yeah i could but that would mean i'd have to list down entities and not only that but it wouldn't work for custom entities that also cannot be damaged/etc.

shy leaf
#

hmmm

#

what i did here is to first do excludeTypes the stuff needed

#

and then do try catch

#

double filter

misty pivot
#

i dont understand why try catch isn't a good option, is there some sort of catch?

#

if i were to only do try catch, would there be a problem?

shy leaf
#

i honestly havent had any trouble using try catch but

#

i assume it doesnt look pretty

#

(and it really isnt but it does its job)

#

but hey if theres a better option, ill take it

#

also about .isValid part, im not sure what that really does tbh

misty pivot
#

hm, alright

naive tinsel
#

does setBlockType keep facing rotation?

misty pivot
misty pivot
naive tinsel
#

dam ok

shy leaf
misty pivot
#

yep

shy leaf
#

hmm so its a different version of try catch

#

(j)

misty pivot
#

also i searched in google as one does, it just says it's bad practice to use try catch since it makes the dev miss critical errors but tbh what's stopping me from just temporarily removing it to debug the said function

shy leaf
#

it would be a bad habit if you just wrapped it up everywhere

#

but i think applyKnockback and applyImpulse is an exception here

misty pivot
#

but thanks for some clarification about try catch

shy leaf
#

also if you do want to catch the errors, you can just do

try {
    ....
} catch (e) { console.warn(e) }```

though this doesnt point to line so it can be confusing if the code is large
misty pivot
shy leaf
#

i almost lost all of my hair scripting until i learned try catch exists

naive tinsel
#

how do i change these to tuff stairs while keeping their rotation

naive tinsel
#
const blocks2 = {
  "minecraft:nether_brick_stairs": "minecraft:polished_tuff_stairs"
}

  const { x, y, z } = player.location
  const dim = world.getDimension("overworld")
  for (let X = Math.floor(x) - 10; X < Math.floor(x) + 10; X++) {
    for (let Y = Math.floor(y) - 10; Y < Math.floor(y); Y++) {
      for (let Z = Math.floor(z) - 10; Z < Math.floor(z) + 10; Z++) {
        for (const [blockName, newBLockName] of Object.entries(blocks2)) {
          const block = dim.getBlock({ x: X, y: Y, z: Z })
          if (blockName == block?.typeId) {
            const perm = block.permutation
            block.setType(newBLockName)
            block.setPermutation(perm)
          }
        }
      }
    }
  }
#

ive got this but when it sets the permuattion, it sets the block type back to the nether brick stairs

valid ice
#
const facing = block.permutation.getState('weirdo_direction');
block.setType(newBLockName);
const perm = block.permutation.withState('weirdo_direction', facing);
block.setPermutation(perm)
``` something like that maybe
#

can do the same for upside_down_bit

naive tinsel
#

ok

#

idk why they name them like that

shy leaf
#

because they want to make block stuff complicated as much as possible Face

#

(this is obviously a joke)

solar dagger
#

😂 i love the joke bro

#

(this is obviously me being sarcastic)

naive tinsel
# valid ice can do the same for `upside_down_bit`
                            const facing = block.permutation.getState('weirdo_direction');
                            const facing2 = block.permutation.getState('upside_down_bit');
                            block.setType(newBLockName);
                            // @ts-ignore
                            const perm = block.permutation.withState('weirdo_direction', facing)
                            // @ts-ignore
                            perm.withState('upside_down_bit', facing2)
                            block.setPermutation(perm)```
valid ice
#

weirdo direction be weird

naive tinsel
#

this doesnt do the upside_down_bit

valid ice
#

you have to chain them

#

const perm = block.permutation.withState('weirdo_direction', facing).withState('upside_down_bit', facing2)

naive tinsel
#

ah yes

#

thanks

valid ice
#

(If you don't want to make a new variable for every permutation you add)

granite badger
wary edge
cinder shadow
#

I only use it for debugging but It's never a bad option what

prisma shard
prisma shard
#

nevre

granite badger
# wary edge Try catch is bad practice says who?

https://stackoverflow.com/questions/12609527/why-isnt-try-catch-used-more-often-in-javascript/12609630#12609630
Some browsers don't handle it well, but I can't say the same for qjs.
With my experience most of the times I use try catch, sometimes ignore the error ends up with me taking lots of time to debug and fix issues i should've fixed previously. I don't like avoiding issues temporarily.

prisma shard
#

hmmm waaait,, if you think a littlee, u can undetstand

#

it is a bad practice

#

making ur code neat and not erroring is a good practice

#

all knows

#

but try catch ignores them themporarily

wary edge
granite badger
#

it has its benefits and drawbacks depending on usage. That logic applies to everything, and I use it in some places too. I just hope people here know what they're getting into when using try catch

distant tulip
#

i said it is not the best option sense we can check if the entity is loaded or not
i use it some times too

empty tapir
#

        const addRider = entity.getComponent('minecraft:rideable');
        const addRider1 = addRider.getSeats();
        addRider1[0].position.y = 15;
``` can we edit the seat position of entity?
prisma shard
#

oh! ZAHF?
i really like your addons!
and you dissappeared out of nowhere,
i'm amazed that your back

prisma shard
#

lol everyone falling for him

distant tulip
prisma shard
#

did u play that addon

empty tapir
empty tapir
empty tapir
solar dagger
solar dagger
empty tapir
#

discord is having weird name lol

solar dagger
empty tapir
solar dagger
empty tapir
#

its an entity

solar dagger
#

i think you can eject them and add them back

empty tapir
#

i cant eject the rider once i eject the rider the entity will despawn, and im kinda looking for a way to not make entity for each sit,😅

solar dagger
#

🤔

#

I don't see anything in the docs to transfer/move riders

buoyant canopy
#

how do i put a cooldown on a function, i want to not allow the function to run if it's called again within a second

empty tapir
solar dagger
#

yeah unfortunately

prisma shard
distant tulip
lone thistle
prisma shard
#

:v

distant tulip
prisma shard
# empty tapir its read -only😂

btw what happen to your expansive fantasy addon?
i didn't check it since the last time i downloaded it;
it's not availavable on mcpedl now

empty tapir
solar dagger
#

Zahf is gatekeeping

prisma shard
#

jk

solar dagger
#

💀

empty tapir
#

😂

summer walrus
#

💀

buoyant canopy
prisma shard
#

@distant tulip

#

mina

#

t

#

o

lone thistle
prisma shard
buoyant canopy
prisma shard
#

he's probably giong to say "dont ask to ask"

#

ok so, Just like, playerBreakBlock is a event, I also want to make a custom event - playerOnJump.

The question is-
So, How can I make custom event/callback?
And I want to also make it have subscribe and unsubscribe methods to the event.

I have the code for the jumping
I just don't know how to make it a event/callback.

can you help @distant tulip

#

(ik u dont like pings so sorry)

summer walrus
#

The more you ping the higher the pressure/stressor you're inputting the higher the chance they are overwhelmed and decide to just help you or ignore you completely

distant tulip
devout dune
#

Hellooo!
Just noticed there is no easy access to the Player. via most of the CustomComponents???
How can i access the player?

wary edge
distant tulip
buoyant canopy
distant tulip
#

that should work
just use who ever is the source instead of the player