#Script API General

1 messages · Page 123 of 1

broken pawn
#

let me try something then

jagged gazelle
#

wadahell is that flag??

#

and sup menn...

distant tulip
distant tulip
jagged gazelle
distant tulip
#

Good to hear

broken pawn
#

i have no idea, gotta re-code it again

wheat condor
#

textField needs more than 1
write each thing in different line and look better at the error

stray spoke
#

Does anyone have previews screenshots about debug-utilities?

wheat condor
#

the error is telling you that 2-3 parameters are expected line 8 and the function was called on line 4

fallow minnow
#

how can i wait for a structure to be loaded and then run code after its done?

wary edge
fallow minnow
#

but i need to like wait dynamically

#

i dont know how long itll take the structure to load as its dynamically changed

wary edge
#

It shouldnt take more than 40 ticks.

fallow minnow
#

64x64
from -64 to 200 loading by layer to deter lag

wary edge
fallow minnow
#

oh true

#

so i can just statically define a time and waitTicks that

wary edge
#

Correct.

#

I would do a Map<string, number>

stray spoke
#

Is there snippets for debug utilities bounding box

stray spoke
#

Dk how to use it, it appears invisible on mine with no error logs

#
import {DebugBox} from '@minecraft/debug-utilities'

world.beforeEvents.playerBreakBlock.subscribe(data => {
  const {itemStack: item,player,block} = data;
  if(item?.typeId === "minecraft:wooden_axe"){
    data.cancel = true
    const dbox = new DebugBox(block.location)
    dbox.scale = 5
    dbox.timeLeft = 5
  }
})
stray spoke
#

I don't understand

stray spoke
#

Ohh

fallow minnow
#

what is restricted execution

silver agate
#

?

wary edge
fallow minnow
#

ahh

wary edge
silver agate
stray spoke
#

Like this?

import {DebugBox,DebugDrawer} from '@minecraft/debug-utilities'

world.beforeEvents.playerBreakBlock.subscribe(data => {
  const {itemStack: item,player,block} = data;
  if(item?.typeId === "minecraft:wooden_axe"){
    data.cancel = true
    
    const dbox = new DebugBox(block.location)
    dbox.scale = 5
    dbox.timeLeft = 5
    
    DebugDrawer.addShape(dbox)
  }
})
wary edge
silver agate
wary edge
#

It can be anything.

#

It's a callback, so for however many params you have thats how many params your function should have + 1 for the origin.

silver agate
#

Just for confirmation: I have to put in order origin, mandatory params (one by one), optional params (one by one)?

stray spoke
#

Dk why it just says addShape is not a function

fallow minnow
#

literally 64x64 😭

#

wait

wary edge
fallow minnow
#

i had the coordinates opposite

stray spoke
#

Ohh

#

Thanks

silver agate
stray spoke
#

like from vector 0,0,0 to 5,5,-5

#

It only give sizes

#

Might gonna use some math

wary edge
#

Yes.

stray spoke
wary edge
#

All you have to do is set the corner to the least coord, then set the bounds using the offset

stray spoke
#

Oh I see

#

I was thinking to use lines instead

#

I gotta study this more

#

Thanks again

#

Idk how bounding works

#

Like an offset of the whole box?

wary edge
#

No its basically the size.

stray spoke
#

Ohhh like in the structure box

#

it uses xyz also

#

idk if I'm right

wary edge
#

Yes.

#

So in your example
dbox.bounds = {x:10 , y:15, z:20}

stray spoke
#

I kinda understand now, thank you

#

Like this

tidal wasp
#

Her does anyone know of x == (4 || 5) sould be valid syntax for an if statement

tidal wasp
#

I wanted a shorter was to allow for x to by 4 or 5

dawn zealot
#

remove the brackets and it works

tidal wasp
#

Oh okay

open urchin
#

it wouldn't

#

it would just check that x == 4

dawn zealot
#

js do this (x === 4 || x === 5)

devout sandal
#

How the hell can I make my script place a structure that’s saved in its structures folder.. I can’t for the life of me get it to recognise them. Even in game, I am trying to use the place command and the ids for the custom structures in the bp aren’t registering…

open urchin
#

where are you saving the structures and what are you using as the structure name

wary edge
#

There is a bug where BP structures arent recognized after executing once.

devout sandal
wary edge
#

You need structure load

stray spoke
#

It works but it's always going to the edge

#

My formula is wrong

wary edge
stray spoke
wary edge
stray spoke
#

Lemme try

#

it the same, maybe half or something but float

#
      const min = {
        x: Math.min(p1.x, p2.x),
        y: Math.min(p1.y, p2.y),
        z: Math.min(p1.z, p2.z)
      }
      
      const max = {
        x: Math.max(p1.x, p2.x),
        y: Math.max(p1.y, p2.y),
        z: Math.max(p1.z, p2.z)
      }
      
      const size = {
        x: max.x - min.x,
        y: max.y - min.y,
        z: max.z - min.z
      }
      
      const dbox = new DebugBox({x: min.x + 1, y: min.y + 1, z: min.z + 1})
      dbox.bound = size
wary edge
#

I meant for the size

#

Not the starting location

stray spoke
#

Ohh

#

Alright

#

Thanks a lot

#

Its perfectly fine now

stray spoke
distant tulip
#

Bruh

stray spoke
#

Didn't know ItemStack class have clone()

#

Is this new

distant tulip
#

The function no one uses

distant tulip
stray spoke
#

best for trading features or gui systems

stray spoke
#

How to detect if item stack is placable

distant tulip
#

You can only detect if it is a block
That leave out items with place block component

small depot
#

The time will depend on how big the structure is

stray spoke
stray spoke
#

I've been searching for a way

#

Do you think minecraft:block_placer would work

distant tulip
#

Both of those return array

stray spoke
#

is it like BlockTypes.get(id) if returns false means it's not placable

#

Instead of getAll

distant tulip
#

I guess..?

stray spoke
#

Lol

#

Thanks again

#

I'll try getall

distant tulip
#

I mean get() should work
Was thinking more of a way to get the list, not test if an item is placeable

stray spoke
#

sure, I'm thinking if it's like this in concise way

#

I don't know if this works

burnt musk
#

damn.. we can't get the food component from vanilla items, is there another way to check if a vanilla item is food?

distant tulip
#

You can get it from apples apparently

distant tulip
stray spoke
#

Isnt it ItemStack.hasComponent("minecraft:food")

stray spoke
burnt musk
#

yeah but that returns undefined for most of vanilla food

stray spoke
#

Apples are block type now

#

Hmm

distant tulip
#

Map there values and use that for vanilla items

burnt musk
#

ah yeah... I need a list of food items

#

alright, good enough heheh, although I think I'll do some workaround

#

thanks! :)

pale terrace
#

place structure in runCommand isnt working?

wary edge
pale terrace
#

because the native function crash my world when the structure is big

pale terrace
wary edge
#

Or make the structure smaller.

#

How big is it.

pale terrace
#

a lot

wary edge
pale terrace
wary edge
#

Then it should have no trouble being placed. I've had no issues.

halcyon phoenix
#

WE FINALLY

#

HAVE IT

warped blaze
#

lol

halcyon phoenix
#

is it possible to decrease the size of this?

gaunt salmonBOT
deep arrow
#

For custom block components, whats the difference in onTick, and onRandomTick

wary edge
deep arrow
wary edge
#

Yes.

deep arrow
# wary edge Yes.

Im adding leaf decay to custom leaves, should would it be better to do it via random tick them?

wary edge
#

Yes.

stray spoke
#

I was trying to detect if the held item is a block type/placable, but it always goes false

            const isBlock = BlockTypes.getAll().find(b => b.id === item.id)
            if(isBlock){
              player.runCommand(`fill ${p1} ${p2} ${item.typeId}`)
            }else{
              player.runCommand(`fill ${p1} ${p2} air`)
            }
