Skip to content

TileEntity

youyihj edited this page Dec 2, 2023 · 4 revisions

Tile Entity

@Since 1.4.0

Tile Entities allow blocks to contain data more than 4 bits, and execute some code every tick. All powerful blocks use tile entity. ContentTweaker supports Tile Entity, however, which is broken. ZenUtils add its own system to fix it.

Importing the package

import mods.zenutils.cotx.TileEntity;

ZenProperty

  • ITileEntityTick onTick (default function(tileEntity, world, pos) {})

ZenMethod

  • register() to register the tile entity

ITileEntityTick

The function with the following parameters (in this order) will be called every tick.

Example

#loader contenttweaker
import mods.contenttweaker.VanillaFactory;
import mods.zenutils.cotx.Block;
import crafttweaker.data.IData;

val te = VanillaFactory.createActualTileEntity(1);
te.onTick = function(tileEntity, world, pos) {
    if (world.remote) return;
    val data as IData = tileEntity.data;
    if (!isNull(data) && data has "time") {
        tileEntity.updateCustomData({time: data.time.asInt() + 1});
        if (data.time.asInt() % 100 == 0) {
            val player = world.getClosestPlayer(pos.x, pos.y, pos.z, 64, false);
            if (isNull(player)) return;
            player.sendChat("xxx");
        }
    } else {
        tileEntity.updateCustomData({time: 1});
        // Equivilant to
        // tileEntity.data = tileEntity.data + {time: 1};
    }
};
te.register();

val block = VanillaFactory.createExpandBlock("test", <blockmaterial:wood>);
block.tileEntity = te;
block.register();
Clone this wiki locally