#Script API General

1 messages · Page 6 of 1

glacial widget
#

thanks for letting me know

amber granite
#

Item.nameTag = "idk"

glacial widget
#

also how do i define player cuz i tried with player = world.getallplayers

tiny fable
#

Didn't knew it's that simple, lol

amber granite
#

It is

tiny fable
#

thanks :)

amber granite
#

Uw

glacial widget
# tiny fable thanks :)
system.runInterval(() =>{
for(const player of world.getAllPlayers()){
  const inventory = player.getComponent("inventory").container
  const item = inventory.getItem("")
  const rename = item.nameTag("idk")
}
})

here, but someone correct me if am wrong

amber granite
#

Kinda

#

It s correct

tiny tartan
#

one thing you forgot that you have to setItem after modifying itemStack

amber granite
#

Wait no it s not

#

nameTag is not a function

tiny fable
amber granite
#
  • nameTag is not a function
tiny fable
glacial widget
#
import { world, system, Player, ItemStack, EquipmentSlot, World, } from '@minecraft/server';
import { ActionFormData, MessageFormData, ModalFormData } from "@minecraft/server-ui"; 

world.afterEvents.itemUse.subscribe((i) =>{
  let player = i.source
  const itemStack = i.itemStack
  if (itemStack.typeId == "minecraft:heart_of_the_sea") main(player)
})
const player = world.getAllPlayers()
function main() {
  const form = new ActionFormData()
  .title("§l§dModration Menu§r")
  .body("                  §l§aby Maxis")
  .button("§lkick")
  .button("§lwarn")
  .button("§lmute")
  .button(`§cExit Menu`);
form.show(player).then(r => {
    if (r.selection == 0) kick(player)
    if (r.selection == 1) warn(player)
    if (r.selection == 2) mute(player)
})
}

function kick() {
new ModalFormData()
.title("Kick Menu")
.textField("", "Reason for Kick")
.dropdown("Pick a member", player.map(player => player.name), 2)
.submitButton("done")
.show(player).then(r =>{
let input = r.formValues[0]

if (input) {
  player.sendMessage(`${player.name} Has kicked a player for ${input}`); 
} else {
  player.sendMessage(`${player.name} Has kicked a player for no reason.`);
}
})  
}

function warn() {
new ModalFormData()
.title("")
.textField("", "Reason for warn" )
.dropdown("Pick a player to warn", player.map(player => player.name), 2)
.submitButton("done")
.show(player).then(r =>{
let input = r.formValues[0]

if (input) { 
  player.sendMessage(`${player.name} Has warned a player for ${input}`); 
} else {
  player.sendMessage(`${player.name} Has warned a player for no reason.`);
}
})
}

function mute() {
new ModalFormData()
.title("")
.textField("", "Reason for mute")
.dropdown("Pick a mute", player.map(player => player.name), 2)
.submitButton("done")
.show(player).then(r =>{
let input = r.formValues[0]
if (input) { 
  player.sendMessage(`${player.name} Has warned a player for ${input}`); 
} else {
  player.sendMessage(`${player.name} Has warned a player for no reason.`);
}
})
}

Could someone help me define player

tiny tartan
#

give it param

glacial widget
amber granite
#

mute

#

Function

#

Instead of mute()

glacial widget
amber granite
#

Put mute(player)

#

player is a parameter

#

In all the three ones

#

Add player as Parameter in them

glacial widget
amber granite
#

hmm

tiny fable
amber granite
#

Yes it must be

function kick(player)
{}
tiny fable
glacial widget
amber granite
#

Brother

#

Make if (!player) return
Won't make any difference

tiny tartan
glacial widget
# amber granite Yes it must be ```js function kick(player) {} ```
function kick(player) {
new ModalFormData(player)
.title("Kick Menu")
.textField("", "Reason for Kick")
.dropdown("Pick a member", player.map(player => player.name), 2)
.submitButton("done")
.show(player).then(r =>{
let input = r.formValues[0]

if (input) {
  player.sendMessage(`${player.name} Has kicked a player for ${input}`); 
} else {
  player.sendMessage(`${player.name} Has kicked a player for no reason.`);
}
})  
}
#

like this right?

tiny tartan
#

yup

amber granite
#

That s all

#

Do the same with main

glacial widget
#

i still get errors

amber granite
#

And warn and the others

amber granite
glacial widget
#

i forgot to add the (player) to mute

#

my bad yall, am being a fofo dumbieformally_pumpkin

tiny tartan
#

and remove const player = world.getAllPlayer() cuz that will return array

amber granite
#

Yes u should

#

Put foreEach method

tiny fable
#
world.afterEvents.itemUse.subscribe((i) =>{
  let player = i.source
  const itemStack = i.itemStack
  if (itemStack.typeId == "minecraft:heart_of_the_sea") main(player)
})
const allPlayer = world.getAllPlayers()
// ^ Rename this to avoid confusion
function main(player) {
  const form = new ActionFormData()
  .title("§l§dModration Menu§r")
  .body("                  §l§aby Maxis")
  .button("§lkick")
  .button("§lwarn")
  .button("§lmute")
  .button(`§cExit Menu`);
  form.show(player).then(r => {
    if (r.selection == 0) kick(player)
    if (r.selection == 1) warn(player)
    if (r.selection == 2) mute(player)
})
}

function kick(player) {
  new ModalFormData()
  .title("Kick Menu")
  .textField("", "Reason for Kick")
  .dropdown("Pick a member", allPlayer.map(player => player.name), 2)
  .submitButton("done")
  .show(player).then(r =>{
    let input = r.formValues[0]

    if (input) {
      player.sendMessage(`${player.name} Has kicked a player for ${input}`); 
    } else {
      player.sendMessage(`${player.name} Has kicked a player for no reason.`);
    }
  })  
}

function warn(player) {
  new ModalFormData()
  .title("")
  .textField("", "Reason for warn" )
  .dropdown("Pick a player to warn", allPlayer.map(player => player.name), 2)
  .submitButton("done")
  .show(player).then(r =>{
    let input = r.formValues[0]
  
    if (input) { 
      player.sendMessage(`${player.name} Has warned a player for ${input}`); 
    } else {
      player.sendMessage(`${player.name} Has warned a player for no reason.`);
    }
  })
}

function mute(player) {
new ModalFormData()
.title("")
.textField("", "Reason for mute")
.dropdown("Pick a mute", allPlayer.map(player => player.name), 2)
.submitButton("done")
.show(player).then(r =>{
let input = r.formValues[0]
if (input) { 
  player.sendMessage(`${player.name} Has warned a player for ${input}`); 
} else {
  player.sendMessage(`${player.name} Has warned a player for no reason.`);
}
})
}
amber granite
#

If u won't to iterate through all the players

tiny fable
amber granite
#

Wait

#

Yeah changing player const won't make difference too !

#

Remove it from the script

#

Remove :

const player

Unless u need it , rename it

glacial widget
#

does anyone know how to fix?

amber granite
#

It s a problem with ModalForm

glacial widget
amber granite
#

First did u apply the changes ?

glacial widget
#

when i debug there are no errors

turbid oriole
#

Hello family. I've learned a lot lately about the Minecraft+Javascript execution flow. It's very strange but interesting.

#

I didn't know that there were equal events for pre-world modification and post-world modification. Even the callback function argument refers to properties that refer to different things.

#

I did not imagine that the same structure could refer to two different states of a coordinate. Pre and post.

#

:3 and very interesting how each flow is associated with each tick. And how a tick function is executed from a local scope and has no lift.

neat hound
grand heart
#

is it possible to get itemStack inside a shulker box itemStack??

#

(shulker box in inventory/not placed)

knotty plaza
#

Nope

turbid oriole
#

