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
TheBrokenRail e7a6b55d76
All checks were successful
ScriptCraft/pipeline/head This commit looks good
Update Docs And Fix Gradle Plugin
2020-06-01 19:07:01 -04:00

61 lines
1.7 KiB
Markdown

# 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());
```