Compare commits

...

14 Commits
CI ... master

Author SHA1 Message Date
github-actions[bot]
438203ac50 Sync to Pumpkin-MC/pumpkin-plugin-wit@39bf330 2026-09-28 07:47:53 +00:00
github-actions[bot]
f34d020778 Sync to Pumpkin-MC/pumpkin-plugin-wit@4d7a501 2026-09-21 16:20:57 +00:00
github-actions[bot]
cb05bd1a41 Sync to Pumpkin-MC/pumpkin-plugin-wit@2366bb9 2026-09-19 21:43:12 +00:00
Demetrius Kanios
b3ca5acc3c Add ability to use callbacks. 2026-09-04 22:26:58 -07:00
Demetrius Kanios
0b81199965 Reformat 2026-09-04 21:56:56 -07:00
github-actions[bot]
e24055f5b8 Sync to Pumpkin-MC/pumpkin-plugin-wit@1ad73ff 2026-09-04 20:25:18 +00:00
Demetrius Kanios
98243f6889 Relicense under MIT OR Apache-2.0 2026-08-15 11:00:34 -07:00
github-actions[bot]
380d1e8fc1 Sync to Pumpkin-MC/pumpkin-plugin-wit@ab193d1 2026-08-04 19:07:21 +00:00
github-actions[bot]
37495f2e9c Sync to Pumpkin-MC/pumpkin-plugin-wit@ff6acb8 2026-08-04 17:17:58 +00:00
Demetrius Kanios
4e7edc5ef1 Update build instructions 2026-08-03 18:05:47 -07:00
Demetrius Kanios
ab0a6a0a71 Use standard 7 character short hash for artifact names 2026-08-03 18:05:47 -07:00
github-actions[bot]
2428b8a39d Sync to Pumpkin-MC/pumpkin-plugin-wit@3f5bbef 2026-08-04 00:55:45 +00:00
Demetrius Kanios
7ed409b5af Add update-wit workflow 2026-08-03 17:54:46 -07:00
Demetrius Kanios
d4fb356cb7 Add rolling release CI 2026-08-03 17:45:50 -07:00
9 changed files with 547 additions and 139 deletions

View File

@ -1,67 +0,0 @@
name: Main
on:
push:
branches:
- "*"
tags:
- "v*"
workflow_dispatch:
permissions:
contents: write
pull-requests: write
jobs:
main:
name: Build, test, and release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
with:
submodules: true
- name: Set up wasi-sdk
uses: bytecodealliance/setup-wasi-sdk-action@b2de090b44eb70013ee96b393727d473b35e1728
- name: Set up wit-bindgen
uses: bytecodealliance/actions/wit-bindgen/setup@v1
- name: Build
run: make install
- name: Test
run: wasm32-wasip2-clang -o test_plugin.wasm -mexec-model=reactor -Iinstall/include install/lib/libpumpkin-api.a example/main.c
- name: Set ARTIFACT_NAME
id: artifact-name
run: |
if [[ '${{ github.ref }}' = refs/tags/v* ]]; then
tag='${{ github.ref }}'
suffix="-${tag:11}"
else
suffix="-ci"
fi
echo "ARTIFACT_NAME=pumpkin-api$suffix" >> $GITHUB_OUTPUT
- name: Bundle
env:
ARTIFACT_NAME: ${{ steps.artifact-name.outputs.ARTIFACT_NAME }}
run: |
mv install $ARTIFACT_NAME
tar -cvJf $ARTIFACT_NAME.tar.xz $ARTIFACT_NAME
- name: Upload artifacts
uses: actions/upload-artifact@v7
with:
archive: false
path: ${{ format('{0}.tar.xz', steps.artifact-name.outputs.ARTIFACT_NAME) }}
- name: Upload artifacts to release
if: startsWith(github.ref, 'refs/tags/v')
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ github.ref }}
file: ${{ format('{0}.tar.xz', steps.artifact-name.outputs.ARTIFACT_NAME) }}
overwrite: true

75
.github/workflows/main.yml vendored Normal file
View File

