#Script API General
1 messages · Page 106 of 1
ping me then
Can somebody send me the docs for applying knockback
I would search here 'applyKnockback' for more samples
import { EntityQueryOptions, DimensionLocation } from "@minecraft/server";
function bounceSkeletons(targetLocation: DimensionLocation) {
const mobs = ["creeper", "skeleton", "sheep"];
const horizontalForce = { x: 5, z: 4 }; // horizontal knockback strength - xz vector
const verticalStrength = 0.3; // upward knockback strength
// Spawn 10 mobs in a pattern
for (let i = 0; i < 10; i++) {
targetLocation.dimension.spawnEntity(
mobs[i % mobs.length],
targetLocation
);
}
const eqo: EntityQueryOptions = { type: "skeleton" };
// Apply knockback to all skeletons in the area
for (const entity of targetLocation.dimension.getEntities(eqo)) {
entity.applyKnockback(horizontalForce, verticalStrength);
}
}
the fact that @granite badger aint even updating the example even after PR sucks, kinda.
he told u to make a pr ;/
and so i did
yeah, sry, (jayly) I didnt mean anything personal.
I just needed the docs but thank you
Sorry if that comes off rude btw
ohk
the example's kinda outdated ig...
yeah most of the examples are way too outdated
Hello everyone, can you help me? I need to summon lightning at custom projectile when it hits entities or hits any blocks, anybody can make a script?
(I'm on 21.100) how do I make it test for block ticks? That's the way it's described in the wiki. And what's a startUp listener? Ty for the runcommand thing btw
You just got hacked by conmaster
Tysm
Check out this article, if you'll be lacking in smth, just ask there
🙂
aww, did he get my ip adrress?
he must not cause i live in the backrooms
nah, he got your nose
👃
PR is merged. Should be on site soon, sorry about that
great! why sorry.
What did they add in v2 APIs btw, haven’t been catching up
where can i find on_interact documentation?
i went from script api only, to endstone c++ plugin development can can't go back to script api anymore its crazy how much more we can do with server software
How is endstone, btw? Is it pretty good? (I’m guessing yes)
yesss its def worth it.
because you still can use it like normal bds, but then you can use plugin development with python or c++.
many more options like beforeEvent cancels, and tons of other options
yes, it supports all RP and BP normally
you're not wrong
Yeah ig I don't understand that part, been trying to have AI help me build this
Depends on your needs, if you're familiar with add-ons and BDS ecosystem enough, you don't really need to use Endstone
I am not using Endstone, beacuse I prefer to have a stable server software rather than lots of functions and plugins, that I won't even use, but it's really good for simple servers
If you server will be a bigger network, consider using proxies with it and then you'll see, if Endstone is must-have for you
Unless, just use Endstone
is it possible to know if a player uses vv?
player0.graphicsMode says Fancy, but Fancy is also Fancy
Yes it should be.
and how?
Works for me.
You might need to relaunch Minecraft properly then? Did you toggle the graphics mode ingame?
yes
with rejoining it works, thanks
That's your issue. The game doesn't recognize if you change it ingame.
It can when I change to Simple
Specifically for VV and Fancy since it's a different pipeline.
Is there a way to get entity's passengers via script api?
Entity.getComponent("rideable").getRiders(): Entity[]
Thanks!
yw
is it possible to change entity inventory "restrict_to_owner" value using script?
Is it possible to get the entity that is being rode on, from the riding entity
oh dang, those are mojangs examples right? they should update their docs examples
you can trigger an event on the entity that adds/removes component groups
so yes
ahh i see, btw how i can set the owner for entity inventory?
tameable component class
Documentation for @minecraft/server
thanks!
its read only.
Should it be not...
read the doc you just sent
How do I make my projectile born leashed?
it must have the leashable component
then spawn it, get the component and leash it
function spawnProjectile(entityId, player, name = false, leash = false) {
try {
const dir = player.getViewDirection();
const origin = player.getHeadLocation();
const pos = {
x: origin.x + dir.x,
y: origin.y + dir.y,
z: origin.z + dir.z
};
const projectile = player.dimension.spawnEntity(entityId, pos);
const comp = projectile.getComponent("projectile");
const comp2 = projectile.getComponent("leashable");
if (name) {
projectile.nameTag = player.nameTag
}
if (leash) {
comp2.leash(player);
}
if (comp) {
comp.owner = player;
comp.shoot({
x: dir.x * 1.5,
y: dir.y * 1.5,
z: dir.z * 1.5
});
} else {
console.warn(`[PROJETIL] A entidade '${entityId}' não tem o componente 'projectile'`);
}
} catch (e) {
console.warn(`[Erro em spawnProjectile]: ${e}`);
}
}
when I leave leash true, it gives the error "not a function"
replace leash(player) with leashTo(player)
Ok
'twas a rhetoric phrase
Modify each chat message through the chat event and iterate through this for each letter.
Someone deleted my message
What is the script version
How can I get the first empty slot?
I tried this and it didn't work.:
player.runCommand(`testfor @s[hasitem={item=air,location=slot.enderchest,slot=${i}}]`);
You need to use entity inventory component
const inv = player.getComponent('inventory');
const firstEmptySlot = inv.container.getSlot(inv.container.firstEmptySlot);
then you can do whatever you want with the slot like set the item
for enderchest idk
mm
if you tried to get a item's localizationKey, would that return like item.apple? and how can i get the actual name.. Oh maybe by using string methods to remove the item. and capitalize the name after it?
cant i get nameTag of item,,, isnt the nameTag is the item's name? like wouldnt it return Apple if i used get the item's nameTag
ok gotta test mayb in game
i think it is empty unless it is explicitly renamed to something (for example via anvil)
i might be wrong tho
u r correct
ah
with script APIs you cant access the enderchest inventory (from what I can tell from the docs). But you can use commands & the hasitem selector to do that.
I would write a .mcfunction that checks every enderchest slot & when it finds an empty slot store the slot id in a scoreboard. Then in a new function pass over every slot again but include a condition to check for the slot, then do whatever you need to do with it.
(Can all be done with execute command)
for most of the things this should do,
const text = itemStack.localizationKey
world.sendMessage({translate: text})
Oh,, the translate, thanks
does that translate work outside of sendMessage..
alr
any function that takes RawMessage interface as a parameter
should work
oki
function enderChestFirstEmptySlot(player) {
for (let i = 0; i < 27; i++) {
const isEmpty = player.runCommand(`replaceitem entity @s slot.enderchest ${i} keep air`).successCount
if (isEmpty) return i
}
}
Oh nice
nice
How can I apply knock so that the player lands on a specific location?
not possible
KINEMATICS
MATH
PHYSICS
CALCULUS
alright
Dealing with all the friction values is hard
yeah and applyimpulse ignores knockback so it could ease the roughness
it's janky tho
Madlad have something for it but it is not accurate
imo what u can do is summon a fake player and make it walk to a location and tp ur entity to that player
iic we dont need structures to spawn fake players now
I'm a bit busy so I'm late replying sorry
2.1.0-beta
wait till I have adjusted to college, I'll be the madlad you once spoken of
2.2.0-beta* or 2.1.0 (stable)
I use 1.21.93
I'd consider updating to latest version and updating your script to slash commands instead chat messages
I don't know how to do that...
migrate to the latest version or use slash commands?
How to do command with slash.
Ok
mc.system.beforeEvents.startup.subscribe(init => {
init.customCommandRegistry.registerEnum('a:a', ["sell", "admin"]);
init.customCommandRegistry.registerEnum('a:b', ["money", "coin"]);
init.customCommandRegistry.registerCommand({
name: 'a:ah',
description: 'Auction House',
permissionLevel: mc.CommandPermissionLevel.Any,
optionalParameters: [
{ name: 'a:a', type: mc.CustomCommandParamType.Enum },
{ name: 'a:b', type: mc.CustomCommandParamType.Enum },
{ name: 'price', type: mc.CustomCommandParamType.Float }
]
}, (ctx, action, currency, price) => {
const player = ctx.sourceEntity;
if (!action) {
mc.system.run(() => {
giaoDienChon(player, "Auction House", 1, "Giảm");
});
return;
}
Like this right?
yes, just check before calling a function if player actually a Player instance
if (!(player instanceof Player)) return
Ok
Is there a way to check if a translation key exists or not?
Where are you getting translation key from?
i have a behavior pack, and i have a resource pack, the behavior pack tries to send a rawMessage, if it gets translated, show it, if it doesn't send a default message.
Why is remember m9 a member now
You may have to use JSON UI
you have to create your own functions that checks if language translation exists
class LanguageTranslations {
private constructor() {}
private static readonly TRANSLATION_KEYS: Readonly<Set<string>> = new Set<string>([
// keys go here
])
public static isValid(key: string): boolean {
return this.TRANSLATION_KEYS.has(key)
}
}
?????????????
are you AI?
Actually Incredible? yeah he is.
Basically, just a piece of code that doesn't solve the problem at all.
I have an idea how this can be done via JsonUI, but it seems to me that it doesn't work that way.
It also depends on the type of this text, because if it is the name of an entity or block or item, then it can be checked, but if not, then it cannot.
Although the easiest way is to just do a translation for all keys
how this does not solve the problem?
you can create a script to automaticly generate a JSON file will all of vanilla keys
or just one of them
because it's just an OOP shell that needs keys anyway. The problem is that we don't know the keys and don't want to manually put them in there
where did he say that he can't just use a pre-built list?
it's much simpler to-do than using JSON-UI with it
He didn't say that, yeah. But I think it's obvious if he had that question. And I don't think he had any problems checking if the element was in the list.
if he is maintaining a server, he could use a pre-built
i was saying, can u not just put it somewhere and get its display value? signs or something for checking? if the value is same as key, it aint translating. just asking. would it work?
He can, but it's still not convenient.
so using Herobrine's ChestUI is also inconvenient, beacuse you have to update it if you have more items or you're updating to latest version
This is completely off topic
nope, my method is using almost the same thing as Herobrine has implemented
just gets a value out of prebuilt variable
if he is going to maintain/update add-on for a bit longer, I would go with this class->method
why is this happening 😭
if not, then he has to get it work with JSON-UI stuff
could you translate it to english?
what difference does your method make? The problem is that Pre-built is not convenient because you need to update it manually (a script also needs to be run manually).
basically it detects the script as a malicous software (Also, i don't speak spanish, this happened to a friend of mine)
could you send the file that this error mentions in it?
it's easier to implement than digging in JSON-UI
yeah just one sec
here it is
isn't it dangerous because of amount of listeners that you're creating?
Depends on your skills and requirements for the solution. BUT, the question was still about how to find out whether the key is valid or not, and not about how to find out whether an element is in a list
if you'll put every translation key into this set, you'll also get the result if key is valid or not
🙂
I think you're missing something in my implementation
uhh idk
what are listeners anyway? the subscribe method thing?
The code you sent checks whether the element is in the list or not. It is not about where to get this list, if it was an API method (which we unfortunately do not have) or at least a script that gets this list, then yes.
you can get this list by using another script do dig these keys out of a bedrock-sample lang file
pretty unoptimized...
I had multiple files with the same form two listeners but different function (for example wide block)
I know. Let's just end this topic already.
Detected: Trojan:Script/Wacatac.B!ml
Status: Active
The active threats have not been fixed and are running on the device.
Date: 15/08/2025 16:06
Details: This program is dangerous and executes commands from an attacker.
Affected items:
containerfile: C:\Users\Drixs\Downloads\BendyReani.mcpack
file: C:\Users\Drixs\Downloads\BendyReani.mcpack->BendyReani/scripts/2tallblock.js
webfile: C:\Users\Drixs\Downloads\BendyReani.mcpack|https://cdn.discordapp.com/attachments/.../BendyReani.mcpack?...
here is the translation btw
that's also a point
Here is the chatgpt's optimized one (the problem is still remaining)
still unoptimized
tell him to rewrite script to implement this thing without using for loop with 2n listeners
Hold up, so you are telling me it is a harmful file becuase it is unoptimized?
The thing is, I also have this file which it doesn't get detected as a harmful file
No. I'm just saying it's not optimized. The problem is detecting it as malware in the OS
Try creating a new file and copy the code there.
still didn't work
hm
i asked chatgpt to optimize it further
What if you just create a new file and write something else there?
it remains to go back to the past so that itemUseOn starts working... although if you use old versions of the API...
In general, the code itself still needs some work...
So I shouldn't use itemUseOn?
Well, like, create a new file and see if it shows up as malware.
If you are using old version of the API, you can
But what I want to understand why is this file doesn't get detected as a malware while the other is always detected as a malware, even though they both use itemUseOn?
Well I use 1.17.0
he meant itemUseOn aint on latest version
ur code needs work if its for latest api
oh then I should use playerPlaceBlock am I right?
ye
but will that fix the malware detection problem anyway?
no, it has nothing to do with that.
hmm, can u not just copy paste the code in a new file?
tried that, it didn't work
idk man
u r downloading an addon, right? try rebuilding if its doable. or just zip the file and try downloading maybe?
already tried that man, tho I will try sending it as a zip file
gpt doesn't know how to optimize code
hell the code is worse than i thought
actually i paste it into my pack and suddenly the whole pack stopped working
Do you seem to know how to fix my problem?
what's the issue
this @woven loom
it detectts it as a trojan
this is the file
wait ,what is the actual file to look at? you sent a bunch
He just forwared it
This is the original one I had problem with, I tried solving it by telling chatgpt to optimize it (just a desperate attempt)
well, the script is for 2 tall multiblocks
I don't think i have an option
its js, js dont even is compiled, it shouldnt be recognized as so
the application that is blocking might be bugged
ik right
the thing is in the pinned messages, I found one that is talking about this issue
the solution was to change its encoding
however that didn't work
the encoding doesnt affect, i think what blocks generally would try to find some suspicious syscalls
so do I avoid using system.run()?
oh
js should not trigger anything
It turns out I am not the only one
#add-ons message
check this message
the same problem
what is the program that runs and checks it?
windows defender
i use linux for about 2 years, so i forgot
it seems that there is no solution in the post
i found some about babylonjs, but same thing, no solution on the post
so it is a known problem
WAIT, I THINK I HAVE FINALLY FIXED IT!
Can someone with windows please test it for me?
Here is the file
how to get the dropped item count?
const item = entity.getComponent('item')?.itemStack; // ItemStack | undefined
item.amount
The component exists if the entity is minecraft:item
not relevant to the question .-.
so is the dropped item is already an entity?
Well, yes. You basically just need to get an instance of Entity, check if it is minecraft:item and you will have access to the item component.
i see, thanks! ill try that
Relevant, event listener for dropping item action
🙂
why do slimes default to a health value of 20 🗿
even when they split apart they only have 1 health it reads 20 for some reason
isn't default health value pinned to a hard-coded component's value?
I'm referring to currentValue
you had this whole conversation about my question and didn't ping me once?
Yeah I Know about the Array.includes() method and yes, i definitely don't want to provide the API with a pre built array of strings, it was clear from the start that the answer he provides was generated by a drunk AI.
Are slimes just completely broken when trying to grab values wth
It even throws errors trying to grab their variants when they split apart
huh, i had that working before
those 20s are also apparently the current health values of the slimes
yeah it's straight up removed
I guess I have to determine which slime it is based on it's movement value which is pretty absurd EDIT: I can't do this either, the value gets thrown all over the place when they split and they are instantly killed by an attack.
and JSONUI while able to filter out translation keys, it wouldn't be able to provide a default text with it
Do itemstacks with different dynamic properties stack and if so is there a way to prevent it?
DynamicProperty only works on most unstackable items
????????????
what do you mean?
Do dynamic properties not work on stackable items?
Yes, item stack can only have dynamic properties if it's max stack size is 1
ok thanks 👍
Will changing durability cancel item charging?
Item has to be replaced, so probably yes
probably, yeah.
damnn, I'm trying to make a semi auto gun that when you hold the use button it should not fire consistently
Write a simple script to test that
Log smth into console every time item will start charging
Yeah, I used to detect it with query.is_using_item but every time the item durability decreases the item use cancels
You're replacing item while decreasing it's durability, that's why
Yeah, I'm gonna try charging instead of using
does the onTick custom component for blocks means that the script is triggered every tick? kinda obvious but i may be wrong
Yes
k thx
Isn't it more related to minecraft:tick component, is it?
uhm
"minecraft:tick": {
"interval_range": [10, 20],
"looping": true
}```
so does this mean that the component runs on the ten ticks between the 10th and 20th tick of a second or it means that it runs around 10 to 20 times on random ticks of a second?
i don't know if you understand what i mean
this is a delay after the previous launch
if you specify [1,1] it will run every tick. if you specify [2,3] it will run every 2 or 3 ticks.
that's a clearer explanation than the one on the wiki imo, ty
give me a perfect value for applyImpulse 😭
someone
im wanna make my entity swim on water
its not psosible with entity.json so
-999
;-;
-999 aura?
Weren't there already some water navigation components?
They don't work.
-999 logical points
doesnt matter cuz i already have -664613684616321 credits
its decreasing day by day
are you trying to make the entity buoyant?
or navigate through water
this
add a sail to your entity's model
It runs randomly from 10 to 20 ticks between iterations
;-;
Trying to migrate my project out of Bridge into Webstorm but running into some issues if anyone has done similar.. notably setting up a watcher so that I can add my resource pack as a Root Directory, but have it automatically mirror into the minecraft/development[rp/bp] folders. I have the TS watcher already set up, but can't see a way to make that specifically do what I want from docs/MS pages. Alternatively, was trying to put the BP/RP directly in the dev folders and just modify them there, with the root Webstorm project being elsewhere and just adding those two folders as root dirs, but then run into the issue of not having them all be under one github repo
~1800 lines of code across 12 TS files. time for a full IDE lol. getting to the point where changing just one class/function/interface signature leads to an entire night of refactoring, which I completely understand is my fault for not doing proper project / domain planning from the start, just wasn't sure if I would actually get anywhere with bedrock when I started.
as a WebStorm user, I am not using any mirrors
you have to write your own script that will copy these files, or open directly BP/RP directories
Is there a way to add the script to the "build" process? For example, right now I have it set to tsc "on save", but I'd like to maybe add
robocopy "%source_bp_folder%" "%server_bp_folder%" /MIR /MT:8 /NFL /NDL /NJH /NP /NC
robocopy "%source_rp_folder%" "%server_rp_folder%" /MIR /MT:8 /NFL /NDL /NJH /NP /NC
to that process after. I am not super familiar with jetbrains products
what do you mean by build process?
ah I guess I mean .. for example with Java/gradle, you can add pretty much anything you want to the build process. so when you hit "run this Task" or similar, you can have it do something like...
- clean the server's plugin folder
- recompile all of your plugins to .jar
- move them to the server plugin folder
- start the server
not seeing anything similar for node/ts/webstorm
I think WebStorm does not support building button like IntelliJ, CLion etc., you have to add your own sh file script probably
thanks. I did see a way to add a script or executable to a custom Watcher, maybe that is the route
will mess with it after I move my postgres database to my mac mini lol. been meaning to do that for a while because I dont like background processes running on my main computer
This is my monorepo structure, not finished due to my other project, but I recommend smth like this
src/ directory contains building script (watching is not finished)
and you just have a script to sync the bp/rp to the minecraft folder I take it?
yes, but I haven't finished my work on this script
I only wrote a script to compress BP/RP directories into smallest zip archives
is what I have been doing but feels kinda bad for quick iterative devlopment to have to restart it every time
-# I can't send a message 😭
hmm not a bad idea to do it in TS. sometimes I forget you don't need to use batch/powershell for this kind of thing lmao
Uh, where is script api channel
Most of people would do this in Python or other simple languages, TS is just preference atp
?
We are still in-topic around scripting
Just wondering how he can copy his BP/RP files using a script
That look like node js to me
I don't really care tho
You guys feel free to continue
I knew it tbh xD
I am kinda surprised i didn't try any of those
I used bun when it came out, but it failed to run
Deno is good alternative, but not as stable as Node
yeah bun and deno are hit or miss. use node always when you need something stable/reliable
Bun is new and they're implementing every module from scratch
mainly was using Deno until I decided to try out webstorm, and now seeing that it can auto-configure a TS project with node sort of defeats the purpose of deno to me
I like it's performance, but I am still missing port of some of modules like bedrock-protocol, which are essential for my work
That kinda sound like a stupid idea, there millions of modules out there
It's pretty good after all, Bun is hitting up to x2-3 better benchmark scores than Node overall
yeah it's pretty fast if it works for what you need
but to be fair, if I need something fast, any JS runtime is not what I would reach for
java + spring/hibernate 🙂
I got pretty deeper with JS, and it's not that bad in-topic of perfomance
nope it absolutely is fast enough.
Fastify (JS back-end library) is faster than Spring
yes, but does not offer even 1/10th the features lol
It ihs not bad, but compared to stuff like go rust c or c++ it is kinda slow
its pretty hard to get meaningfully faster on a complete project stack than node with rust/c++. by that I mean, its very easy to whip up a benchmark that "proves" rocket or something is fast AF, but once you start getting into a full web stack with IO bottlenecks etc, they end up basically the same, but you'd spent a lot of time reinventing the wheel with rust/c++
I honestly use js for most of my automated tasks, i just find it way easier to write and debug
same lately. I only started TS about a month ago, but have been programming for about 20 years. I've very quickly learned why it is so popular
the "idea in your head" to "I have this working" time is insane
I don't think i ever used ts in a real project
I feel like it slow me done more than it worth
I am slow at typing as it is, i don't need to define every type to make my compiler happy
you can turn off strict mode. it'll let you be selective where you add types. I mainly just add them to enforce function param safety. but a good example of why that can be helpful.. I rewrote herobrine's chestUI code in TS, and it is about 60-200x faster depending on what you are doing because I could remove all type checking since I know for a fact that the types are sound. filling a 99 button UI with mine takes "0ms" with BS dateTime test, takes 60-200ms with default depending on if you use durability/enchant data
same
the only thing I find a lot helpful with ts is the suggestions when creating classes and functions because pure js will require you to either guess/check the docs/memorize what you are tring to do
UHH
Entity.setVelocity not exists?
Well if it does not, Is there a workaround of doing it?
applyImpulse
velocity is how fast they are moving and applyImpulse pushes the entity which increases their velocity
you do that by pushing the entity using applyImpulse?
mh
Entity.clearVelocity() exists if you need that
use jsdoc
They worship you like a god
How.. nothing against your Script but its basically a Set and a Wrapper class
I want rhis Attention as well
use TS, only advantages imo
you don't understand, this is very useful (no)
how much of your code is actually code
≥ 3/4
Rest are types and Interfaces
Or you can't take that OOP is much easier to maintain
Working with larger codebases is really hard if you're not using at least FOOP, which is also messy
Art of TypeScript is to write as less of types as you can
sound like js to me
JS is missing a lot of features that TypeScript offers
everyone and his need, if you feel like ts help you, that up to you
i see a lot of positives, but they are not worth the hassle
the hassle is paid back in development phase, where you catch bugs in the IDE directly
while you have to execute JavaScript code directly to check for even small crack-ups
you learn to catch small stuff quickly, it is not that big of a deal
after 2 years in JavaScript, I still wan't confident enough to catch more complicated bugs that early to fix them before testing directly
GUYS
I wrote a whole frikin PATHFINDING AI for my duck entity
It's not possible to make them swim using entity.json, So just made it using scripts
It ignores obstacles, Sets rotation randomly and smoothly, Goes into bigger areas of pond/river so they dont keep idling into a corner, The ducklings follow a duck , etc
When you say AI, are you using that loosely?
Imagine a big centipede tracking a player across a mountain
class ArrayBuilder {
/**
* @param {Number} defaultLength
*/
constructor(defaultLength) {
this.#defaultLength = defaultLength;
}
#defaultLength
/**
* @returns {Array}
*/
createNewArray(length = this.#defaultLength) {
return new Array(length);
}
}
Interesting
using hashtags as private properties
😭
It's easier to track errors in ts especially with OOP
that's what I want to say, but Serty is such a fan of pure JS with JSDoc
even the app they're using to write their JavaScript code is written in TypeScript
class ArrayUtils {
/**
* @param {Array} array
* @returns {Number}
*/
static getArrayLength(array) {
return array.length;
}
}```
Then there's also diff ways of code styles
Can I let player place blocks on my custom block without sneaking when the block uses a custom component with onPlayerInteract?
then you need to give up the custom component
and then?
reimplement your custom component to a regular listener
I have never seen a code like this
but which? ItemUseOn isn't there anymore
I have nothing against TS, I'm just used to JS and JSdoc, it's more convenient for me and I don't want to rewrite my entire project to TS. I'm just amused by how you turn 1 line of code into 10 because it's OOP
PlayerInteractWithBlock
jsdoc?
you just have to wrap few things into a class, it does not take that much effort
What JSDoc does TypeScript-powered JavaScript support?
the index.d.ts?
oh, thanks
Well, you can do as you like. It just looks like "ah, why?..."
it's harder to break things
Also when renaming a property, it's faster when it's OOP, especially when its all nested
Also a fact
hm?
this code looks like:
class VeryUsefulPlayerUtilities {
/**
* @param {Player} player
* @returns {Vector3}
*/
static getPlayersLocationUsingPlayer(player) {
return player.location
}
}
🙄
🙄
did he just try to access a property from an array?
Those comment types starting to annoy me when I'm coding too fast ngl
it takes even longer to add these comments than a single type
/**+enter
import { Player, type Vector3 } from "@minecraft/server"
class VeryUsefulPlayerUtilities {
static getPlayersLocationUsingPlayer(player: Player): Vector3 {
return player.location
}
}
What is the point of this
Why wrap an already abstracted class
ask @round bone
Also ive figured a thing
normally, this should work
for (const type of entityTypes) {
for (const e of overworld.getEntities({ type: type })) {
but this also works...
for (const type of entityTypes) {
for (const e of overworld.getEntities({ type })) {
won't work
oh hey, pyEnjoyer, Long time no see!
he is giving me unpractical reasons why OOP in TS is less practical than functional programming in functional JS
Hello
will work.
You showed a very bad example
just lyk
I didn't wrote this example by myself
do you think that I would create a wrapper for a single property?
@minecraft/server does not have Vector3
it does.
it's an interface
even in stable
No I'd assumed it would be scaled, but there is no reason for you to create a wrapper class over the already existing Array class
Then I don't know how it works... maybe I need to test it again
you don't have interfaces in JavaScript, that's why you don't know these things
It should work, It's TS only
ok then
I know, the array example is written by Serty, not me
Oh
then no wonder he thinks OOP is less useful
lmao
Yeah
I just don't understand why you have to turn 1 line into 10 just to make it a class
to make the code scalable
The point is to make it modular and scalable
For simple things like what you showed, its completely unnecessary
however if you have a system that in the future, you want to update/scale
then OOP is good for that
#1067535608660107284 message
functional programming can be scalable if done correctly
same with OOP
they are both good
guys stop ill break your code
class VeryUsefulPlayerUtilities {
static getPlayersLocationUsingPlayer(player) {
await null;
await null;
await null;
await null;
return player.location
}
}
That doesn't work when I use a hoe
got removed
Should work, There's a itemStack property, can you show your code?
Yes, and I use classes and everything else that JS provides, but not to copy the Set.has method
it does not copy Set.has method
it encapsulates translations keys out of a variable to a private static property
quite a long time ago ngl
It's been like
world.afterEvents.playerInteractWithBlock.subscribe((event) => {
console.log(event.itemStack.typeId)
}```
almost 2 years
it has been removed around 2 years ago and replaced with PlayerInteractWithBlock
Use beforeEvents if you want the code to work regardless of the block and item
- do you have your console set to log? or change to console.warn
- use ternary operators, its my practice 😔
- Use beforeEvent, That will work surely
thanks, now it works fine
By the way, the itemStack property does not always exist in this event.
Ahh I used itemUse recently
fair enough then
It still exists, don't worry haha
Very disgusting
asking for entityHurtBeforeEvent day 6422445801
I stopped using VS Code for development about 2 months ago for WebStorm and I feel that writing scripts in it is much better
I have professional version beacuse of GitHub Student Pack
webstorm has a really good debugger
Probably the best one out of other IDEs
Yeah for sure
Its extremely powerful
You can output a large object and you can search the object using the debugger
I used to use it to analyse mc packets
with bedrock protocol
bedrock-protocol is so weird sometimes
how so
not much documentation, code is written in JavaScript, I tried to add Snappy support, but the code is so messy I just dropped it
function Vector(x, y)
{
this.x = x;
this.y = y;
this.add = function(v)
{
this.x += v.x;
this.y += v.y;
return `(${this.x}, ${this.y})`;
}
}
const vector = new Vector(1, 2);
console.log(vector.add(vector));``` Would this be functional or OOP
xd
me when js
That's how I had to do OOP in school
in js???
Yes
no way
Yeah, I got some tasks on my private repo still
I was just messing around with things ages ago
and found I could do that
and I was like
💀
skull emoji'd in real life
This type of classes is the only thing that I learned from programming school
I still make fun of this to today
this is interesting but I have no idea how to implement it inside functions
can you give me some examples mk?
u mean jsdocs?
/**
* @param {string} s
*/
/**
* @param {string} parameter
*/
function example(parameter){}
👍
use ts and it will be 10000% better
I love the way you're forcing all of these people to drop pure JavaScript and move onto TypeScript
🍿 👀
same
use --experimental-strip-types flag or ts-node
same (but I'm just always lazy to do it)
Yeah, btw can't you just make these types interfaces?
Interfaces are a bit faster for TSC
Yessir
I started using back-end services as a database/caching stuff
Yeah I use an expressjs local server
which sends data to my db
then I just communicate between that and server-net
I was using Express.js, until I discovered Fastify
I do the same thing, just wrap request routes inside services
import { Vector3 } from "@minecraft/server"
import { AfterEventListener } from "leafpe/utils/events/AfterEventListener"
import { Dimensions } from "leafpe/utils/globals/Dimensions"
import { ServerData } from "leafpe/utils/globals/ServerData"
class WorldLoadAfterEventListener extends AfterEventListener<"worldLoad"> {
public readonly eventName: "worldLoad" = "worldLoad" as const
public onEventActivate(): void {
Dimensions.init()
const { x, y, z }: Vector3 = ServerData.ITEM_DATABASE_POSITION
Dimensions.overworld.runCommand(`tickingarea add ${x} ${y} ${y} ${x} ${y} ${z} item_database true`)
}
}
export { WorldLoadAfterEventListener }
Doing the same thing as you xD
Yeah
I have mine in my server initialisation method
I assume urs is also something like that
to call this
class
that initialises the events
😭
lmao
What are you using packet event for? Blocking crashing?
timer ac
currently
might see what else I can do
-# #useovertakes
Most of the anticheat for crashes etc is gonna be via a relay
Probably gonna make my reach ac with the relay aswell since
script API abit too slow
I wrote myself a BDS wrapper to get XUID and server usage via console/Node.js process
child_process?
Yeah
I did that aswell xd
I am using XUID as a primary key in my external database
That's why I need it
If I'm not lazy, I could make my own server software usable and be able to grab all that data easily
I'd just need to create all the packet implementations
which I dreaded
alot
I like BDS-ecosystem and I am staying with it
I am probably the biggest hater of PMMP and PHP
Oh yeah
that's why I made my server software in ts
Mainly cos its my strongest langugae
and 2. because if I use it
I can just
recreate the script API
and add extra stuff
to it
Reasonable
Scripting API lacks a lot of things, even a basic ender chest is not implemented
Yeah exactly
and alot of networking data
is lacking
I can't even clearVelocity on the player well
It hardly even works
as far as I'm aware
We are forced to use run-arounds
If I could get ping
it'd be so useful
for anticheats
like movement cheats, and reach
Yeah
I have to get their last 20-40 movements
and try to analyse it
to see if theres any inconsistencies
to determine whether they were lagging
Technically you can use Endstone to get these metrics, but you're getting a lot of bloat with it
during the "reach"
The timer anticheat I made I was actually quite proud of
I made it a 3 stage system
to prevent false flags
and it worked perfectly
detected 1.01x >=
with no false flags
Then I changed some values and now it false flags
😭
I'll have to implement my own anti-cheat soon aswell
BDS now have authoritive-moment option and its working pretty well
but it's really intuitive statistics
I'm going to 11th class after vacation
oh yeah I noticed
when I was using timer
but u can still use like
1.05x <
I barely have learned any advanced math
i am going to 1th grade on university 💀 😭
thats pretty much free time killer
1th
its all good
I'll be on university in 3 years
I hope that PHP will be boycotted by this time
PHP is so over-used, idk why even PMMP is done in PHP lol
I hate php
i mean the performance is worse than most of the JS engines
yea doesn't make any sense
also officially its called element offset indexing
ahh thats why JQuery is the way it is
Another piece of devil
You CZ keyboard layot
At my work experience, they told me to use php
and I said no
Only because they dont hold the cards
if it were an actual workplace
I'd have to say sure
💀
🍿 👀
imma learn Zig with free time i have, its really nice language
its basicly new era C/C++
i know nothing
thats good
I probably need to switch to software development/data science, beacuse I am colorblind and I have to drop front-end related stuff beacuse of it
🙁
i wish i could learn C , C++ , java, and rust
i will learn them whjen i get bigger in age
programming is love
front-end is too over-reacted just focus on backend man
I am already focused on it, but I won't be working on front-end without any designs beacuse of my colorblind eyes
there is no need to learn rust, its the last thing you should learn
unless you do some security shit
JS , TS - for bedrock edition scripts
java - for making java edition mods
C, C++ - i am also interested in making windows applications and tinkering
rust - uhhhh its cool - "says yall"
I hate front end development
it scales your executables to exremely large files just bc its "safe"
Replace Java, with C#, C# is actually good language
its really similar
I was doing React when I was 13 xD
rust developers when they realise you can make shit "memory safe" by using smart pointers in c++
I started with programming from 13 actually
nah, we are talking about the compiler it self yapping at you if you don't follow that a$$ strict rules
even now , i dont know abot react
Few days after my 14th birthday, I got diagnosed with colorblind and by this time I just learned Tailwind CSS and Next.js/Vite, and I dropped more front-end learning
Oh yeah
lol
how old are you now
also compilation time of rust is crazy
16
thats good
i started batch programming at 11 bc if my dad 🫡 🇨🇿 , he just said "Hey son, look i can do this cool shit" and i was like, ohh damn i want to do that too
It's almost my 3 year anniversary
og
of programming
I randomly discovered Python Compiler Online, then wrote few programs in it, then I dropped for a bit longer time (in 2020)
In 2021 I started playing Mimo with my friend, a simple game that's learning you full-stack development, Python and SQL, and I had really fun time while playing it
So I started coding even more
And that's how I am here
I already knew basics of JS before I started learning scripting API
me from redstone, cmd blocks, functions, bp/entity files, to scripting
Here's my history
My dad used to do his office work on a Shit 2010 pc, And i used to watch him , So he teached me about computers (mostly just refreshing 100x times lmfao), then i knew about minecraft from youtube, tried downloading Java Edition, but understood i can NEVER. (how could i expect to run java edition on a 2010 pc???), then knew about bedrock edition, Saw that it can run smoothly on my shit pc. Then played all time, Then at a time, I saw about addons, It was frinkin cool, thought about making them (but couldn't actually, i just used to download addons and look at them, combine those addons), i eventually then watched addon tutorials, those old ones really didn't help, then ever since Script API dropped, i saw its MUCH easier. Then i got into it and i'm here
I was also doing command blocks back in 2020-2022
That reminds me actually I used to be good at cmd blocks back in like 2020
d
xd
what sparked me was the cheaters/hackers in our survival server
Bedrock is much more optimised than Java in my opinion
back when nbts were a thing
?
ye
That's why i got here
still much more freedom on java tho
everyone started with MC i feel i am really Alien
i touched mc java, but my laptop was dying, so nahhh
I find it funny how I found my passion for programming because I wanted to make a kitpvp realm 💀
i started mc on family smart tablet
pe
The same console that has been raising me up for the last 12 years
I won't I have tried it before
I am already compiling my addon and now I have to compile my script
u can use npx tsc --watch
it's too tedious to compile ts -> compile addon -> reload
add script compilation to process of add-on compilation
I'll do it in the future i'm too lazy as of now
It will autocompile it
its like js
u can just write the code
it compiles for u before u even get to mc
then u can reload
I see, thanks a lot for the recommendation I'll definitely take note of it
Guys, I am wondering if there is a way now to detect if a player has fully loaded a world? Without timing the execution of a code?
Add a global variable isLoading = false, on worldLoad event set it to true
I could've worded my question better, does that executes if the player is in loading screen? If so, that is not my goal
No
It doesnt
when tho? we'll be in same classes basically. might as well catch up to u.
im going 10th class after this year
On september.
1st
hmm. u r 3 months late, yeah.
😭
just 🥱
I live in Poland right now, you are probably living in south countries
ye
did you move from somewhere?
I have been in few countries in my childhood
And I am facing some issues with polish because of it
How to manipulate int properties using script?
What do you mean by integer properties?
"example:example": {
"type": "int",
"range": [
0,
20
],
"default": 0,
"client_sync": true
},
}```
entity properties
entity.setProperty('example:example', 3);
You can use Entity.setProperty method
THANKS
And Entity.getProperty
Is it possible to replace one script by another via subpacks?
I have a ts file that can only return true or false and I want to change it depending on a subpack player has chosen
You might wanna wait for manifest v3 for pack options.
Are they gonna drop it soon?
It's currently in Preview only.
Haven't heard of it before
When was it added? Are there any docs?
Yes.
what
What?
I've posted a bunch of examples in #1019665690233405500
sorry, i was just concerned
is it a system or world event?
or something else
is it possible to inform the player you need another addon using script?
You can add a dummy item in Add-On B and if add-on A does not detect that item then send a message.
i see i dont understand that xd
i do and dont
so i add a item from the addon thats needed?
Yes.
okay? how do i detect it if its not installed?
Documentation for @minecraft/server
ty i have to keep telling people my dlc addon isnt to be used a standalone they need the main addon to work
Can't you add a pack into dependency array?
Or it's working with RPs only?
RPS only
Oh, kinda sad
its reduce space and file size
BP works as well.
You can yes. But this solution also ensures in case one somehow downloads without both packs.
no i meant my addon doesnt work without the other addon
pick the id of an item from your main addon and just
try {
new ItemStack("zach:main_addon_item")
} catch (e) {
world.sendMessage("This is a DLC, you must have the main addon applied to this world.")
}```
alr
you can also search the id in the itemTypes and throw if the script couldn't find it
well well well
hi, i got slept last night, but why was my messege deleted?
How do you check if a chunk is unloaded?
i know you can try to get a block at a location & it will return undefined if chunk is unloaded, but iterating on a bunch of blocks is awful for performance.
I need to check if any of the blocks in a volume are in unloaded chunks
world.beforeEvents.playerInteractWithEntity.subscribe(({ player, target }) => {
if (target.typeId !== 'minecraft:player') return;
system.run(() => player.runCommand('scriptevent leaf:open stats_viewer'));```
soo
get a block on that chunk
try getting the topMostBlock in that location, if it returns Y 320 then its unloaded chunk
for every block on the border of a volume? not very efficient...
I was hoping for another solution if there is one
oh you want to test an entire chunk, I thought just 1 block is enough, I mean you can check the 4 blocks on the side of the chunk, won't that work?
im working with an arbitrary volume of any size that can cover one or more chunks, I thought that i would have to iterate on every block in the volume. But I realize now I can iterate on a wildly smaller array of chunk positions instead of individual block positions
mmm so simple yet i somehow didnt consider 🧠🔨
Hello, how to block /kill for a specific entity?
I won't eliminate entity by /kill @e or /kill Custom:entity
Please help 🙏
Set minimum health value to be 1
Half health?
just know that the only way to get rid of your entity after that would be despawning it (or using .remove() in script api)
The "min" value inside the health component
it wouldn't kill by /kill ?
yes
would it still be killable?
no
how do i use player.playerPermissionLevel
it seems to not be working
i tried
if (player.playerPermissionLevel == "operator")
oh wait nvm it's an int not a string
immortal then?
yes, unless removed with remove() or despawned
I see, thanks
dang, I thought Custom Slash Commands are stable
Is there a way to make ui intern stuff translatable in the en_GB.lang or de_DE.lang file?
in lang files in general I mean of course
just use rawMessage with the translate key
How? Just put in aaaa.ksk.ls instead of "Aaaa Ksk Ls"?
How to define rawtext in script?
How does it need to be formatted?
Ty!
Ty too!
Why does it throw that error at the THOMAS line?
js form.textField("Na", "Aa Be Cc", "THOMAS");
You have to pass an object
form.textField("Na", "Aa Be Cc", {
defaultValue: "THOMAS"
})
Thank you 
No problem.
Why is this not possible?
{rawtext: [{ translate: "ui.button.idk" }, { with: { rawtext: [{ translate: ["ui.button.idk.amogus"] }] } }]}
[{translate}, {translate}]
Assuming translate is string
hey💢
Does someone have vanilla PvP knockback replica
Like real vanilla PvP one, very similar
Or one similar to hive or cubecraft
I don't know what you mean, but it works now
thanks
By command also?
By /kill command, it will killed?
no
With command also it won't kill
?
no...
By command will it kill?
wtf man
Just kidding 😂

Btw thank you for clarify
np
Why does it say /content/0/default and /content/1/default, expected 'string' received 'object'? The translated text should be a string (it is a string) and at other places in the code translating in buttons or titles (forms) works flawless.
default value cannot be a raw message. Like it says, it needs to be a string.
Damn, alright thank you!
Why does this in MessageFormData show [object Object] instead of the translation file text?
form.body({
translate: "ui.waystone.teleport.confirm"
} + " " + requiredPoints + " " + {
translate: "ui.waystone.teleport.confirm_1"
});```
Or can you like insert variables from the script into the translation?
{rawtext: [{translate:'ui.waystone.teleport.confirm'}, {text:' '}, {text:requiredPoints}, {text:' '}, {translate:'ui.waystone.teleport.confirm_1'}]};
you cant add strings and raw messages like that
define an array of rawmessages insetad
@silent Damn thank you 
Oh sorry for the ping
Thought I'd turned it off
console.warn(itemStack.getTags()) // "ore_detector"
if (!itemStack.hasTag("ore_detector")) return
How am I getting false from if case, when the item has a tag
It appends the minecraft namespace.
Why are you not using a namespace for your tags?
Do I have to use namespaces for tags also?
Didn't know, I'll add them then, thanks
Yes. You SHOULD be using namespaces.
I thought that I can use tags without namespaces
I added a namespace in every single place of my pack, except item namespaces
player.stopSound("ambient.nether_wastes.mood");```
Why does it say invalid function (I'm using 2.2.0-beta
Or is it removed already?
It exists, but are you positive you are calling that function from the correct object?
Yeah, the same with play instead of stop works perfectly fine in the same context
Hmm, then I got nothing. Best I can say is share your code in #1067535382285135923 by opening a forum and get some more in-depth help there.
Ty