#

Even if the item is grass block

earnest meadow
#

onBreak block custom component doesn't fire if a player breaks the block?

#

what?

earnest meadow
#

not sure what causes it, only onPlayerBreak works for me

jagged gazelle
stray spoke
jagged gazelle
#

u probably did something wrong then...

#

I never had a problem dealing with types...

stray spoke
#

then changed it to item.typeId

#

It worked now

warm mason
#

Minecraft doesn't send any error or warn if you're trying to register unknown event, so..

mystic harness
#

form

cursive fog
#

does anyone know why this wont work

#
world.afterEvents.playerSpawn.subscribe((data) => {
    const { player, initialSpawn } = data;
    if (!initialSpawn) return;
    const inv = player.getComponent('inventory')?.container;
    if (!inv) return;
    const itemStack = new ItemStack("vdg:akm");
    itemStack.setDynamicProperty('vd:akammo', 30);


    world.afterEvents.itemUse.subscribe(ev => {
        const { source: player, itemStack } = ev
        if (itemStack.typeId !== gun) return
        const ammo = itemStack.getDynamicProperty('vd:akammo');

        const dpshoot = system.runInterval(() => {
            if (typeof ammo === 'number') {
                itemStack.setDynamicProperty('vd:akammo', ammo - 1);
                if (ammo <= 0) itemStack.setDynamicProperty('vd:akammo', null)
            }
        }, 1)
        if (ammo == null) empty = true
        if (ammo > 0) empty = false

    })
});


world.afterEvents.itemUse.subscribe(ev => {
    const { source: player, itemStack } = ev
    if (itemStack.typeId !== gun) return
    if (empty == true) return
    const shoot = system.runInterval(() => {
        shootProjectile('arrow', player.dimension, player.getHeadLocation(), player.getViewDirection(), {
            power: 10,
            uncertainty: 3,
            owner: player
        })
    }, 2)


    world.afterEvents.itemStopUse.subscribe(ev => {
        const { source: player, itemStack } = ev
        if (itemStack.typeId !== gun) return
        system.clearRun(shoot)


    })
})

#

basically if the ammo variable which is a dynamic propery reaches 0 or null it turns empty to true which on the second part if empty is true it would return

stray spoke
#

I think it's because setDynamicProperty only accepts String, Number, Boolean, and Vector3, not null

#

You might need to set it to something else just not null

last latch
stray spoke
#

Strings like "undefined" "none" or something else

#

undefined type is not valid too

prisma shard
#

You can't get a property after its deleted

#

null basically deletes it

last latch
#

every empty property is undefined

stray spoke
#

My apologies

last latch
#

no problem

stray spoke
#

I setScore to a custom named participant but it says undefined

#

Do I use addScore instead

#

I can't find other methods to add participants

#

Oh doesn't work too

#
const ConfigObj = world.scoreboard.getObjective("bbconfig")
    if(ConfigObj) return;
    
    world.scoreboard.addObjective("bbconfig", "Config")
    
    // 1 = true, 0 = false
    ConfigObj.addScore("showBoundingBox", 1)
    ConfigObj.addScore("showWarning", 0)
    
    // rgb values 0 to 10
    ConfigObj.addScore("boxColorRed", 0)
    ConfigObj.addScore("boxColorGreen", 0)
    ConfigObj.addScore("boxColorBlue", 0)
distant tulip
#

can we prevent entity x rotation from snaping back to 0 after setRotation?

#

without using run interval

snow knoll
distant tulip
#

well, i guess i can force rotation using properties

snow knoll
#

Nvm

sudden nest
#

Is there a way to display an entity just like block/item display?

halcyon phoenix
#

what do you mean?

stray spoke
#

Yo I didn't know you can set dynamic property on World class

#

Pretty useful

stray spoke
#

Is it possible to add a custom command parameter where if I chose the enum "add", the next param requires Integer, and if I chose ejum "remove", the next param requires String

#

/call <add> <number>
/call <remove> <string>

weary umbra
#

We really want that

stray spoke
#

I see

#

Thank you

amber granite
#

I guess u can make it using scripting

stray spoke
#

I know it can, but the parameters are straight forward

#

It can't be custom like:
/call add <number> <string>

if I chose other enum it changes the next param:
/call remove <string> <boolean> <number>

wary edge
#

Correct.

midnight crane
#

So this other gui thing is that a whole separate I'm making in a different .js

sudden nest
fallow minnow
#

is the dyeable component usable for leather armor?

#

im trying to dye stuff

fallow minnow
#

how can i use it?

thorn ocean
#

Just reached a limit on a property due to string limits. Is there anyway to decrease the number, maybe using sets? Otherwise, I was just going to use another dynamic property with a different id to save more info.

wary edge
alpine wave
#

@winged gull can you please tell me what's wrong with this code and no I didn't use ai I have those notes there to help me remind me

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

// Define the system interval to run every second
system.runInterval(() => {
    updateTimePlayed();
    updateMoney();
}, 20); // Run every tick (1 tick = 1/20 of a second)

// Function to update the Time Played scoreboard
function updateTimePlayed() {
    let players = world.getPlayers();
    players.forEach(player => {
        // Get current time from the player's scoreboard (if it exists, otherwise set it to 0)
        let currentTime = player.getScoreboard().getScore("Time") || 0;
        // Update the scoreboard for time played (add 1 second)
        player.getScoreboard().setScore("Time", currentTime + 1);
    });
}

// Function to update the Money scoreboard
function updateMoney() {
    let players = world.getPlayers();
    players.forEach(player => {
        let currentMoney = player.getScoreboard().getScore("Money") || 0;
        // Add money every 10 seconds (if time is a multiple of 10)
        let time = player.getScoreboard().getScore("Time");
        if (time % 10 === 0) {
            player.getScoreboard().setScore("Money", currentMoney + 1);
        }
    });
}

// Function to display time and money in the action bar
function displayTime() {
    let players = world.getPlayers();
    players.forEach(player => {
        // Get the time played and format it into hours, minutes, and seconds
        let timeInSeconds = player.getScoreboard().getScore("Time");
        let hours = Math.floor(timeInSeconds / 3600);
        let minutes = Math.floor((timeInSeconds % 3600) / 60);
        let seconds = timeInSeconds % 60;

        // Get the player's money
        let money = player.getScoreboard().getScore("Money") || 0;

        // Create a string with the formatted time and money
        let formattedTime = `${hours}h ${minutes}m ${seconds}s`;
        let displayText = `Time: ${formattedTime} | Money: $${money}`;

        // Update the player's action bar with the time and money information
        player.sendActionBar(displayText);
    });
}

// Display time and money every second to all players in the action bar
system.runInterval(displayTime, 20); // Run this every tick (every second)
amber granite
#

What s the problem?

#

@alpine wave

half ivy
#

Hey queston how do I add a player to a scoreboard and give them a random score

hoary matrix
#

wut ?

half ivy
#

Ok so I am making a script thst creates a scoreboard objective. And when a player joins the world i wanna give them a random score

hoary matrix
#

its with a command or command block

#

with the command scoreboard

#

scoreboard players random @a (objective:like money kill) (min:amount) (max:amount)

half ivy
#

No i mean with scripting

#

Ik how to make a scoreboard

amber granite
#

Is your scoreboard non-shown ? @alpine wave

#

@half ivy

#

Or get showed

half ivy
#

It's non shown

amber granite
#

Then use dynamicProperties

#

It s better and easier to handle

#

Unless u are using commands

#

@half ivy

half ivy
#

Yeah

amber granite
#

Using commands right ?

half ivy
#

Yeah

amber granite
#

Don't know how to script right ?

half ivy
amber granite
#

._.

#

There a whole interface for scoreboard in scripting

