you can use my web editor for type completion :p
https://minato-mba.github.io/web-apps/web-editor.html
#Script API General
1 messages · Page 55 of 1
typescript debugger wen
mostly just want it to highlight syntax error, since js linting runs under ts nowadays
Item swap is a ... curious approach
:-: someone please retry my code :
import { world } from "@minecraft/server";
world.beforeEvents.playerPlaceBlock.subscribe(({ block }) => {
if (block.type !== "minecraft:chest") return;
let EastConnected = (
block.east().permutation.getState("facing_direction") == block.permutation.getState("facing_direction") &&
block.east().getComponent("inventory").container.size == 27 &&
block.east().type == "minecraft:chest"
) ? true : false;
let WestConnected = (
block.west().permutation.getState("facing_direction") == block.permutation.getState("facing_direction") &&
block.west().getComponent("inventory").container.size == 27 &&
block.west().type == "minecraft:chest"
) ? true : false;
if (EastConnected || WestConnected) {
world.sendMessage("there is a connected chest");
}
});
why are you all fighting with double chests since ages? I'm slowly getting curious
This is the smallest chest detector u can find
import { world } from "@minecraft/server";
const isConnectedChest = (b, d) => (a = b[d]())?.type === "minecraft:chest" && a.permutation.getState("facing_direction") === b.permutation.getState("facing_direction") && a.getComponent("inventory").container.size === 27;
world.beforeEvents.playerPlaceBlock.subscribe(({ block: b }) => {
if (b.type === "minecraft:chest" && (isConnectedChest(b, "east") || isConnectedChest(b, "west"))) world.sendMessage("There is a connected chest");
});
Where are not fighting we are inventing
will do
Smallest ☠️ :
import { world } from "@minecraft/server";
world.beforeEvents.playerPlaceBlock.subscribe(({ block: b }) => {
const c = (d) => (a = b[d]())?.type === "minecraft:chest" && a.permutation.getState("facing_direction") === b.permutation.getState("facing_direction") && a.getComponent("inventory").container.size === 27;
if (b.type === "minecraft:chest" && (c("east") || c("west"))) world.sendMessage("There is a connected chest");
});
Works only with beta api
Fighting? This is an educated discussion, with each of us working to find the optimal solution to each of our different approaches.
((mine has come the closest))
okay didn't mean it in a harmful way, but this is quite interesting I must say
Agreed!
Yesh now how can make it smaller ? ☠️
I believe Lucy is saying, "Why and what are you all struggling with double chests" more than "Why are you fighting each ither over double chests".
^^^
Given how often completely ridiculous arguments break out here, I can understand choosing the word "fight" lol
As someone who has just been lurking on/off, I am quite confused what the situation with double chests.
The question is quite simple: Can you detect if a placed chest will connect to another chest?
Maybe the most accurate word to say is competition
It has been a very fun exercise.
._. yeah
But it soultion was so easy :-: but so tricky
Some said it s impossible
Some said it has edge cases
Some did extra work on it
But we didn't see the direct way or the simplest:-: everyone find the solution but from its point of view and it s mind processing method
How to turn this command into a script, without using runCommand??
/execute if score northern worldtime matches 1.. run scoreboard players remove northern worldtime 1
const objective = world.scoreboard.getObjective("worldtime") ?? world.scoreboard.addObjective("worldtime")
if (objective.getScore(player) >= 1) {
objective.addScore(player, -1)
}
Hilp , how can i get data from before event then put it in after event
what component would i use to imitate placing vines like the vanilla chrimson vines? i got all the other components i just cant seem to figure out the place block when placing it on an already growing vine
Probably on interact.
Or itemUseOn
world.beforeEvents.itemUseOn.subscribe((event) => {
const { block, itemStack } = event;
if (!itemStack) return;
const below = block.dimension.getBlock(block.below().location);
if (itemStack.typeId === "blushrooms:popple_vine" && block.typeId === "blushrooms:popple_sprout" && below.typeId === "minecraft:air") {
block.setPermutation(BlockPermutation.resolve('blushrooms:popple_vine'));
below.setPermutation(BlockPermutation.resolve('blushrooms:popple_sprout'));
decrement_stack(player, itemStack, 1);
}
});
});
is this right?
._.
seems correct
below could just be block.below()
yeah idk. ive used multiple ways i cant get it lol
is it possible to force the host to quit?
You can kick the host, yes. Just execute the runCommand method from Dimension and not from Player when calling the kick command.
doesnt seem to work
It does, show the line of code you used.
Do this:
world.getDimension(args.dimension.id).runCommand()
still no
Are you doing this in a local world and not a server?
local world
Then no, it won't work. It works in a server.
bruh i said host lol
Is there anything to force the host to quit?
I already told you.
thats for bds... and that doesnt even have a host
BDS, and Realms.
thats litterally the same but yeah
Could you invoke remove() on the player?
that broke my game lol
Ah, did it cause you to time out instead of kicking directly?
i cant enter the world?
idk what was happening with my game but no remove doesnt work
Do you plan to run a local world only?
If your project supports editing the player definition, I would look into applying the "minecaft:despawn" component with an event. That might be better than remove()?
well remove didnt work in general but im trying the compent method rn
Use to be able to explode the player to force quit but I don't know if that was patched.
That was funny
If neither of those work anymore, then the only other method I know, and despite how inconvenient it may be, has to be my personal favorite, is having a mob with the "minecraft:behavior.eat_mob" component eat the player. Last I tested, that caused an instant kick
thats amazing
and i think the despawn one works but its buggin
dooooope I got it working where I can trigger an event to kick host
needed to set the timers and stuff to 1, which eplains why it was taking forever to kick them
Oh, shoot, I forgot there were two despawn components.
yeah instant despawn dont work
system.beforeEvents.shutdown.subscribe(() => {
});```
though i think this could potentally lock the player in the disconnect menu
you meant this?
No.
Depends, how long you been gone?
No.
Ok I just walked into a skygen that managed to bypass/turn off the word filtering
I'm way too curious of how it's done
If I had a system to splice the messages around the sensitive words to put an invisible character in, Minecraft would just write the character as some UTF garbage so...
Please don't take this seriously but how??
That's not the only strange thing about this skygen either, there's like 30 people here and it's running smooth as heck
But that's a completely different issue
Optimization goes far
as for turning off word filtering- don't even need scripts to do it. just
"enable_profanity_filter": false in JSON UI elements
JSON UI elements..... where?
How?
What file path in behavior pack
That actually makes sense too, the skygen made me download a resource pack (Minecraft doesn't allow me to see shared packs tho :/ )
RP/ui/hud_screen.json -> chat_label object in there
RP/ui/chat_screen.json -> messages_text->controls->text object in there
downloading packs is pretty common 
Hmm ok
Doubt it just removed the filter
It was 1.3 mb so I also doubt it
It was a very fancy skygen BP I'll tell you that
And it had an HP bar mod
Someone was going frickin NUTS over the fact that profanity was allowed after I pointed it out lmao

It wasn't pretty
I can imagine
did they remove beforePistonActivate event?
yes
Now I just need to figure out how to make these work
I've never used those files before
where are the chat events?
I recommend looking at the vanilla samples files
Still beta APIs
so there is no more chat commands anymore?
but whats the chat event now
world.beforeEvents.chatSend or world.afterEvents.chatSend
Were you here when they separated before & after events?
1.20.0 update, it was pretty big
One could say it was massive
I need up to date documentation to look at
can you point me to it
Hey can I delete these garbage files in the RP like /ui/how_to_play_common.json and /sounds/sound_definitions.json
try it and see
I just dont wanna break my game :/
Run through the https://wiki.bedrock.dev/json-ui/best-practices.html page
see what's cooking
TLDR anything that isn't needed in JSON UI can be yeeted
ahhhhhhh i was at "minecraft-bedrock-stable"
that includes stuff you haven't edited in the files themselves
ye
i see
I think I deleted too much, chat messages wont show up at all in the chat screen anymore and it throws an error that the property couldn't be found 😔
I'm afraid that if I try it directly from the vanilla pack without deleting anything it'll throw a lot more errors because
There are so many syntax errors that bridge finds in the vanilla file
Whatever
perhaps comments
lol this is all there is in the chat_screen.json file currently
{
"namespace": "chat",
"messages_text": {
"controls": [
{
"text": {
"enable_profanity_filter": false
}
}
]
}
}```
I'm a curious man, what can I say
Try adding the stuff that's in the text object from the vanilla file
Just did EVERYTHING that was already there, if it doesn't work Ill try that
ooo fun, it doesn't throw errors when loading
That's a good sign
Omg
That's so funny
It's so simple
But so funny
lol the anvil renaming still doesn't like it but it did unblock chat lmao
Well now I know
Check anvil file
Similar process
Can't find anything in hud_screen
Oh
anvil_screen isn't it
ha ha
ye
Despite what I'm doing you continue to help
What a chad
Also what's the object name
Dunno, haven't looked into that one
Oh gee
I think I found it
"[email protected]_edit_box"
autofinish says it's a property that exists there so i guess it works ¯_(ツ)_/¯
Oh, thats the same for... every object
I started putting it in every object until I find one that finally picks it up
(I dunno if it's even possible at this point :/ )
Imma get a shower. Be back in a bit
Back
Ok
So
I just realized 2 things:
1, I would probably have to mess with the anvil_screen_pocket file to make this work and
2, someone in my skygen asked me if their weapon was fine to use and they gave me a netherite sword with the name (obfuscated)GO GO GADGET CHAT DESTRUCTOR(obfuscated) then like FIFTEEN LINES of nothing, they said it wasn't a hacked item and just a resource pack, which makes me think that these two situations are similar in the way they're done
Edit: found how it's done. This little sht: json "[email protected]_edit_box": { "anchor_from": "top_left", // the parent "anchor_to": "top_left", // this control "property_bag": { "#property_field": "#item_name" }, "max_length": 30, "$text_edit_binding_name": "#text_box_item_name", "$text_edit_box_label_size": [ "default", 10 ] } The profanity filter remains unbroken
how to break shield using scripts?
so i wanna delete the command out of this and make it set the block when its destoryed is that possible?
import { world, ItemStack } from "@minecraft/server"
world.beforeEvents.playerBreakBlock.subscribe(event => {
if (event.block.typeId == "minecraft:wheat") {
let block = event.block;
let player = event.player;
let location = block.location;
event.player?.runCommandAsync(`execute @s ~~~ setblock ${location.x} ${location.y} ${location.z} wheat`);
}
}
)```
like without running a command on the player to set the block bakc
block.setType('minecraft:wheat')
but it wont save the growth progress.
also why are you not just using cancel?
wdym?
thats fine im trying to make it replant the wheat after breaking
the cancel property.
its in most of the beforeEvents
it cancels the event from happening so in this case, it would stop the block from breaking
someone helped me with making that part
I want them to break the wheat though
okay.
that would cause a duplication glitch
is that what you are aiming for lol
or are you creating an auto replanting thing
yes auto replanting lol sorry for the confusion
nah, was just wondering
all good so I would just replace the entity.Runcommand with block.setType('minecraft:wheat')?
yes.
what does this mean? and how can I fix it
don't use async run command
there is a limit of 255 cmd
runCommandAsync 
is the latest stable version 1.16.0 or 1.17.0?
Thank God it’s deleted in 2.0.0-beta, that surely won’t have any negative impacts on dev work! 
1.16.0 if you’re running stable, 1.18.0 if you’re running preview
noice, thank!
i was hoping v2 won't come out until all the beta stuff come to stable
Oh system
Thanks
how do i get a list of effects in minecraft?
import { EffectTypes } from '@minecraft/server';
console.error(JSON.stringify(EffectTypes.getAll()));```
thought i need to enter into the prototype property or some sht
There are also ItemTypes, BlockTypes, EntityTypes, DimensionTypes, EnchantmentTypes,
yes thanks anyways
guys, does anybody knows y im getting this error?
here's the line the error is showing error for
selectedItem.getEquipment('Mainhand').nameTag = `Bucket of ${target?.nameTag}`
and the error itself
[Scripting][error]-Error: Failed to get property 'nameTag' at <anonymous> (animal_bucket.js:189)
im trying to give the bucket name of an entity that player interacts with, its beforeEvents.playerInteractWithEntity
i tried to just give name of Bucket of cc, and it didnt give any error, so its pointing out that it cant get nameTag property from ${target.nameTag}
send your full code, or only the playerInteractWithEntity part
world.beforeEvents.playerInteractWithEntity.subscribe(data => {
const player = data.player
const target = data.target
const itemStack = data.itemStack
const selectedItem = player.getComponent('minecraft:equippable')
if (target?.typeId === 'v360:mole' && itemStack?.typeId === 'minecraft:bucket') {
system.run(() => {
selectedItem.setEquipment('Mainhand', new ItemStack('v360:bucket_of_mole', 1)).nameTag = `Bucket of ${target?.nameTag}`
target.remove()
})
}
})```
const charged = source?.getComponent('is_charged'); isn't working? ( trying to detect if the creeper is charged )
ive changed the selectedItem.getEquipment('Mainhand').nameTag = Bucket of ${target?.nameTag} already, trying something
Does the mole have a nametag?
yes
maybe try ${target?.nameTag()}
idk
doesnt work
has it been renamed using a name tag? or did you change it's name tag in your code?
i gave a mole nametag, and than tried to pick him up with a bucket
but the bucket didnt get mole's name
did the mole disapear?
Ohhh
You need to set the itemstacks name first before setting it the setequipment.
no
ah, hold on
wait, how do i do it actually
make a const for itemstack?
Yeah.
actually yes
const item = new ItemStack('v360:bucket_of_mole', 1)
item.nameTag = `Bucket of ${target.nameTag}`
selectedItem.setEquipment('Mainhand', item)
like this I think
okie i'll try rn
?
yay it woooorks
thank u both so much!
thought, y does it work this way, that i have to make a const for it first...
alright next: me
no idea
try to do hasComponent instead of getComponent maybe?
any errors?
doesn't work
Are u sure that thing exists?
yes it does
i should do console.warn(charged) to see
i did this in my world and it worked
const charged = target?.getComponent("is_charged")
if (charged) {
world.sendMessage("entity is charged")
} else {
world.sendMessage("entity is not charged")
}
it could be something else
its undefined
then the entity doesn't have it
but the creeper is charged
hi there, I see that I can monitor when a player take a item with the packetSend events (TakeItemActorPacket), but is it possible to identify which it was picked up?
i see
i cannot detect the charged creeper as the source
console.warn(source?.hasComponent('minecraft:is_charged')) warn: false
const source = damageSource.damagingEntity; ^
What is the shutdown event??
I will continue to improve it
I think when the world stops (host leaves) or server stops, it is only in preview tho
AYO?
data.cancel = true```
Easy cheat for realms without realms LMAO
Well it's a preview thing ofc it wouldn't be in there
fair
Just because it's a before event doesn't mean it is cancelable 🙂
I'm now just imagining someone trying to close their world but the "save & quit" button not doing anything and instead throws an error in the console
hheheheehehhehehhehheehee
if playerLeave before event was cancelable, shutdown would've been possible too
but its too op so why would mojang do that
But it wasn't, was it?
I wish there was a disconnectReason data value in the playerLeave event so I can send in chat why they dc'ed
(Like kick, reset, leave, and connection error)
that would be very useful
what should I use to run them then?
Why is runCommandAsync bad?
It just waits for the next tick after the last command (if there is one) to run it
Right?
i think so
If you want stuff to run in order like you typed in your code, then runCommandAsync ain't the way to go
I feel like it would just be an easier system.run => runCommand tho
Native methods are better to use, if they exist
Please correct me if I'm wrong
runCommand completely halts the code until the command finishes- which is a different problem. Lots of those, and the world can freeze until everything is finished running
OOHHHHHHHH
OH DEAR
Try it out, see for yourself
Yeah that's an issue I didn't know I had
I've been using runCommand EXCLUSIVELY
And I have done my best to not use it, but there's still at least like 3 of them in my largest addon :/
is there anyway i can stop dynamic properties from getting removed if i change the pack uuid?
Ok first, why do you need to change the UUID
It'll mess a lot of things up unless the pack hasn't been used yet
if you're making a new version of your pack, only the "version" fields should be changed
adding packs to realm
like updating
Yeah you seriously dont need to change the UUID for that
Just add the pack to the realm
Very simple
yeah obv bruv
Unless you managed to use the same UUID on MULTIPLE packs in this realm
im talking about updating the pack
Well then just do what Quazchick said
If it's not in the development folders it probably should be anyway
So that you don't need to jump through all THOSE hoops...
in normal packs bc it needs to be to be in a realm
I'm pretty sure you can use development packs in realms too
It just makes it so as long as the UUID is the same, newer packs overwrite older packs no matter what
Damn ok
hmm alr ty
I dont pay for realms so I guess I have to believe you
Thank you
Didn't know that existed
Maybe there should be a forum page with the most important hyperlinks
Or a pinned message here

Dev-resources is enough if people look for it
Lol there's no pinned posts there and people are lazy 😭

Yo bois
Is there someway to store data on the player?
(Across addons)
I know i can just use ipc or even scriptevent and set the props from one addon to another
But
I'm just asking if there is a vanilla way
scoreboard db
hi i have problem with my chat rank addon
world.beforeEvents.chatSend.subscribe(({data}) => {
});
wtf
What script version are you using
1.17 beta
hmm
Yeah i said, "store on player" not exactly shared storage but yeah that's probably the only way
oh no sorry i just realized i m using 1.6.00
What version is your mc?
Nvm
Welp, that'd do it lol
oh okay
should i save the code inputted by the user?
currently saving only the setting
Yessirrr
so, an auto save that it interval can be changed from the setting, how that sound?
That sounds w
Ok 2 things: I'm pretty sure you don't put brackets around the data value (only the parenthesis), and second of all, are you importing world properly?
it was the script version
Oh
lol
i don't know either
is there a way to execute an scripting code when a new chunk is loaded?
Not really sure
But
There is a command
/schedule i think
It triggers when a chunk is loaded or smth. Go read about it
oohh
I will try thx
aah it works only with functions?
You can do:
world.getDimension('overworld').runCommandAsync('schedule <params because idk them>').resultCount;
It's something
Idk if it's .resultCount
Check the docs because i think my memory is rusty
I mean, /schedule params work only with mcfunction
like /schedule on_area_loaded add <from: x y z> <to: x y z> <function:filepath>
So, I need to add a mcfunction with /scriptevent or something
its .successCount
^^^
it resturns if the command ran successfully or failed
i think it returns 0 if it failed and 1 if it succeded?
or maybe the opposite
And its possible to have the actual result of the player
Li idk tag list
Like*
Okay
but the script will not wait util its success, because the command wait until the area load, not the script, if the area isnt loaded it will return 0 and will not wait until the command is success, so, you have to use a mcfunction with scriptevent anyway
anyone got like an anti fly?
he meant a mod that stops hacker from flying
._. ik , i m just trolling
👍
Erm 🤓☝️ /ability @s mayfly false
Hmmm
You need education edition
And its buggy
Oh sorry i just read all messages
Lol
define buggy
Bug bug
you don't even know what hell is buggy then why say that's buggy 😭
Bro look at my name
fair enough....
lol
How can I change the slot selected by the player? I want to force him to change to a specific slot in the hotbar
I think its impossible
ah its selectedSlotIndex you can change its value
Nah after this i want to kms
Look at my name…
try player.selectedSlotIndex = 1 for example
Nah, stop using that stupid excuse
then 🤫
right?
Bro but It explains itself
I called myself i dont know for a reason
^
😦
New name
I fully revamped my shitty compact+++ almost obfuscated code into 3 different addons with each for their own purpose and everything is a bit more descriptive
Your right
You'll eventually know better than anyone
(Impossible but just lifting your spirits)
What will come out first? OreUI or that he knows everything xd
OrYouKnowUI
goofy ahh cat
Me during exams be like:
Midnight Dopamine rush
i should look into implementing a workspace feature
this shii is gasss
- add a way to make new sheet and remove the old one ,
- Select all text feature
i contributed 0.5% in that
less, lol
0.01% lmfao
new sheet? file?
you can select all manually
maybe a copy button to automate is
I love 🐛
I help people find bugs in their things but I can't find bugs in my own scripts 💀😐
How do I round off a float value leaving 2 decimal places?
value.toFixed(2)
What'd you guys think is the best way to check if a player's full body is submerged to water
not player.isInWater since it will return true if it hits any part of the players collision
So it's not possible to make a system where taking damage changes the texture of an item?
Correct.
How do I set an item's name using this js sender.getComponent(EntityEquippableComponent.componentId).getEquipmentSlot(EquipmentSlot.Mainhand)
.nameTag
yeah, why would it not work?
some are both some are get only
const equippable = Player.getComponent('equippable');
const mainhand = equippable.getEquipment('Mainhand');
mainhand.nameTag = 'Bruhhh!';```
How to make my entity spawn behind or next to trees?
Is that a thing that's in stable?
sorry for late reply, I opened this channel and it showed that
is it possible to make bocks place in a world similar to a scatter feature using script api?
yes
Block above and block below is water maybe
Or block 3 higher than players feet is water
Is there a method to get beta top screen infos ?
Can we not run custom chat commands from a command block??
You can run only these with slash
Custom chat commands are just chat messages, so you can't run them from a command block
If you want to do something similar then you can use the scriptevent command
Is there a general module that includes everything that script api dev may use it when working on add-on ?
hmm,
how am i going to detect the killed entity from world.beforeEvents.entityRemove component?
like how?
What I'm trying to do:
detecting when the charged creeper killed some specific mobs.
entityDie isn't good already?
entityDie cannot detect the charged creeper as a killer
tell me if it is possible to detect the charged creeper as the killer in the entityDie component.
Hmm, how are you detecting it?
nvm that question lol
world.afterEvents.entityDie.subscribe(({deadEntity: eEntity, damageSource}) => {
const source = damageSource.damagingEntity;
if (!source) return;
const charged = source?.getComponent('minecraft:is_charged');
if (source?.typeId === 'minecraft:creeper' && charged) {world.sendMessage('?')}
});;```
should i like unsubscribe or something?
Can you do something like this?
const chargedCreepers = new Map();
world.beforeEvents.entityRemove.subscribe(({ removedEntity }) => {
if (removedEntity.typeId === 'minecraft:creeper') {
const isCharged = removedEntity.getComponent('is_charged');
if (isCharged) chargedCreepers.set(removedEntity.id, true);
}
});
world.afterEvents.entityDie.subscribe(({ deadEntity, damageSource: { damagingEntity } }) => {
if (chargedCreepers.has(damagingEntity.id)) {
chargedCreepers.delete(damagingEntity.id);
}
});
since you said that you can't check if the creeper is charged in the entityDie as the killer
datadrivenentityevent and entitydie combo...
hell yeahhh
-# I forgot that it existed ngl
world.afterEvents.dataDrivenEntityTrigger.subscribe(ev => {
const { entity, eventId } = ev;
for (const modifier of ev.getModifiers()) {
const { addedComponentGroups, removedComponentGroups } = modifier;
console.warn(`Added component groups: ${JSON.stringify(addedComponentGroups)}. Removed component groups: ${JSON.stringify(removedComponentGroups)}.`);
}
});```
you dont need to do all that modifier stuff, just check for the event id

I didn't say he needed it 😭
okay.
optional chaining
the one below isnt dealing with the typeId property
lol
^ you did this?
use this combo then
all codes:
const chargedCreepers = new Map();
world.beforeEvents.entityRemove.subscribe(({ entity }) => {
if (entity?.typeId === 'minecraft:creeper') {
const isCharged = entity.getComponent('is_charged');
if (isCharged) chargedCreepers.set(entity.id, true);
console.warn('8')
}
});
world.afterEvents.entityDie.subscribe(({ deadEntity, damageSource: { damagingEntity } }) => {
if (chargedCreepers.has(damagingEntity.id)) {
chargedCreepers.delete(damagingEntity.id);
console.warn('88')
}
});```
this is in afterEvents.entityDie
removedEntity
I just said it 😭
im trying to detect the charged creeper
it's removedEntity not entity
I'm out here ebruh 😭😭😔
lmaoo
just chilling lol
and thats his response
my response: 😔😞
poor guy
double checking:
world.beforeEvents.entityRemove.subscribe(({ removedEntity }) => {
if (removedEntity?.typeId === 'minecraft:creeper') {
const isCharged = removedEntity.getComponent('is_charged');
if (isCharged) chargedCreepers.set(removedEntity.id, true);
console.warn('8')
}
});```
alright it works,
my phone is doomed, twice...
See? I'm not wrong... You're wrong
-# somewhat a reference to a movie
at least it works so i dont have to use normal creepers instead of charged creepers
world.afterEvents.entityHurt.subscribe(({ hurtEntity, damageSource: { damagingEntity, damagingProjectile, cause }, damage }) => {
if (hurtEntity instanceof Player) {
const effect = hurtEntity.getEffect('resistance');
const amplifier = effect ? effect.amplifier : -1;
const reduction = Math.min((amplifier + 1) * 0.2, 0.8);
const resistedDamage = damage * reduction;
const finalDamage = damage - resistedDamage;
console.error(`Original Damage: ${damage}, Resisted: ${resistedDamage}, Final Damage Taken: ${finalDamage}`);
}
console.error(damage);
});
Halp, my calculations are wrong
-# I have a similar problem before... And I forgot where was the fixed
I thought the damage from entityHurt was already reduced after the minecraft calculation
it works like the java one
I use that for checking if my calculation was correct
Which isn't lol
no matter how many mobs is killed, only one of them will drop its head
YOU,
is this really necessary? chargedCreepers.delete(source.id);?
its the one at the entityDie section
i add it inside of system.run to give it a little bit of delay so all mobs will drop their heads
axolotl heads is evil 😞
shut it, if u love them, do not explode them using a charged creeper.
Guys, need help:
This is not working and I don't know why:
world.afterEvents.playerInteractWithEntity.subscribe((eventData) => {
const player = eventData.player;
const entity = eventData.target;
if (entity.typeId !== "test:open") return;
if (!player.hasTag("player_1")) return;
if (player.getDynamicProperty("interacted") === true) return;
const existingScoreboard = world.scoreboard.getObjective("TEST") ?? world.scoreboard.addObjective("TEST");
const currentScore = existingScoreboard.getScore(player) ?? 0;
existingScoreboard.setScore(player, currentScore + 1);
player.setDynamicProperty("interacted", true);
});
What's here wrong?
After I interact with entity, I don't get scores. Also my entity has transform component, so after player interact with it it should transform but score should be added
hey guys, how can i randomize this item list, to get one random item to insert into my entities inventory later on?
const itemList = [
"minecraft:torchflower_seeds",
"minecraft:pitcher_pod",
"v360:blue_bonnets_seeds",
"minecraft:acacia_sapling",
]```
with server-net are you able to write json files and read them?
array[Math.random()*array.length]
i figures it out from here, thank u smokey once again
Can someone help me with scores? Please?
ive been reading a lot about javascript for the last couple of days, strating to understand more and more
Good for u
is there anything i need to know about before using explosion before event?
any bugs?
or limitations
Is it possible to spawn a particle for a player, and have it be visible to whoever I define? I'm using the 1.17 experiment
It is, yes. You can use Player.spawnParticle() instead of Dimension.spawnParticle()
Would it be possible for me to select the players who will spawn the particle and only 1 player will see the particle, like a wallhack that allows you to see the players through the wall?
for example I, as an admin, can see the players through the particle, there will be a particle above the normal members and only the admins will be able to see it
The Player.spawnParticle() spawns it only for one player; nobody else sees it except for them
It's true that I hesitated, I remembered that I can do what I need with this, thank you
yes
Why is this happening?
Code:
mc.world.afterEvents.entitySpawn.subscribe(function (event) {
const entity = event.entity
for (let i = 0; i < entityIds.length; i++) {
if (entity.typeId == entityIds[i].id) {
entity.nameTag = ("Level: " + getScore(entity, "level"));
}
}
})
function getScore(entity, objective) {
try {
return mc.world.scoreboard.getObjective(objective).getScore(entity.scoreboardIdentity);
} catch (error) {
return error;
}
}
Wow, this got me! But i have no idea how that happen
why are ypu returning error
Because i m on the phone and i hate modifying files over and over
And the pc is so sloooo
maybe its bug bc there is noo try catch asf as i know
weird
@neat hazel send more!
Well, if the get score errors, it returns the error, so
so it doesn't throws?
damn i se
my bad haha
i am blind or something
for sec i thought the getScore is native
haha
This is the error
[Scripting][error]-TypeError: Native variant type conversion failed. Function argument [0] expected type:
ScoreboardIdentity | Entity | string
entiy.scoreboardIdentity might be undefined use entity as target directly
entity is not in sb then
Like this?
does it throws for entity as well in that case?
i am not using scoreboard apis too much
Oh, sad
don't be there are many pros here whose are not cons
there might be test method, you should prob use that first
i am fan of returning null and handling the possibility of it, but in some cases returning number would also make sense
So it works now? Or is there anything i can help you with?
does anyone know why spawnItem is working, but the item disappears too fast?
it spawns for like 1 second then just vanishes, I don't get it, am I doing something wrong?
There's no pickup delay, if that's what you're after
it's not that, I'm using addItem, and if the inventory is full it drops on the floor instead,
but I just tested it, it spawns for 1 second and immediately despawns before the player can take it
Are you in creative?
yeah
That's why.
Creative mode doesn't care about inventory slots. If it's full, they just suck it up into the void.
I think I managed to fix it
One question, is there entity.getComponent("minecraft:health").setDefaultValue
Or any way to change the default life of an entity without using its Json code?
so far there is no way in API
Exactly, you can only set the current value, not the default
i meant max one
world.beforeEvents.playerInteractWithEntity.subscribe((event) => {
event.cancel = true;
})
This event should reject all entity interactions, right?
So does this include a player picking up an item?
interaction means interact component
like opening villager menu
How can I find out the highest version of Minecraft-server and server-ui modules?
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]
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]
I want to change the code while i m testing
dev packs ?
Using the `development_*_packs` folders
The correct way to create addons is by using the development_behavior_packs and development_resource_packs folders. Storing your addons here will allow you to reload the world to see addon changes, and will prevent pack caching issues.
You can work directly in the world, or in behavior_packs/resource_packs, but you need an understanding of manifest-versions and caching to avoid issues.
We highly recommend using the development_*_packs folders.
world.beforeEvents.playerInteractWithEntity.subscribe(({ target, player }) => {
if (target.typeId === 'trix:cucaracha') {
const heldItem = player.getComponent("minecraft:inventory").container.getItem(player.selectedSlotIndex);
if (heldItem && heldItem.typeId === "trix:maracas") {
world.playSound(`random.tick`, player.location)
before events cannot modify the world at all
Do u have a sample or an example,
- Does it work in Minecraft bedrock pc or mobile or both ?
Ah
If I put the playsound in a function will it work?
Use system.run or after event so you aren't in read-only mode (before events)
You need to delay it by 1 tick. Use system.run
If you switched to afterEvents, it would only run to successful entity interaction iirc.
Ty
is there a way to make a vanilla block wither proof?
@valid ice , so i must put the folder inside add-ons folder , dosent .mcaddon work with it ?
.mcaddon makes minecraft import the addon into the "normal" and not "development" folder
The difference is the former gets cached into the world folder, while the "development" doesn't. Since it never get cached, you can edit it and use /reload in game
just change it and reload?
I don't know how
I import my addons as .mcaddon
...
If the pack is in the development folder, you just need to update the files and then run /reload
Hmm , i need to put it inside games folders in programs/ windows?
Wherever your com.mojang is
There's regular folders and development folders for BP & RP
Ok then
I am suprised you never knew about dev packs up until now
he did ask about it before, either he had problems with it and didn't get how it work or idk
Maybe i m doing many things wrong
Get all dead entities
Why are you there.
They told me dev behaviour pack ?
I think that's not what they meant.
._.
they mean is the coming.mojang folder
C:\Users\USERNAME\AppData\Local\Packages\Microsoft.MinecraftUWP_8wekyb3d8bbwe\LocalState\games\com.mojang
Thank u
Or this
%localappdata%\Packages\Microsoft.MinecraftUWP_8wekyb3d8bbwe\LocalState\games\com.mojang
One thing I would like to comment on about custom components.
From what I understand, so far the custom components are more like tags, it is not possible to give more information to the game other than saying that the block has so many components.
I hope that in the future, it will be possible to use custom components as {} objects, with their own properties.
That will be custom components v2.
Don't worry, you're not alone in thinking this.
what is this thing called
accidentally enabled it and idk how
Insertion?
Do the youngins not know about insertion?
-# getting called youngins from someone younger than me 
cursor block or whatever it is called
what is Insertion too?
If I write the code like this, will it work? 
getting called youngins from someone younger than me
👴 Well clearly if you don't know what it is.
I call it insertion since it inserts the char at that location. Maybe replacement is a better name but I call it insertion since you press the insert key.
i know what id does lol
just not the name
searching show result on vim, idk how my finger even reached there lol
is there no regeneration option in ItemStack.createPotion?
Hmmm is math random is even that random
I read about randomness while learning some c++
try it out
I don't understand statistics: P
Math.random() was never random.
But it (gladly) does do it's job.
guys regarding this.
is this how you use it?
Entity.setDynamicProperties({
property1: "value1",
property2: 42,
property3: true
});
don't you need to use JSON.stringify?
oh nvm
it's properties not property
can someone help, how do I give someone a regen potion with itemStack.createPotion
there's no way regen actually doesn't exist as an option
it accepts string right? did you try to put it?
Huge project is coming!!!!
yes, I did ItemStack.createPotion({ effect: "Regeneration" });
Healing works, and just gives me instant health
Try to lowercase it.
all of the effects are uppercase
yeah that's the one I followed
nevermind I was doing the 1.21.51 version and apparently regeneration just doesn't exist there
bruh wtf
nice so I have to wait till 1.21.70 to use potion effects
why tf would half of them be missing anyway?
I think in 1.21.60 it's there
tho I didn't try it.
For some reason they forgot to add regeneration
Also the list for potion support via api is here https://jaylydev.github.io/scriptapi-docs/latest/enums/_minecraft_vanilla-data.MinecraftPotionEffectTypes.html
yeah I re read the docs like 50 times thinking I was crazy cuz I thought no way they forgot regen
They always forget what people needs | : ( * mad villager noices*
my whole system relied on the create Potion method so this is really annoying
I need life.

yey
btw I added too many themes lmfao
Please minato the next time remove the placeholder text it s annoying for mobile ppl
auto save to an empty file, it should keep it
btw is that draggable?
idk if i should keep it tbh, shit git confusing
- make it so u can select text too :-:
no
you can?
Damn. 2/10
You can.
😭
-# skill issue
drag select
is there another way to give potion types? I'll have to change my system specifically for regen ig
structure?
yeah could do that
since commands can't do that since it's id is only potion
Or setItem
create potion should work
regeneration isn't added yet.
also, I have a question, let's say 2 people stand close to a structure item, does the person with better internet pick it up?
Goofy ahh nvm
There's data systems
or would it be the person you load it on since they're closest?
/give @s potion 1 10
Idk but , they doing it to make ppl struggle or their funds are very low
oh yeah I forgot about that
yknow it's strange that system still exists, they changed concretes to have unique IDs but not potions
ngl, I feel like it's not needed, just use vscode 🤷
-# or notepad++ 😝
I'm making a plugin for notepad++ lmfao
yeah.
meh, it is just for fun lol
-# and for when i don"t want to load vs to tyoe code for someone
idk how helpful it is for mobile users
for?
Hmm , i have question ,_,
Is there a loophole that can we use it to get more script api features
Idk like , getting some real in used game functionalities in c++
Using js
And some loopholes
lets move to #off-topic
Base code will always be hidden, and internet access for addons is restricted anyways
Hello Guys
haii
227? There's 3.6k online
its how many people following this post that are online
ah ye
Thread had to be cleared out because there's a max user limit per post :discordthink:
im curious why its not just a channel then
but you would have to do that with the other forums to be consistent
would not look nice neither
Back then we only had 10k members and scriptAPI was a niche thing.
2.7k members online, 3.6 users one
really? weird.. maybe my thing isnt working
are beta scripts generally safe to use? I've been waiting for the chat functions to come out forever. HCF and beta json stuff would make it so your world was permanantly stuck like that, but can you just turn beta scripts off once the stuff you use goes out of beta?
If you plan on actively maintaining and updating your addon, then yes. otherwise, no.
Stable is only better for the reason that it never should need upated.
You cannot turn off experimental toggles.
i didn't realize beta-apis needed a toggle ._.
They're safe in that they won't just randomly corrupt your world
And the script API toggle will be around for quite some time yet, as the team is always adding new features
well I was not aware of that, interesting to know
is there any way to tell what parts will come out of beta? I thought the chat functions were in beta 1.16.0 when we were on 1.15, but now they're in beta 1.17
Readin' the changelogs
i mean ahead of time, like if there were some other info source on what would actually come out of beta rather than just stay there each update
Yeah, reading the changelogs lol.
???
this just says "added xyz chat events" https://learn.microsoft.com/en-us/minecraft/creator/scriptapi/minecraft/server/changelog?view=minecraft-bedrock-stable
No, the preview changelogs.
where are those?
Thanks!
rip to chat events. unless I missed them they'll be in beta all the way to 1.19 at least
Well, there ain’t no 1.19
It’s now 1.18.0 and 2.0.0-beta for versions, starting in 1.21.70 previews
i figured since the 1.18 posts didn't say anything about them they would stay in beta through 1.18
I just wanna make typed-in-chat skyrim shouts. lol
if they remove a beta script thing can you still access it by setting your script version back to a version that had it?
let playerIndex = 0;
system.runInterval(() => {
let players = world.getAllPlayers();
if (players.length === 0) return;
let player = players[playerIndex];
if (player) {
player.sendMessage(`${playerIndex}, ${player.nameTag}`);
}
playerIndex = (playerIndex + 1) % players.length;
},1);
Why not just forEach or for loop it
is it the same? I thought it would execute its commands on all players at once
ohh, I'm trying to find the most efficient way to runInterval besides changing the tick
.
system.runInterval(() => {
for (const player of world.getAllPlayers()) {
const item = player.getComponent('inventory').container.getItem(player.selectedSlotIndex)
if (item === undefined) {
world.sendMessage('test')
}
}
})
if using this then the code will be executed on all players at the same time, if using the one I sent earlier then the code will be executed alternately for each player
It still runs in-order, for both a for loop and a forEach
Ah I see, it makes each player have their own tick. My bad!
so which do you think is more efficient?
Do you need to sequentially run code for each player, so each runs one tick after the last player?
umm, I just want if there are a lot of players, it won't overload cpu
I would suggest using runJob & generator functions
It automatically allocates as much code per tick as can be run, then runs the next stuff when it can
There's an example on how to use the function on that page
ok thanks
It is possible to obtain all blocks of a certain type within a specific radius. ?
I'm trying to make the Squid Game "Crystal Bridge" game, but not all the blocks are always destroyed.
getBlockFromRay
Could it work?
how can I make a block run a command every x seconds?
If custom block ,use custom components and the tick component.
thank you!
import { world } from "@minecraft/server"
world.afterEvents.buttonPush.subscribe((data) => {
const source = data.source
const block = data.block
const buttons = [
{
button: {
z: 8,
y: 51,
x: -14
},
rank: "alts:green"
},
]
const buttonMapRank = new Map(buttons.map(({ button, rank }) => [button, rank]));
const rank = buttonMapRank.get(block.location)
const roleTag = source.getTags().find(findTag => findTag.startsWith(rank.substring(0, 6))) == undefined ? "" : source.getTags().find(findTag => findTag.startsWith(rank.substring(0, 6)))
if (rank == roleTag) {
source.removeTag(roleTag)
} else {
if (roleTag === "") {
source.addTag(rank)
} else {
source.removeTag(roleTag)
source.addTag(rank)
}
}
})```
Why isn't this working
I'm trying to make a wall of buttons that you can push to add/remove a tag
But I only want one tag on each person of each prefix
So, like 1 tag from alts: and 1 tag from ranks:
Wait I broke the code that I was trying to show hold on
There we go
When I push a corresponding button nothing happens, at all. Not even an error. Absolutely nothing changes
import { world } from "@minecraft/server";
world.afterEvents.buttonPush.subscribe((data) => {
const player = data.source;
const block = data.block;
const buttons = [
{
pos: "-14:51:8",
tag: "alts:green"
},
];
const buttonMap = new Map(buttons.map(({ pos, tag }) => [pos, tag]));
const blockKey = `${block.location.x}:${block.location.y}:${block.location.z}`;
const tag = buttonMap.get(blockKey);
if (!tag) return;
const currentTag = player.getTags().find(t => t.startsWith(tag.substring(0, 6))) || "";
if (tag === currentTag) {
player.removeTag(currentTag);
} else {
if (currentTag) player.removeTag(currentTag);
player.addTag(tag);
}
});
Ok
Ill try this
I just realized
BROO
I FORGOT TO IMPORT IT IN MAIN.JS WTF 😭
But your method is probably more efficient anyway
Ok so this does work to add and remove a tag of the same name, but it doesn't work to remove a tag of the same prefix
And I can't for the life of me figure out why that is
if (currentTags.includes(tag)) {
currentTags.forEach(t => player.removeTag(t));
} else {
currentTags.forEach(t => player.removeTag(t));
player.addTag(tag);
}```
????
Is this supposed to be replacing the original if statements
yeah.
And what's the currentTags variable
still the same
There's no currentTags variable in your code
Unless the if statement defines it by itself but I doubt that
const currentTags = player.getTags().filter(t => t.startsWith(tag.substring(0, 6)));
Ok
Hmm, it still has the same result as before, it removes the tag of the same name but doesn't remove the tag of the same prefix
Is the subString wrong?
can you explain what you're doing again.
I'm trying to make a wall of buttons that you can push one of them to add/remove a tag, BUT there are families of tags differentiated by their PREFIX, like "rank:" and "alts:". I only want each person to have a MAXIMUM of ONE tag per prefix
Does that make sense?
then the problem is the substring
Ok is it the first or second parameter (the prefixes are always 5 characters long, including the ":")
Substring has a tendency to confuse me because I'm not sure what character it starts and ends counting at
Is subString(0,5) going to select the first five characters, or four characters? Is subString(1,6) going to select the first five characters starting from the second letter, or the first? Things like that.
Welp
I figured it out by myself
It was in fact the substring
It needed to be (0,5) instead of (0,6)
ever tried level.dat file?
In game. Anything is possible via external modifications. But you're not going to tell someone to edit the binary files using dll injections and hex editor to build past the 128 block height limit in the Nether.
Just text editor
It's still risky ngl
Isnt World initialize missing?
system.afterEvents.scriptEventReceive.subscribe((event) => {
if (event.id === `gwim:bounty` && event.initiator === `minecraft:player`) {
let player = event.initiator;
player.sendMessage(`Testing`);
setManualDailyBounty(player)
}
});
can anyone help me ?
This scriptevent isn't working
When i use the command, it just says that the scriptevent is sent
it doesn't even give errors
if anyone can help, then please ping me
yea lol
https://learn.microsoft.com/en-us/minecraft/creator/scriptapi/minecraft/server/worldinitializeafterevent?view=minecraft-bedrock-stable
https://learn.microsoft.com/en-us/minecraft/creator/scriptapi/minecraft/server/worldinitializebeforeevent?view=minecraft-bedrock-stable
It's still there, tho
event.initiator
initiator: If this command was initiated via an NPC, returns the entity that initiated the NPC dialogue.
So, that will only work within NPC dialogue. If you want to call it as a command too, maybe you want to use event.sourceEntity
@runic crypt
Okay thank you
@random flint
system.afterEvents.scriptEventReceive.subscribe((event) => {
if (event.id === `gwim:bounty` && event.sourceEntity === `minecraft:player`) {
let player = event.sourceEntity;
player.sendMessage(`Testing`);
setManualDailyBounty(player)
}
});
if you meant like this
then it doesn't work :D
wait is it because i have event.sourceEntity twice ?
ah, you forgot .typeId
for && event.sourceEntity ==...
yep
ah okay okay
what if i remove it btw ?
just keep the second event.sourceEntity
Yeah, kept that one. Don't change it
ok ok
system.afterEvents.scriptEventReceive.subscribe((event) => {
if (event.id === `gwim:bounty`) {
let player = event.sourceEntity;
player.sendMessage(`Testing`);
setManualDailyBounty(player)
}
});
imma try this 🫡
world.beforeEvents.worldInitialize.subscribe(({ blockComponentRegistry }) => {
blockComponentRegistry.registerCustomComponent('jay4x:egg_block', {
onTick() {
if (system.currentTick % 20 === 0) {
console.warn('tic')
}
}
});
});```
how would I run a command off this?
Here's a janky way.
world.beforeEvents.worldInitialize.subscribe(({ blockComponentRegistry }) => {
blockComponentRegistry.registerCustomComponent('jay4x:egg_block', {
onTick(event) {
if (system.currentTick % 20 === 0) {
console.warn('tic')
const location = event.block.location;
event.dimension.runCommand(`execute at ${location.x} ${location.y} ${location.z} run say ...`)
}
}
});
});```
If you don't care about position, then skip the `/execute` and `const location` part.
Though advised to just use native method instead of commands.
well is it possible to summon a entity where the block is then destory the block? without commands
@random flint
either im doing something wrong
or part of my code is wrong cuz its still not working :F
and amen for that 🙏
can i dm u the code ?
its too long to send here
//spawning zombie inside the block
event.dimension.spawnEntity("minecraft:zombie",event.block.location);
//set block to air (doesn't have destruction particle)
event.block.setType("air");
so like this?
world.beforeEvents.worldInitialize.subscribe(({ blockComponentRegistry }) => {
blockComponentRegistry.registerCustomComponent('jay4x:egg_block', {
onTick(event) {
if (system.currentTick % 20 === 0) {
const location = event.block.location;
event.dimension.spawnEntity("minecraft:chicken", event.block.location);
event.block.setType("air");
event.block.spawnParticle('minecraft:totem_particle', event.block.location);
}
}
});
});```
i added the spawnParticle
Ye. You can clean the code afterward
can i change the block permutation to be place in beforeOnPlayerPlace? I tried permutationToPlace = permutationToPlace.withState(...) but doesn't work
How to make my entity despawn when there is a block in front of the player's eye or sight which blocks the player from seeing my entity.
has anyone made a way to stop pistons from pushing custom blocks? I remember there being a block component ages ago that had that as a toggle but no longer
You can use gpt API in your world?
Using wss + nodejs or python ye
using setCurrentValue in runInterval acting like deafault value 🗿
searching show result on vim
uh vim?
no way lol
The text editor bruh
const equ = player.getComponent("equippable");
const damage = equ.getEquipment(EquipmentSlot.Chest).getComponent("durability").damage;
this keeps saying Failed to get property 'damage' at onUse (index.js:228), why?
the item is a diamond chestplate
When in doubt, check every step of the way:
const equ = player.getComponent("equippable");
console.warn(equ.typeId);
const chestitem = eq.getEquipment(EquipmentSlot.Chest);
console.warn(chestitem.typeId);
const durability = chestitem.getComponent("durability");
console.warn(durability.typeId);
const damage = durability.damage;
console.warn(damage);
Perhaps the item is not damaged, or perhaps your scripting API version does not have an item durability component class. Need to check every edge case
try making a variable for the item 1st
is there a native api method to give tipped arrows like there is for createPotion?
no there is not afaik
is the fog a json ui thing?
no, #1067869590400544869 UI means User interface
fog is in a separated folder
rp/fog/fog1.json