#Script API General
1 messages · Page 34 of 1
how do people get items in ender chest
???
If you mean check items on the players ender chest? Sadly you can't
I always notice a lot of people do this.
ender chest viewer
oh
There is no official API support to do that right now.
but ive seen people do it
Then send the addon, name who did it, videos, ss, cause we are saying it already... You can't
fr
They are not using official API support to accomplish their goals.
let me look at the addon
admin utils on mcpedl
Nahhh
they have an ender chest viewer
They are probably using commands.
I just posted a way to do this today #1306719668429389834 message
It's pretty hacky, uses a ton of commands, but it's the best we have unfortunately
One day they will introduce a component lol.
Hasitem
That involves using commands.
I opened the file and it's not an end chest, it's only chest
-# or I suck at finding things lmfao
i know I just guessed the method
I was right it was hasitem
I hope so. It would be great to be able to actually get items out of an ender chest. You can kinda do most things with commands, but of course you can't add or remove items that have attached data.
what about replaceitem
oh yeah
attached data
nbt editor in commands like java would go hard
Ender chest component hopefully soon 
That cringe face hahaha
is it possible to make it so that on weather change I set an event that changes all of a specific block to change.
For example i’m making clouds that turn into rain clouds when it starts raining
I already have the weather change event, but it does not allow for block
only for server-net? or script api in general
This has nothing to do with the server-net module
If you make clouds in blocks, then lags are inevitable. It's better to do them on entities or particles
It would be general, if it gets added.
particles would be best, no need to manage entities, just have a 1 tick particle that gets applied and then switch it out on events
and iirc they're faster to render
It’s not being implemented as your thinking. I’m making cloud blocks you can stand on up in the sky
I’m trying to avoid using onTick
Instead I tried out the weatherChange event, but I don’t have a way using that to set all cloud blocks to rain blocks that I can find
make the blocks invisible and spawn the necessary particles there
Still does not solve the fact that I can’t get the block
Because I can detect the change in weather yes, but nothing beyond that in the event
ah like terraria?
hmm
that is an interesting problem
Yeah, I want to do it my own way though.
I have this idea where there’s structures and stuff high in the clouds, but I want to make it so that the white clouds turn into rain clouds when it starts raining, this is where the issue is
you could use onRandomTick
it might look better as well
so they all slowly become rain clouds
I’m doing that now but with onTick, and setting an interval so it happens slowly
The issue is when you multiply that by 100’s of blocks i’m afraid of the consequences
I wouldn't set an interval
get the current tick at the start and compare it
it should be a bit faster
The issue is then some clouds would be white for a long while while it’s raining for a minute or so, setting an interval lets that not happen
it sets a max limit for how long it’s allowed to stay a white cloud while it’s raining
Otherwise with random tick there’s a chance it does not happen at all right?
I can’t get to my laptop right now, but i’ll give you all the details I can in the post
But I was hoping to avoid ticking in general because of how bad it would get with lots of blocks
ah wait I got an idea
how are your blocks being placed?
you could try onPlace and then inside of that subsribing to the weatherChangeEvent
might work, not sure though
would be better than checking every tick
normal block
worldgen?
Thought of that, issue is in order for that weather change event to go off, it would need on place to go off first
Well for now it’s placing
Like i’m placing it around now for testing, and eventually i’ll make it a structure
here go to the post I made
afterEvents works with worldInitialize?
its the same as beforeEvents?
slightly different, only the beforeEvent has the custom component registry
so i cant use it with the custom component?
what?
without the custom_component_registry, what can i do with worldInitialize?
Execute events when the world is launched
Heyas. I'm wondering if there is a way to tell if an entity is a player? I'm new to JavaScript so its likely a simple is class of type thing, right?
Is it js if (typeof(entity) == Player)?
or do I need the '===' test?
if (entity.typeId === 'minecraft:player')
ahh... Okay
I always use this way but absolutely this not only way
Thank you
Is it worked?
Oh I haven't got to the part where I need it yet, just planning what I'm going to do and making sure I can
Oh
I think it can work
I have to re-establish the state of things when the world is initialised, including testing what has happened to entities which may or may not be players
Sry I don't fully understand of it
I'm building a Ferris Wheel but I need to control how players dismount otherwise they will kill themselves. I need to check the riders of the seat entities to see if they are players or not, in order to know how to do it.
I'm not entirely sure what will happen if you log out while riding and log back in again
Yes, just as I suspected, you will try to log in again in the seat... I wonder what will happen if the seat has changed since then? I guess you'll fall...??
Can U send image
Oh of what do you mean?
The thing U are making
ok...
one sec
Here it is
I'm going to build a ferris wheel controller block which will manage 12 ferris seats (which can actually seat 2 entities) and I need to know at all times, what the entites are that are riding it and if they are players or not
Once I establish that its a player, I do not let them have no riding component else I force them back into the seat they were riding
Did U alr have the code now
I have the prevent dismount code... ```js
if (ferrisSeat == undefined) {
//if (ferrisPlayer) {
//ferrisSeat = ferrisPlayer.dimension.spawnEntity("mewp:ferrisseat", ferrisPlayer.location);
//}
} else {
if (ferrisPlayer) {
const riding = ferrisPlayer.getComponent("minecraft:riding");
if (!riding || !riding.entity) {
if (ferrisDegrees <= 250 || ferrisDegrees >= 290) {
const rideable = ferrisSeat.getComponent("minecraft:rideable");
rideable?.addRider(ferrisPlayer);
} else {
ferrisPlayer = undefined;
}
}
}
But I'm going to need to scan the seats and their riders every "tick" I suspect
I need to scan the seat entities's rideable components for entities and determine if they are players. I think I'm good now that I know how to detect the type of the entity
👌
And I guess I just give a warning not to log out while riding 😉
Why U not force let player can't log out?
Oh you can do that??
for what sorry?
Your Ferris wheel code
Well its only testing what happens when I try to control a rideable entity at the moment
and moving it around
and preventing dismounts
You need the rideable entity
So U are not actually coded yet?
The seat have rideable components?
sure
You can ride the seat around and around
and dismount only when its at the bottom
here is the function I call every "tick": ```js
let ferrisPlayer = undefined;
let ferrisSeat = undefined;
let ferrisLoc = {};
let ferrisDegrees = 270;
function ferrisTick() {
if (ferrisSeat == undefined) {
} else {
if (ferrisPlayer) {
const riding = ferrisPlayer.getComponent("minecraft:riding");
if (!riding || !riding.entity) {
if (ferrisDegrees <= 250 || ferrisDegrees >= 290) {
const rideable = ferrisSeat.getComponent("minecraft:rideable");
rideable?.addRider(ferrisPlayer);
} else {
ferrisPlayer = undefined;
}
}
}
const radius = 11;
const rads = ferrisDegrees * (Math.PI / 180);
const z = radius * Math.cos(rads);
const y = radius * Math.sin(rads);
const loc = { x: ferrisLoc.x, y: ferrisLoc.y + y, z: ferrisLoc.z + z };
if (Math.trunc(loc.y) == Math.trunc(ferrisSeat.location.y) && Math.trunc(loc.z) == Math.trunc(ferrisSeat.location.z)) {
//world.sendMessage(`loc x: ${loc.x}, y: ${loc.y}, z: ${loc.z}`);
ferrisDegrees += 5;
if (ferrisDegrees > 360) {
ferrisDegrees -= 360;
}
} else {
ferrisSeat.teleport(loc);
}
}
}```
and the event to get it going... ```js
world.afterEvents.playerInteractWithEntity.subscribe((event) => {
const { beforeItemStack, player, target } = event;
world.sendMessage("interact after");
if (target.typeId == "mewp:ferrisseat") {
ferrisPlayer = player;
if (!ferrisSeat) {
ferrisSeat = target;
ferrisLoc = { x: target.location.x, y: target.location.y + 11, z: target.location.z };
//ferrisSeat.teleport(ferrisLoc);
}
}
});
I had to use teleport because trying to apply impulses wasn't working. Maybe its because Ididn't know what I was doing but oh well
Here is the json for the seat entity (in behaviour pack): { "format_version": "1.21.40", "minecraft:entity": { "description": { "identifier": "mewp:ferrisseat", "is_spawnable": true, "is_summonable": true, "is_experimental": true }, "component_groups": {}, "components": { "minecraft:type_family": { "family": [ "vehicle", "ferriswheel" ] }, "minecraft:conditional_bandwidth_optimization": {}, "minecraft:collision_box": { "width": 2, "height": 1 }, "minecraft:damage_sensor": { "triggers": { "deals_damage": "no" } }, "minecraft:persistent": {}, "minecraft:physics": { "has_collision": true, "has_gravity": false }, "minecraft:can_fly": {}, "minecraft:behavior.float": {}, "minecraft:rideable": { "seat_count": 2, "interact_text": "action.interact.ride.minecart", "pull_in_entities": true, "seats": [ { "position": [ -0.4, 0.1, 0.0 ] }, { "position": [ 0.4, 0.1, 0.0 ] } ] } }, "events": {} } }
The entity had to have can_fly, behavior.float and no gravity physics to work properly. The collision stuff isn't working I suspect because its rideable.
I'm surprised it doesn't try to turn but I haven't enabled any of that kind of thing in the behaviours, I suppose.
U alr made it force seat now?
What thing U lack yet
Yeah, if it has a player then it makes sure they keep riding
Its a bit strange when you do try to dismount, you do jump out briefly but get grabbed back in
Okay, so preventing them from logging out if you say I might be able to do that, that would be nice... And then also, every tick, I need to check the seat for changes in its rideable component's seated entities to see if they are players or not
Once I have multiple seats, I need to "attach" one to a player
I can't persist all that data so I need to be able to regenerate it on the fly
function checkSeatEntities() {
if (ferrisSeat) {
const rideable = ferrisSeat.getComponent("minecraft:rideable");
if (rideable && rideable.seatedEntities.length > 0) {
rideable.seatedEntities.forEach(entity => {
if (entity.isPlayer()) {
}
});
}
}
}
I think can try this to check entity
is there any way to detect if the entity gets an explosion near it?
yes, wait ill send an example
Does anyone know how to make a script that makes an arrow disappear when it hits a block?
yes, wait a sec
ping me when finished
world.afterEvents.projectileHitBlock.subscribe((event) => {
event.projectile.remove();
const { x, y, z } = event.location;
console.warn(`Removed arrow at ${x} ${y} ${z}`);
});
So when the arrow hits a block, it will be removed?
;O
yes
thank you so much ! ;D ❤️
world.beforeEvents.explosion.subscribe((event) => {
const { dimension, source } = event;
const initialLocation = source.location || event.getImpactedBlocks()[0].location;
const nearEntities = dimension.getEntities({
location: initialLocation,
maxDistance: 12, // can be changed
closest: true // can be removed if you want to get all entities within the maxDistance
});
});```
Should work
a more typesafe way would be to do
if(entity instanceof Player){}
Clearer
if (entity instanceof Player) { ... }
ok
Btw entity.typeId === 'minecraft:player' would be alot more safe because when you stringify your player objekt and parse it again, it wont be an instance of the Player class anymore
great.
hm, const onFire = entity.getConponent('onfire') should detect when the entity is on fire
if (onFire) { ,,, }?
wait let me check
// onFire will be undefined if entity is not burning
if (onFire) { ... }
export class EntityOnFireComponent extends EntityComponent {
private constructor();
/**
* @remarks
* The number of ticks remaining before the fire goes out.
*
*/
readonly onFireTicksRemaining: number;
static readonly componentId = 'minecraft:onfire';
}
sure, ping me when anything is
Don't just stringify a class instance lmao. You'd want proper serialisation/deserialasation. It would also loose its handle to native. Tldr: use instanceof and be typesafe
You're right
folks am i right in saying you cant have some configuration variables stored in a JSON file and load them in using the Script API??
it should detect when my entity get exploded or an explosion near it right?
wait will it just detect the explosion location or the closest explosion radius?
all explosions has radius, when the explosion happens nearby the entity will the radius be detected too or the explosion location only?
trying to explain
Correct.
it will get the all the entites within the maxDistance or the closest if wanted
For custom knockback
edit the player or entity .json files
so, when the explosion happens, it will pick the closest entity within 12b radius right?
JSON
@quick shoal please stop crossposting.
Okay
Sry
yourFile > entities > player.json
{
"format_version": "1.18.20",
"minecraft:entity": {
"description": {
"identifier": "minecraft:player",
"is_spawnable": false,
"is_summonable": false,
"is_experimental": false
},
"component_groups": {
"minecraft:knockback_resistance": {
"value": 0.6
}
}
}
}
Thanksss I will try it
yes, you also can rmove the property closest to get all entites within the distance
(i dont know if this even works but sure)
i will remove it.
sure
Wait did I need full player.json or just the thing I need to changed?
you dont need the full one
missing parts are implemented "inside of" minecraft
this fog has an entity inside of it, when the explosion happens it will not do anything to the entity, so i want to make it when the explosion happens it will make the entity explode too, ty for helping
Oh
this fog has 25% to spawn from mining sulfur ore in the nether
Then the closest property is what
whenever the entity sets on fire it will cost the fog to explode
That's cool
Nice, no problem
Can I find it in player.json?
the message was for t17x
if you mean this message
dont worry
Does 0.6 is the best value?
0.6 was just an example
Why the people they who made the custom kB doesn't use player.json?
hmm, maybe because if you would do it via script you have more control over it
No
yes
also a point
I found
If using script
When the player pvping they will have a long range reach
💀
well
I never thought it would be so easy
I thin if you do it via scrit you have mroe control over what happens BUT it won't work that fluently
Yea
I'm just need a ** low knockback **
Imma test it now:)
then put the value on 0.6-0.9
you need to restart the world if you edit entity json files
/reload wont work
Bro I put 0.4
No I using phone so I always reimport addons and delete world then recreate it
uhhh.. okay?
(just rejoin the world..)
well - idk how it works on MCPE
so i better shut up
uhh
What is that means
wait
What
@distant gulch
world.beforeEvents.explosion.subscribe(({ dimension, source, getImpactedBlocks }) => {
const iLoc = source.location || getImpactedBlocks()[0].location;
for (const entity of dimension.getEntities({ location: iLoc, maxDistance: 7 })) {
if (entity.typeId === 'entity') entity?.triggerEvent('exe:explode') ←←←
}
})```has a log
[Scripting][error]-ReferenceError: Native function [Entity::triggerEvent] does not have required privileges. at <anonymous> (index.js:465)
system.run(()
that was the reason why people are using scripts...i i guess player knocback can't be overwritten
...
cute arrows
Fine
The issue you're encountering is because the "minecraft:player" entity cannot directly apply the minecraft:knockback_resistance component in this way. The minecraft:player entity is a special built-in entity type in Minecraft Bedrock Edition, and it doesn't follow the same behavior as custom entities in many cases.
hah
No:(
!hah
folks, has anybody come across a skyblock quests system, I'm looking for a point in the right direction of how to record and reward players in my realm for simple skyblock-like quests (mine 64 cobble, collect 32 leaf blocks etc) all i can find at the moment are fancy UI's that you tick off manually
You can use scorebaords to keep track of events.
Very true @wary edge its the counting/rewarding part i was looking for. I'm ok with creating my own, but its always good to smooth a wheel than re-invent it
if (entity.typeId === 'entity' && entity?.isValid()) system.run(() => {entity?.triggerEvent('exe:explode')}); ←
is it bec of entity→?←.triggerEvent?
wait
@untold magnet do
world.beforeEvents.explosion.subscribe(({ dimension, source, getImpactedBlocks }) => {
const iLoc = source.location || getImpactedBlocks()[0].location,
entitiesInArea = dimension.getEntities({ location: iLoc, maxDistance: 7, type: 'entity' });
system.run(() => {
for (const entity of entitiesInArea) {
if (!entity.isValid()) continue;
entity.triggerEvent('exe:explode');
};
});
});
will be more perfomant
dont use type: 'entity' bec i will be using that method for other different entities
okay then:
entity.typeId will return (example) minecraft:skeleton
and not entity
hmm,
na
what then?
it just detecting if the fog entity gets an explosion nearby it
lemme test if this would work
world.beforeEvents.explosion.subscribe(({ dimension, source, getImpactedBlocks }) => {
const iLoc = source.location || getImpactedBlocks()[0].location;
system.run(() => {for (const entity of dimension.getEntities({ location: iLoc, maxDistance: 7, type: 'entity'})) if (!entity?.isValid()) continue; entity?.triggerEvent('event')})
})```
should but "type" wont ig
@untold magnet this should do it
world.beforeEvents.explosion.subscribe(({ dimension, source, getImpactedBlocks }) => {
const initLocation = source.location || getImpactedBlocks()[0].location;
system.run(() => {
const entitiesInArea = dimension.getEntities(
{ location: initLocation, maxDistance: 7 }
);
for (const entity of entitiesInArea) {
if (!entity.isValid()) continue;
entity.triggerEvent('exe:explode');
};
});
});
Don't forget that source can be undefined and the block array can be empty
well if source is undefined it should take the first block but when its empty we got a problem
I don't see "?" in source.location
ohh my bad i forgot it
@untold magnet use this - Thanks for the remark @warm mason
import { world, system } from "@minecraft/server";
world.beforeEvents.explosion.subscribe(({ dimension, source, getImpactedBlocks }) => {
const initLocation = source?.location || getImpactedBlocks()[0].location;
if (!initLocation) return;
system.run(() => {
const entitiesInArea = dimension.getEntities(
{ location: initLocation, maxDistance: 7 }
);
for (const entity of entitiesInArea) {
if (!entity.isValid()) continue;
entity.triggerEvent('exe:explode');
};
});
});
Well, it will also give an error if the array of blocks is empty
why if (!entity?.isValid()) continue;?
By the way, why use beforeEvents?
it was like an instinct to use it
but maybe afterEvent would be better
due i dont need to run system.run
Because mega bugs are mojang when the entity is in front of your face but it is not valid #1067535608660107284 message
right right, wait
world.afterEvents.explosion.subscribe(({ dimension, source, getImpactedBlocks }) => {
const initLocation = source?.location || getImpactedBlocks()[0]?.location;
if (!initLocation) return;
const entitiesInArea = dimension.getEntities(
{ location: initLocation, maxDistance: 7 }
);
for (const entity of entitiesInArea) {
entity.triggerEvent('exe:explode');
};
});
Thats should fixxxx it
looks so much cleaner now
By the way, the first block will most likely be somewhere on the outskirts of the explosion, so it would be better to determine the average of their locations
yes that was also my first tought but well, i was too lazy for this
i just want the explosion to detect my entity without logs
call them errors, not logs
errors logs both hurts
edit this
world.afterEvents.explosion.subscribe(({ dimension, source, getImpactedBlocks }) => {
const iLoc = source.location || getImpactedBlocks()[0].location
if (!iLoc) return;
const entities = dimension.getEntities({ location: iLoc, maxDistance: 7 });
for (const entity of entities) if (entity.typeId === 'entity' && entity.isValid()) entity.triggerEvent('event')
})```if needed
I changed my mind about writing this
just... make it detects my entity
bec i have no idea how
function getAverageBlockLocation (blocks) {
if (blocks.length === 0) { return null; };
const blocksLength = blocks.length;
let xSum = 0, ySum = 0, zSum = 0;
for (const block of blocks) {
const { x, y, z } = block.location
xSum += x; ySum += y; zSum += z;
};
return {
x: xSum / blocksLength,
y: ySum / blocksLength,
z: zSum / blocksLength
};
};
const iLoc = source.location || getImpactedBlocks()[0].location
[Scripting][error]-Error: Failed to get property 'location' at <anonymous> (index.js:463)
source?.location
same log
world.afterEvents.explosion.subscribe(({ dimension, source, getImpactedBlocks }) => {
const initLocation = source?.location || getAverageBlockLocation(getImpactedBlocks());
if (!initLocation) return;
const entitiesInArea = dimension.getEntities(
{ location: initLocation, maxDistance: 7 }
);
for (const entity of entitiesInArea) {
entity.triggerEvent('exe:explode');
};
});
function getAverageBlockLocation (blocks) {
if (blocks.length === 0) { return null; };
const blocksLength = blocks.length;
let xSum = 0, ySum = 0, zSum = 0;
for (const block of blocks) {
const { x, y, z } = block.location
xSum += x; ySum += y; zSum += z;
};
return {
x: xSum / blocksLength,
y: ySum / blocksLength,
z: zSum / blocksLength
};
};
is all of that really necessary
how
logs? 'errors'
no
different ones
btw use this as return ```js
return {
x: Math.round(xSum / blocksLength),
y: Maph.round(ySum / blocksLength),
z: Math.round(zSum / blocksLength)
};
will be better
it now has math
Maph
Yes
Maph
(typo)
@untold magnet
import { world, system } from "@minecraft/server";
world.afterEvents.explosion.subscribe((event) => {
const initLocation = event.source?.location
|| getAverageBlockLocation(event.getImpactedBlocks());
if (!initLocation) return;
const entitiesInArea = event.dimension.getEntities(
{ location: initLocation, maxDistance: 7 }
);
for (const entity of entitiesInArea) {
entity.triggerEvent('exe:explode');
};
});
function getAverageBlockLocation (blocks) {
if (blocks.length === 0) { return null; };
const blocksLength = blocks.length;
let xSum = 0, ySum = 0, zSum = 0;
for (const block of blocks) {
const { x, y, z } = block.location
xSum += x; ySum += y; zSum += z;
};
return {
x: Math.round(xSum / blocksLength),
y: Math.round(ySum / blocksLength),
z: Math.round(zSum / blocksLength)
};
};
This should be the final
i dont think its locked for a specific entity isn't it?
either use entity.typeId or his "family"
first of all, no edits or changes
I'll test it out without doing anything
if it works fine I'll edit it a bit
alr
how
Ok this needs to be moved to a post now.
Okay sorry
lets dm
@distant gulch, should we try to unsubscribe it?
also what the actual hell will the unsubscribe will do to the event?
take "unsubscribe" by word
uh,
const entities = entity?.dimension.getEntities({location: entity?.location, maxDistance: 1});
for (const eEntity of entities) {eEntity?.addEffect('poison', 1, {amplifier: 1, showParticles: false}); eEntity?.addEffect('blindness', 3, {showParticles: false})};```is not working
it should
detect entities around my specific entity in 1 block radius
and give them 2 effects
^ no logs
Bot down
what?
Bot is down
i meant with console.warn
Oh
console.warn(entities)?
try everything
.. typeof entity
.. entity
typeof entities.length
typeof entities
Maybe entities arent found or entity is undefined
is it bec of entity?.isValid()?
console.warn(typeof entities.length) ill try this
nothing is happening
lemme test something else
nothing? weird
if you do typeof it will always return anything
lol
fixed
good
anyways
it will give u fetal poison, which means if u stay there for a while u will die
nice
Nice
good then we got it
at the end we needed to use beforeEvent
If anything is, just dm me ahgain
sure, ( i will when i find more unnecessary issues, like the 'location' log, xd )
yes...
maybe i know why this error appeared
source: (the exploding entity) we used afterEvent. so it isnt existant at this moment
gtg
Guys how to use
damaingEntity
option in applyDamage
Nvm, I think I know..
Is apply damage like this?
p2.applyDamage(0, {
cause: EntityDamageCause.entityAttack,
damagingEntity: p1
});
Installation for @minecraft/server
Latest API module install:
npm i @minecraft/[email protected]
Beta API module install:
npm i @minecraft/[email protected]
Preview API module install:
npm i @minecraft/[email protected]
Preview Beta API module install:
npm i @minecraft/[email protected]
Installation for @minecraft/server-ui
Latest API module install:
npm i @minecraft/[email protected]
Beta API module install:
npm i @minecraft/[email protected]
Preview API module install:
npm i @minecraft/[email protected]
Preview Beta API module install:
npm i @minecraft/[email protected]
Debug result for [code](#1067535608660107284 message)
Compiler found 2 errors:
[36m<REPL0>.js[0m:[33m1[0m:[33m1[0m - [31merror[0m[30m TS2304: [0mCannot find name 'p2'.
[7m1[0m p2.applyDamage(0, {
[7m [0m [31m~~[0m
``````ansi
[36m<REPL0>.js[0m:[33m3[0m:[33m29[0m - [31merror[0m[30m TS2304: [0mCannot find name 'p1'.
[7m3[0m damagingEntity: p1
[7m [0m [31m ~~[0m
There are no errors from ESLint.
Do not use the compiler in this channel
Okay
"compiler"
there is any bug related to 'minecraft:block_face' state and getState, getAllStates?
How to use applyDamage correctly
Oof
entity.applyDamage(1, { damagingEntity: entity, damagingProjectile: projectile })```
Or
```js
entity.applyDamage(1, { cause: 'entityAttack', damagingEntity: entity })```
Thankssss
How can i place only one of the list?
listBlock[Math.floor(Math.random() * listBlock.length)]
Does that not work?
nop, Did you wanna check the list?
const listBlock = [
block.setPermutation(BlockPermutation.resolve(${block.typeId}, configStates)),
block.setPermutation(BlockPermutation.resolve(${block.typeId}, configStates)),
block.setPermutation(BlockPermutation.resolve(${block.typeId}, configStates)),
block.setPermutation(BlockPermutation.resolve(${block.typeId}, configStates))
]
it places all list... :c
I...do not see any difference between the elements?
wdym?
What are you trying to achieve, exactly?
a expand block event.... 👉 👈
after interact with a item it will placed only one the variables at a time...
Right...but...all those elements are exactly the same no?
in my file, no.... 👀
do you want to see that part?
with using the runCommand and on the list the {}, i didnt had that issue...
So the issue is just the blocks then? Perhaps not referencing the proper blocks?
What is blockNorth?
i just want one for each interact...
block.north(1)
What happems if yoi do listBlocks[0]?
where in the const ?
or the part with math?
Right below the const.
Does someone know why when i try to set dynamic properties in my item it says "Cannot set dynamic properties on stackable items" but this item isn't stackable, it's max _stack_size is 1 and it was working good before.
This is my item json
{
"format_version": "1.20.0",
"minecraft:item": {
"description": {
"identifier": "item",
"category": "Items"
},
"components": {
"minecraft:max_stack_size": 1,
"minecraft:icon" : {
"texture": "item"
}
}
}
}
Are you sure its setting it to the right item?
there? with 0, 1, any number, its the same, it placed all at the same time
there is a post... xD
yeah im 100% sure
cant player.runCommandAsync(`setmaxplayers 5); ?
no closing quotes
setmaxplayers need high permission level i think
This is a outdated template and im trying update it
Is there any way I can disable the ability of the player to look around cause I tried it on the behavior side by adding a movement:basic property with a value of zero but it doesn't work so I wonder if I can achieve that in scripts
simply remove the worldInitialize event
How
;-;
getDynamicProperty(identifier: string): boolean | number | string | Vector3 | undefined
```this should make sense
that's why there's no need to register em,
altho u should create a function if u need defaults
You can set vec3s??
Oh yea vec3s not date object
Sorry my mind is just a bit uhh, foggy rn
Wdym
Is there a way to detect what potion effect a splash potion did when hitting an entity?
get the direction im looking at with getViewdirection(); and draw a straight line in the direction you are looking at? (Straight line is shown with particles)
@subtle cove how to work without worldInitialize
How do I make it with 3-4 arguments?
world.structureManager.place("charge", overworld, x, -60, z);
What are U want
world.structureManager.place('test', dimension, { x:0, y:0, z:0 }, { integrity: 1, animationMode: "Layers", animationSeconds: 1 });
@idle dagger
I need place it at defined x, y and z
Try it again
I changed
@idle dagger
Btw U need to const dimension
const dimension = world.getDimension('overworld');
@idle dagger is it worked?
@idle dagger
@idle dagger tell me if it working
k wait
Ok
You don't need to be so aggressive in getting an answer. Go take a walk
Sure
Can U fix me a little issue
This
The documentation is completely worthless this time around
ty it’s working
I'm not familiar enough with world initialization to know right this second, sorry
What U changed
the commented got removed
yes
Thank U so much
the way the entity gets defined there seems okay
I will test it
U help me a big
@subtle cove
The vector is has problem too
It said vector is not export member at minecraft/server
Wait
The code is not have vector
But the contents log said
Oh
Is the other file
wrong file ;-;
How
Change it to vector3?
import { Vector, ItemStack } from '@minecraft/server'
import { ChestUI, Page, Button, exitUI } from './YBchestUI/ChestUI'
new ChestUI('home')
const home_btn = new Button(0, '回首頁', { icon: 'bed', pageAfterClick: 'home' })
new Page('home')
.newButton(13, '進入', { icon: 'acacia_door', pageAfterClick: 'menu' })
.sameButton({ from: 0, to: 9 }, '背景', { icon: 'camera' })
.sameButton({ from: 17, to: 26 }, '背景', { icon: 'camera' })
new Page('menu',
home_btn,
new Button(11, '傳送至大廳', {
icon: 'ender_pearl', onClickFunc(v) {
exitUI(v.player, true, true)
v.player.teleport(new Vector(0.5, -60, 0.5))
v.player.playSound('mob.endermen.portal')
}
}),
new Button(13, '播放音效', {
icon: 'goat_horn', onClickFunc(v) {
v.player.playSound('mob.enderdragon.growl')
}
}),
new Button(15, '獲得食物', {
icon: 'beef_cooked', onClickFunc(v) {
v.inventory.addItem(new ItemStack('minecraft:cooked_beef', 1))
v.player.playSound('random.orb')
}
})
)
This file
import { ItemStack } from '@minecraft/server'
import { ChestUI, Page, Button, exitUI } from './YBchestUI/ChestUI'
new ChestUI('home')
const home_btn = new Button(0, '回首頁', { icon: 'bed', pageAfterClick: 'home' })
new Page('home')
.newButton(13, '進入', { icon: 'acacia_door', pageAfterClick: 'menu' })
.sameButton({ from: 0, to: 9 }, '背景', { icon: 'camera' })
.sameButton({ from: 17, to: 26 }, '背景', { icon: 'camera' })
new Page('menu',
home_btn,
new Button(11, '傳送至大廳', {
icon: 'ender_pearl', onClickFunc(v) {
exitUI(v.player, true, true)
v.player.teleport({ x: 0.5, y: -60, z: 0.5 })
v.player.playSound('mob.endermen.portal')
}
}),
new Button(13, '播放音效', {
icon: 'goat_horn', onClickFunc(v) {
v.player.playSound('mob.enderdragon.growl')
}
}),
new Button(15, '獲得食物', {
icon: 'beef_cooked', onClickFunc(v) {
v.inventory.addItem(new ItemStack('minecraft:cooked_beef', 1))
v.player.playSound('random.orb')
}
})
)
{x,y,z} is enuf
Uh just that simple
I alr know this method but I'm not ensure before
Vector3 is basically {x,y,z}
Vector2 {x,y}
-# iirc
the old Vector class had methods like add, subtract, distance of two vectors
So the export member is now removed by mojang?
yeah
@subtle cove ar U remove the export in the file just now?
It cause erro
Wait it original not exist
Is it possible to run a command before a player spawns in the world
import { world, system } from "@minecraft/server";
world.afterEvents.entityLoad.subscribe((data) => {
const player = data.source;
})
I just want the player to be the executor in running a command how do I do it
Because the file I give at begin is changed by ai
So after an entity.loads the player will run the command
@subtle cove same problem, but this is DynamicPropertiesDefinition
Just use the method U used just now
Sry for the rehelp
Can someone plss help me on this
I recommend playerSpawn
Wait
I just want to achieve this
Cause after the player spawns I will run a command where the player can't move so he will be forced to watch a cutscene
PlayerSpawn also can do this
import { world, system } from "@minecraft/server";
world.afterEvents.playerSpawn.subscribe(({ player, initialSpawn }) => {
if (initialSpawn) {
}
});
@ruby haven
What does initial spawn checks?
It will just run function when player join
If not joined spawn event it will return
Thank you so much I tried it in the behavior Json of the player but it doesn't work so I had to rely on scripts thank bro
Json is hard to do this type thing I guess
Yeah cause it loads after the player spawns while scripts load before the player spawns
@subtle cove
Or U just tell me how solve thiis
[Scripting][error]-Plugin [api play - 1.0.0] - [Main.js] ran with error: [SyntaxError: exported variable 'setPlayerPage' does not exist]
Debug result for [code](#1067535608660107284 message)
Compiler found 8 errors:
[36mChestUI.js[0m:[33m1[0m:[33m38[0m - [31merror[0m[30m TS2305: [0mModule '"@minecraft/server"' has no exported member 'DynamicPropertiesDefinition'.
[7m1[0m import { world, system, EntityTypes, DynamicPropertiesDefinition, Player, Vector } from '@minecraft/server';
[7m [0m [31m ~~~~~~~~~~~~~~~~~~~~~~~~~~~[0m
``````ansi
[36mChestUI.js[0m:[33m1[0m:[33m75[0m - [31merror[0m[30m TS2724: [0m'"@minecraft/server"' has no exported member named 'Vector'. Did you mean 'Vector2'?
[7m1[0m import { world, system, EntityTypes, DynamicPropertiesDefinition, Player, Vector } from '@minecraft/server';
[7m [0m [31m ~~~~~~[0m
``````ansi
[36mChestUI.js[0m:[33m3[0m:[33m74[0m - [31merror[0m[30m TS2792: [0mCannot find module './exports'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?
[7m3[0m import { Entrance, Page, Button, UIerror, checkTypes, ICON, ICONR } from './exports';
[7m [0m [31m ~~~~~~~~~~~[0m
``````ansi
[36mChestUI.js[0m:[33m154[0m:[33m11[0m - [31merror[0m[30m TS2339: [0mProperty 'propertyRegistry' does not exist on type 'WorldInitializeAfterEvent'.
[7m154[0m e.propertyRegistry.registerEntityTypeDynamicProperties(player_def, EntityTypes.get('minecraft:player'));
[7m [0m [31m ~~~~~~~~~~~~~~~~[0m
``````ansi
[36mChestUI.js[0m:[33m157[0m:[33m11[0m - [31merror[0m[30m TS2339: [0mProperty 'propertyRegistry' does not exist on type 'WorldInitializeAfterEvent'.
[7m157[0m e.propertyRegistry.registerEntityTypeDynamicProperties(entity_def, EntityTypes.get('yb:inventory'));
[7m [0m [31m ~~~~~~~~~~~~~~~~[0m
``````ansi
[36mChestUI.js[0m:[33m184[0m:[33m24[0m - [31merror[0m[30m TS2339: [0mProperty 'itemDefinitionEvent' does not exist on type 'WorldBeforeEvents'.
[7m184[0m world.beforeEvents.itemDefinitionEvent.subscribe((e) => {
[7m [0m [31m ~~~~~~~~~~~~~~~~~~~[0m
``````ansi
[36mChestUI.js[0m:[33m206[0m:[33m29[0m - [31merror[0m[30m TS2339: [0mProperty 'selectedSlot' does not exist on type 'Player'.
[7m206[0m const slot = player.selectedSlot;
[7m [0m [31m ~~~~~~~~~~~~[0m
``````ansi
[36mChestUI.js[0m:[33m221[0m:[33m38[0m - [31merror[0m[30m TS2345: [0mArgument of type 'string | number | boolean | Vector3' is not assignable to parameter of type 'string'.
Type 'number' is not assignable to type 'string'.
[7m221[0m var player = world.getEntity(entity.getDynamicProperty('ownerID'));
[7m [0m [31m ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~[0m
ESLint results:
ChestUI.js
159:9 warning The /tag command can be fully replaced with the Entity.addTag api in the @minecraft/server module. See https://learn.microsoft.com/en-us/minecraft/creator/scriptapi/minecraft/server/entity#addtag for more information. minecraft-linting/avoid-unnecessary-command
160:9 warning The /tag command can be fully replaced with the Entity.addTag api in the @minecraft/server module. See https://learn.microsoft.com/en-us/minecraft/creator/scriptapi/minecraft/server/entity#addtag for more information. minecraft-linting/avoid-unnecessary-command
This not fix yet
It's so hard to fix
well you don't need DynamicPropertiesDefinition, it's outdated.
Vector is also an outdated class, so remove it
whats the itemDefinitionEvent for?
yb:seek?
That is custom item
Wait
Lemme see
Bruh
That things
Is use for
See the vaild Icon(item at chest gui
i cant find any item event to use for that
this an item.typeId?
Yea
k
I found in items folder
I have try to fix it by myself
But it always goes error
Especially the export issues
I have no idea what caused it.
But the issue maybe is did by me
@subtle cove did U could fix the code?
[perhaps...](#1307339701341917204 message)
Thxxxx
Installation for @minecraft/server
Latest API module install:
npm i @minecraft/[email protected]
Beta API module install:
npm i @minecraft/[email protected]
Preview API module install:
npm i @minecraft/[email protected]
Preview Beta API module install:
npm i @minecraft/[email protected]
can i remove variables from a const after i already set up?
like this:
const listVariables = [Varible1,Varible2,Varible3,Varible4]
if (//a simple check filter//) {
listVariables - Variable2
}
question...
i need to use index, indexOf(#V), and splice?
nevermind i figure it out...
i need all 3
Xd
correction....
only the last one its necessary
is it possible to make custom slash commands yet
sad
When the beforeEvent version of chatSend comes, you then can ask that question, it may happen, it may not.
It's not stable yet which means mojang has got plans to change it in the feature.
i doubt it would work that way
for registering a command
I think that slash commands will be made more like custom components
^
there would be no way to display it in the list of command suggestions if they were to be checked through a chat event
I didn't say anything about commands, all I said is the event is in beta which means they have plans to change it in the feature.
yes indeed
but u were replying to my inquiry about custom slash commands so i mean i figured
Yes I was replying telling you that the current state of the event is unfinished.
Then what does the event have to do with it?
anyone have a good way of detecting inventory slot interaction like clicking on a slot with an item
i need to be able to read the item stack of the slot its moved to as well
Idk I heard some stuff from like 2 years ago yapping about the event getting an upgrade with custom commands too, i don't remember the member who said this but yea
i thought about comparing the player's inventory to an old inventory from 1-2 ticks ago but it seems like it would be very bad performance wise
You mean detecting when a player moves an item?
yes
idk if you've seen what i mean but for example on a lot of java servers you can apply things like enchanted books to items by clicking with them on the item you want to enchant
Ye
ϟ ViperMC | FULL NETWORK SERVER | Infernal / Kits / Practice EU/US & Hub!
➛ Paypal Price: $3.20 USD
➛ BUY FROM: https://hsdevs.tebex.io/package/4819829
➛ Website: http://hsdevs.xyz
(HSDevs | Official New Website).
➛ Discord: http://discord.hsdevs.xyz
(HSDevs | Official Discord Server).
❃ Hub Setup Information:
- ViperMC Builds ...
watch it from the timestamp i set
Possible, but it's sloppy
how
i need any reliable way that wont be too bad performance wise
Check each item change in inventory :D
but how
is the only way the way i suggested?
save old inventory from last tick and compare?
Optimize it
bc i feel like with 10-11 players it will become very bad performance wise
Bettttr
Then just check when necessary
and when should it be necessary
how do i detect it being necessary if they can click on the item with an enchanted book at pretty much any time
You just gave me motivation XX With Duration Of 293828282s
If the player's speed = 0, he does not move, which means the inventory can be opened
smart
There's a Cursor slot component, though, it's irrelevant for mobiles
crash server method = spam swap items in your inventory with 10 alt accounts
And for half an hour I puzzled over why this thing doesn’t work?!
preview maybe
It says on doc :)
I only noticed later
"Not used on touch controls"
That's why you double check :)
Ima try to make some script, yall improve it
But this does not prevent mojangs from using this function on all devices
In our case, we need to check the swap of equipment and books
Here's a better idea: Instead of doing the "drag and drop" mechanic, why not just "use and select"?
sorry what
give an example of "use and select"
Right-click the enchant book (on the Hotbar)
Scroll to other slots
Then right-click your equipment (on the Hotbar)
or
Enchant book on the offhand.
Equipment on the mainhand.
Right-click to apply "enchantment"
you cant put books on offhand
Custom items are?
You can make a custom Item look like a book without a resource pack
scaling issues
no
and positioning
I wanted to write this code, but I got lazy
if the user has a custom pack enabled
and uses like 32x or 64x for book
it will look gigantic
and the orientation when held is also off
wdym scaling issue, I've doing it and got no issue
import { world, system } from "@minecraft/server";
let iS = {}; // Inventorys
function compareItems(i1, i2) { // Item 1, Item 2
let aC = ['lore', 'canPlaceOn', 'canDestroy']; // Array Components
for (let k in aC) {
if (i1[k].length !== i2[k].length) return false;
if (i1[k].filter((v, _) => i1[k][_] == i2[k][_]).length !== i1[k].length) return false;
}
let cC = ['typeId', 'amount', 'lockMode', 'keepOnDeath']; // Constant Components (Like Not Array, I Should Change the Name...)
for (let c of cC) {
if (i1[c] !== i2[c]) return false;
}
return true;
}
function sI(p) { // Save Inv, Smaller Names For Tiny Micro Optimizations
let iC = p.getComponent('inventory').container;
for (let i = 0; i < iC.size; i++) {
let I = iC.getItem(i);
if (!iC) continue;
iS[p.id][i] = I;
}
}
function cI(p) { // Compare Inv, Smaller Names For Tiny Micro Optimizations
let iC = p.getComponent('inventory').container;
for (let i = 0; i < iC.size; i++) {
let I = iC.getItem(i);
if (compareItems(I, iS[p.id][i])) continue;
// Code For Being Different ItemStack
}
}
system.runInterval(() => {
// idk
}, 3);
Some Basic Code, Y'all Can Go On Right?
Yeah you can see on the comments, "Smaller Names For Tiny Micro Optimizations"
Such clear code
Ain't clear
i doubt it does
apart from file size
It does optimize but "Tiny Micro Optimizations" Very very little, basically unnoticeable..................
Probably
For small optimizations it is better to use loops in the format (let i =0; i < 123...)
They are faster, I checked
Yeah, just compareItems I didn't do that, cuz it was just a yeeted function I just had lying around in my blissSMP addon
I never actually used it so ye
I cared less about it (at that time)
Very short variable names like that only make it difficult to read and understand what is going on and what they represent. Especially when you return back to the code at a later date. There really isn't any noticeable benefits for doing that with the JavaScript engine these days. Their lengths have no significant impact on performance. Bottlenecks are typically related to algorithms, data structures, or I/O operations, not variable name length.
Cool to know.
Welp at least my addon is unreadable, so I just obfuscate it and even if one does deobfuscate it they'll have absolutely no idea what the code means :)
Cool perk from doing dumb shii ig
Lol
Oh Gemini can reverse engineer my voodoo rituals that I did to my code..
Nah ima just troll my friends with this
Gega has been typing for a long while now 👀
Lol
Nahhhhhh
@random flint you did not just type all that time and stop lol
Bruh you tempted me this long? Nvm.
I'm invested haha
Same fr
In my theory, Custom enchantments "drag and drop" mainly check for three states on each slot:
- Is an Empty Slot
- Is an Enchant Book
- Else (Equipment, Unenchantable)
So basically you only want to check for slots that have the enchanted book first. Then, if the slot becomes empty, it assumes the player has picked it up.
Check each tick again, if the player decides to drop the book, or place it on another container.
If the player decides to just not enchant anything, their emptySlotsCount would increase since they're putting back the enchanted book on an empty slot.
Otherwise, we kept checking the filled slots if they suddenly changed into a book.
This process probably took a soft copy of what each filled slot has to compare it.
If it's found, then stop the check, and began "enchanting" or smt, idk...
I was expecting it to be way longer than that 😂😂😂😂
No ones want to read long text unfortunately
Bruh all that long just for this little text?
Yea, people are impatient these days lol
If it was me.... Nahhhhh I wanna wait a long time, but for something worth the wait.
Cleaning the text, rephrase some to simplify it. I'm on a phone. It's 3 AM here
Lol
Nah bro you ain't an AI, you don't need to 100% perfect while typing online
And go get some sleep
It's to get the point across ig
Sweet Dreams. Sleep well.
Nah, gega is AI... I can just call him and ask to generate script and he'll be done after 2 seconds.
any way to get the world current setworldspawn coords?
is there an event for when a player fires a projectile
No, and it cannot be. Because "the player launches a projectile" is quite abstract
But you can use entitySpawn and check what you need
is there a way to reliably achieve this
i've tried checking for the nearest player w that but it doesnt work too well
sometimes it works sometimes it doesnt
projectileHitEntity and get the owner?
☝️
this would return the player when they get hit?
Huuuh?
but the thing is i also need to know what itemstack they sent the projectile out of
when another ntity gets hit by the projectile that causes this event to fire, it has a property that tells you who threw the particle? is that what u mean
The event will return the entity who fired the projectile and there is a method you can call in the event which will return the entity that was hit.
The hell you mean particle?
projectile
stop acting dumb you knew exactly what i meant bro
🤦
Bump
thank you, will check it out soon
// Script by WavePlayz
import { world } from "@minecraft/server";
// Subscribe to the `projectileHitEntity` event, which is triggered when a projectile hits an entity
world.afterEvents.projectileHitEntity.subscribe((eventData) => {
// Destructure the eventData to get the source entity (the one that shot the projectile)
const { source } = eventData;
// Get the entity that was hit by the projectile
const hitEntity = eventData.getEntityHit()?.entity;
// Check if the hitEntity is valid
if (hitEntity) {
// Extract the x, y, and z coordinates from the hitEntity's location
const { x, y, z } = hitEntity.location;
// Create a string representing the coordinates in the format "x, y, z"
const coordinates = `${x}, ${y}, ${z}`;
// Construct a message indicating which player hit which entity and where
const message = `${source.name} hit the entity at location ${coordinates}`;
// Send the message to all players in the world
world.sendMessage(message);
// Immediately kill the hit entity
hitEntity.kill();
}
});```
world.afterEvents.entitySpawn.subscribe(data => {
let entity = data.entity
system.runTimeout(() => {
if (!entity.isValid()) return
let comp = entity.getComponent("minecraft:projectile")
if (comp && comp.owner?.typeId == "minecraft:player") {
playerShot(comp.owner, entity)
}
})
})
function playerShot(player, projectile) {
}
thank you
When the shell appeared, he needed
Documentation for @minecraft/server
Not my fault 🤣... The docs exist too
okay but why point it out when you knew that i meant projectile and not particle
there's no need to question it if you actually did not get confused by it
mistakes happen, i thought about particles so my brain decided to type out particle instead of projectile
Do you need shot detection or hit detection?
Not worth it to fight, small things just forget it
sorta both
i need to get the info of the item stack the projectile was thrown out of
but i only need that info when an entity is hit by that very projectile
Here the playerShot function is triggered when the player shoots
thanks
seems like it would work im just concerned about them swapping slots after shooting
Save it to a variable and then use it in the projectileHitEntity event
will do thx
Kinda need small help, i want to create a bounding box in two locations, imagine the structure block bounding box one... I store the location in point1 and point2
My smol brain kinda forget how to do this..
-# excuse cause I'm tired asf
Sounds like you already know what to do. Unless you need help with something specific?
guys who know how remove shade of locked item
#1067869374410657962
can some one throw me docs or can tell me...
how can i use:
return;
i use it to avoid things, like a cancel.event
buts some time i saw some files likes:
return; something;
how does that work?
please...
function example1() {
const a = 1;
const b = 2;
return a + b;
}
function example2() {
const a = 1;
const b = 2;
if (a + b == 12) {
return a + b;
} else {
return;
}
}
console.log(example1()) // 3
console.log(example2()) // undefined```
bumping this
it only can be done with const? And almost anything can be const, right?
You can also use return 'text', I'm not very good at explaining
any way thank you was hoping it maybe be like a 'callback checkpoint' or something like that
A constant just means you can't reassign the value later on in the script
guys can you help me make a cooldown system for my tool. I'm trying to use this code but it not working.
const CooldownComponent = {
onHitEntity({ attackingEntity, source }) {
// Ensure the source is a player
if (!(source instanceof Player)) return;
// Get the equippable component from the player
const equippable = source.getComponent("minecraft:equippable");
if (!equippable) return;
// Get the mainhand item
const mainhand = equippable.getEquipmentSlot(EquipmentSlot.Mainhand);
if (!mainhand.hasItem()) return;
// Retrieve the item
const item = mainhand.getItem();
const itemTags = item.getTags(); // Retrieve all tags of the item
// Check tags and apply corresponding weakness effect
if (itemTags.includes("minecraft:is_hoe")) {
attackingEntity.addEffect("weakness", 12, {
amplifier: 1,
showParticles: false
});
} else if (itemTags.includes("minecraft:is_pickaxe")) {
attackingEntity.addEffect("weakness", 15, {
amplifier: 1,
showParticles: false
});
} else if (itemTags.includes("minecraft:is_sword")) {
attackingEntity.addEffect("weakness", 15, {
amplifier: 1,
showParticles: false
});
} else if (itemTags.includes("minecraft:is_axe")) {
attackingEntity.addEffect("weakness", 24, {
amplifier: 1,
showParticles: false
});
} else if (itemTags.includes("minecraft:is_shovel")) {
attackingEntity.addEffect("weakness", 15, {
amplifier: 1,
showParticles: false
});
}
}
};
world.beforeEvents.worldInitialize.subscribe(({ itemComponentRegistry }) => {
itemComponentRegistry.registerCustomComponent("hollow:cooldown", CooldownComponent);
});
Why use const if you can just use function?
-# I know it works the same if you say it but just genuinely curious
function CooldownComponent = {
// code //
}
world.beforeEvents.worldInitialize.subscribe(({ itemComponentRegistry }) => {
itemComponentRegistry.registerCustomComponent('hollow:cooldown', CooldownComponent);
});```
Whoaaaa did you just define a function, that isn't a prototype function by ```js
function funcName = {
};
??
What is this voodoo black magic????
-# Burn the Witch!!
import { world, system } from "@minecraft/server";
world.afterEvents.playerSpawn.subscribe(({ player, initialSpawn }) => {
if (initialSpawn) {
player.runCommand("function movenot");
player.runCommand("scoreboard objectives add Trauma dummy");
player.runCommand("scoreboard players add @s Trauma 10");
player.runCommand("scoreboard objectives add Days dummy");
player.runCommand("scoreboard players add @s Days 30");
}
});
As you can see in the script there Is a Days dummy and I want to make a system where the moment the value of the scoreboard dummy named Days becomes 0 I want to run a command the player is the one executing it
Do U need help
I'm not fully understand
Sry
What do U trying to do
Do you know scoreboards?
You see I added a Days dummy to the player and a gave it a value of 30 to represent the time before the player dies so everytime a day passes the 30 is being subtracted by 1 which I already made the problem is I don't know how to detect when the the Days dummy value becomes 0 so I can run a command
Oh
U can just use scoreboard class
sadly I never learned at that
But I will try
if (world.scoreboard.getObjective("Days").getScore(player) <= 0) {
// code
}
Oh
U knew it?
No, I’m just writing what I came up with.
|| It's a joke ||
I will try it
Thanks I'll try this
Oh no hahaha

My eyes 😵💫
I already told him how to do it
Okay thanks bro if you need help other than scripting you can ask help for me
addScore() like this?
I think I must goto check docs
For what
Dummy or player
He needs to check whether the value has reached 0
Nvm
I'm just learn that
I think if we need deduct score can do like this
addScore(dummy, -1)?
@ruby haven wait a moment if U can't do it yourself I will help u
Yeah I can't
Please wait for a bit moment. I am eating. Sorry.
Wait I already finished the part where everytime a day passes the score is being deducted the only problem is
To detect when the score becomes 0
.
But U using run command
Wait serty how do I add it in this code import { world, system } from "@minecraft/server";
world.afterEvents.playerSpawn.subscribe(({ player, initialSpawn }) => {
if (initialSpawn) {
player.runCommand("function movenot");
player.runCommand("scoreboard objectives add Trauma dummy");
player.runCommand("scoreboard players add @s Trauma 10");
player.runCommand("scoreboard objectives add Days dummy");
player.runCommand("scoreboard players add @s Days 30");
}
});
I will help U later
system.runInterval(() => {
for (let player of world.getAllPlayers()) {
if (world.scoreboard.getObjective("Days").getScore(player) <= 0) {
player.sendMessage("Time over")
}
}
})
Yea
Okay I'll try this
So I'm just need change run command to scoreboard class for U @ruby haven
For what
If that's how it works for him. Why change?
AND? Using commands is not good when you are using API methods and suddenly you need a command. There is basically nothing like that here, because it only uses the commands
Yea so I will change it
I tried it, it works but the command is lopping how do I make it so that it will only run one time
import { world, system } from "@minecraft/server";
world.afterEvents.playerSpawn.subscribe(({ player, initialSpawn }) => {
if (initialSpawn) {
player.runCommand("function movenot");
player.runCommand("scoreboard objectives add Trauma dummy");
player.runCommand("scoreboard players add @s Trauma 10");
player.runCommand("scoreboard objectives add Days dummy");
player.runCommand("scoreboard players add @s Days 30");
};
system.runInterval(() => {
for (let player of world.getAllPlayers()) {
if (world.scoreboard.getObjective("Days").getScore(player) <= 0) {
player.sendMessage("Time over")
}
}
})
});
This is the current progress only problem is it loops
world.afterEvents.playerSpawn.subscribe(data => {
let score = world.scoreboard.getObjective("Days") || world.scoreboard.addObjective("Days")
let player = data.player
if (score.getScore(player) == undefined) {
score.setScore(player, 30)
}
})
No that part doesn't loop the Time is over loops
Well, just do what you need and return the value to 30 days or reset it
system.runInterval(() => {
for (let player of world.getAllPlayers()) {
if (world.scoreboard.getObjective("Days").getScore(player) <= 0) {
player.sendMessage("Time over")
world.scoreboard.getObjective("Days").removeParticipant(player)
}
}
})
You see the idea is when the Days become 0 I will load a structure in the player and it will become a boss fight so really want the command to run one time only
.
how to detect if player select an item in inventory?
function getSelected(player) { // ItemStack || undefined
return player.getComponent("equippable").getEquipment("Mainhand")
}
import { world, system, Scoreboard, ScoreboardObjective } from "@minecraft/server";
world.afterEvents.playerSpawn.subscribe(({ player, initialSpawn }) => {
if (initialSpawn) {
player.runCommand("function movenot");
world.scoreboard.addObjective('Trauma', null);
world.scoreboard.addObjective('Days', null);
world.scoreboard.addScore(player, 'Trauma', 10);
world.scoreboard.addScore(player, 'Days', 30);
}
});
system.runInterval(() => {
for (let player of world.getAllPlayers()) {
if (world.scoreboard.getObjective("Days").getScore(player) <= 0) {
player.sendMessage("Time over")
}
}
})
I mean like this
I wrote everything to him a long time ago... Correct runInterval to a new one
@quick shoal
Well, not on mobile devices
sad
If you are on a computer then you can
Ok
That can be achieved in the player.json file behavior side
import { world, system, Scoreboard, ScoreboardObjective } from "@minecraft/server";
world.afterEvents.playerSpawn.subscribe(({ player, initialSpawn }) => {
if (initialSpawn) {
player.runCommand("function movenot");
world.scoreboard.addObjective('Trauma', null);
world.scoreboard.addObjective('Days', null);
world.scoreboard.addScore(player, 'Trauma', 10);
world.scoreboard.addScore(player, 'Days', 30);
}
});
system.runInterval(() => {
for (let player of world.getAllPlayers()) {
if (world.scoreboard.getObjective("Days").getScore(player) <= 0) {
player.sendMessage("Time over")
world.scoreboard.getObjective("Days").removeParticipant(player)
}
}
})
@ruby haven
Use ,this full
Example environment sensor component there is a filter their where you can check if the player is holding a specific item
wrong
What's wrong
actually, you can detect the items in the slot using script
Can I have a link to the documentation?
what's wrong
The fact is that you took methods out of nowhere
Bro docs
I follow documents
world.scoreboard.getObjective("Days").addScore(player, 30)
Check the filters side
never mind, maybe I really need to learn scoreboard class as seriously
There is no such thing
Ok
Which docs are you using
Try this https://jaylydev.github.io/scriptapi-docs/latest/classes/_minecraft_server_1_15_0.Scoreboard.html
Okey
You can't change the value right away, you need to get the scoreboardObjective class first
What is the point of other documentation?
Thanks for teaching scoreboard class
import { world, system, Scoreboard, ScoreboardObjective } from "@minecraft/server";
world.afterEvents.playerSpawn.subscribe(({ player, initialSpawn }) => {
if (initialSpawn) {
player.runCommand("function movenot");
world.scoreboard.addObjective('Trauma', null);
world.scoreboard.addObjective('Days', null);
world.scoreboard.getObjective('Trauma').addScore(player, 10);
world.scoreboard.getObjective('Days').addScore(player, 30);
}
});
system.runInterval(() => {
for (let player of world.getAllPlayers()) {
if (world.scoreboard.getObjective("Days").getScore(player) <= 0) {
player.sendMessage("Time over")
world.scoreboard.getObjective("Days").removeParticipant(player)
}
}
})
@ruby haven fixed
What filter?
We have our own code examples on some APIs that microsoft docs may not have yet
But your document will look less informative?
@ruby haven try it
|| Wait, he chooses from the pile of codes that you gave him ||
You might want to click on the file names on the examples
Already works now
This is latest
Which U using
Oh..thx
Go to Filters cause the information is categorized like
Ai goal components
Components
Filters
etc.
what is the name of the filter?
Give me a scenario that I can apply it
?
has_equipment part
Not,
that's not it.
It checks if there is a specific I item either in your inventory, armor slot or hand equiped
Only now I need to check whether the item is selected in the inventory
.
When you select item to inventory doesn't that go to your hands?
No
Oh well I guess it can only be achieved through scripts then
That's the thing: it's possible, but only on a computer
Thanks for the help
Thanks also
Well, depends
I got problems with Naming classes/variables e.t.c and structuriing problems, i dunno how i can fix it
Real hard and pain is phone coder..
hah, yes
I'm not sure it's hard
Guys, I've got a problem where I'm starting a job in world after initialise and I'm getting an error in that job telling me that I'm trying to access a block that's in a chunk that's not initialised and ticking. How do I check for that and how should I start a job after the world is properly loaded?
You can't access blocks that are not loaded. You need a ticking area to keep it loaded or a fake player to stay loaded.
Otherwise, don't attempt to access the block(s) unless you can do so through another player, or entity.
I'm doing this on world initialise
My point still stands.
Yeah, so how do I determine whether the area is a "ticking" one then?
Don't have to. It would naturally be loaded and so the object of the block would return with all of its properties and methods.
U can use entitySpawn like pings
And it seems there are no entities loaded at the time, either
If the block returns empty (undefined) then you keep checking until it returns. Have to handle it with conditions.
Its not a block that its complaining about, its the location for a spawn
Entities, such as mobs, won't be loaded. They go into a frozen state when players are not in the area, and I believe they are despawned after the fact when a time has gone by, but either way, you can't touch them.
So, how to I start a job that will actually be started after the world is properly initialised?
Yo does any server plugins exist for mcpe
The world can be loaded all day but you still will not be able to access the block or location in question unless you have a player or fake player loaded in. Or you have created a ticking area to keep the chunk loaded.
I am trying to re-establish internal state about entities and there aren't any loaded after world initialise
Even though they are persistent
Who or what is persistent?
I'd use entitySpawn event
That would be the best option.
I guess I will have to have some flag to determine whether a player is logged in
entity.isValid()
Use the entitySpawn playerSpawn event for that and check the property initialSpawn to see if it's their first time spawning in the server
They aren't loaded for me to do this
I'll just set a flag whenver the spawn event is fired and wait on that as a latch. That way, there is some player spawned before I try to access the entities
That method works regardless if the entity instance is loaded or not.
Block instance too, also works.
It's just a test if the thing is still accessible by the script
playerSpawn
Well that didn't seem to work, either
Correct, got my tongue twisted up lol.
Even releasing a latch by use of playerSpawn after event didn't work, btw
But I have got a work-around yeah...
I don't know if it will stand up in the real world
is there a way to make name tags display in a different color for different clients
i want people in the same faction to see the names of their team members in green n enemies in yellow
not just in script api if theres any other way lmk
no
-# visually I'd say
sad
any way to make a player fully invisible w/o using size component ? i mean hiding the armor fire n everything
Bro i want the ids
He told you how to get it
I just want a site where i can see them
