#Custom Parameters

1 messages · Page 1 of 1 (latest)

wooden atlas
#

Parameters in custom components only work in some events?
I just tested it in onPlace to detect numeric values, but I'm getting an error, NaN or undefined

torpid hedge
#

could you send your block json and script?

wooden atlas
# torpid hedge could you send your block json and script?
JSON
{
  "format_version": "1.21.90",
  "minecraft:block": {
    "description": {
      "identifier": "bd:test_1",
      "menu_category": {
        "category": "items"
      }
    },
    "components": {
      "bd:test": {
        "slot_1": 1,
        "slot_2": 1,
        "slot_3": 1,
        "slot_4": 1
      },
      "minecraft:destructible_by_mining": {
        "seconds_to_destroy": 1
      },
      "minecraft:geometry": {
        "identifier": "geometry.block"
      },
      "minecraft:material_instances": {
        "*": {
          "texture": "bd:test",
          "render_method": "opaque"
        }
      },
      "minecraft:destruction_particles": {
        "texture": "bd:test"
      },
      "minecraft:collision_box": true,
      "minecraft:selection_box": true
    }
  }


JS

import { BlockPermutation, ItemStack } from '@minecraft/server';
import { itemInteract, decrementStack } from './utils';
export class test1 {
  onPlace({ block, dimension, player }, { params }) {
    if (block.typeId == 'bd:baking_pan') return;
    const slot1 = params.slot_1;
    const slot2 = params.slot_2;
    const slot3 = params.slot_3;
    const slot4 = params.slot_4;
    console.log(slot1)
    block.setPermutation(BlockPermutation.resolve('bd:test_2', {
      "bd:slot1": slot1,
      "bd:slot2": slot2,
      "bd:slot3": slot3,
      "bd:slot4": slot4
    }));
  }
}
torpid hedge
#

what does the console.log(slot1) display in the content log

wooden atlas
#

Undefined or NaN

verbal token
#

Are you sure you're using V2?

wooden atlas
#

I tested this with the onPlayerInteract event and it works perfectly

#

But with this onPlace event it doesn't work, it shows undefined

verbal token
#

looks like something impossible

#

try logging the whole params variable

#
console.log(JSON.stringify(params))
wooden atlas
#

I'll try

wooden atlas
verbal token
wooden atlas
#

Maybe it doesn't work in all events? Or maybe it's a bug, or maybe I'm doing something wrong

verbal token
#

Because then when trying to get the slot_1 property it would give an error

torpid hedge
#

you're definitely placing the test_1 block?

wooden atlas
#

when the block bd:test_1 is placed, it should detect the numeric parameter values and transform into a different block, changing its states based on those parameter values

#

Does this work for you?

verbal token
#

Can you show the whole code?

wooden atlas
#
import { BlockPermutation, ItemStack } from '@minecraft/server';
import { itemInteract, decrementStack } from './utils';
export class test1 {
  onPlace({ block, dimension, player }, { params }) {
    if (block.typeId == 'bd:baking_pan') return;
    const slot1 = params.slot_1;
    const slot2 = params.slot_2;
    const slot3 = params.slot_3;
    const slot4 = params.slot_4;
    block.setPermutation(BlockPermutation.resolve('bd:test_2', {
      "bd:slot1": slot1,
      "bd:slot2": slot2,
      "bd:slot3": slot3,
      "bd:slot4": slot4
    }));
  }
}
verbal token
wooden atlas
#
system.beforeEvents.startup.subscribe(({ blockComponentRegistry }) => {
  blockComponentRegistry.registerCustomComponent("bd:test", new test1());
});
verbal token
#

Why create a class for functions?

wooden atlas
#

I'm just testing and I find it easier this way

verbal token
#

Then I don't know

wooden atlas
#

I'd like to implement that feature in my project, but this problem is preventing me from moving forward

verbal token
#

Well, considering the code and what you're saying... that's just impossible. Because if params = undefined, then const slot1 = params.slot_1 would throw an error and console.log wouldn't even work.

wooden atlas
#

Maybe the Params work, but the event doesn't detect the parameters within the block's JSON

#

As I said before, it works perfectly in the onPlayerInteract event, and I've tried it in many ways, used parameters with different names, different order, etc. My only remaining thought is that it's a bug or that it doesn't work in all events

verbal token
#

Everything works fine for me

#

Try not using the class

wooden atlas
#

It still shows "undefined." Could you send me the code you used? Please include all imports.

verbal token
#

It uses my library so it won't work for you but the function looks something like this

wooden atlas
#

But are you trying to get the value of the parameter inside the block's JSON?

wooden atlas
#

I don't know if I misunderstood you or if you misunderstood me. What I want is for the onPlace event to get the parameter values inside the custom component, which isn't working for me despite having everything set up correctly. In the code you sent me, I don't see you trying to get anything, which is why I asked.

wooden atlas
#

Ah, okay, I had something similar and it output '{}', so that's why I got confused 😅

verbal token