Update Docs And Fix Gradle Plugin
All checks were successful
ScriptCraft/pipeline/head This commit looks good

This commit is contained in:
TheBrokenRail 2020-06-01 19:07:01 -04:00
parent 82f5dabd58
commit e7a6b55d76
8 changed files with 240 additions and 7 deletions

View File

@ -7,4 +7,6 @@
[View Architecture](ARCHITECTURE.md)
[View Tutorials](tutorials/README.md)
[View TypeDoc](https://jenkins.thebrokenrail.com/job/ScriptCraft/job/master/TypeDoc/)

48
docs/tutorials/BLOCK.md Normal file
View File

@ -0,0 +1,48 @@
# Create A Block
## Create Your Block Class
JavaScript:
```javascript
import { Identifier, BlockState, BlockSettings, ActionResult, CustomBlock } from 'minecraft';
class MyBlock extends CustomBlock {
constructor() {
super(new BlockSettings('STONE', 'IRON'));
}
onUse(world, blockState, blockPos, side, player, hand) {
world.setBlockState(blockPos.offset(side), BlockState.getDefaultState(new Identifier('minecraft:stone')));
return ActionResult.SUCCESS;
}
}
```
TypeScript:
```typescript
import { Identifier, BlockState, BlockSettings, ActionResult, World, Pos, Hand, PlayerEntity, Direction, CustomBlock } from 'minecraft';
class MyBlock extends CustomBlock {
constructor() {
super(new BlockSettings('STONE', 'IRON'));
}
onUse(world: World, blockState: BlockState, blockPos: Pos, side: Direction, player: PlayerEntity, hand: Hand): ActionResult {
world.setBlockState(blockPos.offset(side), BlockState.getDefaultState(new Identifier('minecraft:stone')));
return ActionResult.SUCCESS;
}
}
```
## Register Your Block
```javascript
import { Registry, Identifier } from 'minecraft';
Registry.register(Registry.BLOCK, new Identifier('modid', 'my_block'), new MyBlock());
```
## Register Your Block Item
```javascript
import { Registry, Identifier, BlockItem, ItemSettings } from 'minecraft';
Registry.register(Registry.ITEM, new Identifier('modid', 'my_block'), new BlockItem(new Identifier('modid', 'my_block'), new ItemSettings().setItemGroup('building_blocks')));
```

View File

@ -0,0 +1,112 @@
# Create A Block
## Create Your Block Entity Class
JavaScript:
```javascript
import { CustomBlockEntity, NumberType } from 'minecraft';
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();
}
}
```
TypeScript:
```typescript
import { CustomBlockEntity, CompoundTag, NumberType } from 'minecraft';
class MyBlockEntity extends CustomBlockEntity {
ticks = 0;
toTag(tag: CompoundTag): CompoundTag {
tag.set('MyTicks', this.ticks, NumberType.INT);
return tag;
}
fromTag(tag: CompoundTag): void {
const obj = tag.get('MyTicks');
if (typeof obj === 'number') {
this.ticks = obj;
} else {
this.ticks = 0;
}
}
tick(): void {
this.ticks++;
this.markDirty();
}
}
```
## Create Your Block Class
JavaScript:
```javascript
import { Identifier, BlockState, BlockSettings, ActionResult, CustomBlockWithEntity } from 'minecraft';
class MyBlock extends CustomBlockWithEntity {
constructor() {
super(new BlockSettings('STONE', 'IRON'));
}
onUse(world, blockState, blockPos, side, player, hand) {
world.setBlockState(blockPos.offset(side), BlockState.getDefaultState(new Identifier('minecraft:stone')));
return ActionResult.SUCCESS;
}
createBlockEntity() {
return new MyBlockEntity();
}
}
```
TypeScript:
```typescript
import { Identifier, BlockState, BlockSettings, ActionResult, World, Pos, Hand, PlayerEntity, Direction, CustomBlock } from 'minecraft';
class MyBlock extends CustomBlock {
constructor() {
super(new BlockSettings('STONE', 'IRON'));
}
onUse(world: World, blockState: BlockState, blockPos: Pos, side: Direction, player: PlayerEntity, hand: Hand): ActionResult {
world.setBlockState(blockPos.offset(side), BlockState.getDefaultState(new Identifier('minecraft:stone')));
return ActionResult.SUCCESS;
}
}
```
## Register Your Block
```javascript
import { Registry, Identifier } from 'minecraft';
Registry.register(Registry.BLOCK, new Identifier('modid', 'my_block'), new MyBlock());
```
## Register Your Block Item
```javascript
import { Registry, Identifier, BlockItem, ItemSettings } from 'minecraft';
Registry.register(Registry.ITEM, new Identifier('modid', 'my_block'), new BlockItem(new Identifier('modid', 'my_block'), new ItemSettings().setItemGroup('building_blocks')));
```

61
docs/tutorials/ITEM.md Normal file
View File

@ -0,0 +1,61 @@
# 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());
```

6
docs/tutorials/README.md Normal file
View File

@ -0,0 +1,6 @@
# Tutorials
[Create A Block](BLOCK.md)
[Create A Block Entity](BLOCK_ENTITY.md)
[Create A Item](ITEM.md)

View File

@ -3,7 +3,10 @@ import { BlockSettings, Identifier, Registry, BlockState, ActionResult, World, P
console.log('hello');
class MyBlockEntity extends CustomBlockEntity {
ticks = 0;
constructor() {
super();
this.ticks = 0;
}
toTag(tag) {
tag.set('MyTicks', this.ticks, NumberType.INT);

View File

@ -159,11 +159,11 @@ class ScriptCraftPlugin : Plugin<Project> {
tasks.named<Copy>("processResources") {
dependsOn(typescriptTask)
into("scriptcraft") {
from(Callable {
File(extension.root, "build/ts")
})
into("scriptcraft")
}
}
}
}

View File

@ -43,7 +43,8 @@ public class QuickJSModules {
}
stream.close();
return isDirectory(textBuilder.toString(), path, mod.getClass()) ? null : textBuilder.toString();
String data = textBuilder.toString();
return isDirectory(data, path, mod.getClass()) ? null : data;
}
} catch (IOException e) {
}