2024-11-25 02:30:27 +00:00
|
|
|
import { IReader } from "bufferstuff";
|
|
|
|
import TileEntity from "./TileEntity";
|
|
|
|
import TileEntityChest from "./TileEntityChest";
|
|
|
|
import TileEntityType from "../enums/TileEntityType";
|
|
|
|
import Vec3 from "../Vec3";
|
2024-11-25 22:28:33 +00:00
|
|
|
import UnsupportedError from "../errors/UnsupportedError";
|
2024-11-25 02:30:27 +00:00
|
|
|
|
|
|
|
// 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) {
|
2024-11-25 22:28:33 +00:00
|
|
|
tileEntity = new TileEntityChest(position);
|
2024-11-25 02:30:27 +00:00
|
|
|
} else {
|
2024-11-25 22:28:33 +00:00
|
|
|
throw new UnsupportedError("Unsupported tile entity type encountered");
|
2024-11-25 02:30:27 +00:00
|
|
|
}
|
|
|
|
// Call instantiated class' fromSave
|
|
|
|
tileEntity.fromSave(reader);
|
|
|
|
|
|
|
|
return tileEntity;
|
|
|
|
}
|
|
|
|
}
|