BlockEvents.broken('kubejs:lc', e => {
const { x, y, z } = e.block.pos;
e.block.popItem("minecraft:diamond");
e.block
.createEntity("minecraft:zombie")
.mergeNbt({
Health: 40,
CustomName: '{"text":"Zombie King"}',
IsBaby: 1,
ArmorItems: [
{ id: "minecraft:diamond_boots", Count: 1 },
{ id: "minecraft:diamond_leggings", Count: 1 },
{ id: "minecraft:diamond_chestplate", Count: 1 },
{ id: "minecraft:diamond_helmet", Count: 1 }
],
HandItems: [
{ id: "minecraft:diamond_sword", Count: 1 },
{ id: "minecraft:shield", Count: 1 }
],
ActiveEffects: [
{ Id: 1, Amplifier: 1, Duration: 6000 },
{ Id: 5, Amplifier: 2, Duration: 6000 }
]
})
.spawn()
.setPosition(x, y + 2, z) // <- Throws an error
});
#Cannot call method "setPosition" of undefined (with createEntity)
10 messages · Page 1 of 1 (latest)
Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!
Cannot call method "setPosition" of undefined (with createEntity)
BlockEvents.broken("kubejs:lc", (e) => {
const { x, y, z } = e.block.pos;
e.block.popItem("minecraft:diamond");
const resultEntity = e.block.createEntity("minecraft:zombie");
resultEntity.mergeNbt({
Health: 40,
CustomName: '{"text":"Zombie King"}',
IsBaby: 1,
ArmorItems: [
{ id: "minecraft:diamond_boots", Count: 1 },
{ id: "minecraft:diamond_leggings", Count: 1 },
{ id: "minecraft:diamond_chestplate", Count: 1 },
{ id: "minecraft:diamond_helmet", Count: 1 },
],
HandItems: [
{ id: "minecraft:diamond_sword", Count: 1 },
{ id: "minecraft:shield", Count: 1 },
],
ActiveEffects: [
{ Id: 1, Amplifier: 1, Duration: 6000 },
{ Id: 5, Amplifier: 2, Duration: 6000 },
],
});
resultEntity.setPosition(x, y + 2, z);
resultEntity.spawn();
});
This means the entity is not yet created and then setPosition not working on mine?
you need create a variable to store the entity reference and call methods separately
My bad to chain methods XD
yeah, that's part of the problem, too
And I've just found another bug... your name is not bold btw
This is the working code:
BlockEvents.broken("kubejs:lc", (e) => {
const { x, y, z } = e.block.pos;
e.block.popItem("minecraft:diamond");
const resultEntity = e.block.createEntity("minecraft:zombie");
resultEntity.mergeNbt({
Health: 40,
CustomName: '{"text":"Zombie King"}',
IsBaby: 1,
ArmorItems: [
{ id: "minecraft:diamond_boots", Count: 1 },
{ id: "minecraft:diamond_leggings", Count: 1 },
{ id: "minecraft:diamond_chestplate", Count: 1 },
{ id: "minecraft:diamond_helmet", Count: 1 },
],
HandItems: [
{ id: "minecraft:diamond_sword", Count: 1 },
{ id: "minecraft:shield", Count: 1 },
],
ActiveEffects: [
{ Id: 1, Amplifier: 1, Duration: 6000 },
{ Id: 5, Amplifier: 2, Duration: 6000 },
],
});
resultEntity.setPosition(x + 0.5, y + 1.5, z + 0.5);
resultEntity.spawn();
});
This code functions as expected. It summons a zombie with custom nbt data at a specific location (position) when broken.
I removed the original loot of my custom block with:
StartupEvents.registry("block", (e) => {
const lc = e.create("lc")
lc.lootTable = {
type: "minecraft:block",
pools: []
}
})
This custom block drops diamond when destroyed manually (using popItem is intentional because I'll separate the summon part and item drop part in the future)
(I wrote the above sentence in order to help others by adding this to search index ;-))