I have an anomalous behavior, when I place a block and remove a block periodically for some reason the block that is placed is the one in the position of the one that was removed, in this case ai air. Do you know if it's a bug?

#

The drop methods are both inside an instantiated object.

knotty plaza
#

Check the permutationBeingPlaced property in that case

turbid oriole
turbid oriole
#

I was already able to summarize the anomalous behavior: it places a block in one position but extracts it from another position from which it should not.

#

But I don't understand exactly why it happens. If you like, I'll give you the code. A small part.

knotty plaza
#

Ok lets check it out

turbid oriole
#

Wait, I'll transcribe it.

#
class Head {
    constructor(blockGen, blockGrow, direction){
        super(blockGen.location);
        this.blockGenerator = blockGen;
    }
    
    placeBlock(){
        mundo.setBlockType(this.location, this.blockGenerator.typeId);
    }
    
    forward(){
        this.placeBlock();
        this.tail.destroyBlock();
    }
}
#

Something like that.

#

To avoid complications, I didn't put the tail and all that.

knotty plaza
#

How are you getting this.location?

#

Wait, I think I know how

turbid oriole
#

:'v tail has its own position, also head. But head does strange things: it takes the block at the position of the blockGen (block that had the coordinate that was assigned to head) and places it in the place where I should place the block that was.... Wait, I see something.

turbid oriole
knotty plaza
#

Yeah... I'm not understanding well what you are saying, but I might have an idea of whats happening

turbid oriole
#

Wait, I see what blockGen was in the beginning.

#

Oh, I thought I already saw the error. Confirm if it's true:

#

When do I run the event after the player place. Block calls the callback function and returns an event element from its arguments, correct? Well, that object has a "block" attribute. No?

#

I just realized something. It behaves dynamically I think.

knotty plaza
#

Most of the Block class properties are getters

turbid oriole
#

If I call a function that is executed every 2 ticks within the callback, it changes the block values.

knotty plaza
#

They will return the current value every time you call them

turbid oriole
#

Here when creating the object you assigned the e.block, see? Maybe it is the Failure

turbid oriole
#

I'm back, you were right, the block methods are getters and will give the current state. Bug fixed.

#

:v How did you duplicate objects to unbind them from the server's hands? XD

#

While you help me I will see with Object.assign();

knotty plaza
#

You can do this```js
const info = {
typeId: block.typeId,
location: block.location,
permutation: block.permutation,
}

turbid oriole
#

I can't create an object from Minecraft classes? How does an object like that look? What default values do you have?

knotty plaza
#

What?

tiny fable
#

Hello guys! another question
is it possible to give items an enchanting glint through scripts?

knotty plaza
#

No, next question

tiny fable
#

alright then

turbid oriole
#

To execute it I can devise many ways, although the important thing is to know if we can execute commands from the Script, it would be the most comfortable ways.

tiny fable
#

sure

knotty plaza
#

Not sure if saving the item in a mcstructure and editing the NBT would work

#

Not sure if thats a property that can be edited trought NBT

turbid oriole
turbid oriole
#

Does anyone know how I can override this behavior? I'll be investigating.

knotty plaza
#

And not every item is enchantable

turbid oriole
knotty plaza
#

Thats what I said

turbid oriole
#

Although I think I know an esoteric method.

drifting cobalt
#

guys how to use / on script, i mean like runCommandAsync(`function/a/b/c`)

turbid oriole
#

/

#

\

drifting cobalt
#

?

#

\

turbid oriole
#
\/
drifting cobalt
#

okayy thanks

turbid oriole
#

It is a special character for strings in Javascript.

drifting cobalt
#

function\/a\/b\/c

#

like this?

turbid oriole
#

Mdn Mozilla.

drifting cobalt
#

ok just \

turbid oriole
turbid oriole
drifting cobalt
#

okay thanks

turbid oriole
#

Why do you use ` ? Xd

knotty plaza
#

Whats the problem?

drifting cobalt
#

[Scripting][error]-Unhandled promise rejection: CommandError: Syntax error: Unexpected "/": at "oad abc:de>>/<<miaw"

drifting cobalt
knotty plaza
#

I get it, try with runCommand('function "a/b/c"')

turbid oriole
#

:b

drifting cobalt
turbid oriole
#

What is the syntax of the function command? I forgot her.

#

XD Are you seriously asking for a string?

drifting cobalt
#

nvm

turbid oriole
drifting cobalt
#

player.runCommandAsync(`structure load ${selectedStructure}`) what abt this

knotty plaza
turbid oriole
drifting cobalt
#
const selectedStructure= [
    "abc:ab/miaw"
]
turbid oriole
#

I spoke well, stupid.

drifting cobalt
#

XD

turbid oriole
knotty plaza
turbid oriole
#

I'll go solve my linking problem

knotty plaza
#

This does work completely fine for me

drifting cobalt
#

const structures = [
    "abc:ab/miaw0",
    "abc:ab/miaw1",
    "abc:ab/miaw2"
];
selectedStructure = structures[Math.floor(Math.random() * structures.length)];
player.runCommandAsync(`structure load ${selectedStructure[0]} ${block.location.x - 2} ${block.location.y} ${block.location.z - 2} 0_degrees none true true true`);
knotty plaza
#

Try with mystructure: instead of abc:

drifting cobalt
turbid oriole
knotty plaza
drifting cobalt
#

nvm idk now its working

#

thanks guys

turbid oriole
drifting cobalt
#

"${selectedStructure}"

turbid oriole
#

Better wait, I'll check the documentation. To see the command.

knotty plaza
drifting cobalt
#

yes, i forgot the " "

#

XD

turbid oriole
#

Oh no.

turbid oriole
drifting cobalt
turbid oriole
#

@knotty plaza You're right, I'll have to extract the data from the object: what a shame.

stiff ginkgo
#

bao_panda_blankbao_panda_blankbao_panda_blankbao_panda_blankbao_panda_blankbao_panda_blankbao_panda_blankbao_panda_blank
how to use .setProperty?
bao_panda_flipbao_panda_flipbao_panda_flipbao_panda_flipbao_panda_flipbao_panda_flipbao_panda_flipbao_panda_flip

knotty plaza
#

This is from the bee json file```json
"minecraft:entity": {
"description": {
"identifier": "minecraft:bee",
"is_spawnable": true,
"is_summonable": true,
"is_experimental": false,
"properties": {
"minecraft:has_nectar": {
"type": "bool",
"client_sync": true,
"default": "query.had_component_group('has_nectar')"
}
}
}

#

You have to set the property first

#

Then you can change it from the script

stiff ginkgo
#

thank but how to use it in script? bao_panda_flip

#

like this?

knotty plaza
#

entity.setProperty('key', 1 /* The value */)

abstract cave
#
import { Player, world } from "@minecraft/server";

world.afterEvents.entityHurt.subscribe(eventData => {
    const player = eventData.damagingEntity;
    const entity = eventData.hurtEntity;

    if (player.typeId === "minecraft:player") {
        player.runCommand("say hi");
    }

});```
why does this^ give me this error

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

distant tulip
wary edge
distant tulip
#

he is using damagingEntity directly
and that's not a property for the eventData

wary edge
#

People should really read the docs

distant tulip
#

yeah

fading sand
#

anyone know what this means?:

#
libc++abi: terminating due to uncaught exception of type std::length_error: vector
[2024-07-26 12:40:18:872 INFO] Package: com.mojang.minecraft.dedicatedserver
Version: 1.21.2.02
OS: Linux
Server start: 2024-07-26 12:40:07 UTC
Dmp timestamp: 2024-07-26 12:40:18 UTC
Upload Date: 2024-07-26 12:40:18 UTC
Session ID: ca141809-bf5e-41a3-879d-ed8414f4a216
Commit hash: 50d69ddfd20afc969dbcb5826bbf80368ebf9044
Build id: 25836814
CrashReporter Key: 8c4937c1-64cb-3532-a8dc-1deb28f67293
Crash
[2024-07-26 12:40:18:872 INFO]  at gsignal (UnknownFile:?)
        at abort (UnknownFile:?)
        at __clone (UnknownFile:?)
