mc-beta-server/server/tileentities/TileEntityLoader.ts
Holly c0872ead39
All checks were successful
Node.js Build / build (20.x) (push) Successful in 5m17s
Tile Entities + misc changes
- Tile Entities
 - TextColorParser for chat colours on the console
 - package.json ver bumps
 - De-dupe WorldSaveManager!!
2024-11-25 02:30:27 +00:00

25 lines
No EOL
912 B
TypeScript

import { IReader } from "bufferstuff";
import Block from "../blocks/Block";
import TileEntity from "./TileEntity";
import TileEntityChest from "./TileEntityChest";
import TileEntityType from "../enums/TileEntityType";
import Vec3 from "../Vec3";
// I would like this to be in TileEntity, but recursive dependency.
export default abstract class TileEntityLoader {
public static FromSave(reader:IReader) : TileEntity {
let tileEntity:TileEntity;
const type: TileEntityType = reader.readUByte();
const forBlock = Block.blocks[reader.readUByte()];
const position = new Vec3(reader.readUByte(), reader.readUByte(), reader.readUByte());
if (type === TileEntityType.Chest) {
tileEntity = new TileEntityChest(type, forBlock, position);
} else {
tileEntity = new TileEntity(type, forBlock, position);
}
// Call instantiated class' fromSave
tileEntity.fromSave(reader);
return tileEntity;
}
}