#Custom Parameters
1 messages · Page 1 of 1 (latest)
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
}));
}
}
what does the console.log(slot1) display in the content log
Undefined or NaN
Are you sure you're using V2?
Yes
I tested this with the onPlayerInteract event and it works perfectly
But with this onPlace event it doesn't work, it shows undefined
looks like something impossible
try logging the whole params variable
console.log(JSON.stringify(params))
I'll try
Shows undefined
This is impossible
Maybe it doesn't work in all events? Or maybe it's a bug, or maybe I'm doing something wrong
Because then when trying to get the slot_1 property it would give an error
you're definitely placing the test_1 block?
Yes
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?
Can you show the whole code?
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
}));
}
}
Where is the component registration?
system.beforeEvents.startup.subscribe(({ blockComponentRegistry }) => {
blockComponentRegistry.registerCustomComponent("bd:test", new test1());
});
Why create a class for functions?
I'm just testing and I find it easier this way
Then I don't know
I'd like to implement that feature in my project, but this problem is preventing me from moving forward
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.
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
It still shows "undefined." Could you send me the code you used? Please include all imports.
It uses my library so it won't work for you but the function looks something like this
But are you trying to get the value of the parameter inside the block's JSON?
?
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.
line 2 and 3
Ah, okay, I had something similar and it output '{}', so that's why I got confused 😅
You said it outputs undefined ._.