#Script API General
1 messages · Page 114 of 1
tho theres a standalone file
theres a handful of stuff you can make use of for anything math
ye
Someoone know if is possible modify the Ui in forms, but for Add-Ons?
wdym?
Modify the UI of the forms, without using something that violates the addons rules
oh okay, so i need to modify vanilla files right?
Well you can use addon you don't have to change vanilla ones, but yea it does override some vanilla behavior, but if done correctly then its relatively safe
Well what all of you are working on?
i wonder what kind of addons are made nowdays
Finally got the debugger to connect to BDS, is there any way to see which add-on is writing to dynamic properties?
Mostly for this
Run a debug profiler for each one of them
did mark variants use to be writeable? whyd they change it to read only? all my favorite things are going to read only 😭 ill miss you scale component
nvm i figured it out bc im cool or smth like that
whats the point of using try catch if i just throw the error again 🤔
its like "if this errors, do something"
What folder to store server secrets and what format?
try catch on its own doesnt "throw"
the rest of the code will run as normal
what server secrets
No sense, Try catches were meant to be handled
i personally prefer errors as valuesso in general i dont use try catch nor throws
throws i use just for some violation
I saw this in a script and it was stupid so i asked this
try {
dimension.runCommand(command)
} catch (error) {
throw new Error(error)
}
lmfao 😭
😢 why the hell to use try catch then?
it catches only "throws"
then
if nothing never throws, its never gonna be executed
yeah
i dont know if i should be laughing or be frightened
Throws an exception if the command fails due to incorrect parameters or command syntax, or in erroneous cases for the command. Note that in many cases, if the command does not operate (e.g., a target selector found no matches), this method will not throw an exception.
What's wrong here?
world.afterEvents.playerInteractWithEntity.subscribe((event) => {
const player = event.player;
const entity = event.target;
if (!player || !entity) return;
const equip = player.getComponent("minecraft:equippable");
if (!equip) return;
const item = equip.getEquipment(EquipmentSlot.Mainhand);
if (
entity.hasTag("token_17") &&
player.hasTag("tokens_place") &&
item?.typeId === "test:item"
) {
player.dimension.runCommand("clone 227 6 234 227 6 234 232 15 210");
}
});
does that throw error or what
wha-wha what is this
you wrote some binary
There is no error and no response.
I need clone command especially here
put some console logs around and see where does it stop
never knew about clone command, it's interesting
put a console.warn on top of runCommand line, And see if it runs
playerInteractWithEntity has itemStack property
Oh yes
try using that instead of equippable
Okay, imma try, thanks guys!
world.beforeEvents.playerInteractWithEntity.subscribe((event) => {
const player = event.player;
const entity = event.target;
if (!player || !entity) return;
const inv = player.getComponent("minecraft:inventory");
if (!inv) return;
const container = inv.container;
if (!container) return;
const item = container.getItem(player.selectedSlotIndex);
if (!player.hasTag("tokens_place")) {
return;
}
if (!entity.hasTag("token_17")) {
return;
}
if (!item) {
return;
}
if (item.typeId !== "test:item") {
return;
}
player.runCommandAsync("clone 227 6 234 227 6 234 232 15 210");
});
That worked (without debug messages)
This crash is driving me insane. This weird __clone thing happens whenever a player punches a mob, but only sometimes when the server starts. It happens 3-5 times in a row then nothing for like a day. It's exactly like this https://github.com/itzg/docker-minecraft-bedrock-server/issues/508 but it happens on entity hit, which suggests scripting, but I've checked all addons removing one at a time, and nothing? Ideas?
Looking through the .mcstats nothing stands out when it crashes, no addon handle spikes or JS memory issues
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]
I've got a custom slash command /mine a however it currently lets players do /mine aaaaaa which will become an issue later down the road (Prestige ranks like AA, BB, etc). Is there there any way it fails if the player does more than the 1 A?
Make it an enum? Not sure what you mean.
i have different Mines: Mine A, Mine B etc, and later on I plan on adding prestige ones, so Mine AA for example. If a player currently does /mine aaaaaaa it teleports them to Mine A regardless of how many letters they add to the end. It would become an issue if a player tries to access a prestige mine, like Mine AA because it will still teleport them to Mine A, and not Mine AA
Then make it an enum?
That still doesnt fix the issue im having
How does it not?
Players just select the mine they want, you check if they meet the requirement, if not dont do anything.
Im trying, however it keeps accepting "aa" as "a", it seems to only be checking the first letter, so if people start doing "/mine ab" it will allow them to warp to mine a
How are you parsing it?
const player = origin.sourceEntity;
const arg = args[0];
if (!player) {
return { status: CustomCommandStatus.Failure };
}
const requested = `rank_${arg.toLowerCase()}`;
const playerRank = player.getDynamicProperty("rank");
if (!/^[a-z]$/.test(arg)) {
player.sendMessage("§cInvalid mine! Example: /mine a");
return { status: CustomCommandStatus.Failure };
}```
You just need to use Enums and hardcode it is all I'll say. Dont do this regex whatever. Just do a switch case or map to teleport.
No matter what I do, it just seems to be an issue. If I add a debug like console.warn("player entered: " + arg) it would show "Player entered a" even if the player entered aa
Open a post with the full code because what you sent doesnt show the full context.
Can i get some help with this?
I just changed the version to 2.2.0
I was using 1.9.0 iirc
DimensionType iirc
How can I make something happen when an item is used on air?
itemUse does the trick
how can i put an item in the scond hand of the player using script ?
Documentation for @minecraft/server
ty
Wdym?
quick question. how do you make a custom command without namespace. I've been using chatsend all along and dont know that we can now use / command without namespace.
why is lever_selected returning undefined
cause it is not defined
lever_permutation have no getSelected function
const leverSelected = lever_permutation.getSelected({
face,
faceLocation: relativeFaceLocation
})
is that not valid getSelected function
But I define it before I call it in the big switch case
Ok so how would I define it because im confused
not sure what it is supposed to be tbh
you are doing
const leverSelected = lever_permutation.getSelected
lever_permutation is levers.propery
and propery is new SelectionBoxes()
SelectionBoxes is imported, so i am not sure what's there
why doesn't the iteminventorycomponent work for shulkers?
it works for bundles and custom possibly?
this page has been hidden due to the bug mentioned at the top of it
the code on this page does not work
I dont think you can, it would need to be placed.
Is item inventory component a recent addition
okay, thanks for letting me know, i am just trying to read the information inside a chest, so i can display the contents
of the shulker
inside a form
you are using SelectionBoxes, but calling getSelected() as if it were FaceSelectionPlains
according to the wiki
getSelected(faceLocation: Vector3, options?: { invertX?: boolean; invertY?: boolean; invertZ?: boolean }): number | string | undefined
but you are doing
const leverSelected = lever_permutation.getSelected({
face,
faceLocation: relativeFaceLocation
})
?
for the shulker inside the chest
it wont detect it
im pretty sure anyway.
ill test but even if it did, probably not the full list
i doubt it would tho
Then I haven't noticed that bug ig
nah it doesn't work lol
Because the other 2 addons I have the use face selection planes work perfectly fine
just isn't supported for their lore
Or does it only effect the boxes
unless you're still using the v1 @minecraft/server API
Dammit
version dependent

yeah, ill just ask them to use bundles to show stuff inside them in the form
oh well
@inland merlin you can work around it by cloning the shulker and spawning it and destroying it
that should throw the items
Is there any possible work around
oh, well its the shulker inside a chest, its not placed down
i forgot cani place the block
down?
check #1067535712372654091
you can spawn the item and kill it
ohhh hmm, so killing the shulker makes the items drop from inside it?
yes
it is a survaivl thing
awhhh ok
killing the shulker box item will drop its inventory?
cheers mate
yes
ill give this a go
i didnt know that
not sure if it is kill or damage tho
there is a scripting resource for it
bundles too
i forget what the api uses to spawn the itemStack as an entity
please remind me, i tried looking it up, but forget where it is
something like createItemStack, or newItemStack
of the copied item
dim.spawnItem(itemStack)
oh... it must have changed because i swear it was something lese
else
for the copied itemStack shulker inside a chest
to have it spawn outside the chest
just get the item and use that
okay
get item already return a copy
I have an absolutely diabolical work-around that involves a whole other script in a whole other addom
your own stuff, or based off of what im trying?
?
this works
/damage @e 100 self_destruct
this seemed to drop the items, not kill()
for dropping the shulker contents
GOT IT WORKING THANK YOU
ill clean it up
but yeah, heck yeah ended up using the applyDamage
even better
nice
the chestshop is insane lol im trying to make it part of a newer essentials im making
Good point, but thats alr
I mean its in order
From 0 + slot
That's good if it is 100% of the times
Seems to be so far
I get what u mean
Because im breaking the inventory out
So maybe I need to double check
Can you log date.now when you get the items and send it here?
Assuming you are using entity spawn
Yeah I stopped working it for the moment, but im curious as well
Ill send it to you to see if it comes out in order
Or random
Currently in my phone, will do when i can
Ok
any way to cancel this form showing up? my message gets sent after the form is shown to the player
I am using an armor stand runtime identifier and I'm wonder is it possible to destroy the armor stand item that spawns when it's broken and replace it with the entity placer item instead, without messing up the fact that it drops all the stuff it was wearing
Whose sould do i need to sacrifice to Jeb to make this shit work
(Yes I've implemented every change suggested first)
Im taking volunteers
Let me try 1 last thing again
i was wondering how many people use typescript or javascript?
I mean, everyone using typescript are also just using JavaScript
as in, do write the typescript and then transpile, or just write javascript
ok so aparently something is just wrong with the way im trying to grab the selection_box
I DO NOT KNOW WHAT
but something is wrong
Wait I think i might have it
It isnt the colons but they probably arent helping
U figure it out yet?
Not yet
Check if the player has items to sell (e.g., via an if statement on itemAmounts[selectedIndex] > 0) before calling form.show(player), and only show the form if true—otherwise, just send the "no items" message immediately.
Ahhh, thx
With this in mind
Can someone tell why this is still returning undefined
Like I used the goddamn fix for face location and still NOTHING
And I can see the fix is pretty clearly working
import { beforeEvents } from "@minecraft/server-admin";
system.run(() => {
beforeEvents.asyncPlayerJoin.subscribe(async (data) => {
world.setDynamicProperty('pending_pfids', undefined)
console.warn("test", data.persistentId)
const name = data.name
const pfid = data.persistentId; // This is the PlayFab ID
const map = JSON.parse(world.getDynamicProperty('pending_pfids') ?? '{}');
map[name] = pfid;
console.warn(JSON.stringify(map))
world.setDynamicProperty('pending_pfids', JSON.stringify(map));
return Promise.resolve();
});
})
``` anyone know why this wont get the pfid?
it works in other packs i have but not this one, its so confusing
actually
it does work
but the hitboxes are borked to shit
and there is another block update bug
:)))))))))))))))))
401k 🗣️
how do i lock chests from copper golems? for a chestshop, don't want them placing anything into them
does worldLoad event triggers on /reload
u can change what things they can open in their json
yes from what I know
awh ok, ill have to look inside their json, was hoping there was something i could do to stop them dynamically on locations etc..
It's really good for initializing other scripts & such
unless u wanna /kill them in a radius there isnt really a way
dang lol, i just don't want them to be able to open them lol
like a beforeEvent or something
like, a custom UI thingy chest-shop?
ye
ooooo
then test for coppergolem
you can cancel the event via using that too
opening a chest
i guess i never really thought about it
then test for the chest coords
for entities
ill check out the entityInteract as that would solve my problem
thx for letting me know
ill integrate into my existing stuff'
i looked theres no entity interact with block event
I'm not sure but I think there's like a feature where you can store name-data in containers
hmm
or copy the model and texture and make a custom block chest
custom block container / just make a custom ui system
yeah use herobrines one
custom form shop
or just use the normal copper chest and place a barrier above it
btw custom containers are naturally interactive with hoppers, right?
no clue
or do I have to toggle something
I'm working on making copper golems auto-load cannons
if hoppers work it'll be fine.
could just script that
cuz iron golems have a inventory component im pretty sure
so just get Mainhand
i already know about herobrines chestform, its not that for my chestshop
artillery foundation
artillery storage
artillery gun (entity)
the entity basically tests for items in the artillery storage connected to an artillery foundation
then uses them
if we place a block on top of a chest, will it block them im assuming
very useful for auto-cannons and flak
yeah
had to make cooldowns for big stuff tho
ill just have to do that then lol recommend that
I mean yeah you could just do that
brilliant
done, lol no coding needed
not too sure if it will cancel your gui tho
cuz from what I've seen, some stuff like hoppers cancel the gui when being moved & stuff
so I'm not certain but chests might auto-close if you place a block over them.
yeah, it pretty much just cancels their using of the chest when placing a block on top if already open
the block method is the easiest method
well it was a good idea
yeah lol
actionform / modalforms for chestshop
ohh
so it is using actionforms
I am new to custom ui.json stuff
working on modular helmets rn
figured out a way to put a custom button on screen that works
just sell for now, maybe adding a buy option from players down the road. but its gonna be part of my own essentials
looks interesting
quite a unique UI btw
not all buttons which is hella inconvenient
mostly text is good
yeah and that's good
i forgot its a modalform
lmao
lots of bugs but it tests player inv for compatible stuff and displays it in the UI where you can select what to attach.
oh nice
oooh
i made a system that basically copies donut smp generators/spawners system
but thats for another time lol uses herobrines stuff
great idea implementing a number system for purchases
hella annoying in other servers where you gotta press the button 1k times for building blocks
yeah, thats why the chestshop is powerful, its also got a lock item inside the chest to protect it from players accessing
interesting
just makes it easier, it auto places into the chest
and it doubles as a lock for other normal chests lol
not just chestshops hehe
yeah the method we figured out earlier in this chat about getting the data from the shulkers is insane lol
literally have to copy and damage the shulker as an entity, and then get each entity item information etc etc... and then populate that lol
things we do in bedrock
I have a suggestion
automate the shop system and abuse the copper clankers
extactly!!!
its actually not a bad idea to use them
to auto fill
from behind or something
I love Minecraft
as i have landclaims/skyblock claiim protections as well
we finally have minimum-wage 1940s j*bs
skyblock i have made has a full protection (with limits on script api)
Will adding a tickingarea load the specefic coordinates or will load the entire chunk? In case of loading the chunk, Do i have to add tickingarea as a circle? What's difference between a circle ticking area and and position tickingarea? If i add the tickingarea, Then If i remove the tickingarea afterwards, Will the postion/chunk still be loaded?
lol
chunk-based
you have a limit tho
Are you sure
I think it was 5
Ok ty
? If i add the tickingarea, Then If i remove the tickingarea afterwards, Will the postion/chunk still be loaded?
isn't the limit 10 for ticking areas or is it based on chunks
thats fair
native so much better,
if yall doing a server, endstone /c++ and python is way faster for plugins...
ninjallo has been converting all his script api to endstone python pluigins for his bedrock server and its actually much faster and better with the tps, as he has around 15-20 people on at all times
i wish we could do more with script api
sweatshops and steel factories
hehe
if i could just do plugins for endstone i would, script api just has more people using the addons lol
well you can do anything if you dig deep enough and write enough code to make English essays look like a single sentence
I'm working on a tag-monitoring system for my clankers
its come along way
basically keeps a console log of their clanker work
ooooo that seems cool
helpful
you can divide them into groups and name the monitoring item too, I was gonna use it to determine which ones of my workers were building the shells and which ones loaded em'
gonna eventually make them operate the cannons too but maybe in the future, I'm feeling lazy.
Minecraft is literally undergoing the industrial revolution rn lol
think about it, we got auto-crafters, clankers, and faster minecarts for item transport.
tell me more about the faster minecarts, they finally updated that? i haven't looked into that
ye
near infinite speeds
nah, bugrock has it too I think
lol that would be insane tbh
@crisp trellis d you know
imagine, infinite speed + the new spear coming out lol
its damage is based on speed
now I'm curious wether the clankers can open minecart and boat chests
where are the limits
railguns will now need a stunt-man instead of 1000 pieces of tnt lol
lol
I think it stops
bcuz you literally are not rendering the chunk anymore
without tickingarea I don't think anything works.
it would be a bad practice to keep it loaded
ugh, why does bugrock have to have seperate simulation render distance and block render distance
yeah
it would be insanely laggy tbh
because the server needs to run it basically 24/7
straining background RAM
and slowing down lots of other stuff
yup
Java does too.
It also makes sense for performance.
Installation for @minecraft/server-ui
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]
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]
How can i get the center of a chunk
minecraft wiki says the chunk height is 384, so the Y would be middle of 384?
does the height start counting from 0 or all the way bottom...
if the X or Z of a chunk cordinates is js Math.floor(X / 16) * 16);
the center would be more 7.5 than that?
so
{ x: chunkX + 7.5, y: 64, z: chunkZ + 7.5 }
64 seemed as a placeholder i still dont know about Y
well uh is that Math.floor(X / 16)
or do i multiply again 16
Idk if this is allowed but if anyone can help with this, I am stressing..
https://discord.com/channels/523663022053392405/1425869571293839420
The 384 goes from -64 to 320 so the middle would be y = 128
Now that applyImpulse is available for usage on players, what is the point in even using applyKnockback on players
Any advantages the latter has over the former?
is there any native way to apply knockback with custom friction to mobs
is there any way that code only runs, when a special command is in the chat
applyImpulse is more precise because it accepts a full 3D vector (x, y, z coordinates in one object), allowing seamless control over all directions. In contrast, applyKnockback uses a 2D horizontal vector (x, z only) plus a separate scalar for the y (vertical) component, which can make 3D calculations feel split and less intuitive.
Understood, wasnt even my question but I never really knew what applyImpulse does better besides format and that everyone says that it is better
i figured out a way 😆
obviously the current configuration for it sucks but tweaking it with typescript is a pain maybe i should make commands for that instead
So does that mean that using applyImpulse means that distance moved along x, y, and z would all be the same if set to the same value?
Since I know that 1 along x and z are is the same but y isn't when it comes to applyKnockback
Projectiles only
w do you mean
The only place you can change drag, gravity and that kinda of stuff is with projectiles
Impulse is just cleaner to work with.
As a 3d object
i think you replied to the wrong message
Meant to reply to this
ehh well my workaround is good enough
so it's alright
only issue is it's a little twitchy on the hit player's end
in vanilla projectile hurt to player will not give them invulnerability ticks,
but my custom pvp script uses applyDamage to damage players and currently projectile hits also cause invulnerability for 10 ticks no matter what. is there a way around this
does healing the player a little bit afterwards still work was that ever even a thing because I remember creating a combo gamemode by giving players regeneration every tick
eh well i tried doing this
victim.getComponent("health")?.setCurrentValue((victim.getComponent("health")?.currentValue ?? 0) + 0.01);
but it doesn't seem to fix it
dont comment on the optional chaining pls im lazy 😢
You can create custom commands if that's what you are looking for
https://wiki.bedrock.dev/scripting/custom-commands
Is there a way to detect an interaction between a vanilla item on a vanilla block?
playerinteractwithblock
and then get the item they used with selectedslotindex and compare its typeid
thank you
Is it possible to put a cooldown on the interaction? It works, but it registers so many interactions so quickly that its too much.
Nevermind I got it, thanks again
Would like an answer or any possible ideas to solve this if you have any
maybe try this for me, not sure if it works but could be something close?
directly set the player's health, trigger the hurt sound with applyDamage(0), and simulate the red flash with camera.fade?
this may not even work but the idea to avoid the invulnerability ticks...
that will indeed work yes but i dont wanna do that because it doesnt look like normal dmg
there isnt even a red fade animation its just the hurt cam animation when u get hit + hurt color on skin
man I wish I was good at texturing
wait actually huh
why would you use applyDamage(0) instead of playSound? and applyDamage(0) won’t have any effect on the player
if its health doesnt lower as a result of damage apply it wont do any of the hurt events
Just guessing, I don't know what works or not
Oh lol, well ignore my a**
haha it’s ok I appreciate you taking the time to answer anyway
👀
You probably have to add Entity class with a method inside type definitions.
yeah well i just decided to do that later
it compiles anyway
it might be annoying to catch errors though
Or you can simply add ts-ignore to it.
well...
What causes this problem?
youre giving more stuff than expected in the function
What the guy above me said
You have function f that takes parameters x, y, z for example (f(x,y,z)). But when you call that function you call it with more arguments than what the function will actually make any use of e.g. f(1,2,3,4) would leave 4 unused because there’s no defined argument to catch the value of the 4th input which will result in this error
I still dont know what the difference between a parameter or argument is to this day so excuse my bad terminology 😢😢
do dynamic properties really reset after pack version update?
Yeah they should
Or at least when using a different manifest or when the pack is applied to another world
Note that pack version means the release version of the addon, not the version of the game it is meant for
not the case for me
Only after UUID change iirc
i just changed version number and still keeps resetting my dynamic property idk why does this happen
that really shouldnt be the case
nope, dynamic properties are tied to the pack's UUID. as long as that doesn't change, they should still be there
cannot kick player?
One such idea that brings to mind is to send a title message, store it and read off the binding in the inventory screen.
how do i get when the is when get the how is get the when?
and why does my script api keep saying "requested version: UI: 1.3.0" and not running the script api
.....
{
"type": "script",
"language": "javascript",
"uuid": "192d5bd8-9530-4db0-b4b8-78414820aa7f",
"entry": "scripts/main.js",
"version": [
1,
0,
0
]
}
],
"dependencies": [
{
"uuid": "49a5e694-a0c9-4171-9047-7453a3d2d734",
"version": [
1,
0,
0
]
},
{
"module_name": "@minecraft/server",
"version": "2.1.0"
},
{
"module_name": "@minecraft/server-ui",
"version": "1.3.0"
}
]
}
🤮
I hate this method of fighting.
Well it’s all configurable
Wdym method of fighting
Obviously im not gonna leave the knockback values at that lmao it was just to exaggerate how it differs from vanilla
Could you elaborate?
i do remember if it was 2.1.0 (/server), the server-ui should be 2.0.0
starting from @minecraft/server 2.1.0
cmiiw
i tried that originally but it didnt work so i downgraded the version
Nope because JSON UI is one of the things I haven't learned. But the idea is a persistent variable you set to a binding from the title binding and u read that persistent binding to change the UI. This question is more suited for #1067869374410657962 anyways.
Oh crap u already asked there
Ah hell nah this mf pioneering the Mike Tyson space program
its not as bad now
errrr
Is there no documents or previously answered questions about shooting extra projectiles as an attack?
Srs,
Projectile damage doesn't give invulnerability ticks?
If true that would be good for my barrage punch system
in vanilla it does not im pretty sure
nvm it does
Oh ok tnx for replying though
but i swear i get bowspammed on faster than 10 tick
Lol
that happens when the arrow deals higher damage than the previous arrow
Good morning everyone
does anyone know why this is not in my behavior packs section at the preview version
Why does mc edu keep removing older script verions
pretty sure edu was not made so people could script
Than why have it in there?
All of my old worlds keep breaking cuz mc keeps removing the older script version
And i have to use edu for work reasons
Never done lists before in js, is this how I can format it?
, not ;
Thanks
@woven loom
So something like this?
uh in this u have to remove ,
ye
Would you believe me if I told you I'm new to js??
i have seen u here tho
hm
Im just using GPT to research core concepts of the language and then trying to apply them to my own scripts (probably unsuccessfully)
oh well u should remove those commas that u have used in ur class
ye
Tbh this isn't even a project I'm likey going to continue with
I just want practice
I do want to make a classes system but my brain will never get used to mass coding mechanics and tag systems
It's funny.. I finally have enough knowledge to code stuff in but at the end of the day I still cant make anything
its not that hard, ypu can do it
Im just scared of having a 1000+ line source file
I hate being unorganized but I don't even know how I would organize
fastest most efficient way to clear an area?
fill cmd
if ur beginner its fine
how about big area like
max height, and 21x21 XZ
split into smaller chunks and use fill cmd
Helloo. I have a question, what JS test was about calling upon events within an entity? Or rather a custom event/component group?
I know it's either using scriptevent or custom commands but I forgor :(
Nevermind, it is scriptevent and I still gotta add the component groups affected by such.
is it right player.isValid returns false if the player already quit?
guys ive seen people use the Map() thingy many times in scripts and stuff but ionno how it works and it got many types like WeakMap() nad stuff so can someone explain what it is and how i can use it please?
In its other most commonly used name, it's called a dictionary. Which basically stores unique keys to a value. Very useful for certain performance optimisation where you need to read a lot. Other niche stuff is assigning ID's to objects and u can just get an object by an ID like a string or a number, etc...
are personal compass possible atp (like force point the compass to specific direction, for specific player)
how i do change vanilla block loot? if hardcoded say "y"
i seeee
thanks a lot brother
thanks 🔥
Hardcoded, but you can disable tile drops and implement it from scratch.
can we check if the bundle has item or it is empty using script api?
Is it possible to recover the target via scripts?
like if a cow died you want to recover the exact cow?
no, I'm trying to understand if it's possible to recover the target that an entity is targeting, so as to perform a charge attack correctly, otherwise I would have to take the first most distant player and charge the player who is not really the target.
i think yeah it is possible
is there a way to ensure a player has fully loaded into the world before i try sending them a message
is there any way to set blocks in unloaded chunks
or to like load them first i mean
i would use tickingareas but can those be created in unloaded areas?
fastest way to get if an entity is hostile or paceful without cheching typeIds?
you cant you'll have to teleport the player or either find a new way to do so exploiting game glitches
tickingarea does work actually
it got patched
why would it get 'patched'
idk
there's a component for entities that lets them load ticks
yes
yeah so why would that get patched
unless you mean removed
its not a bug or a glitch
its able to keep chunks loaded not to load new ones
but if you watied 2 ticks it could
What's the fastest way to get if a mob is hostile or not?
Has player.isOp() been removed?
Yes, it has been replaced with new permission system.
Uh so now how can I check if the player has operator or is like the owner?
Player.prototype.isOp = function () {
return this.commandPermissionLevel >= 1 || this.playerPermissionLevel === PlayerPermissionLevel.Operator;
};
Use this for now
That will return true or false right?
Yes
Kk ty
people who don’t use typescript are beginners
Not always, but in most cases.
thats not a fact
beginners in typescript, yeah
i can say people who uses ts are beginners in js and that will have some trouth to it
what
thats not what he said tho
ohh
the reality is that both experienced and beginner developers use both languages for different reasons
can i somehow detect where performance spikes detected by watchdog come from
maybe performance.now()
and use minecraft debugger extension
performance is a thing on quick?
i thought only Date was accessible and usable to track time
im prefering to use f# rather than ts
seriously
how can i locate biome/structure and parse the coordinates of the result
and also can i give lodestone compass set to a specific coordinates to player thru scripts?
Hey... dipping my toes back into add-ons so had to update a few things... any idea why vscode giving me this? I did update the NPMs where they normally are.
Did something change?
When was the last time you worked with script api
I don’t know what @param does but
If you’re trying to use Vector3 to declare the type of something as equal to the type of that
Then it might be the problem
Vector3 is only accessible as a type now not as a constructable class
sometimes i have to open the module's index.d.ts file in vscode before it realises it exists
You might wanna manually look into your node_modules folder as well
I encountered some issues where @minecraft/server-ui had nested a duplicate @minecraft/server module inside
But maybe the solution is something as simple as this or just reopening VSC
Is there a way to detect a player's EXP level?
player.level
Well, what is it?
Detecting if player's EXP level is 100 and allowing entity that's detecting the level to be damaged from the level 100 player
Maybe scoreboards...
Player at lv100, give score of 1. If entity is hurt with the player with score of 1, deal damage to self .3.
Making an entity that can only be hurt by a player with level 100 <
Yeah, something like that
The entity in question
I feel like scoreboards would overcomplicate things
Tags would work just as well, imo🤷♂️
Ah, true.
Honestly found out how good scoreboards are and I've just been spamming it everywhere I do
I actually noticed
Need a checker? Scoreboards.
Need a counter?
Scoreboards
In need of a "detector"?
Scoreboards
Made the phase 2 checker with script and scoreboard so much easier
Dynamic properties are better for scripting tho
Yeah I'm still at the surface of scripting
I can tell
Mainly since the answer to your question is right here in the documentation
Yeahh. Anywho, I'll do the entity first before I do any fancy magic...
If you ever have a question on scripting, I would strongly reccomend going to the entity and player documentation first
always check the documentation and wiki before asking questions here
Can't help it, I like asking fleshies for answers.
just to document
probably the import isnt getting the type but the class constructor instead, which doesn't exist anymore
Yea my solution is redundant tho
No the issue is with tje module itself not being found
aa you've mentioned
Not vector3 not being accessible
Yea
Mightbe this
i'd try first restarting vscode
i had issues where it failed for some unknown reason
i restarted it and it worked
If it for some reason only installs it in @minecraft/server-ui\@minecraft/server
Bc it did that for me
Yeah it happens for me every time I install the modules
I just manually perma delete the other server module
I'm back??
is there some resources abt dynamic particles (or particles that can be seen by specific player/s)
yes
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]
it was "@minecraft/server-ui" right?
Yes also I already fixed it I just read some documents i thought I can't find the solution
They changed the button parameters to an object with properties
Does anyone know if playAnimation can be shown only to a specific player
Player playAnimation does that by default iirc
You need to pass it array of players to show the animation for them
can anyone tell me what this says
What part you didn't understand?
In line 14 there is a function that expecting commandPermessionLevel in the first argument but got something else
Hello minato
I haven't done anything with script for a long time. Can't we still get the data of an item?
Heya!
Sadly we still cannot
return the translation key for said item/block/some other stuff
for data driven stuff it's the value of the display_name component
Minecraft:apple = item.minecraft.apple
İs it true?
that would be item.apple.name i think
yeah
I don't know the key from memory lol
So it works as I said?
I haven't done anything script-related for about a year. What else has been added that is significant besides /commands?
i could send you my .js
beacuse i dont understand what io need to change
I just said what
yes but i dontr know if i did it right
im new at coding so dont expect much
Nothing wrong with that
Send the code as text, i am at my phone
can someone tell me why it's not working please ? (tryna title something on the shooter of a projectile) `import {
world,
system,
EntityDamageCause
} from "@minecraft/server";
const bullets = ["minecraft:arrow","sample:bullet"];
world.afterEvents.entityDie.subscribe((event) => {
const {
damageSource,
deadEntity
} = event;
const {
cause,
damagingEntity,
damagingProjectile
} = damageSource;
if (cause === EntityDamageCause.projectile && bullets.includes(damagingProjectile?.typeId)) {
damagingEntity?.runCommand("title @s title SampleTitle");
}
});
world.afterEvents.projectileHitEntity.subscribe((event) => {
const {
dimension,
hitVector,
location,
projectile,
source
} = event;
const entityHit = event.getEntityHit()?.entity;
if (bullets.includes(projectile?.typeId)) {
source?.runCommand("title @s title Hit");
}
});`
can i give lodestone compass set to a specific coordinates to player thru scripts?
#1067876857103536159
Oh ok
Not since May, but code had not changed and it was not doing it before. @param is used in jDoc which forces me to comply to definitions, its like having a typescript big brother but still using js. If I move a project to where it shared a closer top folder with the NPMs, then there is no error message. I just need to work out why all of a sudden (but not all of a sudden, a change may have happened a few months ago within VSCode), it is doing this. I do not want to have a nodes_module folder in every project. But if it is needed now, I need to make a deploy system for it.
I am using JS, not TS, so I do not have that. I will probably need to work with how far away in a folder structure works. I just know, that last May it was fine and now it is not, but I need to make sure I did not move the node_modules folder out of scope. I do recall building a deploy system for my lib files, so I can make changes in one place and have it copied to all folders using that file
Well I figured out that location is mattering... from the pic, the stuff in the green folders can see the nodes_modules folder, but not the stuff in the orange folders. I may need to move the NPM folder to the outside of both of them . Thanks for replying before.
There is a global node_modules folder for your PC there
Another besides the one inside the NPMs folder?
I use that
C:/users/you/node_modules
Nope, don't have one there. And all my stuff is c:\projects. I do not like putting this stuff behind the wall of my ID... in case there is problem one day...
I see that it, debug-utilities and admin do that. I do not need admin, so deleted it.. and just redid them all. So do you fix it everytime, move the index.d.ts and other files back out of the subfolders?
After studying it for a while, it may be valid per the wording of the package-lock info. Server has "peerDependencies" and this does not create subfolders, but server-ui has "dependencies" and it looks like it creates it do define it, in case you do not have them. For some reason, I think that has something to do with it.
Success in case anyone else runs across the same issue (vscode not finding the installed NPMs for @minecraft/server).
-
Recreated node_modules (server, common, vanilla-data, server-ui) at the script folder level, but fixed server-ui to not have it's own node_modules folder*(not sure this is a good thing yet, may affect dependencies - will test this again - may not have been an issue at all)*
-
One by one, moved node_modules folder, package-lock.json and package.json to the outside parent folder , making sure to update the
name:in package-lock and .package-lock.json to the parent folder name and verifying still working. -
Once I had it at the desired folder level, made sure code in both repo subfolders acknowledged it
If you use Local NPM and not Global
I do not know enough about how it all works and how to make anything see local or global. From observation, I think I figured a few things out.
you can install it globally
bun i -g package
init.customCommandRegistry.registerCommand(helloCommand, helloCustomCommand);
I'm using the shoot method to fire a projectile via scripts, but I've noticed that the projectile only rarely collides with entities. Do you know why?
Might be the entities Collision Box
The projectile has a collision of 0.35 but it seems to pass the entity many times over, only with the runtime_identifier on arrow the projectile behaves well as arrow, but I can't use it so I don't understand because with the scripts the projectile doesn't seem to work correctly
that shouldnt happen smth is wrong 🤔
my AI detector is going off
Myabe try using "minecraft:is_collidable": {} component
Since your problem is your projectile doesnt collide with entities, this might fix it
I use afterEvents.playerInventoryChange, but it always runs when the player joins the event. How do I make it run only when the player is already loaded in the world?
How do I make it so that when the player interacts with a block, the item ID that was in their hand when they interacted appears in the chat?
How would i tell how long a player has been sneaking?
Or at least store data on how long a player has been shifting
And save that data per player
The only idea I have rn are tags
There is an event that trigger when player press or release shift or space key
Use that and calculate the difference
How can I send a scriptevent with the player as the source entity?
its possible to kill an active custom particle through scripting?
how to unsubscribe from an event?
it's not like system.clearRun
here it says that event.subscribe returns a callback
unsubscribe takes a callback
const callback = world.afterEvents.blockExplode.subscribe(data => { })
world.afterEvents.blockExplode.unsubscribe(callback)
ah, so i put the return value of subscribe as the argument for unsubscribe?
yeah
run the scriptevent command, you cannot specify the source with system.sendScriptEvent and the method does not exist on the entity class.
player.runCommand('scriptevent namespace:id message')
I don't think this is going to work...
o
player is grayed out and i am trying to pass it to the callback
hmmm, i think this one deserves a post
Thats incorrect... The subscribe function returns a void. U do this...
callback = (ev) => {}
...subscribe(callback);
...unsubscribe(callback);
did i do it correctly?
im correct.
active_challanges 🤣
whoopsies
thanks
i have changed it to this, and i think it works?
It's a void. What the hell are you supposed to do with a value that doesn't even exist.
Actually nvm
it works tho
how do you explain that?
also look carefully, subscribe takes a callback that returns void and returns a callback that returns void
why did he leave lol
Do runIntervals get canceled when the playerButtonInput detects the player inputs another button?
No.
You need to explicitly stop them.
Dammit
What are you trying to achieve?
I'm trying to detect when the player is shifting for x consecutive seconds
While wearing a specific set of boots
Ai is the future of coding anyway
It really does speed up things so why wouldn’t one use it
maybe some people want to use their own intelligence
instead of starting and stopping a runInterval, try using a runInterval that always runs with a check inside it
its more reliable and easier to debug that way
did you change your pfp
yes i did
his eyes man, what happened
Ain't you used to be a duck
Aye bro wtf they do to you
thats true
and the fact its a simplified drawing
If I set a dynamic property to system.current tick it won't change every time I call it
Right
Well call to get the value of the dynamic property
the value will be whatever its saved as at the time you saved it.
Ok
i find the even more simplified goose funny
just because of the eyes
Yeah I didn’t say you can’t
But In my opinion there’s no point in avoiding ai ’just because’ since you won’t survive in the industry for very long by doing that at least not on a higher level assuming you have competitors
It’s a globally inevitable change we’ll have to adapt to over time no matter if we like it or not
yes, that's the reality of it.
however I'm not going to sacrifice my enjoyment of creating things just for competition, it feels great knowing I don't use ai in my creations.
How to use /connect in scripts api ?
/connect is for websockets, not script api
but if ur asking how to run it, dimension.runCommand("connect")
how do i get glyphs to work on
player.onScreenDisplay.setTitle
it just doesn't show, but works on chat
for rawtext
using for sidebar
should it work the same?
- Released AABB from beta to v2.4.0
- Released Entity.getAABB from beta to v2.4.0```
what's AABB?
bounding box
hmm thats strange lol, its custom ones.. so maybe?
its a glyph so it should work same way
ok, im probably just doing it wrong thanks for testing for me
is it possible to prevent player from picking up an item?
afaik, no
waht does this mean
i think my permission level cant be zero right?
but what is it then
ur custom command is missing permission argument
permissionLevel: CommandPermissionLevel.Any,
then import CommandPermissionLevel
hi, who know how to get a modified music on a disc ?
is this what you mean?
Debug result for [code](#1067535608660107284 message)
Compiler found 1 errors:
[36mindex.js[0m:[33m12[0m:[33m48[0m - [31merror[0m[30m TS2345: [0mArgument of type '{ name: string; description: string; permissionLevel: CommandPermissionLevel; optionalParameters: { type: string; name: string; }[]; }' is not assignable to parameter of type 'CustomCommand'.
Types of property 'optionalParameters' are incompatible.
Type '{ type: string; name: string; }[]' is not assignable to type 'CustomCommandParameter[]'.
Type '{ type: string; name: string; }' is not assignable to type 'CustomCommandParameter'.
Types of property 'type' are incompatible.
Type 'string' is not assignable to type 'CustomCommandParamType'.
[7m12[0m init.customCommandRegistry.registerCommand(helloCommand, helloCustomCommand);
[7m [0m [31m ~~~~~~~~~~~~[0m
There are no errors from ESLint.
Hydraulic Timbs
does script api know URLSearchParams?
No, that's a web api
aww sad
how aout encodeURI
That is a part of normal javascript so it will work
Search yt
you can check the docs
in general if you know js, you might know how to code with the api
Kiro every month
how do u forget
its impossible for me to forget
then that would mean i would have had to stop coding when i was 5
but i started coding at 8
and never stopped
i js a bebe😭
your github shows the opposite
i coded before i created a github acc
my github was created in like 2023 or 2022
my OLD github
i have like 3 github accs
but why dont you have any project in it?
2021*
i dont use my current github
this is my old github
which was created when i was 11
and you can see i joined discord in 2020
which was the same year i started making 3D Guns
why not?
do you use something else?
i got interested to see what gitlab has
can i track the light of Chunks using script?
Can anyone tell me how i casn save the posotion of a player
import { world } from "@minecraft/server";
// save them :)
function savePlayerCoords(player) {
const loc = player.location;
const coordData = {
name: player.name,
x: Math.floor(loc.x),
y: Math.floor(loc.y),
z: Math.floor(loc.z),
dimension: player.dimension.id
};
world.setDynamicProperty("playerCoords", JSON.stringify(coordData));
}
// get them :)
function getPlayerCoords() {
const savedData = world.getDynamicProperty("playerCoords");
if (savedData) {
return JSON.parse(savedData);
}
return null;
}```
you can use those functions in your project
thanks
it depends whether you want to save them on the session or on disk
and how do i fill the blocks at the saved location
yes its only one tiome for now
that looks good already
levo included that in their original example. you need to stringify the saved dynamic property
JSON.parse
i mean parse
okay i think im not that far at making behavior packs
ithink icant do that now i will search and collect information
const savedLoc = world.getDynamicProperty("playerCoords");
if (savedLoc) {
// do stuff with savedLoc
}```
be mindful that savedLoc also includes the player id and dimension
so the fill blocks at the brackets from safedloc
basically
okay thank you
just replace player.location with savedloc
this is what i tried but i will give up and try tomorrow
is there a way we can get shelf inventories? or anything?
shelf inventories?
like getting the contents of shelves
Is there a way to easily desaturate a player's view? Like make it BW or just less... vibrant?
Not via scripting. But you can use vibrant visuals. However you probably meant dunamically in which case no.
AH yeah kinda needs to be dynamic. Thanks, I'll keep investigating!
is there a way to stop a entity like a boat or armorstand from taking damage?
not yet
doubt it
they have different hp mechanics
forget everything nd just cod it ;-;
Is MinecraftDimensionTypes useless now?
perhaps for quite a long time until custom dimensions would be even possible
I mean if it was deprecated or something
I get a log using this
Not sure what was the replacement
i cant find it from typings as well, but the DimensionTypes.getAll() is still there
No i meant i need the new npm modules command to install the latest version
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]
Thx u
well yeah but like
whenever reloading of the scripts happens
right before it
because i wanna save data
maybe i could just wrap it around a custom call
and then use that instead of native /reload
idk if scripts have privilege to run /reload tho
???
thats not what i mean....
smh
there's a difference between an engine firing to event listeners AFTER the action has been done and right BEFORE it
!
yes
Yes u can't
okay
But possible
what would i use that for if i want to catch /reload calls
or not the call but the action of scripts being reloaded
So /reload call is basically a chat message
no it's not
Make ur own reload then
commands and chat messages use a completely separate handler in mcpe
yah i will i already stated that
there isn't
