This repository has been archived on 2023-11-26. You can view files and clone it, but cannot push or open issues or pull requests.
ScriptCraft/src/main/resources/scriptcraft/test/index.ts

42 lines
1.7 KiB
TypeScript

import { CustomBlock, BlockSettings, Identifier, Registry, BlockState, ActionResult, World, Pos, Hand, PlayerEntity, BlockItem, ItemSettings, CustomItem, Direction, LivingEntity } from 'minecraft';
console.log('hello');
class MyBlock extends CustomBlock {
constructor() {
super(new BlockSettings('STONE', 'IRON'));
}
onUse(world: World, blockState: BlockState, blockPos: Pos, side: Direction, player: PlayerEntity, hand: Hand): ActionResult {
world.setBlockState(blockPos.offset(side), BlockState.getDefaultState(new Identifier('minecraft:stone')));
return ActionResult.SUCCESS;
}
}
Registry.register(Registry.BLOCK, new Identifier('test', 'my_block'), new MyBlock());
Registry.register(Registry.ITEM, new Identifier('test', 'my_block'), new BlockItem(new Identifier('test', 'my_block'), new ItemSettings()));
class MyItem extends CustomItem {
constructor() {
super(new ItemSettings().setItemGroup('building_blocks').setMaxCount(128));
}
onUse(world: World, player: PlayerEntity, hand: Hand): ActionResult {
console.log('Item Use: Normal');
return ActionResult.SUCCESS;
}
onUseOnBlock(world: World, blockPos: Pos, side: Direction, player: PlayerEntity, hand: Hand): ActionResult {
console.log('Item Use: Block ' + blockPos.toString());
world.spawnEntity(new Identifier('minecraft:cow'), blockPos.offset(side).add(new Pos(0.5, 0, 0.5))).toString();
return ActionResult.SUCCESS;
}
onUseOnEntity(player: PlayerEntity, target: LivingEntity, hand: Hand): ActionResult {
console.log('Item Use: Entity ' + target.getPosition());
return ActionResult.SUCCESS;
}
}
Registry.register(Registry.ITEM, new Identifier('test', 'my_item'), new MyItem());