@ -0,0 +1,75 @@
name: Main
on:
push:
pull_request:
workflow_dispatch:
workflow_run:
types:
- completed
workflows:
- "Update WIT"
permissions:
contents: write
pull-requests: write
jobs:
main:
name: Build, test, and release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
with:
submodules: true
- name: Set up wasi-sdk
uses: bytecodealliance/setup-wasi-sdk-action@b2de090b44eb70013ee96b393727d473b35e1728
- name: Set up wit-bindgen
uses: bytecodealliance/actions/wit-bindgen/setup@v1
- name: Build
run: make install
- name: Test
run: wasm32-wasip2-clang -o test_plugin.wasm -mexec-model=reactor -Iinstall/include install/lib/libpumpkin-api.a example/main.c
- name: Set GITHUB_RELEASE_TAG & ARTIFACT_ID
run: |
set -eux
if [[ '${{ github.ref }}' = refs/tags/v* ]]; then
tag='${{ github.ref }}'
tag="${tag:10}"
artifactID="${tag:1}"
else
tag=CI
artifactID='${{ github.sha }}'
artifactID="${artifactID:0:7}"
fi
echo "GITHUB_RELEASE_TAG=$tag" >> $GITHUB_ENV
echo "ARTIFACT_ID=$artifactID" >> $GITHUB_ENV
- name: Bundle
run: |
mv install pumpkin-api-c-${ARTIFACT_ID}
tar -cvJf pumpkin-api-c-${ARTIFACT_ID}.tar.xz pumpkin-api-c-${ARTIFACT_ID}
- name: Upload artifacts
uses: actions/upload-artifact@v7
with:
archive: false
path: ${{ format('pumpkin-api-c-{0}.tar.xz', env.ARTIFACT_ID) }}
- name: Upload artifacts to release
if: startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/master'
uses: ncipollo/release-action@v1
with:
tag: ${{ env.GITHUB_RELEASE_TAG }}
artifacts: ${{ format('pumpkin-api-c-{0}.tar.xz', env.ARTIFACT_ID) }}
allowUpdates: true
omitPrereleaseDuringUpdate: true
omitName: true
omitBody: true
omitDraftDuringUpdate: true
removeArtifacts: true

39
.github/workflows/update-wit.yml vendored Normal file
View File

@ -0,0 +1,39 @@
name: Update WIT
on:
workflow_dispatch:
permissions:
contents: write
jobs:
update-wit:
name: Update WIT
runs-on: ubuntu-slim
steps:
- name: Checkout
uses: actions/checkout@v6
with:
submodules: true
- name: Update submodule
id: update_submodule
run: |
set -eux
cd wit
git fetch origin master
git checkout FETCH_HEAD
echo "wit_commit=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Commit
run: |
set -eux
witCommit='${{ steps.update_submodule.outputs.wit_commit }}'
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add wit
git commit -m "Sync to Pumpkin-MC/pumpkin-plugin-wit@${witCommit}"
git push

176
LICENSE-APACHE Normal file
View File

@ -0,0 +1,176 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or exemplary damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS

21
LICENSE-MIT Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2024-2026 Pumpkin Contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -5,13 +5,18 @@ This package provides everything needed to write a Pumpkin server plugin compile
## Quick start ## Quick start
1. Download the latest release of this package. 1. Download the latest release of this package.
You'll want to download the latest version of the bindings from the [CI release](https://github.com/Pumpkin-MC/pumpkin-api-c/releases/tag/CI).
We don't have stable versions as Pumpkin and its API is still pre-release.
```bash ```bash
# Assuming the latest version is 0.1.0-dev1 # Assuming the latest commit is 2428b8a. Skip this if you downloaded manually
curl -OL https://github.com/Pumpkin-MC/pumpkin-api-c/releases/download/v0.1.0-dev1/pumpkin-api-0.1.0-dev1.tar.xz curl -OL https://github.com/Pumpkin-MC/pumpkin-api-c/releases/download/CI/pumpkin-api-c-2428b8a.tar.xz
tar -xJvf pumpkin-api-0.1.0-dev1.tar.xz tar -xJvf pumpkin-api-c-2428b8a.tar.xz
# Move and/or name it somewhere/something predictable # Move and/or name it somewhere/something predictable
mv pumpkin-api-0.1.0-dev1 pumpkin-api mv pumpkin-api-c-2428b8a pumpkin-api
``` ```
2. Create your plugin (`main.c`): 2. Create your plugin (`main.c`):

View File

