2023-08-12 22:06:16 +01:00
|
|
|
import { World } from "../World";
|
2023-11-02 08:31:43 +00:00
|
|
|
import { BlockBehaviour } from "./BlockBehaviour";
|
2023-08-20 01:17:05 +01:00
|
|
|
import { BlockBehaviourFlower } from "./BlockBehaviourFlower";
|
2023-11-02 08:31:43 +00:00
|
|
|
import { BlockBehaviourGrass } from "./BlockBehaviourGrass";
|
2023-08-20 01:17:05 +01:00
|
|
|
import { IBlockBehaviour } from "./IBlockBehaviour";
|
|
|
|
|
|
|
|
abstract class Behaviour {
|
2023-11-02 08:31:43 +00:00
|
|
|
public static base = new BlockBehaviour();
|
|
|
|
|
|
|
|
public static grass = new BlockBehaviourGrass();
|
2023-08-20 01:17:05 +01:00
|
|
|
public static flower = new BlockBehaviourFlower();
|
|
|
|
}
|
2023-08-12 22:06:16 +01:00
|
|
|
|
2023-04-08 20:52:47 +01:00
|
|
|
export class Block {
|
|
|
|
public readonly blockId:number;
|
2023-11-02 08:31:43 +00:00
|
|
|
|
2023-04-13 23:52:13 +01:00
|
|
|
public static readonly blocks:Array<Block> = new Array<Block>();
|
|
|
|
public static readonly lightPassage:Array<number> = new Array<number>();
|
2023-08-20 01:17:05 +01:00
|
|
|
public static readonly blockBehaviours:Array<IBlockBehaviour> = new Array<IBlockBehaviour>();
|
2023-06-19 18:29:16 +01:00
|
|
|
public static readonly blockNames:Array<string> = new Array<string>();
|
2023-04-08 20:52:47 +01:00
|
|
|
|
|
|
|
public constructor(blockId:number) {
|
2023-04-13 23:52:13 +01:00
|
|
|
Block.blocks[blockId] = this;
|
|
|
|
Block.lightPassage[blockId] = 0;
|
2023-06-19 18:29:16 +01:00
|
|
|
Block.blockNames[blockId] = "";
|
2023-11-02 08:31:43 +00:00
|
|
|
Block.blockBehaviours[blockId] = Behaviour.base;
|
2023-04-08 20:52:47 +01:00
|
|
|
this.blockId = blockId;
|
|
|
|
}
|
|
|
|
|
2023-04-13 23:52:13 +01:00
|
|
|
public get lightPassage() {
|
|
|
|
return Block.lightPassage[this.blockId];
|
|
|
|
}
|
|
|
|
|
|
|
|
public set lightPassage(value:number) {
|
|
|
|
Block.lightPassage[this.blockId] = value;
|
|
|
|
}
|
|
|
|
|
2023-06-19 18:29:16 +01:00
|
|
|
public get blockName() {
|
|
|
|
return Block.blockNames[this.blockId];
|
|
|
|
}
|
|
|
|
|
|
|
|
public set blockName(value:string) {
|
|
|
|
Block.blockNames[this.blockId] = value;
|
|
|
|
}
|
|
|
|
|
2023-08-20 01:17:05 +01:00
|
|
|
public get behaviour() {
|
|
|
|
return Block.blockBehaviours[this.blockId];
|
|
|
|
}
|
|
|
|
|
|
|
|
public set behaviour(value:IBlockBehaviour) {
|
|
|
|
Block.blockBehaviours[this.blockId] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public setBehaviour(value:IBlockBehaviour) {
|
|
|
|
this.behaviour = value;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2023-05-02 08:50:49 +01:00
|
|
|
public setLightPassage(value:number) {
|
|
|
|
this.lightPassage = value;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2023-06-19 18:29:16 +01:00
|
|
|
public setBlockName(value:string) {
|
|
|
|
this.blockName = value;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2023-08-12 22:06:16 +01:00
|
|
|
public neighborBlockChange(world:World, x:number, y:number, z:number, blockId:number) {
|
2023-11-02 08:31:43 +00:00
|
|
|
this.behaviour.neighborBlockChange(world, x, y, z, blockId);
|
|
|
|
}
|
|
|
|
|
|
|
|
public droppedItem(blockId:number) {
|
|
|
|
this.behaviour.droppedItem(blockId);
|
2023-08-12 22:06:16 +01:00
|
|
|
}
|
|
|
|
|
2023-04-11 01:53:33 +01:00
|
|
|
// Define statics here
|
2023-06-19 18:29:16 +01:00
|
|
|
static readonly stone = new Block(1).setBlockName("Stone");
|
2023-11-02 08:31:43 +00:00
|
|
|
static readonly grass = new Block(2).setBehaviour(Behaviour.grass).setBlockName("Grass");
|
2023-06-19 18:29:16 +01:00
|
|
|
static readonly dirt = new Block(3).setBlockName("Dirt");
|
2023-04-08 20:52:47 +01:00
|
|
|
|
2023-06-19 18:29:16 +01:00
|
|
|
static readonly bedrock = new Block(7).setBlockName("Bedrock");
|
2023-04-09 04:19:10 +01:00
|
|
|
|
2023-06-19 18:29:16 +01:00
|
|
|
static readonly waterStill = new Block(9).setLightPassage(128).setBlockName("Still Water");
|
2023-04-09 04:19:10 +01:00
|
|
|
|
2023-06-19 18:29:16 +01:00
|
|
|
static readonly lavaStill = new Block(11).setBlockName("Still Lava");
|
2023-04-17 02:05:11 +01:00
|
|
|
|
2023-06-19 18:29:16 +01:00
|
|
|
static readonly sand = new Block(12).setBlockName("Sand");
|
|
|
|
static readonly gravel = new Block(13).setBlockName("Gravel");
|
2023-04-09 04:19:10 +01:00
|
|
|
|
2023-06-19 18:29:16 +01:00
|
|
|
static readonly wood = new Block(17).setBlockName("Wood");
|
|
|
|
static readonly leaves = new Block(18).setLightPassage(240).setBlockName("Leaves");
|
2023-05-02 08:50:49 +01:00
|
|
|
|
2023-06-19 18:29:16 +01:00
|
|
|
static readonly glass = new Block(20).setLightPassage(255).setBlockName("Glass");
|
2023-04-11 07:47:56 +01:00
|
|
|
|
2023-08-20 01:17:05 +01:00
|
|
|
static readonly tallGrass = new Block(31).setLightPassage(255).setBehaviour(Behaviour.flower).setBlockName("Tall Grass");
|
2023-04-13 23:52:13 +01:00
|
|
|
|
2023-06-19 18:29:16 +01:00
|
|
|
static readonly flowerDandelion = new Block(37).setLightPassage(255).setBlockName("Dandelion");
|
|
|
|
static readonly flowerRose = new Block(38).setLightPassage(255).setBlockName("Rose");
|
2023-04-17 02:05:11 +01:00
|
|
|
|
2023-06-19 18:29:16 +01:00
|
|
|
static readonly clay = new Block(82).setBlockName("Clay");
|
2023-09-04 01:43:11 +01:00
|
|
|
|
|
|
|
static readonly netherrack = new Block(87).setBlockName("Netherrack");
|
2023-04-08 20:52:47 +01:00
|
|
|
}
|