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/docs/tutorials/ITEM.md

61 lines
1.7 KiB
Markdown
Raw Normal View History

2020-06-01 23:07:01 +00:00
# Create A Item
## Create Your Item Class
JavaScript:
```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:
```typescript
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
```javascript
import { Registry, Identifier } from 'minecraft';
Registry.register(Registry.ITEM, new Identifier('modid', 'my_item'), new MyItem());
```