#How would I make a Chest Shop form-ui
1 messages · Page 1 of 1 (latest)
use ItemUseOn in beforeEvent
but you will need an item in the player's mainhand to achieve this
this is the nth time im saying this in this server lmao
1.20 broke it
then ```js
if (player.getComponent("minecraft:inventory").container.getItem(player.selectedSlot)) return;
ItemUseOn will only subscribe if a player used an item
#cancel-1.20
it wont detect interactions anymore with mainhand
This ruined my warp system
Minecraft Update be like:
removed useful things
renamed beforeEvents to BefOreEvEnTs
yea and it ruined my land claim and chest shop addon
changed 834120 things
moved MinecraftEnchantmentTypes to @minecraft/vanilla-data
made y'all forms in beforeEvents not work
made some methods not avaliable without system.run
added some 'features which gonna be removed in future updates'
lmao
i wish they have an option to retrieve the previous script api version
We all
@bitter barn do u know the script
not possible at this moment
Oh
cuz the only event that made it possible is bugged rn
also to spawn chest minecart u have to do this in system.run so double cancel
if its okay with you, you can use left click instead (by punching the chest)
Ok
@slim warren wait so u know the script
It’s fine if u don’t
Well I guess now one knows
@slim warren
Would u know how to make a villager shop form-ui
it's ez
world.afterEvents.entityHit.subscribe(je => {
if (je.hitEntity) return
let hitBlock = je.hitBlock
let player = je.entity
if (!(player instanceof Player)) return
if (hitBlock.typeId?.endsWith('chest') {
//your form code
}
)
just detect the hit
why je?
jamalEruption?
@slim warren is that for villager shop
or just destructure it early
world.afterEvents.entityHit.subscribe({hitEntity, hitBlock, entity} => {
...
})```
wdym
its for chest thing that you asked for
Oh Ty
ye
but you need to punch the chest there
Ok np
But would I use
world.afterEvents.entityHit.subscribe({hitEntity, hitBlock, entity} = > {
//Everything else
})
if thats what you will use then you need to edit some in the code
Ok I might not use that then…
What would the import be
Import { something } from ‘@minecraft/server’
world.afterEvents.entityHit.subscribe(({hitEntity, hitBlock, entity}) => {
let player = entity
if (!(player instanceof Player)) return
if (hitBlock?.typeId == "your:chosen_block") {
//your form code
}
if (hitEntity?.typeId == "your:chosen_entity") {
//your form code
}
}
)
just world
What do I put for your: and chosen_entity
just id of entity
when they gonna be under attack
example villager
So “your:villager” for example
Oh
for chest it will be "minecraft:chest"
Sry I forget stuff sometimes
np broski
There’s already an error
what is it
entity} =>
It doesn’t like =>
Idk why
Hello?
@slim warren
Anyone
….
It works if I just do = or ==
just tested it
and yep
?
Still doesn’t I’ll send on different account
Can u help pls
thats wrong
What is it
world.afterEvents.entityHit.subscribe(({hitEntity, hitBlock, entity}) => {
world.afterEvents.entityHit.subscribe(({ hitBlock, hitEntity, entity }) => {
});
Also what do I put for your:chosen_block
here
So what is your:chosen_entity
id of entity
its your chosen entity
depending on what you need
modify the code depending on your need
So minecraft:chest
yes, thats what you will put in your chosen block
just replace it with id of entity
Oops
I didn’t mean to do that
So
I would do
if (hitEntity.typeId == “minecraft:zombie”) for example
yes
How would that be useful tho
And also what would I do for the hitBlock form code and the hitEntity form code
Which one is for the ui menu
@bitter barn
What is ‘selectg’
Wdym “select one of them”
So I don’t need entity
then remove if with entity
Can u just show me what it would look like
world.afterEvents.entityHit.subscribe(({ hitBlock, hitEntity, entity }) => {
if (hitBlock.typeId == 'minecraft:chest') {
// ur code here
};
});
So I don’t need if (!(player instance of Player)) return or let player = entity
yes
Ok ty
let form4 = new ui.ActionFormData()
@slim warren
Nvm but it’s not working
@bitter barn
@bitter barn
@bitter barn
PLS ANYONE
what is it
please state the problem, not just "its not working"
Ok
Ok
``import { world } from '@minecraft/server'
import { ActionFormData } from '@minecraft/server-ui'
import * as ui from '@minecraft/server-ui'
let form4 = new ui.ActionFormData()
world.afterEvents.entityHit.subscribe(({hitBlock}) => {
if (hitBlock?.typeId == "minecraft:chest") {
form4.title("Bombie Shop")
form4.body("This is the Shop")
}
})``
why do you have multiple imports of actionformdata
ill try it on my world hold on
Ok
import { world } from '@minecraft/server';
import * as ui from '@minecraft/server-ui';
world.afterEvents.entityHit.subscribe(({hitBlock, entity}) => {
if (hitBlock?.typeId == "minecraft:chest") {
const form = new ui.ActionFormData()
.title("Bombie Shop")
.body("This is the Shop")
.button(``) // button is required in this type of form
.show(player).then((resultData) => {
});
};
});
fixed
oh yeah, he didnt put a button
- button is required
- he forgot to
.show() - he forgot to add
entitycuz he has to show it to someone - double import
lmao
Lol
what i was supposted to do guys
blame at their code, then insult his entire family and challenge him 1v1 on the hive?
Error
send error
Ok
What have I done wrong
Ty
np
Then if u do a chest form
U know how to make like a villager form ui
When u click on it, it opens a ui menu
we already sent the code earlier
here
So it’s
world.afterEvents.hitEntity.subscribe(({hitEntity, entity}) => {
if (hitEntity?.typeId == “minecraft:chest”) {
const form = new ui.ActionFormData()
//code Here
@slim warren
Or is it wrong
There is an error in this [code](#1119978445032669224 message):
[36m<repl>.js[0m:[33m10[0m:[33m15[0m - [31merror[0m[30m TS2304: [0mCannot find name 'player'.
[7m10[0m .show(player).then((resultData) => {
[7m [0m [31m ~~~~~~[0m
ik
chest is not an entity, change it to the id of your desired entity
ye
to set which chest
and is there someway I can add a specific data to it
test for xyz
what will it look like
if (hitBlock.x == x && hitBlock.y == y && hitBlock.z == z && hitBlock.typeId == "minecraft:chest")
ok ty
wait
im trying to do it with a villager
heres the code
`` import { world } from '@minecraft/server'
import * as ui from '@minecraft/server-ui'
world.afterEvents.entityHit.subscribe(({hitEntity, entity}) => {
if (hitEntity?.typeId == "minecraft:chest") {
const form4 = new ui.ActionFormData()
.title("VIP Room")
.body("Tp to The VIP Room")
.button(Tp, 'textures/items/ender_pearl') // button is required in this type of form
.show(entity).then((resultData) => {
})
}
}) ``
I might of done something wrong
do you think minecraft:chest is villager
import { world } from '@minecraft/server'
import * as ui from '@minecraft/server-ui'
world.afterEvents.entityHit.subscribe(({hitEntity, entity}) => {
if (hitEntity?.typeId == "minecraft:villager") {
const form4 = new ui.ActionFormData()
.title("VIP Room")
.body("Tp to The VIP Room")
.button(`Tp`, 'textures/items/ender_pearl') // button is required in this type of form
.show(entity).then((resultData) => {
})
}
})
it should work rn'
still doesnt work
no error code
is it the type.Id
look cause this is my code:
``import { world } from '@minecraft/server'
import * as ui from '@minecraft/server-ui'
world.afterEvents.entityHit.subscribe(({hitEntity, entity}) => {
if (hitEntity?.typeId == "minecraft:villager") {
const form4 = new ui.ActionFormData()
.title("VIP Room")
.body("Tp to The VIP Room")
.button(Tp, 'textures/items/ender_pearl') // button is required in this type of form
.show(entity).then((resultData) => {
})
}
}) ``
so is it not possibe
or should i just add it to the chest shop one
import { world } from '@minecraft/server'
import * as ui from '@minecraft/server-ui'
world.afterEvents.entityHit.subscribe((eventData) => {
const player = eventData.entity
const hit = eventData.hitEntity
if (!hit) return;
if (hit.typeId == "minecraft:villager") {
new ui.ActionFormData()
.title("VIP Room")
.body("Tp to The VIP Room")
.button(`Tp`, 'textures/items/ender_pearl')
.show(player).then((resultData) => {
})
}
})
it should work
it says hitEntity is not defined
There are 7 errors in this [code](#1119978445032669224 message):
[36m<repl>.js[0m:[33m4[0m:[33m39[0m - [31merror[0m[30m TS2304: [0mCannot find name 'eventData'.
[7m4[0m world.afterEvents.entityHit.subscribe(eventData) => {
[7m [0m [31m ~~~~~~~~~[0m
``````ansi
[36m<repl>.js[0m:[33m4[0m:[33m50[0m - [31merror[0m[30m TS1005: [0m';' expected.
[7m4[0m world.afterEvents.entityHit.subscribe(eventData) => {
[7m [0m [31m ~~[0m
``````ansi
[36m<repl>.js[0m:[33m5[0m:[33m20[0m - [31merror[0m[30m TS2304: [0mCannot find name 'eventData'.
[7m5[0m const player = eventData.entity
[7m [0m [31m ~~~~~~~~~[0m
``````ansi
[36m<repl>.js[0m:[33m6[0m:[33m17[0m - [31merror[0m[30m TS2304: [0mCannot find name 'eventData'.
[7m6[0m const hit = eventData.hitEntity
[7m [0m [31m ~~~~~~~~~[0m
``````ansi
[36m<repl>.js[0m:[33m8[0m:[33m9[0m - [31merror[0m[30m TS2304: [0mCannot find name 'hitEntity'.
[7m8[0m if (hitEntity.typeId == "minecraft:villager") {
[7m [0m [31m ~~~~~~~~~[0m
``````ansi
[36m<repl>.js[0m:[33m13[0m:[33m15[0m - [31merror[0m[30m TS2304: [0mCannot find name 'entity'.
[7m13[0m .show(entity).then((resultData) => {
[7m [0m [31m ~~~~~~[0m
``````ansi
[36m<repl>.js[0m:[33m17[0m:[33m2[0m - [31merror[0m[30m TS1128: [0mDeclaration or statement expected.
[7m17[0m })
[7m [0m [31m ~[0m
wrong syntax
There is an error in this [code](#1119978445032669224 message):
[36m<repl>.js[0m:[33m13[0m:[33m15[0m - [31merror[0m[30m TS2345: [0mArgument of type 'Entity' is not assignable to parameter of type 'Player'.
Type 'Entity' is missing the following properties from type 'Player': level, name, onScreenDisplay, selectedSlot, and 16 more.
[7m13[0m .show(player).then((resultData) => {
[7m [0m [31m ~~~~~~[0m
so what is correct
import { world } from '@minecraft/server'
import * as ui from '@minecraft/server-ui'
world.afterEvents.entityHit.subscribe((eventData) => {
const player = eventData.entity
const hit = eventData.hitEntity
if (!hit) return;
if (hit.typeId == "minecraft:villager") {
new ui.ActionFormData()
.title("VIP Room")
.body("Tp to The VIP Room")
.button(`Tp`, 'textures/items/ender_pearl')
.show(player).then((resultData) => {
})
}
})
that's the same
corrected syntax
did u hit villager?
yes
There is an error in this [code](#1119978445032669224 message):
[36m<repl>.js[0m:[33m13[0m:[33m15[0m - [31merror[0m[30m TS2345: [0mArgument of type 'Entity' is not assignable to parameter of type 'Player'.
Type 'Entity' is missing the following properties from type 'Player': level, name, onScreenDisplay, selectedSlot, and 16 more.
[7m13[0m .show(player).then((resultData) => {
[7m [0m [31m ~~~~~~[0m
well do u know a one that u right click instead of hit
import { world } from '@minecraft/server'
import * as ui from '@minecraft/server-ui'
world.afterEvents.entityHit.subscribe((eventData) => {
const player = eventData.entity
const hit = eventData.hitEntity
if (!hit) return;
if (hit.typeId == "minecraft:villager") {
if (entity instanceof Player) {
new ui.ActionFormData()
.title("VIP Room")
.body("Tp to The VIP Room")
.button(`Tp`, 'textures/items/ender_pearl')
.show(player).then((resultData) => {
})
};
}
})
ye npc
try this.
it doesnt work..
if u know the clickable one then do that one pls
cause it seems like theres no luck
@bitter barn
do u know the script for the clickable one
i know, but you're beggin for a lot of code rn
ik and im sry
im trying to build a server
and it will help if u can help me
but if u feel like ur being pressured, I understand....
no, I am just too lazy to do this rn
ok
well when u are ready, just send cause i might not be there when u are ready
for now, ill just try on my own
ok
how tf is ur shop 3k lines
cant u then copy and paste
well the actual algorithm will be like 30 lines
my server
do you want a shop?
what villager
well yea
tell me what you want
I’ll make it for you and you can just edit the items inside of it
and prices etc
Ok do you know javascript a little
ye ik
do you know objects
wdym objects
const object = {“test”: 5}```
no. is that bad idk that?
ok
I will try make it as understandable as possible
ok
?
you don't get it?
No
Ohhhhh
People who use script api skip learning javascript
very true
yes
it's like 20/25% of the people
or are on the server just to get free scripts
true
when smelly has released his goofy chat ranks
official bedrock scripting api got more people just to get scripts than actual developers XD
so am I going to know the script or not
wdym?
cause @bitter barn said he will tell me thecode
I just needed to update it
ok
const armours =
[
{name: "Leather", cost: 10000, icon: "textures/items/leather_chestplate", structure: "LeatherSet"},
{name: "Chain", cost: 25000, icon: "textures/items/chainmail_chestplate", structure: "ChainSet"},
{name: "Iron", cost: 50000, icon: "textures/items/iron_chestplate", structure: "IronSet"},
{name: "Diamond", cost: 100000, icon: "textures/items/diamond_chestplate", structure: "DiamondSet"},
{name: "Netherite", cost: 250000, icon: "textures/items/netherite_chestplate", structure: "NetheriteSet"}
]
const swords =
[
{ name: "Wooden sword", cost: 5000, icon: "textures/items/wood_sword", structure: "woodSword"},
{ name: "Stone sword", cost: 10000, icon: "textures/items/stone_sword", structure: "stoneSword"},
{ name: "Iron sword", cost: 25000, icon: "textures/items/iron_sword", structure: "ironSword"},
{ name: "Diamond sword", cost: 50000, icon: "textures/items/diamond_sword", structure: "diamondSword"},
{ name: "Netherite sword", cost: 100000, icon: "textures/items/netherite_sword", structure: "netheriteSword"}
]
export function getScore(target, objective, useZero = true) {
try {
const oB = world.scoreboard.getObjective(objective);
if (typeof target == "string")
return oB.getScore(
oB.getParticipants().find((pT) => pT.displayName == target)
);
return oB.getScore(target.scoreboard);
} catch {
return useZero ? 0 : NaN;
}
}
world.afterEvents.entityHit.subscribe(e => {
const player = world.getAllPlayers().find(p => p.name === e.entity.nameTag)
console.warn(e.hitEntity.typeId)
if(e.hitEntity?.typeId.includes("minecraft:villager"))
{
return shopUI(player)
}
})
function shopUI(player){
const form = new ActionFormData()
.title("Shop Menu")
.button(`Armour`)
.button(`Swords`)
form.show(player).then(r => {
switch(r.selection)
{
case 0:
return armourUI(player)
case 1:
return swordUI(player)
}
})
}
function armourUI(player)
{
const form = new ActionFormData()
.title("Armour shop")
for(let i = 0; i < armours.length; i++){
form.button(`${armours[i].name}\nCost: ${armours[i].cost}`, `${armours[i].icon}`)
}
form.show(player).then(r => {
const {x,y,z} = player.location
if(getScore(player.name, "Money") >= armours[r.selection].cost)
{
player.sendMessage(`Purchase successful`)
return world.getDimension('overworld').runCommandAsync(`structure load ${armours[r.selection].structure} ${x} ${y} ${z}`)
}
})
}
function swordUI(player)
{
const form = new ActionFormData()
.title("Sword shop")
for(let i = 0; i < swords.length; i++){
form.button(`${swords[i].name}\nCost: ${swords[i].cost}`, `${swords[i].icon}`)
}
form.show(player).then(r => {
const {x,y,z} = player.location
if(getScore(player.name, "Money") >= swords[r.selection].cost)
{
player.sendMessage(`Purchase successful`)
return world.getDimension('overworld').runCommandAsync(`structure load ${swords[r.selection].structure} ${x} ${y} ${z}`)
}
})
}```
done
@ancient apex
bro u were bored af
I was
I still am
It took like what 5-10 mins
so
ye ik
I didnt even test it
might work
i would never do these amounts of code for free xd

No errors in [code](#1119978445032669224 message)
@timber pollen Is that purple icon actually in floating above the chest or is that an invisible item frame?
floating
How'd you do that?
await null is cool
not rly
why not
wdym
what
idk too
The chest is an entity 💀??
technically yes, but no
So that's is true ?
no
chest is counted as block. but it has some of enttiy inside itself
import { world } from '@minecraft/server'
import { ActionFormData } from '@minecraft/server-ui'
cool, this yours?
what? no, its a block
sort of, ig, but its hard coded so its really a block
Because in the cod i see entityHit because that's
no, it returns back if the event target that is being hit is an entity
if (je.hitEntity) return
ye
cool, i also used that thing on my keycrates
can i see
also what thing
the usage of entity's mainhand to display an item
what's the use of that?
looks very nice
but how can you make the block floating right
and the tools too
very cool
i know you use mainhand
took a long trial and error to align those things
wait it has different rotation for type of items?
that alignment stressed me out for almost a month, just to get the right offset and rotation
yeah, im using a preanimation scripts for animation controller
yea i also had that before, and it looked like this
#1078896624136364032 message
real
me too
its kinda hard to position the block
mind giving :>
jkjk
i used Invisible Item Frame addons to see the item rotation values lol
i cant tho, the rotations and things are dependent on my entity's model, its like hardcoded to my keycrates addon
oh yea thats true
nah they fix it
it was no sense to trigger itemUseOn item event with no item
yeah that's why its called ItemUseOn
is it confirmed that they will add an interaction event thing
not very confirmed but its in a plan
air is item too broski
look
you can have this in your arms?
yes
do you can pick it up?
yes
so it's an item
nah, empty hand and air is still different
you can give via nbt air but other slots are empty
In an async function await null moves the function out of the current js frame
can it be use in beforeEvents
Yes
You cant use the event arg after
You have to assign everything you need or cancel before you call await null; in the async callback
so like
world.beforeEvents.something.subscribe(async event => {
event.cancel = true
const player = event.source
await null
//then the rest of the code without privilege, like:
player.name = "hello"
})
await null;
That will wait 10 tick await null; is only one tick or js frame haven’t test it exactly but it works
oh, nice, ill use it instead of system run
player.nameTag
yeah i know, its just an example
we can't change player names, only their nametags
yep
What if only 1 entry?
then only use what you need, if you only need hitentity then remove hitblock
Oh okay thanks