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);
}
}
#how to make campfire save the time remaining
1 messages · Page 1 of 1 (latest)
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?
Save the time it was placed and loop checking how long has passed
Use dynamic property I guess, don't use map or [] cause when you reload world it will be reset
so i add dynamic propriety to the item then i make a loop that checks if it is == 0 to turn it off then every seconds timer = timer -1 to make it go down
how do i add dynamic proprietis to a block?
no you can't you need to use world instead
then the name of the property is the lcoation of the block
world.setDynamicProperty(`block${block.location}`, block.location)```
Okk so that proprietiy saves the block location right? I need to add the timer to that
wait i need to clarify what are you tryng to do? can you explain?
I want to make the campfire turn off after a time and I want also to not be unsaved when player leaves the world
is this a custom or nah?
the campfire turned off is a custom block the campfire lit isnt
What does it do?
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
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
Too much, I don’t know how to handle if player breaks the campfire
So In Short it's vanilla block and after time it would turn off?
playerBreakBlock?
It works as a vanilla block but if I reload the script or close the world the script will not run after 2000 ticks becouse it was stopped
because you're using system.runTimeout
Wait
Use dynamic properties like I did before
I just created a plant tick system
Yeah I told this already but he said it's too much for him
Too complex
Noo
It's simple dude....
Simple it's just like, world.setDynamicProperty(id, value)
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
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?
Correct
Now answer this @turbid patio
The unlit is a custom block becouse itemUseOn won’t work on normal campfire
The lit campfire is the vanilla campfire becouse I didn’t want to create a new campfire with cooking recipes and stuff
So we'll use playerplaceblock then... I'll make you a small template
It is useless the campfire in my mod can be obtained only by usingfire starter on the unlit campfire so I can use that
And it is more optimized becouse if campfire is unlit then it won’t load it
world.afterEvents.playerPlaceBlock.subscribe(({ block, player }) => {
if (block.typeId !== 'minecraft:campfire) return;
world.setDynamicProperty('campfire:' + block.location, 0);
});```
Letterally in my mod you can’t place Minecraft:campfire
It isn’t in crafting recipes
Then change it self
Why do I have to use that if I can use my code that is when player lights the campfire it starts that mechanism
Then edit your code
Yea give me time
Will you put a block detect system in interval?
Like, if it breaks with commands or something else player breaking
Yeah.
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
Yeah, but in 1.10.0 block.typeId doesn't exist, so I tried using testforblock, and it's work as well
Yeah but I think carchi is beta soo
And sometimes i quit, dynamic properties are clear
but block.permutation.matches() do work on stable tho
Lol
That's why I use testforblock
That's pretty weird.
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
Hmm?
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) }
};
});
}
Why you clear the dynamic property? Why not just set it undefined?
Idk
I didn't know that was possible
What do you change?
@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)
Set it undefined
okkk
world.setDynamicProperty(id, undefined)
why it gives me only 1 dinamic propriety and not all
const allDynamicProprieties = world.getDynamicPropertyIds()