summary refs log tree commit diff
path: root/src/BlockPhysics.h
diff options
context:
space:
mode:
authorWlodekM <[email protected]>2024-06-16 10:35:45 +0300
committerWlodekM <[email protected]>2024-06-16 10:35:45 +0300
commitabef6da56913f1c55528103e60a50451a39628b1 (patch)
treeb3c8092471ecbb73e568cd0d336efa0e7871ee8d /src/BlockPhysics.h
initial commit
Diffstat (limited to 'src/BlockPhysics.h')
-rw-r--r--src/BlockPhysics.h29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/BlockPhysics.h b/src/BlockPhysics.h
new file mode 100644
index 0000000..9bd8126
--- /dev/null
+++ b/src/BlockPhysics.h
@@ -0,0 +1,29 @@
+#ifndef CC_BLOCKPHYSICS_H
+#define CC_BLOCKPHYSICS_H
+#include "Core.h"
+/* Implements simple block physics.
+   Copyright 2014-2023 ClassiCube | Licensed under BSD-3
+*/
+typedef void (*PhysicsHandler)(int index, BlockID block);
+
+CC_VAR extern struct Physics_ {
+	/* Whether block physics are enabled at all. */
+	cc_bool Enabled;
+	/* Called when block is activated by a neighbouring block change. */
+	/* e.g. trigger sand falling, water flooding */
+	PhysicsHandler OnActivate[256];
+	/* Called when this block is randomly activated. */
+	/* e.g. grass eventually fading to dirt in darkness */
+	PhysicsHandler OnRandomTick[256];
+	/* Called when user manually places a block. */
+	PhysicsHandler OnPlace[256];
+	/* Called when user manually deletes a block. */
+	PhysicsHandler OnDelete[256];
+} Physics;
+
+void Physics_SetEnabled(cc_bool enabled);
+void Physics_OnBlockChanged(int x, int y, int z, BlockID old, BlockID now);
+void Physics_Init(void);
+void Physics_Free(void);
+void Physics_Tick(void);
+#endif