TheBrokenRail
e7a6b55d76
All checks were successful
ScriptCraft/pipeline/head This commit looks good
1.7 KiB
1.7 KiB
Create A Item
Create Your Item Class
JavaScript:
import { ActionResult, ItemSettings, CustomItem } from 'minecraft';
class MyItem extends CustomItem {
constructor() {
super(new ItemSettings().setItemGroup('building_blocks').setMaxCount(128));
}
onUse(world, player, hand) {
console.log('Item Use');
return ActionResult.SUCCESS;
}
onUseOnBlock(world, blockPos, side, player, hand) {
console.log('Item Use: Block ' + blockPos.toString());
return ActionResult.SUCCESS;
}
onUseOnEntity(player, target, hand) {
console.log('Item Use: Entity ' + target.toString());
return ActionResult.SUCCESS;
}
}
JavaScript:
import { ActionResult, World, Pos, Hand, PlayerEntity, ItemSettings, CustomItem, Direction, LivingEntity } from 'minecraft';
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');
return ActionResult.SUCCESS;
}
onUseOnBlock(world: World, blockPos: Pos, side: Direction, player: PlayerEntity, hand: Hand): ActionResult {
console.log('Item Use: Block ' + blockPos.toString());
return ActionResult.SUCCESS;
}
onUseOnEntity(player: PlayerEntity, target: LivingEntity, hand: Hand): ActionResult {
console.log('Item Use: Entity ' + target.toString());
return ActionResult.SUCCESS;
}
}
Register Your Item
import { Registry, Identifier } from 'minecraft';
Registry.register(Registry.ITEM, new Identifier('modid', 'my_item'), new MyItem());