#
/scoreboard players add playerName ObjectiveName Count ```
#

@half ivy

half ivy
#

Thanks

amber granite
#

If u need how to make it in script i can make it though

halcyon phoenix
#

but you can make an entity with no AI

sudden nest
#

What i wanted to use this is like displaying a frozen entity even from other addons. Like that

pale terrace
#

offset camera in first and third person still not working?

halcyon phoenix
#

is that what you meant?

sudden nest
#

Ah like riding? I think evokers can still do somethint or creepers, or not?

halcyon phoenix
#

like overlay

#

Spawn the entity on the entity

sudden nest
#

Ah okay, but doing that, i think creepers can still explode or some entities doing their behavior

halcyon phoenix
#

skeletons can still shoot too

#

But that can be fixed if the entity has been frozen and delete all arrows that it shoots

#

but the creeper, I have no idea how to disable it through script

sudden nest
#

Yeah, i just wish they have that, so there's many things you can do especially to creators.

halcyon phoenix
#

you have to probably add a component to creepers

jagged gazelle
#

pipol...

halcyon phoenix
halcyon phoenix
jagged gazelle
#

There is no way to check the "data" part of the item right??

jagged gazelle
#

<item> <amount> <data>

#

stick 1 1

#

something like that...

halcyon phoenix
#

here are some itemStack properties and methods

jagged gazelle
#

nvm u still can't

#

guess I'll stick with hasitem method...

#

fck.

halcyon phoenix
#

what do you mean by data though?

jagged gazelle
#

it's in the tip of my tongue lol

#

anyone can say it properly lol

halcyon phoenix
#

lmao

jagged gazelle
# halcyon phoenix lmao

The best I could do rn is js const command = player.runCommand('testfor @s[hasitem={item=stick,data=2}]').successCount

stray spoke
#

That's like a damage

#

Probably set the durability component

#

Maybe just use dynamic properties

jagged gazelle
#

which u can't.

stray spoke
#

Don't even know if it's about stackable item

#

My apologies

alpine wave
halcyon phoenix
#

is that like making a specific item liek example a stick but with different data so that its not stick?

#

iirc this is what used in datapacks right, pure commands

#

is that correct?

stray spoke
#

In old version there's no specific id for colored blocks, or other variants of blocks

#

We had to type something like/give concrete 1 5 in order to give ourselves a specific colored concrete

#

That's where data is used for

#

For tools it's a durability

#

It can be also used for other items to treat as "unique" than the other item with the same id

#

That's all I remember

still bolt
#

What exactly is early/restricted execution? I'm trying to create a scoreboard objective in a world.beforeEvents.playerInteractWithBlock event and it throws an error.

granite cape
#

hum long time

stray spoke
vapid grove
#

is applyKnockback or applyImpulse supportable for tnt?

snow knoll
untold magnet
#

what is the best way to detect a specific entity using scripts? i don't want to call every single entity in the game to detect a specific one (detecting the zombie entity instead of every single entity)

#

for (const entity from world.getDimension('overworld').getEntities()) {} will return every single entity in the world, which is not good for my system,

#

do i have to add .getEntities({type: 'minecraft:zombie'}) or something?

last latch
stray spoke
#

He's famous

#

Wow

last latch
#

i guess you could say that

stray spoke
#

Nice

broken pawn
#

even i begin to read his article recently but he haven't updsted it

stray spoke
#

I've seen many important identities here

#

Including zelisce

#

You're a former dev of a featured server right

last latch
#

but I wouldnt call myself important

broken pawn
#

is it any other way to get TypeFamily of entities whenever i use afterEvents.entityDie? cuz using getComponent resulting on failure due to entity getting removed

sage portal
broken pawn
#

nah, just a normal way

#

deadEntity.getComponent(EntityComponentTypes.TypeFamily)?.hasTypeFamily("undead")

#

the only question mark is on the end of getComponent

#

or is it caused by (deadEntity?.getComponent) placing question mark on deadEntity ?

sage portal
broken pawn
#

then no answer for this

but how to use array for execute (deadEntity.typeId)

stray spoke
#

Wym

broken pawn
#

using forEach

stray spoke
#

Is it an array of entity type Ids you want to make forEach loop

broken pawn
#

instead of using (deadEntity.typeId==""||deadEntity.typeId=="")

stray spoke
#

Oh

wary edge
stray spoke
#

Oh here's the boss

broken pawn
#

nice we got the boss

wary edge
#

If youre in the preview and can use beta.

stray spoke
#

Lol

broken pawn
broken pawn
#

i knew stirante.... he's the one who develop essentials addon

#

also my goat

stray spoke
# broken pawn instead of using (deadEntity.typeId==""||deadEntity.typeId=="")

My way would be like this:

const list = {
  zombie: zombieFunc,
  villager_v2: villagerFunc,
  wolf: wolfFunc
}

world.afterEvents.entityDie.subscribe(data=>{
  const {deadEntity: entity} = data;
  
  Object.keys(list).forEach(mob=>{
    if(entity.typeId === `minecraft:${mob}`){
      list[mob]()
    }
  })
})

function zombieFunc(){...}
function villagerFunc(){...}
function wolfFunc(){...}
#

But there's a cleaner and more concise way than this

stray spoke
#

Without even trying

broken pawn
#

my library.js will getting extra size after this

stray spoke
#

you can separate it

#

per js file

#

Using exports

broken pawn
#

yes, it used to store function and other array tho

stray spoke
#

Then why in one lib.js

#

i mean it's also good for some reason

broken pawn
#

for global use, once i have an addon idea, i'll just take it from there

stray spoke
#

Understandable

broken pawn
#

🗣️ 🔥 🔥

stray spoke
#

That's also efficient

#

But if it's a lot of code

#

Gotta separate it

#

For me in my opinion

broken pawn
#

everyone has it preference, i always like to make it compact

#

🤘

stray spoke
#

Yeah, Object type is my favorite

#

And classes

#

For grouping them

broken pawn
#

yes, anyway thanks for the knowledge, even thought i'm not a scripter, just for casual use for my realms

#

it do help a lot now

stray spoke
#

You should thank Smokey 🔥🔥🔥

broken pawn
#

🗣️ 🔥 🔥

still bolt
hoary matrix
#

someone know if it's possible to detect when an entity wear any armor ?

broken pawn
#

use EntityEquippableComponent

#

let A0 =Entity.getComponent(EntityEquippableComponent.componentId).getEquipment(EquipmenSlot.Head)

if(A0.hasTag(ArmorTag)){}else{}

#

it detects player Equipment

#

make sure which slot needs to be detected

#

if Chestplate, the .getEquipment(EquipmentSlot.Chest)

warm mason
hoary matrix
#

it will not work in a zombie ?

#

for testing it

stray spoke
#

I kinda made my own world edit with a bounding box display, I only have cmds like:
/wfill <blockId?> - if block is empty, it uses the block in mainhand, if not placeable or empty, places air instead
/offset <x> <y> <z> - moves the blocks from selected area
/config - just a form ui to configure settings such as showBoundingBox, showWarning, showLogs, boxColor {red, green, blue}
/wand - gives an axe item with dynamic property, sets 2 positions by breaking blocks
/pos1 - sets your current position as first position
/pos2 - sets your current position as second position

what else do I make

fallow minnow
#

why am i getting early execution errors???

wary edge
fallow minnow
#

its for my database but everything is imported properly or wrapped in a system.run

wary edge
#

What is IslandManager

fallow minnow
#

my island manager

subtle cove
fallow minnow
subtle cove
#

Does that run after early execution...

fallow minnow
#

uhhh

#

its just fetching dynamic properties

#

so i see why its erroring

#

but wrapping it in system.run or importing the file before system startup does nothing

#

i remember this error before but i forgot what i had to do

#

ah this

midnight crane
#

How do I use the script event command

subtle cove
fallow minnow
#

or that LMAO

#

yeah that works

subtle cove
#

U can also reassign anything on global any time

#

Not just on early execution

fallow minnow
#

good to know

subtle cove
#

If u want that to work, u can do new Promise since awaition is there

subtle cove
stray spoke
#

How to use StructureManager

wary edge
#

What are you trying to do?

stray spoke
#

I just have doubts that it might be wrong if I used it like structureManager.get(id) directly, it might have parents like world.structureManager or else

stray spoke
stray spoke
#

Thankss again

snow knoll
#

I'm making telekinesis
To do it, should I constantly teleport an entity to the offset of the player's body or should I use applyImpulse for smoother movement of the entity
Is the smooth movement worth the larger strain on performance?
Would the strain on performance be very high?

stray spoke
#

I suggest both impulse and orbiting the body, just different methods to use

#

Control Entity - right click
Apply Impulse - left click/hit

amber granite
#

Hey guys gotta be asking

#

Is ti possible to make door using script api

wary edge
#

Not really feasible.

amber granite
#

Sas i thought i saw someone make them

fleet stone
#

is there currently a bug, where the custom item components just dont work? i have my custom component in the components block in my custom item json but minecraft seems to have forgotten, custom item components are a thing and gives the error message "... this member was found in the input, but is not present in the Schema" i have even copied the exact code from https://learn.microsoft.com/en-us/minecraft/creator/documents/scripting/components-tutorial?view=minecraft-bedrock-stable&viewFallbackFrom=minecraft-bedrock-preview but it does not work 🙁

A walkthrough teaching you how to create custom components for Minecraft: Bedrock Edition.

hoary matrix
#

guys

hoary matrix
#
let fortuneLevel = 0;
    try {
        const heldItem = player.getComponent("equippable")?.getEquipment("mainhand");
        if (heldItem?.getComponent("enchantable")) {
            const ench = heldItem.getComponent("enchantable");
            fortuneLevel = ench.hasEnchantment("fortune") ? ench.getEnchantment("fortune").level : 0;
        }
    } catch (e) {}

    const fortuneBlocks = [
        "minecraft:diamond_ore",
        "minecraft:deepslate_diamond_ore",
        "minecraft:coal_ore",
        "minecraft:deepslate_coal_ore",
        "minecraft:emerald_ore",
        "minecraft:deepslate_emerald_ore",
        "minecraft:gold_ore",
        "minecraft:deepslate_gold_ore"
    ];

    let quantity = 1;
    if (dropItemId) {
        if (blockId.includes("lapis")) {
            quantity = 4 + Math.floor(Math.random() * 5);
            if (fortuneLevel > 0) quantity *= (fortuneLevel + 1);
        } else if (blockId.includes("redstone")) {
            quantity = 4 + Math.floor(Math.random() * (fortuneLevel + 2));
        } else if (blockId.includes("nether_gold_ore")) {
            quantity = 2 + Math.floor(Math.random() * 5);
            if (fortuneLevel > 0) quantity += Math.floor(Math.random() * (fortuneLevel * 2 + 1));
        } else if (fortuneLevel > 0 && fortuneBlocks.includes(blockId)) {
            quantity = 1 + Math.floor(Math.random() * (fortuneLevel + 1));
        }
        itemStack = new ItemStack(dropItemId, quantity);
    } else {
        itemStack = new ItemStack(blockId, 1);
    }
js
hoary matrix
#

yessir

hoary matrix
amber granite
#

@wary edge does Minecraft api support json comments ?

wary edge
amber granite
#

☠️ i don't know in which channel to put

#

Lol

#

But are
/* Comments */ works or they will break .json files ?

fallow minnow
#

if you want to make it to where they dont error just change the language model to jsonc

celest fable
#

how to get the container component of shulkerbox in its item form

I've tried item.getComponent("inventory") it can't, also when I tried item.getComponents().length it return 0

unique dragon
#

only blocks and entities

celest fable
wary edge
celest fable
alpine wave
#

Guys is this right

world.afterEvents.playerMove.subscribe

#

I making a slime block launch pad

jagged gazelle
alpine wave
#

@broken pawn then how do I make a slime block launch pad

#

Because I saw it in a world I was on

broken pawn
#

system.runInterval i guess? and how is it work?

alpine wave
#

It supposed to launch to any where the player is facing

#

Oh like if the player is facing forward it launches them forward

broken pawn
#

looks like using applyKnockback

broken pawn
#

pretty confusing isn't it?

alpine wave
#

@broken pawn is this right also

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

    if (!player || !block) return;
    if (block.typeId !== "minecraft:orange_shulker_box") return;

    giveStarterKit(player);
    player.sendMessage("§aStarter items received.");
});

/* ================================
   GIVE STARTER ITEMS
================================ */
function giveStarterKit(player) {
    const inv = player.getComponent("inventory").container;

    inv.addItem(new ItemStack(MinecraftItemTypes.leatherHelmet));
    inv.addItem(new ItemStack(MinecraftItemTypes.leatherChestplate));
    inv.addItem(new ItemStack(MinecraftItemTypes.leatherLeggings));
    inv.addItem(new ItemStack(MinecraftItemTypes.leatherBoots));

    inv.addItem(new ItemStack(MinecraftItemTypes.stoneSword));
    inv.addItem(new ItemStack(MinecraftItemTypes.stonePickaxe));
    inv.addItem(new ItemStack(MinecraftItemTypes.stoneAxe));
    inv.addItem(new ItemStack(MinecraftItemTypes.shield));

    inv.addItem(new ItemStack(MinecraftItemTypes.cookedBeef, 16));
    inv.addItem(new ItemStack(MinecraftItemTypes.oakPlanks, 32));
}
broken pawn
#

imma diagnose this

alpine wave
#

Ok

broken pawn
#

it should be work

#

why didn't you add a tag to make sure it'll never duped

#

if(player.hasTag(""))return;

alpine wave
#

And also how do I make a leaderboard floating text system that changed every 10 seconds, from kills, to deaths, to money

alpine wave
broken pawn
#

understandable

stray spoke
alpine wave
#

@broken pawn is the applyknockback right

world.afterEvents.playerInteract.subscribe((event) => {
    const player = event.player;
    const loc = player.location;

    // Check if the player interacts with a slime block
    const block = event.block;

    if (block.typeId === "minecraft:slime_block") {
        // Apply knockback when the player lands or jumps on a slime block
        player.applyKnockback(0, 0, 0, 1.2);
        player.sendMessage("§aYou were launched by the slime block!");
    }
});
#

I did what you said

broken pawn
broken pawn
#

then add filter

stray spoke
#

One of them doesn't work on Player type entity

#

I just forgot it

#

I mean the applyImpulse and applyKnockback

broken pawn
#

interesting

#

anyway, does multiple Object works normally?

stray spoke
#

They act the same but one of them is easier to handle where to land, the other one defines the position of source knockback

#

Wym

broken pawn
#
AE.entityDie.subscribe(({deadEntity:A})=>{try{
    Object.keys(Vanilla).forEach(B=>{if(A.typeId==`minecraft:${B}`){Vanilla[B]()}});
    Object.keys(EternalEnd).forEach(B=>{if(A.typeId==`panascais_end:${B}`){EternalEnd[B]()}});
}catch(Empty){}});
#

like that

stray spoke
#

You can put it on one forEach actually

broken pawn
#

how

stray spoke
#

Lemme try to code it wait

#

using else if to add another condition

broken pawn
#

ah yes the if else

stray spoke
#

I might have misunderstood

#

My apologies in advanced

broken pawn
#

no problem, we always have a mistaken action

stray spoke
#

The conditions are the same

stray spoke
broken pawn
#

yes like that

stray spoke
#

yes that'll work, like the code you gave

#

If it's the same Object, you can put it on one forEach loop

broken pawn
alpine wave
#

@broken pawn getting this error even know it's in there

[Scripting][error]-SyntaxError: Could not find export 'MinecraftItemTypes' in module '@minecraft/server'

[Scripting][error]-Plugin [GenPvP - 1.0.0] - [main.js] ran with error: [SyntaxError: Could not find export 'MinecraftItemTypes' in module '@minecraft/server']

#

Does it also need to be in manifest.json

broken pawn
#

i guess instead of using MinecraftItemTypes, just use string ""

#

"minecraft:leather_helmet"

alpine wave
#

Can you give the fixed code real quick

fallow minnow
#

how can i use the dyeable component?

broken pawn
#

spawnItem(new ItemStack("minecraft:dragon_egg",1),V3);

fallow minnow
#

does it have to be a custom item

broken pawn
alpine wave
#

Or give me a line

#

And I can fix it

#

Like this @broken pawn

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

    if (!player || !block) return;
    if (block.typeId !== "minecraft:orange_shulker_box") return;

    giveStarterKit(player);
    player.sendMessage("§aStarter items received.");
});

/* ================================
   GIVE STARTER ITEMS (using strings)
================================ */
function giveStarterKit(player) {
    const inv = player.getComponent("inventory").container;

    inv.addItem(new ItemStack("minecraft:leather_helmet"));
    inv.addItem(new ItemStack("minecraft:leather_chestplate"));
    inv.addItem(new ItemStack("minecraft:leather_leggings"));
    inv.addItem(new ItemStack("minecraft:leather_boots"));

    inv.addItem(new ItemStack("minecraft:stone_sword"));
    inv.addItem(new ItemStack("minecraft:stone_pickaxe"));
    inv.addItem(new ItemStack("minecraft:stone_axe"));
    inv.addItem(new ItemStack("minecraft:shield"));

    inv.addItem(new ItemStack("minecraft:cooked_beef", 16));
    inv.addItem(new ItemStack("minecraft:oak_planks", 32));
}
broken pawn
#

exactly

#
function giveStarterKit(player) {
    const inv = player.getComponent("inventory").container;

    inv.addItem(new ItemStack("minecraft:leather_helmet",1));
    inv.addItem(new ItemStack("minecraft:leather_boots",1));
    inv.addItem(new ItemStack("minecraft:leather_leggings",1));
    inv.addItem(new ItemStack("minecraft:leather_boots",1));

    inv.addItem(new ItemStack("minecraft:stone_sword",1));
    inv.addItem(new ItemStack("minecraft:stone_pickaxe",1));
    inv.addItem(new ItemStack("minecraft:stone_axe",1));
    inv.addItem(new ItemStack("minecraft:shield",1));

    inv.addItem(new ItemStack("minecraft:cooked_beef", 16));
    inv.addItem(new ItemStack("minecraft:oak_planks", 32));
}
alpine wave
#

@broken pawn got these errors

[Scripting][error]-TypeError: cannot read property 'subscribe' of undefined at <anonymous> (main.js:148)

[Scripting][error]-Plugin [GenPvP - 1.0.0] - [main.js] ran with error: [TypeError: cannot read property 'subscribe' of undefined at <anonymous> (main.js:148)
]

[Scripting][error]-TypeError: not a function at run (main.js:58)
at startSpawnCountdown (main.js:84)
at spawnCommand (main.js:45)

alpine wave
prisma shard
#

uh no man sorry

alpine wave
#

@broken pawn can you tell me what I need to fix

#

The subscribe one is this one

world.afterEvents.playerInteract.subscribe((event) => {
    const player = event.player;
    const loc = player.location;

    // Check if the player interacts with a slime block
    const block = event.block;

    if (block.typeId === "minecraft:slime_block") {
        // Apply knockback when the player lands or jumps on a slime block
        player.applyKnockback(0, 0, 0, 1.2);
        player.sendMessage("§aYou were launched by the slime block!");
    }
});
#

I pretty sure

#

Yep that the subscribe error one

#

For the spawn countdown error it's this one

function startSpawnCountdown(player) {
    let timeLeft = 5;
    let delay = 20;

    const run = () => {
        if (!player?.isValid()) return;

        player.dimension.spawnParticle(
            "minecraft:shriek_particle",
            player.location
        );

        if (timeLeft > 0) {
            player.sendMessage(`§bTeleporting in ${timeLeft}...`);
            timeLeft--;
            delay = Math.max(6, delay - 3);
            system.runTimeout(run, delay);
        } else {
            const customSpawnLocation = {
                x: 100,
                y: 70,
                z: 100
            };
            player.teleport(customSpawnLocation, {
                dimension: player.dimension,
                rotation: player.getRotation(),
            });
            player.sendMessage("§aTeleported to spawn.");
        }
    };

    run();
}
#

@broken pawn there I gave the code of the errors

#

Can you tell me what I need to fix or something

prisma shard
#

ok man

#

ill fix for u

alpine wave
#

I gave the full code it's the file

prisma shard
prisma shard
#

since the one currently is not a valid event

alpine wave
#

The slime block is a launch lad

#

Pad

prisma shard
#

player.applyKnockback(0, 0, 0, 1.2);
And this line is not valid either, That is old format of applyKnockback

#

verticalStrenght was uhh removed

alpine wave
#

What is the updated thing

#

I want a slime block launch pad

thorn flicker
prisma shard
#

im not sure

#

uh

thorn flicker
#

no.

#

lol

prisma shard
#

okay but i forgot

#

cant u just tell

#

lmao

thorn flicker
#

maybe dont suggest

prisma shard
#

oh alr

alpine wave
#

@thorn flicker can you give fix of ot

#

It

thorn flicker
prisma shard
#

Ohhhh its horizontalForceXZ in curly braces

alpine wave
#

@thorn flicker at least give the thing that needs to be fixed

#

Aka the fixed line

prisma shard
alpine wave
#

@thorn flicker it says your not replying but not to be rude or stuff I asking a question are you going give the fixed line?

thorn flicker
alpine wave
#

Just asking is it playerInteractWithBlock for launching

thorn flicker
alpine wave
#

Srry

thorn flicker
#

np

alpine wave
#

And also when I right click the shulker box the orange one with open the shulker chest menu and it doesn't actually right click and give me the starter items

thorn flicker
#

lol

#

ghost ping

jagged gazelle
thorn flicker
alpine wave
#

@thorn flicker [Scripting][error]-ReferenceError: Native function [Container::addItem] cannot be used in restricted execution. at giveStarterKit (main.js:182)
at <anonymous> (main.js:172)

#

Getting this error

jagged gazelle
#

holy tags...

alpine wave
#

And also the slime launch pad not working but I get no errors

thorn flicker
#

lmao

#

look above

jagged gazelle
alpine wave
#

[Scripting][error]-ReferenceError: Native function [Dimension::spawnParticle] cannot be used in restricted execution. at run (main.js:63)
at startSpawnCountdown (main.js:84)
at spawnCommand (main.js:45)

thorn flicker
stray spoke
alpine wave
#

Also this too

thorn flicker
stray spoke
#

Nice

thorn flicker
#

yeah

stray spoke
#

More efficient

jagged gazelle
#

especially the clear velocity

#

not very perfect but it works...

alpine wave
#

@stray spoke can you help me with the errors

thorn flicker
stray spoke
jagged gazelle
#

it's sometimes jumpy in my side lol

thorn flicker
jagged gazelle
#

probably because of the tick rate

thorn flicker
#

hm

alpine wave
#

For one thinge spawn particle thingy not working which .aming the whole tp cooldown and tp thing not work andfhe starter kit not working because of the add item I think and another the slime block launch pad not working but no erros

#

@stray spoke

jagged gazelle
#

Soo umm, quick question... did you read the basics of MC script api?

stray spoke
#

May you show me the code

thorn flicker
alpine wave
thorn flicker
alpine wave
#

@stray spoke there

#

Want me to send video of it

stray spoke
#

Sure, I'll analyze the code first

jagged gazelle
thorn flicker
stray spoke
#

I see

#

Oh wait

thorn flicker
#

and if they refuse to utilize it 🤷‍♂️

jagged gazelle
#

I'm gonna abuse the player swing start now

alpine wave
alpine wave
stray spoke
jagged gazelle
thorn flicker
#

thats what I meant to ask

jagged gazelle
#

spam the usage of that event lol, especially there's swing source

alpine wave
#

Or something

#

Is it fixed

#

Did you forget to fix a code

stray spoke
alpine wave
jagged gazelle
# stray spoke

privilege error at using beforeEvents, you're modifying the world before it happens, so it's not possible, you need to make it happen next tick, that's why you need to use system.run()

#

that's the problem the guy is facing awhile ago...

stray spoke
#

That's what I did

jagged gazelle
# stray spoke That's what I did
world.beforeEvents.playerInteractWithBlock.subscribe((event) => {
    const player = event.player;
    const block = event.block;

    if (!player || !block) return;
    if (block.typeId !== "minecraft:orange_shulker_box") return;

    giveStarterKit(player);
    player.sendMessage("§aStarter items received.");
});

/* ================================
   GIVE STARTER ITEMS (using strings)
================================ */
function giveStarterKit(player) {
    const inv = player.getComponent("inventory").container;

    inv.addItem(new ItemStack("minecraft:leather_helmet",1));
    inv.addItem(new ItemStack("minecraft:leather_boots",1));
    inv.addItem(new ItemStack("minecraft:leather_leggings",1));
    inv.addItem(new ItemStack("minecraft:leather_boots",1));

    inv.addItem(new ItemStack("minecraft:stone_sword",1));
    inv.addItem(new ItemStack("minecraft:stone_pickaxe",1));
    inv.addItem(new ItemStack("minecraft:stone_axe",1));
    inv.addItem(new ItemStack("minecraft:shield",1));

    inv.addItem(new ItemStack("minecraft:cooked_beef", 16));
    inv.addItem(new ItemStack("minecraft:oak_planks", 32));
}```
#

