This commit is contained in:
parent
c9eb558a3b
commit
3ea727fb7f
@ -7,7 +7,7 @@ import { ActionResult, ItemSettings, CustomItem } from 'minecraft';
|
||||
|
||||
class MyItem extends CustomItem {
|
||||
constructor() {
|
||||
super(new ItemSettings().setItemGroup('building_blocks').setMaxCount(128));
|
||||
super(new ItemSettings().setItemGroup('building_blocks').setMaxCount(16));
|
||||
}
|
||||
|
||||
onUse(world, player, hand) {
|
||||
@ -27,13 +27,13 @@ class MyItem extends CustomItem {
|
||||
}
|
||||
```
|
||||
|
||||
JavaScript:
|
||||
TypeScript:
|
||||
```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));
|
||||
super(new ItemSettings().setItemGroup('building_blocks').setMaxCount(18));
|
||||
}
|
||||
|
||||
onUse(world: World, player: PlayerEntity, hand: Hand): ActionResult {
|
||||
@ -58,4 +58,4 @@ class MyItem extends CustomItem {
|
||||
import { Registry, Identifier } from 'minecraft';
|
||||
|
||||
Registry.register(Registry.ITEM, new Identifier('modid', 'my_item'), new MyItem());
|
||||
```
|
||||
```
|
||||
|
@ -1,26 +1,18 @@
|
||||
import { BlockSettings, Identifier, Registry, BlockState, ActionResult, BlockItem, ItemSettings, BuiltinRegistry } from 'minecraft';
|
||||
import { BlockSettings, Identifier, Registry, BlockState, ActionResult, BlockItem, ItemSettings, BuiltinRegistry, CustomBlock } from 'minecraft';
|
||||
|
||||
console.log('hello');
|
||||
|
||||
const ironBlock = BuiltinRegistry.BLOCK.get(new Identifier('minecraft:iron_block'));
|
||||
|
||||
class MyBlock extends CustomBlockWithEntity {
|
||||
class MyBlock extends CustomBlock {
|
||||
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')));
|
||||
console.log('Block Used!');
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
createBlockEntity() {
|
||||
return new MyBlockEntity();
|
||||
}
|
||||
}
|
||||
|
||||
Registry.register(Registry.BLOCK, new Identifier('modid', 'my_block'), new MyBlock());
|
||||
|
@ -1,26 +1,18 @@
|
||||
import { BlockSettings, Identifier, Registry, BlockState, ActionResult, World, Pos, Hand, PlayerEntity, BlockItem, ItemSettings, Direction, BuiltinRegistry } from 'minecraft';
|
||||
import { BlockSettings, Identifier, Registry, BlockState, ActionResult, World, Pos, Hand, PlayerEntity, BlockItem, ItemSettings, Direction, BuiltinRegistry, CustomBlock } from 'minecraft';
|
||||
|
||||
console.log('hello');
|
||||
|
||||
const ironBlock = BuiltinRegistry.BLOCK.get(new Identifier('minecraft:iron_block'));
|
||||
|
||||
class MyBlock extends CustomBlockWithEntity {
|
||||
class MyBlock extends CustomBlock {
|
||||
constructor() {
|
||||
super(new BlockSettings(ironBlock.getMaterial(), ironBlock.getMaterialColor()));
|
||||
}
|
||||
|
||||
onUse(world: World, blockState: BlockState, blockPos: Pos, side: Direction, player: PlayerEntity, hand: Hand): ActionResult {
|
||||
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')));
|
||||
console.log('Block Used!');
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
createBlockEntity(): CustomBlockEntity {
|
||||
return new MyBlockEntity();
|
||||
}
|
||||
}
|
||||
|
||||
Registry.register(Registry.BLOCK, new Identifier('modid', 'my_block'), new MyBlock());
|
||||
|
Reference in New Issue
Block a user