#Script API General

1 messages · Page 40 of 1

jolly citrus
#

they need to have the cooldown on their sidebar

#

like this

slow walrus
#

you should commit some of your changes lmao

#

309

jolly citrus
#

idk how to unsync it

chilly fractal
#
import { system } from "@minecraft/server";
let cooldowns = new Map();

function useItem(player, item) { // example function, only for educational purposes, do not copy paste
  let cooldownKey = `${player.id}:${item.typeId}`;
  if (system.currentTick <= cooldowns.get(cooldownKey)) return function(){player.sendMessage('Whoa This Item Is Still On Cooldown!'); player.playSound('random.bassattack');}();
  cooldowns.set(cooldownKey, system.currentTick+(16*20)); // 16 seconds delay
  // run some code
  system.runTimeout(() => {
    cooldowns.delete(cooldownKey);
  });
}
chilly fractal
#

Wow! Great commands! Thanks!

bright dove
#

does anyone know a way to apply enchant to an in-hand tool ?

jolly citrus
#

?

bright dove
chilly fractal
#

Yea*

dreamy elbow
#

Player.runcommand(<command here>)

bright dove
#

I mean like something like setEnchant ?

#

that doesn't exist ?

dreamy elbow
chilly fractal
# bright dove I mean like something like setEnchant ?
import { EnchantmentType } from "@minecraft/server";

let item = player.getComponent('inventory').getItem(player.selectedSlotIndex), enchComp = item?.getComponent('enchantable');

if (!enchComp) return;
enchComp.addEnchantment({type: new EnchantmentType('fire_aspect'), level: 2});
player.getComponent('inventory').setItem(player.selectedSlotIndex, item); // sets item back to the same slot because mc doesn't register enchant unless you do this
bright dove
#

Thanks ya

chilly fractal
#

(Of course assuming player is a valid player variable), and you're welcome :)

#

Yo Emwynn, u writing a paragraph?

dreamy elbow
#

Hey what would be the best practice for saving data to a block while trying to to conserve space. I've been using
world.setdymanicProperty(Json.stringify(block.location),number)

But I feel like it's gonna take up a LOT of space

chilly fractal
dreamy elbow
#

I'm making an "hp" for block's that are stepped on, if you step on them too much they'll downgrade from grass into coarse dirt, then into paths, then into gravel

#

I just wanted to see what the effect would be

chilly fractal
#

Ah

dreamy elbow
#

But don't want to add it if it's gonna be a like 40 million gigs of data

#

Lol

chilly fractal
#

It's not gonna be large actually

#

Unless... a massive amount of blocks

fiery solar
dreamy elbow
chilly fractal
dreamy elbow
#

I should probably add a forget response just in case, that way if a block hasn't been stepped on more than once in like x amount of time it won't still be counted

#

Okie thanks just wanted to check there wasn't a safer or smarter way I was overlooking

slow walrus
#

go into your project folder and delete the .git folder

slow walrus
chilly fractal
#

I know this is off topic, but since we are js coders, I'm wondering what is the best way to get the device width? I'm using window.innerWidth but idk it isn't working with my formula to resize navbar and other elements on certain browsers like the kiwi browser & the acode html viewer

celest relic
#

When I use this on custom blocks with the liquid detection component, it says the block type can't be waterlogged. What should I do?

gaunt salmonBOT
grim raft
#

yo

#

how can I get the effect of an entity/player

#

also whats wrong with this

