-
-
Notifications
You must be signed in to change notification settings - Fork 110
updated spawning page #1011
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
Open
mosemister
wants to merge
2
commits into
stable
Choose a base branch
from
task/spawning-entity
base: stable
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
updated spawning page #1011
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,54 +2,50 @@ | |
| Spawning an Entity | ||
| ================== | ||
|
|
||
| .. warning:: | ||
| These docs were written for SpongeAPI 7 and are likely out of date. | ||
| `If you feel like you can help update them, please submit a PR! <https://github.com/SpongePowered/SpongeDocs>`__ | ||
|
|
||
| .. javadoc-import:: | ||
| com.flowpowered.math.vector.Vector3d | ||
| org.spongepowered.api.entity.Entity | ||
| org.spongepowered.api.entity.EntityType | ||
| org.spongepowered.api.event.cause.entity.spawn.SpawnType | ||
| org.spongepowered.api.event.cause.entity.spawn.SpawnTypes | ||
| org.spongepowered.api.world.Location | ||
| org.spongepowered.api.world.extent.Extent | ||
| org.spongepowered.api.world.extent.EntityUniverse | ||
| org.spongepowered.api.world.server.ServerLocation | ||
| org.spongepowered.api.world.server.ServerWorld | ||
| org.spongepowered.api.world.volume.entity.EntityVolume.Modifiable | ||
|
|
||
| You will need three things for spawning an :javadoc:`Entity`: a :javadoc:`Location`, an :javadoc:`Extent`, and an | ||
| :javadoc:`EntityType`. The process for getting these is quite simple, you just need to grab a ``Location`` from | ||
| You will need three things for spawning an :javadoc:`Entity`: a **Position** as a ``Vector3d``, an :javadoc:`World`, and an | ||
| :javadoc:`EntityType`. The process for getting these is quite simple, you just need to grab a ``Position`` from | ||
| somewhere in your plugin code and choose the type of ``Entity`` you wish to spawn. | ||
|
|
||
| For example, let's try to spawn a Creeper: | ||
|
|
||
| .. code-block:: java | ||
|
|
||
| import org.spongepowered.api.entity.Entity; | ||
| import org.spongepowered.api.entity.living.monster.Creeper; | ||
| import org.spongepowered.api.entity.EntityTypes; | ||
| import org.spongepowered.api.event.CauseStackManager.StackFrame; | ||
| import org.spongepowered.api.event.cause.entity.spawn.SpawnTypes; | ||
| import org.spongepowered.api.world.Location; | ||
| import org.spongepowered.api.world.World; | ||
| import org.spongepowered.api.world.server.ServerLocation; | ||
| import org.spongepowered.api.world.server.ServerWorld; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| public void spawnEntity(Location<World> spawnLocation) { | ||
| World world = spawnLocation.getExtent(); | ||
| public void spawnEntity(ServerLocation spawnLocation) { | ||
| ServerWorld world = spawnLocation.world(); | ||
|
|
||
| Entity creeper = world.createEntity(EntityTypes.CREEPER, spawnLocation.getPosition()); | ||
| Creaper creeper = world.createEntity(EntityTypes.CREEPER, spawnLocation.getPosition()); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this really meant to be "Creeper" instead of "Creaper"? |
||
|
|
||
| // We need to push a new cause StackFrame to the stack so we can add our own causes | ||
| // In previous versions of the API you had to submit a Cause parameter | ||
| // that would often not contain the real root cause | ||
| // By default the current plugin's PluginContainer is already pushed to the stack. | ||
| try (StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) { | ||
| try (StackFrame frame = Sponge.server().causeStackManager().pushCauseFrame()) { | ||
| frame.addContext(EventContextKeys.SPAWN_TYPE, SpawnTypes.PLUGIN); | ||
| world.spawnEntity(creeper); | ||
| } | ||
| } | ||
|
|
||
| This will grab the world from our ``Location``, which we will need for the actual spawning. Next, it uses | ||
| :javadoc:`EntityUniverse#createEntity(EntityType, Vector3d)` to create the entity, but do note that this does not | ||
| This will grab the world from our ``ServerLocation``, which we will need for the actual spawning. Next, it uses | ||
| :javadoc:`EntityVolume.Modifiable#createEntity(EntityType, Vector3d)` to create the entity, but do note that this does not | ||
| spawn the entity into the world, it just will create it. We will need to specify the type of ``Entity`` to spawn, and | ||
| the co-ordinates from our ``Location``. | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
It should be "a World", not an.