#need help with a script
89 messages · Page 1 of 1 (latest)
Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!
as I am new to this I have no clue on how to get this working please help 
??patience
Please be patient, we're helping as fast as we can
We volunteer our time and knowledge to help people as we can.
Not everyone here will have your answer the moment you want it.
Time zones, work/life/schedules etc. also change when people are available to help.
TL;DR: Please have patience. IF and WHEN someone knows, they will assist you.
this would be really laggy to implement if your idea is to scan entire regions for blocks
yes, 853,334 blocks every tick if distributed perfectly
i swear there was a library mod for scanning regions for blocks at some point
i can't remember what it was though
what you could do is track the block place and break
well thing is I have custom ore nodes (blocks that look like wow nodes)
basically I have full and empty node blocks, what i have an issue is that they do not go back to full block type when server has been restarted
(i have them working on while server is on) for example player breaks ore node and then after a minute it regenerates back to full node
or whatever you do rn
its for a custom server where those nodes are custom placed
ah
basically those are one of the only blocks players can break really
full node -> broken -> replaced with empty node-> 1 minute -> replaced with full node
did that with mcreator
but yeah have been messing around with this for 4 days now and cant get it to do the regen if world/server is shut down and started back up 😄

you could do that with kubejs
please don't use mcreator
I have even less of an idea how to get it working with kubeJS 😄
also wouldnt it cause the same issue either way
that if server is restarted when some of the nodes are still in empty state: they would not start regenerating?
you could stoore some data in persistentData with kubejs
idk if something like that even exists in mcreator
no clue as well... well I guess more research for another 4 days and banging my head against wall till it works 
This code should place the block again after 60 seconds if it was broken. Note that if the block can be obtained it will be a bit op and it wouldn't work in other dimensions correctly
let time = 1200 //60 seconds
ServerEvents.loaded(event => {
if(!event.server.persistentData.broken_ores){
event.server.persistentData.broken_ores = {}
for(let i = 0; i < time; i++){
event.server.persistentData.broken_ores.put(i.toString(), [])
}
event.server.persistentData.broken_ores_time = 0
}
})
BlockEvents.broken("block_here", event => {
let pData = event.server.persistentData
let key = pData.broken_ores_time.toString()
pData.broken_ores.put(key, [[event.block.x, event.block.y, event.block.z]].concat(pData.broken_ores.get(key)))
event.block.set("temp_block_here")
event.cancel()
})
ServerEvents.tick(event => {
let pData = event.server.persistentData
pData.broken_ores_time++
if(pData.broken_ores_time >= time) pData.broken_ores_time = 0
let key = pData.broken_ores_time.toString()
pData.broken_ores.get(key).forEach(loc => {
event.server.getLevel("overworld").getBlock(new BlockPos(loc[0], loc[1], loc[2])).set("block_here")
})
pData.broken_ores.put(key, [])
})
for "block_here" the " should stay or no?
yes
you need to replace both with the block id, so "minecraft:diamond_ore" for example
so first one is the block that is broken? and second one is for what block is placed instead of it?
the first is the one to be broken and the second is the one that should respawn
if you want to replace it with a different block in the meantime
I have edited the script to also have that
oh damn
again thank you 
testing it now
this script goes in the server_scripts folder right?
yes
[18:49:13] [Server thread/ERROR] [KubeJS Server/]: example.js#14: Error in 'BlockEvents.broken': TypeError: Cannot read property "block" from undefined
accidently had a dot instead of a comma
after key?
no in this line pData.broken_ores.put(key, [[event.block.x, event.block.y. event.block.z]].concat(pData.broken_ores.get(key))) (this is the wrong version)
no it would be event.block.y, instead of event.block.y. as it should be added to the array and not continue the method chain (idk the actual name for this)
the error is after event.block.y
oh... sorry for being quite of a 
uhh [19:04:08] [Server thread/ERROR] [KubeJS Server/]: example.js#23: Error in 'ServerEvents.tick': Java constructor for "net.minecraft.core.BlockPos" with arguments "dev.latvian.mods.rhino.Undefined,dev.latvian.mods.rhino.Undefined,dev.latvian.mods.rhino.Undefined" not found.
[19:04:08] [Server thread/ERROR] [KubeJS Server/]: …rhino.EvaluatorException: Java constructor for "net.minecraft.core.BlockPos" with arguments "…rhino.Undefined,…rhino.Undefined,…rhino.Undefined" not found. (server_scripts:example.js#23)
all good you are currently helping me by a ton and half 😄
[19:09:40] [Server thread/ERROR] [KubeJS Server/]: example.js#23: Error in 'ServerEvents.tick': Can't find method net.minecraft.world.level.Level.m_6933_(net.minecraft.core.BlockPos,string).
[19:09:40] [Server thread/ERROR] [KubeJS Server/]: …rhino.EvaluatorException: Can't find method net.minecraft.world.level.Level.m_6933_(net.minecraft.core.BlockPos,string). (server_scripts:example.js#23)
do I need to change the overworld as well?
or the world name does not matter really as its more of a dimension name?
try it now
currently it only works for the overworld
oh no need for other dims in my case really as everything is in same dim
ok seems like its ignoring the temporary block for some reason but does place the block back tho
you've replaced "temp_block_here" with the correct block, right?
yep
let time = 1200 //60 seconds
ServerEvents.loaded(event => {
if(!event.server.persistentData.broken_ores){
event.server.persistentData.broken_ores = {}
for(let i = 0; i < 1200; i++){
event.server.persistentData.broken_ores.put(i.toString(), [])
}
event.server.persistentData.broken_ores_time = 0
}
})
BlockEvents.broken("minecraft:diamond_ore", event => {
let pData = event.server.persistentData
let key = pData.broken_ores_time.toString()
pData.broken_ores.put(key, [[event.block.x, event.block.y, event.block.z]].concat(pData.broken_ores.get(key)))
event.block.set("minecraft:stone")
})
ServerEvents.tick(event => {
let pData = event.server.persistentData
pData.broken_ores_time++
if(pData.broken_ores_time >= 1200) pData.broken_ores_time = 0
let key = pData.broken_ores_time.toString()
pData.broken_ores.get(key).forEach(loc => {
event.server.getLevel("overworld").getBlock(new BlockPos(loc[0], loc[1], loc[2])).set("minecraft:diamond_ore")
})
})```
also it seems that it ignores the time tho
sometimes regens right after and sometimes takes half minute
should be fixed now
reason was that the locations were never removed
can you try now for the temp block
hmm the timer now works but temp block is still not placed
just noticed you changed it and it works! thank you!
testing on vanilla diamond or it does not drop the diamond tho 
aka no drops
while the loot drop part i will figure out myself, it seems like when I changed the time to 12000 (10 minutes) it just spams the console with: 20:11:52] [Server thread/ERROR] [KubeJS Server/]: example.js#23: Error in 'ServerEvents.tick': TypeError: Cannot call method "forEach" of null
Because I cancel the Break event. There's.popItemFromFace, but idk how to get the face
Can you send the code
let time = 12000 //60 seconds
ServerEvents.loaded(event => {
if(!event.server.persistentData.broken_ores){
event.server.persistentData.broken_ores = {}
for(let i = 0; i < time; i++){
event.server.persistentData.broken_ores.put(i.toString(), [])
}
event.server.persistentData.broken_ores_time = 0
}
})
BlockEvents.broken("minecraft:diamond_ore", event => {
let pData = event.server.persistentData
let key = pData.broken_ores_time.toString()
pData.broken_ores.put(key, [[event.block.x, event.block.y, event.block.z]].concat(pData.broken_ores.get(key)))
event.block.set("minecraft:stone")
event.cancel()
})
ServerEvents.tick(event => {
let pData = event.server.persistentData
pData.broken_ores_time++
if(pData.broken_ores_time >= time) pData.broken_ores_time = 0
let key = pData.broken_ores_time.toString()
pData.broken_ores.get(key).forEach(loc => {
event.server.getLevel("overworld").getBlock(new BlockPos(loc[0], loc[1], loc[2])).set("minecraft:diamond_ore")
})
pData.broken_ores.put(key, [])
})```
Add event.server.persistentData = {} as the First Line in the .loaded event. relog into the world and remove the Line again
Idk how much memry this Takes Up though
I can't find Like a simple answer on how much that would be online
As for each extra Tick we create a new object key
not sure if i did it corectly but seems like i didnt
after having unrest I managed to get it working tho I removed the temp_block as not sure how to get that working. tho I did all that after giving up and using forbidden tool:
let time = 12000; // 60 seconds
ServerEvents.loaded(event => {
if (!event.server.persistentData.broken_ores) {
event.server.persistentData.broken_ores = {};
for (let i = 0; i < time; i++) {
event.server.persistentData.broken_ores.put(i.toString(), []);
}
event.server.persistentData.broken_ores_time = 0;
}
});
BlockEvents.broken("minecraft:diamond_ore", event => {
let pData = event.server.persistentData;
let key = pData.broken_ores_time.toString();
let locations = pData.broken_ores.get(key) || [];
locations.unshift([event.block.x, event.block.y, event.block.z]); // More efficient insertion
pData.broken_ores.put(key, locations);
});
ServerEvents.tick(event => {
let pData = event.server.persistentData;
pData.broken_ores_time++;
if (pData.broken_ores_time >= time) pData.broken_ores_time = 0;
let key = pData.broken_ores_time.toString();
let locations = pData.broken_ores.get(key);
if (Array.isArray(locations)) {
locations.forEach(loc => {
let blockPos = new BlockPos(loc[0], loc[1], loc[2]);
event.server.getLevel("overworld").getBlock(blockPos).set("minecraft:diamond_ore");
});
}
pData.broken_ores.put(key, []); // Clear the list after processing
});
what's the issue now?