system.runInterval(() => {
    for (const player of world.getAllPlayers()) {
        const poison = Entity.getEffect('poison')
        if (poison) {
            Player.addTag('poison')
        }
    }
})```
#

it says the problem is with getEffect

warm mason
#

Entity and Player variable is not defined

grim raft
warm mason
#

It's in your code. You simply don't have them. You are referring to a non-existent object

gaunt salmonBOT
# grim raft also whats wrong with this ```js system.runInterval(() => { for (const playe...

Debug result for [code](#1067535608660107284 message)

Compiler Result

Compiler found 2 errors:

<REPL0>.js:3:31 - error TS2339: Property 'getEffect' does not exist on type 'typeof Entity'.

3         const poison = Entity.getEffect('poison')
                                ~~~~~~~~~

``````ansi
<REPL0>.js:5:20 - error TS2339: Property 'addTag' does not exist on type 'typeof Player'.

5             Player.addTag('poison')
                     ~~~~~~

Lint Result

ESLint results:

<REPL0>.js

2:16 error 'player' is assigned a value but never used @typescript-eslint/no-unused-vars

alpine nebula
#

Where do I find list of criteria for query? Like for

const query = { type: 'item', closest: 1, location: { x, y, z } };
const drop = dim.getEntities(query)[0];
grim raft
#

is this what u reffering to?

warm mason
remote oyster
# jolly citrus i dont even use github for this anymore

I highly recommend familiarizing yourself with Git, as it’s an invaluable tool for managing your code. Git makes it easy to track changes, so you can see exactly what was modified, when, and by whom. If you make a mistake, Git allows you to revert to earlier versions of your code, saving you time and frustration. It also lets you experiment with new ideas by creating branches, so you can test changes without affecting your main codebase. Git provides a clear and organized way to manage your code, making it much easier to navigate mistakes and improvements as your project grows.

grim raft
#

oh thats for players

ember swallow
#

@warm mason Hey, me again, do you know anything from entities? if yes, can you meybe pls look in entities general? it's probably really easy but can't get it fixed, Thanks!

warm mason
ember swallow
#

if a entity dies, it plays a sound and partcile, i don't want that

ember swallow
#

I know I put it there, but wanted to ask to you if you could help 😄

wary edge
distant gulch
#

Guys help

#

Why does Minecraft says (beforeEvents) "worldInitialize" is undefined?
Im using the 2.0.0-alpha for the server module

distant gulch
distant gulch
#

NoO??

#

It worked like for years

warm mason
distant gulch
#

Well, it worked before the update

#

Did they removed it or what?

warm mason
distant gulch
#

Yes.

warm mason
#

Go to 1.18.0-beta

distant gulch
#

but why can i use 2.0.0-alpha in my other addon? it doesnt throws any errors

distant gulch
#

weird

gusty bramble
#

I have a more general js question but how would I make something that takes “value” and divides it by 32. I want value to be a separate thing so I can set values to it automatically I don’t want it to be a set number or something if that makes sense

distant gulch
distant gulch
warm mason
distant gulch
wary edge
gusty bramble
#

I literally can’t remember how

warm mason
distant gulch
warm mason
#

value / 32

warm mason
wary edge
#

That's the whole premise of stable APIs, it shouldn't break after updates.

distant gulch
warm mason
# wary edge It shouldn't if you use stable 👍 .

Yes, yes. I remember that “wonderful” day when all my items said bye because they were not satisfied with the version format. Although it was an old addon, which was the field for my training... At least nothing broke in my new addon

wary edge
distant gulch
#

because beforeEvents.chatSend is only included in beta versions

ember swallow
#

Hey, How do you do with a script, if you left click, and try to hit something with a sword, that you can do a effect and sound effect, or activate a function? I think this works with scripts like the 'on use' but can't figure it out :C

warm mason
ember swallow
#

owww animation controllers, i will have a look at that Thanks!

gaunt salmonBOT
unique dragon
#

they recently added the liquid detection to custom block

#

add that component to your block

celest relic
#

However, it may be because the component was in a permutation.

#

The permutation was still met though, I'm not sure why it didn't allow it

hardy tusk
#

@spring axle what do you think about this?

distant gulch
#

how do I run a script based on what someone clicks in actionFormData

#

I want them to switch to a new form depending on which option they click

remote oyster
distant gulch
remote oyster
#

Just remove the Types in the example.

distant gulch
#

well for some of the stuff, my console showed that I can only do it in typescript

#

specifically the

#

(log: (message: string, status?: number)

#

tho actually

#

do I even need that?

#

I don't think I do

#

I'll try without it lol

#

thanks

remote oyster
#

That's in TS because message and status are expressing the Type for each one.

Remove the Types and it's basically JS.

Example TS:

const example: string = "This is a string";

Example JS:

const example = "This is a string";
distant gulch
#

ohh, I see what u mean

#

thanks!

remote oyster
#

Must be in JS when applying to a world. Some of us use TS because it speeds up development, maximizes efficiency, and immensely assists at detecting realtime mistakes before getting to runtime testing.

gusty bramble
#

I’m so confused why doesn’t this work it says NaN for Seconds

#

Here’s another example

#

This is what I get out

knotty plaza
thorn flicker
#

||you should use template strings instead||

distant tulip
#

uh... you are adding a string to an array

knotty plaza
#

Also that

#

That happens when you don't use Typescript

gusty bramble
#

Can I do this in a better way?

distant tulip
gusty bramble
#

I did that before it didn’t fix anything

distant tulip
#

send that code

gusty bramble
#

Oh wait

#

let comparators = 4;//input from the command
let batteries = 2;//input from the command

let c = [comparators]*32*[batteries]*15/20;
let m = Math.floor(c/60);
console.log('GameTicks:'+ comparators*32*batteries*15, 'Seconds:'+ c-m*60, 'Minutes:'+ m)

Yeah no this doesn’t work I originally had the [c] still but it seems that wasn’t the reason

thorn flicker
#

you should send code instead of images in the future

distant tulip
plush moss
#
import { world, BlockComponentTypes} from "@minecraft/server";

world.beforeEvents.playerInteractWithBlock.subscribe((event) => {
    const player = event.player;
    const block = event.block;

    if (!player || !block) return;

    if (block.getComponent(BlockComponentTypes.Sign)) {

        event.cancel = true;

        const sign = block.getComponent(BlockComponentTypes.Sign);
        if (sign) {
            try {
                const rawText = {
                    rawtext: [
                        { text: "§aClicked" }
                    ]
                };
                sign.setText(rawText);
            } catch (error) {
            }
        }
    }
});

Does anyone knows how to set a text to a sign

hardy tusk
#

KissMyTanga?? POGGIES

#

HrEnte!!

plush moss
#

was geht

hardy tusk
#

lmao

plush moss
#

bin da gerade bisschen am verzweifeln xd

distant tulip
hardy tusk
#

its optional

gusty bramble
hardy tusk
#

it doesnt need it

distant tulip
#

nvm it is optional

distant tulip
gaunt salmonBOT
hardy tusk
plush moss
#

[Scripting][error]-ReferenceError: Native function [BlockSignComponent::setText] does not have required privileges. at <anonymous> (index.js:20)

#

gibt das immer wieder aus

hardy tusk
#

ahh

plush moss
#

egal was ich gemacht habe

#

xd

distant tulip
#

wrap it in a system.run

jolly citrus
#

hello ente

plush moss
hardy tusk
#

Ok du musst den Code in system.run(()=>{}) wrappen

plush moss
hardy tusk
#

also in den {} dein code

gusty bramble
plush moss
hardy tusk
#

das wird dann nächsten Tick ausgeführt, das is damit so ne Interaktion durch Script API nicht so lange verzögert wird, weil sonst müsste Minecraft warten bis dein Code komplett fertig is bevor es die eigentliche Interaktion durchführt

hardy tusk
#

also alles ab if(block.getComponent...)

plush moss
#
world.beforeEvents.playerInteractWithBlock.subscribe((event) => {
    const player = event.player;
    const block = event.block;

    if (!player || !block) return;

    if (block.getComponent(BlockComponentTypes.Sign)) {

        event.cancel = true;
        system.runTimeout(() => {

        const sign = block.getComponent(BlockComponentTypes.Sign);
        if (sign) {
                const rawText = {
                    rawtext: [
                        { text: "§aClicked" }
                    ]
                };
                sign.setText(rawText);
        }
    })
    }
});
#

meinst ja so

#

ja thx

hardy tusk
#

Ja so würd ichs machen ```js
world.beforeEvents.playerInteractWithBlock.subscribe((event) => {
const player = event.player;
const block = event.block;

if (!player || !block) return;

const sign = block.getComponent(BlockComponentTypes.Sign);
if(sign) {
    event.cancel = true;
    system.run(()=>{
        
        if (sign) {
            const rawText = {
                rawtext: [
                    { text: "§aClicked" }
                ]
            };
            sign.setText(rawText);
        }
    })
}

});

distant tulip
gusty bramble
#

Much appreciated

plush moss
#

xd

hardy tusk
#

woops

#

ja hab das in dc bearbeitet das bischen krampf

plush moss
#

geht aber so auch nicht mehr xd

hardy tusk
#

ja stimmt

#

der cancel macht nix mehr

plush moss
#

ja

#

xd

#

egal habs ja

hardy tusk
#

k

#

aber den component kannst du trzdem in ner variable vorher speichern

#

du gettest den 2 mal

#

das nicht gut

distant tulip
#

guys
please keep it in English

warm mason
#

👀

hardy tusk
#

jedes mal wenn du das machst schwitzt Script API richtig

hardy tusk
plush moss
#

weißt du noch wie man das ding zum glowen bringt

#

xd

hardy tusk
#

glow ink sacks

plush moss
#

ja aber mit scripts

#

xd

hardy tusk
#

aso

hardy tusk
#

ansonsten geht das einf nd

plush moss
#

ja hab ich auch geguckt

#

xd

#

man kann es waxen mehr nicht

hardy tusk
#

aber du kannst trzdem theoretisch n schild das schon glowing hat nehmen und das kopieren und den Text darauf printen dann jedes mal

plush moss
#

checke auch smart eig

warm mason
#

👀

distant tulip
#

welp there is a way
but sense i don't speak what ever is that ... i can't help you

jolly citrus
#

ente speaks english

hardy tusk
#

you can check tho

distant tulip
#

it is not

hardy tusk
#

k

plush moss
#

@hardy tusk man kann immer noch nicht die block facing direction holen mit scripts right?

hardy tusk
#

Doch

plush moss
#

seit wann

#

xd

distant tulip
#

save a glowing sign in structure block and reuse it

hardy tusk
#

Thats a block state

warm mason
plush moss
#

@hardy tusk wie xd

hardy tusk
#

block.permutation.getState()

#

je nach block entweder einer von denen oder von den anderen

#

weirdo direction is my favorite

plush moss
#

ah nice seit welcher version geht das

warm mason
#

..........

plush moss
distant tulip
warm mason
plush moss
#

oh sry than bro

sly currentBOT
#
kissmytanga

hello how are you

plush moss
#

tf

warm mason
#

Maybe you can just tell us in a language that everyone understands what you need and we will help you?

plush moss
#

they have a translate thing here

plush moss
#

me and creepy are good friends btw

hardy tusk
#

ye

distant tulip
#

that doesn't matter
move to dm if you don't need public help

hardy tusk
#

ok bro

plush moss
#

np bro

hardy tusk
plush moss
#

hahaha

#

yeah we doing it

distant tulip
plush moss
#

@hardy tusk

hardy tusk
#

?

plush moss
#
                    sign.setText(rawText);
                    sign.setWaxed()
#

why is this not working xd

hardy tusk
#

cuz u messed up

sly currentBOT
#
kissmytanga

brother how do you make this setWaxed

#
kissmytanga

the translate works well but hahaha

warm mason
distant tulip
#

setWaxed(bool)

hardy tusk
#

ye sign.setWaxed(true)

plush moss
distant gulch
#

How does chatSend work?

#
world.beforeEvents.chatSend.subscribe((e) => {
    if (!e.sender.isValid) return;
    if (e.message.startsWith('!')) {
        e.sender.sendMessage("Working")
    }
})
#

Console says that subscribe is undefined

warm mason
#

show manifest

distant gulch
#

alr one sec

distant gulch
#

this is the dependancies

#
"dependencies": [
        {
            "module_name": "@minecraft/server",
            "version": "1.16.0"
        }
    ]
#

1.16.0 is no longer beta I don't think

dim tusk
#

Chatsend is still beta that's why

distant gulch
#

1.16.0-beta?

warm mason
#

1.17.0-beta

distant gulch
#

ah

#

alr

#

lemme test it

#

alr bet, thanks guys!

untold magnet
#

yo, just to make sure:
is it possible to detect the itemStack of entities?
like detecting the item that the entity is holding.

tawny jungle
#

Is there a way to get ontick to run runinterval only once?

wary edge
#

You can set loop to alse in the tick component.

untold magnet
distant tulip
#

testfor command with hasitem selector

untold magnet
#

in that case, how can i get the item id?

#

impossible right?

distant tulip
#

kinda?
unless you are willing to test for all the items one by one

untold magnet
#

i think i can use something else

jade grail
#

is there a way for me to save entities data then spawn the exact same entity again?

#

all i know is how to save the location and typeId

distant gulch
#

How do I remove errors on tests

#

Where do I add the '?'

#

for like

#

state.?toLowerst

#

LowerCase*

distant tulip
#

?.

distant gulch
#

I'm doing

#

state?.toLowerCase?.toString()

#

and it did not fix the error

distant tulip
#

.toLowerCase()

distant gulch
#

it shows in console

#

that it can't run toLowerCase to an undefined property

dim tusk
jade grail
#

about 2 hours ago ..

#

well ty for help

drowsy scaffold
#

how do I apply knockback from a Vector3 location? I have a sumo ring but want to remove people who are wearing netherite from it without teleporting them

ruby haven
#

I made an arena a 30 block wide radius and I made a death scene of the boss and the player within that arena using tp there is one major flaw though if the player killed the boss on the side of the arena the death scene will not be seen correctly because the camera is being blocked by the arenas walls is there any way to tp the entity on the center of the arena?

drowsy scaffold
ruby haven
drowsy scaffold
#

like it wouldn't trigger an afterDeath event handler?

#

because I think you can still access a location property even after death

ruby haven
#

Well my boss has a minimum health value so it doesn't actually die so I can still tp it however the problem is don't know if it is possible to tp it in the center of the arena

#

So after entitydie I tp the boss in the center of the arena so the death scene can be seen clearly

dim tusk
ruby haven
#

Wait the structure actually generates in the center of the player so what if I save the coordinates in a variable then later use that to tp the boss?

ripe swan
#

Anyone know if there's a script API equivalent to the q.is_charging molang query on the front end?

cold grove
#

itemStartUse after event?

ripe swan
#

It's not an item, it's an entity (vex) doing the charging attack

#

I tracked down how the animation controller is changing the texture to an is_charging query, but there isn't an isCharging entity property on the entity object, so I'm not sure how to detect it from the script api

ruby haven
#

Is there a way to make a player not die after being hit like having a minimum health component

random flint
#

player.json

ruby haven
random flint
ruby haven
#

Is it possible to track the damage value of the entity then compare that to the health of the player then I substract damage how many I want

dim tusk
#

you want to get the melee damage player dealt?

#

You can't get the melee damage of player without attacking something, I'm not kinda sure tho

ruby haven
#

No the boss melee damage dealt to the player

dim tusk
random flint
#

Just make a component group, and damage sensor that detects and cancels fatal hits, then remove the component group afterward bruh. ( It run entity event )

dim tusk
random flint
# dim tusk Quick question, if the player is damaging a mob with armor can you detect how mu...

Not in a direct way.

You can Map each vanilla wearable Item attributes (armor and toughness)

Dynamically, If you want it to be compatible with other custom armor outside your pack, you could make a custom entity, and iterate each ItemTypes class for all possible wearable itemStack, then test each Armor Points and Armor Toughness by damaging the custom entity.
-# Probably run once on world load.

Then, using runCommand() or the async variants to get the armor dmg reduction, you'll use the hasItem={} selector to check each equipment slot for each typeIds, then calculate it according to the formula in Minecraft wiki.

It has a flaw tho, not being able to detect enchantments. However, you can barely distinguish "armor dmg reduction" and "enchantment dmg reduction" using an additional check of changing the damage cause between "entityAttack", "magic", "explosion", "projectile" etc
-# You'll be copying the hurtEntity using a structure, and a lot of copy-paste to isolate each armor for accurate reading. (Unless the getEquipment() works)

ruby haven
#

What does fatal detect if the damage is enough to kill the entity?

random flint
dim tusk
#

How about having a resistance effect? Can you detect the damage absorbed?

random flint
dim tusk
simple arch
#

can somone help?

tawny jungle
ruby haven
#

Is it possible to change death messages?

dim tusk
#

My weakness is the custom items

flat barn
#

it means the entity you are trying to get the component of wasnt found or does not exist

distant gulch
#

and I LOVE IT

#

I'm nerding out rn

#

thanks for trying to help with the uppercase things Coddy

#

That's the only reason I pinned u lol, just a thanks

dim tusk
distant gulch
#

lol

#

Wanna see my addon?

#

It's 1011 lines

#

its actually quite a simple program

#

but I had to add a LOT of data

abstract cave
#

Is there a way i can break a block using scripts

distant gulch
#

it was very tedius

dim tusk
dim tusk
distant gulch
#

So you type '-help'

#

and it gives instructions

#

but basically

#

you set your yearly income

#

the state u live in

#

and the value of ur house

#

and it then tells you

#

when u type 'stats percent'

#

'-stats percent'*

#

it tells u:

#

Property Taxes:
State Taxes:
FICA Taxes:
Federal TaxesL

#

and Total Taxes:

dim tusk
#

Tf 😭😭

distant gulch
#

then if u type '-stats cost'

dim tusk
#

Chill out on messages

distant gulch
#

it tells u all that in costs

#

sorry, that's just how I type lol

dim tusk
#

And I feel like you replied to the wrong person

distant gulch
#

nah, u and one other dude mentioned something abt toUpperCase

#

and I alr thanked the other dude

#

but yeah, it tells u ur taxes based on income, state, and property value

dim tusk
#

I'm 800 lines deep already

distant gulch
#

I didn't bother adding filing status

#

dang

#

mines just a bunch of data from tax websites

#

each state is different in every field, and some have income brackets, some don't

#

and I had to look up (on a laggy laptop)

#

every single stat for every state

#

and then use chatSend and calculations, which I've never done before with either

slow walrus
# distant gulch

oh my god bro just make a mathematical model for the tax percent

#

or something

#

so many if elses lmao

slow walrus
#

nvm

#

just

distant gulch
#

every single state is different, every single value is different, every single if (income < ) is different

slow walrus
#

yeah ik

distant gulch
#

literally not a single thing repeats

#

ye

#

that's why it sucked to code

slow walrus
#

there's better ways to do it than a else if chain though

distant gulch
#

yeah, I realized that 1/3 way thru

#

but if it restarted, it would've taken longer

#

bc I'd have to go back and redo the values

#

which are a lot

#

And it's not like this is laggy

#

it runs with no delay ingame

#

so I don't see a point in changing it this far in lol

#

I could've just made every single thing easier by not changing the dynamicProperties until the end and just putting the array in the case of the 3 values based on income lol

#

then every state would only have 3-15 lines to it

slow walrus
#

btw, I would use <= instead of just <, then you don't have to add 1 to every number

#

makes it nicer to read

#

and your last else if can just be an else

dim tusk
# distant gulch

Y'know what's funny I will literally bonk you just to do it like this... js if () sender.setDyna.... else if () sender.setDyna...

#

Especially if you're doing one thing inside of the bracket

distant gulch
#

makes me feel correct

#

it's not adding additional lag rlly

round bone
#

use map instead objects

dim tusk
dim tusk
round bone
distant gulch
dim tusk
dim tusk
#

I'm kinda confused with the calculation

#

So I'm in hard mode and zombie attacks me it's 4.5 and when I have resistance effect 3 the damage is 0.9

#

Which is way of with the calculation in the wiki

#

Which is 0.2 x level

#

When I do damage - (0.2 * 3) it's equal to 0.3

#

So 0.3 + 0.9 = 1.2 which is way way off of 4.5

warm mason
#

Each level of resistance effect reduces damage by 25%

dim tusk
#

The wiki said 20%... Lma

simple arch
#
inventory = this.#simulatedPlayer?.getComponent("inventory").container
equipment = this.#simulatedPlayer?.getComponent("equippable")
#

or

#
inventory = this.#simulatedPlayer?.getComponent(mc.EntityComponentTypes.Inventory).container
equipment = this.#simulatedPlayer?.getComponent(mc.EntityComponentTypes.Equippable)
#

they don't exist

simple arch
#

so if these don't exist (apparently) what should I do then?

#

im using the 1.17.0-beta server module

warm mason
simple arch
#

they just return undefined ig because as shown by my snip they return undefined

simple arch
warm mason
#

Maybe it's because simulatedPlayer is undefined

simple arch
#

its not undefined though

#
 const simulatedPlayer = SimulatedPlayer.test.spawnSimulatedPlayer({ x: 0, y: 1, z: 0 }, username, gamemode)

        if (sender) {
            simulatedPlayer.teleport(sender.location, {
                dimension: sender.dimension,
                facingLocation: sender.getViewDirection()
            });
        } else {
            throw new Error("sender's location is not initialized.");
        }

        this.#simulatedPlayer = simulatedPlayer
        this.#intervals = {}
#

this is in my

constructor
warm mason
simple arch
#

do I just do

console.log(string | number | etc...)

just to clarify?

warm mason
simple arch
#

okay I managed to get it to work

ruby haven
#

Is it possible to change death messages?

bright dove
#

is this valid code ?

slow walrus
#

do damage - (0.25 * 3 * damage)

bright dove
#

mhm

warm mason
ruby haven
dim tusk
# slow walrus do `damage - (0.25 * 3 * damage)`

For me it kinda don't make any sense because I tried to grab the damage of the zombie per level of resistance players have when the base is 4.5

zero: 4.5
one: 3.6000003814697266
two: 2.6999998092651367
three: 1.8000001907348633
four: 0.8999996185302734

#

20% -> 25% -> 33.33% -> 50%

warm mason
#

Stop what. Doesn't level four completely absorb damage?

dim tusk
#

The point is the percentage is not flat

#

And I obviously know that information.. k?

slow walrus
#

cause if it's total for each level then your maths is completely wrong

dim tusk
slow walrus
#

zero: 4.5 (100%)
one: 3.6000003814697266 (80%)
two: 2.6999998092651367 (60%)
three: 1.8000001907348633 (40%)
four: 0.8999996185302734 (20%)

slow walrus
#

you've done them wrong

dim tusk
#

Hm....

#

Kkk my bad i guess?

slow walrus
dim tusk
#

Ik confused asf, lemme redo my script.

#

And also serty said it's 25%

slow walrus
slow walrus
#

yeah ik he's wrong

warm mason
#

I'll check my system now. Maybe I'm really wrong

dim tusk
slow walrus
#

the final damage after resistance reduction?

dim tusk
slow walrus
#

ah ok, then do

const damage_reduction = 0.20 * resistance_level * damage
#

oh wait

#

no

#

cause your damage will be after reduction

#

so you gotta get the original damage first

#

which should be

bright dove
#
class EnchantDeshPickaxe {
    constructor(player) {
        this.player = player;
    }

    enchantSelectedItem() {
        // Retrieve the currently selected item from the player's inventory
        let item = this.player.getComponent('inventory').getItem(this.player.selectedSlotIndex);
        
        // Check if the item is the pickaxe and is enchantable
        if (item && item.typeId === "cosmos:desh_pickaxe") {
            let enchComp = item.getComponent('enchantable');
            if (!enchComp) {
                console.log("The selected item is not enchantable.");
                return; // Exit if the item is not enchantable
            }

            // Define the enchantment to be added
            const enchantment = { type: new EnchantmentType('silk_touch'), level: 1 };

            // Add the enchantment to the item
            enchComp.addEnchantment(enchantment);

            // Update the item in the player's inventory to register the enchantment
            this.player.getComponent('inventory').setItem(this.player.selectedSlotIndex, item);
            
          }
        }
    }```
#

@dim tusk is this a valid class ?

slow walrus
#

and then the damage reduction is original - damage

const damage_reduction = original_damage - damage
dim tusk
# slow walrus oh wait

That's why the damage resisted is wrong when I'm trying to add it on the current damage.

Damage: 1.8000001907348633 | Resisted Damage: 0.7200000762939454

slow walrus
#

or just

const damage_reduction = damage / (1 - 0.2 * resistance_level) - damage
warm mason
bright dove
warm mason
#

And it's the same here

thorn flicker
#

you should store part of that in a variable so you can use it again below

warm mason
#
.getComponent("inventory").container.getItem()
#
class EnchantDeshPickaxe {
    constructor(player) {
        this.player = player;
    }

    enchantSelectedItem() {
        let inv = this.player.getComponent("inventory").container
        let item = inv.getItem(this.player.selectedSlotIndex);
        
        if (item && item.typeId === "cosmos:desh_pickaxe") {
            let enchComp = item.getComponent('enchantable');
            if (!enchComp) {
                console.log("The selected item is not enchantable.");
                return; // Exit if the item is not enchantable
            }
            const enchantment = { type: new EnchantmentType('silk_touch'), level: 1 };
            enchComp.addEnchantment(enchantment);
            inv.setItem(this.player.selectedSlotIndex, item);
          }
        }
    }
thorn flicker
#

👍

warm mason
#

In general, it’s not very clear why create an entire class just for the sake of adding enchantment to a certain pickaxe

bright dove
#

Thanks

bright dove
#

i should've make it a function but i want to make it a class for the sake of syntactic flowery

thorn flicker
warm mason
bright dove
#

Thanks though 😍

thorn flicker
#

nothing wrong with that

bright dove
#

pun intended >:) ?

warm mason
distant tulip
#

most of the time the functions names are self explanatory

warm mason
distant tulip
#

for readability just avoid confusing stuff that not widely known (if possible)

bright dove
#

I'd like to pretend JS is like Java

#

As a result, it's all classes

#

doesn't reduce speed anyway

dim tusk
#

I have "Resistance II" btw

slow walrus
#

you put the bracket in the wrong place

#

it should be infront of the 1

#

not the 0.20

dim tusk
#

Ohh lmao

warm mason
slow walrus
#

shit

#

oh ffs

#

wtf

#

ok nvm

#

whatever

warm mason
#
world.afterEvents.entityHurt.subscribe(({
    hurtEntity, damage
}) => {
    if (hurtEntity instanceof Player) {
        const resistance = hurtEntity.getEffect('resistance');
        const originalDamage = damage / (1 - (resistance.amplifier+1)*0.2)
        console.warn("Damage: " + damage + " | Original Damage: " + originalDamage)
    }
});
dim tusk
#

Ok that's why I keep changing the values it's still not working lmao

slow walrus
slow walrus
#

ah right

distant gulch
#

Made a command manager.
the command looks like hell himself

dim tusk
#

I'm starting lost my mind here....

dim tusk
distant gulch
dim tusk
#

I don't have effect but why it's 5.625

distant gulch
#

imma take a look, wait

warm mason
dim tusk
#

I know that's why I put it 0

distant gulch
#

forget it, i made a mistake

warm mason
distant gulch
dim tusk
# warm mason Where did you put 0?
world.afterEvents.entityHurt.subscribe(({
    hurtEntity, damage
}) => {
    if (hurtEntity instanceof Player) {
        const resistance = hurtEntity.getEffect('resistance');
        const originalDamage = damage / (1 - ((resistance?.amplifier || 0) + 1) * 0.2);
        console.error("Damage: " + damage + " | Original Damage: " + originalDamage);
    }
});```
warm mason
#

no..

#
world.afterEvents.entityHurt.subscribe(({
    hurtEntity, damage
}) => {
    if (hurtEntity instanceof Player) {
        const level = (hurtEntity.getEffect('resistance').amplifier + 1) || 0;
        const originalDamage = damage / (1 - level * 0.2);
        console.error("Damage: " + damage + " | Original Damage: " + originalDamage);
    }
});
dim tusk
#

It works putting -1

#

But okay

warm mason
warm mason
dim tusk
#

Yeah I copied it already

dense wraith
#

One message removed from a suspended account.

#

One message removed from a suspended account.

#

One message removed from a suspended account.

dim tusk
#

I can say it's working but not 100% accurate

dense wraith
#

One message removed from a suspended account.

warm mason
#

You can use this random and do it something like this

let menu = new ActionFormData()
for (let i = 0; i < 4; i++) {
  menu.button(Random.element(["Button 1", "Button 2"]))
}
dim tusk
warm mason
dense wraith
subtle cove
#
const cards = [].sort(() => Math.random() - 0.5).slice(0,4)
dense wraith
#

One message removed from a suspended account.

subtle cove
#

[] will be ur part to fill in, with string (list of all cards)

warm mason
#

But in general, you will still need to remember what text each button has, so..

let menu = new ActionFormData()
let buttonValues = []
for (let i = 0; i < 4; i++) {
  let value = Random.element(["Button 1", "Button 2","Button 3..."])
  buttonValues.push(value)
  menu.button(value)
}
dim tusk
#

Damn, looks like I need to take account other effects too, like regenerations or instant health

#

damage in entityhurt just returns how much health entity lsoe

chilly fractal
#

Yo does the block in playerPlaceBlock beforeEvent return the block being placed's location? (I assume not because there is a permutationBeingPlaced so how would I get the new block's location?

warm mason
chilly fractal
#

It says block being impacted by this event

warm mason
#

and?

chilly fractal
#

And why would they have permutationBeingPlaced if I can just get the typeId from the block straight up... right?

#

TypeId & perm and anything else

warm mason
chilly fractal
#

Okay so basically what you are trying to say is block is the block being placed but isn't Readable until I exit read only mode right?

warm mason
random flint
clear pendant
#

is it possible to rotate the camera in the z axis?

random flint
#

Tilting? no

clear pendant
#

pain

steady canopy
# distant gulch

What extension do you use to make it show the result of the operation?

shut citrus
#

how minecraft caculates fishing rod pull mechanic?

distant gulch
abstract cave
abstract cave
distant gulch
tender ocean
#

how to make an entity break a specific block so that it executes the entityHitBlock event?

weary umbra
#

does the sign component have setGlow() or something like that?

chilly fractal
#

Probably might be within it's states

#

The like block permutation's states ig

weary umbra
distant tulip
chilly fractal
#

Don't spite me y'all, I said "probably"

#

Not straight up "it is"

#

Also BTW does the permutation of the spawner return the mob spawner type?

#

Probably not right?

distant tulip
distant tulip
chilly fractal
chilly fractal
distant tulip
#

you are referring to the mob?

chilly fractal
#

Yes, like the mob that is getting spawned within that spawner

distant tulip
#

no it is not a permutation

chilly fractal
#

All i need to know is if I can or cannot do that

#

(With some way or another)

distant tulip
#

wait for a mob to spawn...

chilly fractal
#

Welp :)

tender pier
#

How can I detect when the player is sneaking?

warm mason
tender pier
distant gulch
oak lynx
#

Are there any fixes in the api to the current dupe which involves leaving

dim tusk
neat hazel
#

What's the error?

LINE 41 -->mc.world.beforeEvents.worldInitialize.subscribe(initEvent => {
  initEvent.blockComponentRegistry.registerCustomComponent('hash:tube_component', tubeComponent);
});
oak lynx
neat hazel
warm mason
warm mason
#

change to 1.17.0-beta

#

2.0.0-alpha no longer exists

neat hazel
neat hazel
warm mason
buoyant canopy
#
for (let i in ['red', 'green', 'blue']) {
  console.log(typeof i)
}

What do you expect this loop to output?

buoyant canopy
#

yes, this has me stomped for a while

thorn flicker
buoyant canopy
#

you would expect i to be 0, 1, 2
but it is '0', '1', '2' which got me confused for my code isn't working

warm mason
#

Why? loop iterates through the array

wary edge
#

Yeah I expect i to be a string since its looping through an array.

simple zodiac
#

thats what a for of loop does. A for in loop loops through the object keys as far as i know

warm mason
#

Oh, well, yes. in iterates over the properties of the object so the output should be number

simple zodiac
#

nah the object keys will always be strings regardless

warm mason
simple zodiac
buoyant canopy
buoyant canopy
wary edge
#

You might wanna do of instead.

simple zodiac
#

I dont even know what you are trying to do so I can't tell you

buoyant canopy
#

i just added a plus sign before it and that solved my issue

#

+i convert i into a number

buoyant canopy
warm mason
buoyant canopy
#

again, i don't have a problem, i find it interesting that i is a string and not a number, but now i know why

#

so does of return the values an object?

buoyant canopy
#

that means i could use:
1 of [1, 2, 3]
instead of:
[1, 2, 3].includes(1)

buoyant canopy
#

huh

warm mason
#

of only works in loops as I know and it returns an iterator of the object's values

buoyant canopy
#

why does in work outside loops while of doesn't

warm mason
#

Maybe it works, but I don't know

buoyant canopy
#

i just tried it

warm mason
#

👀

marsh berry
#

I am running my bedrock server in a Docker on my unraid server. And i cant get server -net activated in my permission file in the config folder. I do delete the file you need to delete to add a new config. But at startup it just overwrites the new config file with the old one. Can it be because im not running the official server on Windows? Or a Docker bug?

distant tulip
ruby haven
#

I made a script that activates a death scene after the player is killed by a certain entity the problem is that entity summons another entity so the script won't work how do I make the entity be treated as the same as the original entity?

distant tulip
#

how so

buoyant canopy
#

i mean, in when used outside a for loop returns if a key is found in an object: 'x' in {x: 1} returns true, you would expect the same works for of but it checks if x is found as a value in the object

dense wraith
#

One message removed from a suspended account.

#

One message removed from a suspended account.

dim tusk
# dense wraith One message removed from a suspended account.

Use forEach

function zanjutsulevel(player) {
    let zanjutsumoves = [
        { texture: "textures/ui/levelup/whirlwindslash.png", tag: "whirlwindslash" },
        { texture: "textures/ui/levelup/nightjarslash.png", tag: "nightjarslash" },
        { texture: "textures/ui/levelup/ichimonji.png", tag: "ichimonji" },
        { texture: "textures/ui/levelup/cross.png", tag: "cross" },
        { texture: "textures/ui/levelup/flash.png", tag: "flash" }
    ];

    let randomZanjutsu = zanjutsumoves.sort(() => Math.random() - 0.5).slice(0, 4);

    const zanjutsulevel = new ActionFormData();

    zanjutsulevel.title("§d");
    zanjutsulevel.body("");

    randomZanjutsu.forEach((move, index) => {
        zanjutsulevel.button(`§d${move.tag}`, move.texture);
    });

    zanjutsulevel.show(player).then((res) => {
        if (res.selection !== -1) {
            player.runCommand(`say card ${res.selection + 1} chosen`);
            player.runCommand(`playsound jjk.menuclick1 @s ~~~ 10000 1 10000`);
        }
    });
}
dense wraith
dense wraith
dim tusk
dense wraith
#

One message removed from a suspended account.

#

One message removed from a suspended account.

#

One message removed from a suspended account.

dim tusk
# dense wraith One message removed from a suspended account.
function zanjutsulevel(player) {
    let zanjutsumoves = [
        { texture: "textures/ui/levelup/whirlwindslash.png", tag: "whirlwindslash" },
        { texture: "textures/ui/levelup/nightjarslash.png", tag: "nightjarslash" },
        { texture: "textures/ui/levelup/ichimonji.png", tag: "ichimonji" },
        { texture: "textures/ui/levelup/cross.png", tag: "cross" },
        { texture: "textures/ui/levelup/flash.png", tag: "flash" }
    ];

    let randomZanjutsu = zanjutsumoves.sort(() => Math.random() - 0.5).slice(0, 4);

    const zanjutsulevel = new ActionFormData();

    zanjutsulevel.title("§d");
    zanjutsulevel.body("");

    randomZanjutsu.forEach((move, index) => {
        zanjutsulevel.button(`§d${move.tag}`, move.texture);
    });

    zanjutsulevel.show(player).then((res) => {
        if (res.selection !== -1) {
            player.runCommand(`say card ${res.selection + 1} chosen`);
            player.runCommand(`playsound jjk.menuclick1 @s ~~~ 10000 1 10000`);

            const selectedMove = randomZanjutsu[res.selection];

            switch (selectedMove.tag) {
                case "whirlwindslash":
                    player.runCommand("say whirl!");
                    break;
                case "nightjarslash":
                    player.runCommand("say nightjar!");
                    break;
                case "ichimonji":
                    player.runCommand("say ichimonji!");
                    break;
                case "cross":
                    player.runCommand("say cross!");
                    break;
                case "flash":
                    player.runCommand("say flash!");
                    break;
                default:
                    break;
            }
        }
    });
}
#

I'm not kinda sure if this works well you can just try it

dense wraith
#

One message removed from a suspended account.

#

One message removed from a suspended account.

dim tusk
dim tusk
#

All I want for Christmas is to be able to detect the data and set the data of the item using script's

distant gulch
#

How do I set up VS Code?

#

I want it to work like bridge, but without using bridge lol

dim tusk
distant gulch
#

Well I'm using a laptop

#

only 8GB

#

of ram

#

but I can manage

dim tusk
distant gulch
#

I did

distant gulch
dim tusk
ruby haven
#

How can I pass the responsibility of being a damagingEntity cause I have an entity called smile there is this attack called stomp where it summons another entity called mz:stomp, this entity disappears after 0.1 seconds so how can I pass it's responsibility of being a damagingEntity to the original entity smile

abstract cave
#

Is there a way i can run a command in a specific location, via dimension
whenever i use it, i only runs at 00 can i change the location

latent wing
#

Does anyone know how to add extra buttons to the normal player interface?

dim tusk
#

Damn, three questions in a row

abstract cave
dim tusk
#

Or what command you trying to run?

dim tusk
ruby haven
latent wing
#

It's quite old and I couldn't find the video, but the addon was paid

dim tusk
abstract cave
ruby haven
timid zenith
#

A question someone here who knows to update custom npc please thank ????

timid zenith
ruby haven
proud pond
#

how can a memory leak be caused by script api

dim tusk
distant gulch
#

How do I set a volume with world.getDimension().getBlocks()?

cold grove
#

like, melee attack?

ruby haven
cold grove
#

just area attack?

ruby haven
cold grove
#

you can make via scripts that attack and set the damageSource to the original entity

ruby haven
cold grove
#

but you should remove every damage behaviour in your json

ruby haven
cold grove
ruby haven
cold grove
#
const attacker_original = ...;
const attacker_summoning = ...;
const maxDistance = 5; 
attacker_original .dimension.getEntities({ location: attacker_summoning .location, maxDistance })
.forEach((e) => {
    e.applyDamage(10, { damagingEntity: attacker_original });
});```
cold grove
ruby haven
warm mason
ruby haven
ruby haven
dim tusk
dim tusk
#

use entityspawn you can get the cause of spawning

ruby haven
#

Wait my entity smile is summoning an entity through a component called spawn_entity and the method I assigned is born in the spawnEntity event listener there are only 2 parameter which is the entity spawned and the cause how can I check the entity that spawned it?

distant gulch
whole saddle
#

hey guys, do you know how to read shulker box content from the inv of a player? I tried it via playerBreakBlock and it worked with BlockComponentTypes, but if I try that with the inventory container of a player and blockcomponenttypes it doesn't really work (it doesn't give out any info). Does anyone know how to get that info?

chilly fractal
#

You can't read shulker box contents from the inv of a player

whole saddle
#

do you know any other method that could bring this to work?

chilly fractal
#

You could read it if you placed it because of the block inventory component much like the entity inventory component

chilly fractal
whole saddle
#

bruh

#

ok

#

thanks

uncut summit
#

What's the new chatsend subscribe?

chilly fractal
# whole saddle bruh

I mean just ask the player to place the shulker then on the playerPlaceBlock after event, read all it's data, and use setblock (block coords) air destroy and get the nearest item in that coord, and give the player a copy and kill it... ig?

chilly fractal
uncut summit
chilly fractal
#

But only the beforeEvent has existed tho, now you have an afterEvent! yay!

chilly fractal
#

(I think)

uncut summit
#

Why isn't it working used to work before

#

I'm getting a error that the subscribe isn't right

#

I tried before events

chilly fractal
#

You can't cancel an afterEvent.

uncut summit
#

No like the whole subscribe is wrong it says

slow walrus
#

:l

#

are you using AI again

chilly fractal
#

Also why use ```js
for (const recipient of world.getPlayers()) {
recipient.sendMessage(formattedMessage);
}

When you literally don't have a dead players system, not a trolling system or anything to filter who to send the message to?
slow walrus
#

the AI doesn't know to just use world.sendMessage

chilly fractal
#

If you fed it enough docs & npm it still wouldn't know?

slow walrus
#

nope, it's stupid as hell

#

first time it'll just hallucinate like shit, then you tell it your errors, then it'll go "Ah you're right, here's a slightly fixed version!"

#

rinse and repeat

#

and it eventually ends up with obscure redundant code

chilly fractal
#

I mean I don't rely on AI except on a bit of language assignments as I am pretty dumb in German but yeah I double check the answers

slow walrus
#

that works, but there's better ways

#

because it'll get stuck on how it wants to do it

ruby haven
#

Is possible to detect if an entity spawned detect the entity that spawned it?

chilly fractal
random flint
#

entitySpawn afterEvents

chilly fractal
uncut summit
slow walrus
chilly fractal
#

Welp

ruby haven
random flint
slow walrus
# uncut summit Help
  1. Delete whichever AI you're using, as I've told you before
  2. Use the chatSend before event, you can't cancel the afterEvent
  3. check that you are using the beta api, the chatSend beforeEvent isn't available on stable.
  4. quick tip, replace the last player loop with just world.sendMessage()
chilly fractal
uncut summit
#

Code

#

I tried beforeevents

slow walrus
#

as per the comments

#

very easy to tell

random flint
uncut summit
slow walrus
#

Windows Key + Shift + S

#

use that

#

to screenshot

uncut summit
#

My pc discord not working

random flint
# uncut summit
  • Rejoin the world.
  • Maybe the older version of the pack got cached onto the world folder
distant gulch
#

-# screenshot will be saved to your clipboard

chilly fractal
slow walrus
distant gulch
#

You guys thing the prefixes are pretty "readable" and easy to keep in mind?

-n <repeat_count: number>
-c <command: string>
-p* <raw_parameters: string>
-rx* <feedback_receiver: player>
warm mason
distant gulch
distant gulch
#

Not a own lang.

warm mason
distant gulch
#

Is this still diff. to read?

#

-_-

random flint
#

Well, you gotta add a lot of instructions or references and what each keyword does

#

what does - signify? l?

distant gulch
#

-l is a parameter

#

i say that -l haves 0 0 0 and -p haves "player1

#

Kinda like in python when you say
arg1 = value inside a function call

random flint
ruby haven
random flint
distant gulch
ruby haven
slow walrus
chilly fractal
#

Okay so I'm not too good with entities butt, yes with another t, I'm pretty sure you can trigger an event like "event": "ds:sayWhoSpawnedMe" and then have an event setup (all this is within the entity file still),

// events object of your entity 
"events": {
  "ds:sayWhoSpawnedMe": {
    "queue_command": {
      "command": [
        "scriptevent ds:sayWhoSpawnedMe 0123210"
      ]
    }
  }
  // any other events if you have any (make sure to put "," at the end of this event if you you wanna make other events)
}

and in your Scripting part do:

system.afterEvents.scriptEventReceive.subscribe((data) => {
  let entity = data.sourceEntity, id = data.id, verificationCode = data.message;
  
  if (id !== 'ds:sayWhoSpawnedMe') return;
  //if (verificationCode !== "0123210") return;
  world.sendMessage(entity.typeId);
});

BTW verificationCode is extra from me, you don't need to use it.., if you want to use it just uncomment it.
@ruby haven

ruby haven
chilly fractal
distant gulch
#

How do I grab every block from an area and run something from it?
I've tried -

const test = new BlockVolume({x: 0, y: 0, z: 0}, {x: 0, y: 0, z: 0})l
const blocks = world.getDimension().getBlocks(test);
#

obv the coords are diff

#

but it doesn't give me the array of blocks

#

and I want to run a forEach on all the blocks in that volume

#

and I'd rather not do a getBlock for each individual block location in an area

past blaze
distant gulch
#

I didn't know LocationIterator grabbed the,

#

them*

#

thanks

distant gulch
#

nvm, ignore me

#

forgot to make it a function

distant gulch
#

Where can I find all the stable module versions?

#

and beta ig too

cold grove
#

/docs info

gaunt salmonBOT
pallid portal
#

curiosity got the best of me.

Aside from the ambiguous wiki that just lists functions, components and modules.
Is there a resource that explains how to just write a script in simple terms.

Namely, if you were to make a custom block component with an interaction, place, detect other blocks, or just do an event.
Isn't there a document that explains how to format/assemble a script file?

And if the answer is learning JavaScript, would this mean doing a whole course on that would magically mean you can write Scripts for Minecraft Bedrock addons?

wary edge
pallid portal
#

If I do so and find out that the way the scripts are formatted is not the same. Imma be upset.

#

(all of this over a project with friends that did not need these things......)

chilly fractal
past blaze
scarlet lynx
#

@wary edge Hey, do you know if there is a area where I can reach out to Scripting Devs ( mojang ) of ideas for stuff

wary edge
scarlet lynx
valid ice
#

Display name is client side tho

wary edge
valid ice
#

Ohhhhh that part

granite badger
#

blame them for having so many format for key translations

valid ice
#

Translation keys are so cooked 😭

scarlet lynx
valid ice
#

RP lang file translations

scarlet lynx
#

Yeah, they could do the BP pack side though

granite badger
#

i recently made a mapping for vanilla item translations, it was a lot of effort

scarlet sable
#

what allows mobs to break blocks?

#

in the api of course

burnt robin
#

is server-net not able to use express servers??

#

i've used a http request in minecraft and the same for fetch in node.js both to the same server same setup fetch worked and gave the data but minecraft server-net didnt

#

it returned an empty object

dim tusk
#

Guys, can you detect if banner have designs already like you already used them in loom....

#

If not can commands do it?

distant tulip
dim tusk
distant gulch
#

Is there a method to manually load a chunk script side?

hardy tusk
neat hound
#

I wish there was something that would hit you upside the head and say... you hjave single equal signs in your IF statement...

hardy tusk
#

There is also a practice for that, that says you should never do var == 1 but rather always 1 == var so the engine can throw an error for that

dim tusk
hardy tusk
#

(But I forgot the name of it since I dont ever run into that problem and wrote it off as irrelevant)

neat hound
distant gulch
#

wondering if there was a js api i didnt know about

dim tusk
distant gulch
#

How is chunks loaded actually calculated in the debugger?

hardy tusk
distant gulch
#

I have 12 chunk radius, 12*12 at most should be 144?

dim tusk
#

Is that vscode?

hardy tusk
hardy tusk
#

Agree

slow walrus
#

loaded just means they're been loaded from the disk into memory

distant gulch
#

But nothing should be happening, sicne its just me with a 12 render distance

#

wait

slow walrus
#

the chunks still tick

distant gulch
#

yes i understand

#

hahahah

#

i was looking at the blue

#

thank you

slow walrus
#

👍

#

the naming is a bit ambiguous

#

but yeah

neat hound
hardy tusk
#

Damn

distant tulip
#

you will notice it overtime

neat hound
#

I am usually pretty good about it.. except when I'm not... I tend to write a lot of code and then test.. I've gotten good enough to do that... but when I miss this occasionally... takes a while to troubleshoot. I had this... js if (grid4.y = 0) newBlockFace = 'down'; else if (grid4.y = 3) newBlockFace = 'up'; else if (grid4.x = 0) newBlockFace = getPerpendicularFace(eventFace, 0); else if (grid4.x = 3) newBlockFace = getPerpendicularFace(eventFace, 1); ); else newBlockFace = eventFace;

distant gulch
#
               const sign = world.getDimension("overworld").setBlockType({ x, y: y + 2, z }, "minecraft:oak_sign");
``` Has anoyne tried messing aorund with signs?
#

Seems as if signs are not a block

distant gulch
wary edge
distant gulch
#

MinecraftBlockTypes dosnt seem to be a valid export from @minecraft/server

#

is there a raw id for that?

wary edge
#

Check in-game or the mc wiki. I can't check right now.

distant gulch
#

thanks

wary edge
#

should just be oak_standing_sign... should

sterile epoch
#

what is the difference between in and of in a foor loop? i used in accidentally instead of 'of' and it didn't work

sterile epoch
#

ahhh, thank you

distant gulch
#
               const signBlock = world.getDimension("overworld").getBlock({ x, y, z });
               const signPerm = BlockPermutation.resolve('minecraft:standing_sign', { ground_sign_direction: 0 });
               signBlock.setPermutation(signPerm);
               const signComponent = signBlock.getComponent(BlockComponentTypes.Sign);
               signComponent.setText({ translate: 'item.skull.player.name', with: ['Steve'] });```
dim tusk
#

Which is not built in you need to get the bundle

dim tusk
#

I have a simple functions that detects detects if player eats a cake but if the cake is in last eaten state when player interact it, it can't detect since it disappears do anyone knows a fix?

#
const blockPerm = new WeakMap();

world.beforeEvents.playerInteractWithBlock.subscribe(({
    block, player
}) => {
    blockPerm.set(player, block.permutation);
});

world.afterEvents.playerInteractWithBlock.subscribe(({
    block, player, beforeItemStack, itemStack
}) => {
    const stats = JSON.parse(player.getDynamicProperty('stats') || '{}');
    const blocks = blockMap[block.typeId];
    const perm = blockPerm.get(player);

    if (blocks) {
        if (perm && perm !== block.permutation) {
            switch (perm.type.id) {
                case 'minecraft:cake':
                    console.error('Eat Cake!');
                    break;

                default:
                    break;
            }
        } else if (
            perm.type.id !== 'minecraft:cake'
        ) {
            console.error(`${block.typeId}`);
        }
    }
});```
neat hound
#

drag and drop where you need it.

dull shell
#
import { world, GameMode } from "@minecraft/server";

/** @type {import("@minecraft/server").BlockCustomComponent} */
const CreativeModeOnlyBlockComponent = {
    onPlayerDestroy(event) {
        event.block (block.typeId === "jay:coal_ore")
        event.player (entity.typeId === "minecraft:player") 
          entity.runCommandAsync("execute @s ~~~ say broke coal ore");
    }
}```
im trying to make it so when I break my custom block it runs a command but im not getting any errors logs?
#

in my content log

deep yew
#

what is "onPlayerDestroy"?

dull shell
#

on player destoryed?

deep yew
#

oh I see, I was very confused by the variable

dull shell
#

no your okay

deep yew
#

It may be due to the execute command being changed from the old format

#

execute as @s run say broke coal ore

dull shell
#

no my other pack with scripts work without the new one

deep yew
#

interesting

dull shell
#

i feel like my code is wrong

#

im not that good with js

deep yew
#

I'm not familiar with the code aspect, using the CreativeModeOnlyBlockComponent stuff

#

But it just seems odd to not be a function or listener

dull shell
#

I got that from the microsoft docs 1sec

#

i found this and reworked around it

deep yew
#

do you have the part 2?

#

"world.beforeEvents.worldInitialize..."