#I have a problem with the repair of my item

1 messages · Page 1 of 1 (latest)

dire sphinx
#
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 haven't found why my item can't be repaired?

uncut ember
dire sphinx
#
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}`);
    })
}
uncut ember
#

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}`);
    })
}
dire sphinx
#

ok th man

dire sphinx
uncut ember
#

Sure

dire sphinx
#
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);

}
dire sphinx
# uncut ember Sure

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

uncut ember
#

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}`);
});
dire sphinx
#

ah okay OK I think the meter inside would be better

uncut ember
#

Oh I just noticed that

#

Now its fixed

dire sphinx
# uncut ember Now its fixed

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

#

?

uncut ember
#

Let me see

dire sphinx
#
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;
    }
});
uncut ember
#

Why the space at the end?

dire sphinx
#

?

uncut ember
dire sphinx
#

because I in and one without and with

uncut ember
#

I didn't understand a thing

#

But anyways

dire sphinx
#

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

uncut ember
#
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;
    }
  });
});
dire sphinx
uncut ember
#

Common problem, let me fix that

dire sphinx
#

ok

uncut ember
#

Fixed

#

Don't forget to import system

dire sphinx
# uncut ember Don't forget to import `system`

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??

uncut ember
#

I will be honest, I didn't understand a thing of what you said

dire sphinx
uncut ember
#

You can get all the entities in the location that belongs to that block face

#

Only the ones that are 'minecraft:item'

dire sphinx
#

and the identities in question are items, it is possible ?

uncut ember
#

Are you trying to detect those items in specific situations?

dire sphinx
#

do you have a code to show me this because I wouldn't know how to do it?? if it doesn't bother you

uncut ember
#

For the example I need to know if you are trying to detect that item being on a block in specific situations or anytime

dire sphinx
uncut ember
#

Oh I get it

dire sphinx
#

all over the block stone example

uncut ember
#

Are you using scripts to move the items?

dire sphinx
#

no but I would like to do it

past gull
#

Not to bother you folks but.

dire sphinx
#

?

past gull
#

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

dire sphinx
#

frankly I'm not

dire sphinx
uncut ember
dire sphinx
past gull
uncut ember
#

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

past gull
#

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

dire sphinx
#

frankly if it works already very well

dire sphinx
uncut ember
#

item.getComponents()

past gull
#

Alright thanks folks

dire sphinx
dire sphinx
#

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}

})
uncut ember
#

Looks like there is no pistonActiveBeforeEvent anymore

dire sphinx
#

I looked in the learns but I think that's the problem, that's why I'm asking

dire sphinx
uncut ember
#

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

uncut ember
dire sphinx
#

OK I will look at that

uncut ember
#

Just change the 'your:machine_identifier' to that

dire sphinx
uncut ember
dire sphinx
#

yes

uncut ember
#

In the part where I typed // Do something you can check if (itemStack.typeId === 'minecraft:stone')

dire sphinx
#

another question how can I do that if a block poses it as an item generator??

dire sphinx
uncut ember
#

What are you trying to do?

dire sphinx
uncut ember
#

I don't fully understand what you write but I get what you want

dire sphinx
dire sphinx
uncut ember
#

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);

uncut ember
# dire sphinx

I can't see the errors when I write everything from discord

#

Let me fix that one

dire sphinx
uncut ember
#

Ok one last error

uncut ember
#

Also, you are checking if the item is stone but not doing anything

#

I'm surprised it is not showing any error

dire sphinx
#

I was actually going to ask the question how I can do so that when it happens it kills itself and generates another item?

dire sphinx
#
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
      }
    }
  });
dire sphinx
uncut ember
#

Why are you comparing it like that?

#

Ok change the content of the if statement to this:```js
if (itemreplace.includes(itemStack.typeId))

uncut ember
#

Why did you change the 1's to 0's?

dire sphinx
#

c so that its silk in the direction of the entrance to the block?

dire sphinx
uncut ember
#

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

dire sphinx
#

ha OK

dire sphinx
dire sphinx
#
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
uncut ember
#

block.location

#

For that, define the block variable first