#Add multi step recipes to existing scripts?

43 messages · Page 1 of 1 (latest)

lapis sun
#

So, i didn't want to open a thread just for this but my brain is almost exploding, i have this script that receives a specified item and returns a specified output when fed to a mob, the thing i want to implement is multiple inputs to a single output, help?

SCRIPT :

ItemEvents.entityInteracted((event) => {
    const {item, hand, target, level, server} = event

    /**
     * Feeds a mob with a specific input item and drops the specified output item.
     * @param {string} mob - The type of mob to feed.
     * @param {number} input - The ID of the input item.
     * @param {number} output - The ID of the output item.
     * @param {number} [amount=1] - The amount of output items to drop (default is 1).
     */
    let basic_feeding = (mob, input, output, amount) =>{
        amount = amount ?? 1
        const {x, y, z} = target
        if(
            target.type == mob && 
            hand == 'main_hand' && 
            item.id == input
          ){
                item--
                target.playSound('entity.item.pickup', 0.3, 1)
                target.playSound('entity.fox.bite', 0.8, 1)
                server.runCommandSilent(`execute in ${level.dimension} positioned ${x} ${y + 0.5} ${z} run particle minecraft:cloud ~ ~ ~ 0.2 0.2 0.2 0.001 30`)
                level.getBlock(x, y, z).popItem(Item.of(output, amount))
        }
    }

    basic_feeding('minecraft:pig', 'minecraft:iron_ingot', 'minecraft:copper_ingot', 3)
})
crystal groveBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

hallow burrow
#

you want it to be fed multiple items (lets say, 3 iron ingots) to then output 1 (or amount) copper ingots?

lapis sun
#

yeah, but with different items

#

like one apple, one iron ingot to then output a copper ingot

hallow burrow
#
    
    let recipes = {
      'minecraft:copper_ingot': {
          output: 'minecraft:copper_ingot',
          amount: 1,
          input: ['minecraft:iron_ingot', 'minecraft:apple']
      }
  }

ItemEvents.entityInteracted((event) => {
  const {item, hand, target, level, server} = event


  let basic_feeding = (mob, recipe) =>{
      const {x, y, z} = target
      

      let pData = target.persistentData
      if(!pData.eaten) pData.eaten = {}

      if(recipe.input.includes(item.id) && !pData.eaten[item.id]){
          pData.eaten[item.id] = true
          item.count--
      }

      let eatenAll = true
      recipe.input.forEach((input) => { 
          if(!pData.eaten[input]) eatenAll = false
      })

      if(eatenAll){
          pData.eaten = {}
          target.playSound('entity.item.pickup', 0.3, 1)
          target.playSound('entity.fox.bite', 0.8, 1)
          server.runCommandSilent(`execute in ${level.dimension} positioned ${x} ${y + 0.5} ${z} run particle minecraft:cloud ~ ~ ~ 0.2 0.2 0.2 0.001 30`)
          level.getBlock(x, y, z).popItem(Item.of(recipe.output, recipe.amount))
      }
  }
  basic_feeding('minecraft:pig', recipes['minecraft:copper_ingot'])
})```
lapis sun
#

i love you so much

#

fr

#

thank you so much

hallow burrow
#

this basiclly keeps track of what input items there are; and only allows them inside the pig once

#

can be conflicty if u have recipes that both take apples for example

lapis sun
#

thx for the warning

#

you're getting a special place in my modpack

#

🙏

hallow burrow
#

for example:

  let recipes = {
    'minecraft:copper_ingot': {
        output: 'minecraft:copper_ingot',
        amount: 1,
        input: ['minecraft:iron_ingot', 'minecraft:apple']
    },
    'minecraft:copper_block': {
      output: 'minecraft:copper_block',
      amount: 1,
      input: ['minecraft:iron_block', 'minecraft:apple']
  }
}```
#

if u do this; and give the pig an ingot and a block

#

whatever u have set first will trigger first

lapis sun
#

it's conflicty cuz you can do it in any order you'd like right?

hallow burrow
#
basic_feeding('minecraft:pig', recipes['minecraft:copper_ingot'])
basic_feeding('minecraft:pig', recipes['minecraft:copper_block'])```
#

oh actually

lapis sun
#

weird

#

is it due to the same item being used in both recipes or is it just like that?

hallow burrow
#

yea

#

this makes it a bit better>


const recipes = {
  'minecraft:copper_ingot': {
    output: 'minecraft:copper_ingot',
    amount: 1,
    input: ['minecraft:iron_ingot', 'minecraft:apple']
  },
  'minecraft:copper_block': {
    output: 'minecraft:copper_block',
    amount: 1,
    input: ['minecraft:iron_block', 'minecraft:apple']
  }
}

ItemEvents.entityInteracted((event) => {
  const { item, hand, target, level, server } = event


  let basic_feeding = (mob, recipe) => {
    const { x, y, z } = target

    if (hand != 'MAIN_HAND') return

    let pData = target.persistentData
    if (!pData.eaten) pData.eaten = {}

    if (recipe.input.includes(item.id) && !pData.eaten[item.id]) {
      pData.eaten[item.id] = true
      item.count--
    }

    let eatenAll = true
    recipe.input.forEach((input) => {
      if (!pData.eaten[input]) eatenAll = false
    })

    if (eatenAll) {
      server.schedule(1, () => {
        recipe.input.forEach((input) => { pData.eaten[input] = false })
        target.playSound('entity.item.pickup', 0.3, 1)
        target.playSound('entity.fox.bite', 0.8, 1)
        server.runCommandSilent(`execute in ${level.dimension} positioned ${x} ${y + 0.5} ${z} run particle minecraft:cloud ~ ~ ~ 0.2 0.2 0.2 0.001 30`)
        level.getBlock(x, y, z).popItem(Item.of(recipe.output, recipe.amount))
      })

    }
  }
  basic_feeding('minecraft:pig', recipes['minecraft:copper_ingot'])
  basic_feeding('minecraft:pig', recipes['minecraft:copper_block'])
})```
#

scheduling it by 1ms will allow the apple to be properly removed; but if u give it an ingot and block first, and then an apple, it will still drop both items

lapis sun
#

shouldn't be much of a problem if i use very different items right?

hallow burrow
#

nope 🙂

lapis sun
#

there's just one thing that's confusing me

#

you're asking for a mob parameter

#

but i don't see it being used on the function itself

hallow burrow
#

oh true

#

derp

lapis sun
#

you didn't add it or am i going crazy?

#

at this point i don't even know xd

hallow burrow
#

i forgot

#

just add:
if (target.type != mob) return before the if(hand != 'MAIN_HAND') return

lapis sun
#

thx

#

appreciated

hallow burrow
lapis sun
#

🙏