function fix(player){
new ActionFormData()
.title(`Fix`)
.button('Repair Item Main Hand')
.show(player).then(r => {
if (r.cancelationReason == `UserBusy`) return fix(player);
if (r.canceled) return
const Item = player.getComponent('minecraft:inventory').container.getItem(player.selectedSlot)
if (!Item) return;
const inv = Item.getComponent('durabilité').damage = 0
inv.setItem(player.selectedSlot, Item)
player.sendMessage(`you to repair: ${Item}`);
})
}
#I have a problem with the repair of my item
1 messages · Page 1 of 1 (latest)
The component id is durability
function fix(player){
new ActionFormData()
.title(`Fix`)
.button('Repair Item Main Hand')
.show(player).then(r => {
if (r.cancelationReason == `UserBusy`) return fix(player);
if (r.canceled) return
const inv = player.getComponent('minecraft:inventory').container.getItem(player.selectedSlot)
const Item = Item.getComponent('durability').damage = 0
if (!Item) return;
inv.setItem(player.selectedSlot, Item)
player.sendMessage(`you to repair: ${Item}`);
})
}
Check what your inv variable is
Its not the player container
function fix(player){
new ActionFormData()
.title(`Fix`)
.button('Repair Item Main Hand')
.show(player).then(r => {
if (r.cancelationReason == `UserBusy`) return fix(player);
if (r.canceled) return;
const inv = player.getComponent('inventory').container;
const Item = inv.getItem(player.selectedSlot)
if (!Item) return;
Item.getComponent('durability').damage = 0
inv.setItem(player.selectedSlot, Item);
player.sendMessage(`you to repair: ${Item}`);
})
}
ok th man
I have another code that doesn't work, could you help me?
Sure
function LogsChat(player){
let chat = [];
world.beforeEvents.chatSend.subscribe((eventData) => {
const player = eventData.sender;
const message = eventData.message
chat.push(`${player} - ${message}`);
});
new ActionFormData()
.title(`Logs`)
.body(chat.join("\n"))
.button("Left")
.show(player);
}
My stumbling block is when someone writes in the chat and marks it in a menu to see who writes it but it doesn't work
You are defining the chat variable again every time you call the function
You need to define it outside the function
const chat = [];
function LogsChat(player){
new ActionFormData()
.title(`Logs`)
.body(chat.join("\n"))
.button("Left")
.show(player);
}
world.beforeEvents.chatSend.subscribe((eventData) => {
const player = eventData.sender;
const message = eventData.message
chat.push(`${player.name} - ${message}`);
});
ah okay OK I think the meter inside would be better
sorry if I bother you but I have other problems can you tell me what the error is because I searched everywhere and couldn't find it so I need help
?
Let me see
world.beforeEvents.chatSend.subscribe((eventData) => {
const player = eventData.sender;
switch (eventData.message) {
case '-heal ':
eventData.cancel = true;
const health = player.getComponent('health');
health.setCurrentValue(health.effectiveMax || 20);
player.sendMessage('Healed!');
break;
}
});
Why the space at the end?
?
There is a space after -heal
because I in and one without and with
because it tells me I don't have the privileges I did a system run it didn't work so I don't know how to do it
world.beforeEvents.chatSend.subscribe((data) => {
const player = data.sender;
if (!data.message.startsWith('-')) return;
data.cancel = true;
const [cmd, ...args] = data.message.slice(1).toLowerCase().split(/ +/g);
system.run(() => {
switch (cmd) {
case 'heal':
const health = player.getComponent('health');
health.setCurrentValue(health.effectiveMax || 20);
player.sendMessage('Healed!');
break;
}
});
});
?
Common problem, let me fix that
ok
yes it and import and I have small questions is it possible to execute if I detect an item from a north face of a block and it kills me plus make it spawn an item from a south face??
I will be honest, I didn't understand a thing of what you said
possible to detect an item on one side of a block and spawn another item on another side of the block
You can get all the entities in the location that belongs to that block face
Only the ones that are 'minecraft:item'
and the identities in question are items, it is possible ?
Are you trying to detect those items in specific situations?
do you have a code to show me this because I wouldn't know how to do it?? if it doesn't bother you
For the example I need to know if you are trying to detect that item being on a block in specific situations or anytime
Oh I get it
all over the block stone example
Are you using scripts to move the items?
no but I would like to do it
Not to bother you folks but.
?
I would like to know if you can copy items and save them like in an object
Here seemed pretty close to the question since you had a problem with repairing items so yea I thought this would be the best time to ask this question
frankly I'm not
look at the tags of the post
Maybe with Object.entries(item)
sorry I misunderstood your question sorry
Question and beta APIs that's what I said
const dimensions = [
world.getDimension('overworld'),
world.getDimension('nether'),
world.getDimension('the_end')
]
system.runInterval(() => {
for (const dimension of dimensions) {
for (const entity of dimension.getEntities({ type: 'minecraft:item' })) {
const item = entity.getComponent('item');
if (!item) continue;
const itemStack = item.itemStack;
const { x, y, z } = entity.location;
const blocks = [
dimension.getBlock({ x, y, z: z - 1 }),
dimension.getBlock({ x, y, z: z + 1 }),
dimension.getBlock({ x: x - 1, y, z }),
dimension.getBlock({ x: x + 1, y, z })
];
const machine = blocks.find(b => b?.typeId === 'rm:industrial_furnace');
if (!machine) continue;
if (itemStack.typeId === 'minecraft:stone') {
entity.remove();
dimension.spawnItem(new ItemStack('your:new_item'), { x, y, z });
}
}
}
});
This is the only way I could think of
I'm sure there are other faster ways
No wait, I just noticed something
I know you can get an items enchants, lore, typeId, amount, nametag, but how would you get the tags or other components also idk how to get durability
frankly if it works already very well
item.getTags()
Item.getComponent('durability')
item.getComponents()
I wanna get durability not set it
Alright thanks folks
I'm testing the code to see if there are any problems and a small question: someone gave me a script that worked before but now it doesn't work anymore. Could you see if it doesn't bother you?
Now its better
Let me check it
world.beforeEvents.pistonActivate.subscribe((p)=>{
const {block,isExpanding,piston} = p
let loc = piston.getAttachedBlocks()[0]
if (!loc) return;
let pushed_block = block.dimension.getBlock(loc).typeId
if (pushed_block == "rm:grass_umbreakable") {p.cancel = true}
if (pushed_block == "rm:industrial_furnace") {p.cancel = true}
if (pushed_block == "rm:iron_generator") {p.cancel = true}
if (pushed_block == "rm:convoyers") {p.cancel = true}
})
Looks like there is no pistonActiveBeforeEvent anymore
I looked in the learns but I think that's the problem, that's why I'm asking
how do I make it work with an item (minecraft:stone)?
There is no way to cancel the event anymore, maybe detecting wich way the blocks have been moved and setting them again in their place
Stone as the machine block?
OK I will look at that
Just change the 'your:machine_identifier' to that
Only stone items?
yes
In the part where I typed // Do something you can check if (itemStack.typeId === 'minecraft:stone')
Fixed
?
What are you trying to do?
I would like to generate items when it blocks and poses as in the photo
I don't fully understand what you write but I get what you want
I am looking to generate items like in the photo
You can spawn items with ```js
const dimension = world.getDimension('overworld') // Or any other dimension you want
dimension.spawnItem(new ItemStack('minecraft:raw_iron'), location);
I can't see the errors when I write everything from discord
Let me fix that one
Fixed
Ok one last error
Fixed
Also, you are checking if the item is stone but not doing anything
I'm surprised it is not showing any error
I was actually going to ask the question how I can do so that when it happens it kills itself and generates another item?
?
const itemreplace =[
"minecraft:stone"
]
const dimensions = [
world.getDimension('overworld'),
world.getDimension('nether'),
world.getDimension('the_end')
]
system.runInterval(() => {
for (const dimension of dimensions) {
for (const entity of dimension.getEntities({ type: 'minecraft:item' })) {
const item = entity.getComponent('item');
if (!item) continue;
const itemStack = item.itemStack;
const { x, y, z } = entity.location;
const blocks = [
dimension.getBlock({ x, y, z: z - 1 }),
dimension.getBlock({ x, y, z: z + 1 }),
dimension.getBlock({ x: x - 1, y, z }),
dimension.getBlock({ x: x + 1, y, z })
];
const machine = blocks.find(b => b?.typeId === 'rm:industrial_furnace');
if (!machine) continue;
if (itemStack.typeId === 'minecraft:stone');
// Do something
}
}
});
Added it
Why are you comparing it like that?
Ok change the content of the if statement to this:```js
if (itemreplace.includes(itemStack.typeId))
Why did you change the 1's to 0's?
c so that its silk in the direction of the entrance to the block?
why not change it?
Why change it?
If you change it, it won't detect the block at the side
It will detect the block at the same coordinate
So if the item is not completely inside the block, it won't detect it
ha OK
possible that when it spawns it is tp ^^^2 for who goes to the other side of the block?
world.beforeEvents.playerPlaceBlock.subscribe(event => {
const {x,y,z} = event.location
const block = event.block;
const player = event.sender;
log.push(`${player} - Block : ${block} Loc : ${x,y,z}`)
})
```@uncut embermy block it does not recover the block and the location
Get location from block
block.location
For that, define the block variable first