#Script API General
1 messages · Page 130 of 1
hm
holdon
i got to mount my ssd
to have access to the files
alright
ill try to return false when the player gets knockback, so getting hit or being launched by an explosion will not count as a jump
i forgot where my files are '-'
xd
found it
i was searching it on .local but it was on .var
'-'
world.afterEvents.playerButtonInput.subscribe((ev) => {
for (const component of components)
if (component.affected_items.has(current))
if (
ev.button === InputButton.Jump &&
ev.newButtonState === ButtonState.Pressed
)
component.onJump?.(ev.player);
else if (ev.button === InputButton.Sneak) {
if (ev.newButtonState === ButtonState.Pressed)
component.onSneak?.(ev.player);
else component.onStopSneak?.(ev.player);
}
});
if (!player.isFalling && !player.isFlying) {
const velocity = player.getVelocity();
const len = this.velocity_amplifier >> 1;
velocity.x *= len;
velocity.y ^= velocity.y;
velocity.z *= len;
ev.applyImpulse(velocity);
}
currently, i did some major improvements to it, fixing most of those issues
did u just copied it from ur script or something? i cant test it bec its missing alot of stuff
now it cancels the jump detection when u get damage and ur not onGround, like i just added a new Map() that used to allow the jump to be counted
now breeze-balls doesnt count as jump, any explosion that damages u and knocks u into the air doesnt count as jump, including being damaged and get a tiny bit of knockback, thats also doesnt count as a jump
BUT, minor knockbacks that doesnt damage u but throws u into the air by EXACTLY a block, will count as a jump.
yeah
just from my script
it ain't made to be copy pasted
i mean, i didnt write it here with this purpose
i also made it count jump boost 0-1, so anything higher will not count as a jump (jump boost 1 is the maximum u can get in pure survival)
@dusky flicker as u can see, its pretty situational, like not something that happens all time, right?
i mean, what else? is there anything else that makes u go upwards against ur will?
i did some reseach, these things can still count as a jump:
riptide trident
fishing rod (only happens on multiplayer when one of the players decide to fish u for whatever reason)
blocking a ravager with a sheild to trigger its knockback roar and blocking that with ur shield.
landing on slime - fixed
ill do some more testings ig
ill give queries a shot, they might work better
nope, there are no hope, there might be some hope, ill give it a shot tho.
there is some hope, ill complete it tomorrow, i have tweaked the system to hard limit the jump detection
Any idea why this isn’t workin. And a work around it ```javascript
import { world } from "@minecraft/server";
world.beforeEvents.chatSend.subscribe(async (eventData) => {
if(eventData.message.includes("")) {
eventData.cancel = true
eventData.sender.runCommand("kick @s")
}
});
Which part isn’t working? The kick?
Already fixed lol
sorry my guy, i did sleep yesterday
i think the ender dragon does
blud sleep in the big 2026 💔 🥀
-# jk
it will damage u, the damage has a strong knockback, so my system will not count that
i don't wanna have insomnia ❤️💐
so that will only count for "jumps" that dont cause damage?
if so i don't think i can think in anything else
for me, i do think so,
u can use a shield to block the damage
and get knockback,
that kind of knockback counts as a jump,
and fishing rods can still pull u and counts as a jump
gotta play some isaac,
i really think as you got it working, even though nlt perfect, you should keep working in other things on the addon
and then when you have more stuff completed
improve the jump system
why does this function crash my game when ran? It used to not, but recently it just started for some reason
@distant tulip show me ur button input method so i can test it out and see if it works better or worse,
It won't work with auto jump as Serty said
fuck auto jump, i just want to test it out lol
Well send it in a bit
@untold magnet
import { world, system, InputButton, ButtonState } from "@minecraft/server";
const jumpIntervals = new WeakMap();
world.afterEvents.playerButtonInput.subscribe(({ player, button, newButtonState }) => {
if (button !== InputButton.Jump) return;
if (newButtonState === ButtonState.Pressed) {
if (jumpIntervals.has(player)) return;
const handle = system.runInterval(() => {
if (!player.isValid || !player.isJumping) return;
console.log("Player is jumping");
}, 1);
jumpIntervals.set(player, handle);
}
if (newButtonState === ButtonState.Released) {
const handle = jumpIntervals.get(player);
if (!handle) return;
system.clearRun(handle);
jumpIntervals.delete(player);
}
});
does it return once per jump? bec currently its spamming the log,
it does not
add a delay to the interval
there is no other way afaik
challenge accepted, ill modify it.
eh... good luck
btw your original version have a bug
return in a loop break the loop, so not multiplayer friendly
use continue
done
import {world, system, InputButton, ButtonState} from '@minecraft/server';
const jumpIntervals = new WeakMap();
const jumpCache = new Map();
world.afterEvents.playerButtonInput.subscribe(({player, button, newButtonState}) => {
if (button !== InputButton.Jump) return;
if (newButtonState === ButtonState.Pressed) {
const handle = system.runInterval(() => {
const vY = player?.getVelocity().y;
const hasJumped = jumpCache.get(player?.id) ?? 0;
const eBlock = player?.getBlockStandingOn();
if ((player?.isOnGround || player?.isInWater) && hasJumped === 1 && (eBlock?.typeId !== 'minecraft:slime' || (eBlock?.typeId === 'minecraft:slime' && vY === 0))) jumpCache.set(player?.id, 0);
if ((!player?.isOnGround && !player?.isInWater && !player?.isClimbing) && hasJumped === 0 && vY > 0) {
jumpCache.set(player?.id, 1);
world.sendMessage('jump');
};
}, 1);
jumpIntervals.set(player, handle)
};
if (newButtonState === ButtonState.Released) {const handle = jumpIntervals.get(player); if (!handle) return; system.clearRun(handle); jumpIntervals.delete(player)};
});;```
it wasnt registering the first jump
like it was only detecting when u jump twice, not once,
so i fixed that,
hold on,,
i think i got it working
final results:
import {world, system, InputButton, ButtonState} from '@minecraft/server';
export const ePlayers = new Set();
const jumpIntervals = new WeakMap();
const jumpCache = new Map();
world.afterEvents.playerJoin.subscribe(({playerId}) => {ePlayers.add(playerId)});
world.afterEvents.playerLeave.subscribe(({playerId}) => {ePlayers.delete(playerId); jumpCache.delete(playerId)});
system.runInterval(async () => {
for (const ID of ePlayers) {const player = world.getEntity(ID);
if (!player?.isValid) return;
const hasJumped = jumpCache.get(player?.id) ?? 0;
const eBlock = player?.getBlockStandingOn();
if ((player?.isOnGround || player?.isInWater) && hasJumped === 1 && (eBlock?.typeId !== 'minecraft:slime' || (eBlock?.typeId === 'minecraft:slime' && vY === 0))) jumpCache.set(player?.id, 0);
};
});;
world.afterEvents.playerButtonInput.subscribe(({player, button, newButtonState}) => {
if (button !== InputButton.Jump) return;
if (newButtonState === ButtonState.Pressed) {
{const hasJumped = jumpCache.get(player?.id) ?? 0; const vY = player?.getVelocity().y; if ((!player?.isInWater && !player?.isClimbing) && hasJumped === 0 && vY > 0 && vY !== 0.15000152587890625); world.sendMessage('First Jump'); jumpCache.set(player?.id, 1)};
const handle = system.runInterval(() => {
const vY = player?.getVelocity().y;
const hasJumped = jumpCache.get(player?.id) ?? 0;
if ((!player?.isOnGround && !player?.isInWater && !player?.isClimbing) && hasJumped === 0 && vY > 0) {
jumpCache.set(player?.id, 1);
world.sendMessage('Jump')
};
});
jumpIntervals.set(player, handle);
};
if (newButtonState === ButtonState.Released) {const handle = jumpIntervals.get(player); if (!handle) return; system.clearRun(handle); jumpIntervals.delete(player)};
});;```
does not detect auto jump,
lets be real here, who tf uses auto jump in the big 2026?
this has one downside, the jumping may not be detected if the vY was too low and the TPS was too low
it will detect some too low jumps (vY > 0 && vY < 0.02) in low TPS,
Me, carpal tunnel
Mobile users
{
typeId: "goat:steve_kit",
onUse: (e, world, player, item) => {
const steve = player.dimension.spawnEntity("goat:steve", player.location);
const tameable = steve.getComponent("minecraft:tameable");
tameable.tame(player);
steve.nameTag = "Steve"
}
},
This was working before but for some reason it's not working anymore, did they changed something?
I used it to spawn a custom entity pre tamed to yourself with a name tag applied
Does anyone know to detect a left click or tap on mobile?
entityHitBlock works, but it's meh for mobile users. 🫠
It doesnt work on mobile? Or what does meh mean?
@distant tulip update-
this tiny system works just fine, even autojump is working with it:
import {world, system} from '@minecraft/server';
const jumpCache = new Map();
system.runInterval(() => {
for (const ID of world.getAllPlayers()) {
if (!player?.isValid) continue;
const hasJumped = jumpCache.get(player?.id) ?? 0;
const eBlock = player?.getBlockStandingOn();
if ((player?.isOnGround || player?.isInWater) && hasJumped === 1 && (eBlock?.typeId !== 'minecraft:slime' || (eBlock?.typeId === 'minecraft:slime' && vY === 0))) jumpCache.set(player?.id, 0);
if (player?.isJumping && (!player?.isOnGround && !player?.isInWater && !player?.isClimbing) && hasJumped === 0 && vY > 0 && (vY > 0.15 && vY < 0.155)) {
jumpCache.set(player?.id, 1);
world.sendMessage('Jump')
};
};
});;```
vY !== 0.15000152587890625 is used to stop detecting scaffoldings
Please don't do equality comparisons with floats like this, this is making me cry
Do an absolute error check, like if it is ±0.01 from 0.15
or just use player.isJumping
Asking again since my last attempt works well but not perfect.
Is there a reliable way to detect player mining? My attempt utilised hitBlock, PlayerSwing and playebreak which works well. However, the issue arise when youre continuously mining thus not griggering the hitBlock.
how exactly? player?.isJumping is returning true while climbing scaffoldings, so i thought of using the scaffolding vertical velocity to stop it from returning true.
check if vy > 0.15 && vy < 0.155
for example
floats dont have inifinite precision
so its pretty unlikely to get something with so many numbers after the '.'
mojang should probably add a way to detect climbing scaffoldings, like player?.isScaffolding or whatever
Isn't there isClimbing? Or did my mind make that up
Yes, it is a thing for a Entity class
Yeah, not sure if works for scaffolding or not
try isClimbing
@distant tulip isClimbing works only on ladders, but not scaffoldings for some reason
and i do have isClimbing there,
btw, is it possible to detect when the player uses a lunge enchanted spear?
maybe via a item cooldown or whatever
you can check if its enchanted or not by getting the enchantable component
itemReleaseUse has a useDuragtion property, you can check if its longer than the charge complete time to detect when the player releases it to lunge.
umm, thats not how it works, it will lunge the player by just attacking with it
so ig ill have to detect if the spear is enchanted with lunge, the spear cooldown and detect if the hunger is < 6
thats the riptide trident
im not confusing it.
I just forgot how the spear worked
use the playerSwing event.
no need to check for the cooldown neither, because you cant swing during the cooldown with it.
Documentation for @minecraft/server
too late
const lunge = itemStack?.getComponent('minecraft:enchantable')?.getEnchantment('lunge');
const hasLunged = lungeCache.get(player?.id) ?? 0;
if (itemStack?.typeId.endsWith('_spear') && lunge && hunger?.currentValue > 6) {
const cooldown = itemStack?.getComponent('minecraft:cooldown')?.getCooldownTicksRemaining(player);
if (cooldown !== 0 && hasLunged === 0) {
lungeCache.set(player?.id, 1);
console.warn('Lunged');
} else if (cooldown === 0) lungeCache.set(player?.id, 0);
} else lungeCache.set(player?.id, 0);```and it works lol
in system.runinterval?
yeah
one runInterval for like 8 addons,
ill give it a shot
what
my current jump detection is inside the same interval
cant you just use playerButtonInput
i know autojump doesnt get detected with it but what else is wrong with it
basically, a core addon (more like a library mod on java) that contains all of my addons functionality, so instead of having a runInterval inside each addon, ill just have one large interval inside the core addon and it will contain all of the other addons functions.
if it works well, why fucking it?
and tbh, i did manage to modify the playerButtonInput one and force it to work just like how i wanted, but the only downside was that autojump wasnt detectable, and that button input detection has a runInterval inside of it, so it is the worse option,
why what?
button input:
system.runInterval(() => {
for (const ID of world.getAllPlayers()) {
if (!player?.isValid) return;
const hasJumped = jumpCache.get(player?.id) ?? 0;
const eBlock = player?.getBlockStandingOn();
if ((player?.isOnGround || player?.isInWater) && hasJumped === 1 && (eBlock?.typeId !== 'minecraft:slime' || (eBlock?.typeId === 'minecraft:slime' && vY === 0))) jumpCache.set(player?.id, 0);
};
});;
world.afterEvents.playerButtonInput.subscribe(({player, button, newButtonState}) => {
if (button !== InputButton.Jump) return;
if (newButtonState === ButtonState.Pressed) {
{const hasJumped = jumpCache.get(player?.id) ?? 0; const vY = player?.getVelocity().y; if ((!player?.isInWater && !player?.isClimbing) && hasJumped === 0 && vY > 0 && vY !== 0.15000152587890625) {world.sendMessage('First Jump'); jumpCache.set(player?.id, 1)}};
const handle = system.runInterval(() => {
const vY = player?.getVelocity().y;
const hasJumped = jumpCache.get(player?.id) ?? 0;
if ((!player?.isOnGround && !player?.isInWater && !player?.isClimbing) && hasJumped === 0 && vY > 0) {
jumpCache.set(player?.id, 1);
world.sendMessage('Jump')
};
});
jumpIntervals.set(player, handle);
};
if (newButtonState === ButtonState.Released) {const handle = jumpIntervals.get(player); if (!handle) return; system.clearRun(handle); jumpIntervals.delete(player)};
});;```
"why fucking it"
new:
const hasJumped = jumpCache.get(player?.id) ?? 0;
const eBlock = player?.getBlockStandingOn();
if ((player?.isOnGround || player?.isInWater) && hasJumped === 1 && (eBlock?.typeId !== 'minecraft:slime' || (eBlock?.typeId === 'minecraft:slime' && vY === 0))) jumpCache.set(player?.id, 0);
if (player?.isJumping && (!player?.isOnGround && !player?.isInWater && !player?.isClimbing) && hasJumped === 0 && vY > 0 && (vY > 0.15 && vY < 0.155)) {
jumpCache.set(player?.id, 1);
world.sendMessage('Jump')
};```
what does that even mean
its something known as, if the code is working, dont touch it.
"why fucking it" doesnt make sense.
its the way you are saying it
and this code is working pretty damn well,
anyways,
because performance? optimization?
just bec it works well, doing what i want it to do, (detects whenever the player jumps)
even with autojump
However, if the code is not optimise that would triumph over this saying.
this one has a total of two runIntervals, one for holding the jump button and one to reset the jump cache
import {world, system} from '@minecraft/server';
export const ePlayers = new Set();
const jumpCache = new Map();
world.afterEvents.playerJoin.subscribe(({playerId}) => {ePlayers.add(playerId)});
world.afterEvents.playerLeave.subscribe(({playerId}) => {ePlayers.delete(playerId); jumpCache.delete(playerId)});
system.runInterval(() => {
for (const ID of ePlayers) {const player = world.getEntity(ID);
if (!player?.isValid) continue;
const hasJumped = jumpCache.get(player?.id) ?? 0;
const eBlock = player?.getBlockStandingOn();
if ((player?.isOnGround || player?.isInWater) && hasJumped === 1 && (eBlock?.typeId !== 'minecraft:slime' || (eBlock?.typeId === 'minecraft:slime' && vY === 0))) jumpCache.set(player?.id, 0);
if (player?.isJumping && (!player?.isOnGround && !player?.isInWater && !player?.isClimbing) && hasJumped === 0 && vY > 0 && (vY > 0.15 && vY < 0.155)) {
jumpCache.set(player?.id, 1);
world.sendMessage('Jump')
};
};
});;```is it like bad for performance or something?
triggering code every tick vs only when it needs to
the issue with 'only when it needs to' using the button input thing, is that it also uses a runInterval,
but then youll clear the interval when you no longer need it
that interval is per player, more player holding the jump button means more intervals,
You're not clearing the runs.
if i did clear the runInterval, the whole addon will stop working, bec that one interval contains everything
ig i need to return if not used somehow
You're misunderstanding what we're saying.
-# maybe cuz im tired,
Then take the time off to rest. Approach this later.
time for some rest then
this is why i try not to code when tired, its more stressful lol
how else am i suppose to detect the 'autojump' jumps?
inputbutton event doesnt trigger unless the button is pressed/unpressed
they are asking how else
autojump doesnt require any button inputs
ig the only way would be in system.runInterval like they were originally using
hmm
do i have to return if im not using the code somehow? idrk if that even possible
What are you needing to detect jumping for?
stamina addon and possibly for other addons
would basing it off it's velocity be not a gud approach?
but, how am i going to detect the velocity when needed?
it has to be inside a runInterval
or just if (vY === 0) continue;
isOnGround checks?
so it wont run the jump detectors when the player is not jumping and has no vertical velocity
oh well, prob another complex logic
d u know whats the issue is, the interval wont stop running, bec it will keep checking if the player isOnGround or not
all of this struggle, is just bec mojang didnt add entityJumpAfterEvent
but ay, at least i did find a workaround,
at the cost of some performance,
-# its just, way way better than whatever abomination i have made in the Enhanced Mobs addon
that script is really unhealthy imo
"unhealthy" lol
unhealthy indeed
let count = 0;
system.runInterval(() => {
count++;
['overworld','nether','the_end'].map(dim => {
for (const entity of world.getDimension(dim).getEntities({propertyOptions:[{propertyId:'xhardercore:worker',value:'employed'}]})) {...}
});;
});;```what could possibly go wrong?
those 'employed' are zombies that can place blocks, track their target and even mine blocks,
the average american is more healthy than this script
- the zombies spawn rates are increased, by alot, so there are alot of zombies that are getting detected using this script, (most of them are unemployed)
what abt /execute cmd for such and trigger scriptevent, altho idk what the performance would be like
im using commands to destroy the blocks, and to summon some mobs (basically summoning a gass entity after a boomer explodes or get killed)
no /execute and no scriptevent
i can show u the full script if u want, and tell me if its healthy or not
nah, i'd rather let u take some rest, lol
i cant
im downloading a game, it will be finished in an hour (probably two) bec the internet is too shitty
so i wont sleep anytime soon,
even power naps...
and ay, i code better while being tired, (speaking of experience)
i just cant understand others well while being tired,
can't disagree to that ngl
damn
i can spend the WHOLE day thinking about fixing an issue, and right when i go to bed and trying to connect to a random dream server, ill just figure it out and have to go saving the fix idea in a notebook just incase if i forget it the next day,
I just realized functions are objects in javascript...
what
so you can attach properties to functions
I now understand functional programming than OOP...
i think in gsneral, javascript functions are more like closures
I wonder what use cases can be applied knowing JS functions are objects rather than you can attach functions to it or closures
do people really slap some variables inside the function object 💀
can be useful in react though
Give an example
what do you mean
Just looking to see some variant of code to know if you understand what you are saying.
function dog() {
return "I'm a dog";
}
dog.shout = function() {
return "ARF";
};
dog.myname = "My name is Doug";
console.log(dog.shout()); // ARF
console.log(dog()); // I'm a dog
console.log(dog.myname); // My name is Doug
this can be useful to avoid classes I assume
Definitely, but also personal preference as well. Some are accustomed to using classes due to their experience and background in other areas so even though functions as objects can, in many ways, be far more superior, some still use classes out of comfort and experience. So there definitely isn't anything wrong with classes in JS. Just different by nature lol.
yeah. I like OOP too very flexible for me
I mix it up, but I think that's just because I can't make up my mind so I go with the flow and accept it haha.
The problem with this is you can only attach properties at runtime
depends if u can remember all the logic behind, which is very hard to track when coding
That’s the beauty of writing code lol, understanding the strengths and weaknesses of different approaches and choosing based on the trade-offs.
When I see people debating what’s “good” or “bad,” I usually just step away. At that point, it often comes down to preference and context. There are many ways to accomplish the same goal, some may be better suited than others, but rarely is there only one “correct” way.
export const parseFirstMention = (message = "@") => {
let rgxResult = parseFirstMention.rgx.exec(message);
if (!rgxResult) return null;
const lastIndex = message.search(rgxResult[0]) + rgxResult[0].length;
return {
name: rgxResult[2] || rgxResult[3] || "",
message: message.slice(lastIndex).trimStart(),
};
};
parseFirstMention.rgx = /(@(?:"([^"]+)"|(\S+)))/;
```got this rgx attached cus regex is expensive when triggered in large quantity
is the rgx dynamically changing?
no
it costs some performance
instantiating regex is different from instantiating number/string/boolean
same with instantiating a function
mmm I see
size is different from performance
like RAM isnt CPU...
idk, its just there to lessen cpu work
yeah, I just thought since (I assume) attaching property to a function would just mean it just reference to the memory address of the property
not entirely sure how instantiation of functions work too lol
is it possible to play swing animation on playerInteractWithBlock?
doing ()=> {} is instantiating already, which isn't rly expensive
you block needs to be interactable
have u trid it yet?
is it on the block components?
are you dealing with a vanilla block
Nope, I'm using a custom block
so dont use playerInteractWithBlock and make a custom component event.
wana check this one 👀 https://discord.com/channels/523663022053392405/1131984839151714354
||and another cursed stuff: #1144641554942803978 message ||
giving it the onPlayerInteract event will make it interactable and the player will swing their arm.
ohh okaayy, Thankk youu!! I'll try it
Thankss!
how can i make my camera follow another players camera in 3rd person?
like a "follow" command
Can I use PlayerInventoryChangeAfterEvent to detect Entity's inventory
says Player
meaning only player.

