{event.create ("test_block", "basic")." /> {event.create ("test_block", "basic")."/>

How to renderjsv1.1.9 how to register the custom KJS block physical registration custom rendering renderjs minecraft gam

First, register a KJS block entity casually:...

 StartuPEVENTS.Registry ("block", event => {

Event.create ("test_block", "basic")

.BlockIntity (BlockentityInfo => {{

Blockityinfo.enablesync () // Important, setting can synchronize data

}) LightLevel (15)

})

Register rendering: startup.

 global.inited = false

Clientevents.init (event => {{

Global.inited = true

Event.registerBlockIntityRenderer ("Kubejs: test_block", (context) => renderjsblocklyrenderererererer

.Create (context)

.Setcustomrender (Renderer, Context) => {

Var posstack = context.posestack

Var light = levelrenderer.getlightColor (context.blockentityjs.level, context.blockntityjs.blockpos.above ()) // Get the brightness

Var item = item.empty

Var data = context.blockntityjs.data//

If (data.contains ("item") {{

Item = item.of (data.getstring ("item"))

}

Ifm! = Item.empty) {

PoseStack.pushpose ()

PoseStack.translaate (0.5, 1.5, 0.5) // Translation (0.5, 1.5, 0.5)

PoseStack.mulpose (VEC3F.XN.rotationDegrees (90)) // X -axis rotation 90 degrees

Renderer.ItemRenderer.RendersStatic (item, "group", light, context.packedoverlay, context.posestack, context.buffersource, client.player.Getid ()))

PoseStack.poppose ()

}

PoseStack.pushpose ()

PoseStack.translate (0.25, 1, 0.25)

Posestack.scale (0.5, 0.5, 0.5)

Renderer.BlockRenderDispatcher.RendersingleBlock (blocks.fire.defaultBlockstate (), context.posestack, context.buffersource, light, context.pack Edoverlay)

PoseStack.poppose ()})

Cure

})

Right -click event: server.

 const $ blockersityjs = java.loadClass ("dev.latvian.mods.block.entity.blockntityjs")

Blockevents.richtclicked (event => {{

Var block = event.getBlock ()

Var entity = block.entity

If (entity instanceof $ Blockntityjs) {

Entity.data.putString ("item", event.player.getmainhanditem (). Getid ()))

Console.log (Entity.data);

Entity.sync () // Manual synchronization

}

})

What? I hope to adjust in the game? (Client script)

 if (global.inited) {

Var renderr = Client.getBlockIntityRenderspatcher (). RJS $ GetRendererByType ("Kubejs: Test_block") // Get Render

If (Renderer InstanceOf RenderJSBLOCKENTITYRENDERERERERER) {

// Reset the render

Renderer.setCustomrender (Renderer, Context) => {

Var posstack = context.posestack

Var light = levelrenderer.getlightColor (context.blocktityjs.level, context.blocktityjs.blockpos.above ())))))))))))))))

Var item = item.empty var data = context.blocktityjs.data

If (data.contains ("item") {{

Item = item.of (data.getstring ("item"))

}

Ifm! = Item.empty) {

PoseStack.pushpose ()

PoseStack.translate (0.5, 1.5, 0.5)

Posestack.mulpose (VEC3F.XN.rotationDegrees (90))

Renderer.ItemRenderer.RendersStatic (item, "group", light, context.packedoverlay, context.posestack, context.buffersource, client.player.Getid ()))

PoseStack.poppose ()

}

PoseStack.pushpose ()

PoseStack.translaate (0.25, 1, 0.25) posestack.scale (0.5, 0.5, 0.5)

Renderer.BlockRenderDispatcher.RendersingleBlock (blocks.fire.defaultBlockstate (), context.posestack, context.buffersource, light, context.pack Edoverlay)

PoseStack.poppose ()

})

}

}

Just set the RELOAD Client.

Effect:

When right -clicking, the items on your hand will be displayed.