where?

stray spoke
#

There seems mistype on custom command registry also

#

In his code

alpine wave
#

@stray spoke the slime block launch pad doesn't work and also the starter kit gives items but no chestplate

jagged gazelle
#

kk mb

stray spoke
#

I was about to rename my file to send it again incase

stray spoke
alpine wave
#

There are no errors

stray spoke
#

Ohh

#

Alright

stray spoke
#
inv.addItem(new ItemStack("minecraft:leather_helmet",1));
    inv.addItem(new ItemStack("minecraft:leather_boots",1));
    inv.addItem(new ItemStack("minecraft:leather_leggings",1));
    inv.addItem(new ItemStack("minecraft:leather_boots",1));

    inv.addItem(new ItemStack("minecraft:stone_sword",1));
    inv.addItem(new ItemStack("minecraft:stone_pickaxe",1));
    inv.addItem(new ItemStack("minecraft:stone_axe",1));
    inv.addItem(new ItemStack("minecraft:shield",1));

    inv.addItem(new ItemStack("minecraft:cooked_beef", 16));
    inv.addItem(new ItemStack("minecraft:oak_planks", 32));

It's just this

alpine wave
#

Can you give the line and also give the fix to the slime block not launching

stray spoke
#

Too many requests but okay

jagged gazelle
#