@ -4,70 +4,144 @@
static pumpkin_plugin_t g_plugin = {0}; static pumpkin_plugin_t g_plugin = {0};
void pumpkin_register_plugin(pumpkin_plugin_t plugin) { void pumpkin_register_plugin(pumpkin_plugin_t plugin) { g_plugin = plugin; }
g_plugin = plugin;
}
// WIT exports // WIT exports
void exports_pumpkin_plugin_metadata_get_metadata(exports_pumpkin_plugin_metadata_plugin_metadata_t *ret) { void exports_pumpkin_plugin_metadata_get_metadata(
if (g_plugin.get_metadata) { exports_pumpkin_plugin_metadata_plugin_metadata_t *ret) {
pumpkin_metadata_t meta = g_plugin.get_metadata(); if (g_plugin.get_metadata) {
plugin_string_dup(&(ret->name), meta.name); pumpkin_metadata_t meta = g_plugin.get_metadata();
plugin_string_dup(&(ret->version), meta.version); plugin_string_dup(&(ret->name), meta.name);
plugin_string_dup(&(ret->version), meta.version);
ret->authors.len = meta.authors_count; ret->authors.len = meta.authors_count;
ret->authors.ptr = (plugin_string_t*)malloc(ret->authors.len * sizeof(plugin_string_t)); ret->authors.ptr =
for (size_t i = 0; i < ret->authors.len; ++i) { (plugin_string_t *)malloc(ret->authors.len * sizeof(plugin_string_t));
plugin_string_dup(&(ret->authors.ptr[i]), meta.authors[i]); for (size_t i = 0; i < ret->authors.len; ++i) {
} plugin_string_dup(&(ret->authors.ptr[i]), meta.authors[i]);
plugin_string_dup(&(ret->description), meta.description);
ret->dependencies.len = meta.dependencies_count;
ret->dependencies.ptr = (plugin_string_t*)malloc(ret->dependencies.len * sizeof(plugin_string_t));
for (size_t i = 0; i < ret->dependencies.len; ++i) {
plugin_string_dup(&(ret->dependencies.ptr[i]), meta.dependencies[i]);
}
ret->permissions.len = meta.permissions_count;
ret->permissions.ptr = (plugin_string_t*)malloc(ret->permissions.len * sizeof(plugin_string_t));
for (size_t i = 0; i < ret->permissions.len; ++i) {
plugin_string_dup(&(ret->permissions.ptr[i]), meta.permissions[i]);
}
} }
}
bool exports_plugin_on_load(plugin_own_context_t context_handle, plugin_string_t *err) { plugin_string_dup(&(ret->description), meta.description);
if (g_plugin.on_load) {
g_plugin.on_load(context_handle); ret->dependencies.len = meta.dependencies_count;
ret->dependencies.ptr = (plugin_string_t *)malloc(ret->dependencies.len *
sizeof(plugin_string_t));
for (size_t i = 0; i < ret->dependencies.len; ++i) {
plugin_string_dup(&(ret->dependencies.ptr[i]), meta.dependencies[i]);
} }
return true;
}
bool exports_plugin_on_unload(plugin_own_context_t context_handle, plugin_string_t *err) { ret->permissions.len = meta.permissions_count;
if (g_plugin.on_unload) { ret->permissions.ptr = (plugin_string_t *)malloc(ret->permissions.len *
g_plugin.on_unload(context_handle); sizeof(plugin_string_t));
for (size_t i = 0; i < ret->permissions.len; ++i) {
plugin_string_dup(&(ret->permissions.ptr[i]), meta.permissions[i]);
} }
return true; }
} }
void exports_plugin_handle_event(uint32_t event_id, plugin_own_server_instance_t server, plugin_event_t *event, plugin_event_t *ret) { bool exports_plugin_on_load(plugin_own_context_t context_handle,
// Basic event pass-through plugin_string_t *err) {
*ret = *event; if (g_plugin.on_load) {
g_plugin.on_load(context_handle);
}
return true;
} }
bool exports_plugin_handle_command(uint32_t command_id, plugin_own_command_sender_t sender, plugin_own_server_instance_t server, plugin_own_consumed_args_t args, int32_t *ret, plugin_command_error_t *err) { bool exports_plugin_on_unload(plugin_own_context_t context_handle,
err->tag = PUMPKIN_PLUGIN_COMMAND_COMMAND_ERROR_COMMAND_FAILED; plugin_string_t *err) {
if (g_plugin.on_unload) {
plugin_string_t str; g_plugin.on_unload(context_handle);
plugin_string_set(&str, "Command not implemented"); }
return true;
pumpkin_plugin_text_own_text_component_t text = pumpkin_plugin_text_static_text_component_text(&str);
err->val.command_failed = text;
return false;
} }
void exports_plugin_handle_task(uint32_t handler_id, plugin_own_server_instance_t server) { void exports_plugin_handle_event(uint32_t event_id,
plugin_own_server_instance_t server,
plugin_event_t *event, plugin_event_t *ret) {
*ret = *event;
pumpkin_event_handler_t handler =
(pumpkin_event_handler_t)(uintptr_t)event_id;
handler(server, ret);
}
bool exports_plugin_handle_command(uint32_t command_id,
plugin_own_command_sender_t sender,
plugin_own_server_instance_t server,
plugin_own_consumed_args_t args,
int32_t *ret, plugin_command_error_t *err) {
pumpkin_command_handler_t handler =
(pumpkin_command_handler_t)(uintptr_t)command_id;
return handler(sender, server, args, ret, err);
}
void exports_plugin_handle_command_suggestion(
uint32_t handler_id, plugin_own_command_sender_t sender,
plugin_own_server_instance_t server, plugin_suggestion_request_t *request,
plugin_command_suggestions_t *ret) {
pumpkin_command_suggestion_handler_t handler =
(pumpkin_command_suggestion_handler_t)(uintptr_t)handler_id;
handler(sender, server, request, ret);
}
void exports_plugin_handle_task(uint32_t handler_id,
plugin_own_server_instance_t server) {
pumpkin_task_handler_t handler =
(pumpkin_task_handler_t)(uintptr_t)handler_id;
handler(server);
}
bool exports_plugin_handle_ipc_message(plugin_plugin_id_t *sender,
plugin_ipc_message_t *message,
plugin_ipc_message_t *ret,
plugin_string_t *err) {
if (g_plugin.handle_ipc_message) {
return g_plugin.handle_ipc_message(sender, message, ret, err);
}
plugin_string_dup(err, "This plugin cannot recieve messages");
return false;
}
bool exports_plugin_handle_ai_goal_can_start(
uint32_t goal_id, plugin_own_server_instance_t server,
plugin_own_entity_t entity) {
pumpkin_ai_goal_t *goal = (pumpkin_ai_goal_t *)(uintptr_t)goal_id;
return goal->can_start(server, entity);
}
bool exports_plugin_handle_ai_goal_should_continue(
uint32_t goal_id, plugin_own_server_instance_t server,
plugin_own_entity_t entity) {
pumpkin_ai_goal_t *goal = (pumpkin_ai_goal_t *)(uintptr_t)goal_id;
return goal->should_continue(server, entity);
}
void exports_plugin_handle_ai_goal_start(uint32_t goal_id,
plugin_own_server_instance_t server,
plugin_own_entity_t entity) {
pumpkin_ai_goal_t *goal = (pumpkin_ai_goal_t *)(uintptr_t)goal_id;
goal->start(server, entity);
}
void exports_plugin_handle_ai_goal_tick(uint32_t goal_id,
plugin_own_server_instance_t server,
plugin_own_entity_t entity) {
pumpkin_ai_goal_t *goal = (pumpkin_ai_goal_t *)(uintptr_t)goal_id;
goal->tick(server, entity);
}
void exports_plugin_handle_ai_goal_stop(uint32_t goal_id,
plugin_own_server_instance_t server,
plugin_own_entity_t entity) {
pumpkin_ai_goal_t *goal = (pumpkin_ai_goal_t *)(uintptr_t)goal_id;
goal->stop(server, entity);
}
void exports_plugin_handle_generate_phase(uint32_t generator_id,
plugin_generation_phase_t phase,
plugin_own_chunk_buffer_t chunk) {
pumpkin_chunk_generator_t handler =
(pumpkin_chunk_generator_t)(uintptr_t)generator_id;
handler(phase, chunk);
} }

