#Adding a block/item with a custom model, texture, directionality, and a hitbox

43 messages · Page 1 of 1 (latest)

drifting pebble
#

I am trying to add blocks to expand the Create: Molten Metals mod using kubeJS in Fabric 1.20.1. I am having issues adding the molds with custom textures and models.

Here's the script:

StartupEvents.registry('block', event => { event.create('molten_adamantite_ingot_mold') .displayName('Molten Adamantite Ingot Mold') .hardness(0.0) .resistance(0.0) .fullBlock(false) .soundType('metal') .requiresTool(false) .model('kubejs:block/molten_adamantite_ingot_mold.json') })

I have the model json file under minecraft/kubejs/assets/kubejs/models/block and it still renders a full block with the purple and black checkerboard.

How do I get it to use the model json and the texture? The wiki defines both under the .model() function

.model(value: ID) Specify a custom model. The path must look like 'kubejs:block/texture_name' (which would be included under kubejs/assets/kubejs/models/block/texture_name.png). Defaults to 'kubejs:block/<block_name>'.

Thank you in advance.

restive badgeBOT
#

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

drifting pebble
orchid crane
drifting pebble
#

Trying now

#

No dice. Same effect.

orchid crane
drifting pebble
#

same thing

orchid crane
#

how does the model.json looke like

drifting pebble
#

{
"parent": "kubejs:block/mold",
"textures": {
"mold": "kuebjs:block/molten_adamantite_ingot_mold"
}

which points to the parent

{
"credit": "Made with Blockbench",
"textures": {
"mold": "molten_metals:block/ceramic_ingot_mold",
"particle": "#mold"
},
"elements": [
{
"from": [5, 0, 3],
"to": [11, 4, 13],
"faces": {
"north": {"uv": [10, 12, 16, 16], "texture": "#mold"},
"east": {"uv": [0, 12, 10, 16], "texture": "#mold"},
"south": {"uv": [10, 12, 16, 16], "texture": "#mold"},
"west": {"uv": [0, 12, 10, 16], "texture": "#mold"},
"up": {"uv": [0, 0, 10, 6], "rotation": 90, "texture": "#mold"},
"down": {"uv": [0, 6, 10, 12], "rotation": 90, "texture": "#mold"}
}
}
],
"display": {
"thirdperson_righthand": {
"rotation": [0, 90, 55],
"translation": [0, 4, 2.5],
"scale": [0.85, 0.85, 0.85]
},
"thirdperson_lefthand": {
"rotation": [0, -90, -55],
"translation": [0, 4, 2.5],
"scale": [0.85, 0.85, 0.85]
},
"firstperson_righthand": {
"rotation": [0, 45, 0],
"translation": [0, 5.85, -1],
"scale": [0.68, 0.68, 0.68]
},
"firstperson_lefthand": {
"rotation": [0, 45, 0],
"translation": [0, 5.85, -1],
"scale": [0.68, 0.68, 0.68]
},
"ground": {
"translation": [0, 4, 0],
"scale": [0.5, 0.5, 0.5]
},
"gui": {
"rotation": [30, 135, 0],
"translation": [0, 4.75, 0]
},
"head": {
"translation": [0, 14.25, 0]
},
"fixed": {
"rotation": [0, 90, 0],
"translation": [0, 4, 0]
}
}
}

#

I'm basically extending the functionality of an existing mod with all this

orchid crane
#

btw, you should use codeblock, which makes reading codes easier

viscid patrolBOT
#

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)
})
drifting pebble
#

I'm not seeing any

viscid patrolBOT
#

Paste version of mold.json from @drifting pebble

orchid crane
drifting pebble
viscid patrolBOT
#

Paste version of molten_adamantite_ingot_mold.json from @drifting pebble

orchid crane
#

ok, no missing bracket in actual file. Send the latest log then

viscid patrolBOT
#

Please send your Minecraft log. It can be found at ./logs/latest.log.
Note! Minecraft and KubeJS logs differ. Please send the latest.log, not a KubeJS log.
Please send the file directly, without links or snippets.

orchid crane
#

Just tested the model, seems like fine, so the problem is not in the model itself

drifting pebble
viscid patrolBOT
#

Paste version of latest.log from @drifting pebble

drifting pebble
#

I think it's trying to reference something from the molten metals mod itself

orchid crane
#

Maybe you should register the thing under the molten_metal namespace

#

or copy the model file to the path molten_metals:models/block/molten_adamantite_ingot_mold.json

[16:20:01] [Worker-ResourceReload-7/WARN]: Unable to load model: 'molten_metals:block/molten_adamantite_ingot_mold' referenced from: kubejs:molten_adamantite_ingot_mold#inventory: java.io.FileNotFoundException: molten_metals:models/block/molten_adamantite_ingot_mold.json
drifting pebble
#

Oh I see the issue. I didn't change the namespace in the item models

#

Let me try fixing that and I'll lyk

drifting pebble
#

So the first person model works but not the block still