atp just open a post

jagged gazelle
alpine wave
#

Bro I telling him to give lines

stray spoke
#

The correct id for slime block is "minecraft:slime"

#

That's why it doesn't work

alpine wave
#

Ok

stray spoke
#

Simply copy paste and edit the id

#

inv.addItem(new ItemStack("minecraft:leather_chestplate",1));

#

Like this

stray spoke
#

And then edit the slime_block to slime

#

Alright then

alpine wave
#

And I added chestplate

#

Is it leather_chestplate

stray spoke
#

Test and see

alpine wave
#

@stray spoke I tested the slime thing and it still not launching

#

@stray spoke will this work with slime block if I renamed few things

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

const PRESSURE_PLATES = [
"minecraft:stone_pressure_plate",
"minecraft:polished_blackstone_pressure_plate",
"minecraft:heavy_weighted_pressure_plate",
"minecraft:light_weighted_pressure_plate",
"minecraft:wooden_pressure_plate",
"minecraft:acacia_pressure_plate",
"minecraft:birch_pressure_plate",
"minecraft:cherry_pressure_plate",
"minecraft:crimson_pressure_plate",
"minecraft:dark_oak_pressure_plate",
"minecraft:jungle_pressure_plate",
"minecraft:mangrove_pressure_plate",
"minecraft:spruce_pressure_plate",
"minecraft:bamboo_pressure_plate",
"minecraft:warped_pressure_plate"
];

