Jump to content

Recommended Posts

Posted

Hi, I am currently developing a code mod, everything seems to be working fine so far, but I have come to the point, where I want to add a little animation to a block.

I have created a Model in the VSModelCreator and imported it into the corresponding shapes directory in the mod path. This all works so far, I've now got a model with textures and all. Now I tried adding an animation to the block and it looked good in the Model Creator. I exported the file and now I have a JSON file with models AND an animation. This is the part that I think is probably important:

"animations": [
  {
  "name": "sprinklerTurn",
  "code": "sprinklerTurn",
  "quantityframes": 30,
  "onActivityStopped": "PlayTillEnd",
  "onAnimationEnd": "EaseOut",
  "keyframes": [...]
  }
]

Now, I want to be able to play this animation on the Block (or rather the BlockEntity) that uses this model. I have already completed the rest of the mod and everything else is working with a Block and BlockEntity CS Class. This is my blocktype file:

{
	"code": "tin_sprinkler",
	"class": "sprinklersmod.sprinkler",
    "entityClass": "sprinklersmod.blockEntitySprinkler",
    "blockmaterial": "wood",
    "creativeinventory": { "general": [ "*" ] },
    "sidesolid": {
		"all": false
	},	
	"sideopaque": {
		"all": false
	},
    "sounds": {
        "place": "game:block/planks",
        "break": "game:block/planks"
    },
    "collisionbox": {
        "x1": 0.25, "y1": 0, "z1": 0.25, "x2": 0.75, "y2": 0.5, "z2": 0.75
    },
    "selectionbox": {
        "x1": 0.25, "y1": 0, "z1": 0.25, "x2": 0.75, "y2": 0.5, "z2": 0.75
    },
    "shapeByType": {
        "*": {"base": "block/tinsprinkler"}
    },
    "textures": {
        "tinbronze": {"base": "game:block/metal/anvil/tinbronze"},
        "brass": {"base": "game:block/metal/lantern/brass"}
    }
	
}

Theres still a bit of tweaking to be done here, but I registered the shape and now want to be able to access the animation. I was looking at many places for a way to do this, but I didn't really find much about the topic (only on how to create animations in the first place). So, my question is, how can I run the animation in my BlockEntity class the proper way? Which Class or Function do I need to call to make the block run its animation once? (In the best case asynchronously so it doesn't block the rest of the code from running).

Bonus question:

I want add a small "sprite" based water sprinkle animation to my block, but I didn't seem to find a way to make parts of a block model invisible unless called by the Keyframes to become visible. Is there a way for that?

Posted

@Spear and Fang I see how it is supposed to work. However when trying to access BlockEntityAnimationUtil or BEBehaviorAnimatable my IDE tells me those could not be found, even though I am using the newest Vintage Story API as base for my project. Do I need to import or include it in some way?

image.thumb.png.a0cd39d0ddd815e72db426e71385bb70.png

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.