View File

@ -8,37 +8,122 @@ extern "C" {
#endif #endif
typedef struct { typedef struct {
const char* name; const char *name;
const char* version; const char *version;
const char** authors; const char **authors;
size_t authors_count; size_t authors_count;
const char* description; const char *description;
const char** dependencies; const char **dependencies;
size_t dependencies_count; size_t dependencies_count;
const char** permissions; const char **permissions;
size_t permissions_count; size_t permissions_count;
} pumpkin_metadata_t; } pumpkin_metadata_t;
typedef void (*pumpkin_on_load_t)(plugin_own_context_t ctx); typedef void (*pumpkin_on_load_t)(plugin_own_context_t ctx);
typedef void (*pumpkin_on_unload_t)(plugin_own_context_t ctx); typedef void (*pumpkin_on_unload_t)(plugin_own_context_t ctx);
typedef bool (*pumpkin_ipc_message_handler_t)(plugin_plugin_id_t *sender,
plugin_ipc_message_t *message,
plugin_ipc_message_t *ret,
plugin_string_t *err);
typedef pumpkin_metadata_t (*pumpkin_get_metadata_t)(void); typedef pumpkin_metadata_t (*pumpkin_get_metadata_t)(void);
typedef void (*pumpkin_event_handler_t)(plugin_own_server_instance_t server,
plugin_event_t *event);
typedef bool (*pumpkin_command_handler_t)(plugin_own_command_sender_t sender,
plugin_own_server_instance_t server,
plugin_own_consumed_args_t args,
int32_t *ret,
plugin_command_error_t *err);
typedef void (*pumpkin_command_suggestion_handler_t)(
plugin_own_command_sender_t sender, plugin_own_server_instance_t server,
plugin_suggestion_request_t *request, plugin_command_suggestions_t *ret);
typedef void (*pumpkin_task_handler_t)(plugin_own_server_instance_t server);
typedef void (*pumpkin_chunk_generator_t)(plugin_generation_phase_t phase,
plugin_own_chunk_buffer_t chunk);
typedef bool (*pumpkin_ai_goal_predicate_t)(plugin_own_server_instance_t server,
plugin_own_entity_t entity);
typedef void (*pumpkin_ai_goal_action_t)(plugin_own_server_instance_t server,
plugin_own_entity_t entity);
typedef struct { typedef struct {
pumpkin_get_metadata_t get_metadata; pumpkin_ai_goal_predicate_t can_start;
pumpkin_on_load_t on_load; pumpkin_ai_goal_predicate_t should_continue;
pumpkin_on_unload_t on_unload; pumpkin_ai_goal_action_t start;
pumpkin_ai_goal_action_t tick;
pumpkin_ai_goal_action_t stop;
} pumpkin_ai_goal_t;
typedef struct {
pumpkin_get_metadata_t get_metadata;
pumpkin_on_load_t on_load;
pumpkin_on_unload_t on_unload;
pumpkin_ipc_message_handler_t handle_ipc_message;
} pumpkin_plugin_t; } pumpkin_plugin_t;
void pumpkin_register_plugin(pumpkin_plugin_t plugin); void pumpkin_register_plugin(pumpkin_plugin_t plugin);
#define REGISTER_PUMPKIN_PLUGIN(plugin) \ #define REGISTER_PUMPKIN_PLUGIN(plugin) \
void exports_plugin_init_plugin(void) { \ void exports_plugin_init_plugin(void) { pumpkin_register_plugin(plugin); }
pumpkin_register_plugin(plugin); \
} static inline void pumpkin_context_register_event(
pumpkin_plugin_context_borrow_context_t self,
pumpkin_event_handler_t handler,
pumpkin_plugin_context_event_type_t event_type,
pumpkin_plugin_context_event_priority_t event_priority, bool blocking) {
pumpkin_plugin_context_method_context_register_event(
self, (uint32_t)(uintptr_t)handler, event_type, event_priority, blocking);
}
static inline uint32_t
pumpkin_scheduler_schedule_delayed_task(pumpkin_task_handler_t handler,
uint64_t delay_ticks) {
return pumpkin_plugin_scheduler_schedule_delayed_task(
(uint32_t)(uintptr_t)handler, delay_ticks);
}
static inline uint32_t
pumpkin_scheduler_schedule_repeating_task(pumpkin_task_handler_t handler,
uint64_t delay_ticks,
uint64_t period_ticks) {
return pumpkin_plugin_scheduler_schedule_repeating_task(
(uint32_t)(uintptr_t)handler, delay_ticks, period_ticks);
}
static inline void pumpkin_scheduler_cancel_task(uint32_t task_id) {
pumpkin_plugin_scheduler_cancel_task(task_id);
}
static inline void pumpkin_command_node_execute_with_handler(
pumpkin_plugin_command_borrow_command_node_t self,
pumpkin_command_handler_t handler) {
pumpkin_plugin_command_method_command_node_execute_with_handler_id(
self, (uint32_t)(uintptr_t)handler);
}
static inline void pumpkin_command_node_suggest_with_handler(
pumpkin_plugin_command_borrow_command_node_t self,
pumpkin_command_suggestion_handler_t handler) {
pumpkin_plugin_command_method_command_node_suggest_with_handler_id(
self, (uint32_t)(uintptr_t)handler);
}
static inline void
pumpkin_world_set_chunk_generator(pumpkin_plugin_world_borrow_world_t self,
pumpkin_chunk_generator_t handler) {
pumpkin_plugin_world_method_world_set_chunk_generator(
self, (uint32_t)(uintptr_t)handler);
}
static inline void
pumpkin_mob_add_custom_ai_goal(pumpkin_plugin_world_borrow_mob_t self,
uint8_t priority, pumpkin_ai_goal_t *goal) {
pumpkin_plugin_world_method_mob_add_custom_ai_goal(self, priority,
(uint32_t)(uintptr_t)goal);
}
#ifdef __cplusplus #ifdef __cplusplus
} }

2
wit

@ -1 +1 @@
Subproject commit 2aacac1f07848b6273b30a0390818e87ef1259e9 Subproject commit 39bf330fa6aefc91c8ac61bd07d0fdbd5a5b95ac