system.runInterval(() => {
for (const player of world.getAllPlayers()) {
const block = player.dimension.getBlock(player.location);
if (!block) continue;

if (PRESSURE_PLATES.includes(block.typeId)) {
    const direction = player.getViewDirection();
    player.applyKnockback({ x: direction.x * 8, z: direction.z * 8 }, 1);        
}

}
}, 1);

#

I found it on mcpedl

stray spoke
#

If that was your intent

alpine wave
#

Oh then I do I do it by stepping on it I do that much Abt scripting API

#

⁰Idk

#

@stray spoke can you give me at least a code line of kt

#

1 line

#

@stray spoke like this

system.runInterval(() => {
    for (const player of world.getAllPlayers()) {
        const loc = player.location;
        
        // Offset Y by -0.1 to detect the block the player is standing ON
        const blockBelow = player.dimension.getBlock({ 
            x: loc.x, 
            y: loc.y - 0.1, 
            z: loc.z 
        });

        if (blockBelow?.typeId === "minecraft:slime") {
            // Apply knockback (vertical launch)
            // x: 0, z: 0 ensures they go straight up
            // The second parameter is the horizontal force, the third is vertical
            player.applyKnockback(0, 0, 0, 1.2);
        }
    }
}, 1);
stray spoke
#

Yes but that would be repeating

alpine wave
#

So how do I remove repeating

stray spoke
#

Conditons

alpine wave
#

What about now @stray spoke okay I probably didn't need to ping you

system.runInterval(() => {
    for (const player of world.getAllPlayers()) {
        // CONDITION 1: Only trigger if the player is actually touching the ground
        if (!player.isOnGround) continue;

        const loc = player.location;
        const blockBelow = player.dimension.getBlock({ 
            x: loc.x, 
            y: loc.y - 0.1, 
            z: loc.z 
        });

        // CONDITION 2: Check if the block is slime
        if (blockBelow?.typeId === "minecraft:slime") {
            // Launch the player
            player.applyKnockback(0, 0, 0, 1.2);
            
            // Note: Because applyKnockback sends them into the air, 
            // 'isOnGround' immediately becomes false, stopping the loop.
        }
    }
}, 1);

And yes I used Gemini

#

But is it right

stray spoke
#

Why don't you test it first to see if it met your satisfaction

#

There's wrong syntax on applyKnockback

#

Changed it to something like this, like the old one

player.applyKnockback({x: 0, z: 0}, 1.2)
alpine wave
#

@stray spoke [Scripting][error]-TypeError: Incorrect number of arguments to function. Expected 2, received 4 at <anonymous> (main.js:169)

[Scripting][error]-TypeError: Incorrect number of arguments to function. Expected 2, received 4 at <anonymous> (main.js:169)

[Scripting][error]-TypeError: Incorrect number of arguments to function. Expected 2, received 4 at <anonymous> (main.js:169)

[Scripting][error]-TypeError: Incorrect number of arguments to function. Expected 2, received 4 at <anonymous> (main.js:169)

[Scripting][error]-TypeError: Incorrect number of arguments to function. Expected 2, received 4 at <anonymous> (main.js:169)

[Scripting][error]-TypeError: Incorrect number of arguments to function. Expected 2, received 4 at <anonymous> (main.js:169)

[Scripting][error]-TypeError: Incorrect number of arguments to function. Expected 2, received 4 at <anonymous> (main.js:169)

