This commit is contained in:
parent
aa8e3f5e2b
commit
bc7dc8d5c2
|
@ -29,6 +29,4 @@ RUN curl -sL https://apt.kitware.com/keys/kitware-archive-latest.asc | apt-key a
|
|||
apt-get update && \
|
||||
apt-get install --no-install-recommends -y cmake
|
||||
|
||||
RUN apt-get clean
|
||||
|
||||
RUN npm install -g typescript typedoc
|
||||
RUN apt-get clean
|
28
build.gradle
28
build.gradle
|
@ -92,9 +92,8 @@ sourceSets {
|
|||
}
|
||||
}
|
||||
|
||||
def typescriptRoot = rootProject.typescript_root as String
|
||||
def resources = new File(rootProject.rootDir, 'src/main/resources')
|
||||
def typescriptRootFile = new File(resources, typescriptRoot)
|
||||
def typescriptRoot = 'src/main/js'
|
||||
def typescriptRootFile = new File(rootDir.absolutePath, typescriptRoot)
|
||||
|
||||
task typescript(group: 'build') {
|
||||
inputs.dir typescriptRootFile
|
||||
|
@ -107,14 +106,24 @@ task typescript(group: 'build') {
|
|||
typescriptOut.mkdirs()
|
||||
|
||||
project.exec {
|
||||
executable 'tsc'
|
||||
workingDir typescriptRootFile
|
||||
|
||||
args '--outDir', new File(typescriptOut, typescriptRoot).absolutePath
|
||||
args '--project', typescriptRootFile.absolutePath
|
||||
executable 'npm'
|
||||
|
||||
args 'run', 'build', '--'
|
||||
args '--outDir', new File(typescriptOut, 'scriptcraft').absolutePath
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
task eslint(group: 'verification', type: Exec) {
|
||||
workingDir typescriptRootFile
|
||||
|
||||
executable 'npm'
|
||||
|
||||
args 'run', 'eslint'
|
||||
}
|
||||
|
||||
processResources.dependsOn typescript
|
||||
|
||||
def typedocOut = new File(buildDir, 'typedoc')
|
||||
|
@ -131,8 +140,10 @@ task typedoc(group: 'documentation') {
|
|||
|
||||
project.exec {
|
||||
workingDir typescriptRootFile
|
||||
executable 'typedoc'
|
||||
|
||||
executable 'npm'
|
||||
|
||||
args 'run', 'typedoc', '--'
|
||||
args '--out', typedocOut.absolutePath
|
||||
}
|
||||
}
|
||||
|
@ -151,9 +162,6 @@ processResources {
|
|||
exclude 'fabric.mod.json'
|
||||
}
|
||||
|
||||
exclude typescriptRoot + '/**/*.ts'
|
||||
exclude typescriptRoot + '/types'
|
||||
|
||||
for (JNIPlatform platform : jniPlatforms) {
|
||||
def buildDir = new File(cDir, "build-${platform.name}")
|
||||
if (!buildDir.exists()) {
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
# Done to increase the memory available to gradle.
|
||||
org.gradle.jvmargs = -Xmx1G
|
||||
|
||||
typescript_root = scriptcraft
|
||||
|
||||
# Fabric Properties
|
||||
# check these on https://fabricmc.net/use
|
||||
minecraft_version = 1.15.2
|
||||
|
|
|
@ -3,4 +3,7 @@
|
|||
set -e
|
||||
|
||||
./download-quickjs.sh
|
||||
./download-jni-headers.sh
|
||||
./download-jni-headers.sh
|
||||
|
||||
cd ../src/main/js
|
||||
npm install
|
|
@ -12,22 +12,22 @@ import net.minecraft.util.math.BlockPos;
|
|||
import net.minecraft.world.World;
|
||||
|
||||
public class CustomBlockEntity extends BlockEntity implements BlockEntityClientSerializable, Tickable {
|
||||
private static long newObjID = 0;
|
||||
private static double newObjID = 0;
|
||||
|
||||
private final long objID;
|
||||
private final double objID;
|
||||
|
||||
public CustomBlockEntity(BlockEntityType<?> type, Identifier id) {
|
||||
super(type);
|
||||
|
||||
objID = newObjID++;
|
||||
|
||||
QuickJSManager.bridge("CustomBlockEntity.create", id.toString(), (double) objID);
|
||||
QuickJSManager.bridge("CustomBlockEntity.create", id.toString(), objID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromTag(CompoundTag tag) {
|
||||
super.fromTag(tag);
|
||||
QuickJSManager.bridge("CustomBlockEntity.fromTag", (double) objID, tag);
|
||||
QuickJSManager.bridge("CustomBlockEntity.fromTag", objID, tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -37,7 +37,7 @@ public class CustomBlockEntity extends BlockEntity implements BlockEntityClientS
|
|||
|
||||
@Override
|
||||
public CompoundTag toTag(CompoundTag tag) {
|
||||
return (CompoundTag) QuickJSManager.bridge("CustomBlockEntity.toTag", (double) objID, super.toTag(tag));
|
||||
return (CompoundTag) QuickJSManager.bridge("CustomBlockEntity.toTag", objID, super.toTag(tag));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -47,20 +47,20 @@ public class CustomBlockEntity extends BlockEntity implements BlockEntityClientS
|
|||
|
||||
@Override
|
||||
public void tick() {
|
||||
QuickJSManager.bridge("CustomBlockEntity.tick", (double) objID);
|
||||
QuickJSManager.bridge("CustomBlockEntity.tick", objID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLocation(World world, BlockPos pos) {
|
||||
super.setLocation(world, pos);
|
||||
QuickJSManager.bridge("CustomBlockEntity.setLocation", (double) objID, world, (double) pos.getX(), (double) pos.getY(), (double) pos.getZ());
|
||||
QuickJSManager.bridge("CustomBlockEntity.setLocation", objID, world, (double) pos.getX(), (double) pos.getY(), (double) pos.getZ());
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
protected void finalize() throws Throwable {
|
||||
try {
|
||||
QuickJSManager.bridge("CustomBlockEntity.free", (double) objID);
|
||||
QuickJSManager.bridge("CustomBlockEntity.free", objID);
|
||||
} finally {
|
||||
super.finalize();
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ public class CustomBlockEntity extends BlockEntity implements BlockEntityClientS
|
|||
}
|
||||
}
|
||||
|
||||
public long getObjID() {
|
||||
public double getObjID() {
|
||||
return objID;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.thebrokenrail.scriptcraft.api.block;
|
||||
|
||||
import com.thebrokenrail.scriptcraft.api.block.CustomBlock;
|
||||
import com.thebrokenrail.scriptcraft.api.block.CustomBlockEntity;
|
||||
import net.minecraft.block.BlockEntityProvider;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
|
29
src/main/js/.eslintrc.json
Normal file
29
src/main/js/.eslintrc.json
Normal file
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
"root": true,
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"parserOptions": {
|
||||
"tsconfigRootDir": ".",
|
||||
"project": ["./tsconfig.json"]
|
||||
},
|
||||
"plugins": [
|
||||
"@typescript-eslint"
|
||||
],
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:@typescript-eslint/eslint-recommended",
|
||||
"plugin:@typescript-eslint/recommended",
|
||||
"plugin:@typescript-eslint/recommended-requiring-type-checking"
|
||||
],
|
||||
"rules": {
|
||||
"@typescript-eslint/no-extra-parens": "error",
|
||||
"@typescript-eslint/semi": "error",
|
||||
"curly": "error",
|
||||
"@typescript-eslint/indent": ["error", 4],
|
||||
"arrow-parens": ["error", "as-needed"],
|
||||
"@typescript-eslint/no-unused-vars": "off",
|
||||
"@typescript-eslint/no-empty-function": "off",
|
||||
"@typescript-eslint/no-use-before-define": "off",
|
||||
"quotes": ["error", "single"],
|
||||
"eol-last": ["error", "always"]
|
||||
}
|
||||
}
|
2
src/main/js/.gitignore
vendored
Normal file
2
src/main/js/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
node_modules/
|
||||
package-lock.json
|
15
src/main/js/package.json
Normal file
15
src/main/js/package.json
Normal file
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"name": "scriptcraft",
|
||||
"devDependencies": {
|
||||
"@typescript-eslint/eslint-plugin": "latest",
|
||||
"@typescript-eslint/parser": "latest",
|
||||
"eslint": "latest",
|
||||
"typedoc": "latest",
|
||||
"typescript": "latest"
|
||||
},
|
||||
"scripts": {
|
||||
"eslint": "eslint --ignore-path .gitignore src",
|
||||
"build": "tsc",
|
||||
"typedoc": "typedoc"
|
||||
}
|
||||
}
|
|
@ -89,11 +89,80 @@ export class CustomBlock {
|
|||
* @param hand Hand
|
||||
* @returns Action Result
|
||||
*/
|
||||
onUse(world: World, blockState: BlockState, pos: Pos, side: Direction, player: PlayerEntity, hand: Hand) {
|
||||
onUse(world: World, blockState: BlockState, pos: Pos, side: Direction, player: PlayerEntity, hand: Hand): ActionResult {
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom Block Entity
|
||||
*/
|
||||
export class CustomBlockEntity {
|
||||
/**
|
||||
* World
|
||||
*/
|
||||
protected world: World;
|
||||
/**
|
||||
* Position
|
||||
*/
|
||||
protected pos: Pos;
|
||||
|
||||
/**
|
||||
* Set Location
|
||||
* @param world New World
|
||||
* @param pos New Position
|
||||
*/
|
||||
setLocation(world: World, pos: Pos): void {
|
||||
this.world = world;
|
||||
this.pos = pos;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save Data To Tag
|
||||
* @param tag Tag
|
||||
* @returns Tag
|
||||
*/
|
||||
toTag(tag: CompoundTag): CompoundTag {
|
||||
return tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Data From Tag
|
||||
* @param tag Tag
|
||||
*/
|
||||
fromTag(tag: CompoundTag): void {}
|
||||
|
||||
/**
|
||||
* Runs Every Tick
|
||||
*/
|
||||
tick(): void {}
|
||||
|
||||
/**
|
||||
* Get World
|
||||
* @returns World
|
||||
*/
|
||||
getWorld(): World {
|
||||
return this.world;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Position
|
||||
* @returns Position
|
||||
*/
|
||||
getPos(): Pos {
|
||||
return this.pos;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark Dirty
|
||||
*/
|
||||
markDirty(): void {
|
||||
if (this.getWorld() != null) {
|
||||
useBridge('World.markBlockEntityDirty', this.getWorld().javaObject, this.getPos().getX(), this.getPos().getY(), this.getPos().getZ());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Block State
|
||||
*/
|
||||
|
@ -144,75 +213,6 @@ export class BlockState {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom Block Entity
|
||||
*/
|
||||
export class CustomBlockEntity {
|
||||
/**
|
||||
* World
|
||||
*/
|
||||
protected world: World;
|
||||
/**
|
||||
* Position
|
||||
*/
|
||||
protected pos: Pos;
|
||||
|
||||
/**
|
||||
* Set Location
|
||||
* @param world New World
|
||||
* @param pos New Position
|
||||
*/
|
||||
setLocation(world: World, pos: Pos) {
|
||||
this.world = world;
|
||||
this.pos = pos;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save Data To Tag
|
||||
* @param tag Tag
|
||||
* @returns Tag
|
||||
*/
|
||||
toTag(tag: CompoundTag) {
|
||||
return tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Data From Tag
|
||||
* @param tag Tag
|
||||
*/
|
||||
fromTag(tag: CompoundTag) {}
|
||||
|
||||
/**
|
||||
* Runs Every Tick
|
||||
*/
|
||||
tick() {}
|
||||
|
||||
/**
|
||||
* Get World
|
||||
* @returns World
|
||||
*/
|
||||
getWorld() {
|
||||
return this.world;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Position
|
||||
* @returns Position
|
||||
*/
|
||||
getPos() {
|
||||
return this.pos;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark Dirty
|
||||
*/
|
||||
markDirty() {
|
||||
if (this.getWorld() != null) {
|
||||
useBridge('World.markBlockEntityDirty', this.getWorld().javaObject, this.getPos().getX(), this.getPos().getY(), this.getPos().getZ());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link CustomBlock} With {@link CustomBlockEntity}
|
||||
*/
|
||||
|
@ -241,7 +241,7 @@ export class BlockRegistry implements SimpleRegistry<CustomBlock> {
|
|||
this.#blockEntities = [];
|
||||
}
|
||||
|
||||
register(id: Identifier, obj: CustomBlock) {
|
||||
register(id: Identifier, obj: CustomBlock): void {
|
||||
this.#blocks.set(id.toString(), obj);
|
||||
if (obj instanceof CustomBlockWithEntity) {
|
||||
useBridge('Registry.registerBlockWithEntity', id.toString(), obj.settings.createJavaObject());
|
||||
|
@ -271,12 +271,12 @@ export class BlockRegistry implements SimpleRegistry<CustomBlock> {
|
|||
return this.#blockEntities;
|
||||
}
|
||||
|
||||
createCustomBlockEntity(id: Identifier, i: number) {
|
||||
createCustomBlockEntity(id: Identifier, i: number): void {
|
||||
const block = this.get(id) as CustomBlockWithEntity;
|
||||
this.#blockEntities[this.#blockEntities.length] = (block.createBlockEntity());
|
||||
this.#blockEntities[i] = block.createBlockEntity();
|
||||
}
|
||||
|
||||
freeCustomBlockEntity(i: number) {
|
||||
freeCustomBlockEntity(i: number): void {
|
||||
delete this.#blockEntities[i];
|
||||
}
|
||||
}
|
||||
|
@ -289,10 +289,9 @@ addBridge('CustomBlockEntity.fromTag', (i: number, tag: JavaObject) => {
|
|||
BlockRegistry.INSTANCE.getCustomBlockEntity(i).fromTag(new CompoundTag(tag));
|
||||
});
|
||||
|
||||
addBridge('CustomBlockEntity.toTag', ( i: number, tag: JavaObject): JavaObject => {
|
||||
return BlockRegistry.INSTANCE.getCustomBlockEntity(i).toTag(new CompoundTag(tag)).javaObject;
|
||||
}
|
||||
);
|
||||
addBridge('CustomBlockEntity.toTag', (i: number, tag: JavaObject): JavaObject => {
|
||||
return BlockRegistry.INSTANCE.getCustomBlockEntity(i).toTag(new CompoundTag(tag)).javaObject;
|
||||
});
|
||||
|
||||
addBridge('CustomBlockEntity.tick', (i: number) => {
|
||||
BlockRegistry.INSTANCE.getCustomBlockEntity(i).tick();
|
||||
|
@ -303,7 +302,9 @@ addBridge('CustomBlockEntity.setLocation', (i: number, world: JavaObject, x: num
|
|||
});
|
||||
|
||||
addBridge('CustomBlockEntity.free', (i: number) => {
|
||||
console.log('Free: ' + i);
|
||||
BlockRegistry.INSTANCE.freeCustomBlockEntity(i);
|
||||
console.log('Free After: ' + BlockRegistry.INSTANCE.getCustomBlockEntity(i));
|
||||
});
|
||||
|
||||
addBridge('CustomBlock.onUse', (id: string, world: JavaObject, state: JavaObject, x: number, y: number, z: number, side: keyof typeof Direction, player: JavaObject, hand: keyof typeof Hand): string => {
|
|
@ -25,7 +25,7 @@ export class DamageSource {
|
|||
*/
|
||||
private static build(bridge: string, value: BridgeValueType): DamageSource {
|
||||
const obj = useBridge(bridge, value) as JavaObject;
|
||||
if (obj) {
|
||||
if (obj != null) {
|
||||
return new DamageSource(obj);
|
||||
} else {
|
||||
return null;
|
||||
|
@ -89,7 +89,7 @@ export class Entity {
|
|||
*/
|
||||
getEntityWorld(): World {
|
||||
const obj = useBridge('Entity.getEntityWorld', this.javaObject) as JavaObject;
|
||||
if (obj) {
|
||||
if (obj != null) {
|
||||
return new World(obj);
|
||||
} else {
|
||||
return null;
|
||||
|
@ -102,7 +102,7 @@ export class Entity {
|
|||
*/
|
||||
getID(): Identifier {
|
||||
const obj = useBridge('Entity.getID', this.javaObject) as string;
|
||||
if (obj) {
|
||||
if (obj != null) {
|
||||
return new Identifier(obj);
|
||||
} else {
|
||||
return null;
|
||||
|
@ -143,14 +143,14 @@ export class Entity {
|
|||
/**
|
||||
* Kill Entity
|
||||
*/
|
||||
kill() {
|
||||
kill(): void {
|
||||
useBridge('Entity.kill', this.javaObject);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove Entity
|
||||
*/
|
||||
remove() {
|
||||
remove(): void {
|
||||
useBridge('Entity.remove', this.javaObject);
|
||||
}
|
||||
|
||||
|
@ -158,7 +158,7 @@ export class Entity {
|
|||
* Set Entity Fire Ticks
|
||||
* @param ticks Fire Ticks
|
||||
*/
|
||||
setFireTicks(ticks: number) {
|
||||
setFireTicks(ticks: number): void {
|
||||
useBridge('Entity.setFireTicks', this.javaObject, ticks);
|
||||
}
|
||||
|
||||
|
@ -175,7 +175,7 @@ export class Entity {
|
|||
* @param source Damage Source
|
||||
* @param amount Damage Amount
|
||||
*/
|
||||
damage(source: DamageSource, amount: number) {
|
||||
damage(source: DamageSource, amount: number): void {
|
||||
useBridge('Entity.damage', source.javaObject, amount);
|
||||
}
|
||||
|
||||
|
@ -185,7 +185,7 @@ export class Entity {
|
|||
*/
|
||||
getPosition(): Pos {
|
||||
const pos: number[] = useBridge('Entity.getPosition', this.javaObject) as number[];
|
||||
if (pos && pos.length === 3) {
|
||||
if (pos != null && pos.length === 3) {
|
||||
return new Pos(pos[0], pos[1], pos[2]);
|
||||
} else {
|
||||
return null;
|
||||
|
@ -196,7 +196,7 @@ export class Entity {
|
|||
* Set Entity Position
|
||||
* @param pos Entity Position
|
||||
*/
|
||||
setPosition(pos: Pos) {
|
||||
setPosition(pos: Pos): void {
|
||||
useBridge('Entity.setPosition', this.javaObject, pos.getX(), pos.getY(), pos.getZ());
|
||||
}
|
||||
|
||||
|
@ -206,7 +206,7 @@ export class Entity {
|
|||
*/
|
||||
toTag(): CompoundTag {
|
||||
const obj = useBridge('Entity.toTag', this.javaObject) as JavaObject;
|
||||
if (obj) {
|
||||
if (obj != null) {
|
||||
return new CompoundTag(obj);
|
||||
} else {
|
||||
return null;
|
||||
|
@ -217,7 +217,7 @@ export class Entity {
|
|||
* Load Data From {@link CompoundTag}
|
||||
* @param tag Tag
|
||||
*/
|
||||
fromTag(tag: CompoundTag) {
|
||||
fromTag(tag: CompoundTag): void {
|
||||
useBridge('Entity.fromTag', this.javaObject, tag.javaObject);
|
||||
}
|
||||
}
|
|
@ -14,4 +14,4 @@ export { ItemStack, ItemSettings, CustomItem, BlockItem } from './item';
|
|||
export { World } from './world';
|
||||
export { LivingEntity, PlayerEntity } from './entity';
|
||||
export { CompoundTag, ListTag, NumberType } from './tag';
|
||||
export { Registry } from './registry';
|
||||
export { Registry } from './registry';
|
|
@ -27,7 +27,7 @@ export class ItemStack {
|
|||
*/
|
||||
static create(item: Identifier, count?: number): ItemStack {
|
||||
const obj = useBridge('ItemStack.create', item.toString(), count ? count : 1) as JavaObject;
|
||||
if (obj) {
|
||||
if (obj != null) {
|
||||
return new ItemStack(obj);
|
||||
} else {
|
||||
return null;
|
||||
|
@ -40,7 +40,7 @@ export class ItemStack {
|
|||
*/
|
||||
getItem(): Identifier {
|
||||
const obj = useBridge('ItemStack.getItem', this.javaObject) as string;
|
||||
if (obj) {
|
||||
if (obj != null) {
|
||||
return new Identifier(obj);
|
||||
} else {
|
||||
return null;
|
||||
|
@ -67,7 +67,7 @@ export class ItemStack {
|
|||
* Set Item Count
|
||||
* @param count New Count
|
||||
*/
|
||||
setCount(count: number) {
|
||||
setCount(count: number): void {
|
||||
useBridge('ItemStack.setCount', this.javaObject, count);
|
||||
}
|
||||
|
||||
|
@ -83,7 +83,7 @@ export class ItemStack {
|
|||
* Set Item Damage
|
||||
* @param count New Damage
|
||||
*/
|
||||
setDamage(damage: number) {
|
||||
setDamage(damage: number): void {
|
||||
useBridge('ItemStack.setDamage', this.javaObject, damage);
|
||||
}
|
||||
|
||||
|
@ -101,7 +101,7 @@ export class ItemStack {
|
|||
*/
|
||||
getTag(): CompoundTag {
|
||||
const obj = useBridge('ItemStack.getTag', this.javaObject) as JavaObject;
|
||||
if (obj) {
|
||||
if (obj != null) {
|
||||
return new CompoundTag(obj);
|
||||
} else {
|
||||
return null;
|
||||
|
@ -112,7 +112,7 @@ export class ItemStack {
|
|||
* Set Item Tag
|
||||
* @param tag New Item Tag
|
||||
*/
|
||||
setTag(tag: CompoundTag) {
|
||||
setTag(tag: CompoundTag): void {
|
||||
useBridge('ItemStack.setTag', this.javaObject, tag.javaObject);
|
||||
}
|
||||
|
||||
|
@ -122,7 +122,7 @@ export class ItemStack {
|
|||
*/
|
||||
toTag(): CompoundTag {
|
||||
const obj = useBridge('ItemStack.toTag', this.javaObject) as JavaObject;
|
||||
if (obj) {
|
||||
if (obj != null) {
|
||||
return new CompoundTag(obj);
|
||||
} else {
|
||||
return null;
|
||||
|
@ -136,7 +136,7 @@ export class ItemStack {
|
|||
*/
|
||||
static fromTag(tag: CompoundTag): ItemStack {
|
||||
const obj = useBridge('ItemStack.fromTag', tag.javaObject) as JavaObject;
|
||||
if (obj) {
|
||||
if (obj != null) {
|
||||
return new ItemStack(obj);
|
||||
} else {
|
||||
return null;
|
||||
|
@ -225,7 +225,7 @@ export class CustomItem {
|
|||
* @param hand Hand
|
||||
* @returns Action Result
|
||||
*/
|
||||
onUse(world: World, player: PlayerEntity, hand: Hand) {
|
||||
onUse(world: World, player: PlayerEntity, hand: Hand): ActionResult {
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
|
||||
|
@ -238,7 +238,7 @@ export class CustomItem {
|
|||
* @param hand Hand
|
||||
* @returns Action Result
|
||||
*/
|
||||
onUseOnBlock(world: World, pos: Pos, side: Direction, player: PlayerEntity, hand: Hand) {
|
||||
onUseOnBlock(world: World, pos: Pos, side: Direction, player: PlayerEntity, hand: Hand): ActionResult {
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
|
||||
|
@ -249,7 +249,7 @@ export class CustomItem {
|
|||
* @param hand Hand
|
||||
* @returns Action Result
|
||||
*/
|
||||
onUseOnEntity(player: PlayerEntity, target: LivingEntity, hand: Hand) {
|
||||
onUseOnEntity(player: PlayerEntity, target: LivingEntity, hand: Hand): ActionResult {
|
||||
return ActionResult.PASS;
|
||||
}
|
||||
}
|
||||
|
@ -290,7 +290,7 @@ export class ItemRegistry implements SimpleRegistry<CustomItem | BlockItem> {
|
|||
this.#items = new Map<string, CustomItem>();
|
||||
}
|
||||
|
||||
register(id: Identifier, obj: CustomItem | BlockItem) {
|
||||
register(id: Identifier, obj: CustomItem | BlockItem): void {
|
||||
if (obj instanceof CustomItem) {
|
||||
this.#items.set(id.toString(), obj);
|
||||
useBridge('Registry.registerItem', id.toString(), obj.settings.createJavaObject());
|
|
@ -85,7 +85,7 @@ export class CompoundTag {
|
|||
*/
|
||||
set(key: string, value: number, numberType: NumberType): void;
|
||||
set(key: string, value: Exclude<TagType, number>): void;
|
||||
set(key: string, value: TagType, numberType?: NumberType) {
|
||||
set(key: string, value: TagType, numberType?: NumberType): void {
|
||||
useBridge('CompoundTag.set', this.javaObject, key, value instanceof CompoundTag || value instanceof ListTag ? value.javaObject : value, numberType != null ? numberType : NumberType.DOUBLE);
|
||||
}
|
||||
|
||||
|
@ -103,7 +103,7 @@ export class CompoundTag {
|
|||
*/
|
||||
static create(): CompoundTag {
|
||||
const obj = useBridge('CompoundTag.create') as JavaObject;
|
||||
if (obj) {
|
||||
if (obj != null) {
|
||||
return new CompoundTag(obj);
|
||||
} else {
|
||||
return null;
|
||||
|
@ -147,7 +147,7 @@ export class ListTag {
|
|||
*/
|
||||
set(key: number, value: number, numberType: NumberType): void;
|
||||
set(key: number, value: Exclude<TagType, number>): void;
|
||||
set(key: number, value: TagType, numberType?: NumberType) {
|
||||
set(key: number, value: TagType, numberType?: NumberType): void {
|
||||
useBridge('ListTag.set', this.javaObject, key, value instanceof CompoundTag || value instanceof ListTag ? value.javaObject : value, numberType != null ? numberType : NumberType.DOUBLE);
|
||||
}
|
||||
|
||||
|
@ -165,7 +165,7 @@ export class ListTag {
|
|||
*/
|
||||
static create(): ListTag {
|
||||
const obj = useBridge('ListTag.create') as JavaObject;
|
||||
if (obj) {
|
||||
if (obj != null) {
|
||||
return new ListTag(obj);
|
||||
} else {
|
||||
return null;
|
|
@ -36,7 +36,7 @@ export class World {
|
|||
*/
|
||||
getBlockState(pos: Pos): BlockState {
|
||||
const obj = useBridge('World.getBlockState', this.javaObject, pos.getX(), pos.getY(), pos.getZ()) as JavaObject;
|
||||
if (obj) {
|
||||
if (obj != null) {
|
||||
return new BlockState(obj);
|
||||
} else {
|
||||
return null;
|
||||
|
@ -50,7 +50,7 @@ export class World {
|
|||
*/
|
||||
spawnEntity(id: Identifier, pos: Pos): Entity {
|
||||
const obj = useBridge('World.spawnEntity', this.javaObject, pos.getX(), pos.getY(), pos.getZ(), id.toString()) as JavaObject;
|
||||
if (obj) {
|
||||
if (obj != null) {
|
||||
return new Entity(obj);
|
||||
} else {
|
||||
return null;
|
||||
|
@ -63,8 +63,8 @@ export class World {
|
|||
* @returns Custom Block Entity At Position
|
||||
*/
|
||||
getCustomBlockEntity(pos: Pos): CustomBlockEntity {
|
||||
const obj = useBridge('World.getBlockEntity', this.javaObject, pos.getX(), pos.getY(), pos.getZ()) as number;
|
||||
if (obj) {
|
||||
const obj = useBridge('World.getCustomBlockEntity', this.javaObject, pos.getX(), pos.getY(), pos.getZ()) as number;
|
||||
if (obj != null) {
|
||||
return BlockRegistry.INSTANCE.getCustomBlockEntity(obj);
|
||||
} else {
|
||||
return null;
|
||||
|
@ -78,7 +78,7 @@ export class World {
|
|||
*/
|
||||
getBlockEntity(pos: Pos): Identifier {
|
||||
const obj = useBridge('World.getBlockEntity', this.javaObject, pos.getX(), pos.getY(), pos.getZ()) as string;
|
||||
if (obj) {
|
||||
if (obj != null) {
|
||||
return new Identifier(obj);
|
||||
} else {
|
||||
return null;
|
|
@ -1,4 +1,4 @@
|
|||
import { BlockSettings, Identifier, Registry, BlockState, ActionResult, World, Pos, Hand, PlayerEntity, BlockItem, ItemSettings, CustomItem, Direction, LivingEntity, CustomBlockWithEntity, CustomBlockEntity, CompoundTag, NumberType } from 'minecraft';
|
||||
import { BlockSettings, Identifier, Registry, BlockState, ActionResult, World, Pos, Hand, PlayerEntity, BlockItem, ItemSettings, CustomItem, Direction, LivingEntity, CustomBlockWithEntity, CustomBlockEntity, CompoundTag, NumberType } from 'src/minecraft/index';
|
||||
|
||||
console.log('hello');
|
||||
|
||||
|
@ -10,7 +10,7 @@ class MyBlockEntity extends CustomBlockEntity {
|
|||
return tag;
|
||||
}
|
||||
|
||||
fromTag(tag: CompoundTag) {
|
||||
fromTag(tag: CompoundTag): void {
|
||||
const obj = tag.get('MyTicks');
|
||||
if (typeof obj === 'number') {
|
||||
this.ticks = obj;
|
||||
|
@ -19,7 +19,7 @@ class MyBlockEntity extends CustomBlockEntity {
|
|||
}
|
||||
}
|
||||
|
||||
tick() {
|
||||
tick(): void {
|
||||
this.ticks++;
|
||||
this.markDirty();
|
||||
}
|
|
@ -31,4 +31,4 @@ declare module 'scriptcraft-core' {
|
|||
function addBridge(name: string, bridge: BridgeType): void;
|
||||
|
||||
function useBridge(name: string, ...args: BridgeValueType[]): BridgeValueType;
|
||||
}
|
||||
}
|
|
@ -7,14 +7,14 @@
|
|||
"lib": ["es2020"],
|
||||
"module": "es2020",
|
||||
"target": "es2020",
|
||||
"typeRoots": ["types"],
|
||||
"rootDir": ".",
|
||||
"baseUrl": ".",
|
||||
"typeRoots": ["src/types"],
|
||||
"rootDir": "src",
|
||||
"baseUrl": "src",
|
||||
"paths": {
|
||||
"minecraft": ["minecraft/index"]
|
||||
"minecraft": ["src/minecraft/index"]
|
||||
}
|
||||
},
|
||||
"include": [
|
||||
"**/*"
|
||||
"src/**/*.ts"
|
||||
]
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
{
|
||||
"trailingComma": "none",
|
||||
"tabWidth": 4,
|
||||
"semi": true,
|
||||
"singleQuote": true,
|
||||
"arrowParens": "avoid",
|
||||
"printWidth": 24000
|
||||
}
|
Reference in New Issue
Block a user