#Dynamically assembling campfires pt2

51 messages · Page 1 of 1 (latest)

quartz bane
#

Ok so i've been attempting for a while now trying to create a dynamic and more realistic assembly line for campfires, where you'd need to get logs and place them one by one until you actually have the full structure ready.

The thing is, i've came across multiple problems along the way. some of them being, my inability to properly adjust their rotation blockstate, properly making them place and removing the item from the player's hand as they right click the in progress campfire, and such...

Below i'll show you guys what i have so far...

This is the reference mod that made me wanna replicate it with kubejs, as it doesn't seem that complex for it to be a whole mod on its own...
https://youtu.be/60UZL2c4jys

This is a demo video of the Better Campfire mod.

▶ Play video
hushed sealBOT
#

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

quartz bane
#

these are my custom blocks that'll later get replaced as the player right clicks the initial campfire setup...

StartupEvents.registry("block", (event) => {
  event.create('cut_log_one')
    .defaultCutout()
    .waterlogged()
    .displayName("Cut Log")
    .model('ougaitems:block/campfire_log_one')
    .item(i =>{
      i.modelJson({
        parent: 'ougaitems:item/campfire_log'
      })
    })
    .property(BlockProperties.AXIS)
    .placementState(event => event.set(BlockProperties.AXIS, event.clickedFace.axis))
    .blockstateJson = {
                "variants": {
                    "axis=x": {
                        "model":"ougaitems:block/campfire_log_one",
                        "x": 90,
                        "y": 90
                    },
                    "axis=y": {
                        "model": "ougaitems:block/campfire_log_one"
                    },
                    "axis=z": {
                        "model": "ougaitems:block/campfire_log_one",
                        "x": 90
                    }
            }
    }
    //.box(1, 0, 0, 5, 4, 16)
  event.create('cut_log_two')
    .defaultCutout()
    .waterlogged()
    .noItem()
    .model('ougaitems:block/campfire_log_two')
    .box(1, 0, 0, 5, 4, 16)
    .box(11, 0, 0, 15, 4, 16)
  event.create('cut_log_three')
    .defaultCutout()
    .waterlogged()
    .noItem()
    .model('ougaitems:block/campfire_log_three')
    .box(1, 0, 0, 5, 4, 16)
    .box(11, 0, 0, 15, 4, 16)
    .box(0, 2, 11, 16, 6, 15)
  event.create('cut_log_four')
    .defaultCutout()
    .waterlogged()
    .noItem()
    .model('ougaitems:block/campfire_log_four')
    .box(1, 0, 0, 5, 4, 16)
    .box(11, 0, 0, 15, 4, 16)
    .box(0, 2, 1, 16, 6, 5)
    .box(0, 2, 11, 16, 6, 15)
})
#

This is what i have for each log block alteration...

BlockEvents.rightClicked('kubejs:cut_log_one', event => {
    if (event.player.mainHandItem.id == 'kubejs:cut_log_one') {
        event.block.set('kubejs:cut_log_two')
    }
})
BlockEvents.rightClicked('kubejs:cut_log_two', event => {
    if (event.player.mainHandItem.id == 'kubejs:cut_log_one') {
        event.block.set('kubejs:cut_log_three')
    }
})
BlockEvents.rightClicked('kubejs:cut_log_three', event => {
    if (event.player.mainHandItem.id == 'kubejs:cut_log_one') {
        event.block.set('kubejs:cut_log_four')
    }
})
BlockEvents.rightClicked('kubejs:cut_log_four', event => {
    if (event.player.mainHandItem.id == 'minecraft:coal') {
        event.block.set('minecraft:campfire', {facing: south, lit:'false'})
    }
})
BlockEvents.rightClicked('kubejs:cut_log_four', event => {
    if (event.player.mainHandItem.id == 'minecraft:charcoal') {
        event.block.set('minecraft:campfire', {facing: south, lit:'false'})
    }
})
#

