#Script API General
1 messages · Page 28 of 1
yeah the admins disabled my bot in that channel
alrighty
hey is it possible to contain data inside an item?
I want to save strings or integers in an item
when setting a lore is it possible to do breakline??
item.setLore(["That's Overkill", "wow"])
it technically breaks line visually but its not the same as \n
to break lines use
item.setLore(["That's Overkill\nwow"])```
can be useful to avoid lore limit
what's the difference of usin ' and \n?
item lore is an array, which stores multiple strings or values
this one is technically a string
while this one is two strings (lines?)
Correct
both visually does the same but there are limits of how much letters you can put in a line and how many lines you can use for the lore
oh that's cool huh now I can store values in lores
welp thanks a lot people
Is there a way to open a gui from a block that have the player inventory in it without using entities
Opening something like this
Is it possible to add lore to items
Yes
How?
I don't think it's possible I ask the same question and they said no
make an invisible chest entity, use json ui to customize it, put the entity inside of a block
Oh I already figured it out it was actually in the loot table where you set the lore function I thought you need scripts haha silly me
speed you can except if it's a player,
and yes, you can change health
you can change speed iirc
can i change the damage too?
nah
only the stuff in attributable component
some components can be changed too but its only few
and damage cant be changed
were can i find them?
Tks bro

both can be changed
it is just that player speed reset after he do another action that change the speed
same for entities
Does health reset with the script?
Or it's permanent
@distant tulip Iirc you tried to detect double chests before, did you manage to get that working? Nvm
you can't set the max value
so yeah
ok tks
no
i was trying to shoot a ray between the tow chest and see if the ray hit it
turns out there is a gap there. you can even shoot arrows between the tow
Interesting
maybe try getting the chest inventory?
but i thing it will give you just half of it
Yeah, found this #1196695930104205393 so problem solved. Thanks
Does this work individually in multiplayer?
for example I want to summon something only for the player who died and not for all players on the map
yeah
entity after the if is the dead player
i want to shrink the player down
but the camera won't scale with the player
how can i move it
how long until server 1.15.0 is out of beta?
maybe after the next preview
only on bedrock dedicated server
there you can use the @minecraft/server-net module
but sadly it does not work on realms and worlds
Is it possible to test what biome a player is in?
lol, I was just thinking about this
this is something I really want in the api, but its sadly not possible yet.
Darn, thanks for the response!
You can combine player.json and ScriptAPI
Could you explain? You're most likely referring to the biome sensor component, right?
Isn't Dimension.findClosestBiome a thing? or is it still on preview?
how can i get itemuseon to fire regardless of whether or not there is something in the hand?
findClosestBiome returns a vector 3
and it takes time to execute
`function isHoldingRequiredItem(player) {
const inventory = player.getComponent("minecraft:inventory").container;
if (!inventory) return false;
const mainHand = inventory.getItem(player.selectedSlot);
return mainHand?.typeId === REQUIRED_ITEM;
}`
what the error??
What is block tick and how do i use it
turn content logs on
I managed to solve it
why the hell do i keep getting this error
for this code
Kits_Settings(player) {
// Retrieve the current kit settings
let kitsEnabled = world.getDynamicProperty('kits_enabled')
let maxKits = world.getDynamicProperty('max_kits')
let MoneySystem = world.getDynamicProperty('MoneySystemName')
const form = new ModalFormData()
.textField('Kits Limit (default is 10)', '10', maxKits)
.toggle('Kits Enabled §cOFF§r/§aON', kitsEnabled)
.textField('Defualt Money Scoreboard', 'money', MoneySystem)
form.show(player).then((data) => {
const KitsLimit = data.formValues[0]
if (NaN(KitsLimit) || KitsLimit <= 0) {
player.sendMessage(`Error: ${Errors.NotANumber}`)
return;
}
})
}
[Scripting][error]-Unhandled promise rejection: TypeError: Native optional type conversion failed.
check if the dynamic properties have correct types
wdym
a dynamic property might be having wrong type
like it might need number but it could be getting string
i just redid them with new names and stuff and it still breaks...
Is it possible to increase the tick speed of a certain area using script
that's pointless and your limiting yourself for no reason. Items have dynamic properties for storing custom values
no
you can't change tick speed at all in bedrock
oh, is there a workaround,
Im trying to make crops within a certain radius of a block grow faster,
is there a way i can simulate this
yes probably
not easily though
you'd have to find all the crops in that radius, keep track of them, and then set up your own random ticking interval to grow them
💀
Maybe using BiomeSearchOptions could reduce the time?
If it returns Vector3 then just check if the player's location is within or near that Vector3
:yes_cat:
yeah, Thanks
How would I detect the block permutation so that way my code avoids the block the state lb:opened set to true?
how do i get the container component of a chest?
How to teleport player to where is he facing?
Const location = Player.getBlockFromViewDirrction().block.above().center()
Player.teleport(location)
center() -> bottomCenter()
if you want to be precise then yeah
how to player repair item that he holds?
ask pls
const itemStack = player.getComponent("inventory").container.getItem(player.selectedSlotIndex);
itemStack.getComponent("durability") ? itemStack.getComponent("durability").damage = 0 : null;
player.getComponent("inventory").container.setItem(player.selectedSlotIndex, itemStack)
@tawny reefDont go crossposting please
i just want help im sorry
Umm, how do i use a block to get other blocks within a set radius
question: in the newest versions of MCPE the new scripting works for IOS like in PC?
Yep; script API works for all platforms, all users.
is this still true?
are there any other tutorials for ore ui than this? https://react-facet.mojang.com/docs/getting-started
you can't modify ore ui with add-ons
how do you use it then?
I'm just trying to make scoreboard variables show up above the hearts and armor for my world/realm
you can still do that since the HUD isn't ore UI yet
so ore ui isn't ready yet and we still use json ui until it is?
yes
When using custom commands, is there a way i can force the player chat menu to close after executing the commands
is it possible to create a custom bundle?
Yes #1067869136606220288 please
oh sorry
you cant
we do not have access to ore ui currently.
const itemStack = player.getComponent('equippable')?.getEquipment('Mainhand');
if (itemStack) {
system.run(() => {
itemStack.getComponent("durability") ? itemStack.getComponent("durability").damage = 0 : null;
player.getComponent("equippable").container.setItem(Mainhand, itemStack)```
Error: cannot read property ‘setItem’
helppp
Debug result for [code](#1067535608660107284 message)
Compiler found 4 errors:
[36m<REPL0>.js[0m:[33m1[0m:[33m19[0m - [31merror[0m[30m TS2552: [0mCannot find name 'player'. Did you mean 'Player'?
[7m1[0m const itemStack = player.getComponent('equippable')?.getEquipment('Mainhand');
[7m [0m [31m ~~~~~~[0m
[36m@minecraft/server.d.ts[0m:[33m4559[0m:[33m15[0m
[7m4559[0m class Player extends Entity {
[7m [0m [36m ~~~~~~[0m
'Player' is declared here.
``````ansi
[36m<REPL0>.js[0m:[33m5[0m:[33m13[0m - [31merror[0m[30m TS2552: [0mCannot find name 'player'. Did you mean 'Player'?
[7m5[0m player.getComponent("equippable").container.setItem(Mainhand, itemStack)
[7m [0m [31m ~~~~~~[0m
[36m@minecraft/server.d.ts[0m:[33m4559[0m:[33m15[0m
[7m4559[0m class Player extends Entity {
[7m [0m [36m ~~~~~~[0m
'Player' is declared here.
``````ansi
[36m<REPL0>.js[0m:[33m5[0m:[33m65[0m - [31merror[0m[30m TS2304: [0mCannot find name 'Mainhand'.
[7m5[0m player.getComponent("equippable").container.setItem(Mainhand, itemStack)
[7m [0m [31m ~~~~~~~~[0m
``````ansi
[36m<REPL0>.js[0m:[33m5[0m:[33m85[0m - [31merror[0m[30m TS1005: [0m'}' expected.
[7m5[0m player.getComponent("equippable").container.setItem(Mainhand, itemStack)
[7m [0m [31m [0m
[36m<REPL0>.js[0m:[33m3[0m:[33m28[0m
[7m3[0m system.run(() => {
[7m [0m [36m ~[0m
The parser expected to find a '}' to match the '{' token here.
ESLint results:
<REPL0>.js
5:84 error Parsing error: '}' expected
That command is only for connecting the code connect app to your world.
How do i run a function on all entities from within a system.runInterval?
I made a script, on mobile it is working correctly, but on Windows it is not working as it should, does it make sense that this is happening?
World -> get entities -> runcommand
So using world.getEntity("minecraft:creeper") would allow me to run a function on all creepers?
I used playerinteractwithentity, it saves the mob and after using the item it loads it, on the cell phone it is correct, but on Windows it multiplies the mob
Documentation for @minecraft/server
like if you had saved the mob twice or loaded it twice, why does this happen?
you may need to share the script and what is happening in both devices
this script
what is supposed to happen?
he should save the mob and then remove it from the world, after using the received item on a block he would load the saved mob only once
Now in Windows the whole process is correct, the only problem is when loading the mob, you save a single mob and it loads 2 mobs
in short the mob is being multiplied
world.beforeEvents.itemUseOn.subscribe(async({
itemStack: item, source: player, block, isFirstEvent
}) => {
if (!isFirstEvent) return;
could this fix?
i think so, try it
Okay
Oh, it's a beta feature, that's no use to me, I wanted a totally stable API
Is there no other way?
I wouldn't want to get rid of a script that took a lot of work to produce.
uhm, i'd use custom tags for when the player is placing and after it's placed
world.beforeEvents.itemUseOn.subscribe(async ({
itemStack: item, source: player, block
}) => {
const lore = item.getLore()
if (item.typeId === "mc:genie_lamp_captured" && lore[0]) {
if (player[item.typeId]) return
else player[item.typeId] = true
await null;
system.runTimeout(()=> delete player[item.typeId], 10)
player.onScreenDisplay.setActionBar({ translate: "function.lampe" })
// Usando as coordenadas do bloco no qual o item foi usado
world.structureManager.place(`${Number(lore[0].split("§fID: ")[1])}_mob_capture_device`, player.dimension, block)
player.getComponent("equippable").setEquipment("Mainhand", new ItemStack("mc:genie_lamp"))
}
})
dynamic properties are so much better than scoreboards for something like machines
for me i will use dynamic properties for all of my machines in my addon, i can use scoreboards but dynamic property is much easier and better
As long as you don't need to detect those dynamic properties values outside the scripts, yeah, it's better
anyone know if custom fishing would be possible?
I would like to NOT use entity.json's and purely script api
so like test when they catch a fish and do something
just remake the entire fishing system
have a custom fishing rod item, a hook entity, use scripts to determine where it goes when your fishing rod is used.
and have another system that randomly creates bubbles that move towards your rod entity. if in a distance of 1, make it so you can interact again and get a fish
import { world, system } from "@minecraft/server"
this is correct right ?
because bridge is acting weird :<
hey guys! im thinking of switching to VSCode, what extension would u recommend for scripting?
I would recommend using the Minecraft color extension it’s very useful
oki, thank u =)
and for coding itself?
Install the npm packages then it should provide types.
okey, thank u
how to get where the block is facing?
why two imports? just import { world, system } from ',,,'
yea i fixed it :)
thanks tho
made this
clans, chat ranks, changeable names
ah, servers things
i don't want to make something like that bec i have no friends to play with anyway

Is there a way to spawn XP orbs with specific values?
Like in java there's "value" but in bedrock idk
How to change player holding item name or lore?
How can I spawn a cat with a specific variant?
yes, you just need to trigger the event that adds the component group with the variant.
entity.triggerEvent('event_name')
the spawnEntity method returns entity, so you can just do
spawnEntity('minecraft:cat', player.location).triggerEvent('event_name')
Do you know how the event is called?
There are only events for random variants
oh
well the variant value cannot be change in scripts
I guess its not possible then
sorry
unless you want to change the cat.json to work how you want it to
that is impractical
I'm struggling to make a type of display block like an item frame. I'm trying to make a sort of pedestal that will display the item used on it but can't seem to wrap my head around about doing in
I have issue with native method of spawning items on ground.
case "apple":
source.dimension.spawnItem("minecraft:golden_apple", endPosition);
break;
Every time it shows me error that expected itemStack, native conversion failed. But whenever I'm changing this item to itemStack it is showing error in full script
It needs to be an ItemStack not a string
So:
new ItemStack('minecraft:golden_apple');
const apple = new ItemStack("minecraft:golden_apple", 1);
source.dimension.spawnItem(apple, endPosition);
Nevermind, it's late, It's working now
😄
Thank you!
import { world, system } from "@minecraft/server"
import { ActionFormData, ModalFormData } from "@minecraft/server-ui"
world.beforeEvents.itemUse.subscribe(data => {
let player = data.source
let title = "§l§o§uWelcome"
if (data.itemStack.typeId == "minecraft:compass") system.run(() => main(player))
if (data.itemStack.typeId == "minecraft:clock") system.run(() => main_armor(player))
if (data.itemStack.typeId == "minecraft:diamond") system.run(() => main_backpack(player))
if (data.itemStack.typeId == "minecraft:emerald") system.run(() => main_radio(player))
After i added more system.runs, stuff starts not working
can someone help me why the ui wont open anymore?
with just the compass it works
but after i added more it stopped working
you should use braces
nvm, changing pack from vscode to bridge
just changed my manifest
and got rid of my modules
nooo
okay
stay vscode
but I recommend using braces for those if statements
just wanted to use some autocorrecting
for my stuff
bc using .json entites and adding events and component_groups sometime i miss a brace or parentheses and screws up the whole thing and vs code plugins dont catch the error
that not the whole script
i just send a part i thought there was an issue
the brackets are far down there somewhere
it works
why not use afterEvents to avoid having to use system.run?
that repetitive feeling remind me of having to put a $ at the start of almost everything in jquery
im just learning
i will see about that
question
player.runCommandAsync("execute as @s at @s at @s if score @s DC17MSniperClassAmmo > @s lucky run give @s swmc:dc_17m_sniper_ammo")
player.runCommandAsync("scoreboard players remove @s DC17MSniperClassAmmo 1")
these two commands when activated they intefer with each other or go in order?
also, i have a few suggestions.
-
if you choose to use if statements and you have multiple near eachother, use braces. it's much better than not using them and they help you find the statements.
-
use a switch statement, it will simplify having to use a bunch of if statements and make things a lot easier
-
make a variable for your item so it won't always have to be
data.itemStack.typeId // kind of long
ok, i will see to optimize my script
commands in scripting 
the only way ik lol
i want to give and item depending if the score is less than 10
ik commands well and i just execute commands lol
try learning native API because it would be better that way in long term
ive sent this message like seconds ago and it just got sent now, this school wifi is horrid
Lost
Jitter
interesting titles lol
const score = world.scoreboard.getObjective("DC17MSniperClassAmmo");
const score2 = world.scoreboard.getObjective("lucky");
const inv = player.getComponent("inventory").container;
if(score.getScore(player) < score2.getScore(player)) {
inv.addItem(new ItemStack("swmc:dc_17m_sniper_ammo", 1))
score.addScore(player, -1)
}
all on the docs
check microsoft official docs and jayly docs
never got around finding them
on jayly docs
i press buttons
but they lead me no where
can be confusing at first though
i just realized you wanted less than 10, mb. you can probably figure it out tho
yea alr fixed it lol
How many scripts can you import into a main.js ?
Since the cat variant is random you can spawn one and check the variant through scripts. If it isn't the right one remove it and try again.
Sucks that we have to do it this way, but it's pretty fast. 99% chance that it won't take more than 50 tries to get the right variant.
As many as you want
wrap the entire if stayement block in a system.run instead of using so many seperate ones
easier to read
why entity.target is still beta? 😔
to then change its name to targetEntity
it doesn't work anyway
Is there a way to control the time between events , onRandomTIck in block events
I need this now
i can't share that one
i can walk you through the process of making one if you want
use onTIck?
guys, how do i use isFirstEvent for playerInteractWithBlock?
i want ti stop the interaction to spam, but i dont understand how to use it
world.beforeEvents.playerInteractWithBlock.subscribe(data => {
const item = data.itemStack
const block = data.block
const player = data.player
const isFirstEvent = data.isFirstEvent
isFirstEvent == true
if (block?.typeId === 'minecraft:flower_pot' && item?.typeId === 'pd:mini_cactus') {
system.run(() => {
isFirstEvent == true
block.setType('pd:potted_mini_cactus')
if (player.getGameMode() !== 'creative') {
player.runCommand(`clear @s pd:mini_cactus 0 1`)
}
})
}
})```
this is what i have, but im sure im using it wrong
It needs to be part of your if condition. Having isFirstEvent == true on its own line will perform a comparison (returning either true or false), but nothing is done with the result.
ohh, in if
okey, thank u so much!!
i have just discovered a shortcut to open the content log history
json ui?
no, straight up keybind for it
Ctrl + H?
oh that's useful i didn't knew that keybind exist
It's common knowledge lol
"discovered " lol
I even made a texture pack that places the history button on top of the settings screen because it's that important to me
and now I won't need it anymore XD
Ctrl+H right?
someone should make a hud button for mobile users
true
but how exactly, is there a place i can specify tick interval
the block json
"minecraft:tick": {
"interval_range": [4,4],
"looping": true
}
what other shortcuts i don't know about?
Is there a way to get the permutations of a block
block.permutation
Is binary teleporting a script thing?
Hey, I am in a rush to release my server in a hour.. How do I see if a item has a cooldown like if it currently has a cooldown as I want to only let it run if it doesn't have a cooldown through minecraft
const hasCooldown = player.getItemCooldown("example:category") > 0
ty but what is example catgoery?
do I put my item name in there?
which item do you want to check for?
does it have the cooldown component? the category should be defined there
console.warn(entity)
let player = data.player
let entity = data.target
if (entity.typeId == "myth:trade_market_guy") {
Market.MarketMenu(player)
}
})``` does anyone know why this isnt working?
world.afterEvents.playerInteractWithEntity.subscribe(data => {
const { player, target } = data;
if (target?.typeId === "myth:trade_market_guy") {
Market.MarketMenu(player)
}
})
might not make a difference, and if it doesnt its probably your MarketMenu function
doesnt work
for some reason it worked perfectly fine with itemUse
entity is not defined, use data.target
you did it after you called entity
console.warn(entity)
that was just for testing, i didnt have that before and it still didnt work
the rest looks good to me, then the problem might be in that Market class thing
i tried putting the console.warn after
still didnt work
no matter what entity i click on, it doesnt work (the console.warn)
you are logging the entity itself, maybe log the typeId of the entity
what does your code look like now?
let player = data.player
let entity = data.target
console.warn(`entity`)
if (entity.typeId == "myth:trade_market_guy") {
Market.MarketMenu(player)
}
})```
do ${entity}
is beta Api active and you are using a the correct script version in the manifest
yes
the console.warn is just for testing
oh
console.warn(`entity`) let player = data.player let entity = data.target console.warn(`entity`) none of these warns work lol
im not getting any errors in the log either
what if you got the typeId wrong
no, i mean outside the world.afterEvents
hmmm
if it works fine with itemUse, then your function isnt the problem
it might the actual event
not even console.warn works
have you tried beforeEvents
but you said it worked outside the event?
yeah
inside the event it doesnt work
that means the event didn't work for some reason
wrap in system.run
interesting, so the beforeEvents detects the interaction but the afterEvents doesn't?
the function
it works now
thats weird
why wouldnt the afterEvent work?
broken ig
maybe it just detects successful interactions, while before events don't even know if the interaction was successful
Does anyone here have a teaching video to learn Script? basic level
can someone help me with my question
onTick(event) {
const {
block,
dimension
} = event
const above = block.above(1);
const below = block.below(1);
const north = block.north(1);
const south = block.south(1);
const east = block.east(1);
const west = block.west(1);
const blockN = north.permutation.getAllStates()
if (blockN == {
"growth": 0
}) {
north.setPermutation(BlockPermutation.resolve("minecraft:air"));
}
}
nothing happens, no errors, no nothing
im trying to set the permutation of a block if its state is a certain number
let blockFromViewDirection = player.getBlockFromViewDirection({ maxDistance: 30 }) anyone know if its possible to check how far the block the player is looking at is?
north.setPermutation(BlockPermutation.resolve("minecraft:wheat", growth:7));
how do i set the permutation
you need to do some vector math
how do i vector
get the location of the block, then calculate it with player's coordinates
blockN?.growth == 0
{ growth: 7 }
Could you make a small template to use? Or smth like that
there's no method to get it yet.
dang I had high hopes
is there any way though or workaround?
What is this vector differences and how do i use it to get multiple blocks within a radius
get the blocks in an area and filter out blocks that there distance is larger than the radius (using the differences between there location and the original location)
step 1: you take desired location.
step 2: you create a loop for the x axis y axis and z axis.
step 3: get the blocks on those location by iterating on each of the axis.
step 4: setPermutation on each of those blocks or you could use setType.
there might be better method but that's how I do it
How would i get a left and right offset based on the player's camera in scripts? been trying to figure it out for a bit but my brain is mush
like how /particle minecraft:basic_flame_particle ^-1^^ is right and /particle minecraft:basic_flame_particle ^1^^ is left
now i'm trying to figure how how to turn rotation values into a vector3
you'll needa calculate the forward and right direction vectors from the camera's view rotation
right will be the camera rotation + 90 degrees
or -
depends which way it rotates
then you just use trig functions to calculate the x and y components of the direction vector
number difference is (a - b) thats the difference and if you use the ABS value of it you get the length
its same for vectors
(aV - bV)
the result is difference verctor
the vector difference in meaning of gettings blocks in radius is just cutting the block offset so you have to do the
(blockToTestVector - entryPointVector).length < radius
can anyone help me with a script in which if i place a sponge, it clears all lava in a 5 block radius ???
if you can please ping me
can we get the location of the nearest custom structure with script api?
no custom structure cant be found like tha unless you include something on the structure
yeah, but i want to locate the structure even if unloaded
that isnt possible unless you generate structures with script api
ok, thank you
How to detect when an entity is inside a block, something similar to this, but with script
"test": "in_block",
"value": "tall_grass",
"subject": "self",
"operator": "=="
}```
how do i use setHudVisibility?
world.afterEvents.playerInteractWithEntity.subscribe(({ player, target }) => {
if (target.hasTag("SpawnCow")){
player.runCommand("/tp @s 1118 116.5 805")
}
})```
I Need help this doesnt work on 1.21.30 for me
#1067869022273667152
oh wait
haven't read the question
Dimension class has a getBlock method, use the player location in that method
are you using beta apis?
yes
any log?
no
its for my lobby
trying to make it so if u right click a npc it will run a custom command we made
which will redirect the player
yes
Does anyone know how to turn script ui text field into a const?
So i can use like in teleporting coordinates?
show me the manifest
your using modalformdata right?
"format_version": 2,
"metadata": {
"authors": [
"HiveLanky"
]
},
"header": {
"name": "§l§uB+ S5.2",
"description": "",
"min_engine_version": [
1,
20,
80
],
"uuid": "40f7605b-e51c-4dd5-a89c-64cd929c9e69",
"version": [
1,
0,
0
]
},
"modules": [
{
"type": "data",
"uuid": "0f3d8e5f-a6b2-4e36-bfce-92f51f021bdb",
"version": [
1,
0,
0
]
},
{
"type": "script",
"language": "javascript",
"uuid": "127111b6-49cb-440c-8e0c-0da777c8444c",
"entry": "scripts/main.js",
"version": [
1,
0,
0
]
}
],
"dependencies": [
{
"uuid": "a48d4554-bdf3-4393-87d9-73edb910996b",
"version": [
1,
0,
0
]
},
{
"module_name": "@minecraft/server",
"version": "1.15.0-beta"
},
{
"module_name": "@minecraft/server-gametest",
"version": "1.0.0-beta"
},
{
"module_name": "@minecraft/server-ui",
"version": "1.4.0-beta"
}
]
}```
ah, know i remember, interact after event only works if the entity has interact component
change afterEvent to beforeEvent
that should work
world.beforeEvents.playerInteractWithEntity.subscribe(({ player, target }) => {
if (target.hasTag("SpawnCow")){
player.runCommand("/tp @s 1118 116.5 805")
}
})
like that?
yes, just remember that before events can't modify the world, so your runCommand, put it inside of a system.run()
wat?
also you should use teleport method of entity
let me make an ex
im going to change it so instead of /tp it will be /transferserver
are you able to just quickly write something out
world.beforeEvents.playerInteractWithEntity.subscribe(({ player, target }) => {
if (target.hasTag("SpawnCow")){
system.run(() => {
player.runCommand("/tp @s 1118 116.5 805")
});
}
})
like that
ty
@distant tulip
i made something wanna see ??
there's a way to give a player an item with different enchants in it?
for example a sword already enchanted with sharpness and unbreaking
thanks
yes
itemStack is a constructor
just add the enchantments
and then set the item
Where is an error here?
it not showing errors but not working when I shoot bow and arrow hitting entity
world.afterEvents.projectileHitEntity.subscribe(event => {
const { source, projectile } = event;
if (projectile.typeId === 'minecraft:arrow') {
if (source?.typeId === 'minecraft:player') {
const hitEvent = event.getEntityHit()?.entity;
source.playSound("random.orb")
hitEvent.playSound(“random.orb”)
}
}
});```
Your hitEvent.playSound(“random.orb”) uses non-standard quotation marks. Look closer at this line
can anyone help me, how do you get enchantments from an item
itemStack.getComponent('enchantable').getEnchantments()
thank you
np
does the itemStack has to be replace with the item
sure
Obviously
see showcase channel 🙂
Then why it does not playsound to the player too?
I'm guessing that the module (or script) is failing to validate entirely. Does the rest of your scripting work fine?
Generally syntax errors will prevent a script from validating. That is different from a run-time error
The script works fine and there is no syntax and run time errors
Does fixing the quotation marks also fix the projectile issue?
yo how can I detect if someone doesnt have a tag, ik about hasTag(), do I need to put a "!" in it or is there another way
!item.hasTag("tag")
the item JSON file contains a minecraft:tags component which is a list of tags that the item has
oh
tbh you helped me with something else at the same time lol
was searching for that too
can someone help me create a script?
what is the best method to do an event with items and also use the cooldown and durability system with the item?
- CustomComponent
- beforeEvent.itemUse
Custom component
Because before I used events with json and now I'm completely lost...
Already seen nothing understood or I'm doing it wrong
}
function main_radio() {
const form = new ActionFormData()
.title("radio")
.body("textures/ui/gui_blue")
.button(`Plugin Cordinates\n§8[ Click to View ]`)
.button(`Radio Options\n§8[ Click to View ]`)
.button("§cExit Menu")
form.show(player).then(r => {
if (r.selection == 0) cord(player)
})
}
function airStrike(player, location) {
const oldLoc = player.location
player.teleport(location)
player.dimension.spawnEntity('minecraft:warden', location)
player.teleport(oldLoc)
}
function cord(player) {
new ModalFormData()
.title("airStrike")
.textField("X coordinate:", "", "0")
.textField("Y coordinate:", "", "0")
.textField("Z coordinate:", "", "0")
.submitButton("SEND AIR STRIKE")
.show(player).then(({ formValues: r }) => {
if (r.every(value => Number.isInteger(value)))
airStrike(player, { x: r[0], y: r[1], z: r[2] });
else player.sendMessage("Value not accepted")
})
}
Could someone help me find the error, i hope fresh eyes can find it?
Debug result for [code](#1067535608660107284 message)
Compiler found 3 errors:
[36m<REPL0>.js[0m:[33m1[0m:[33m1[0m - [31merror[0m[30m TS1128: [0mDeclaration or statement expected.
[7m1[0m }
[7m [0m [31m~[0m
``````ansi
[36m<REPL0>.js[0m:[33m9[0m:[33m23[0m - [31merror[0m[30m TS2552: [0mCannot find name 'player'. Did you mean 'Player'?
[7m9[0m form.show(player).then(r => {
[7m [0m [31m ~~~~~~[0m
[36m@minecraft/server.d.ts[0m:[33m4559[0m:[33m15[0m
[7m4559[0m class Player extends Entity {
[7m [0m [36m ~~~~~~[0m
'Player' is declared here.
``````ansi
[36m<REPL0>.js[0m:[33m10[0m:[33m44[0m - [31merror[0m[30m TS2552: [0mCannot find name 'player'. Did you mean 'Player'?
[7m10[0m if (r.selection == 0) cord(player)
[7m [0m [31m ~~~~~~[0m
[36m@minecraft/server.d.ts[0m:[33m4559[0m:[33m15[0m
[7m4559[0m class Player extends Entity {
[7m [0m [36m ~~~~~~[0m
'Player' is declared here.
ESLint results:
<REPL0>.js
1:0 error Parsing error: Declaration or statement expected
how do i check if an player is getting kicked?
Well that doesnt help bc this is only a piece of a way bigger code just a problem area i posted
does anyone have a script that immitates the clearvelocity function but for players?
Can't you just teleport the player to their own position
not sufficient since it messes with player head rotation
and teleport itself doesnt clear velocity very well
Hi how i do to implement minecraft:cooldown & minecraft:durability with custom component ?
is it possible to draw a line with particles from one pair of coordinates to another?
why does itemStack.hasComponent("minecart:food") always return false?
even if the item is food
what am i doing wrong?
i am using it in a itemCompleteUse after event
oh no... it says this component only applies to data driven items.
is there another way to tell if an item is a food item or not?
What is the max chars or bytes for a dP?
function loadingForm(player: Player) {
const run = system.runTimeout(() => {
uiManager.closeAllForms(player);
system.clearRun(check);
console.warn("finished");
}, 20 * 5);
const check = system.runInterval(() => {
console.warn(run);
}, 20 * 0.5);
new ActionFormData()
.title("panel1")
.button(`a`)
.show(player).then((result) => {
if (result.canceled) system.clearRun(run);
});
}``` is "run" supposed to keep increasing by 2? Or is that not supposed to happen..
32767
bytes?
yes
i will use an array of food ids for now.
yes
there is a way
test if the item has the "minecraft:food" component
like this js if (player.getComponent("equippable").getEquipment(EquipmentSlot.Mainhand).hasComponent("minecraft:food")) return console.warn("this is food!!");
u can split it up but i wasnt bothered
i think thats right
use a for loop, like make a global xyz location which would be your starting point. then use the x or z as the thing that is < or > to the amount of numbers (coords) you want to add to it.
then make sure the spawnParticle method is in that loop, and have it spawn whatever particle
yes. internally each function is put into an array (I assume) and the number that system.runTimeout etc returns is the index into the array of that function, so when you clearRun, it deletes that index. In your code snippet, you use two runs, so the next time it runs, it'll be increased by 2 since you've added two
it that makes sense
Yeah
I was just wondering if it was supposed to reset after I clear a run..
Like it always goes up by 2
well 1 now
So itll start at 0 and if I run that function 10 times it'll be 10
And to reset it I have to reload
So are those runs still running in the background?
The run IDs don't get re-used, the ID is just a counter
Ohhh alright
if (blockGottenId.includes(cropList)) {
blockGotten.setPermutation(BlockPermutation.resolve("minecraft:torchflower_crop", {
"growth": 7
}))
for some reason the .includes part aint working do you know why
if cropList.includes(blockGottenId)
so i was doing it the wrong way around
yeah
you're supposed to check if the array includes the value
welp just load it in
not value includes array
is there no listeners for bundles?
when item is inserted or when item is removed?
Like inventory?
[Scripting][error]-TypeError: not a function at onTick (custom_components/crop_growth.js:
why this error
if (cropList.includes(blockGottenId)) {
switch (blockGottenId) {
case 'minecraft:wheat':
blockGottenId.setPermutation(BlockPermutation.resolve("minecraft:wheat", {"growth": 7}))
break;
default:
// code
}
show entire file
too big for discord

[Scripting][error]-TypeError: not a function at onTick (custom_components/crop_growth.js:54)
this is the error
i think i accidentaly deleted something
where is onTick
the error comes from the blockGottenId.setPermutation...
idk i can't see everything
sorry for the bother, i think i was using typeId instead of block
[👀 ]
waos
that's one way to break a potato
In block permutations, whats the difference between resolve and withState
const barrelStates = {
open_bit: false,
facing_direction: 4
}//barrel.permutation.getAllStates()
barrelStates.open_bit = true
barrelStates.facing_direction = 0
block.setPermutation(BlockPermutation.resolve('barrel', barrelStates))
block.setPermutation(block.permutation.withState('open_bit', true))
resolve allows u to make default/edited states,
withState just have one state to edit
{
"hud_title_text": {
"type": "image",
"size": [ "100%c + 10px", "100%c + 8px"],
"alpha": 0.8,
"anchor_from": "top_right",
"anchor_to": "top_right",
"offset": [ 0, 0 ],
"texture": "textures/ui/Gray",
"layer": 30,
"controls": [
{
"title": {
"type": "label",
"text": "#text",
"layer": 31,
"localize": false,
"font_size": "small",
"font_scale_factor": 1.6,
"bindings": [
{
"binding_name": "#hud_title_text_string",
"binding_name_override": "#text",
"binding_type": "global"
}
]
}
}
]
}
}```
Why do I get this error? There is no orientation property lol.
#1067869374410657962
How do I make it so that players with certain tags cannot be hit or hit other players and entities?
iirc, there's no proper script-api way
player.json damage_sensor is one of the options
how does setSpeedAndDirection work? i know if it's syntax, what i mean is what do i need to add in the custom particle file? (im using snowstorm btw)
export function openSellPad(player) {
let sellPadForm = new ModalFormData()
.title("Sell an Item")
.dropdown("Select an item to sell", [
"Apple",
"Carrot",
"Potato",
"Golden Carrot",
"Golden Apple",
"Diamond",
"Gold Ingot",
"Iron Ingot",
"Cobblestone",
"Stone",
"Oak Log",
"Spruce Log",
"Birch Log",
"Jungle Log",
])
.slider("Select a Quantity",1,64,1,1);
sellPadForm.show(player).then((response) => {
let selectedItem = ["Apple","Carrot","Potato","Golden Carrot","Golden Apple","Diamond","Gold Ingot","Iron Ingot","Cobblestone","Stone","Oak Log","Spruce Log","Birch Log","Jungle Log"][response.formValues[0]];
let selectedQuantity = response.formValues[1];
let sellPrice = 0;
switch (selectedItem) {
case "Apple":
sellPrice = 5;
break;
case "Carrot":
sellPrice = 3;
break;
case "Potato":
sellPrice = 2;
break;
case "Golden Carrot":
sellPrice = 15;
break;
case "Golden Apple":
sellPrice = 20;
break;
case "Diamond":
sellPrice = 100;
break;
case "Gold Ingot":
sellPrice = 50;
break;
case "Iron Ingot":
sellPrice = 10;
break;
case "Cobblestone":
sellPrice = 1;
break;
case "Stone":
sellPrice = 2;
break;
case "Oak Log":
sellPrice = 5;
break;
case "Spruce Log":
sellPrice = 5;
break;
case "Birch Log":
sellPrice = 5;
break;
case "Jungle Log":
sellPrice = 5;
break;
}
let count = 0;
for (let i = 0; i < player.getComponent("minecraft:inventory").container.size; i++) {
let item = player.getComponent("minecraft:inventory").container.getItem(i);
if (item && item.name == selectedItem) {
count += item.amount;
}
}
if (count >= selectedQuantity) {
player.runCommand(`clear @s "${selectedItem.replace(' ', '_')}" ${selectedQuantity}`);
let totalSellPrice = sellPrice * selectedQuantity;
// Add money to player's scoreboard
player.runCommand(`scoreboard players add @s Money ${totalSellPrice}`);
player.sendMessage(`§aYou have sold ${selectedQuantity} ${selectedItem}(s) for §e${totalSellPrice} coins!`);
} else {
player.sendMessage(`§cYou don't have enough ${selectedItem}(s) to sell!`);
}
});
}
I know its done wrong need help selling the item/getting rid of it and testing for item
// item_and_price.js
export default {
"minecraft:apple": 5,
"minecraft:carrot": 3,
// rest of the items and their price
}
in the file where your switch-case is
import items from "./item_and_price.js"
// your codes here
// remove switch case and put this
for(let [item, price] of Object.entries(items)) {
if(selectedItem == item) {
sellPrice = price;
}
}
@pseudo timber
this will fix the mess of switch case
i fixed it thanks
check if it works
wow, you are so smart!
I can't believe i didn't think of that, tried it, got confused about why doesn't it work, came here, and found out why
nope, minecraft foods dont have food component
This really does not need to iterate properties over the object.
import items from "./item_and_price";
sellPrice = items[selectedItem];
what does itemUseOn event do?
if we could just read bundle inventory. Sigh
Detecting events similar to growing grass with bone meal
Hi ther
What does "?" in function does? Is it actually needed
Script is not mine, one guy copied it from examples from somewhere
It checks the previous parameter. (if it is undefined and you write a dot, it will give an error, but if with "?" then there will be no error)
Thx
|| Крутое сообщение о смерти кстати) ||
||Мб и крутое, но я как уже сказал, не мой скрипт, я за другого чувака спросил. Может он щас и зайдет
Я не заметил пока ты не сказал)))||
it is kinda pointless there btw
No, the investor component may not have a container property
привет?)
inv component always have container
||Ну ты хоть переводчиком пользуйся))||
а ты че
Iam risky
hmm
so like villager inventory?
The rules don’t seem to say that you can’t communicate in your native language, but I would do it more carefully
this is English only server @quartz token @stone bridge
Лучше переведи, а то можешь и бан ненароком словить. Сервер чисто англоязычный
Ikr
import { world, Player, EntityInventoryComponent, EquipmentSlot } from "@minecraft/server";
world.afterEvents.entityHitEntity.subscribe((event) => {
const attacker = event.damagingEntity;
const target = event.hitEntity;
world.sendMessage('dasd')
if (attacker instanceof Player) {
const inventoryComponent = attacker.getComponent("minecraft:inventory") as EntityInventoryComponent;
const itemInHand = inventoryComponent.container?.getItem(attacker.selectedSlotIndex);
if(String(itemInHand?.typeId) == "minecraft:stick"){
attacker.sendMessage((target.typeId+ " был(а) вьебан(а) "+ attacker.name))
target.applyKnockback(0,0,0,5)
}
}});
I don’t know, but as we see, the documentation indicates that there may not be a container
remove "as EntityInventoryComponent;"
yeah
i should try it on the villagers
never seen container output undefined
||Я уже это говорил))||
@stone bridge
Same
Perhaps "inventoryComponent" has the value undefined.ts(18048)
ts?
yes
maybe add ? after get component
everything worked on the newest version, but there was an error on 1.20.50
import { world, Player, EntityInventoryComponent, EquipmentSlot } from "@minecraft/server";
world.afterEvents.entityHitEntity.subscribe((event) => {
const attacker = event.damagingEntity;
const target = event.hitEntity;
world.sendMessage('dasd')
if (attacker instanceof Player) {
const item = attaker.getComponent("minecraft:equippable").getEquipment("Mainhand")
if(String(item?.typeId) == "minecraft:stick"){
attacker.sendMessage((target.typeId+ " был(а) вьебан(а) "+ attacker.name))
target.applyKnockback(0,0,0,5)
}
}});
basically its a short if condition
container?.getItem()
is basically just
if (container) container.getItem()
and the : after is just an else
Got it
Didnt knew it can be added in the middle
that is a player
container should be defined
that error is just from ts or idk
Perhaps the object is undefined.ts(2532)
world.afterEvents.entityHitEntity.subscribe(({ damagingEntity: dEntity, hitEntity: entity }) => {
same thing
I was wrong, change equipable to equippable
the error has not disappeared anywhere
if you're talking about the one in the code editor, then change the editor
well, or put "?" before the points
The "getEquipment" property does not exist in the "EntityComponent" type.ts(2339)
where is it written
don’t pay attention to this, either change the editor or try switching to js (it’s faster by the way)
i fix it
item = item.getEquipment("Mainhand")
|| and why use TS after that?.. ||
I've been doing this for 1 day and just started studying the whole thing)
error
what a mistake
I've been doing this for 1 day and just started studying the whole thing)
Throw out this editor or switch to JS
this is vs code))))
Never mind, he's talking nonsense
how do i fix after events on use on not working?
world.afterEvents.itemUseOn.subscribe(({ source, itemStack, block }) => {
console.warn("click")
})
doesnt work, i also have the custom component of the block to make the item can right clicked
okay, I understood correctly, to change it, it's enough just to change ts to js
how to fix it?
what have you tried? and what waasnt working?
i tried right cliking and it doesnt show anything
i fixed it with before events somehow
with an item in hand?
i alredy fix
itemUseOn should get called when you have an item in hand, when you have nothing it should get
okay
@wheat condor but if you want to check if he interacts with the block use this:
world.beforeEvents.playerInteractWithBlock.subscribe((evd) => {
});
no i alredy fixed it im doing a custom campfire with fire duration and a fire plugh to start
okay
also an option
why does auto completions not work for components for me
maybe it isnt installed
using bridge
hmm with bridge i can't help you, ive never used it before
@warm mason
Check if the scripts folder exists: Ensure that the scripts folder exists and contains TypeScript (.ts) files. If it's located elsewhere, modify the path in the include section.
i also use vs code but bridge is more easy to create json things
ohh its a writing engine
I want to change ts to js
if (dmg < durability) {
dmg += 1
} else {
itemStack = null
}
//set itemstack in inv
thats the right syntax?
there is really no point in using ts without knowing what is used for
for items durabilitty?
wich syntax?
for damage and max durability
....
huh
why does everything work in the single world and when I upload it to the server it doesn't work(?
Are you using beta api?
yes
Are you sure they are enabled in the world on the server?
yes
What error will you get?
there are no errors (or I don't see them)
How did you realize that something wasn’t working?
well, in my solitary world, when I beat someone, an event was triggered, but not here
I found the valid_known_packs file.json now try to come up with something
By the way, yes. Your packs should be in json files in the world folder
it didn't help(
He's not even here.
behaviors are server side
hmm?
you said it is not working on a server
yes
so.. what is the point of both screenshots?
unless there is an addon on the server, it will not be shown in the current sets?
you need to upload it
and it will not show in your client
as i said bp are server side stuff
https://discord.com/channels/523663022053392405/1296926644971507752 if someone can help me using minecraft:cooldown and minecraft:durability with custom component
How does system.runJob() know when to proceed in the next tick? Does it limit iterations based on device specifications (such as chunk limits) or does it notice that execution becomes slow?
Ive found this: The system.runJob() function is designed to execute tasks over multiple ticks in a way that prevents blocking the main game loop. However, it does not inherently monitor device specifications, such as chunk limits or system performance, to adjust how it proceeds with execution.
How can i create a button that create another botton but only for you, and nobody sees them
Like for a warp menu
getBlocks is in stable in some preview?
can i use minecraft/server-net on a realm?
I think not, because to do this you need to add this module to the list of allowed modules on the host, but in realm there is hardly such a function
const volume1 = {x:location.x - 1, y:location.y, z:location.z - 1};
const volume2 = {x:location.x + 1, y:location.y, z:location.z + 1};
const combinedVolume = new BlockVolume(volume1, volume2);
const blocks = block.dimension.getBlocks(combinedVolume, {includeTypes: ['runecraft:white_rose']}, false);``` does anyone see something wrong with this?
the block in questions is surrounded by the block
oh wait
I forgot getBlocks was totally useless
Is it possible to do setblock from an array so it's like a randomized setblock
how do I access an entities time of fire duration? like how long it's still on fire for
holy crap I can be message 100k
boom
https://discord.com/channels/523663022053392405/1295732842491547658
use my library, easy for using
if a player or entity dies, does isValid() set to false? or only when they despawn/leave?
Where should I ask about feature and feature rules
#1067869232395735130
Thanks bro
Hello
Which is better to store data, scoreboard or dynamic properties?
dynamic properties all the way
Is it faster or is there any reason?
- faster
- more efficient and more compatibilty
- not accessible by the player
- easier to control
- doesnt conflict with other addons
Good reason, thanks mate!
probably not faster but it is the safer and intended way of storing stuff
it is faster
dynamic properties are way more faster
Scoreboards are no competition
only upside for scoreboads are shareablity between packs and way to split data based on objectives
oh alr
i was searching for a benchmark you posted and couldn't find it
i remembered someone saying scoreboard are faster
i think scoreboard runs only on next available tick so it can have like 0.05 ms of latency
I am pretty sure they never were
afaik
i may be wrong then (in saying i heard it somewhere)
its all right, i just got confused
how to lock mob's direction in 8 ticks
anyone help me with this
ik i need to remove or add but everytime i try it messes up
check line 171
Yeah I'm trying to fix but everytime I remove etc it breaks
remove these
I did the other code breaks then and sends the error split
did you still got the error?
yes
well do exactly what Minato said and it ill work:
i removed them for you instead
its in the file lol but idk where wont say
where do you use it?
if you have it mutliple times in there you can try it by dong this:
:/
// the split method
console.warn('SPLIT-01 WORKS') // will not get called when error in the upper split method occours
so you can identify the location of it
How to make mob attack his family mob? Like skeleton attack skeleton or skeleton attack zombie
Without making them shooting themself
is therr any way to get player XUID via this API?
currently using IPC and looking for something more efficient
every module allowed btw
(item.typeId.split(":") ?? [ "", "" ])[1]
Nope
But maybe in 1.20.50 🧐
Not too certain if you'll be able to read packet data or not
oh k
IF you are it will only be accessable via server-net
So like a BDS server
yeah, already messed some things with last preview before
i js need xuid to have unchangable primary key for my external db
yeah
So you're able to grab XUID with the new packet system?
nope, beacuse I can't read content of packet
join packet is probably sending XUID of a player
Supposedly people were saying you can only read the packet size, send, and cancel them
yeah
docs told me the same
so just need to wait for new methods
or there might be a small chance that PlayerJoinAfterEvent.playerId might be it
but it's a string, so it's probably an entity id
it is player id
hm
entity?.extinguishFire should detect if the entity is on fire?
apparently i can use entity.getComponent('minecraft:onfire') too
it is used to extinguishFire (put out the fire)
ah,
Someone can help me
im trying to make a small system that will detect if the entity is on fire or not.
for a solar panel system
How can i make a function that make 34 command all the sale but with 34 number
Like
1 - player.runCommand(‘clear 1’)
2 - player.runCommand(‘clear2’)
Like this
But not in 34 line of code
const onFire = entity.getComponent('onfire').entity;?
just entity.getComponent('onfire')
ah, mybad
whats wrong?
everythinmg
it says not enough money
const plotBorderBlock = "minecraft:polished_blackstone";
Should be a boprder block
In that case open a post with your code and content logs
thats my mistake
https://discord.com/channels/523663022053392405/1297687515196559530
Just realized you already made a post
nice
um
getBlocks is in stable in some preview?
no
thx
anyone
so smth completly diff?
Not possible to manipulate mob behavior, but u can trigger entity.json events using script
remove the comma all the way at the end, before the array's closing bracket. it's adding a null value to the end of the array, which is why you're getting the error
I'm here again) how do I make a delay before teleporting?
import { world, system } from '@minecraft/server';
import {
ActionFormData,
MessageFormData,
ModalFormData
} from "@minecraft/server-ui";
world.beforeEvents.playerBreakBlock.subscribe(event => {
const item = event.itemStack; if(item?.typeId == "minecraft:compass" && item.nameTag == "§l§bМеню"){
event.cancel = true;
}
return;
});
world.beforeEvents.itemUse.subscribe(data => {
const player = data.source;
if (data?.itemStack?.typeId == "minecraft:compass" && data?.itemStack?.nameTag == "§l§bМеню") {
system.run(() => form(player));
}
function form() {
const form = new ActionFormData();
form.title('§l§1МЕНЮ');
form.button('§lТп на спавн', 'textures/ui/check');
form.button('§c§lЗакрыть', 'textures/ui/cancel');
form.show(player).then(r => {
switch(r.selection) {
case 0:
tp(-7, -53, 1);
player.runCommandAsync('playsound note.harp @s');
break;
default: return;
}
});
}
function tp(x, y, z) {
player.runCommandAsync('effect @s blindness 2 255');
player.runCommandAsync(`tp @s ${x} ${y} ${z}`);
}
});
in the tp function
system.runTimeout(tp(), ticks);
you need the callback
system.runTimeout(() => {
player.teleport(vector3)
}, Ticks);
okay, it started working, but the error did not disappear(
Show the code
I'm dumb. It's okay.
Dont say that mate 
is there any component I need to add to an item before using the itemUse event?
world.beforeEvents.itemUse.subscribe(data => {
const player = data.source;
});
how do I give the player an item with my own name(compass name=Menu)

is it possible to make a daylight sensor using scripts only?
daylight sensor works when the block is facing the sunlight and if the block above the daylight sensor is blocking the sunlight it will stop working
how can i do that using scripts?
a script where it plays custom audio then loops?
Gets the highest block
uh, is it useful for making a daylight sensor system?
i think you mean 50 ms
no
just get the game time and weather for that
i just want to make the system works only when the block is facing the sun, just like how zombies burns in daylight
but for the block, without adding entities
oh then i guess in that case it could be used
you would use it to see if the top solid block is above that block's position
only if any of the above blocks is solid / cannot block the sunlight like glass
block.dimension.getTopmostBlock(block.location.thing, ??)

then use Dimension.prototype.getBlockFromRay()
ah, there's a getBlockFromRay for the block
yes
i dont have to use entities for that,
yes
is it will throw errors if the detention is detecting blocks outside the high limit?
another problem.... I can't get the name of the compass (I assume because it's lock_in_slot)
no
like if i place the block at y200 and it start detecting blocks that above the y limit it will throw errors?
no because blocks cannot be outside of the height limit
so i can make the ray of it infinity and it shouldn't throw any errors right
lemme try and see.
ik
the only way blocks could be above or below the height limit is with this: https://modbay.org/mods/1561-8crafters-world-height-limit-modifier.html
lol
is this a glitch or an official feature?
official feature
finally mojang is adding customizable dimension
cant wait for dimension creation
so you have to modify chunks beforehand to stop them from dissappearing
this has been a feature since 1.18.30 btw
basically you can create extreme underground stages
I can't get a name tag in the last event
and only lock_in_slot
like I have a compass locked in the 8th slot
if I don't put a locked object there, then everything is ok
world.afterEvents.entityHitBlock.subscribe(data => {
var player = data.damagingEntity;
const item = player.getComponent("minecraft:inventory").container.getItem(8);
player.sendMessage(String(item?.nameTag))
player.sendMessage(String(item?.typeId))
if (String(item?.typeId) == "minecraft:compass") {
item.nameTag = "§l§bМеню"
}
});
yes
it would be crazy to create something like terraria dimensions
uh,
getBlockFromRay(block.location, { y }, { maxDistance: 999 })?
that should detect blocks from above?
if you change the nametag of the item stack that won't modify the original item
idk about Victor3 thing
you also need to replace the old compass with the new one created by your script
player.getComponent('inventory').container.setItem(player.selectedSlotIndex, itemStack)
@quartz token
no remove max distance
for the direction do {x: 0, y: -1, z: 0}
noticed
wait nvm y should be 1
done, it should detect blocks above it?
yes
up until height limit
i get it
there can't be any above the height limits
adding maxDistance is for making the system has a limited distance not infinity
even if you use my pack https://modbay.org/mods/1561-8crafters-world-height-limit-modifier.html it would once increase the actual height limit, so it would still work
now if (!block.isSolid()) console.warn('7') should work just fine?
already
it returns BlockRaycastHit not Block: https://learn.microsoft.com/en-us/minecraft/creator/scriptapi/minecraft/server/blockraycasthit?view=minecraft-bedrock-experimental
const ray = block.dimension.getBlockFromRay(block.location, { x: 0, y: 1, z: 0 }).block
yes
const ray = block.dimension.getBlockFromRay(block.location, { x: 0, y: 1, z: 0 }).block;
if (!ray.isSolid()) console.warn('Hi')```done ig
do you want it to include liquid and passable blocks
does solar panels works underwater?
so yes?
i don't think so but why not, yes i will make it works under the liquid thing
add this as options: ```js
{includeLiquidBlocks: true, includePassableBlocks: true}
understood
what if i didn't add that possible blocks?
then it would ignore them
ah, alright understood
now i have to make it detects the daytime / the weather
sunrise is 23000
sunset is 36000
i have to detect them using a script
welp, t17x-brain was slain by Javascript
how can i detect numbers between 23,000 and 36,000?
const time = world.getTimeOfDay;
if (time <= 23000 && time >= 36000) { ,,, };?
@winged gull this should do it right?
sorry for the ping

I don't understand why, but it only works after the event is triggered 2 times
I think so
it is because you are not setting the name tag until after you display it.
returns log called not a function
my translator translated it very crookedly and I didn't understand anything(
here const time = world.getTimeOfDay; ← not a function log
yoy forgot to call the function
you forgot the ()
add those
uh,
don't do what you did at the end where you set the name tag on the item stack and then replaced the current item with that, instead just do container.getSlot(8).nameTag="§l§bMenu"
not working
what the error now
no errors
no logs
not working for some reason
and most importantly, day 1 is 23000, day 2 is 46000, the day time ticks changes and not resetting
getTimeOfDay(): Returns number - The time of day, in ticks, between 0 and 24000
You might have to modulus the time as it is probably will be way greater than that
nope
caps at 24000
rolls back to 0 each day
getTime does what Im thinking then
yeah lol
so how can i detect the day time?