a9e9ee6a-6834-47f0-adcb-bcfb1a747922
container@pterodactyl~ Server marked as offline...
[Pterodactyl Daemon]: ---------- Detected server process in a crashed state! ----------
[Pterodactyl Daemon]: Exit code: 1
[Pterodactyl Daemon]: Out of memory: false
[Pterodactyl Daemon]: Aborting automatic restart, last crash occurred less than 60 seconds ago.
#

i just used my addon on my server and after some time the server keeps crashing with this message

halcyon phoenix
#

you are accessing damagingEntity through damageSource

abstract cave
wary edge
#

:/

#

You literally had it

#

And I told you damageSource isnt an entity but an EntityDamageSource

abstract cave
wary edge
#

You had it right, but its not an entity its a EntityDamageSource

abstract cave
#

how to I get the player who hit the entity

wary edge
#

@abstract cave :/ i already told you

#

Since it isnt an entity, its a EntityDamageSource. Youll need to get the objects properties

fading sand
#

Also crashed my singleplayer world..

wary edge
#

Open a post then?

halcyon phoenix
#

check Dms @abstract cave

abstract cave
nimble schooner
#

Why am I unable to import BlockAreaSize?

#

(from „@minecraft/server“)

halcyon phoenix
nimble schooner
#

For blockareas

#

To test for entities within them

halcyon phoenix
#

can you send me docs? sounds interesting

nimble schooner
#
  1. I don‘t have the docs
  2. It doesn‘t work that‘s why I‘m asking for help
somber onyx
cold grove
fast lark
#

how can i tp some one in a specific dimension?

inland merlin
#

Does preview some some sorta inventory event?

#

I'm looking for docs

nimble schooner
#

Why am I unable to import BlockAreaSize from „@minecraft/server“?

inland merlin
#

Your using

amber granite
#

Yes

nimble schooner
nimble schooner
#

Alright ty

misty pivot
#

is there a similar event like onRandomTick from block custom components? basically i wanna make vanilla crops die randomly when the player isn't near

misty pivot
#

oh so like, it's not possible to do so aswell?

distant gulch
#

Why is is the net module only for BDS ?

wary edge
distant gulch
distant gulch
# wary edge Sure

i want to manipulate the player properties by using this

    Object.defineProperty(Player, "isStaff", {
        enumerable: true,
        configurable: false,
        writable: true,
        get: function() {
    
        },
        set: function(state) {
    
        }
    });
#

is this how it works?

#

(because i want to make my own anti cheat and i need some methods i can call quickly)

valid ice
#

Yeah, you can do that

#

There's also value(params) for if you want it to be a method and not a property

distant gulch
#

okay nice ty

valid ice
#

I do soomething like this here:

Object.defineProperties(Player.prototype, {
  methodThingy: {
    value(param1, param2) {
      const added = param1 + param2;
      return added;
    }
  },
  propertyThingy: {
    get() { 
      return this.getComponent('equippable').getEquipment('Mainhand');
    },
    set(item) {
      this.getComponent('equippable').setEquipment('Mainhand', item);
      return item;
    }
  }
})```
distant gulch
#

thanks 👍

valid ice
#

and a .d.ts file helps with intellisense on those!

distant gulch
#

alright thanks

static nebula
#

Can someone help me? How do I disable the effect particles here, type true at the end of the mcpe command:

player.addEffect('slow_falling', 300, { amplifier: 2 });
#

?

static nebula
#

Oh, thank so much

#

I'll try

misty pivot
#

can you call another constructor of the same class? like lets say

class test {
    main() {
        if (something) //run secondary
    }
    secondary() {
        ...
    }
}```
wary edge
misty pivot
#

ah i see

amber granite
#

What u wanna achieve?

misty pivot
#

i just wanna split up some code to make it visually easier

amber granite
#

class Test {
constructor() {
this.main();
}

main() {
    if (this.something) {
        this.secondary();
    }
}

secondary() {
    // Your secondary initialization logic here
    console.log("Secondary method called");
}

}

// Example usage
let testInstance = new Test();

#
class Test {
    constructor(param) {
        this.initialize(param);
    }

    initialize(param) {
        if (param === 'main') {
            this.main();
        } else if (param === 'secondary') {
            this.secondary();
        }
    }

    main() {
        console.log("Main method called");
        // Your main initialization logic here
    }

    secondary() {
        console.log("Secondary method called");
        // Your secondary initialization logic here
    }
}

// Example usage
let testInstance1 = new Test('main');       // Calls main method
let testInstance2 = new Test('secondary');  // Calls secondary method
misty pivot
#

im still pretty confused what does this actually mean

amber granite
#

this = the class

#

super = the class or the parent class , or one level superior element in the prototype chain

misty pivot
#

ohhhh, man in W3Schools all i could read was a bunch of this

amber granite
#

Ok easily

#

this refer to the object

#

Like if :

let object = {
J : 5,
B : this.J }
#

this refer to the object

misty pivot
#

ohh, yeah, i understand now

amber granite
#
  • this is defined in the run Time
#
  • u use this instead of object name
#

Because when u want to make copies of that object

#

u can't as example put :

let object = {
J : 5,
B = object.J }
#

When u make new instance of it

#

The instance inside will looks like this :

let instance = Object.create(object);
/// Instance would look like :
instance= {
J : 5 ,
B = object.J }
#

Let s say object is now not defined anymore

#

That will make a huge problem

#

so use this

#

To solve it

#

And this will be replaced internally with the new object name

misty pivot
#

i see, i think i now have a clear understanding of classes and gained 3 iq points

distant tulip
#

"this" can refer to a lot of thinks
you can use it in objects classes functions prototypes (in html you can use it to refer to the window)

misty pivot
#

so this is basically just the object so it doesn't matter if i rename the object it will still adapt

amber granite
#

Yah but sometimes

#

It has another contexts

misty pivot
amber granite
#

Liek this gets its context from run Time excution

lethal crystal
#
function customization(player) {
  const form = new ActionFormData();
  form.title("@customization.title");
  form.body(
    { translate: "@customization.hair" },
    { text: "/n/n" },
    { translate: "@customization.skin" }
  );
  form.button("@customization.button_1");
  form.button("@customization.button_2");
  form.show(player).then((response) => {
    switch (response.selection) {
      case 0:
        player.runCommandAsync("event entity @s spark:change_hair_back");
        customization(player);
        break;
      case 1:
        player.runCommandAsync("event entity @s spark:change_hair_next");
        customization(player);
        break;
    }
  });
}

Can anybody tell e why my form is not opening and saying that;

[Scripting][error]-TypeError: Incorrect number of arguments to function. Expected 1, received 3    at customization (@NS/test.js:22)
    at <anonymous> (@NS/test.js:9)
amber granite
#

problem with .body()

distant tulip
# misty pivot oh, i thought it was just for classes lmao

i mostly use it in prototypes
for example in my isCrawling prototype "this" refer to the player

import {Player} from "@minecraft/server"

/**
 * Checks if the player is in a crawling state based on distance between his head location and his feet location.
 * @return {boolean} true if the player is crawling, false otherwise
 */
Player.prototype.isCrawling = function () {
    const distance = this.getHeadLocation().y - this.location.y
    return distance < 0.31 && !this.isSwimming && !this.isGliding && !this.isSleeping;
};
  • how to use:
    put the code above in your script.
