mc-beta-server/server/tileentities/TileEntityLoader.ts
Holly d82b86546a
All checks were successful
Node.js Build / build (20.x) (push) Successful in 5m18s
implement tile entity add + remove, and make loading more robust.
2024-11-25 22:28:33 +00:00

24 lines
No EOL
882 B
TypeScript

import { IReader } from "bufferstuff";
import TileEntity from "./TileEntity";
import TileEntityChest from "./TileEntityChest";
import TileEntityType from "../enums/TileEntityType";
import Vec3 from "../Vec3";
import UnsupportedError from "../errors/UnsupportedError";
// 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 position = new Vec3(reader.readUByte(), reader.readUByte(), reader.readUByte());
if (type === TileEntityType.Chest) {
tileEntity = new TileEntityChest(position);
} else {
throw new UnsupportedError("Unsupported tile entity type encountered");
}
// Call instantiated class' fromSave
tileEntity.fromSave(reader);
return tileEntity;
}
}