[Scripting][error]-TypeError: Incorrect number of arguments to function. Expected 2, received 4 at <anonymous> (main.js:169)

[Scripting][error]-TypeError: Incorrect number of arguments to function. Expected 2, received 4 at <anonymous> (main.js:169)

[Scripting][error]-TypeError: Incorrect number of arguments to function. Expected 2, received 4 at <anonymous> (main.js:169)

[Scripting][error]-TypeError: Incorrect number of arguments to function. Expected 2, received 4 at <anonymous> (main.js:169)

[Scripting][error]-TypeError: Incorrect number of arguments to function. Expected 2, received 4 at <anonymous> (main.js:169)

[Scripting][error]-TypeError: Incorrect number of arguments to function. Expected 2, received 4 at <anonymous> (main.js:169)

[Scripting][error]-TypeError: Incorrect number of arguments to function. Expected 2, received 4 at <anonymous> (main.js:169)

[Scripting][error]-TypeError: Incorrect number of arguments to function. Expected 2, received 4 at <anonymous> (main.js:169)

#

Is that error the knock back

alpine wave
#

No I doing it now

#

Do I need ; on it

#

At the end of it

stray spoke
#

That's optinal

alpine wave
#

Ok

stray spoke
#

It stil works without semi colon in the end

alpine wave
#

It doesn't lauch me forward only upward @stray spoke

jagged gazelle
#

u need to use the player's view direction to launch based on the direction they're facing

alpine wave
#

Like this

system.runInterval(() => {
    for (const player of world.getAllPlayers()) {
        // Condition: Only trigger if the player is actually touching the ground
        if (!player.isOnGround) continue;

        const loc = player.location;
        const blockBelow = player.dimension.getBlock({ 
            x: loc.x, 
            y: loc.y - 0.1, 
            z: loc.z 
        });

        // Condition: Check if the block directly beneath them is slime
        if (blockBelow?.typeId === "minecraft:slime") {
            // 1. Get the direction the player is looking
            const viewDir = player.getViewDirection();
            
            /**
             * applyKnockback parameters:
             * directionX: viewDir.x
             * directionZ: viewDir.z
             * horizontalForce: 1.5 (Adjust this for forward speed)
             * verticalForce: 0.8   (Adjust this for height)
             */
            player.applyKnockback(viewDir.x, viewDir.z, 1.5, 0.8);
        }
    }
}, 1);

#

Be honest Gemini probably wrong

#

@stray spoke got this error of that [Scripting][error]-TypeError: Incorrect number of arguments to function. Expected 2, received 4 at <anonymous> (main.js:178)

#

Or @jagged gazelle

#

Yooo I fixed it

#

It works

sudden nest
#

halo have anyone used getEntitiesFromRay? it doesn't seem to do anything similar to getBlockFromRay.

#

const raycast = dimension.getEntitiesFromRay(block.location, {x: 0, y: 1, z: 0}, {maxDistance:5})[0];

i am expecting to detect the entity above it

#

i mean there's volume option from getEntities, was just trying this one

alpine wave
#

@stray spoke is it possible to make a custom scoreboard in the top right corner of your screen

sudden nest
fleet stone
wary edge
sudden nest
#

Anyone encountered creating a custom block that has a "onTick" Component, then placing that custom block using world generation single block placement, which doesn't trigger the onTick, only the randomTick.

#

Tried using 2 permutations with different timer loop interval upon interacting, still doesn't activate the onTick.

Although, if i just place it normally or using setBlock it works perfectly fine.

sudden nest
#

Oh, well.. bao_mob_fox_sleep

#

How does randomTick works from block component? Is it based on interval declared from the block.json?

wary edge
#
Minecraft Wiki

Nearly all video games (including Minecraft) are driven by one big program loop. Just as every gear in a clock is synchronized with the pendulum, every task involved in advancing a game simulation is synchronized with the game loop. Appropriately, one cycle of the game loop is called a tick.

sudden nest
#

What's the range of randomTick?

wary edge
#

Read the article I sent

#

It's based on random ticking per chunk, just like vanilla blocks.

sudden nest
jagged gazelle
weary umbra
midnight crane
#

Is there a new way to do gui's because I did my usual thing and it didn't work

world.afterEvents.itemUse.subscribe(async (data) => {
   const player = data.source;
    if (data.itemStack.typeId === 'minecraft:apple') {
            await test(player);
    }
})

function test(player) {
    const menu = new ActionFormData()
        .title("title")
        .button("1")
        .button("2")
        .button("3");

    menu.show(player).then(result => {
        if (result.canceled) return;

        switch (result.selection) {
            case 0:
                // response for first button 
                break;
            case 1:
                                // response for second button 
                break;
            case 2:
                // response for third button 
                break;
        }
    });
}
jagged gazelle
#

playerSwingStart is so fuckin fun to use...

midnight crane
last latch
jagged gazelle
jagged gazelle
midnight crane
jagged gazelle
#

there's a swing source, if it's an attack, build, drop

last latch
#

afterEvent only?

jagged gazelle
jagged gazelle
last latch
jagged gazelle
jagged gazelle
#

there's also detecting pickup...

last latch
#

yeah. that is something i picked up lmao

jagged gazelle
#

or just check the changelogs lol

last latch
#

i see they started to add something useful finally

amber granite
#

Thx

#

@jagged gazelle are you still in need for a way to detect if item is charged or not ?

jagged gazelle
empty yoke
#

But will addComponent() ever be added for entities?

fleet stone
#

what exactly is the difference between the BlockCustomComponents "onRandomTick" and "onTick" ? like are there tow types of ticks? or am i dumb? i dont get it

amber granite
jagged gazelle
snow knoll
#

Is a runInterval better for performance than a behaviour animation/behaviour animation controller?
Or vice versa?

open urchin
broken pawn
#

so many events occurred here lmao

broken pawn
#

runInterval is fixed while behavior animation triggers when something actived (assuming like world.afterEvents)

snow knoll
#

Ah

#

What I want to do is setRotation on an entity constantly until it dies or stops riding the player it's on
What would you suggest

broken pawn
#

i have no experience about it, waiting for someone to answer then

#

🗣️ 🔥 🔥

hoary matrix
#

hi guys is it possible to read enchantment by using beforeEvents.playerBreakBlock

#

?

thorn flicker
thorn flicker
hoary matrix
thorn flicker
hoary matrix
#

W but how bc i made a script to read an enchantment but it detect nothing

warm plume
#

Hi bro i want to make my table and entity spawn entity when the block place and it disappears when the block breaks

hoary matrix
#

and kill the entity ?

hoary matrix
warm plume
#

Can you give me example about it

hoary matrix
#

i dont have exemple sry

amber granite
hoary matrix
hoary matrix
#

smokey said me to put in i

thorn flicker
#

what

hoary matrix
#

wait

#

its a part of the script

#

i can't copy the full script

#