//return true or false as mentioned in the jsDoc
 if(player.isCrawling()){
  player.sendMessage("Stop crawling like a baby :p")
}
lethal crystal
amber granite
#

Wait a min

misty pivot
misty pivot
amber granite
#
  • Don't forget
distant tulip
amber granite
#

functions has its this too

misty pivot
distant tulip
#

class*

amber granite
#

Like static propreties

#

Instead of making new propreties every time u create new obje6

misty pivot
#

ah, alright

amber granite
#

Like if three object has

#

A proprety called :
PI : 3.14

#

Just put it in the prototype

#

To make them all share it

#

Instead of making new copies of it

misty pivot
#

ohhh, i thought it's used to add new things to an object, like if i wanted to add a new method the player

amber granite
#

Yes , but not its real usage

#

Because when u want to make a class or constuctor function

#

U must put all properties that can be shared in it

#

To save ur ram from lacking

misty pivot
#

i see, also is the script speed depended on the ram of the device/host server?

distant tulip
#

huh
how can that cause a memory leak

amber granite
#

U make many instances of proprety

distant tulip
#

that not really a "memory leak"

amber granite
#

: | , so my brain isn't braining anymore

amber granite
#

Really

#

Using prototype, make ur code more effecient and more optimized

misty pivot
#

memory leak is an object that exists but cant be accessed right?

distant tulip
#

a memory leak is when a function keep adding stuff without any control over it
how can a prototype prevent it?

amber granite
#

That what google and chat gpt said : |

misty pivot
amber granite
#

No , u can use it in other things too

#

It used for inheritance

misty pivot
#

oh yeah, forgor about that

#

anyway, thx y'all for the patience and for the brief lesson

amber granite
#

So , when using prototype, it access that property

#

From the constuctor function

#

Instead of making new instances of it for each object

#

It called prototype chain

misty pivot
#

oh, I understand, it's similar to this

amber granite
#

No

#

• = •

misty pivot
#

yeah, just hear me out tho

amber granite
#

To make it easier for u

#

Let s say , we have one iphone chargeur

#

And all ur family has iphone

#

Without chargers

#

So instead of all ur family members buy new chargers

misty pivot
#

OH, Y'ALL SHARE IT

amber granite
#

Yeah

#

I know my example is not good

#

But ._. yeah

#

That what prototype does

misty pivot
#

yeah dw, i got it

#

dont give me homework tho 😭

amber granite
#

So buying new chargers is expensive

#

So the money in this situation is ur RAM

#

And u don't want to spend all ur RAM on new constant propreties that can be shared between all new instances of that object

#

Xd

#

I hope u understand that

#

Because it s too important concept

misty pivot
#

i can see its use but i think for an addon it's not pretty useful since a ton of stuff is already given, but similar to minato's isCrawling that's a way for it to be useful since it's gonna be used a lot

amber granite
#

It s useful

#

If u make a class as example

#

Like databases

misty pivot
#

i need to catch up some sleep, in already tweakin

amber granite
#

Kk

misty pivot
amber granite
#

, goodnight anyways

distant tulip
#

"this" is getting no where

amber granite
#

how programming languages tutorials makers feels when they write :
What is THIS ?

warm drum
#

can script stop game message?

#

like "Player has joined the game" or "Wolf was slained by zombie" type of message

distant tulip
#

no

warm drum
distant tulip
#

use playerBreakBlock event and runCommand function

valid ice
warm drum
valid ice
#

Don't have one

abstract cave
#
import { Player, world } from "@minecraft/server";

world.afterEvents.entityHurt.subscribe(eventData => {
    const player = eventData.damageSource.damagingEntity;
    const entity = eventData.hurtEntity;
    const equippable = player?.getComponent("equippable");
    const slot = equippable.getEquipment('Mainhand');

    if (player?.typeId == "minecraft:player", slot?.typeId === "ad:luminite") {
        player.runCommand("say You hit an entity");
    }

});

Anyone know why this doesnt work, it doesnt give any errors

valid ice
#

use &&, not ,

nimble schooner
#

What did they do to world.beforeEvents.playerInteractWithBlock.subscribe?

#

How to use it now?

distant tulip
#

it is the same
just not stable

nimble schooner
#

Whats the newest manifest version?

#

Or in which version can I use it without having a syntax error

gaunt salmonBOT
#

Latest NPM Types

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

Beta APIs NPM Types

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

Preview Latest NPM Types

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

Preview Beta APIs NPM Types

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

1.12.0-beta

nimble schooner
#

Ty

#

Wow, my way too big annoying pack which I didn’t update since 2023 finally works again

#

Tysm

#

Only problem is BlockAreaSize

distant tulip
#

it is blockVolume now

nimble schooner
#
.getEntities({
        excludeTypes: ["minecraft:villager", "minecraft:player"],
        volume: new BlockAreaSize(1800, 400, 1800),
        location: {
            x: 1600,
            y: -64,
            z: 1600
        }
    }) ```
#

So I only have to change the name

#

Do I still have to import it or is it built in already?

distant tulip
#

no
how dose BlockAreaSize work
blockVolume need tow corners of the volume

nimble schooner
#

uhhh

#

so like from -400, -400 to 400, 400?

#

How to do that if it isnt like blockareasize

distant tulip
#

vector3
new BlockVolume(from,to)

nimble schooner
#

vector3 is with y, right?

distant tulip
#

yeah

#

what dose BlockAreaSizedo in your code

#

was doing*

nimble schooner
#

so like new BlockVolume({x: -400, y: -64, z: -400}, {x: 400…?

nimble schooner
distant tulip
#

ah turns out volume only need vector3

#

so this should work

.getEntities({
        excludeTypes: ["minecraft:villager", "minecraft:player"],
        volume: {x:1800, y:400, z:1800},
        location: {
            x: 1600,
            y: -64,
            z: 1600
        }
    }) ```
nimble schooner
#

Oh lol

#

Alright

#

So they made it just simpler

#

Actually good change xD

#

Tysm for help <3

distant tulip
#

ur wlc

steep hamlet
#

how can i get a dropped item's id?

#

with typeId it only returns minecraft:item

valid ice
#

Entity.getComponent('item').itemStack

steep hamlet
#

thanks

fickle pulsar
#

guys

#

how to use jayly bot

#

nvm

cold grove
#

Using it duuh

#

Hope it helped

turbid oriole
amber granite
#

Tab ?

turbid oriole
#

VSC?

amber granite
#

Vscode?

turbid oriole
#

Yes

amber granite
#

What u mean by tab

cold grove
#

Its the documentation page

turbid oriole
turbid oriole
#

Leave.

cold grove
#

Not the official one

amber granite
distant tulip
abstract cave
#
world.afterEvents.itemUseOn.subscribe(eventData => {
    const block = eventData.block;
    const item = eventData.itemStack;

    if (item?.typeId === "su:fish_net", block?.typeId === "water") {
        player.runCommand("say you placed a block");
    }
});
#

Anyone knows why this doesnt work

wary edge
drifting ravenBOT
#
How To Ask Good Questions

Be specific and include relevant details about the question upfront.

  • What are you trying to accomplish?
  • If you have code, which part is not working? Any content logs?
  • What have you already tried?
  • Have you searched the Bedrock Wiki?

https://xyproblem.info/

knotty plaza
#

And you can't really interact with water

abstract cave
knotty plaza
#

Try getting the block from a raycast

abstract cave
#

it doesnt give errors or work in general

amber granite
#

Agree

abstract cave
wary edge
#

You need the liquid clipped component for your item

abstract cave
#

i tried

amber granite
#

Replace , with &&

wary edge
#

Great catch kiro

#

Maybe that's why it wasn't working for you because I've used lliquid clipped and it works

amber granite
#

Thx

amber granite
#

