-
-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Plugin Development Tutorial / API Docs #5
base: master
Are you sure you want to change the base?
Conversation
pub struct MyPlugin {} | ||
|
||
impl MyPlugin { | ||
pub fn new() -> Self { | ||
MyPlugin {} | ||
} | ||
} | ||
|
||
impl Default for MyPlugin { | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub struct MyPlugin;
will be enough, no need for the other implementations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mhh i get an error when having non default, is there a way to prevent that ?
rustc: no function or associated item named `new` found for struct `MyPlugin` in the current scope
items from traits can only be used if the trait is implemented and in scope
the following traits define an item `new`, perhaps you need to implement one of them:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The #[plugin_impl]
proc macro uses the new() on the struct to construct it so that you can have your own fields in it
pub struct MyPlugin {} | ||
|
||
impl MyPlugin { | ||
pub fn new() -> Self { | ||
MyPlugin {} | ||
} | ||
} | ||
|
||
impl Default for MyPlugin { | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here aswell
Before we can get started, we need to have a folder to house our plugin's source code. Either create one using the file explorer, or from the command line using: | ||
```bash | ||
mkdir hello-pumpkin && cd hello-pumpkin | ||
``` | ||
|
||
Next we need to initialize our crate, do so by running this command in the folder you created: | ||
```bash | ||
cargo init --lib | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would simpler to replace this with cargo new <name> --lib
.
This PR aims to add docs and a development tutorial for the Pumpkin plugin system from Pumpkin-MC/Pumpkin#339
TODO