#3D Item with animation

26 messages · Page 1 of 1 (latest)

dusk wolf
#

Is it possible to create a custom food item with a 3D model and custom eating sound using KubeJS in 1.20.1?
and
I'm using Better Combat and Emotecraft. Is there a way to trigger a specific animation or emote when a player eats a custom KubeJS item? I want to replace the standard vanilla eating animation with something custom.

sacred yewBOT
#

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

dapper adder
#
  1. Yes, custom 3D model is absolutely doable.
  2. Not sure, I would love to learn how to make it have a custom eating sound myself. But I think it's doable.
  3. I have no idea if it can trigger an animation or emote. It would depend what the API looks like, and/or whether they have KubeJS integration or not. Even if they don't, you can maybe use Java.loadClass(), but I wouldn't know where to start with those specific mods yet.

For custom 3D model:

  1. Make the model in blockbench
  2. Put the model json file blockbench generates in kubejs/assets/<namespace>/models/item, where <namespace> is either kubejs if you didn't define a namespace when you create the item in StartupScripts, or your item's namespace.
  3. Put the textures from the model you made in blockbench into kubejs/assets/<namespace>/textures/item, maybe use a subfolder if you specified on in the model json.
dusk wolf
dapper adder
#

Well, take this for example. It's a test item thrown together in 5 seconds, not meant to resemble anything yet. The green block starts at 0,0,0; if you hit the display tab, you can see where various models would hold your model in various slots. For example, in a zombie's dominant hand, it would look like this.

#

But if I were to move the parts around a bit, so now the green block is at 7,0,7, now it fits in the zombie's hand more naturally.

#

Then I can move some blocks and/or resize them...
until I'm roughly happy with what I made.

#

And if I'm still not happy, I can set per-slot offsets

#

This little test object will have a json that looks like this:

{
    "format_version": "1.9.0",
    "credit": "Made with Blockbench",
    "elements": [
        {
            "from": [7, 5, 3],
            "to": [9, 7, 7],
            "rotation": {"angle": 0, "axis": "y", "origin": [7, 5, 7]},
            "color": 5,
            "faces": {
                "north": {"uv": [0, 0, 2, 2], "texture": "#missing"},
                "east": {"uv": [0, 0, 4, 2], "texture": "#missing"},
                "south": {"uv": [0, 0, 2, 2], "texture": "#missing"},
                "west": {"uv": [0, 0, 4, 2], "texture": "#missing"},
                "up": {"uv": [0, 0, 4, 2], "rotation": 270, "texture": "#missing"},
                "down": {"uv": [0, 0, 4, 2], "rotation": 90, "texture": "#missing"}
            }
        },
        {
            "from": [7, 0, 7],
            "to": [9, 7, 9],
            "rotation": {"angle": 0, "axis": "y", "origin": [7, 0, 7]},
            "color": 7,
            "faces": {
                "north": {"uv": [0, 0, 2, 7], "texture": "#missing"},
                "east": {"uv": [0, 0, 2, 7], "texture": "#missing"},
                "south": {"uv": [0, 0, 2, 7], "texture": "#missing"},
                "west": {"uv": [0, 0, 2, 7], "texture": "#missing"},
                "up": {"uv": [0, 0, 2, 2], "texture": "#missing"},
                "down": {"uv": [0, 0, 2, 2], "texture": "#missing"}
            }
        },
        {
            "from": [7, -16, 3],
            "to": [9, 5, 5],
            "rotation": {"angle": 0, "axis": "y", "origin": [7, 0, 3]},
            "color": 7,
            "faces": {
                "north": {"uv": [0, 0, 2, 16], "texture": "#missing"},
                "east": {"uv": [0, 0, 2, 16], "texture": "#missing"},
                "south": {"uv": [0, 0, 2, 16], "texture": "#missing"},
                "west": {"uv": [0, 0, 2, 16], "texture": "#missing"},
                "up": {"uv": [0, 0, 2, 2], "texture": "#missing"},
                "down": {"uv": [0, 0, 2, 2], "texture": "#missing"}
            }
        }
    ],
    "display": {
        "thirdperson_righthand": {
            "translation": [0, 3.25, 0]
        },
        "thirdperson_lefthand": {
            "translation": [0, 4, 0]
        },
        "firstperson_righthand": {
            "translation": [0, 6, -2.5]
        },
        "firstperson_lefthand": {
            "translation": [0, 6, -2.5]
        },
        "ground": {
            "translation": [0, 9.5, 0],
            "scale": [1, 0.5, 1]
        },
        "gui": {
            "rotation": [-90, 45, 90],
            "translation": [-5, 8.25, 0],
            "scale": [0.8, 0.8, 0.8]
        },
        "head": {
            "rotation": [0, 90, 0],
            "translation": [3, 30, 0]
        },
        "fixed": {
            "rotation": [-90, 45, 90],
            "translation": [-6.5, 10, 0]
        }
    },
    "groups": [
        {
            "name": "Root",
            "origin": [8, 8, 8],
            "color": 0,
            "children": [0, 1, 2]
        }
    ]
}

Obviously if you colored the model it would have actual textures in place of #missing, but in summary:

dusk wolf
#

hmm

#

ok

dapper adder
#

Here's the example item in JSON again, but with a texture, so you can know what it looks like when you've exported your own.

karmic gullBOT
#

Paste version of walking_cane.json from @dapper adder

dapper adder
#

And this example item would look like this.

Keep in mind, this example item is 2 voxels thick, rather than the default 1, but I kept it super simple because it's an example. You can make your item as complex as you want, as long as you tweak the positions in the 'Display' tab to fit your character's hand, 1st person view, head slot, item slot, etc.

Or, you can do something insane and make it extend outside of the inventory slot. If you really want.

#

When you use this method, you do NOT have to include .model("<mymodel>") or .texture("<mytexture>") in your item definition script. If the model's name matches your item's name (let's say you used event.create("walking_cane") for the sake of this example, and the model was walking_cane.json), then it should work.

#

But as for the other two question, custom eating sound and triggering an animation from a mod, those will have to be answered by someone else.

dusk wolf
#

Thanks for the JSON example! How do I specifically customize the First Person view (how the player sees the item while holding it) and the Item Frame appearance?

Which fields in the 'display' section of the JSON should I focus on for those two, and is there a way to preview the Item Frame specifically inside Blockbench?

dapper adder
dusk wolf
#

i see

#

thx

dapper adder
#

Just be aware, that menu has two 1st person tabs (left and right), and two in-hand tabs (left and right).

dusk wolf
#

Just to make sure I got the workflow right:

Create the model at 0,0,0 and adjust the positions in the Display tab.

Export the JSON to assets/kubejs/models/item/model.json.

Save the Texture (PNG) to assets/kubejs/textures/item/model_texture.png.

In my KubeJS Startup Script, I just use event.create('model_name').
Since the file names match the item ID, KubeJS/Minecraft will automatically link the model and the texture without me needing to call .texture() or .model() in the script. Is that correct?

dapper adder
#

The model doesn't have to be at (0,0,0), (7,0,7) is closer to the hands by default.

#

All that looks correct otherwise, yup!

#

Then, I await someone else who has experience with custom sounds and/or special animations to deal with the rest.