Try the thing first

#

: P he left the conversation

knotty plaza
abstract cave
amber granite
#

Yeah + player is not defined

#

U must extract it from event

#

eventData

abstract cave
#

im confused here

amber granite
#

?

abstract cave
#

i should get the player from the evnentData and then use it to do....?

amber granite
#

Just add a variable

#

Called player

#
let player = eventData.source
#
  • change ur if statement
#

With this one :

knotty plaza
#

Now everything is defined```js
world.afterEvents.itemUseOn.subscribe(({ source: player, block, itemStack: item }) => {
});

amber granite
#
if ( item?.typeId === "su:fish_net" && block?.typeId === "minecraft:water" )
abstract cave
amber granite
#

No

#

U put , instead of &&

abstract cave
#

ok

amber granite
#
  • type id
#

Must start with

#
minecraft:water
abstract cave
remote oyster
remote oyster
#

Might be wrong, but I'm pretty certain.

amber granite
#

I don't think so

#

Because it s ===

amber granite
#

And the type id

remote oyster
amber granite
#

Will start with the Minecraft:

amber granite
#

It s not automatical

#

U must add minecraft at first

#
import { world } from '@minecraft/server';

world.afterEvents.itemUseOn.subscribe(({ block, itemStack: item, source: player }) => {
    if (item?.typeId === "su:fish_net" && block?.typeId === "minecraft:water" && player) {
        player.runCommand("say you placed a block");
    }
});
knotty plaza
#
world.afterEvents.itemUseOn.subscribe(({ source: player, itemStack: item }) => {
  const ray = player.dimension.getBlockFromRay(player.getHeadLocation(), player.getViewDirection(), {
    includeLiquidBlocks: true,
    includePassableBlocks: true,
    maxDistance: 6
  });
  if (!ray) return;
  
  if (item?.typeId === "su:fish_net" && ray.block?.typeId === "minecraft:water") {
    // Your code
  }
});
amber granite
#

Bro is surely confused rn 💀

knotty plaza
abstract cave
#

also, it didnt work

amber granite
#

Any one ?

abstract cave
#
world.afterEvents.itemUseOn.subscribe(eventData => {
    const block = eventData.block;
    const item = eventData.itemStack;
    const player = eventData.source

    if (item?.typeId === "su:fish_net" && block?.typeId === "minecraft:water") {
        player.runCommand("say you placed a block");
    }
});

knotty plaza
abstract cave
distant tulip
abstract cave
knotty plaza
amber granite
#

What s the error message?

#

Log

abstract cave
distant tulip
#

send your json file

#

itemUseOn don't work on all items

proper forum
#

Does Block.getTags() method work? I've always had problems with this method (with custom blocks) as it always returns only one tag.

amber granite
#

Is Block supposed to have more than 1 tag ?

#

How u use it ?

#

I mean the way u implemented it in ur script

abstract cave
# distant tulip send your json file
    "format_version": "1.20.80",
    "minecraft:item": {
        "description": {
            "identifier": "su:fish_net",
            "menu_category": {
                "category": "items"
            }
        },
        "components": {
            "minecraft:icon": "su_fish_net",
            "minecraft:max_stack_size": 16,
            "minecraft:liquid_clipped": {
                "value": true
            }
        }
    }
}```
distant tulip
#

there is component that allow your item to interact with blocks
yo should add it
idk it name

abstract cave
#

isnt on_use getting depriciated

abstract cave
#

only block placer and entity placer

distant tulip
amber granite
#
{
    "format_version": "1.20.80",
    "minecraft:item": {
        "description": {
            "identifier": "su:fish_net",
            "menu_category": {
                "category": "items"
            }
        },
        "components": {
            "minecraft:icon": "su_fish_net",
            "minecraft:max_stack_size": 16,
            "minecraft:liquid_clipped": {
                "value": true
            },
            "minecraft:on_use_on": {
                "event": "minecraft:item_use_on",
                "target": "self"
            }
        }
    }
}
knotty plaza
abstract cave
knotty plaza
#

Yes, I do use it

abstract cave
distant tulip
proper forum
# amber granite Is Block supposed to have more than 1 tag ?

Yes. The idea is to have multiple tags, but for some reason for the script the block only has one tag (even Block.hasTag doesn't work)
For example:

/**
 * 
 * @param {Block|ItemStack|Entity} source 
 * @param {string} key 
 */
export function getTagData(source, key) {
    console.warn(source.getTags())
    console.warn(source.hasTag("test"))
    for (let tag of source.getTags())
        if (tag.startsWith(key + ":")) return tag.replace(key + ":", "");
    return undefined;
}

Block components (shortened):

"components": {
  "tag:test": {},
  "tag:gravel": {}
}

getTagData searches the tags for a match and returns the rest of it. But with the example block, getTags() only returns "gravel" and the hasTag returns false

amber granite
#

If it didn't work then lower ghe format_version

remote oyster
amber granite
#

Both

#

Because typeId gives u string

remote oyster
amber granite
#

if u use
=== To check if id match or not

#

U must include it

abstract cave
distant tulip
remote oyster
#

I'm not referring to strict type matching. I'm speaking about the return for items.typeId in general. Since they are using a custom namespace it's necessary to pass it. Otherwise, they could leave it out and the return on that item would be the same result.

amber granite
abstract cave
amber granite
#

Dang it

abstract cave
amber granite
#

Yeah

#

Sleeping

tacit sigil
#

Yo who can make me an add-on for $5

amber granite
#

Me

#

What the add-on about first?

#

@tacit sigil

tacit sigil
#

I already told he was Pokémon anything that you can do that would revolve around Pokemon will do

amber granite
#

Hmm

tacit sigil
#

So what can you do that would be helpful for the Pokemon Mod

amber granite
#

So Pokémon add-on

tacit sigil
#

Yes

amber granite
#

Including models , animation, etc... ?

tacit sigil
#

Can I see some of your models

amber granite
#

I don't make models ._.

cold grove
#

I think this nor the place for that

#

Go to the skill share server and ask for a developer

amber granite
#

Skill share

#

?

tacit sigil
#

Let's move into DM's

amber granite
#

Idk , but that thing require entities channel

trim slate
#

Fivver is the place to be for commissions

#

Protects the buyer and seller

amber granite
#

I don't think fiverr has add-ons creator , so

#

Yeah but it s better to do that anyways

trim slate
#

I used to make packs for people on fiverr all the time

amber granite
#

Cool

turbid oriole
turbid oriole
wary edge
unique dragon
#

only items have "minecraft:tags" component

wary edge
unique dragon
#

ye

turbid oriole
pale terrace
warm drum
#

Can we use script to play attachable animation?

burnt remnant
#

how do you decrement a stack?

#

yknow, - 1 instead of adding +1 to the stack? i ask this because when attempting to do -1 to .amount it gets an error saying it must between 1-255. so is subtracting literally impossible

open urchin
#
if (stack.amount > 1) stack.amount--;
else stack = undefined;
burnt remnant
#

using -- does nothing for me

#

not even an error

#

const chestInventory = blockAbove.getComponent("minecraft:inventory").container;

const itemInFirstSlot = chestInventory.getItem(0);

itemInFirstSlot.amount--;

#

ive tried different variations too,

itemInFirstSlot.amount--

itemInFirstSlot.amount - 1

itemInFirstSlot.amount = itemInFirstSlot.amount - 1

#

nothing

burnt remnant
#

it better not be because i did const instead of let

distant tulip
distant tulip
#

after the change made

turbid oriole
#

Can Minecraft net be used from Android?

burnt remnant
# distant tulip after the change made

if (itemInFirstSlot.typeId === blockBehindW.typeId && block.permutation.getState("minecraft:cardinal_direction") === "west" && northblock.typeId === "rel:steam_engine_powered" && northblock.permutation.getState("minecraft:cardinal_direction") === "north" && southblock.typeId === "rel:steam_engine_powered" && southblock.permutation.getState("minecraft:cardinal_direction") === "south")
{
itemInFirstSlot.amount = itemInFirstSlot.amount--;
chestInventory.setItem(itemInFirstSlot ,0);
if (blockInFrontW) {
block.dimension.getBlock(blockInFrontLocationWest).setType(blockBehindW.typeId);
}
}

its still not working and setting the item managed to break the other if statement.

distant tulip
burnt remnant
#

im not getting an error, nothing is happening

#

and i know that first if statement is being activated and doing fine

#

so i restarted minecraft and now im getting an error?? weird?

#

75 is

chestInventory.setItem(itemInFirstSlot ,0);

distant tulip
burnt remnant
#

Okay no error

burnt remnant
#

tried restarting the game too

#

instead of

itemInFirstSlot.amount = itemInFirstSlot.amount--

im just going to try

itemInFirstSlot.amount--

hushed ravine
#

Is chatSend cancellable in Stable APIs?

distant tulip
burnt remnant
#

oh my god it worked

distant tulip
#

good

burnt remnant
#

im gonna cry

distant tulip
#

🗿

hushed ravine
burnt remnant
distant tulip
#

💀

#

when

burnt remnant
#

i use to use setItem, so if the stack was 62, id setItem to 61, if it was 61 id setItem to 60. so i did that 64 times, times another 8 times , now i can just use subtraction

#

and every setItem i did was 4 lines long

distant tulip
#

bruh

burnt remnant
#

hi everyone me again 😂 so i noticed beforeEvents.itemUse doesnt work on my item thats in the offhand, is there a way to get it to work for offhand items or no?

steep hamlet
#

is it possible to make blocks that use "minecraft:custom_components" stop acting like they have interactable component?

woven loom
#

anyone has the query parser ?

steep hamlet
#

whar

woven loom
#

@a[...]

distant tulip
steep hamlet
#

even tho i have nothing interact related in their code

distant tulip
#

whats in your custom component

distant tulip
#

the block json

steep hamlet
distant tulip
#

i don't see why it would be intractable

distant tulip
woven loom
#

ye

distant tulip
# woven loom ye

i think i do
but idk if this is what are you looking for
used it in an old world to clear entities

function parseSelectors(command) {
    const selectorVariablePattern = /@([aeprs]|initiator)/;
    const selectorArgumentsPattern = /\[([^\]]+)\]/;
    let result = {
        target: null,
        arguments: {}
    };
    const variableMatch = command.match(selectorVariablePattern);
    if (variableMatch) result.target = variableMatch[1];
        else return result;
    const argumentsMatch = command.match(selectorArgumentsPattern);
    if (argumentsMatch) {
        const argumentsString = argumentsMatch[1];
        const argumentsArray = argumentsString.split(',');
        argumentsArray.forEach(arg => {
            const [key, value] = arg.split('=');
            result.arguments[key.trim()] = value.trim();
        });
    }
    return result;
}

