#Redeclaration of const *insert here*

39 messages · Page 1 of 1 (latest)

carmine island
#

I'm trying to reuse scripts for multiple purposes but keep running into the problem that my scripts cannot use the same const. How can I remedy this?

frosty sageBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

grave topaz
#

mainly for-loops ect

carmine island
#

I'll try that

#

thanks

carmine island
#

seems like it stopped the error but has made it so only one of the two scripts work

grave topaz
#

i think what happened was you had 2 unrelated issues and changing all const to let solved one of them heh

#

also

misty abyssBOT
#

Never say 'it crashed', 'it errored', or 'it didn't work' without providing the full scripts and log/crash report!

grave topaz
#

though i cant really say without the current code or error report

carmine island
#

let CharcoalMakingTime = 100
/**@param {Internal.BlockEntityJS} blockEntity */
global.charcoalKilnCore = blockEntity => {
let {data, block, level, x, y, z} = blockEntity
let exposedSeconds = data.getInt("Exposed")
let timePassed = data.getInt("Passed")
if(checkEncased(blockEntity)) data.putInt("Passed", timePassed + 1);
else data.putInt("Exposed", exposedSeconds + 1);
level.spawnParticles("adchimneys:modern_smoke", false, x + 0.5, y + 1, z + 0.5, 0, 1.5, 0, 3, 0)
spreadCharcoalKiln(blockEntity)
if(exposedSeconds >= 6) block.set("minecraft:fire")
if(timePassed >= CharcoalMakingTime) block.set("kubejs:pile_of_charcoal")
}

let $Direction = Java.loadClass("net.minecraft.core.Direction")
/@param {Internal.BlockEntityJS} blockEntity /
let checkEncased = (blockEntity) => {
let {level, block} = blockEntity
let encased = $Direction.values().every(dir => {
/
@type {Internal.BlockContainerJS} */let theBlock = block[dir]
let faceSize = theBlock.blockState.getCollisionShape(level, theBlock.pos)
.getFaceShape(dir.opposite)
.toAabbs()[0]?.size||0
let isFull = faceSize == 1
return isFull
})
return encased
}
/
@param {Internal.BlockEntityJS} blockEntity /
let spreadCharcoalKiln = blockEntity => {
let {level, block} = blockEntity
$Direction.values().every(dir => {
/
@type {Internal.BlockContainerJS} /let theBlock = block[dir]
if(theBlock.hasTag('kubejs:charcoal_kiln_block')){
theBlock.set("kubejs:charcoal_kiln_core")
}
})
}
ForgeEvents.onEvent("net.minecraftforge.event.level.BlockEvent$NeighborNotifyEvent", event => {
global.fireCheck(event)
})
/
*
*

  • @param {Internal.BlockEvent$NeighborNotifyEvent} event
  • @returns
    */
    global.fireCheck = event => {
    let {pos, state} = event
    /**@type {Internal.ServerLevel} */let level = event.level
    if(!state.isBurning(level, pos)) return;
    let offsets = [1, -1].map(n => Array.from(Array(3).keys()).map(i => {let vec3i = [0, 0, 0]; vec3i[i] = n; return vec3i;})).reduce((a, b) => a.concat(b))
    offsets.forEach(offset => {
    let offsetPos = pos.offset.apply(pos, offset)
    let offsetBlock = level.getBlock(offsetPos)
    if(offsetBlock.hasTag("kubejs:charcoal_kiln_block")){
    offsetBlock.set("kubejs:charcoal_kiln_core")
    }
    })
    }
#

code for one script

#

let VesselCookTime = 10
/**@param {Internal.BlockEntityJS} blockEntity */
global.unfiredVesselCooking = blockEntity => {
let {data, block, level, x, y, z} = blockEntity
let exposedSeconds = data.getInt("Exposed")
let timePassed = data.getInt("Passed")
if(checkEncased(blockEntity)) data.putInt("Passed", timePassed + 1);
else data.putInt("Exposed", exposedSeconds + 1);
level.spawnParticles("adchimneys:modern_smoke", false, x + 0.5, y + 1, z + 0.5, 0, 1.5, 0, 3, 0)
spreadVesselCooking(blockEntity)
if(exposedSeconds >= 6) block.set("kubejs:unfired_vessel_log4")
if(timePassed >= VesselCookTime) block.set("kubejs:vessel_ash")
}

