KubeJS + CC: Tweaked - KubeJS Integration with ComputerCraft
This mod creates a bridge between KubeJS and the CC: Tweaked modification, allowing developers to add custom peripheral devices to any blocks in Minecraft. Using JavaScript, you can extend the functionality of existing mechanisms and create your own interactions.
Main Features
The mod provides tools for creating custom peripheral devices that can be bound to various blocks. You can add your own methods that will be available through ComputerCraft computers.
Usage Example
Here's how you can add additional methods to a furnace:
// priority: 0
// Last code update: April 30th 2024
ComputerCraftEvents.peripheral(event => {
// First parameter: peripheral type
// Second parameter: which block it applies to
// Note: you can use regex for the second parameter
event.registerPeripheral("furnace", "minecraft:furnace")
// Limits method calls to 1 per tick,
// as the method is scheduled in the main thread.
// The main thread is synchronized with the block
.mainThreadMethod("burnTime", (container, direction, arguments) => {
// This custom method returns the current
// remaining burn time of the furnace.
return container.entityData.getInt("BurnTime")
})
.mainThreadMethod("cookingProgress", (container) => {
// This custom method returns the percentage
// of the current cooking process.
// A progress of 0 returned during two consecutive
// ticks means that no cooking is happening.
let data = container.entityData
let cookTime = data.getInt('CookTime')
let cookTimeTotal = data.getInt('CookTimeTotal')
if (!cookTimeTotal) return 0;
return (cookTime / cookTimeTotal) * 100
})
// Has no call limits,
// however the method cannot access most world data.
// For example, it cannot access tile entity NBT
.method("say_hi", (container, direction, arguments) => {
container.up.set("diamond_block")
return "hi, here's your diamond block"
})
})
This example demonstrates how to get information about burn time and cooking progress in a furnace, as well as add a simple method for interaction.