The thing is,

  1. I`m unable to properly rotate this and keep the rotation consistent across each change too. I've been tryna think of a way for me to copy the rotation state of the previous block but i can't seem to even properly rotate the first log block in its x and z axis
#

this the garbage i got running lmao

#
  1. when right clicking each log it also puts an extra log on top of the one, it doesn't delete the item from my hand and idk how i could do that too...
#

Dynamically assembling campfires pt2

terse oak
scenic dust
#

you can also use event.player.mainHandItem.count -= 1 or just --event.player.mainHandItem.count
as for the placement of new ones when interacting with an existing one, you might be fine to just event.cancel() a placed block event if the block it's being placed off is one of your custom ones, and the item in hand matches the one used to "add" logs

quartz bane
terse oak
#

if you need to sort out how to rotate blocks like a log i have a script for that

quartz bane
terse oak
#

startup script for creating log (current example would be a redwood log):

event.create("redwood_log")
        .soundType('wood')
        .hardness(2)
        .property(BlockProperties.AXIS)
        .placementState(event => event.set(BlockProperties.AXIS, event.clickedFace.axis))
        .model('kubejs:block/logs/redwood_log')
        .displayName("Redwood Log")
        .requiresTool(false)
        .tagBlock("mineable/axe")
        .tagBlock("minecraft:logs")
        .tagBlock("minecraft:logs_that_burn")
        .blockstateJson = {
            "variants": {
                "axis=x": {
                    "model": "kubejs:block/logs/redwood_log",
                    "x": 90,
                    "y": 90
                },
                "axis=y": {
                    "model": "kubejs:block/logs/redwood_log"
                },
                "axis=z": {
                    "model": "kubejs:block/logs/redwood_log",
                    "x": 90
                }
            }
        }```
server script for stripping a log
```js
BlockEvents.rightClicked(event => {
        const { player, block, server, player: { mainHandItem } } = event
        if (mainHandItem.hasTag('forge:axes') && block.id == 'kubejs:redwood_log') {
            block.set('kubejs:stripped_redwood_log', block.properties)
            server.runCommandSilent(`playsound minecraft:item.axe.strip block @a ${block.x} ${block.y} ${block.z} 1 1`)
            event.cancel()
        }
    }```
#

lemme know if you need help on creating a model file

quartz bane
#

ic hmmm, the thing is, campfires use "rotation", so like rotation=north etc etc

#

i wouldn't be able to conserve the blockstate after each change and update of the first log

quartz bane
#

as its not a full block as you can see

terse oak
#

right, yeah this script is more suitable to normal logs and pillar blocks

#

hmm

#

lemme see if I have anything else that might work

#

oh wait, this just needs to be rotated to face the player when placed like a furnace, not rotated like a log right?

#

to do that you would just change the startup registry to be like this when creating each block

event.create('cut_log_one', 'cardinal')```
quartz bane
#

nicee, now i just gotta figure out how to store the initial facing direction

terse oak
#

nice

quartz bane
#
  • for some reason its culling the faces when placed by the side of another log
#

so just gotta figure those two out 🙂

terse oak
#

looking at your initial script, it looks like you are treating them as solid opaque blocks, which do that by default. You may benefit from these on each of your block registry events

.renderType('translucent')
.notSolid()
.defaultTranslucent()```
#

you probably don't need the renderType but the others might make a difference

#

fyi some of the pages on that wiki haven't been updated since 1.18 so there are some things there that don't work in 1.19 or 1.20. For example it says .material changes the block sound but in 1.19 and 1.20 you need to use .soundType instead

quartz bane
#

It basically creates a whole in the model + it doen't fix the actual issue...

scenic dust
#

try using cutout render type instead of translucent

quartz bane
frank oasisBOT
#

these are my custom blocks that'll later get replaced as the player right clicks the initial campfire setup...