let $Direction1 = Java.loadClass("net.minecraft.core.Direction")
/@param {Internal.BlockEntityJS} blockEntity /
let checkEncased = (blockEntity) => {
let {level, block} = blockEntity
let encased = $Direction1.values().every(dir => {
/
@type {Internal.BlockContainerJS} */let theBlock = block[dir]
if(dir == "up"){
if(theBlock.blockState.air) theBlock.set("fire")
return theBlock.blockState.isBurning(level, theBlock.pos) || theBlock.blockState.air
}
let faceSize = theBlock.blockState.getCollisionShape(level, theBlock.pos)
.getFaceShape(dir.opposite)
.toAabbs()[0]?.size||0
let isFull = faceSize == 1
return isFull
})
return encased
}
/
@param {Internal.BlockEntityJS} blockEntity /
let spreadVesselCooking = blockEntity => {
let {level, block} = blockEntity
$Direction1.values().every(dir => {
/
@type {Internal.BlockContainerJS} /let theBlock = block[dir]
if(theBlock.hasTag('kubejs:charcoal_kiln_block')){
theBlock.set("kubejs:charcoal_kiln_core")
}
})
}
ForgeEvents.onEvent("net.minecraftforge.event.level.BlockEvent$NeighborNotifyEvent", event => {
global.fireCheck1(event)
})
/
*
*

  • @param {Internal.BlockEvent$NeighborNotifyEvent} event
  • @returns
    */
    global.fireCheck1 = event => {
    let {pos, state} = event
    /**@type {Internal.ServerLevel} */let level = event.level
    if(!state.isBurning(level, pos)) return;
    let offsets = [1, -1].map(n => Array.from(Array(3).keys()).map(i => {let vec3i = [0, 0, 0]; vec3i[i] = n; return vec3i;})).reduce((a, b) => a.concat(b))
    offsets.forEach(offset => {
    let offsetPos = pos.offset.apply(pos, offset)
    let offsetBlock = level.getBlock(offsetPos)
    if(offsetBlock.hasTag("kubejs:vessel_cooking")){
    offsetBlock.set("kubejs:unfired_vessel_cooking")
    }
    })
    }
#

code for the other

#

the vessel script is what is working just fine

#

the charcoal script is doing most of what it is supposed to except it turns itself into fire when it shouldn't

carmine island
#

Basically you place log in ground then light it on fire then place another #minecraft:dirt block on top then after some time it turns into charcoal except it turns itself into fire when in the ground but turns itself into charcoal if no block is above it

#

And the vessel script works essentially identical to the pit kiln in TFC and it functions just fine

#

If I remove the vessel script the charcoal script works as intended

misty abyssBOT
#

You can write your code in a codeblock by typing it between the codeblock delimiters:
Note that these are backticks, not apostrophes

```js :arrow_left:

ServerEvents.recipes(event => {
event.smelting('minecraft:glass', '#forge:sand').xp(.1)
})

``` :arrow_left:

This example will look like this:

ServerEvents.recipes(event => {
  event.smelting('minecraft:glass', '#forge:sand').xp(.1)
})
grave topaz
#

put your code in that so its readable^

#

also

misty abyssBOT
#

Please send your KubeJS startup log. It can be found at /minecraft/logs/kubejs/startup.log.
If you are on 1.18 or 1.16 it will be called startup.txt.
Please send the file directly, without links or snippets.

grave topaz
carmine island
misty abyssBOT
#

Paste version of vesselcooking.js, charcoalmaking.js from @carmine island

grave topaz
#

no problem, now just for your startup logs

#

and thank you

grave topaz
#

mainly what im after, if theres an error itll be there

carmine island
misty abyssBOT
#

Paste version of startup.log from @carmine island

grave topaz
#

hmm no errors

#

what i suggest is combining both scripts into one since they both use the notifyneighbor event, this way you'll be able to regulate both of the in the same context at the same time and determine what you want to do and be able to solve any contradictions

carmine island
#

Found the issue: I had some stuff with the same name that I didn't catch causing the interference

#

Thanks for your help