#Script API General
1 messages ยท Page 20 of 1
Each element in an array can be whatever you want
let and const are my bbs
alr
var was useful when I was coding arduino
for global you can use let in any function
you should try that for sure
yh true but objects is so good for saving data
Both have their use cases
yeah the same goes for switch and if statments
The code is only as powerful as the creator makes it
using array with objects 
As many as you want
how to I use each value?
and each variable have a key
nested
ew
const obj = {
key: "test1"
}
console.log(obj.key)
It has its uses 
Just like anything else
that's actually quite simple
I still can't believe I made this much progress in 2 days lol
yh ur right but some people does not know how to make it look clean
you can't escape it
noce

If the creator writes bad code, that ain't the programs fault
yeah true

python has a easy entry but have you not seen the about of def = functions you need just for a checker
oh ye
Can just do pos1 = getPlayerLocation()
also remove ;
W //
getPlayerLocation return an obj
since when?
kinda tried that
it gives a weird error
object ; object
Error?
since it is added?
it is just a vector3
Do you have that function defined in your code anywhere
but that what shows up
oh so a ({x, y, z})
yeh of course
Console warning an object does that ye
yep
oh cool
use JSON.stringify(obj)
i gotta start adding console logs at the start of a event to check if its working or not
Can do JSON.stringify(objectData) to get it as a string
yo can you explain some more?
silence so loud fr
๐
so there's a mistake?
the = sign
?
let cameraPoint = []
nvm
and push to it
1 day until Full Satisfaction
Satisfactory, a game which has been in early access since 2018, is releasing tomorrow at 8:00 am PST
oh that's smart
Also pls refer to variables as values so ppl don't confuse it with actual var ๐
ok
there's an error apparently
Can someone help me, I need to take the armor from the eslots from a chest and put them on a mob, I tried this but it doesn't work :C
The variable cofre and chest should be chest but I forgot haha, but that is not the error.
what's the error code?
Equippable component only works on players atm
i thought about that which is impressive lol
Is there another way to do it? The armor that he grabs from the chest is a dyed leather armor
There sure ain't
Ok, thanks
Yeah like to get where a block is facing and to set where a block is facing, I will get the direction from an old block and set the new block's direction to it.
chatSend is beta?
Yep
If anyone knows please reply! Thanks!
/reload reloads the manifest too?
Nop
scripts and functions files only
okie
Ay do u know a way brotha?
set it state that control rotation
isn't 1.14.0-beta the latest?
yes
Basically I copy a block by blah blah, structure block, and eventually I'm placing it, I get the old block and the structure block
I wanna set the structure block's direction to the old block (one placed from item)
did you set it in manifest
Also I gtg rn cuz im really tired
ye
odd
It's 1:40am for me so ya
Oh, should be afterEvents not afterEvent
Are you using VSCode?
If so, you may want to...
- add
//@ts-checkat the top of your js files. - make sure to install the latest npm files so it can intellicode correctly
- use jdoc notation above functions do define what the types are
This will keep you out of a lot of typos. There is one more, it is to see the TS annotations. It helps a lot to catch ahead of time..... I am not sure how I did it though...
..and as some on here will say... or just use Typescript.... I don't though... the above keeps me locked in.
i haven't installed npm files yet
does that even work?
Provided your array is valid, I guess. Looks fine to me.
You do know that chatSend is still beta, right
how do i check if the array still has info in it?
ye why?
so, just make sure latest beta or preview beta
yep it's working so far
I saw an earlier post
yep
I just want to know if the array will be nullified
you can use filter
You are nulling entries in the array.... maybe slice them out if unwanted
lemme check
then when .length=0...
Can also just set the array to [] again
what?
but he did not mention [0]
Oh yeh
i started from 1
you did 1 and 2, waht baout 0
Arrays index from zero, BTW
Bro thinks we in Matlab ๐ฅ
don't do that...
realest stuff i heard all day
why tho?
ohhh
0 is love, 0 is life (for more than just array indexing)
Because it is at the core of way many more programming languages... so you are calling all of them losers.. and that is not good
and 1 is 0
The first element is at an index of 0
Does anyone know why it doesn't work? It gives these two errors
[Scripting][error]-TypeError: not a function at <anonymous> (blocks.js:29)
[Scripting][warning]-Script reload did not re-register 'fm:interact' custom block component
world.beforeEvents.worldInitialize.subscribe((eventData) => { eventData.registerCustomComponent("fm:interact", {
onPlayerInteract(event) {
const player = event.player;
const block = event.block;
const inventoryComponent = player.getComponent("inventory");
if (!block || !inventoryComponent) return;
const container = inventoryComponent.container;
const selectedSlot = player.selectedSlot;
if (typeof selectedSlot !== "number" || selectedSlot < 0 || selectedSlot >= container.size) return;
const heldItem = container.getItem(selectedSlot);
if (heldItem?.typeId === "fm:evil_amulet") {
if (block.typeId === "fm:mana_generator") {
world.getDimension("overworld").runCommandAsync(`summon mob:c_eye ~ ~-0.3 ~`);
}
}
}
});
});```
Well you're using it correctly, nothing wrong with what you have
You're just skipping an element altogether
fair
It may give unintentional results in the future, however... but you will run into that when you need to
Isn't it these 2 properties.. https://jaylydev.github.io/scriptapi-docs/preview/classes/_minecraft_server_1_16_0_beta.WorldInitializeBeforeEvent.html
What is registerCustomComponent
pls use the reply feature
it gets confusing
Yep, you wouldn't need the nested cancel in that case
I know.. that is why we tell you guys to make a post when you need help that requires a lot of back and forth
well i don't know if I will even finish this project so ye
Shit gets lost in here...
thought shit was banned
It's lost, so we cannot ban it
lets go
alright
Posts are for anything, from random one line questions to involved projects
And as always, I recommend learning basic js syntax & methods before jumping in, and reading the docs to see available methods
sup
So choose a tag that suits your post the best
is it possible to change entity scale by scripts? i think it is possible
hmm
entity.getComponent('entityScaleComponent')?
Have not seen that, but you can finagle it other ways using events to change a variant/mark_variant/skin_id and having something inside sense the change or a timer checking or animation controller
But can you change it or just get the info?
i can do that using "component_group"
but how can i change the entity group using scripts?
entity events filters, when the entity got a specific tag, it will change the component group of it, and if the entity doesn't have any tag it will remove it from the component group
i know
i think you can just directly fire events
via Entity.triggerEvent()
Would anyone know how I would go about preventing fall damage from specific players?
editing player's damage sensor to prevent fall type damage will do
this is what im trying to do;
interacting with the block will scale up the entity inside it ( changing the components group ), hitting the entity will scale it down ( will turn the entity back to norml
that is way simpler than adding & removing tags
yeah
where is that located? player.json?
player.json
that can be done using/ability command, turning off the fall damage
The block, if custom can fire the events... , the entity inside can do it too if the hit box is as big as the box at least
i dont want to do that, scale it up when interacting with the block is way better than always having the entity
do you have some example code? I have seen the wiki team damage demo but not sure how to change it
like when u try to mine the block
you did say you wanted it to scale an entity... how is it not supposed to be there
u don't have to look at a specific place that is out of the entity hitbox to mine the block
original scale is 0.1, after interacting with the block it will scale it up to 1 so the hitbox will be bigger and can be interactive u know what i mean
damage sensor.... just need to set your filters.. can check for tags, which is most likely what you will use.
or a property
i mean the scale will be bigger than the block itself so u can interact with the entity
tyty
You can set the scale and hit box in same component group
Not saying this is the solution, but I would not rule it out
i dont know that much about entities,
question
play with the vanilla ones.... that is how you can learn alot... those complicated ones. they give you that json code
does firing entity events affect after a tick
at end of I believe... which is why it is called queue command now
if you want next tick, call a timer that calls the event
Those are same tick
I'm having a nightmare with them now as I make my tree spiders
Thing is, sometimes you do not want same tick because change of info cannot be read until next tick... so build in timer delays to call in next tick... if you need that
using Entity.triggerEvent()
You will have to run a conclusive test.....
that is what I do... cause I need to know what is happening when
if you have a scoreboad with the ticks.. you can have the event tell raw a message with the tick score... and compare to...??
and i sent this like 8 minutes ago
was just wondering since i was using component groups w/ events linked to scripts that triggers when the player falls for more than 1.5 blocks
so that i can change attack component value from negative to positive while falling
but sometimes it just doesnt work
could be related with Entity.isFalling being weird though
custom entity?
nope, player
player?
1.5 block fall had to catch with the eyes...
test with having the action bar say when falling... you need debug logging you can turn on and off
while falling...
while falling
to elaborate on this, players have -10000 attack component value when theyre not holding a mace and is not falling
and when the player falls for more than 1.5 blocks, it triggers a component group that removes the old attack component and add the new attack component with value of 1 so that the mace can do damage
if the player did not fall for 1.5 blocks, it uses the combat system i made
but apparently the mace just refuses to do damage sometimes lol
Is it that the mace does not change, or the code did not make it there?
do you relay need scripting for that?
ik but im making it easy to edit
man, only if we had beforeEvents entityHurt or entity attribute component for attack
Real
how are you applying component group
events
events triggered with script?
yep
try triggering component group directly
not sure how to do fall check with that though
is there a way to create a system that executes a command like a command block in repeat?
nvm i thought there is addComponentGroups
it is addedComponentGroups
runInterval
apparently it was the Entity.isFalling
i used player.getVelocity().y < 0 instead and its working fine now lol
or... not?
how do i get all players in the world and run code for each of them
world.getAllPlayers().forEach(player => {
//code
});
or
for (const player of world.getAllPlayers()) {
//code
};
Thanks
forEach
why dont i see this in the jayly docs
its a JavaScripts thing
oh
And there are several ways to do most things, which confused the hell out of the beginners. Especially the shortcut code... like arrow functions vs functions. Gotta know the basics of those things to get by on anyone's examples.
a lot of the shortcuts really confused me in the beginning
yeah, if everyone did things the long way, or the way that resembles English, the beginners would have a much easier time... but the cool way is to lamda it all up into the shortest code possible so that others have to really know their stuff to decipher.... Some programmer's do not realize that this is the part that trips people up...
but then again,... taking the basics class would clear it up
There's simply too many ways to do the same thing. JavaScript somehow supports a functional, object-oriented, and imperative design at the same time
A lot of it (arrow functions) are used somewhat harmfully IMO. People should really be naming their functions
gotcha
๐
If you think about writing it so that the interns have to maintain it.. then you wirte it better and clearer and documented.. so they do not ask you quiestions.. if they can read english
A lot of beginner questions can be answered with "whatever you want" which is a pretty drastic change coming from the strict rules of json lol
Arrow functions exist to circumvent oddities with the this keyword. People treat them like "short functions;" when you go to debug that code, you will see a lot of "at <anonymous>" in the stack trace.
You can benefit from named functions and arrow functions by assigning it to a variable and using that variable like a function
... Or just used name functions
realer statements have never been said
import { world, Player, system } from "@minecraft/server";
let mana = 100;
let maxMana = 100;
let manaRegenerate = 1;
let isDisplayingMana = false;
world.getAllPlayers().forEach(player => {
system?.runInterval(() => {
if (!player) return;
const equippable = player.getComponent("minecraft:equippable");
const equippedItem = equippable?.getEquipmentSlot("Mainhand");
if (equippedItem && equippedItem?.typeId === "wands:wand") {
player?.runCommand(`title @s actionbar Mana: ${mana}/${maxMana}`);
}
}, 25);
});
i tried fixing this error, but nothing seems to work
[Scripting][error]-InvalidContainerSlotError: The container slot is either empty or is no longer loaded. at <anonymous> (main.js:12)```
You want getEquipment not getEquipmentSlot
hmm, what the difference
One returns an ItemStack, one returns an ItemSlot(?)
ItemSlots are like containers for ItemStacks; they have a property pointing to the ItemStack
Do you not have the API reference to see what is returned?
i do, but wasnt paying attention, to those details
Everything is in the details.... and you probably do not read the installation instructions either, LOL
Oh don't look all innocent
The details are where the loopholes are, where the lawyers get you, where you find a new way, how the hackers get in. Programmers, imo, are detailed oriented.. or lousy programmers.
One returns an ItemStack, the other returns a ContainerSlot
As Nikki says, I recommend reading the docs
I read them for fun.. but then again I am special that way...
you did WHAT
look at the classes, see what the properties and methods are, open up the examples and get all kinds of glorious ideas... I intend to be a scripting master...
How can I detect if there is a specific block underneath another and do something?
Example: if there is a stone block underneath an obsidian block, the stone block becomes a block
const block_below = block.below()
if (block.typeId === "minecraft:obsidian" && block_below.typeId === "minecraft:stone") {
// do whatever
}
mainly just the block.below() part
no mob vote mean no new ai goals ?
I fail to see how that relates at all
new component
You know we still get new mobs right?
nope
Well now you know
๐ฑ
is BlockCustomComponent onPlace called only when the player places the block or even in other situations like /setblock?
only when placed by players
ok
70% of the time google
world.beforeEvents.worldInitialize.subscribe((e) => {
e.itemComponentRegistry.registerCustomComponent("evo:voids_edge", {
onUse(e) {
const player = e.source;
const xyz = player.location;
const dimension = player.dimension;
player.startItemCooldown("custom", 20);
player.playSound("mob.enderdragon.flap");
player.runCommandAsync("particle evo:voids_edge_particle ~~~");
durability(player, e.itemStack, 10);
let nearbyEntities = dimension.getEntities({
location: player.location,
maxDistance: 10,
excludeTypes: ["minecraft:item", "minecraft:xp_orb"]
});
nearbyEntities.forEach((entity) => {
if (entity == player) return;
if (entity.isValid()) {
const dx = xyz.x - entity.location.x;
const dz = xyz.z - entity.location.z;
const length = Math.sqrt(dx ** 2 + dz ** 2);
const dx2 = dx / length;
const dz2 = dz / length;
entity.applyKnockback(-dx2, -dz2, 3, 0);
entity.runCommandAsync("particle evo:voids_edge_particle ~~~");
}
});
}
});
How to fix this
Entity pull away not closer
How to make entity pull closer ?
how can i change an itemstack amoutn?
itemstack.amount = 1
Question, please: how to avoid using experimental api entity.target to get entity's target? i can't find of a good solution
should be
I'm having an issue with that
show code
import { world, system } from "@minecraft/server"; function getPlayer() { const allPlayers = world.getAllPlayers(); if (allPlayers.length === 0) { return undefined; } return allPlayers[0] } function getPlayerLocation() { const player = getPlayer(); if(player === undefined) { return undefined; } return player.location; } function getPlayerRotation() { const player = getPlayer(); if(player === undefined) { return undefined; } return player.getRotation(); } world.beforeEvents.chatSend.subscribe((event) => { const player = event.sender; const message = event.message; let CameraPoint=[1,2]; if(message === "CameraPoint1"){ event.cancel = true; //the first point save if(CameraPoint[1] !== null){ //the point is already full world.sendMessage("ยงcCamera point is already full"); } else if(CameraPoint[1] == null){ CameraPoint[1]= { pos:getPlayerLocation(), rot:getPlayerRotation() } world.sendMessage("ยงqCamera point is set"); } } else if(message === "CameraPoint2"){ event.cancel = true; //the seconde code save if(CameraPoint[2] !== null){ //the point is already full world.sendMessage("ยงcCamera point is already full"); } else if(CameraPoint[2] == null){ CameraPoint[2]= { pos:getPlayerLocation(), rot:getPlayerRotation()} world.sendMessage("ยงqCamera point is set"); } } if(message === "Clear"){ event.cancel = true; if(CameraPoint[1] !== null && CameraPoint[2] !== null){ CameraPoint[1]=null; CameraPoint[2]=null; world.sendMessage("ยงqPoints have been cleared successfully") } else { world.sendMessage("ยงqThe points are already cleared") } } } )
for the love of god wrap it with ```js
lmao didn't know that was a thing
use Map instead
map?
const cameraPointMap = new Map();
cameraPointMap.set(key, value);
const value = cameraPointMap.get(key);
cameraPointMap.delete(key);
ehh
map is a function here?
it also remembers the insertion order like how the embed description says
interesting
this is how i used it
const playerStatus = new Map();
function initializePlayerStatus(player) {
const status = {
sprintKnockbackHit: false,
sprintKnockbackValid: false,
critSweepValid: true,
shieldValid: false,
mace: false,
lastSelectedItem: undefined,
lastSelectedSlot: undefined,
cooldown: 0,
lastAttackTime: 0,
shieldDelay: 0,
fallDistance: 0,
};
playerStatus.set(player.id, status);
}
export function getPlayerStatus(player) {
if (!playerStatus.has(player.id)) {
initializePlayerStatus(player);
}
return playerStatus.get(player.id);
}```
```js
for (const player of world.getAllPlayers()) {
const status = getPlayerStatus(player);
status.lastAttackTime = Date.now();
}```
this is a bit too advanced for me
my brain hurts lol
its worth knowing it
yep ig
you can also ask GPT about this (no dont ask it about minecraft API, ask em Javascript)
chat gpt and coding ain't on the same line lol
fair
its surprisingly a good teacher
what was the project that made you use this?
sweeping edge?
you also work for free?
maybe? if im willing
but mostly i dont accept commission or job offers
its just a hobby
oh so just projects for fun?
yeah
fair
the vid actually helped me understand how this thing works
does Entity.getRotation() vector2 return the degree of the entity's head yaw and pitch?
yeah
I've made this after following up from a question and conversation I had yesterday but this semi works. This seems to only take into account that players tag once the world has reloaded and not every time someone takes damage. If you spawn into the would with the tag but then remove it, you'll still take no fall damage. Any solutions?
After more testing I feel like it's not even checking the players tag and is just acting on whether deals_damage is true or false
Could someone help me remove 1 item from 1 chest? For example, I want to remove 1 coal from the chest every 5 seconds.
I have no idea how to do it
Unless you know the exact location of any specific chest it will be a heavy task having to search the area around each player to find one, then look through its inventory to handle the removal of a coal.
I know the location
well well well, i had some issues
i had to make a script that will spawn an entity at the block location when it has been placed ( already )
and when the entity is out of the block range it will teleport back to the same block, like saving the block location,
if the block disappeared, the script will trigger an event
lemme explain
That simplifies it then. I'll follow up later to see if someone already helped you. I can't write the code. Literally just got an emergency call lol.
I can do it in a little bit.
I will keep trying here, if I succeed I will let you know, and I hope the call you received is not bad news.
when u place the block, the entity will spawn and save the block location, when the entity somehow moved out of the block or the block has been pushed by a piston, it will teleport back to the last saved location,
if it teleported back and the block was different it will trigger an event
here's some code I have, it's not perfectly tailored to your solution but should start you off in the right way:
const chest = world.getDimension("overworld").getBlock({x: 10097, y: -59, z: 10000});
const chestInvComp = chest.getComponent("inventory");
item = chestInvComp.container.getItem(slotId);
slotId is a variable that I have to select specific slots
but you can loop through the container based on the number of slots the container has and check for coal and remove 1 from the itemStack
this is your loop:
for(let i = 0; i < chestInvComp.container.size; i++)
i think yaw only
atm?
what?
atm addon?
I don't know what "ATM" is, but it is an addon.
bruh
bro the atm machine that gives cash
bro lives in Antarctica or smtg
const map1 = new Map();
map1.set('a', 1);
map1.set('b', 2);
map1.set('c', 3);
can i make the value 1 for exemple an object?
Yea, you can put any value in a Map.
let's go
what about a array?
Yup, those too
how will it work tho?
Put an array in place of 1. So something like [1, 2, 3]
no like how will I summon it?
since when you use maps you only call the name so like the a
Are you wanting to get the value of a key in a Map? That would be map1.get(<your key>), with <your key> being, well, a key
I did it guys, thanks for the help
ok for example
const Player = new map();
map1.set('a',PlayerCount=[1,2,3,4]);
don't mind the mistake
set is after map
but ye
if i call a what will happened here
Well, it's invalid syntax. PlayerCount[1,2,3,4] will confuse JavaScript
yep
What is PlayerCount? Is that an array you have defined before? Like: const PlayerCount = [1,2,3,4];?
OK, then your example would look more like this:
const PlayerCount = [1,2,3,4];
const Player = new Map();
Player.set('a', PlayerCount);
In which case, calling Player.get('a'); will return the array PlayerCount is assigned to, whose contents are currently [1,2,3,4]
hmm
hello
how to save last location?
i mean when the entity spawn on a specific location, it will save the exact location and teleport the entity back to that location in some cases
sup
it's a function
entity.location
wait i think I'm wrong
for a player at least it's player.location
entitySpawn event:
- entity.prevLoc = entity.location
function or smt:
- entity.teleport(entity.prevLoc ?? entity.location)
//this is caching
that's beta?
ehh
wait, thats not exactly what im trying to do
Well, thanks for the helpful info on what you are trying to do
inside of runInverval, the script will detect an entiry and checks the entity if it inside of a specific block or not
sโ an entity class thing (which the player class extends)
It's but short 
mhm
The point is, that the player class can use most of the methods and properties the entity class has to offer
so player is a sub class of entity?
Yep
well a player is also an entity
nice
if the entity is inside the block it will save the block location, if the entity has been teleported outside the block somehow it will be detected and will teleport back to the saved block location, after it teleporting back it will check if the block is still there or not and if it was not there an event will be triggered
i hope i explained it right tho
applyImpulse() setRotation() from entity class doesn't work on players, so that's why it's "most"
applyKnockback is the only way to move the player
Well, you got what to do. Now just implement that to a working mess
the only problem is idk how to save the location
dynamicProperty can stores Vector3
entity.setDynamicProperty right?
yes
hmm, I'll check it
mhm
Like the literal object. You don't even need to stringify it
?
reverse engineer
does it use js?
Bedrock is written in C++.
bruh
And the API is in QuickJS
eh, how exactly?
ok my head hurts
entity.setDynamicProperty("loc1",entity.location)
understood
Retrieve it somewhere? When your entity need to teleport?
let location = entity.getDynamicProperty("loc1");
console.log(location.y);
if (block.center !== ',,,') entity.idk```
let location = entity.getDynamicProperty("loc1");
entity.teleport(location);
understood
I've made this after following up from a question and conversation I had yesterday but this semi works. I feel like it's not even checking the players tag and is just acting on whether deals_damage is true or false
any solutions?
That's... is that json?
let loc = entity.getDynamicProperty('lastLoc', entity.location)
if (block.center === ',,,') loc
if (block.center !== ',,,') entity.teleport(loc)```
?
i think setDyn not getDyn
if (block.center === ',,,') {
entity.setDynamicProperty('lastLoc', entity.location)
}
if (block.center !== ',,,') {
const loc = entity.getDynamicProperty('lastLoc');
if (loc)
entity.teleport(loc)
}```
understood
your setup is wrong
I mean, they say it canceled the damage. The filter thingy just doesn't work on their end.
hmm
how so?
HELO
WASUP
"minecraft:damage_sensor": {
"triggers": [
{
"on_damage": {
"filters": {
"all_of": [
{
"test": "has_tag",
"subject": "self",
"operator": "==",
"value": "noFall"
},
{
"test": "has_damage",
"subject": "self",
"operator": "==",
"value": "fall"
}
]
}
},
"deals_damage": false
}
]
}
It doesn't feel like it belongs to script API tbh
it doesn't lol
ahh amazing tyty, I'll try it out in a few minutes
i just logged in discord after a whole month
should i use system.runTimeout to run a command after the entity teleports back to the last loc to detect the block?
That's a cap, I searched your trace in this server, and you're actively chatting
if you want to run some code after something happen, use runTimeout, yes.
nvm you might be right
lol
but i'm not active every day, that's for sure
i just logged in maybe after a week
for sure
entity.teleport(loc);
system.runTimeout(() => { ,,, }, 2)?
ARE YOU A SPY
}, 2) will run the script after 2 ticks or 2s?
BRO HACKED ME OR WHAT
๐ค
skipped tow days ๐ฑ
I mean, I'll acknowledge it if you only send 1-5 messages each day lol
Listen, let me describe what i want to say.
I've been doing a lots of homeworks nowadays and i've been being busy for all day long, which could've make me think that a week like a month. I had half-time school before days, so i used to do actively chatting, but then my full time schools started, and that feels like a big change to me. So you might understood
@remote oyster
And, no. i didn't take your "skiped tow days" as a serious thing
i know that was a joke
sorry for the inconvenience
you took that a little too seriously
that shouldve been offtopic
lel

count in minecraft days
True
const entity = world.getEntity('entityId') returns a log, why?
id is the entity numeric id
so i have to do getDim().getEntities thing?
yeah
const scr = world.scoreboard
const killsObj = scr.getObjective('Kills')??scr.addObjective('Kills','dummy')
killsObj.addScore(entity,1)
Now I wonโt have to skiped tow days
huh
*tow awurs
is there a way to change this so all damage is blocked with a specific tag?
change the value from fall to any
or all
I don't remember
ping me in entity channel
I tried that but value is not expected
With nick colors ranks anti spam and more
Neat
Member
._.
block.center will detect if the entity is inside the block?
if (block.center.typeId === 'myBlock') ///
if (block.center.typeId !== 'myBlock') \\
?
Documentation for @minecraft/server
.center() returns a vector 3
so how can i detect the block if the entity was inside it?
i mean the entity should detect if it was inside the block or not
Grab the location property
Or edit the entoty json
nvm im so stupid
how to add something to items via script that animations can read
Wdym animations can read?
i want to hide part of attachable when player is performing a task
query functions don't seem to have anything
maybe scoreboard but then i have to set the score display
You can modify the playerjson to have entity properties then modify the entity prop and read via attacheable
entity.triggerEvent('exe:despawn')
the entity is getting that event trigger, but with this log
double check the event name
its right,
the event is triggering, but with that log
stop the trigger if the entity is not valid
if (block.typeId !== 'exe:grinder' && entity.isVaild) { entity.triggerEvent('exe:despawn') }?
isValid is a method; invoke it. entity.isValid()
also valid not vaild
can i see the script?
I want to learn message editing too
well, theres alot of hardwork
i think, the best way to do that is by making the entity moving with the block, like when u push it up it will go up with the block
using is_pushable_by_piston
NAH
If you want i can send you a example
@scarlet sable
All fun and games until you kill your fake block entity by accident with /kill @e
๐
player.js
making it pushable using piston will always kick the entity outside the block
then go ahead and make custom furnace without using entities using only blocks and JavaScript

๐ญ
Can be easily prevented if you set minimum health of your entity to 1, it wouldnโt die even from the kill command then
i already have that and still dying using/kill
i might done it wrong
i should make the entity able to go through blocks, to avoid being pushed out the block
gosh i had to make a script that will make the block entity is moving with the block, like when u push the block up it will move with it, when u push back the block it will keep inside the block
i think that can be done using onTick components inside the block
yes please
btw how do I copyright my work?
Idk
What's a job and what does "run job" does?
Is playerPlaceBlock, beta?
import {world, Block} from "@minecraft/server";
world.beforeEvents.playerPlaceBlock.subscribe((e) => {
const block = e.block;
const player = e.player;
let location = {
x: block.x,
y: block.y,
z: block.z
}
console.warn(block.location)
})```
Apparently the after event is stable, but the before is not
That would make sense lol
So, if I activate beta and use playerPlaceBlock, it will be added to stable later or so?
Since it's already being used with afterEvent?
Sorry, that doesn't seem like I'm talking sense.
I mean is it possible that it gets removed from beforeEvents at some point?
Nothing is confirmed until it ships
I guess I'll risk it. There doesn't seem to be another option
job is a task or tasks
run job use generator function
in these type of function you can use yield to suppurate a code into multiple chunks/tasks (loops in most cases)
run job run these tasks one by one each free fraction of a tick
ehhh it doesn't work for what i want
Is it possible to prevent a blog from being pushed with a piston?
world.beforeEvents.chatSend.subscribe((event) => {
const player = event.sender;
const message = event.message;
let CameraPoints = [0,1];
if (message === "SetCameraPoint") {
if(CameraPoints[0] === null){
event.cancel = true;
CameraPoints[0]={pos:getPlayerLocation,rot:getPlayerRotation};
world.sendMessage("ยงqFirst camera point was set successfuly");
}
else{
event.cancel = true;
world.sendMessage("ยงcThe first camera point is already full");
}
}
if (message === "clear"){
event.cancel = true;
CameraPoints[0]=null;
world.sendMessage("ยงqAll the camera points were cleared sucessfuly");
}
}
it seems that CameraPoints[0] is never null
Is it possible to make an animation, like that of the "use_animation" component in item components run when you use an Item with onUse
yeah just use Map
maping doesn't work the way i need it
fair
if a player sends SetCameraPoint the scripts checks if the CameraPoint1 has a value of null if it does it gives it a new value (CameraPoint1 is an object btw) so pos gets the valus of the function getplayerposition and rot gets getplayerrotation
camera point 1 has 2 characteristics as an object which are pos and rot
idk how update that stuff if CameraPoint1 is in a map
ill make it after breakfast
Do you have an example on how to apply this to a cycle?
And what is yield!
Yield?*
Scripting-Gods... I am having a brain-fart... wasn't there something that was like an enum of the dimension types... such that you could dimentionType.overworld which is overworld string or dimensionType['overworld']. DimensionType is a class with a typeId... I am a bit confused.
yeah theres enum for dimensions
I cannot find in API
if I assign a value to a map element how do I change it later?
iirc you just do "overworld", "nether", "the_end"
the same way you set it
.set?

yeppers
and get to check the value?
I know I can do it manually, but I wanted something future proofed...
though if you have array inside map you can just do map.get(key).value = yeet
nice
Depends. If the map value is an object, assigning a variable to that value lets you modify it without needing to explicitly call .set
why not just directly use dimension?
ig maps are cool after all
can you explain more?
I'm using an object
you can check the example i sent you yesterday
this is for parameter checking for a function
oh
this morning for me lmao
even thou I am the only user, I like to idiot proof it
and if they add a new dimension, that means I have to go update.. which is not future proofed
perhaps this is a good one
const MyMap = new Map([
['a', {foo: "hi"}]
]);
let obj = MyMap.get('a');
console.warn(obj); // {foo: "hi"}
obj.bar = "there"
console.warn(obj); // {foo: "hi", bar: "there"}
console.warn(MyMap.get('a')); // {foo: "hi", bar: "there"}
so.. just build the check list from the results.... that works
oh
No, you'll get [object Object]โbut putting JSON.stringify(blahblah) would have bloated the example
My fav ref site: https://www.geeksforgeeks.org/javascript-map/#
JavaScript map() function allows you to apply custom functions to each key-value pair in an iterable, seamlessly passing the item as a parameter.
I always forget about the stingy thing... have not gotten into databases yet
the problem is addons need sometimes specific info that js for websites don't use that often
the language is the language
Such as?
api shit
the classes and props are the api
API-agnostic features like Map are going to be found in any (practical) implementation of JS
I presume youre talking about the API and not the actual language
map is language
fair point
anyways I'll take a try and comeback
This is the first thing I do.... open a new google page type js map or any key word that you need a reference for.... the top ones show up... MDN, W3, GeeksForGeeks... can miss it
MDN is my go-to for reference
I think MDN goes more in-depth, and tends to mention easy pitfalls for novice programmers (which I have nearly fallen into before)
been checking out that topic for at least an hour
If you want one that will hurt your head, check out Array.prototype.reduce
I believe asking the dumbest questions gives the best info
ye i checked it out
and split
it's not hard tbh
but i don't see a use for it
I believe asking after you cannot figure it out produces a great self-sufficient thiinker... the only type of programmer I trust with my stuff at work... everyone else.. is just a user.. push buttons
If you understand the idea of reducer functions, kudos to you ๐
it's that hard?
If you want JS practice... do codewars dot com..... people do get ridiculous with refactoring imo
this one seems quite simple
some solutions are mind boggling
Usually there are clearer ways to do the same thing, but not always. I can't quite wrap my head around it intuitively, and it takes me a good few minutes to write a good Array.reduce
well understanding a code and write one is not the same
I 100% can't write a reduce code
Here is a vector.add function I put together using array.reduce
static add(...vecs: Vector3[]): Vector3 {
return vecs.reduce((old, anew) => {
const out = {...old};
out.x += anew.x;
out.y += anew.y;
out.z += anew.z;
return out;
});
}
It's about classes, don't worry too much about thatโread that as "function" for the moment
what was that?
epic fail
lol
As part of a broader Vector class, it would be used like this:
let a = {x: 1, y: 1, z: 0};
let b = {x: 1, y: 0, z: 2};
let c = {x: 0, y: 3, z: 3};
const sum = Vector.add(a, b, c);
consle.warn(sum); // {x: 2, y: 4, z: 5}
Here is an example of why GeeksForGeeks is good for concepts... not many list it out like this so you can look one by one...
the only thing confusing me is ...vecs
vector3?
That's a spreader
The notable figure there is the spread operator: ... In a function declaration, it lets the function know it should accept any number of arguments
Yea, a spread operator.
oh ok
The resulting value gets passed as a single parameter (named vecs here), and it's an array
vector is just an object with 3 properties... x,y,z
the points were the problem
a victor is just coords
what do you mean by points
Yes, otherwise known as a single point in space!
what is the trouble you are having
yep
i was just trying touderstand that script but i didn't know wht the dots were for
Probably doesn't help that "point" and "dot" could both refer to a period
And that "point" can refer to both a period and a Vector3
But yes, spread syntax is handy, in functions and beyond
const arr = [1, 2, 3];
const newArr = [...arr, 4, 5];
console.log(newArr); // Output: [1, 2, 3, 4, 5]
I'm not in the lvl that can understand this
I did just paste that from a larger file without any context, so that's all right
ye context is important
Technically a static method must be part of a class declaration, so a proper, fully usable snippet of that code would be like:
class Vector {
static add(...vecs) {/* ... */}
}
This is basics.. I think... have you done a YT class yet?
You can get pretty far without knowing class syntax
I mean class-class
class & static feels like zip files or executable shortcuts for me lol
ok i made a bad spelling mistake but my wifi wont let me edit it
bad wifi.. bad wifi
there we go
class log { static zip() {}} be hitting you with that log.zip()
I took a pretty basic one
Just a reminder of casual stuff
Didn't find the time for a full 20h course tbh
sometimes I use a file as a class... import * as thisClass.... then use everything like a class member
Also i find the api really fun so I'm trying to memorize as much stuff as possible for the moment
well, as long as you are happy
: D
I always keep the scripting API documentation open every time I work with the API
Oh really?
jayly docs my beloved
I thought it's a muscle memory ngl
Like when you're writing a logical equation and the symbols just get written without thinking
Some of it is. You learn that world.getPlayers() returns a Player array, and you remember all the properties on the Player class you want through repetition. But some stuff is wildly niche and I have to go looking for what classes are capable of which things
That comes with time & practice, really
The more you use something the more adept you become with it (goes for anything in life)
I always wonder if people working with companies on add-ons are allowed to use Google for such stuff
In the marketplace
Of course, they're people like us too, and liable to make mistakes. Not everyone knows everything off-hand
Fair point
Yes
Now if you were to ask me about command wizardry, I might be able to do that without a reference, though I'm kinda rusty
Is anyone a member of a marketplace company?
ofc
Oh
I am not
Interesting
not me
I consider myself a hobbyist first before a Marketplace company employee though
Like wise
i had multiple offers but i turned em down
Is like each member assigned for a specific task? Or just the code kinda flies from one person to another?
I plan to undercut the market place and do great things for free.... after I become an add-on genius
My plans are quite big ngl and kind of delulu
I want to create a mod client
Really depends on the company structure. Most of them will be like what you've described; and the team will (should) use some version-control software to identify who did what and when
then get serious about your language learning... and maybe do typescript...
Oh that's pretty cool
School makes learning stuff quite tuff
relatable
me using microsoft's github to store code written in microsoft's vscode for microsoft's game
And i want to get good grades on my finals so i can choose maybe a tech relatable uni
Ironicโฆ schools are used to learn xD
Fr
if you are not fund-strapped, I suggest Mosh Hamedani All Access Pass... take a year and learn a lot of languages.. well not a lot but a few key... beginner to advanced...
Idk why or When i will use a random french poem tbh but ok
Well that's the second problem
I'm broke af
If not get a job in the next 5 years might become borderline homeless lol
well, there is a lot free on YouTUbe.. like alot... and if you really into it.. then you are already devouring it
What is the stuff i need to focus on when it comes to js?
Even take the FREE famous Harvard class that teaches a lot of basics
Depends- just script API stuff? Or web dev stuff as well?
depend on your goal
Api atm
Because a decent chunk of JavaScript can be cut out if youโre just interested in script API
I want to start making add-ons nothing else
Really just knowing the primitive language features, and being familiar with both an object-oriented design (you're doing this already with methods like Array.sort()) and a functional design (writing functions to re-use code)
Yep
Btw has anyone use a matrix in a code before?
Mm, I haven't but I have meant to
tbh i find my self a lot making scripts outside the api to help in the addons development it self
2D array?
Not specifically
JS lets you make arbitrarily deep arrays by nesting them together, but there are not any native matrix libraries (that I know of)
Looking at the api library i think it's limited a little
I also possess an extremely poor understanding of linear algebra so I probably will not be working with matrices anytime soon lol
Using math in a code could be a cool way for me to train my coding skills and prepare for my actual classes
Yeah, that is how I really got my feet wet. Writing my own regolith manifest maker, complete with fetch the latest version for stable/beta/preview. i love my filter, makes my life easier.
But i wonder if i Ill get the chance to do that
to the most users it is "good enough"
a lot of great addons have been made by it
Oh absolutely. In my Calc III class we are working with vectors a lot, and I already have some practice from writing a small Vector library
Goes both ways. What I learn also helps me understand what vectors are doing better (cross products were so confusing)
That'll be fun
Vectors are very fun :3
there is an other format if you want to store the dimension in there too...
I thought at first it was a physics vector
I would've probably never self guessed it was just x y z coords
All the same, really
At least to Minecraft
Kinda
In school it's identified with intensity and direction
But ig you can get these info using coords
In Minecraft it can be both stored in the same format
locations are not vectors in physics
E.g. block location, or view direction
How?
I KNEW THERE was... a dimension enum.... MinecraftDimensionTypes
Idk why it gives me this error, im clearly geting the tags from the equippableItem variiable
at forEach (native)
at <anonymous> (custom_components/wand.js:45)```
Here my code
```js
system.runInterval(() => {
world.getAllPlayers().forEach(player => {
if (!player) return;
const equippable = player.getComponent("minecraft:equippable");
const equippedItem = equippable?.getEquipment("Mainhand");
const itemTag = equippedItem.getTags();
if (equippedItem && equippedItem?.typeId === "wands:wand" || itemTag === "wands") {
player?.runCommand(`title @s actionbar ยงb:: Mana: ${mana}/${maxMana} ::`);
}
});
}, 20);
What's a minecraftcooldowncathegory?
I grabbed the wrong one
Oh fair
its in the vanilla data
the minecraft cooldown cathegory ๐คก
Like the pearl hotbar cooldown?
the type that make other items in the same category start a cooldown
Oh that's so cool
var MinecraftCooldownCategoryTypes = (MinecraftCooldownCategoryTypes2 => {
MinecraftCooldownCategoryTypes2["Chorusfruit"] = "minecraft:chorusfruit";
MinecraftCooldownCategoryTypes2["EnderPearl"] = "minecraft:ender_pearl";
MinecraftCooldownCategoryTypes2["GoatHorn"] = "minecraft:goat_horn";
MinecraftCooldownCategoryTypes2["Shield"] = "minecraft:shield";
MinecraftCooldownCategoryTypes2["WindCharge"] = "minecraft:wind_charge";
return MinecraftCooldownCategoryTypes2```
open a post
I need to go
var MinecraftDimensionTypes = (MinecraftDimensionTypes2 => {
MinecraftDimensionTypes2["Nether"] = "minecraft:nether";
MinecraftDimensionTypes2["Overworld"] = "minecraft:overworld";
MinecraftDimensionTypes2["TheEnd"] = "minecraft:the_end";
return MinecraftDimensionTypes2```
no
why use enum ๐
param checking for a function... I idiot proof myself
I will never use wrong
but we all have brain farts
true
It is from mricosoft's file from one of the npms
My brain has 70% brain farts instead of cells
but I think I better use getAll() and map it
Can you create a new category?
JSON yeah
Damn bro don't roast me like that xD
lol
when you are a woman being called one... it FEELS like it
Sorry sis
I know.. I know.. I got a son and even he says it sometimes ( when I bug him too much)
I'll be careful next time
It is not that serious
LOL.... I am a bonafide smart-ass
but the auto-pilot thing is key.... to function in the real world, using filters is important
call your lady boss that.. and see what happens
yeah
some time it is needed
you get used to things that it just feel right
you get used to that because the new generation is not slapped upside the head for mistakes like that... LOL
just not used in speaking in a community tbh
big change from facebook to discord
Scripting Gods... in your opinion an arrow function good for the dimension list?
I need a string array of the valid dimensions... to use whereever... so const dimeList = ... world...getAll().map( x -> x.typeId) without being exact
cause i did not do it in vscode yet
Why not use the vanilla enums?
cause it is hardcoded and if another is added and I did not do the npm and copy the file to my library...
Thats...a concern sure
so if a new one added, me screwed
Not for a long time
I know, but I do not want to update an add-on for THAT
I think I will make a vanillaListClass.. and just pull most that are avail in the API... so I have the code ready...
https://stirante.com/script/server/1.13.0/classes/DimensionTypes.html why not? Then loop through?
Documentation for @minecraft/server
Im just confused really on when you would need to use what you suggested unless ots to execute in all dimension
I do not want to do that each time..... seems like I should make function that I can use over and over and in diff places.. .like a library
won't that get outdated when the new api comes out (alpha or idk)
no.. si I can do if (dimes.includes(dimParm))
ok?
Its like BlockTypes which take into account addons as well
oh yeah
Yeah, I found that and was stokked, that I can get that list to validate blocks... even has user blocks
I need like a real world use case example to really understand what you need
I need to verify the param```js
/**
*
- @param {string} command
- @param {string} [dimension='overworld']
- @param {number} tickDelay
*/
export function worldRun (command, dimension = 'overworld', tickDelay = 0) {
if (command && DimensionType[ dimension ])
if (tickDelay < 1)
system.run(() => {
world.getDimension(dimension).runCommand(command);
});
else if (tickDelay >= 1)
system.runTimeout(() => {
world.getDimension(dimension).runCommand(command);
}, tickDelay);
}```without using hard-coded data
but I've been a programmer toooooo long to just keep writing the same code over and over, so I am building my own libraries
DimensionTypes.get(string)?
If undefined...return
if undefined, throw!
yeah, I figure I used it wrong up there.. and I did not get an error
no... LOL
make the second param be a keyof DimensionType or directly the enum member
not in a game.. just get nothing, programmer should be testinging
And never handle the error!
Yeah im not really seeing an issue here nikki
But actually, throwing an error means you leave it up to the end user to decide what to do if the dimension does not exist. Which is better than it silently failing, if they were waiting on it do something
And when (if) we get data-driven dimensions, it makes this more useful
throw is the most useless keyword for general scripting, why would you generate an error if you aren't making a library or a class?
the question is


