Skip to content

Scripted Control

Goodbird-git edited this page Jun 2, 2024 · 8 revisions

New Methods

In order to control geckolib models, animation files, textures and default animations from scripts, some methods were added to ICustomNpc and IBlockScripted classes.

public void setGeckoModel(String model);

public void setGeckoTexture(String texture);

public void setGeckoAnimationFile(String animation);

For the ICustomNpc class there are also methods to set idle and walk animations

public void setGeckoIdleAnimation(String animation);

public void setGeckoWalkAnimation(String animation);

And for the IBlockScripted there is a method for setting its idle animation

public void setGeckoIdleAnimation(String animation);

For the scripted blocks you can also use setRotation and setScale, provided by CNPC itself.

Scripted Block Example

Let's make a nice decoration for your caves. We will use an example bat model for that.

function init(event) { //We set all of the model properties in the init
    var geckoAnimatable = event.block //We save the block into a geckoAnimatable variable
    geckoAnimatable.setGeckoModel("geckolib3:geo/bat.geo.json") //We set the model
    geckoAnimatable.setGeckoTexture( "geckolib3:textures/model/entity/bat.png") //We set the texture
    geckoAnimatable.setGeckoAnimationFile("geckolib3:animations/bat.animation.json") //We set the animation file
    geckoAnimatable.setGeckoIdleAnimation("animation.bat.idle") //We set the idle animation
    event.block.setRotation(180,135,0) //And we rotate the block 180 degrees around the X axis (flip the model upside down) and 135 degrees around Y axis
    event.block.setScale(0.5,0.5,0.5) //We set the scale of the bat to 0.5 so it matches the scale of the cave
}

And as a result we get
image

Npc Example

Because of the unified interface, you can work with the custom-modeled npcs just like with the custom-modeled scripted blocks, except you can not use the block-specific methods like setRotation and setScale.

function init(event) { //We set all of the model properties in the init
    var geckoAnimatable = event.npc //We save the block into a geckoAnimatable variable
    geckoAnimatable.setGeckoModel("geckolib3:geo/bat.geo.json") //We set the model
    geckoAnimatable.setGeckoTexture( "geckolib3:textures/model/entity/bat.png") //We set the texture
    geckoAnimatable.setGeckoAnimationFile("geckolib3:animations/bat.animation.json") //We set the animation file
    geckoAnimatable.setGeckoIdleAnimation("animation.bat.idle") //We set the idle animation
}

image

Clone this wiki locally