#how to make campfire save the time remaining

1 messages · Page 1 of 1 (latest)

turbid patio
#
function handleFireStarter(player, block, itemStack) {
    const inventory = player.getComponent('inventory').container;
    let durabilityComponent = itemStack.getComponent('durability');

    if (durabilityComponent.damage < durabilityComponent.maxDurability && block.typeId === "btm:unlit_campfire") {
        durabilityComponent.damage += 1;
        block.dimension.spawnParticle(`minecraft:basic_flame_particle`, { x: block.location.x + 0.5, y: block.location.y + 0.35, z: block.location.z + 0.5 });
        block.dimension.spawnParticle(`minecraft:ice_evaporation_emitter`, { x: block.location.x + 0, y: block.location.y + 0.35, z: block.location.z + 0 });
        player.runCommand("/playsound fire.fire @a ^ ^ ^1");

        if (Math.random() / times <= 0.01 || times >= 6.3) {
            block.setType('minecraft:campfire');
            player.runCommand("/playsound fire.ignite @a ^ ^ ^1");
            times = 0.1;
            stop = true
            system.runTimeout(() => {
                block.setType('btm:unlit_campfire');
            },6000)
        } else {
            times += 0.1;
        }

        inventory.setItem(player.selectedSlot, itemStack);
    } else if (durabilityComponent.damage >= durabilityComponent.maxDurability) {
        inventory.setItem(player.selectedSlot, null);
    }
}
#

i set the time after the block got placed to 6000 ticks but if i reload the mod ticks remaining wont be saved and the mod will leave the campfire on forever

#

how do i make the campfire turn off if world gets reloaded?

haughty storm
#

Save the time it was placed and loop checking how long has passed

jovial mist
turbid patio
#

how do i add dynamic proprietis to a block?

jovial mist
#

then the name of the property is the lcoation of the block

turbid patio
#

and save the xyz of the bock?

#

wait a min

jovial mist
turbid patio
jovial mist
turbid patio
turbid patio
jovial mist
#

Someone's literally asked you what does it do

#

Also I told you to use dynamicProperty

#

Cause when you use variable or let and you reload the world it would be reset

turbid patio
# near fox What does it do?

Basically I created a custom block that is an unlit campfire when you right click it with a fire starter there is a chance of the block to turn into a lit campfire, after 2000 ticks the campfire comes back to unlit, but if I reload the world the campfire will not become unlit again breaking the system

turbid patio
jovial mist
turbid patio
jovial mist
turbid patio
near fox
#

I just created a plant tick system

jovial mist
#

Yeah I told this already but he said it's too much for him

turbid patio
near fox
#

Noo

jovial mist
near fox
#

Simple it's just like, world.setDynamicProperty(id, value)

jovial mist
#

Wait I'm a bit confused, is this a custom campfire or vanilla campfire? If it's custom campfire this is easy but if not still easy but different from custom onw

turbid patio
#

So I need to create a dynamic propriety in the world named block.location.xyz and value: time remaining for all campfires placed by player in the world. Then a runinterval to subtract 1 from time every second, then a runinterval that if the time is == 0 then it setblock.type to unlit campfire at the position of the block and if a player brakes a campfire it gets coordinates and the dynamic propriety gets removed

#

@jovial mist @near fox is this right?

turbid patio
jovial mist
turbid patio
#

And it is more optimized becouse if campfire is unlit then it won’t load it