StartupEvents.registry("block", (event) => {
  event.create('cut_log_one')
    .defaultCutout()
    .waterlogged()
    .displayName("Cut Log")
    .model('ougaitems:block/campfire_log_one')
    .item(i =>{
      i.modelJson({
        parent: 'ougaitems:item/campfire_log'
      })
    })
    .property(BlockProperties.AXIS)
    .placementState(event => event.set(BlockProperties.AXIS, event.clickedFace.axis))
    .blockstateJson = {
                "variants": {
                    "axis=x": {
                        "model":"ougaitems:block/campfire_log_one",
                        "x": 90,
                        "y": 90
                    },
                    "axis=y": {
                        "model": "ougaitems:block/campfire_log_one"
                    },
                    "axis=z": {
                        "model": "ougaitems:block/campfire_log_one",
                        "x": 90
                    }
            }
    }
    //.box(1, 0, 0, 5, 4, 16)
  event.create('cut_log_two')
    .defaultCutout()
    .waterlogged()
    .noItem()
    .model('ougaitems:block/campfire_log_two')
    .box(1, 0, 0, 5, 4, 16)
    .box(11, 0, 0, 15, 4, 16)
  event.create('cut_log_three')
    .defaultCutout()
    .waterlogged()
    .noItem()
    .model('ougaitems:block/campfire_log_three')
    .box(1, 0, 0, 5, 4, 16)
    .box(11, 0, 0, 15, 4, 16)
    .box(0, 2, 11, 16, 6, 15)
  event.create('cut_log_four')
    .defaultCutout()
    .waterlogged()
    .noItem()
    .model('ougaitems:block/campfire_log_four')
    .box(1, 0, 0, 5, 4, 16)
    .box(11, 0, 0, 15, 4, 16)
    .box(0, 2, 1, 16, 6, 5)
    .box(0, 2, 11, 16, 6, 15)
})
quartz bane
#

.defaultCutout()

quartz bane
#

at least, i don't think it works the way you told me to add yeah

#

cuz it'd block all placing with that log, which's an undesired result because i still want to be able to place it, but don't wanna place it after right clicking it yk

scenic dust
#

you should be able to get the block that's being placed off by some means, might need a raycast though

quartz bane
#

is it?

quartz bane
#

Ok so i was able to fix the cutout issue

#

used

    .notSolid()
    .renderType('cutout')
#

and this is my final script for each block update
stored the facing value under the "FacingValue" variable

BlockEvents.rightClicked('kubejs:cut_log_one', event => {
    if (event.player.mainHandItem.id == 'kubejs:cut_log_one') {
        let facingValue = event.block.properties["facing"];
        event.block.set('kubejs:cut_log_two', {facing: facingValue})
        event.player.mainHandItem.count = event.player.mainHandItem.count - 1
    }
})
BlockEvents.rightClicked('kubejs:cut_log_two', event => {
    if (event.player.mainHandItem.id == 'kubejs:cut_log_one') {
        let facingValue = event.block.properties["facing"];
        event.block.set('kubejs:cut_log_three', {facing: facingValue})
        event.player.mainHandItem.count = event.player.mainHandItem.count - 1
    }
})
BlockEvents.rightClicked('kubejs:cut_log_three', event => {
    if (event.player.mainHandItem.id == 'kubejs:cut_log_one') {
        let facingValue = event.block.properties["facing"];
        event.block.set('kubejs:cut_log_four', {facing: facingValue})
        event.player.mainHandItem.count = event.player.mainHandItem.count - 1
    }
})
BlockEvents.rightClicked('kubejs:cut_log_four', event => {
    if (event.player.mainHandItem.id == 'minecraft:coal') {
        let facingValue = event.block.properties["facing"];
        event.block.set('minecraft:campfire', {infinite:'false', lit:'false', facing: facingValue})
        event.player.mainHandItem.count = event.player.mainHandItem.count - 1
    }
})
BlockEvents.rightClicked('kubejs:cut_log_four', event => {
    if (event.player.mainHandItem.id == 'minecraft:charcoal') {
        let facingValue = event.block.properties["facing"];
        event.block.set('minecraft:campfire', {infinite:'false', lit:'false', facing: facingValue})
        event.player.mainHandItem.count = event.player.mainHandItem.count - 1
    }
})