it doesn't check if the arguments are valid

woven loom
#

it should map to script query tho

distant tulip
#

yeah
i didn't count for complex arguments like hasItem

woven loom
#

? i mean to say EntityQueryOption

distant tulip
#

oh
yeah that is better then what i have

sage portal
#

What's the native way to give someone an item?

shy leaf
#

thats what i did at least

grave nebula
#

some dude was talkin bout attachable

#

tf is an attachable

amber granite
#

!

round bone
thorn flicker
#

the onTick custom component wont activate unless you place the block yourself?

#

I have a generated block and its not ticking unless I place it

#

this is lame

distant tulip
thorn flicker
#

randomTick will do for now ig

round bone
#

it's right?

last latch
glacial widget
#
world.afterEvents.entitySpawn.subscribe((ev) =>{
  let item = ev.entity
  if(item.typeId !== "minecraft:item") return
  const itemStack = item.getComponent("item").itemStack
  item.nameTag = `§5${itemStack.amount}x§d ${getEntitysItemName(item)}`;
});

does anyone know how to update the amount?

glacial widget
valid ice
#

Can't; item component for entities is read-only

still rampart
glacial widget
valid ice
#

well yeah, but you can't edit the item once it is dropped in the world

glacial widget
valid ice
#

Good question

neat hound
#

Maybe you can drop another right there too

round bone
glossy wasp
#

It sayd its at 99999

abstract cave
#

world.afterEvents.itemUseOn.subscribe(eventData => {
    const block = eventData.block;
    const item = eventData.itemStack;
    const player = eventData.source

    if (item?.typeId === "su:fish_net" && block?.typeId === "minecraft:water") {
        player.runCommand("say you placed a block");
    }
});
#

i want to make an item place a block, when placed on water

#

does this look good

#

beacuse it doesnt work

#

also the player.runCommand is just a placeholder

open urchin
#

does the item have the liquid clipped component?

wary edge
#

Like I told you yesterday?

abstract cave
#
                "value": true
            }```
open urchin
#

unless the player interact with block event detects it, idk

open urchin
#

There's world.afterEvents.playerInteractWithBlock in beta versions of @minecraft/server that might trigger

thorn ocean
#

Do you guys have any good idea on storing info to create a large database? I was thinking of using dynamicProperties or tags.

slim spear
amber granite
thorn ocean
woven loom
#

like?

amber granite
thorn ocean
amber granite
#

Databases uses world instead of entities

#

Use DynamicPropreties

#

Because they are not limited

thorn ocean
amber granite
#

They are limited, by 32767 characters

#

But u can divide them into chunks

#

By adding numbers to that dynamic proprety id

#

And that will make then unlimited

#

And if u can get them too, by for loop

woven loom
#

You can have as many keys as possible combinations of 32k bytes.

thorn ocean
#

Alright then. Thanks!

woven loom
amber granite
#

Yeah , i used it

thorn ocean
amber granite
#

U can make a json file

#

I mean u can make object of names

#

Then stringify it using JSON.stringify

#

Or stingified array

thorn ocean
amber granite
#

Yes

#

Use an array for that

#

If u gonna deal with only names

#

Or Set object

thorn ocean
#

Can you show me a small example? I don't think I've delt into this side of JS yet lol.

amber granite
#

Yes ofx

young mango
#

how can i define an entities current health and max health?

amber granite
#

Sorry for my dumb question

#

I mean u want to make it with Set object?

thorn ocean
amber granite
#
  • just a note :
    Set object is just like an array, but the special thing about it , u can duplicate an element in it twice as example :
    U can do that with array :[ "Jam" , "Jam" , "kim" ]
    With set object :
    // Jam only appears once
    [ "Jam" , "kim" ]
#
  • it s not exactly an array , u can search for an item by index ( i just gave u an example to clarify what set is )
amber granite
#

Not exactly

#

It just an object that make an element never be added more than once

#
  • yeah it supports types unlike objects
thorn ocean
amber granite
#

Yes

#
import { world } from '@minecraft/server';

// Step 1: Create a Set and add names to it
const Names = new Set();
Names.add("Steve");
Names.add("Alex");
Names.add("Herobrine");
let playersNames = JSON.stingify(Array.from(Names))
world.setDynamicProprety("id" ,playersNames)
thorn ocean
amber granite
#

JSON.parse()

#
//step 2 : getDP and put it again in the set
const Names = new Set (JSON.parse(world.getDynamicProprety("id")))
amber granite
#

Uw

thorn ocean
# amber granite Uw

Just experimented a little with what you told me and WOW. That is powerful.

amber granite
#

What is powerful exactly XD ?

thorn ocean
amber granite
#

Everything is possible

#

As long as u believe

thorn ocean
amber granite
#

Unless u are an atheist that s another story XD

#

Anyways

cold grove
#

I believe in bibble

amber granite
#

;-;

abstract cave
#

can anyone help, im trying to get my item to place a block using scripts

#

and so far what ive done aint working

stiff ginkgo
#

how to detect when player get hit? like when player get hit that player will run command

unique dragon
grand heart
#
scriptevent wry:func console.log("Hello World!")
[2024-07-28 09:50:25:294 INFO] Script event wry:func has been sent
[2024-07-28 09:50:25:294 ERROR] [Scripting] ReferenceError: 'eval' is not defined
unique dragon
grand heart
unique dragon
# grand heart how do i do that good sir
{
    "format_version": 2,
    "metadata": {
        "authors": [
            "Me"
        ],
        "generated_with": {
            "bridge": [
                "2.7.24"
            ],
            "dash": [
                "github:bridge-core/dash-compiler#8fa35c73292f6382747d0f411fca26431a6d2c8e"
            ]
        }
    },
    "header": {
        "name": "",
        "description": "",
        "min_engine_version": [
            1,
            21,
            0
        ],
        "uuid": " _some code_ ",
        "version": [
            1,
            0,
            0
        ]
    },
    "modules": [
      // modules
    ],
    "capabilities": [
  -      "script_eval"
    ],
    "dependencies": [
       //modules
    ]
}
turbid oriole
#

Hello.

turbid oriole
#

Can someone explain to me the difference between "item" events? Is it true that you cannot detect a click on the screen or at least one block?

unique dragon
turbid oriole
unique dragon
#

?

#

no

turbid oriole
#

XD

unique dragon
#

or on a block

turbid oriole
granite badger
modest oasis
#

guys how can I get player coordinate and store it like you can /back to your previous postion before teleporting to other location or before die

#

nvm seems its too complex for me as a beginner

verbal yew
#

is it possible to show a color in a chest ui to a specific player

#

@modest oasis

misty pivot
#

idk why this isn't working and since i dont really have time to wait for 20 minutes what i did is set it to night and sleep the "show days played" seem to change to day 1 but the script still isn't running

function day() {
    if (!world?.getDynamicProperty("day")) {
        return 10;
    }else return world?.getDynamicProperty("day");
}
if (world.getDay() >= day() && !world?.getDynamicProperty("day")) {
    world.setDynamicProperty("start", true)
}```
#

