@@ -27,7 +27,7 @@ const UpdateEvent = union(enum) {
2727
2828pub const ErrorSet = BinaryReader .AllErrors || error {Invalid };
2929
30- pub const BlockEntityType = struct {
30+ pub const BlockEntityType = struct { // MARK: BlockEntityType
3131 id : []const u8 ,
3232 vtable : VTable ,
3333
@@ -43,10 +43,10 @@ pub const BlockEntityType = struct {
4343 getServerToClientData : * const fn (pos : Vec3i , chunk : * Chunk , writer : * BinaryWriter ) void ,
4444 getClientToServerData : * const fn (pos : Vec3i , chunk : * Chunk , writer : * BinaryWriter ) void ,
4545 };
46- pub fn init (comptime BlockEntityTypeT : type ) BlockEntityType {
46+ pub fn init (comptime BlockEntityTypeT : type , comptime id : [] const u8 ) BlockEntityType {
4747 BlockEntityTypeT .init ();
4848 var class = BlockEntityType {
49- .id = BlockEntityTypeT . id ,
49+ .id = id ,
5050 .vtable = undefined ,
5151 };
5252
@@ -90,7 +90,7 @@ pub const BlockEntityType = struct {
9090 }
9191};
9292
93- fn BlockEntityDataStorage (T : type ) type {
93+ fn BlockEntityDataStorage (T : type ) type { // MARK: BlockEntityDataStorage
9494 return struct {
9595 pub const DataT = T ;
9696 var freeIndexList : main .ListUnmanaged (BlockEntityIndex ) = .{};
@@ -181,14 +181,13 @@ fn BlockEntityDataStorage(T: type) type {
181181 };
182182}
183183
184- pub const BlockEntityTypes = struct {
185- pub const Chest = struct {
184+ pub const BlockEntityTypes = struct { // MARK: BlockEntityTypes
185+ pub const @ "cubyz:chest" = struct { // MARK: cubyz:chest
186186 pub const inventorySize = 20 ;
187187 const StorageServer = BlockEntityDataStorage (struct {
188188 invId : main.items.Inventory.InventoryId ,
189189 });
190190
191- pub const id = "chest" ;
192191 pub fn init () void {
193192 StorageServer .init ();
194193 }
@@ -249,8 +248,8 @@ pub const BlockEntityTypes = struct {
249248 pub fn updateServerData (pos : Vec3i , chunk : * Chunk , event : UpdateEvent ) ErrorSet ! void {
250249 switch (event ) {
251250 .remove = > {
252- const chest = StorageServer .remove (pos , chunk ) orelse return ;
253- main .items .Inventory .ServerSide .destroyAndDropExternallyManagedInventory (chest .invId , pos );
251+ const chestComponent = StorageServer .remove (pos , chunk ) orelse return ;
252+ main .items .Inventory .ServerSide .destroyAndDropExternallyManagedInventory (chestComponent .invId , pos );
254253 },
255254 .update = > | _ | {
256255 StorageServer .mutex .lock ();
@@ -268,7 +267,7 @@ pub const BlockEntityTypes = struct {
268267 pub fn renderAll (_ : Mat4f , _ : Vec3f , _ : Vec3d ) void {}
269268 };
270269
271- pub const Sign = struct {
270+ pub const @ "cubyz:sign" = struct { // MARK: cubyz:sign
272271 const StorageServer = BlockEntityDataStorage (struct {
273272 text : []const u8 ,
274273 });
@@ -307,7 +306,6 @@ pub const BlockEntityTypes = struct {
307306 const textureHeight = 72 ;
308307 const textureMargin = 4 ;
309308
310- pub const id = "sign" ;
311309 pub fn init () void {
312310 StorageServer .init ();
313311 StorageClient .init ();
@@ -433,7 +431,7 @@ pub const BlockEntityTypes = struct {
433431 const localPos = mesh .chunk .getLocalBlockPos (pos );
434432 const block = mesh .chunk .data .getValue (localPos .toIndex ());
435433 const blockEntity = block .blockEntity () orelse return ;
436- if (! std .mem .eql (u8 , blockEntity .id , id )) return ;
434+ if (! std .mem .eql (u8 , blockEntity .id , "cubyz:sign" )) return ;
437435
438436 StorageClient .mutex .lock ();
439437 defer StorageClient .mutex .unlock ();
@@ -521,7 +519,7 @@ var blockyEntityTypes: std.StringHashMapUnmanaged(BlockEntityType) = .{};
521519
522520pub fn init () void {
523521 inline for (@typeInfo (BlockEntityTypes ).@"struct" .decls ) | declaration | {
524- const class = BlockEntityType .init (@field (BlockEntityTypes , declaration .name ));
522+ const class = BlockEntityType .init (@field (BlockEntityTypes , declaration .name ), declaration . name );
525523 blockyEntityTypes .putNoClobber (main .globalAllocator .allocator , class .id , class ) catch unreachable ;
526524 std .log .debug ("Registered BlockEntityType '{s}'" , .{class .id });
527525 }
0 commit comments