28 lines
1.1 KiB
JavaScript
28 lines
1.1 KiB
JavaScript
import { BlockSettings, Identifier, Registry, BlockState, ActionResult, BlockItem, ItemSettings, BuiltinRegistry } from 'minecraft';
|
|
|
|
console.log('hello');
|
|
|
|
const ironBlock = BuiltinRegistry.BLOCK.get(new Identifier('minecraft:iron_block'));
|
|
|
|
class MyBlock extends CustomBlockWithEntity {
|
|
constructor() {
|
|
super(new BlockSettings(ironBlock.getMaterial(), ironBlock.getMaterialColor()));
|
|
}
|
|
|
|
onUse(world, blockState, blockPos, side, player, hand) {
|
|
const entity = world.getCustomBlockEntity(blockPos);
|
|
if (entity instanceof MyBlockEntity) {
|
|
console.log('Ticks: ' + entity.ticks);
|
|
}
|
|
world.setBlockState(blockPos.offset(side), BlockState.getDefaultState(new Identifier('minecraft:stone')));
|
|
return ActionResult.SUCCESS;
|
|
}
|
|
|
|
createBlockEntity() {
|
|
return new MyBlockEntity();
|
|
}
|
|
}
|
|
|
|
Registry.register(Registry.BLOCK, new Identifier('modid', 'my_block'), new MyBlock());
|
|
Registry.register(Registry.ITEM, new Identifier('modid', 'my_block'), new BlockItem(new Identifier('modid', 'my_block'), new ItemSettings()));
|