i know it says 10 there but i adjusted it to run on day 1 using the day dynamic property

sharp elbow
#

When is this snippet running? And where you setting the "day" dynamic property?

#

Your logic could be changed some to show your intent better too—your negation ! will cast the result of getDynamicProperty to a boolean, so while a value of undefined will trigger it, so will 0. Better to compare it explicitly, like world.getDynamicProperty("day") == undefined.

misty pivot
#

the modal form works fine since it tells me the value after the enter it

misty pivot
grand heart
abstract cave
distant tulip
# abstract cave cuz i need it to place block on water

const replaceBlocks = [
  'minecraft:air',
  'minecraft:water',
  'minecraft:lava',
]
world.afterEvents.itemUse.subscribe((event) => {
  const {source, itemStack} = event
  if(itemStack.typeId !== 'item:id') return
  const blockInView = source.getBlockFromViewDirection({maxDistance:4.5})
  if(!blockInView) return
  const {block: blc, face} = blockInView
  const block = getAdjacentBlock(face,blc)
  if(!replaceBlocks.includes(block.typeId)) return
  block.setType('block:id')
  //use setPermutation if you want specific properties
  if(block.typeId == 'minecraft:water') block.isWaterlogged = true
})

function getAdjacentBlock(face,block) {
  switch(face){
    case"Down" : return block.below();
    case"Up"   : return block.above();
    case"East" : return block.west();
    case"North": return block.south();
    case"South": return block.north();
    case"West" : return block.east();
  }
}

amber granite
misty pivot
#

lemme check real quick

amber granite
#
  • world get Day()
#

...

#

Ticks

#

Nvm

#

The last sentence is wrong

misty pivot
#

oh

amber granite
#

Returns number - The current day, determined by the world time divided by the number of ticks per day. New worlds start at day 0.

distant tulip
#

for Ticks use system.currentTick

misty pivot
#

so that means sleeping doesn't count as a day?

distant tulip
#

it dose

#

i don't think days are calculated by currentTick