#
    Line  3050: [16:49:54] [Worker-ResourceReload-9/WARN]: Exception loading blockstate definition: 'kubejs:blockstates/molten_adamantite_ingot_mold.json' in resourcepack: 'KubeJS Resource Pack [assets]' for variant: 'facing=east': Unknown blockstate property: 'facing'
    Line  3051: [16:49:54] [Worker-ResourceReload-9/WARN]: Exception loading blockstate definition: 'kubejs:blockstates/molten_adamantite_ingot_mold.json' in resourcepack: 'KubeJS Resource Pack [assets]' for variant: 'facing=north': Unknown blockstate property: 'facing'
    Line  3052: [16:49:54] [Worker-ResourceReload-9/WARN]: Exception loading blockstate definition: 'kubejs:blockstates/molten_adamantite_ingot_mold.json' in resourcepack: 'KubeJS Resource Pack [assets]' for variant: 'facing=west': Unknown blockstate property: 'facing'
    Line  3053: [16:49:54] [Worker-ResourceReload-9/WARN]: Exception loading blockstate definition: 'kubejs:blockstates/molten_adamantite_ingot_mold.json' missing model for variant: 'kubejs:molten_adamantite_ingot_mold#'```
orchid crane
drifting pebble
#

Okay so now I can place it and it looks correct except that it's occluding the blocks behind it and it isn't facing the direction I place it

orchid crane
#

try .defaultTranslucent() for the occluding problem

#

As for facing, you might need to modify the BlockEvents.placed in server script

drifting pebble
#

So I have the blockstate json

  "variants": {
    "facing=north": { "model": "kubejs:block/molten_adamantite_ingot_mold" },
    "facing=south": { "model": "kubejs:block/molten_adamantite_ingot_mold", "y": 180 },
    "facing=west":  { "model": "kubejs:block/molten_adamantite_ingot_mold", "y": 270 },
    "facing=east":  { "model": "kubejs:block/molten_adamantite_ingot_mold", "y": 90 }
  }
}

but how do I adjust a blockevents.placed script to adjust the rotation using .property(BlockProperties.HORIZONTAL_FACING)?

drifting pebble
#

I noticed there's a "cardinal" HorizontalDirectionalBlockBuilder as an alternate block builder but trying to use it gives me the following error:

[13:39:25] [ERROR] ! add_molds.js#1: ReferenceError: "cardinal" is not defined.

orchid crane
#

I just realized it might be easier to do it with createCustom

orchid crane
# drifting pebble So I have the blockstate json ```{ "variants": { "facing=north": { "mode...
const customMoldsBlocks = {}
StartupEvents.registry("block", event => {
    const $MoldBlock = Java.loadClass("com.ordana.molten_metals.blocks.MoldBlock")
    const $PushReaction = Java.loadClass("net.minecraft.world.level.material.PushReaction")
    const $BlockBehaviour$Properties = Java.loadClass("net.minecraft.world.level.block.state.BlockBehaviour$Properties")
    const createBlockPropertiesMoldCommon =() => $BlockBehaviour$Properties.of()
    .lightLevel((blockStatex) => 4)
    .instabreak()
    .pushReaction($PushReaction.DESTROY)
    .noOcclusion()
    .lightLevel((blockStatex) => 8)
    .emissiveRendering((state, blockGetter, pos) => true)

    const BlockPropertiesMoldCeramic = createBlockPropertiesMoldCommon().sound(SoundType.DECORATED_POT)
    const BlockPropertiesMoldStrong = createBlockPropertiesMoldCommon().sound(SoundType.COPPER)

    const addCustomMoldBlock = (/**@type {String} */name) => {
        const id = `kubejs:molten_${name.toLowerCase()}_ingot_mold`
        const isCermaic = name.toLowerCase().includes("ceramic")
        console.log(`${name} is ceramic: ${isCermaic}`)
        const moldBlockProperties = isCermaic ? BlockPropertiesMoldCeramic : BlockPropertiesMoldStrong
        customMoldsBlocks[name] = {
            id: id,
            block: event.createCustom(id, () => new $MoldBlock(moldBlockProperties))
        }    
    }
    addCustomMoldBlock("ADAMANTITE")
    addCustomMoldBlock("ADAMANTITE_CERAMIC")
})

StartupEvents.registry("item", event => {
    const $BlockItem = Java.loadClass("net.minecraft.world.item.BlockItem")
    const $IProperties = Java.loadClass("net.minecraft.world.item.Item$Properties")
    Object.keys(customMoldsBlocks).forEach(key => {
        const mold = customMoldsBlocks[key]
        event.createCustom(mold.id, () => new $BlockItem(mold.block.get(), new $IProperties()))
    })
})
#

btw, your state json seems wrong

{
  "variants": {
    "facing=north": { "model": "kubejs:block/molten_adamantite_ingot_mold", "y": 90 },
    "facing=south": { "model": "kubejs:block/molten_adamantite_ingot_mold", "y": 270 },
    "facing=west":  { "model": "kubejs:block/molten_adamantite_ingot_mold"},
    "facing=east":  { "model": "kubejs:block/molten_adamantite_ingot_mold", "y": 180 }
  }
}
drifting pebble
#

Let me try this

#

This works perfectly. Thank you. I just need to rename the blocks and add the rest!