This commit is contained in:
parent
dbcf8bb6d7
commit
624193103e
@ -3,11 +3,13 @@
|
||||
## Create Your Block Class
|
||||
JavaScript:
|
||||
```javascript
|
||||
import { Identifier, BlockState, BlockSettings, ActionResult, CustomBlock } from 'minecraft';
|
||||
import { Identifier, BlockState, BlockSettings, ActionResult, CustomBlock, BuiltinRegistry } from 'minecraft';
|
||||
|
||||
const ironBlock = BuiltinRegistry.BLOCK.get(new Identifier('minecraft:iron_block'));
|
||||
|
||||
class MyBlock extends CustomBlock {
|
||||
constructor() {
|
||||
super(new BlockSettings('STONE', 'IRON'));
|
||||
super(new BlockSettings(ironBlock.getMaterial(), ironBlock.getMaterialColor()));
|
||||
}
|
||||
|
||||
onUse(world, blockState, blockPos, side, player, hand) {
|
||||
@ -19,11 +21,13 @@ class MyBlock extends CustomBlock {
|
||||
|
||||
TypeScript:
|
||||
```typescript
|
||||
import { Identifier, BlockState, BlockSettings, ActionResult, World, Pos, Hand, PlayerEntity, Direction, CustomBlock } from 'minecraft';
|
||||
import { Identifier, BlockState, BlockSettings, ActionResult, World, Pos, Hand, PlayerEntity, Direction, CustomBlock, BuiltinRegistry } from 'minecraft';
|
||||
|
||||
const ironBlock = BuiltinRegistry.BLOCK.get(new Identifier('minecraft:iron_block'));
|
||||
|
||||
class MyBlock extends CustomBlock {
|
||||
constructor() {
|
||||
super(new BlockSettings('STONE', 'IRON'));
|
||||
super(new BlockSettings(ironBlock.getMaterial(), ironBlock.getMaterialColor()));
|
||||
}
|
||||
|
||||
onUse(world: World, blockState: BlockState, blockPos: Pos, side: Direction, player: PlayerEntity, hand: Hand): ActionResult {
|
||||
|
@ -63,11 +63,13 @@ class MyBlockEntity extends CustomBlockEntity {
|
||||
## Create Your Block Class
|
||||
JavaScript:
|
||||
```javascript
|
||||
import { Identifier, BlockState, BlockSettings, ActionResult, CustomBlockWithEntity } from 'minecraft';
|
||||
import { Identifier, BlockState, BlockSettings, ActionResult, CustomBlockWithEntity, BuiltinRegistry } from 'minecraft';
|
||||
|
||||
const ironBlock = BuiltinRegistry.BLOCK.get(new Identifier('minecraft:iron_block'));
|
||||
|
||||
class MyBlock extends CustomBlockWithEntity {
|
||||
constructor() {
|
||||
super(new BlockSettings('STONE', 'IRON'));
|
||||
super(new BlockSettings(ironBlock.getMaterial(), ironBlock.getMaterialColor()));
|
||||
}
|
||||
|
||||
onUse(world, blockState, blockPos, side, player, hand) {
|
||||
@ -83,11 +85,13 @@ class MyBlock extends CustomBlockWithEntity {
|
||||
|
||||
TypeScript:
|
||||
```typescript
|
||||
import { Identifier, BlockState, BlockSettings, ActionResult, World, Pos, Hand, PlayerEntity, Direction, CustomBlock } from 'minecraft';
|
||||
import { Identifier, BlockState, BlockSettings, ActionResult, World, Pos, Hand, PlayerEntity, Direction, CustomBlock, BuiltinRegistry } from 'minecraft';
|
||||
|
||||
class MyBlock extends CustomBlock {
|
||||
const ironBlock = BuiltinRegistry.BLOCK.get(new Identifier('minecraft:iron_block'));
|
||||
|
||||
class MyBlock extends CustomBlockWithEntity {
|
||||
constructor() {
|
||||
super(new BlockSettings('STONE', 'IRON'));
|
||||
super(new BlockSettings(ironBlock.getMaterial(), ironBlock.getMaterialColor()));
|
||||
}
|
||||
|
||||
onUse(world: World, blockState: BlockState, blockPos: Pos, side: Direction, player: PlayerEntity, hand: Hand): ActionResult {
|
||||
|
@ -3,9 +3,9 @@ org.gradle.jvmargs = -Xmx1G
|
||||
|
||||
# Fabric Properties
|
||||
# check these on https://fabricmc.net/use
|
||||
minecraft_version = 1.16-pre3
|
||||
yarn_build = 1
|
||||
fabric_loader_version = 0.8.7+build.201
|
||||
minecraft_version = 1.16.2
|
||||
yarn_build = 21
|
||||
fabric_loader_version = 0.9.2+build.206
|
||||
|
||||
# Mod Properties
|
||||
mod_version = 1.0.0
|
||||
|
@ -1,36 +1,12 @@
|
||||
import { BlockSettings, Identifier, Registry, BlockState, ActionResult, BlockItem, ItemSettings, CustomItem, CustomBlockWithEntity, CustomBlockEntity, CompoundTag, NumberType } from 'minecraft';
|
||||
import { BlockSettings, Identifier, Registry, BlockState, ActionResult, BlockItem, ItemSettings, BuiltinRegistry } from 'minecraft';
|
||||
|
||||
console.log('hello');
|
||||
|
||||
class MyBlockEntity extends CustomBlockEntity {
|
||||
constructor() {
|
||||
super();
|
||||
this.ticks = 0;
|
||||
}
|
||||
|
||||
toTag(tag) {
|
||||
tag.set('MyTicks', this.ticks, NumberType.INT);
|
||||
return tag;
|
||||
}
|
||||
|
||||
fromTag(tag) {
|
||||
const obj = tag.get('MyTicks');
|
||||
if (typeof obj === 'number') {
|
||||
this.ticks = obj;
|
||||
} else {
|
||||
this.ticks = 0;
|
||||
}
|
||||
}
|
||||
|
||||
tick() {
|
||||
this.ticks++;
|
||||
this.markDirty();
|
||||
}
|
||||
}
|
||||
const ironBlock = BuiltinRegistry.BLOCK.get(new Identifier('minecraft:iron_block'));
|
||||
|
||||
class MyBlock extends CustomBlockWithEntity {
|
||||
constructor() {
|
||||
super(new BlockSettings('STONE', 'IRON'));
|
||||
super(new BlockSettings(ironBlock.getMaterial(), ironBlock.getMaterialColor()));
|
||||
}
|
||||
|
||||
onUse(world, blockState, blockPos, side, player, hand) {
|
||||
@ -49,28 +25,3 @@ class MyBlock extends CustomBlockWithEntity {
|
||||
|
||||
Registry.register(Registry.BLOCK, new Identifier('modid', 'my_block'), new MyBlock());
|
||||
Registry.register(Registry.ITEM, new Identifier('modid', 'my_block'), new BlockItem(new Identifier('modid', 'my_block'), new ItemSettings()));
|
||||
|
||||
class MyItem extends CustomItem {
|
||||
constructor() {
|
||||
super(new ItemSettings().setItemGroup('building_blocks').setMaxCount(128));
|
||||
}
|
||||
|
||||
onUse(world, player, hand) {
|
||||
console.log('Item Use: Normal');
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
onUseOnBlock(world, blockPos, side, player, hand) {
|
||||
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, target, hand) {
|
||||
console.log('Item Use: Entity ' + target.toTag().toString());
|
||||
console.log('Health: ' + target.toTag().get('Health').toString());
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
Registry.register(Registry.ITEM, new Identifier('modid', 'my_item'), new MyItem());
|
||||
|
Reference in New Issue
Block a user