#Script API General
1 messages · Page 105 of 1
Is it possible to create custom death message when player dies by script like applyDamage ?
No.
Sad
does this only work for players?
Since equippable dont work well with non-player entities, so yes
Toughness is from the netherite, from what I've recently observed
yeah
Dumb question. is there anything weird about the custom commands like cant run on single player or anything?
Make sure the registration happens at startup
Maybe playercommandpermission issue?
Is ther a good way to see if registration happens?
Uhm, can't test atm
But u can see the difference that it appears doing /
i will fiddle a bit. i found one issue... i screwed up the manifest and it unloaded my pack from the world and i was testing without the pack on...
okay figured it out
uhh why entityHealthChanged .newValue print a lot of decimals for player?
world.afterEvents.entityHealthChanged.subscribe(ev => {
const entity = ev.entity;
console.warn(entity.typeId + ': ' + ev.newValue);
});
Yes
Because Minecraft
you can always round it up
const roundedValue = Math.ceil(ev.newValue * 100) / 100
I have 7 more.
Ohh okay, good to know
You are not a cat.
I always been a cat, you're just uninformed lmao...
me everyday:
he sacrificed his lives for script api features
Installation for @minecraft/server
Latest API module install:
npm i @minecraft/[email protected]
Beta API module install:
npm i @minecraft/[email protected]
Preview API module install:
npm i @minecraft/[email protected]
Preview Beta API module install:
npm i @minecraft/[email protected]
because javascript only support float64
we have no access to the internals of it, so theres literally no way to know if on minecraft its treated as a integer or float
but by default it will have some precision cost
is there a way to hide the commands with namespaces
"cost"
That’s the raw value btw, we usually see its rounded value
so minecraft interprets health as float?
wtf do the developers have in mind?
0.1 hp is still half heart
health in float is cool
weird as fuck
at least if it was an integer it would be inconvenient
how exactly?
it would be more precise
for example, you couldn't smoothly regenerate HP or take it away
I especially need this very much
but why exactly you couldn't do so?
and float has no downsides
0.1 + 0.2 == 0.3
Aand?
and what?
What do you mean by this?
you wanna know about how much cycles a cpu uses to make math on floats as well?
bits don't mather
in JS all numbers are float so it doesn't matter
i just showed you a downside
+0.000001 ms slowdown
very scary
if health was an integer you would have to create workarounds to make it a float and that would be much less performant
i could be unfair and simply say "+0.00001 ms slowdown". anyways, i mean, what is the cause of the problem? you saying what will happen but not why it will happen
there is no problem. there WOULD be a problem if health was an integer. but otherwise everything suits me
i think i mispelled. i mean, why would it be a problem to do that you said if health was something like uint32
math is faster with integers, that's right
but we are in channel that uses 💩 JAVASCRIPT
and it's the same piece of shiii.. for engine
the problem would be that it's an integer value. for example, you want to make a sword that restores 0.1 health to you on impact, but if health wasn't a float, you'd have to write extra lines of code... and I'm not even talking about the basic armor system
ah, that makes sense
you have a question like "why not use an integer? and it doesn't matter that we need a float"
is there a way to remove the namespace for the custom command?
afaik, we get two version of the same command, one WITH the namespace and one WITHOUT it.
so why would you exactly need to remove the namespace when u have one without it?
np
is there a list of blocks/items/entity param in minecraft/server
yeha
itemTypes, entityTypes, blockTypes
yeah
it's performance intensive though so try not to call it very often
save it on a variable on startUp
or something
got it thanks
last thing how can i use the localization key for my form button text?
use rawMessage instead of string
any sample snippet of it?
const form = new ActionFormData()
.button({ translate: item.localizationKey })
is there a way to control entity gravity?
no, u gotta learn bedrock physics 1st
You can simulate it with applyKnockback but I don't believe its possible
Might be easier to write your own physics engine, honestly
Simulating custom gravity is trivial when you are fully in control of the acceleration
Then, knowing the position of your simulated physics, you could simply /teleport the entity to that location.
Does anyone know what the conversion from applyKnockback to blocks per second is?
And the conversion of applyKnockback horizontally to applyKnockback vertically?
Yo someone can tell me if herobrine made a chest ui where u can see ur inventory that updates
the only thing i know is that(if nothing has changed) on applying a vector V, the distance the player will travel on the x z axis(ignoring gravity) is around of |v| * 0.8, but it can vary depending on the friction of blocks and, well, gravity
Chest UI is ActionForm under the hood afaik
@valid ice Let me ping for confirmation
Meme of the week - 1
I think herobrine made a chest ui where you can see your inventory
Ikik i was just asking for the github
For this version
of the chest ui
My chest ui is broken
It shows random textures if i usa the item id
umm, is this even a thing?
if (player.isSneaking && whatever else) {import 'something' from 'other script'}?
Why would you need that?
start running the other scripts only when needed,
Is it extremely taxing on performance that you really can't afford for it to run at all times?
look, i dont want to run unnecessary scripts all the time,
There is, kinda. Dynamic imports
I would not personally use it in this way, as an action as common as a player sneaking is not a good use for dynamic imports
like the other script detect whenever the player break a block, i dont want to call that all time
I think this just means you need to restructure your code a different way then.
You could choose to selectively subscribe or remove subscriptions depending on when they are needed
look, i am making a core addon, an addon that will have the scripts && functionality of all addons i have (to make them compatible and using only one runInterval for all of them)
so i made a system that i can detect if the addon is activated or not inside the core addon
so all i need to do next is turning on the addon functionality only when the addon is activated
like:
if (addon === true) import 'smth' from 'addonScript';
i just want to know if that is a thing or not
located inside a runInterval, runs every tick
like it doesnt have any delays i believe
anyways u get the point, i am doing that for some kind a better performances or something
I getcha, I see the vision. There are dynamic imports, but there are drawbacks to these—they are asynchronous. Makes more sense to simply export a function that does your event subscriptions when invoked
So instead of dynamically importing a module where you have event subscriptions at the top level, you could export a function that subscribes to those for you
i see, how tho?
block-breaking.js
import { world } from "@minecraft/server";
export function enableBlockBreakingFunctionality() {
world.afterEvents.playerBreakBlock.subscribe( /* ... */ );
}
main.js
import { enableBlockBreakingFunctionality } from "./block-breaking";
if (whatever) {
enableBlockBreakingFunctionality()
}
i see..
so basically i need to put the whole addon functionality inside a function and run it only when needed?
Yeah, like C-style programs in a way
Have a "main" function that serves as the entry to your program's logic
Is there a way to make it so that when the player moves it runs the command. and tp an entity and this entity will face a direction
const movement = inputInfo?.getMovementVector();
const threshold = 0.5;
const movementX = Math.abs(movement.x) >= threshold ? (movement.x > 0 ? 1 : -1) : 0;
const movementY = Math.abs(movement.y) >= threshold ? (movement.y > 0 ? 1 : -1) : 0;
if (movementX !== 0 || movementY !== 0) {player?.runCommand('say You are moving};
-# detecting if the player is moving or not
Thask
Slightly better way to detect this:
const movement = inputInfo?.getMovementVector();
if (Math.fround(Math.hypot(movement.x, movement.y)) == 1) { /* ... */}
can someone explain how you make a discord bot that sends your realm stuff to discord
Out of scope for scripting.
isn't it to do with a script module tho?
btw, what should i use to detect when the player jumps? bec player.isJumping isnt working properly, like holding the jump button will keep increasimg my dynamic property value,
maybe isJumping and isOnGround somehow?
that could work but, i can see how buggy it will get so i need ot figure out a better method
onPlayerJump or something idk
-# i know that thing doesnt evem exist
player.inputInfo.getButtonState('Jump') == 'Pressed'
Alternatively, we have the playerButtonInput after event
well, will that detect whenever the player jumps? like i know it will, but i mean inGame when u keep jumping under a tree for example or hold the jump button
it activates everytime the jump button is pressed
i know that,
what im trying to do: detects when the player jump, not detecting the button or isJumping things
i dont think that is possible tho
if u look at the player exhaustion value while jumping, u will know what im talking about
im talking about this thing
how the player exhaustion value increases only after jumping
recreating the vanilla exhaustion thing for my addon
then you should just use a system.runInterval
making it works similar to it
If you can directly read the exhaustion value, there's no reason to try and recreate it
that is an option, but that will make the thist bar connected to the hunger bar in a weird way
like getting hunger might affect the hydration bar too
ill try this ig if (player?.isJumping && player?.isOnGround) {***}
wouldn't you want saturation to also affect the hydration bar though?
and i know it will be bugged if u are not jumping due to standing under a block
jumping and slamming your head into a block above you would be pretty exhausting
as u can see, it works but bugged while standing under a block
yeah, idk why you aren't just reading the players exhaustion numbers
but if you really want it to be separate I guess you could check if there's a block above the players head
that would probably be easiest
for this reason
because of the effect?
above/in the player head
yeah, the hunger effect will keep increasing the exhaustion value and making u dehydrate
and u know what, that sounds good lol
like drinking dirty water will affect ur hydration and hunger
U can only change the callback in /reload,
As for that error usually needs world restart
yes, i will be doing that, it will save me tons, tons of time
Oh okay
My dumbass really thought .filter() is broken. I did this js .filter(e => e?.id !== player?.id) confused why it ain't working and I just realized it's e.entity.id not e.id... lmao
btw, how does this math mathing?
20 * (Math.floor(Math.random() * (8 - 4 + 1)) + 5)
i think i get it
Guys quick question, whats the difference between setProperty and setDynamicProperty? :p
set property is entity properties you can check docs for more information while dp or dynamic properties are scripts native only and it can't be accessed outside of scripts...
I don't know, I don't have enough context for that shyt.
Imma guess that's health since 20?
properties is also useful on RP or client entity,
20 ticks

20 * (Math.floor(Math.random() * (max - min + 1)) + min)
Thanks!
and it's used for what...?
what if i have an additional text like for example, This item is called item.arrow.name
it only translates for me when value is localization key alone
rawText?
potions duration or amplifier, i wasnt sure how it works so thats why i asked u
but now i do understand how it worls
yes. You need to separate the rawtext for translate and just pure text only
got it thanks
one last thing, how can i retreive the information of an item like i will provide its type id, and retreive its localization key?
Documentation for @minecraft/server
i mean for entities and blocks**
RawMessage samples:
{rawtext:[{text}, {translate}]}
{text}
{translate}
got it
Sth like magic when ur in void, where lota possibilities r flowing and u don't wana unsub
I was kinda bored and I couldn't fall asleep, so I am using my brain to eventually start sleeping
https://stirante.com/script/server/2.3.0-beta.1.21.110-preview.22/classes/Entity.html#localizationkey
https://stirante.com/script/server/2.3.0-beta.1.21.110-preview.22/classes/Block.html#localizationkey
Documentation for @minecraft/server
Documentation for @minecraft/server
thanks so much
can i make it something like new Entity(typeId).localizationKey?
because i was only given with type ids by EntityTypes and BlockTypes
No, since the localizationKey property requires the Entity, Block or ItemStack itself.
for the entity summon them first then remove them, for item stack try making a constructor then do it.
EntityTypes.getAll().reduce
spawnEntity().localizationKey
remove()
Tbf, the localizationKey should be in (Entity|Block) Type
IDK for blocks tho, I guess you need to place them first.
you can scrap all of them via a simple script and have them ready-to-go
just did trimming of minecraft: and adding tile.---.name in between. thanks yall
It doesn't work for a few
Is it possible to get the name of a block? not the type id?
Flat out name itself not localization?
idk what you mean but i think either or
Block.localizationKey returns the id used in lang files...
Just translate it with rawtext translate...
ah
.
.
.
refer to this three messages I replied to
do you guys know how i can get a player's equipped armor and use it as a server form button image?
u probably have to do some large switch statemnt
like
const chestplate = player.getComponent("minecraft:equippable").getEquipment("Chest")
if (chestplate) {
switch (chestplate.typeId) {
case "minecraft:diamond_chestplate":
// use diamond chestplate texture
break
case "minecraft:iron_chestplate":
// use iron chestplate texture
break
// etcetera
default:
// not a chestplate
}
}```
I might have a script with a pack that maps to item texture, if you’re interested
how does it work?
Basically an item render in textures folder, then a json file that maps item id to texture path.
sure :))
can you import json into scripts??
i thought u couldnt
RP download: https://www.curseforge.com/minecraft-bedrock/addons/minecraft-statistics/download/6810276
Bundling. Otherwise just convert into a js file
thanks!
by default not, only via bundlers
how can i get all entities in another dimension? i can’t get entities in the end if I’m in a different dimension
world.getDimension("the_end").getEntities();
world.afterEvents.itemUse.subscribe((ev) => {
const item = ev.itemStack.typeId;
if (item !== "minecraft:stick") return;
const overworld = world.getDimension('overworld');
const theEnd = world.getDimension('the_end');
if (overworld) {
const endermen = overworld.getEntities({ type: 'minecraft:enderman' });
if (endermen.length > 0) {
console.warn(`- Overworld has ${endermen.length} enderman(s)`);
} else {
console.warn(`- No endermen found in Overworld`);
}
}
if (theEnd) {
const endermen = theEnd.getEntities({ type: 'minecraft:enderman' });
if (endermen.length > 0) {
console.warn(`- The End has ${endermen.length} enderman(s)`);
} else {
console.warn(`- No endermen found in The End`);
}
}
});
probably they are unloaded?
does the dimension unload every time I leave it?
*chunk in the dimension
is it possible to check if a block is transparant or not
like false for stone dirt etc , true for flowers torches
how to make sub commands for custom commands like 'time set' and 'time add'?
the first argument is neither an enum nor string
is it even possible?
If you mean changing command arguments depending on the previous ones, then this is not possible yet.
maybe block.isSolid...
what item component trigger itemStartUse and related events?
it would work but its still on beta
in my case i am not trying to change the arguments, i am trying to make a command similar to the /recipe command but for my achievements system
i ended up splitting it into 2 separate commands
well in that case you can just use enum
well, yeah, but since i can't make it match vanilla commands anyways i might just split it
system.beforeEvents.startup.subscribe(data => {
data.customCommandRegistry.registerEnum('my:action_type', ['give','take']);
data.customCommandRegistry.registerCommand({
mandatoryParameters: [
{
"type": CustomCommandParamType.Enum,
"name": "my:action_type"
}
]
});
});
try use modifer or if that doesnt work then the food component
but why? if you don't want to change the arguments then you can do it like in vanilla
not exactly, type the /recipe command and your custom command and see the difference
hmm ig. i wouldn't have asked if i weren't that lazy lol.
well. it turns out /recipe <give/take> <playerSelector> <string>
the arguments do not change depending on the previous ones.
so it is possible to repeat it completely
just repeated the command /recipe but for my achievement system...
ah, well... it doesn't affect much..
i guess it's fine
i have seen CustomSpawnRulesRegistry in the change logs of 1.21.100, what's that about?
Not useable.
well, how can i detect when the player joins the world to do something for that specific player? like not playerSpawn bec it will trigger every time u respawn
maybe playerJoin and add getAllPlayers inside?
lets give it a shot ig
Use playerSpawn and check for initialSpawn
initialSpawn = false;?
!player.initialSpawn
umm, i just need to put that inside the code? like:
world.afterEvents.playerSpawn.subscribe(({player}) => {!player?.initialSpawn; otherStuff...});;
i just didnt get it, lol
Please read the docs.
Refreshing actionforms? Is there a way to close them?
yes
How?
import { uiManager } from "@minecraft/server-ui";
uiManager.closeAllForms(player)
Thanks
Would this work on chest ui too?
ye
Ayy tysm
havent tested tho, but since it uses forms, then it should work
yes
btw, what is chestUi?
Herobrine643928/Chest-UI https://share.google/fnjkoDktI2DE96dz3
@untold magnet
ohh i see, modifying the formUi to look like a chest with interactable items inside, like click on that item to sell all cobblestone u have
world.afterEvents.playerSpawn.subscribe(({player}) => {
if (!player?.initialSpawn) return;
//otherStuff...
});;
i trued it, it wasnt working so i used this:
world.afterEvents.playerSpawn.subscribe(({initialSpawn, player}) => {if (initialSpawn) {***}});;
and it works
if (!player?.initialSpawn) return;
is writing same as
if (player?.initialSpawn) {}
initialSpawn is not connected to the player, thats what the docs said
like the playerSpawn thing has initialSpawn and player,
What?
player.initialSpawn??
"initialSpawn is not property of the player"
Yeah true.
thats why i was confused in first place, SkibidiStack said !player.initialSpawn and the docs said something else
Would it kill you to read the docs?
i was reading the docs while i was asking u
-# me to my friend every minute@civic nest
at least its working now
I might add two commands to our bots just for you, lol
Can we make command errors only appear in chat and not the content log?
If i use throw in a custom command it sends a red message in chat and a content log error, is it possible to stop the latter?
btw, the effectiveMax of the player exhaustion is 20, then why when i try getting the currrentValue it will reach 4 and decrease the player hunger? isnt it supposed to be 20? why is it set to 4?
Idk what this means.
player.json: "minecraft:player.exhaustion":{"value":0,"max":20},
script: console.warn(player?.getComponent('minecraft:player.exhaustion')?.effectiveMax) returns 20
so the player exhaustion should decrease the player hunger only when it reaches 20
it should be 4.
but when u doconsole.warn(player?.getComponent('minecraft:player.exhaustion')?.currentValue) it will reach 4 and decrease the hunger
🍿 👀
so report it as a bug.
I lowkey don't even know what exhaustion is.
like u have to use currentValue * 5 in order to make it 20
Yeah, it's saying it can be a max of 20 but it will start decerasing hunger at 4.
Not a bug.
hm
The wiki even shows it can go over 4 and this lines up with how it works in game.
got it
i see, then why is the effectiveMax set to 20? for better calculations or something?
Effective Max is just saying the max it can reach is 20.
That's all it is saying.
i see,
happy that this is now stable
Can someone help me make a loop that goes through all the chunks around the player starting from the nearest chunk and stops once it hits an unloaded chunk?
That just sounds like math. 2 for loops for x/z, increment by 16 and use getBlock
Just make two loops that goes over every 16 blocks, getBlock, if undefined then its unloaded.
Not that hard.
i was thinking of creating an empty array, run some nested for loops to push chucks to it by incrementing then decrementing 16 then use the array sort method to sort them by distance from the player, but the loop will halt as soon as it hits an unloaded chuck leaving potential loaded chunks outside the array.
I mean, what are you trying to achieve? You could easily just hardcode it lowkey based on simulation distance.
i have a slime chunk function, i wont to create a command to find the nearest slime chunk from the player location
I see.
now i think about it, i don't even need the chunks to be loaded
Since slime chunks arent seed based, why not hardcode it?
i already have the method that checks whether a chunk is slime or not, it's the math part that triped me off
also this idea involves creating a big array in one tick while i want to iterate chunks one chunk per tick
You could use runJob
runJob is not 1 element per tick.. but it's a good option
You can use waitTicks in it.
That's what I mean.
i was thinking of using system.runInterval until i hit an unloaded chuck, but i will still have to create the array in one tick if i go with my method, because the array needs to be sorted
realistically the player will never hit an unloaded chunk before hitting a slime chunk but i still want to prevent an infinite loop situation
It could be possible on sim4 where you don't load any slime chunks.
since i don't really have to worry about unloaded chunks i guess i could hardcore a sorted array of all the chunks 1000 blocks around the player and system.runinterval through it until the player hits a slime chunk or reaches the end of the array somehow
but i really don't want to put a large ugly array in my code
Can you compare two chest inventories?
You could probably decompile java code and see how the locate command works and base it off that.
you could loop through the chests slots
are you using the isStackableWith() item method or just comparing the item ids?
That actually depends on what you mean by compare. If you want exact slot/item then yeah you have to loop. You could use Container.contains if you want to check if they contain the same item period.
Nice thank you
I wanted to see if two chests had the same inventories, amount and id
yes, you are still gonna use a loop to go through the slots and compare the amount, but i wanted to see if you know about the isStackableWith method which is more selective in comparing between items
Thank you
is there a way to display new text below the player name without modifiying nameTag?
this is what AI came up with, i think it's brilliant
Yeah, arrays arent the only data structures.
it even generated the js code for it
.-.
why is it in Spanish
there is an optional language, it uses google to translate (english is the default)
oh so u can request a template with its comments in your desired language ig
yeah
i used the same algorithm for implementing batching on a renderer
I am waiting for update in DSA that will add non-binary trees and implement non-binary searches, which will be faster
-# It's a joke, I am familiar with DSA
oh did you use 4 direction in a layer or 8?
no, i had to get elements in order on a tree so i could align them to batch then
ah, you didn't use it for a grid like i did
is it possible to get the amount of custom items (not vanilla ones)
no, it was for an N-ary tree
https://github.com/cykna/hyst/blob/reimplement_render/hyst-engine%2Fsrc%2Frendering%2Fui%2Fmod.rs#L117-L164 the code anyways
wasnt made by me but a friend
the project is discontinued, i realized that implementing a 2D renderer is damn hard
and i was doing it the wrong way
amount in a stack or what?
the amount of custom items that were added in minecraft
ig there's a way but I'm not sure if it would even work
ItemTypes.getAll().filter
Yup
can i get latest vanilla item id list by scripts
ItemTypes.getAll() this returns a ItemType[]
i mean not type id but the numerical ones
?
like this ones
huh ive never seen those
can be used to render in aux
Herobrine had one in his chest ui ig.
Ig thats what u r looking for.
yes exactly but i need it in updated version cus seems like theres new items were added in 1.21.100
you would have to work a little for that.
its just i dont know what were the new item's IDs
Idk either
can we give a vanilla item an enchantment glint without enchanting it?
itemTypes have namespace?
yes
How can I make an item not lose durability when hitting entity?
Repair item every single 5-10 seconds
Just set item's durability damage to 0 and replace it
system.beforeEvents.startup.subscribe((initEvent) => {
initEvent.itemComponentRegistry.registerCustomComponent("mevo:durability", {
onBeforeDurabilityDamage(event) {
let { attackingEntity, durabilityDamage, hitEntity, itemStack } =
event;
durabilityDamage = 0;
}
});
});
Should I replace it after making it 0?
but I think you need to do event.durabilityDamage = 0, and not durabilityDamage = 0
Didnt he do
let { durabilityDamage } = event;```
i want this script combo
this won't work
you gotta change the value from the source
because of the reference
event.durabilityDamage = 0
Yes
so you create a new variable, and when copying values from another variable you get a reference to the original value only if it is an object. And if it is a primitive (string, number, boolean) then you get a clone of the value and their changes are not reflected in the original
Yes
#1067535608660107284 message 🙄
I like how I spent a lot of yesterday (I wake up at 11pm-1am due to work schedule) trying to think of ways to disable game interactions that I didn't want (enchant table, anvil, armor stand, etc) just to think of a solution within a minute of sitting down today lol. I know the obvious answer is to check the typeID in beforeInteract, problem with that is that that still runs before and takes priority over item custom component onUseOn. Solution was to stop using an item component for the check, move my harvesting function call to vanilla events, then just blanket blacklist everything before the function is called 😅
Nice it’s work
Now just need to think of a way to still allow players to use chests without being able to get unobtainable items like enchanted diamond equipment from the End and deep dark and unfortunately I think the only way is to remove those items from loot tables. I don't like that approach though because it requires manual review with each game update (for example if I made my pack before trial chambers released I would now need to check if trial chambers introduced any way to get unobtainable items)
why not use entityHitEntity rather than an interval?
Plug it into a listener, then check if item was repaired in last 5-10 seconds
I didn't mean to use intervals
oh I see
event listeners are more performant than runIntervals right?
import { world, EntityHitEntityAfterEvent, Player } from "@minecraft/server"
const lastRepairs: Map<string, number> = new Map<string, number>()
world.afterEvents.entityHitEntity.subscribe(({ damagingEntity: player }: EntityHitEntityAfterEvent) => {
if (player instanceof Player) {
if (lastRepairs.get(player.id) ?? 0 >= Date.now()) return
// repair action
lastRepairs.set(player.id, Date.now() + 10_000)
}
})
depends on the case, but usually yes
:)
I want script combo
upload it to streamable.com
Is there any existing lib that has java edition's ResourceLocation builder functionality?
Mind telling us what that does for those who doesn't have the decompiled code?
It just builds resourcelocations aka identifiers like minecraft:something
There is the BlockTypes.getAll() if that's what you mean?
Nope, I want something to make identifiers. I don't like how raw strings look in my code
There is the VanillaData then.
It's not something crucial, just a matter of habit
You can do MinecraftBlockTypes.AcaciaButton for example. Only for vanilla hence the module name.
This is not quite what I need. Alright, then I'll make my own implementation

new ResourceLocation(<namespace>, <value>) - that's what I needed
Yeah, we don't really like to implement Java modding implementation lol.
NP, as I said, this is not crucial
when will they release applyImpulse for players 😔 im so tired of applyKnockback
it is already available afaik
idk if it's still on beta
What would be the difference between Impulse and knockback?
detecting the potion type is stable on the next stable update right?
dunno if this might help. I use some of resource location syntax like at https://mcpedl.com/minecraft-statistics/
there is no beforeEvent for placing blocks...
PlayerPlaceBlockBeforeEvent
world.beforeEvents.playerPlaceBlock
that's not in stable
If you are forced to use stable, there's no other solution then
well, it might be stable after 2 stable updates
Is there a way to apply infinite effect to a player via scriptapi?
Something like duration.infinite
They havent added support for that yet so you need to use runCommand.
Is it possible to add/remove entity component groups via scripting?
Not really, you need to trigger events which add/remove CGs.
I need to convert baby mob to an adult and vice versa. There's an event that removes baby component but sadly there's no event to remove adult component. Any other ways to do that?
Without editing the JSON? No not really. Unless you delete the entity and spawn the baby variant.
Ok.. if this is the only way
I assume not but is there an equivalent of the /loot spawn command in scripts?
Beta ApI.
really? i can't find it in the dimension class?
oh it's in world
when was that added?
.100 or maybe .110
great so it won't take too long to be released
Maybe maybe not.
hmm it doesn't have an option to spawn a raw loot table...
is there a limit for how many permutations a custom block can have?
I could make a dummy block for the sole purpose of providing loot tables to the lootManager.
Yes before it degrades performance.
how does it hurt performance if the block was never placed or generated in the world?
65536 is definitely more than enough
Can I make it so when I interact with a horse using a specific item something happens?
Yes PlayerInteractWithEntity.
i want this script combo https://streamable.com/w48wvj
12-13 CPS, maybe butterfly?
or jitter
By adding custom knockback or changing the knockback resistance this would be possible afaik.
you cant barge in and demand someone to make it for you. you can ask questions on how you would start making it, or for techniques, but no one will just give you the javascript code. ultimately, you have to make it oyurself
is it possible to hide the the copy of custom command with namespace?
stop demanding for help
you're being disrespectful
Kind. If you add a custom command e.g. cc:quest minecraft will add a copy quest of it. Only works for non-vanilla commands
maybe via UI, but definitely not via script
how can I change entity’s name and only specific player can see it?
not possible
🙁
:(( goodbye nametag color
Technically you could make an animation that would simulate the appearance of a nametag
And use the players option of playAnimation for different colours
It could potentially a bit janky though
what about player.spawnParticle() it's client sided right??
Yes, it is per player
alright thanks for confirming minato
these might help
https://developer.mozilla.org/en-US/docs/Web/JavaScript
https://learn.microsoft.com/en-us/minecraft/creator/scriptapi/?view=minecraft-bedrock-stable
JavaScript (JS) is a lightweight interpreted (or just-in-time compiled) programming language with first-class functions. While it is most well-known as the scripting language for Web pages, many non-browser environments also use it, such as Node.js, Apache CouchDB and Adobe Acrobat. JavaScript is a prototype-based, garbage-collected, dynamic lan...
W response
Dose anyone know what this means?
you have to wrap your method inside worldLoad event
world.afterEvents.worldLoad.subscribe(() => {
world.sendMessage("")
})
Alr thx
would this work as well? system.run(() => { //Code Here })
or should i just use this?
Considering that you are trying to use sendMessage in your code I assume this is something not to be done prematurely in the sense that you want to see it when in the world itself, so I can only safely assume that is how you have your code written. Therefore, using system.run() would be more appropriate here.
O ok thx
You can check if the player interacted with it using the required item
:sus:
what's the easiest way to use molang with scripting? hopefully not animation controllers...
Animation controllers
-# Actually I dont know
But very probably
nooo
yeee
Just animation. iirc, you can use stop expression to edit variables in an animation
are there any open source libraries that can convert string to functions
huh
behavior pack animations?
Rp
there is no point then
i want to base my script on a molang query
I haven't use ACs since q.get_biome_tag was removed i completely forgot how to use them
like run functions using /scriptevent hi:hi console.error('hi')
scriptEventRecieve event
you could use eval
you have to enable it in your bp manifest
how to enable and a small example please 🙏
system.afterEvents.scriptEventReceive.subscribe((event) => {
const { id, message, sourceType } = event;
if (id === "wiki:test") {
console.error('hi')
}
});
world.getDimension("overworld").runCommand("scriptevent wiki:test");
dunno wdym
I want to run code in string form
Idk use eval as he told
list "script_eval" in your manifest dependencies, then use the eval function
capabilities not dependencies mb
{
"format_version": 2,
"header": {
"name": "Bedrock Add-ons",
"description": "Script API Template",
"uuid": "<UUID>",
"version": "1.0.0",
"min_engine_version": [1, 21, 90]
},
"modules": [
{
"uuid": "<UUID>",
"version": "1.0.0",
"type": "script",
"language": "javascript",
"entry": "scripts/main.js",
}
],
// HERE
"capabilities": ["script_eval"],
"dependencies": [
{
"module_name": "@minecraft/server",
"version": "2.0.0"
}
]
}```
editorExtension, experimental_custom_ui, raytraced, and some others. not all relate to scripting
is there a documentation?
thanks
What's this???
why is there no mention of script_eval here?...
what is this experimental_custom_ui?
oreUI maybe
Nothing.
It doesnt work and its an old framework that no longer works.
damn, looks like the developers forgot to remove it as an option
and forgot to add script_eval
because it's very annoying when you have to dig around on the internet to find information about some "secret" feature that isn't mentioned in the documentation
auto-generation of documentation would not be such a bad idea
Rp, not sure about bp
Dm me if you still can't figure it out.
I will try to help when i get home
1037th 100,000th message
Exist a way to detect if I'm inside a house?
You could use raycasts to detect blocks around you.
For example you could check if there is a roof anywhere above you, and maybe that roof has to be say at least 3 blocks in both directions.
I don't know what you need to be considered as a "house" but simple room detection should suffice, its just checking if you have a roof & have at least one wall. As for the exact code you need to implement to perform this detection, you'll have to figure out yourself
What's the criteria of a house though?
Being under a roof and with walls
a naturally generating cave can be considered as a home then
LOL
I saw that @prisma shard
why do you keep deleting it :<
Yes, but the environment_sensor test that detects if you are underground considers trees as "underground"
And it stops me from doing certain things
Check if it's a leaf block maybe?
if you want to do it with script then you gotta make an algorithm with it
But then a platform would be considered underground too, even without walls
best example is terraria's npc houses
I want to stop the tornado from pulling me in if I'm inside something
go research how it works
if it's a tornado, why not shoot a raycast from the tornado?
But wouldn't he need to look at me or the mobs?
what do you mean?
I don't know
what...
how can i detect when a player swings an item
U mean attack?
It doesn't need to look at you..you can check if the tornado is nearby you and it will only pull so
swing, attack, left click. Yeah
Do you mean interact ? Or attack in the air
U can detect attacking an entity
but not pure left click
i've seen it before? was it possible and no longer?
You would have to do some unreliable method
ah
Well for attack there is entityHitEntity event.... but there's no pure left click detection such as attack on air
U would have to constantly tp an armor stand in front of the player
but that’s a method with commands
Interesting method haha
It’s an actual method for detecting left click in the bedrock commands community
actually i saw that it might be possible with AC's, but idk how those work
queries
How to set scoreboard points over limit
Quick question is import Location a thing?
wdym import location
Like this import { system, world, Location }
Fire some rays from it, and depending how many hit the player change the pull strength
no that was removed years ago
He's getting really OG
Wait for me im german
That's why I'm asking. What I know I can do, I wouldn't be able to do what I want
But it already does that
I want to prevent it from doing so if I am home or in a cave
I asked you by what do you mean and you answered me by
I don't know
I'm not a native english speaker, sorry, sometimes I don't completely understand
I understood you asked me something like: What do you think?
In a rough way
oh I see my bad, it's fine there's a lot of non native english speaker here too, but anyways you should try raycasting to the player and see if there is a block in it's path and if there is a block then don't pull that player
I'll try to do it, thank you 💕
Ay thats not me

Dude
sooo
If i have Dynamic Properties saved in a world
and remove the addon
add a new one with the same UUID
will I still have access to the data?
or will it be gone?
it's linked to the UUID
so if the new addon has the same UUID, then it'll stay
well it "stays" anyway
the new addon will just be able to access it
FINALLY
• Added Dimension.getBiome(location: Vector3) which can be used to locate the Biome of a given location.
Nice
new update dropped?
today's preview
pretty small
but has really important stuff
anyways
how can I put text between ModalForm buttons?
how can i make my custom block do something if i right click it with specific item?
Custom block component
Is there an easy way to define whether a block is a sign?
text_sign tag?
thanks!
can we hide the tagged player chat?
just check the typeId
we used to have chatsend before
block.getComponent('sign') != undefined
better
ik 
you are so cool man
are you trying to make me write another ik?
what about Inverse Kinematics?
I need some help.. is typescript drunk or is it me not knowing it good enough?
export class SignGlowingApplierComponent implements ItemCustomComponent {
constructor() {}
onUseOn(event: ItemComponentUseOnEvent, context: CustomComponentParameters): void {
let source: Entity = event.source;
let block: Block = event.block;
let face: Direction = event.blockFace;
if (source instanceof Player && block.getComponent(BlockComponentTypes.Sign) != undefined) {
SpawnSimulatedPlayer(source, function (simulatedPlayer) {
simulatedPlayer.addEffect(MinecraftEffectTypes.Invisibility, 20000000, { showParticles: false });
let stack: ItemStack = new ItemStack(MinecraftItemTypes.GlowInkSac, 1);
simulatedPlayer.useItemOnBlock(stack, block.location, face);
});
}
}
}
show full code
aaaand? I need the code that registers the component. or is that all?
It's 100% not caused by component registry, I have some other components that work just fine
It's just some weird type mismatch I can't figure out
Then I can't help you.
finally...
Thank you Mojang for giving us the ability to detect biomes using scripts!
Now we need the ability to create new dimensions.
next open entity inventory please :'))
it will be more useful
and able to add new keybind :)))
then you will need an alternative for mobile
i mean, its not that complicated to add as a feature, like u can do it using commands or scripts:
command: /openinventory <entity or block> entity:id @a
scripts: entity/block?.openInventory(Target: player);
system.addKeybind()
its not that simple
lol
i know, but not impossible
yeah but you say it like it is that simple
its alot easier than giving us the ability to make custom dimensions
i mean it, mojang can do it but theyre focusing on other things,
like they could give us the ability to detect dimensions since 2019, but theyre focusing on the game content not addons
-# 2019 is a random guess
we should just keep our hopes up, and wait, and wait, and wait, a....
well I did that for getBiome and getLightLevel
yeah, how much have u waited for those things?
I waited for getBiome for 1 day and then made my own version of getBiome
.-.
using entity.json or player.json
Scripts
at least we got the feature, and thats what matters
Well... yes
detecting blocks around the player?
no.
@untold magnet
that wont be accurate.
ah,
at all, getBiome resolves that tho
waiting for equippable component for all entities day 500102
waiting for entityHurt beforeEvent day 943128
like cancelling the damage using scripts or something?
yes.
i see,
or just, wanting to do something before the damage happens in general
waited for entityHurtBeforeEvent for 3 days and then created a hack .-.
entityDie beforeEvent would be nice too.
and what was this "hack"
in fact, only entityDieBeforeEvent is needed
cancelling the death, resulting with the ability to make custom totems
no
you mean entityHurt?
because you could essentially create entityDie beforeEvent with entityHurt beforeEvent
well... I'm too lazy to explain, but it needs a very specific environment... but at least no one will steal it from me :)
detecting the damage amount and if the player will die from that damage
well... in fact, the opposite also works
you can just dm me the explanation sometime
no
yes
well, although this will also be a hack, but a smaller one
ig it would be a method of EntityInventoryComponent/Container class if it ever gets added
like
Entity.getComponent("inventory").container.openContainer(secondEntity: Entity)
or
Entity.getComponent("inventory").openContainer(secondEntity: Entity)
Nobody even believes in server-ui anymore...
what is server-ui?
😭
jk i know what it is and i dont really use it
nothing important...
What do you mean?
if there was a method to force a player to open a container, it should have been in server-ui... well, that's what I think..
It does not need that much updates in comparsion to server module
Ew no.
It definitely should be in server because it's interacting with the Entity.
I think it should be pinned to Container.openInventoryToEntity method
It does not really make sense to pin it as a free function in server-ui module
then it would be better to do it like Player.interactWith(target: Entity | Block)
anything... just the ability to open the entity inventory wireless...
I think i would like this better
can we hide tagged player chats?
Is there a way to get the name of an entity?
“Ender Dragon” instead of “minecraft:ender_deagon”
You can get the localization key.
I tried it with a cow but I get undefined :b
I can access everything normal but localizationKey returns undefined
It's not possible to get stuff like that because it's stored on the client side?
No theres a scripting method fornit.
Just for the cowM
i didnt see anything like that in the docs
what is it?
Documentation for @minecraft/server
I also tried it with the chicken, pig and sheep
I get undefined 🧐
what?
How do I make an item make a sound when holding left click or when it’s interacted as a block?
you can detect interactions but not left click
u can use playerInterectWithBlock and then use the playSound method
use itemStartUse when holding right click event and playerInteractwithblock
oh wait
left click lol
left click detection is already partially impossible so holding is impossible at this point
Don’t some items have this cooldown mechanic, can I use that?
Hm, ok 👍
Oddly enough, the sound that I imported doesn’t list on the playsound command
I need array that has all double blocks!
DIY
probably importing, id, playing issue
🥲
What FOR REAL?
Less go but im using 2.0.0 stable :(
wait for 2.2.0-stable, or wait for 1.22.60/70
1.22.0 will came out with alot of bugs, 1.22.10/40 is all about bug fixing and adding some new coding features
so u will be waiting, alot.
Uh what
1.22.0 already?
Interesting
Its a major update... Uh and whats it gonna be? The end update?
What?
I doubt itl be the end update
Is there a maximum number of keys that a Map can have?
probably no
It depends on your memory
what’s the button limit for a server form?
How do I figure out the aux ids like Herobrine did, I wanna update the pack for myself, herobrine's pack is outdated rn
just guessing the future
i dont think his one is outdated uh what
255 iirc
perfect, thanks!
double check that, i am not too sure
Are there any scripts that detects player's movement input
Could you elaborate what movement input means? Are you trying to figure out if theyre moving forward/backward or the keys they're pressing?
Quite, I'm searching for a script that detects the movement key inputs, where the script detects when a movement key is pressed even the player doesn't move from it's currently location
I'm not sure if InputInfo works if they're moving against a wall, but generally speaking you cannot detect specific key press, just the actions it was binded to.
Understood, thank you for clarifying, i glady appreciated your time, have a nice day
u can do that don't worry
in theory, no, a hashmap(the formal name) uses hashing, an array and linked lists
on inserting, if some conflicts, it creates a new node and sets the last node to now point to this new one
How would conflicts occur?
https://docs.rs/hashbrown/latest/hashbrown/
rust uses this for its hashmap implementation
This crate is a Rust port of Google’s high-performance SwissTable hash map, adapted to make it a drop-in replacement for Rust’s standard HashMap and HashSet types.
hashing is transforming some type T into a number
it would occur when 2 different values, when hashed, generate the same number
for example, some hasher that when hashing "hello" and "world" return for both strings the number 48
A hash function is any function that can be used to map data of arbitrary size to fixed-size values, though there are some hash functions that support variable-length output. The values returned by a hash function are called hash values, hash codes, (hash/message) digests, or simply hashes. The values are usually used to index a fixed-size tabl...
its for java but its the same concept
It is ig, i think
Or maybe I'll recheck if I'm missing something
hashset(Set in js) works as the same but doesnt create the key value pair relation
So the relationship of keys to hashes can't be many to one or it causes an error
you can do as much as you want
.
it uses linked lists
and generally, it will use u64 for numbers of hashing
it will lead values between 0 to 2^64-1
so the chance to some conflict occur is little
maps are often made for avoiding conflicts so theyre in general O(1) for lookup
you know what is a linked list dont you?
if not i can keep explaining
I do (sorry for the late response)
is it normal i lose performance due to simply unfocus the minecraft window?
like seriously, im getting a bunch of warnings of slow code with in average 50ms
but when i focus the game window again it simply stops
Hey guys, I have a bp file that appears as trojan, I tried to fix it by changing the encoding from lf to crlf (UTF-8), but not sure if it no longer appears as trojan, can I please send the pack to someone to test it?
Sounds suspicious .-.
Well, If for some reason you think I am hacking you, I can’t anyway since your windows will warn you if it is a trojan
Well, if you are not on windows then yeah it is an another case
This fricking file always gets detected as a trojan for some reason, how do I fix it??
Its encoding is utf-8 crlf btw
For some reason I thought we had a method for getting an entity based off it's id
we do (?
Dimension.getEntity(id: string)
Doesn't exist on the documentation
and throws content log says it isn't a function
that's why I'm checking, idk whether I had a fever dream or what
found it
it's world.getEntity(id)
not dimension
yeah i came here to say it
i didn't find it in the Dimension class so i was like wtf
well that leads me into my next point of confusion. I've been learning property overrides so I can do client based rendering for certain entities, they seem very useful, but for some reason there's no get method for property overrides
Seem that I'm reliant to save some sort of other data on the server side and use that to tell whether something has had it's property overriden
is there a way to spawn very specific entities?
like entities with specific components and make those components have specific values?
you mean the encoding of the file you provided or the strings when being runned?
because js understands strings as utf16
and anyways, how is it a trokan?
its javascript
I meant the encoding of the file
it's got literally no permission to anything on the cellphone, computer, or whatever
Windows defender detects it as a trojan
I don’t even know why
so just disable it for a while
when i had windows it used to detect files that i compiled with gcc
windows os is weirdo
The thing is not with me, it’s for the people who want to download the addon, they are afraid that something might happen to them if they download it
anyways, i opened a profiler on minecraft, it wrote the content as JSON, is there a way i can see the content in a better way?
Another thing, I remember that I was able to solve this problem with another file long ago, but I just forgot how
just explain that javascript got no permission to do anything
and windows is weirdo
People just don’t get it
Very new to making addons and such, was trying to create my own essentials addon, it uploads to the game, but nothing happens, anyone able to help take a pek?
you dont have an entry
in the manifest
and no dependancies as well
your content log should be flooded with errors
didnt know item also have custom component
yeah, but it's seldomly used since the components there are also events
well to me I seldomly use them
im trying something with custom component, is there a way to make something like this?
"rpg:test": {
"entity": "minecraft:cow" // i want to get this value and use it on my script
}
You can use an array
iiirc, that work
how i can get the "entity" value?
2nd argument from a function and simply use props.entity
🙂
we can now search for messages in post
this post almost at 300k message
Can I know the type of spawner?
uhhh
jhonny gud ol question indeed
thier profile pictures got me for a sec, i was about to screen shot it how Minato ps changed his one, but its diff account
afaik no
Hmm
Lol
We are friends and on the same team
import {
system,
world,
ItemStack
} from "@minecraft/server";
onTick(event) {
//event.block // Block impacted by this event.
//event.dimension // Dimension that contains the block.
if (event.block.type.id === "cc:ore_block") {
if (event.block.getState("cc:state_ore") === 0) {
world.getDimension("overworld").runCommandAsync(`setblock ${event.block.location.x} ${event.block.location.y} ${event.block.location.z} ore_block ["cc:state_ore"=1]`)
};
};
}```
Why does this throw syntax error and how to fix it? (I ask here because I assume the answer to be simple.
change runCommandAsync to runCommand
you must put it inside a startUp listener
also, you're missing function etc. keywords
yeah that too
also, consider using runCommandrather than runCommandAsync
runCommandAsync doesn't exist anymore
what if he is on lower version
oh yeah thats true
not that usual behavior, but he might be in 1.x.x still
crap zodiac signs, how do you all import @minecraft/server?
import * as mc from "@minecraft/server";
const {
system,
world,
ItemStack
} = mc;
```;-;
but its not a good practice
import {
system,
world,
ItemStack
} from "@minecraft/server";```
importing just like that is fine
it still depends on how I use the variables, sometimes for types
why do you need to do that
why?
in lot of cases like JS you can't import interfaces so you can use the namespace to access that type
its totally fine imo
mm alr idk
const {system} = await import("@minecraft/server").catch(_=>(console.error(_), {}));
💀 nice
damn
the codes actually can work even if the module is not valid
i use it for mocking tests and conditional script addons
some part of the scripts are loaded only if the modules are available
#1344125833685635138 message
nice try catches
what a nice code
Tf is this code?
it’s used for this btw https://mcpedl.com/gametest-interpreter/#downloads
entitytypes filter of sort
nice catch
i mean the module name don't even exists but let me check again
scam ;-;
why don't you just use getEntities?
world.getDynamicPropertyIds().forEach(p =>{
p = world.getDynamicProperty(p)
typeof p == "string" && eval(p)
})```when
what does eval do? I forgor
evaluates code
does anyone has oppened project?
addon project
and can test one snipped i have?
@subtle cove do you have your terminal open?
I always map list/objects by logging em and pasting on workspace to toggle & view categorized stuff
Laptop ded atm, sorry
np
does anyone has MC opened and developing addon here?
Can anyone test this
import('data:application/javascript;utf8,console.warn("Test");');
i wonder so badly
please someone have to test it
🙏
How is that a directory path