jovial mist
#
world.afterEvents.playerPlaceBlock.subscribe(({ block, player }) => {
   if (block.typeId !== 'minecraft:campfire) return;
   world.setDynamicProperty('campfire:' + block.location, 0);
});```
turbid patio
#

It isn’t in crafting recipes

near fox
#

Then change it self

turbid patio
#

Why do I have to use that if I can use my code that is when player lights the campfire it starts that mechanism

turbid patio
near fox
#

Like, if it breaks with commands or something else player breaking

jovial mist
near fox
#

Yeah, I use that too, but sometimes it's doesn't detected

jovial mist
# near fox Yeah, I use that too, but sometimes it's doesn't detected

So my plan is get all dynamic property that starts with campfire: then filter remove that so the location of the block is the remaining one where it checks with getBlock if there's no block at that location it would set the dynamic property of that location to undefined or 0

near fox
#

Yeah, but in 1.10.0 block.typeId doesn't exist, so I tried using testforblock, and it's work as well

jovial mist
near fox
#

And sometimes i quit, dynamic properties are clear

jovial mist
near fox
#

ooh

#

Idk

jovial mist
near fox
#

That's why I use testforblock

jovial mist
near fox
#

Like this, see

export async function verifyChiliPlants() {
    let chiliPlantsData = getChiliPlants();
    let chiliPlantPositions = getChiliPlantPositions(chiliPlantsData);

    let verifiedPlantsPromises = chiliPlantPositions.map(async ({ plantId, dimension, location }) => {
        let block = Minecraft.world.getDimension(dimension).getBlock(location);
        if (!block.isAir) {
            try {
                let data = await block.dimension.runCommandAsync(`testforblock ${location.x} ${location.y} ${location.z} finalfantasy:chili_plant`);
                if (data.successCount > 0) {
                    return plantId;
                }
            } catch (error) {
                console.warn(`Error testing block: ${error}`);
            }
            return null;
        }
        console.warn("Block is null");
        return null;
    });

    let verifiedPlants = await Promise.all(verifiedPlantsPromises);
    let currentPlants = verifiedPlants.filter(id => id !== null);

    let remainingDynamicProperties = Minecraft.world.getDynamicPropertyIds()
        .filter(id => !id.includes("chili_plant"));

    let currentPlantsValue = [...currentPlants, ...remainingDynamicProperties].map(property => {
        return {
            property,
            value: Minecraft.world.getDynamicProperty(property)
        };
    });

    if (currentPlantsValue.length > 0) {
        Minecraft.world.clearDynamicProperties();
        currentPlantsValue.forEach(({ property, value }) => {
            Minecraft.world.setDynamicProperty(property, value);
        });
    }
}```
#

And some function


export function getChiliPlants() {
    return Minecraft.world.getDynamicPropertyIds()
        .filter(id => id.includes("chili_plant"));
}

export function getChiliPlantPositions(plants) {
    return plants.map(plant => {
        let [dimension, x, y, z] = Minecraft.world.getDynamicProperty(plant).split("|");
        return {
            plantId: plant,
            dimension,
            location: { x: Number(x), y: Number(y), z: Number(z) }
        };
    });
}

#

Dynamic properties format:

Minecraft.world.setDynamicProperty(`chili_plant_${index}`;, `${block.dimension.id}|${vector_x}|${vector_y}|${vector_z}`);

#

@jovial mist

jovial mist
near fox
#

That program

#

Why when I left the game, the dynamic properties were cleared

jovial mist
#

Wait I'll try to read it

#
export async function verifyChiliPlants() {
    const chiliPlantsData = getChiliPlants();
    const chiliPlantPositions = getChiliPlantPositions(chiliPlantsData);

    const verifiedPlantsPromises = chiliPlantPositions.map(async ({ plantId, dimension, location }) => {
        const block = Minecraft.world.getDimension(dimension).getBlock(location);

        if (!block.isAir) {
            try {
                const data = await block.dimension.runCommandAsync(`testforblock ${location.x} ${location.y} ${location.z} finalfantasy:chili_plant`);
                if (data.successCount > 0) {
                    return plantId;
                }
            } catch (error) {
                console.warn(`Error testing block: ${error}`);
            }
        } else {
            console.warn("Block is null");
        }

        return null;
    });

    const verifiedPlants = await Promise.all(verifiedPlantsPromises);
    const currentPlants = verifiedPlants.filter(Boolean);

    const remainingDynamicProperties = Minecraft.world.getDynamicPropertyIds()
        .filter(id => !id.includes("chili_plant"));

    const currentPlantsValue = [...currentPlants, ...remainingDynamicProperties].map(property => ({
        property,
        value: Minecraft.world.getDynamicProperty(property)
    }));

    if (currentPlantsValue.length > 0) {
        Minecraft.world.clearDynamicProperties();
        currentPlantsValue.forEach(({ property, value }) => {
            Minecraft.world.setDynamicProperty(property, value);
        });
    }
}
#
export function getChiliPlants() {
    return Minecraft.world.getDynamicPropertyIds()
        .filter(id => id.includes("chili_plant"));
}

export function getChiliPlantPositions(plants) {
    return plants.map(plant => {
        const [dimension, x, y, z] = Minecraft.world.getDynamicProperty(plant).split("|");
        return {
            plantId: plant,
            dimension,
            location: { x: Number(x), y: Number(y), z: Number(z) }
        };
    });
}
jovial mist
near fox
#

I didn't know that was possible

turbid patio
#

@jovial mist @near fox how do i remove a dynamicPropriety from the world?

#
system.runInterval(() => {
    const allDynamicProprieties = world.getDynamicPropertyIds()
    world.sendMessage(`${allDynamicProprieties}`)
    for (const id of allDynamicProprieties) {
        world.sendMessage(`${id}`)
        if (id.startsWith("campfire") == true) {
            world.sendMessage(`y`)
            const dynpN = world.getDynamicProperty(id)
            world.sendMessage(`${dynpN}`)
            world.setDynamicProperty(id, dynpN -1)
            if (dynpN <= 1) {
                world.getDimension("overworld").runCommand(`/setblock ${id.replace("campfire", "").trim()} btm:unlit_campfire`)
                world.setDynamicProperty(id)????
            }
        }
    }
}, 20)
turbid patio
#

okkk

jovial mist
turbid patio
#

why it gives me only 1 dinamic propriety and not all

#
const allDynamicProprieties = world.getDynamicPropertyIds()
turbid patio