amber granite
#
function day() {
    if (!world?.getDynamicProperty("day")) {
        return 10;
    } else return world?.getDynamicProperty("day");
if (world.getDay() >= day() && !world?.getDynamicProperty("day")) {
    world.setDynamicProperty("start", true)
}```
distant tulip
#

why do you need to store that

misty pivot
#

store what?

#

oh, the day property is the starting day, like the day an event starts

distant tulip
#

ah

#

why the " return 10"

misty pivot
#

default value

#

if day property isn't set then it defaults to 10

distant tulip
#

i know
i meant why 10

misty pivot
#

oh, it's a test basically

amber granite
#

Yeah i see the problem now

#

Rhe second if statement will never work

misty pivot
#

the second if statement basically if it's pass the day property/default day then it will start an event or in this case make a property named start

amber granite
#

Yeah it will never work

#

I ll fix it for u

distant tulip
#

you are not setting the day to the dp

misty pivot
amber granite
#
function day() {

if (world.getDay() >= day() && !world?.getDynamicProperty("day")) world.setDynamicProperty("start", true)

    if (!world?.getDynamicProperty("day")) {
        return 10;
    } else return world?.getDynamicProperty("day");
}```
misty pivot
#

ah so place the whole if statement in the function

amber granite
#

Yes

misty pivot
#

but why wouldn't it run the first place earlier?

amber granite
#

Because

#

The first if statement

#

The includes return

#

Block the the second if statement

#

So the code after return will never work

misty pivot
#

oh return is like a break

amber granite
#

Yes

misty pivot
#

i didn't knew that

#

thanks very much

amber granite
#

Uw

misty pivot
#

hm, what's strange is it didn't work still, and i tested yes what's being shown in "show days played" option in game is the same value as world.getDay()

#

how about i try a ternary operator?

distant tulip
#

can you tell what are you trying to do?

misty pivot
#

maybe like

if (world.getDay() >= world?.getDynamicProperty("day") != undefined ? world?.getDynamicProperty("day") : 10) {
    world.setDynamicProperty("start", true)
}```
#

kinda like this

amber granite
#

What did u did

#

@misty pivot what are u trying to do first ?

misty pivot
#

so i used the ternary operator to see if day is defined, if so it will use value of they else it'll use default of 10

amber granite
#

So u put an if statement inside an if statement

#

XD

misty pivot
#

yes

amber granite
#

U just make the code bigger for no reason

misty pivot
#

well the function version wasn't working

#

hold up i got an idea

amber granite
#

Did it work now ,?

misty pivot
#

nope it didn't

amber granite
#

Ur logic is kinda bad

amber granite
#

Tell me what u wanna do

#

Or send me full script

misty pivot
amber granite
#

What about the imports ?

misty pivot
#

oh yeah, i did import world and system

amber granite
#

Show me what u did

#

I need to see that

misty pivot
#

this is the first iteration

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

const runner = system.runInterval(() => {
    function day() {
        if (world?.getDynamicProperty("day") == undefined) {
            return 10;
        }else return world?.getDynamicProperty("day");
    }
    if (world.getDay() >= Number(day()) && !world?.getDynamicProperty("start")) {
        world.setDynamicProperty("start", true)
    }
})```
amber granite
#

But

#

U didn't even trigger the function

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

const runner = system.runInterval(() => {
    const dayValue = world.getDynamicProperty("day") || 10;

    if (world.getDay() >= Number(dayValue) && !world.getDynamicProperty("start")) {
        world.setDynamicProperty("start", true);
        console.warn("Dynamic Property, start, has been set to true.");
    }
});
amber granite
#
import { world, system } "@minecraft/server";

const runner = system.runInterval(() => {
function day() {
if (world.getDay() >= day() && (!world?.getDynamicProperty("day"))) world.setDynamicProperty("start", true)
    if (!world?.getDynamicProperty("day")) {
        return 10;
    } else return world?.getDynamicProperty("day");
}
world.sendMessage(`day : ${day()}`)
console.log(day())
},1)```
#

@misty pivot

misty pivot
#

i'll try it out

amber granite
#

U just put that

#

And u think it will work ?

#

Without outputing anything?

misty pivot
#

ah, it's a function right, it's declared but not used earlier

amber granite
#

Yes

remote oyster
#

Just eliminate the function. Doesn't appear to be necessary.

amber granite
#
  • u need to set the dynamic proprety also
nimble schooner
#

Why does player.selectedSlot not return a valid number anymore and how to fix it?

amber granite
#

get

remote oyster
# abstract cave this is confusing
// List of block types that will be replaced when interacted with
const replaceBlocks = [
  'minecraft:air',
  'minecraft:water',
  'minecraft:lava',
]

// Subscribe to the 'itemUse' event that occurs after item usage in the world
world.afterEvents.itemUse.subscribe((event) => {
  const { source, itemStack } = event;

  // Check if the item used matches a specific item ID
  if (itemStack.typeId !== 'item:id') return;

  // Get the block directly in front of the player's view within a maximum distance of 4.5 blocks
  const blockInView = source.getBlockFromViewDirection({ maxDistance: 4.5 });
  if (!blockInView) return;

  // Destructure the block and its facing direction ('face')
  const { block: blc, face } = blockInView;

  // Get the adjacent block based on the face direction
  const block = getAdjacentBlock(face, blc);
  if (!replaceBlocks.includes(block.typeId)) return;

  // Replace the current block with a new block type
  block.setType('block:id');

  // Set specific properties for certain block types
  if (block.typeId == 'minecraft:water') {
    block.isWaterlogged = true;
  }
});

// Function to get the adjacent block based on the given face direction
function getAdjacentBlock(face, block) {
  switch (face) {
    case "Down": return block.below();   // Below the current block
    case "Up": return block.above();     // Above the current block
    case "East": return block.west();    // West of the current block (facing East)
    case "North": return block.south();  // South of the current block (facing North)
    case "South": return block.north();  // North of the current block (facing South)
    case "West": return block.east();    // East of the current block (facing West)
  }
}

Added comments to explain what the code does as you read along from top to bottom. Should clear it up some.

abstract cave
#

been trying to figure it out

#

also, why does it need to check adjacent blocks @distant tulip

remote oyster
hazy nebula
#

for (const entity of world.getEntities()) it responds with "not a function" what is the problem?

nimble schooner
amber granite
#

As function

stiff ginkgo
#

can js apply component_group?

tiny fable
#

Is there no way to read files in the script?

neat hound
# hazy nebula ```for (const entity of world.getEntities())``` it responds with "not a function...

when you encounter a problem like this, it would help to look at the class again and see what methods are available. Perhaps dive into some of the methods to find which one has getEntities.... though in this case it is not obvious... use getDimension() to get to Dimension Class https://jaylydev.github.io/scriptapi-docs/latest/classes/_minecraft_server_1_12_0_beta.World.html

distant tulip
#

@hazy nebula

const allDimensions = [ 'overworld', 'nether', 'the_end' ];
const dimensions = allDimensions.map(dimension => world.getDimension(dimension));
const entities = dimensions.flatMap(dimension => dimension.getEntities());

for(const entity of entities) {
    //code
}
remote oyster
distant tulip
#

thanks lol

hazy nebula
#

Thask everyone but i had change for (const entity of world.getEntities()) to const entity = world.getEntities()) and it work!

amber granite
#

Hhh

#

💀

#

We told u world.getEntities()
Dosen't exist

neat hound
#

In what world does that work

hazy nebula
amber granite
#

Impossible

#

getEntities dosen't exist!!!!

neat hound
#

So did you actually pick up any entities.... can you do a loop on them and sendMessage and prove it

amber granite
#

It s undefined

#

Or null ofc

hazy nebula
neat hound
#

just a simple (from your code) entity.forEach(e => world.sendMessage(${e.typeId})) and a screenshot

hazy nebula
#

Like that

amber granite
#

On getEntities

#

And u will see it has no description

#

It will show u
(any)

#

Only
world.getEntity()

granite badger
#

Is typings installed on their pc

amber granite
#

Exist

amber granite
neat hound
#

he is mistaken, he used dimension....

hazy nebula
#

I dont understand

amber granite
#

Oh

amber granite
amber granite
#

My bad

neat hound
#

LOL.. that was funny.. the scripters defense brigade

distant tulip
neat hound
#

This is how inner universes collapse, programmer breathe logic...

steep hamlet
#

possible to get collision box?

wary edge
amber granite
#

No

neat hound
#

You are like a gopher... pop up with a simple answer...

#

Smokey

pale terrace
#

xd

pale terrace
amber granite
#

Agree

#

But u can make a list with hit boxes

#

I mean hitboxes lists

pale terrace
#

And how do you verify that it is the hitbox of the entity?

#

What I do is make a predefined hitbox in the code in those situations

#

with an average size

wary edge
#

Simply create a map of ids to hitbox

amber granite
#

If u know how to deal with node js

#

U can make everything automated

#

And make it get the hit box of ab entity

#

And put it in object which :
{entityid : hitboxValue
}

sage sparrow
#

hi there, what is the limit for saving dynamic properties? if there is any that I should concern about? or how do I set the threshold? [Scripting] 13.83 MB of dynamic properties were saved during the last minute, exceeding the 10 MB threshold.

amber granite
#

The only limit is ur device's storage

pale terrace
amber granite
#

.

amber granite
#

I have question

#

Does the Minecraft first chunk starts from 0 , 0 ?

last latch
#

i wanted to update my old anticheat, but i see that horion doesnt have a nuker anymore did they delete it or is something corrupted? ||wrong forum||

neat hound
#

my brain... i can't.... figure it out.... what is the RegEx for a string with no alpha a-z

open urchin
#

anything that isn't a letter?

neat hound
#

ues

neat hound
#

yes

#

Worked... THANK YOU

last latch
#

❤️‍🩹

runic crypt
#

guys can anyone help me ?

wary edge
runic crypt
#

how do i make one ?

#

like an addon/script

wary edge
#

Did you search in #1067535382285135923 in case someoen else had the same quetsion? We get this a lot as far as I know

runic crypt
neat hound
runic crypt
#

i want it so that players can execute a command lime /function bounty and a menu pops up prompting them to select the person and the amount

runic crypt
neat hound
runic crypt
#

can you help ?

neat hound
neat hound
#

Well good time to get deeper into it. Figure out how to make a simple script to say something every 5 minutes or tell a player when he hits another player and you are halfway there.... chat commands are easy

runic crypt
neat hound
# runic crypt ill try thanks for the help :)

Visual Studio Code: The epicenter of your Minecraft modding journey. Download it here:
🚀 Visual Studio Code Download: https://code.visualstudio.com/download

GUI Template. Grab it here:
📄 GUI Template Download: https://www.mediafire.com/file/gnkd5t5g7s3345i/GUI_template.js/file

But remember, GameTest Framework is an experimental playground with...

▶ Play video
neat hound
#

more on youtube

runic crypt
#

thanks :)

small depot
#

cool whan are you sharing it :0

nimble schooner
#

Can someone send me the link to the sample packs? Idk how to get it or just tell me