From d0c16ba8db1f08cd3c46de7c6cdca76b20095b5c Mon Sep 17 00:00:00 2001 From: Holly Date: Fri, 22 Nov 2024 23:51:27 +0000 Subject: [PATCH] minor tile entity progress --- server/enums/TileEntityType.ts | 1 + server/tileentities/TileEntity.ts | 20 ++++++++++++++++++++ server/tileentities/TileEntityChest.ts | 10 ++++++++++ 3 files changed, 31 insertions(+) create mode 100644 server/tileentities/TileEntityChest.ts diff --git a/server/enums/TileEntityType.ts b/server/enums/TileEntityType.ts index 7f0e523..63b7484 100644 --- a/server/enums/TileEntityType.ts +++ b/server/enums/TileEntityType.ts @@ -1,4 +1,5 @@ enum TileEntityType { + Unknown, Chest } diff --git a/server/tileentities/TileEntity.ts b/server/tileentities/TileEntity.ts index d43f67b..b6a453c 100644 --- a/server/tileentities/TileEntity.ts +++ b/server/tileentities/TileEntity.ts @@ -1,6 +1,8 @@ +import { IReader, IWriter } from "bufferstuff"; import Block from "../blocks/Block"; import TileEntityType from "../enums/TileEntityType"; import Vec3 from "../Vec3"; +import TileEntityChest from "./TileEntityChest"; export default class TileEntity { private readonly type: TileEntityType; @@ -12,4 +14,22 @@ export default class TileEntity { this.forBlockId = forBlockId; this.position = position; } + + public 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); + } + + return tileEntity; + } + + public toSave(writer:IWriter) { + + } } \ No newline at end of file diff --git a/server/tileentities/TileEntityChest.ts b/server/tileentities/TileEntityChest.ts new file mode 100644 index 0000000..6ca813a --- /dev/null +++ b/server/tileentities/TileEntityChest.ts @@ -0,0 +1,10 @@ +import Block from "../blocks/Block"; +import TileEntityType from "../enums/TileEntityType"; +import TileEntity from "./TileEntity"; +import Vec3 from "../Vec3"; + +export default class TileEntityChest extends TileEntity { + public constructor(type: TileEntityType, forBlockId: Block, position: Vec3) { + super(type, forBlockId, position); + } +} \ No newline at end of file