world.beforeEvents.playerBreakBlock.subscribe(ev => {

wary edge
hoary matrix
#

how ?

#

idk how to do this

last latch
hoary matrix
#

oh

#

yh thx

jagged gazelle
amber granite
#

Oh

jagged gazelle
#

where do u use this??

jagged gazelle
#

Oh sorry, I put the wrong question lol... It supposed to be how...

#

I get the keyframes already, except the linear spline and catmullrom spline

#

Idk how to put that in the first param...

wary edge
jagged gazelle
#

oh, done...

#

I made it work now

#

ohh I forgot how to do this but how do I transfer value from animation to client entity...

celest fable
#

can I get the command feedback message from "runCommand" method?

empty yoke
#

When I use getTopmostBlock() in the nether it always spawns above the bedrock, is this normal?

celest fable
empty yoke
wary edge
empty yoke
#

But why doesn't tryTeleport still teleport me even if there are blocks?

wary edge
empty yoke
wary edge
wary edge
wary edge
#

Or are you trying to find the highest air pocket

empty yoke
wary edge
# empty yoke

Set it to false then. If it's true it will fail because it intersects with a block.

empty yoke
wary edge
last latch
empty yoke
wary edge
#

checkForBlocks = true means it will check for blocks, if there is a block ot wont teleport you. But you asked #1067535608660107284 message so I responded with setting that option to false.

empty yoke
#

How do I find the valid position, if I can't check the blocks, should I check it when the player enters the dimension?

wary edge
empty yoke
wary edge
#

Ticking Area manager has no limit beyond the 255 chunks as far as I know.

fleet stone
#

does someone know, if it is possible to delete an items lore? because setting it to nothing or null just creates a blank line as the lore, but does not remove it completely to look like items without a lore. and there are no methods like resetLore or clearLore. after I have used the ContainerSlot.setLore() ones on an item, the extra line seems to be unremovable

remote oyster
empty yoke
# wary edge Ticking Area manager has no limit beyond the 255 chunks as far as I know.

I'm using the ticking area system, but I'm having a problem with it. You have to wait at least 20 ticks to use the chunk check functions to find the first valid position. This could break the ticking area removal if the world is closed during the 20 ticks. So I'm wondering, should I save the ticking area names in a property so that if they aren't removed, when the next player uses the ability, it retrieves the ids in the property and removes them before creating the new ticking area?

empty yoke
small depot
#

You need beta api

#

You can load up to 300 chunks

#

And if the world or server is closed they get automatically removed

#

But you should use await, because it returns a promise

#

So it’s not instantly loaded, you have to wait some ticks

empty yoke
#

I understand, the system is fantastic but I would need the beta version which I can't use, can you tell me why it takes 20 ticks to load the tickingarea?

cinder shadow
#

Wondering why we just have a generalized "onUse" for custom components and not an onStart/Stop use

cinder shadow
#

this will only work for consumable items

wary edge
#

There is also onConsume

#

It's for shooter and spears likely.

cinder shadow
wary edge
#

But I reckon the default use duration is 1 tick and therefore done.

wary edge
#

The shooter component has a charged property and spears have a use duration

cinder shadow
#

It won't fire for bows or spears

#

Mojang designs them with very high use_duration values

cinder shadow
wary edge
#

Very different docs.

wary edge
#

It is possible to have an item with low use_duration but no food

cinder shadow
#

Well yeah, but both of these fire for pretty much the same things

wary edge
#

Have you tested with the spear?

cinder shadow
#

I have custom spears fully implemented, they don't actually need any sort of scripting to function properly

#

The only reason scripting is needed for bows/crossbows is because they are completely broken

#

I could test later, but I was more so trying to see if I could move any of my custom bow stuff outside of the native event listeners

amber granite
#

Is Date class is available in script api ?

tidal wasp
#

Is there any character limit for dynamic entity properties

#

Actually I have a much better idea for that

#

Im currently trying to make a block copier item and the only things Id need is how would I get the item to know many many states it would need to use

wary edge
tidal wasp
#

But the issue still arises of how tf do I set the right amount of permutations and which ones to set

wary edge
#

What do you mean?

#

Can this item store numerous blocks or one at a time?

tidal wasp
#

1 block at a time

wary edge
#

So what's the issue?

tidal wasp
#

You'd set the block by shift interacting with the block

wary edge
#

Store the permutation into a JSON object, stringify it, then when you're copying it, parse the JSON and set the permutation to it.

tidal wasp
#

Id have to get to my laptop and see what you are saying im unfamiliar with this kinda stuff

#

I can kinda see it tho

tidal wasp
#

Yeah I get it

#

Actually putting into motion would be a different problem entirely

#

The depth of my Javascript expertise is if else and switch case

prisma shard
#

Guys suggest me something fun I can do with scripting

subtle cove
#

script using translate a lot

prisma shard
#

uh

#

How to make cutscenes using camera animations?

#

okay so basically runTimeout spam...

granite cape
#
import { world } from "@minecraft/server";

const HelloWorld = new class {
  constructor() {
    this[Symbol.toPrimitive] = () => "Hello World";
  }
};

world.afterEvents.playerSpawn.subscribe(
  ({ initialSpawn: stp, player: user }) =>
    stp && user.sendMessage(+HelloWorld)
);

wow this syntax is work

slow walrus
#

that's cursed

honest spear
#

well this is also cursed

const isntance = new class extends function (){} {
  if(object) {
    this.object = object;
  }
};
subtle cove
alpine wave
#

Is this right guys

// 2. Left-Click (Attacking/Hitting)
world.afterEvents.entityHitEntity.subscribe((event) => {
    const { damagingEntity, hitEntity } = event;
    
    // Check if the attacker is a player and the target is the shopkeeper
    if (damagingEntity.typeId === "minecraft:player" && hitEntity.typeId === "shop:shop_keeper") {
        const player = damagingEntity;
        
        // Use system.run to handle the UI safely outside the physics event
        system.run(() => showMainMenu(player));
    }
});
#

Is it entityhitentity

supple perch
#

anyone know the order of events of the world's playerLeave after event and the system's shutdown before event?

supple perch
#

i can't test rn so if anyone knows the answer, thanks!

stray spoke
#

But yeah that's more safe, just to lessen the code you can remove it

whole pulsar
#

I use herobrines chest ui and i havent played since 4 month now i just started playing again and the textures are bugged 4 month ago the textures worked fine does someone know why the textures are bugged?

#

some textures show but most of them dont

last latch
#

but there have been made like 10 forks that "should" work

whole pulsar
last latch
whole pulsar
last latch
#

no idea which one works

#

probalby the newest one does

whole pulsar
#

isnt this a fork

last latch
#

But thats my guess haha

whole pulsar
#

okay hahahhaha nice guess

last latch
#

and it seems like mine is more optimized (less elements and bindings)

whole pulsar
last latch
#

Like you dont have only 5, 9, 18, 27, etc slots, you can type how many you want

#

although I havent yet released it but I am planning on doing it

dapper copper
#

i just found out about server-graphics module, can someone tell me what this is for exactly?
i assume material stuff or some defferred rendering but idk

whole pulsar
slow walrus
last latch
slow walrus
#

the main repo is like the main road, then the "forks" are roads that go off it in another direction

whole pulsar
last latch
slow walrus
#

and sometimes that fork can lead back into the main road, which in the git/source control context would be a pull request

whole pulsar
last latch
gaunt salmonBOT
last latch
#

If someone really needs this and wants my version I could add this

whole pulsar
empty yoke
#

Can anyone explain why it doesn't load chunks even though the ticking area has been added?

#

sometimes it loads immediately other times it doesn't even take 2 seconds, how exactly does the tickingarea work it doesn't load instantly as soon as the command is used?

#

But I don't understand why it is added to the list if the chunk is not loaded yet

honest spear
last latch
last latch
#

basically what the herobrine does but a little better (havent shown the "invisible slot" becuz refuses to work for some reason will fix this now)

whole pulsar
last latch
#

yes

whole pulsar
#

does ur pack support custom items?

last latch
#

and amount is a string so you can set anything aslong as it is 3 characters

last latch
#

good idea to add

whole pulsar
last latch
#

dayum 💀

last latch
midnight ridge
last latch
#

❤️

iron apex
#

Hi everyone! I have a question. Can I create code that will detect if a player places an X block on the edge of any block (say, the up and down edges), then that block will change to a Y block while preserving all the states of the X block?

whole pulsar
#

how to fix this custom command issue i as the owner can do the custom command but normal players cant 4 month ago it worked also for normal players

whole pulsar
last latch
#

havent touched custom commands yet

granite cape
midnight ridge
#

i changed to prefix because of this problem

whole pulsar
#

thats crazy

last latch
#

they dont care about players, they care about money

whole pulsar
midnight ridge
whole pulsar
#

oh you changed back to !