Why would you avoid classes, they are the best to make ur code reliable, readable and efficient
Girl thats the same thing
You still have a constructor, methods and properties
Thats how people used to make classes/object templates before they were implemented in javascript

I never said I will avoid classes. I just said the possible use case of attaching properties to the function can be used to avoid classes
.
I guess if you dont want to use OOP
People code as they like, it will work anyway lol
is there a best way to filter out a values in formValues?? (Modal Form) there's still a undefined on the array..
nvm got it
Wait until you find out what JavaScript classes really are under the hood ...
real
Time to drop in the legendary OverTakes function!!!!
TS and JS are really magical with the core concepts of prototypes, its really unique in its sense, i am not sayin its good practice to modify or manipulate but once you do then everything starts feeling magical 🙃
I wish object prototypes were more accessible in TypeScript. TS is really not built around JS structures
yea
thanks
Doesn't classes work?
// JavaScript
// Note that single '>' in comments is for example input.
class MyClass {
constructor (/*args here btw*/) {
// Code that runs when this is done:
// > new MyClass(/*args here*/)
// To access the instance use `this`:
// > this.property = newValue // etc.
}
myMethodName (/*args*/) {
// Invoked when an instance uses it:
// > let ins = new MyClass();
// > /*result = */ ins.myMethodName();
}
// myMethod2 and myMethod3 are used by the subclass. They are still methods fom here though.
myMethod2 (/*args*/) {}
myMethod3 (/*args*/) {}
get something () {
// A "getter" for the property named `something`. Getters accept zero arguments, but does have `this` accessible. Should return a value.
// > console.log(theInstance.something);
}
set something (value) {
// A "setter" for the property named `something`. Setters accept one (1) argument, along with implied `this` accessible. Don't return a value from here.
// > theInstance.something = value;
}
// A getter can have no setter, and same the other way around. Trying to read a write-only property (w/o a getter) or trying to set a read-only property (w/o a setter) will cause an error.
get readOnly () {
}
set writeOnly (value) {
}
}
// You can also subclass. Can only have one base class but can chain it.
class MyOtherClass extends MyClass {
constructor (/*args*/) {
// The constructor requires invoking
// > super(/*args here*/)
// exactly once before you can access `this` from the subclass constructor
}
foo (/*args*/) {
// You can add new methods.
}
myMethod2 (/*args*/) {
// You can completely override methods.
}
myMethod3 (/*args*/) {
// Also can override but still invoke from the parent class:
// > return super.myMethod3(/*args*/);
}
}
Do you know the OverTakes function or not?
Never heard of it.
Have you ever modified native class prototypes
Can you have the game send to chat the result of typeof Proxy (should return a string)?
I'm curious if it is implemented.
I know that... I meant "the output of this should work if you send it to the chat... could you see if Proxy exists, please?"
If it does exist, it should say function.
I recall this because you can use Proxy to override an object's getters and setters, even to properties / methods / etc. that are not yet defined on the object.
Info I know about is from MDN: https://developer.mozilla.org/
If you are just overwriting specific methods, that sort of monkey-patching works (that you shown).
Proxy is indeed available in MC engine
not sure what you want to prove tho
you can use proxy as you wish but keep in mind that proxy is not same object, its a wrapper on top of it
so if the native isntance is the raw handle, then you loose the identity of it
Proxy (and the Reflect that is used with it) is more usable when you want to work on something like an Array:
let arr = [];
Object.getOwnPropertyNames(arr); // result: ['length']
arr.length = 5;
Object.getOwnPropertyNames(arr); // result: ['length']
arr = Array(5);
Object.getOwnPropertyNames(arr); // result: ['length']
arr = Array.from({length:5});
Object.getOwnPropertyNames(arr); // result: ['0','1','2','3','4','length']
¯_(ツ)_/¯
i am still confused
what are you trying to say?
can i help you somehow?
You can still access the raw handle via. the proxified object.
And I guess you missed this message I edited?
If the task I saw earlier was just overriding specific methods of a global built-in object, using a class is overkill.
I noticed so I sent that message once I realized it.
The part of Proxy was just curiousity.
This here shows that the length of an array doesn't mean that it will actually have values assigned to the various indexes.
sure
?
and?
i am sorry, but i feel like i am still missing something
how do i involve in that?
I think i didn't say anything about classes
SetandMapare classes as you must use thenewkeyword to initialize them.Erroris a class but will implicity add thenewkeyword if called without it.Dateis also a class, but when called without thenewkeyword, it acts differently.
The image I copied (which is what you replied to) looks more like it is better suited for a class than how it is set up like in that code.
That is a primitive value of type number... I already know that.
Ok? and what should i do now?
... never mind.
i am so confused 😭 don't do that to me
And obviously I'm bad at expressing things properly, such as replying to the wrong person / message.
ahhh, i see i thought i did something wrong or whatever looks like its just a misunderstanding 👍
My honest apologies...
Good, good, don't worry, i just got confused
The subject shift to Proxy was just my own curiousity.
The only times I have, I always make sure to explicitly mention I did... and never once have I used it for code.
anyway Proxies are really nice, but i avoid them as much as possible
I trust AI as much as I trust back when I was a kid and my ability to hold myself on the chin-up bar (read: I don't trust it at all)
its really bad for debugging
I assume Symbol is also supported?
yea
Symbol is like ES5 afaik
or ES6 idk
i mean BigInts were not supported for long time
but nowdays it has almost everthing
@subtle cove Do you rememeber any of environment apis that are still not available?
Ping me anytime, i happy to assist you with your questions next time
Buffer and ArrayBuffer
wait really?
just there is not much of usecases for them
if we didn't got the Script API integration
i wish we had Uint8Array is valid DP value
yea i remember that i used them like 3 years ago
Is there BigInt ?
yeah
yea
My bad.
no idea why i never tried to use them, always assumed they are not supported
i tried to use them before i know how to use them lol
i was just messing around with globals haha
i can think of few use cases in bds but i never needed to use that
python mentioned 💀
sounds like a crime to me
¯_(ツ)_/¯
Python is just wrong at its core, the syntax is just unacceptable
thats all i don't like about it
i don't care if its slow or whatever
Readability is not really that super good for python eather
you have to get big tabs to make it more readable except you might miss on what level of scope it is
that is really not a good way of comparing
a turtle is faster than a rabbit without legs, yeah sure
How is python related to scripting api
oh thank you... I'll clean up
Too late... hopefully most of the non-JS stuff is out.
For Python stuff that I do know, you can ask in DMs... I'll try opening one with you (so I remember after I am done showering)
wdym
is it possible to get subtick delay?
i need to run something exactly every 3.5 ticks
thats not really possible, the lowest you can make it is tick it self
thats how the game operates
i suggest doing some thing every 3 and 4 ticks
so at the end the interval is two times per 7 ticks
i tried both, 3 is too fast, 4 is too slow
can runJob do it somehow
not really, maybe you would be able to spin the time with empty loop or whatever, but it would still run in the same tick
at the end its just the tick it self
if it was the average speed that i want to be 3.5 ticks i wouldn't have came here
¯_(ツ)_/¯
and i am here to tell you the only few ways
you can also make semi-infinite loop to make the ticks slower
and then doing interval every 3 ticks
there are manyways but nothing as good as 3-4-3-4-3-4 pattern
there is no such a think as middle of the tick
alright, thank you for the help
i wish there was an answer but there really is not
What do you need to execute on a subtick? Every gameplay element operates on ticks, so subticks are not terribly relevant. If it is audiovisual, you should be using stuff on the client (key frames in animations, empty silence in sounds, durations in particles, etc.)
Well said
that's a great idea
how to set equipment a dyed leather armor?
const eq = player.getComponent("minecraft:equippable");
if (!eq) return;
const chest = new ItemStack("minecraft:leather_chestplate", 1);
const legs = new ItemStack("minecraft:leather_leggings", 1);
const feet = new ItemStack("minecraft:leather_boots", 1);
const colorRGB = player.hasTag(TAG_BLUE)
? { red: 0, green: 0, blue: 255 }
: { red: 255, green: 0, blue: 0 };
const chestDye = chest.getComponent("minecraft:dyeable");
if (chestDye) {
chestDye.color = colorRGB;
}
const legsDye = legs.getComponent("minecraft:dyeable");
if (legsDye) {
legsDye.color = colorRGB;
}
const feetDye = feet.getComponent("minecraft:dyeable");
if (feetDye) {
feetDye.color = colorRGB;
}
eq.setEquipment(EquipmentSlot.Chest, chest);
eq.setEquipment(EquipmentSlot.Legs, legs);
eq.setEquipment(EquipmentSlot.Feet, feet);
tried this one but seems like none of them were dyed just normal leather
getComponent("minecraft:dyeable") seem to return undefined
another useles component that don't work on vanilla items
loot table
alr thanks
Just goes to show that vanilla items dont have these components.
yeah, just weird that they don't consider such cases
Scripting and Vanilla Item team likely arent always in sync.
just use an interface ?
oh yeah ill be able to say what i say in JSON UI
hardcoded ✨🙌
Say you shadow a property in an object. How would the interface look for that?
I suppose for a simple case like the following an interface would work.
interface IMyObj {
make: string;
}
const MyObjProto: IMyObj = {
make: "foo",
};
const obj = Object.create(MyObjProto);
console.warn(obj.make) // "foo"
Yet when we get deeply nested prototypes, would each successive object have to take the union of each interface in the chain?
Or if I want to change the type of the property make? (Or if it's a method, change its return type/signature)
yeah I suppose this is the only solution I can think of
override the type
sorry, but i do not know which ones are "aren't available", but rather what "are available"
const global = [
"Object","Function","Error","EvalError","RangeError",
"ReferenceError","SyntaxError","TypeError","URIError","InternalError",
"AggregateError","Array","parseInt","parseFloat","isNaN","isFinite",
"decodeURI","decodeURIComponent","encodeURI","encodeURIComponent",
"escape","unescape","Infinity","NaN","undefined","Number","Boolean",
"String","Math","Reflect","Symbol","eval","globalThis","BigInt",
"Date","RegExp","JSON","Proxy","Map","Set","WeakMap","WeakSet",
"ArrayBuffer","SharedArrayBuffer","Uint8ClampedArray","Int8Array",
"Uint8Array","Int16Array","Uint16Array","Int32Array","Uint32Array",
"BigInt64Array","BigUint64Array","Float32Array","Float64Array",
"DataView","Promise","WeakRef","FinalizationRegistry",
"console","print","Symbol.toStringTag"
];```these stuff
has anyone use the "FinalizationRegistry"?
WeakRef is supported??
Ah, is FinalizationRegistry in?
As of recently yeah, I think a Preview added support for that a little while ago
yea
Yea same for me
Can we save objects or arrays on dynamic properties? for example:
world.setDynamicProperty('array',[ "a", "b", "c" ])
world.setDynamicProperty('object', { "a": 1, "b": 2, "c":3 })
you can use JSON to serialize the objects or arrays
Great idea. Ty
is there a efficient way to do spawnEntity? cuz without tickingManager it's just LocationOutOfBounds which is annoying and because of constantly calling world ticking manager it's causing memory leaks..
Normally you shouldn't be spawning an entity on unrendered locations unless you're doing something with the entity itself so you might have to look into that
I have set it's distance filter to 30-50 blocks since that's what i am doing with it but I can't find a way for it since idk if i can read simulation distance on scripts..
I just realized that the error you're getting isn't even about unloaded chunks. It's spawning entities in out-of-bounds areas like below bedrock level so the issue might have to do with the way you're spawning entities instead
If you're forced to do it that way, then you can just ignore the error by try-catch.
I forgot the error name but i never went to below bedrock😭 i thought it's the same as the chunks error lol
Are you able to show your code?
Ohh wait
2nd one but in Vector3 format {x,y,z} can be saved
weird they did that and treat vector3 as another some sort of data type
The only thing you can natively save that is object at this time is a Vector3 interface (xyz position). If you want to save smth else that is an object, you should use JSON.stringify() and JSON.parse()
oo ur name purple
Was there a recent event? How did you got that
yeah, there was a lucky block jam
welcome to the purple team including VoidCell
😁
Yep, I’ll use that. That was only a doubt btw, I won’t use it for now..
Just been trying to mess with entityItemDrop for the past half hour.. not sure what Mojang thought the use case would be for it but I think it's pretty silly that it uses items as Entity[] instead of the itemStack you dropped.
It would be nice to get a specific playerItemDrop event instead since just using system.runInterval() seemed to be the better way instead.
Use the .getComponent('item') to get the itemstack.
It's also a very good use case, I add the dynamic property to the item dropped entity which then I cancel using itempickupevent if it doesnt match the id.
It would be nice to get a specific playerItemDrop event instead since just using system.runInterval() seemed to be the better way instead.
Better in what way?
One thing I do like about entityItemDrop it also detects loot drops.
I'm guessing that's why it's Entity[] for items then
You can also do item.remove() which you can't with an ItemStack.
I just mean having playerItemDrop or something that returns just the single itemStack that the player dropped because when you do items[0] that only allows for typeId and id
So your issue is trying to get the item stack from the Entity array...which once again, is already possible by just getting the getComponent('item')
I suppose it is...
I tried quite a few things earlier and nothing worked but I guess out of everything I tried somehow that wasn't one of them
Yeah, the item component of entities is easily forgotten. I had your reaction when I first used the event until I realised it's better to be an Entity[] instead of an ItemStack[].
I see why I couldn't get it to work now. After getting the itemStack I was attempting to set the nameTag of said itemStack which fails. I had to get the data I needed from the itemStack and then set the nameTag of items[0] instead to display it.
wow I get no welcome, I see how it is /j
I did it wdym?
ahhh, I must've just ignored the last part like it wasnt there when I sent my message
100%
silly me
Yeah. I would check out myself
yk
in case anything bad happened
because it was there 100%
you are right, I must have extreme brain damage
you are so right
im going to the doctor now
VoicDell lol
no it couldnt have been, I swore it was spelled right
its happening again
im seeing things
What?
now its spelled correctly
lol
Is CustomComponentParameters#params a string that you have to JSON.parse?
its an object.
Tysmmm
entityHurtBeforeEvent are still in beta or will be stable in the next update?
cuz i will be using it to make a gravestone addon, detecting when the player take too much damage while having low health to copy the whole inventory to the gravestone entity
I'd expect it to be in stable next update, but don't actually know
I'd assume it should be pinned if we did know
ig ill just start coding it so i can post it whenever it becomes stable
Good idea
Just use keep inventory
And get the items in the death event and clear them
OR save the inventory beforehand and cache it
without cheats enabled? all of my addons wont turn off ur achievements,
Yeah?
maybe via world.runCommand('gamerule keepInventory true') or whatever
There is a native api for game rules
i see,
World.gameRules or something
will it work properly with instant respawn enabled?
ig ill have to do some testing
Yeah, getting the items and clearing them is fast
and no runintervals are needed
Yeah
since, why would i need one?
Finally found a use for DebugText (mainly the visibleTo feature) 
key*
But the issue is that is also show in the other dimensions
Huh what, when i used it, it didnt had a dimension thing
it is now
Fixed...
key(s)
You can just conditionally add the s
In your opinion, should I use...
world.runCommand
or
runCommandAsync? because my friend said Mojang removed the Async but it works normally for me
if async works then you're on a very outdated version
and for most things you should be using native methods, not commands
How long does it usually take from experimental release for scripting apis to become stable?
There have been some that make it into stable after a month and some that have been in beta for years and probably won't ever be released. It depends on which feature
Example: beforeChatSend 😭 Which has been in beta since the dinasours were around 💀
At this point I think they've just forgotten about the event
entity.target 😭
What does that actually do? I've seen so many people talk about it but I don't think I've ever used it once before...
gets the entity's target..
That doesn't help... 😭
think of a zombie, its attacking you, you are the target
whatever the entity is attacking is the target
Okay, there we go then.. cool.
don't read my mind!!
no
would also be super duper cool if it wasn't read-only
it used to not be
thats not the same "target", this is different
Ah
It's the only type of target I could find 😅
Ah
Documentation for @minecraft/server
different classes, different meanings
Interesting, didn't know you could set the AI related behaviours in scripting
It's read only so no, you can't set anything.
you cant
Ah
Just get then?
Gotcha
it says set, but that was removed
again, it used to be able to
Oh
they just made it read only at some point lol
wait really? aint no way -_-
glad you said it again because i couldn't read it the first time
I don't do entities, but it seemed pretty amazing to do by scripting
That's the basically the convo we just had if you read above
Im praying beforeEvents for entity hurt to come to stable asap
i am using the entity.target on my enhanced mobs addon, for the minerzacks and builders, the script detect the target location and compare it with the entity location to like pile up or building a bridge,
and im not using any beta versions, all stable and works somehow
thats not possible.
then idk how it works
show me the behavior manifest to the addon
also, isn't ur pfp the hollow knight guy?
ig its 2.4.0 or something,
you guess?
its not the exact same, but its based on the hollow knight, yeah
even before the dinasours
serty joined the purple team?
yeah, me, minato and serty were on a team together
with 8crafter and Venoct too
i feel like more people joined this event than the last time
i dont think there were that many people actually
hmm, tbf i dont even know how many people were in the previous event lol
I made like only 1 event for it, I was distracted and was procrastinating hard
it could be that this event included more "known" people
@thorn flicker
wish I did more
what the hell are you talking about
ah.
@late saffron
why are you bringing it here
Why do you care?
thanks
cool ig, just add some orange eyes and u will become the hollow knight,
-# i really love that game, its just too good.
i mean, u can check it out if u want,
https://www.curseforge.com/minecraft-bedrock/addons/xhardercore-enhanced-mobs
(i played some dbd and then forgot to answer lol)
i can relate
the project i posted for my role was... one of its kind
not sure if anyone remembers my "peter griffin brainrot RP"
You probably used a number or a boolean in a text flied
TextField default value must be RawText or String, but your's is a number
@warm mason do you know what to do with this one?
Yeah, u just need to put a string in defaultValue, not a number. Do String(Math.floor(config.frequency)) for example
this error is in notes, but it still has no description or something
Whats line 99?
what
It's already solved
my first script
import {world,system,Player, CustomCommandStatus} from "@minecraft/server";import * as ui from "@minecraft/server-ui";
system.beforeEvents.startup.subscribe((e)=>{
// docs
// .my.id
// .nperma.
e.customCommandRegistry.registerCommand({
name: "menu",
cheatsRequired:true,
description: "Show Menu"
}, async (e)=>{
const player = e?.initiator || e?.sourceEntity
if (!(player instanceof Player)) return;
await null;
new ui.ActionFormData()
.title("MENU - UI")
.body("Hello this is menu description")
.button("Rules")
.button("Home")
.show(player).then((r) => (r.selection==1?(async function LU4M4K33EF00GO7S03ESYN7AX(){return await new ui.MessageFormData().title("RULES").body("- NO NSFW\n- NO TALK\n- NO PROBLEM").button1("Close").button2("OK")})():![]
))
})
})
Is it possible to put multiple rawMessage strings on one lore line? Or combine them to e.g. use multiple translations after one another?
RawMessage can consist of other RawMessage
like ```js
const message = {
rawtext: [
{ text: " Text" },
{ translate: "item.apple" },
{ text: " Another text" }
]
};
oh perfect, that's just what I needed. Thank you!
hello
anyone can help me, why in animation hold_on_last_frame dosen't work for me ?
"format_version": "1.8.0",
"animations": {
"animation.fridge_left_door.open": {
"loop": "hold_on_last_frame" ,
"animation_length": 0.6,
"bones": {
"door": {
"rotation": {
"0.0": {
"post": [-180, -180, -180],
"lerp_mode": "catmullrom"
},
"0.08": {
"post": [-180, -177.5, -180],
"lerp_mode": "catmullrom"
},
"0.32": {
"post": [-180, -132.5, -180],
"lerp_mode": "catmullrom"
},
"0.6": {
"post": [-180, -95, -180],
"lerp_mode": "catmullrom"
}
}
}
}
},
"animation.fridge_left_door.close": {
"loop": "hold_on_last_frame",
"animation_length": 0.6,
"bones": {
"door": {
"rotation": {
"0.0": {
"post": [-180, -95, -180],
"lerp_mode": "catmullrom"
},
"0.28": {
"post": [-180, -132.5, -180],
"lerp_mode": "catmullrom"
},
"0.52": {
"post": [-180, -177.5, -180],
"lerp_mode": "catmullrom"
},
"0.6": {
"post": [-180, -180, -180],
"lerp_mode": "catmullrom"
}
}
}
}
}
}
} ```
import { Fridge } from "./furniture/fridge";
world.afterEvents.itemStartUseOn.subscribe(new Fridge().fridgePlaceEventHandler.bind(new Fridge()));
world.afterEvents.playerBreakBlock.subscribe(new Fridge().destroyFridge.bind(new Fridge()));
world.afterEvents.playerInteractWithEntity.subscribe(ev=> {
if(ev.target.typeId === "y2c:fridge_left_door" || ev.target.typeId === "y2c:fridge_right_door") {
ev.target.playAnimation("animation.fridge_left_door.open");
}
})```
like instead of the entity staying at its last position from the animation it gets defaulted
wrong channel, go to #1067869022273667152 or #1067869590400544869
ahm after the update i am getting this error "playersInWorld is not initialized at validPlayers"
let playersInWorld = [];
world.afterEvents.playerSpawn.subscribe((e) => {
if(!e.initialSpawn) return
if(e.player.hasTag("bot")) return;
playersInWorld.push(e.player)
})
export function validPlayers()
{
if(playersInWorld.length === 0)
return false;
return true;
}
oh wait
nvm i was calling something at early-execution
guys , is Chest UI for herobrine is usable to make it as a normal chest like a fridge container ?
system.runInterval
u must export playersInWorld too
so it would be like
system.runInterval(() => {
// CODE
})
?
Yeah.
Appreciate it
tho recreating an entire knockback system is going to be hard
Im not using an IDE atm so no way to error check yet
damagePrecision = 5
immunityFrames = 5
world.beforeEvents.entityHurt.subscribe((ev) => {
damageTaken = ev.damage
damageSource = ev.source
damageTarget = ev.entity
if immunityFrames > 0 { return }
setDynamicProperty("example:health", getDynamicProperty("example:health") - (damageTaken * damagePrecision)
if getDynamicProperty("example:health") < 1 {
damageTarget.kill()
}
world.sendMessage("ouch")
ev.cancel()
})
at least u got the code structured
import {world } from "@minecraft/server"
let damagePrecision = 5
let immunityFrames = 5
world.beforeEvents.entityHurt.subscribe((ev) => {
const { damage , hitEntity , hurtEntity } = ev;
if (immunityFrames > 0 ) { return }
world.setDynamicProperty("example:health", world.getDynamicProperty("example:health") - (damageTaken * damagePrecision)
if (world.getDynamicProperty("example:health") < 1)
{
hurtEntity.kill()
}
world.sendMessage("ouch")
ev.cancel()
})
It doesn't look horrible but I am really uncertain about my use of dynamic properties
Pretty much until the max health and armor systems get exposed to scripts im just making my own system to handle it
Debug result for [code](#1067535608660107284 message)
Compiler found 6 errors:
[36m<REPL0>.js[0m:[33m6[0m:[33m18[0m - [31merror[0m[30m TS2339: [0mProperty 'hitEntity' does not exist on type 'EntityHurtBeforeEvent'.
[7m6[0m const { damage , hitEntity , hurtEntity } = ev;
[7m [0m [31m ~~~~~~~~~[0m
``````ansi
[36m<REPL0>.js[0m:[33m11[0m:[33m44[0m - [31merror[0m[30m TS2362: [0mThe left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.
[7m11[0m world.setDynamicProperty("example:health", world.getDynamicProperty("example:health") - (damageTaken * damagePrecision)
[7m [0m [31m ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~[0m
``````ansi
[36m<REPL0>.js[0m:[33m11[0m:[33m90[0m - [31merror[0m[30m TS2304: [0mCannot find name 'damageTaken'.
[7m11[0m world.setDynamicProperty("example:health", world.getDynamicProperty("example:health") - (damageTaken * damagePrecision)
[7m [0m [31m ~~~~~~~~~~~[0m
``````ansi
[36m<REPL0>.js[0m:[33m12[0m:[33m1[0m - [31merror[0m[30m TS1005: [0m',' expected.
[7m12[0m if (world.getDynamicProperty("example:health") < 1)
[7m [0m [31m~~[0m
``````ansi
[36m<REPL0>.js[0m:[33m12[0m:[33m5[0m - [31merror[0m[30m TS2365: [0mOperator '<' cannot be applied to types 'string | number | boolean | Vector3' and 'number'.
[7m12[0m if (world.getDynamicProperty("example:health") < 1)
[7m [0m [31m ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~[0m
``````ansi
[36m<REPL0>.js[0m:[33m17[0m:[33m4[0m - [31merror[0m[30m TS2349: [0mThis expression is not callable.
Type 'Boolean' has no call signatures.
[7m17[0m ev.cancel()
[7m [0m [31m ~~~~~~[0m
ESLint results:
<REPL0>.js
12:0 error Parsing error: ',' expected
And that's what I get for not using an IDE I guess
wait is there even entityHurt in stable script api ?
what version do u use ?
Trying to work with latest beta
after Events could work if it was able to ignore extra effects and only take "true" damage
oh ok
I don't feel like reverse engineering enchants, effects and armor math
I wish I could just grab the damage value straight from the json
but I would need to apply modifiers for held items and it just becomes a mess
import {world} from "@minecraft/server"
world.beforeEvents.entityHurt.subscribe((ev) => {
const { damage , damageSource , hurtEntity } = ev;
if (immunityFrames > 0 ) { return }
world.setDynamicProperty("example:health", world.getDynamicProperty("example:health") - (damageTaken * damagePrecision));
if (world.getDynamicProperty("example:health") < 1)
{
hurtEntity.kill()
}
world.sendMessage("ouch")
ev.cancel = true ;
}) ```
i hope that will work
Appreciate it
The end goal is to extract how much damage I would have taken from any particular hit whilst ignoring all defensive bonuses
i see
no
feel free to create posts whenever
It's challenging but not impossible. You will run into difficulties with the armor calculations; armor toughness makes it piecewise
I wanted armor to reduce by flat damage and enchants to apply a percentage after
I can give an example if needed
let's say a full prot 2 iron armor set + Resistance 1
Full iron: 12 defense ( -12 damage )
Prot 2: 2% per level per piece so 4% * 4 = 16%
Resistance 1 = 20%
(Damage - defense) S(enchants, effects)
S is that sigma symbol as I cant find it rn
Its like a really weird E
Σ
This yes
ahh why do u need to recreate the damaging system ?
flat damage first and then all percentages apply to get the final damage
I just don't like how the current system works and it would be cool to be able to scale for progression post dragon, as things do more damage you need more armor
hmm interesting
The whole reason armor toughness got added is likely because they hit their limit already via diamond armor's protection
The easiest way for a new damage system is disabling vanilla armour, enchants, tools, etc.
Thats exactly what I'm trying to do, reverse engineering that all to get the original numbers
That may be easiest, but it is not very exciting or compatible. That's more like saying "a solution to this is not looking at the problem"
idk but i feel like you will hit a limit somehow, because u won't be able to get the full detailed data
I think it would be easier to just backlog the numbers instead of removing every instance of vanilla numbers
With the armor formula, you'll find there are two fundamental equations: One with toughness and one without. If you can measure the entity's total toughness and protection, reversing either one is pretty easy; where it gets tricky is where to draw the line between which one you use
I am not good at anything but commands and scripts
And even scripts are stretching it
Im just doing what I can
As I hate Json
same
Aren't there callbacks for those?
For getting toughness and armor? They are properties accessible on EntityEquippableComponent
no
script
Scripting, that's a component you can read on players and very select mobs
(Reading armor and toughness on non-player entities will be its own challenge)
I assume just anything naturally able to wear armor?
Surprisingly no. That component is not exposed for most entities
Yet the inventory is, as EntityInventoryComponent. It cannot read equipment slots, but it can read inventory slots
Idea -> try -> impassible roadblock
That's my dev experience in a nutshell
Ideas too big for the scope of my skill
Another idea is hardcoding the protection and toughness values for vanilla armor and measuring what armor pieces the mob has on through other means
Wouldn't that require also reading enchantments tho?
Enchantments are another beast ... even I'm not sure how one would read enchantments on entity gear
I guess better start learning Json then...
or using a script "nodejs perhaps" or as py code" or that read all vanilla .json files and put em on a map or an array or something
no and no
Course you fit. You've just picked a tricky idea to work on
yep
it's quite possible, I've already made one...
can u share it ?
Then you're a much better developer than me
nah
My only other lang that I fully get is Lua
Were you able to solve the problem with reading enchantments on entity gear?
well, it's public, but u unlikely will be able to just use it
obscured ?
no :/ but I mostly just increase entities health and don't give them any armor so it's not a problem for me
no, it's just depends on other code
That's a fair compromise
hmmm i c
hmmm
I could just implement my own take on enchants later in dev
Aye, simply omit the component "minecraft:enchantable"—only a guarantee for armor you make though
what would it solve?
Having to worry about enchantment calcs
or , u can use events
I'll just replace all instances of vanilla armor with my custom sets
this isn't a problem compared to other things u need to do
Reading enchantments is annoying, but once you have them counteracting them in the equation is rather straightforward
a bad way
Just check for the armor item in the inventory with scripts and replace them no?
yep
it will make ur system incompatible with other addon's custom armor
and recipes maybe
While true, every solution provided has its use case. If you're making a server then overriding vanilla makes sense.
This is true.
minecraft:diamond_helmet -> test:diamond_helmet
it depends on the used logic
is ur addon for a server or not?
its general use
then don't do it
Not any particular goal in mind
What downsides are there?
#1067535608660107284 message
- like, u will disable enchantments, it's not what players would like
I don't really care much for compatibility icl
With a change as drastic as this, you gotta make sacrifices
as you wish..
It would make things easier. Part of solving this problem is defining the limitations you will be working around, and that is a valid answer too.
If there were a reasonable way to do so then I'd agree but there's not
All armor
damn
If you was able to generate custom items at runtime this wouldn't be an issue
I could just create a converter
I'll probably include 1 anyway for those who want to add support for the addon
or u can just
player.getComponent(EntityComponentTypes.Inventory
)?.container.getItem(0)?.getComponent(ItemComponentTypes.Enchantable)?.removeAllEnchantments();
Well yeah but I would also need to set everything to 0 armor points
Since custom system
I need to return raw damage
The representation of be or not to be
totalArmor amd totalToughness properties in equippable component
and read only
I am not a math major 💀
I can rearrange simple formula but this is not simple in the slightest
No, and the min/max functions make this a PITA
A what?
Pain in the ass 😄
I'd treat them not as a clamp on the final value, but a clamp on how the inputs are read; that is, the effective value for defense points is capped at 20
Fair warning, the weapon damage input is defined in terms of itself when using armor toughness, so in that case you'll need the quadratic formula to find it
My head hurts...
Are you sure that is accurate btw?
I'm about 95% confident
I saw from some sources that bedrock armor calc is simpler or smthn
Used to be before they added toughness, which was at a different time than Java Edition
AFAICT they are now (mostly) the same
(I used this equation with great results)
The min and max throw so many loops into this
If it wasn't for stuff like the mace I could probably just use the main hand + check the damage of whatever is held
But then TNT and stuff too..
@sharp elbow
I know this is frowned upon but I suck at math so asked AI about min / max for reverse engineering.
It definitely gave me something but I'm really unsure on it
I don't know where else to look for how to reverse it
Look at it as splitting into two expressions depending on constraints in the inputs.
weapon_damage * (1 - min(20, x) / 25)
Can be split into the following:
weapon_damage * (1 - 20) / 25 {x > 20}
weapon_damage * (1 - x) / 25 {x <= 20}
(With x being shortened for brevity)
It's dubious but it could be right, only one way to find out
Out of curiosity could you post its findings here?
function reverseArmorFormula(damageTaken, armorPoints, toughness) {
// ----- Regime 1: low damage branch -----
// reduction = armorPoints / 5
const possibleLow =
damageTaken / (1 - (armorPoints / 125));
const threshold =
(4 / 5) * armorPoints * (2 + toughness / 4);
if (possibleLow <= threshold) {
return possibleLow;
}
// ----- Regime 2: high damage branch -----
// reduction = armorPoints - (4 * damage) / (toughness + 8)
const toughnessFactor = 2 + toughness / 4;
const a = 1 / (25 * toughnessFactor);
const b = 1 - (armorPoints / 25);
const c = -damageTaken;
const discriminant = b * b - 4 * a * c;
if (discriminant < 0) {
return null; // no physical solution
}
const originalDamage =
(-b + Math.sqrt(discriminant)) / (2 * a);
return originalDamage;
}
I hate math
Well, it doesn't seem insane
Is just solve low, if not valid solve high?
Honestly I'm not sure, it took a slightly different approach than I would have. And I don't have the brain currently to verify
is extending classes possible here? i haven't tried it tho.. like
... extends BlockBoundingBoxUtils
maybe prototype?
but that also might work, although ive never tried it and always used prototype
only when their constructor isnt private, meaning u can call constructor new on the class
Yeahh i just noticed it, but still thankss!
Anyone know how to cancel a fire aspect hit?
canceling in before hurt event doesnt work
which I assume is a bug
they overlooked on that one? 😭
Documentation for @minecraft/server
doesnt work since it needs to be ran in system
so it will still take a tick of damage
I see, then you will have to calculate the damage lost from that tick and restore it.
too much work lol
Oh I know. I got an entire script for it lol.
weird didnt realize wind bursts are counted as explosions
hiro
how do I play music like pigstep per script, do I use world.playMusic if then what are the disc ids?
well I got smth to work by running runCommand but I would still love to hear the script version of it
and without any commands
Interesting equation. Some simple math, for some people. An equation that will take the Weapon’s Damage, Defence Points, and Armour Toughness to output a Damage value, right?
Idk tbh, I just want to be able to grab raw values
Like the values for Weapon’s Damage, Defence Points, and Armour Toughness, or a different value
block.dimension.spawnEntity("minecraft:xp", block.location) I assume would work
you can use a for loop if you want more than one orb
I'm confused why there's a comma though at the start of solving the equation 😅
These
It's a min max function.
Min and max has commas
Use a finite series function? 
Simple math functions in JavaScripts
Has anyone been having issues with custom command permissions not actually working? I've added several custom commands recently all with CommandPermissionLevel.Any, but only opped players are able to use them
It doesn't make any sense because my other commands made a while back have the same structure and can be used by anyone
show code
export const friendAddCommand = {
name: "rc:fadd",
description: "Sends a friend request to an online player.",
cheatsRequired: false,
permissionLevel: CommandPermissionLevel.Any,
mandatoryParameters: [
{
type: CustomCommandParamType.PlayerSelector, name: "player"
}
]
}```
idk :(
Neither do I
this game targets me with problems
only difference between this and the other custom commands that do work are that they are embedded several folders down in the file path
OP has been an ongoing battle for year's. Riddled with issues due to the complexity of the code under the hood. Which is why I still handle permissions the old fashion way and don't bother with registered custom commands for now. Personal preference and taste until I feel more comfortable about it.
I felt like that was the problem, lol
Damage taken after armor -> damage you would've taken without it
how much does obfuscation impact an addons performance
A waste of time. They are easily reversible.
I wouldn't EASILY, maybe if you know what you're doing you can get through it just fine but most of the bedrock skids don't even know whats going on
You would be surprised.
how come
Experience
I'm asking what you've seen and to what extent was the deobfuscation
Full code
Definitely
are you talking normal obfuscator.io code or things with custom obfuscators and such
The variable and function names might not be an exact match, letter for letter, but you can bet any amount of money it will be the same representation.
Once you read what the function does you can just use common sense to rename that function based on what it's doing.
okay but don't you think people who genuinely know what they're doing and are trying to deobfuscate your addon are not that common
It's very simple
I don't really see a point to it
AI has made it too easy these days.
can you send me an example of an instance where someone has done something on this scale
because I'm genuinely just not processing this 😭
People deobfuscate for a couple of known reasons. One, your code could be suspicious and since it's not monitored from the marketplace there is a level of faith and trust they probably lack from you and your pack. The other reason will be to know how your pack works, if something about it catches their interest.
is it not more productive to just make the addon themselves if they're going that far
You should search in here how often this discussion gets brought up. Lol.
I did search a bit wtf is the obfuscator and deobfuscator war 😭
When people can't see the code there is a level of trust that has to be established between the developer and the user. I don't run stuff on my system in the blind from a third party I do not know.
Definitely not for the better
Wouldn’t the damage taken without armour just be the attack damage of the weapon/tool?
Enchants:
Mace:
Spear:
And the resistance effect
True
So, plus some math based on speed and falling distance. Enchant is easy to do. Resistance on the other hand, I don’t know how much it reflects.
Resistance removes 20% of damage taken at each incremental level
Just feels like it would just be more efficient to reverse the damage formula than do all these checks
So resistance 5 is full invincibility
But you would need to check to get values for the formula
Just feed the engine how much damage you take and then apply stuff for armor and all that
Like tbh if I was going to account for mace and spear then I would also need to tackle explosion math, arrow velocity calcs and a edge case for fall damage too
Why do that when I can just read the damage I would take and then adjust for player conditions like what armor they're wearing
Then do that if you can
Its just reversing the min / max that's the problem
There is an alternative but then compatibility with other addons goes down the drain

Again if I don't mind my addon being a "main" addon then there is a very easy solution
But that's the problem, what if people want to combine it with other addons
What would that solution be?
Scan opened containers and inventory for armor pieces and replace them automatically with custom versions that have no protection value or enchantability
That would only affect Addons with custom armour, not all Addons. It would still have compatibility
I'd probably still get complaints
I can take a deeper look at this later if you still need help when I get home.
Tbh I'll probably just take the less compatible option
Have custom armor? Not supported
Hey, im sorry to bother you all
I wanna learn Scripting ill start next week
But rn
Could someone help me out with a script that does this
- Makes a player immune to all damage if they have a certain tag (if they dont have the tag they can take damage just like normal)
I know its a lot, but i would really appreciate the help 🙏🏻
It would also help me under how the code works as thats how I learn most things
God bless 🙌
Is there way to get the compass direction example I use compass on a loadstone I want to know if there's a property/component on that item where it save the location
there isn't, use player interact with block and save the location in the compass lore
Get started right now, why wait?
Ive got multiple businesses running, and exams for uni this month
Addon dev is just a hobby for now
import { world, Player } from "@minecraft/server";
const IMMUNE_TAG = "immune";
/**
* Cancels any incoming damage to players with IMMUNE_TAG.
*/
world.beforeEvents.entityHurt.subscribe((event) => {
const target = event.hurtEntity;
if (!(target instanceof Player)) return;
if (!target.hasTag(IMMUNE_TAG)) return;
event.cancel = true;
});```
EntityHurtBeforeEvent in beta is still unreal
Who thought we would live to an age where we get this
did they fix the bug where it still does knockback or no
If referring to EntityHurtBeforeEvent then I can confirm I didn't experience it earlier as I updated some of my code to utilize that event.
i believe its only with critting
i dont think its a bug, that would require entityHitEntity beforeEvent
if i have a entity that has a equippable at slot 0, how do i set that equippable via scripting?
like this?
system.runTimeout(() => {
if (!displayEnt.isValid) return;
const equippable = displayEnt.getComponent("minecraft:equippable");
if (equippable) {
equippable.setEquipment("Mainhand", new ItemStack("minecraft:diamond", 1));
}
}, 1);
ok because its not setting the item
but if i put something in the loot table it does have a item
@summer cloud the documentation says is only available for players
Well theres the inventory component, i dont know the context
yea i was aware of that, ill just try out stuff
You have to use /replaceitem
Goood
🙏
is GameTest intentionally freezes time? and disables mob spawning?
how can I add the optional parameter on only a specific enum mandatory parameter on custom commands
You cannot do this yet
Who stole the messages?
Me, I ate them