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
Make (most of) the examples executable again #695
Changes from 5 commits
73cfbce
87b6370
d3fda5d
eb6cdd9
5a6dff5
40087e9
face9f3
85d0aee
2b2f3dd
5df4f63
06debb1
7324a39
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,7 +50,10 @@ following code: | |
import java.nio.file.Files; | ||
|
||
if (Files.notExists(configPath)) { | ||
plugin.getAsset("default.conf").copyToFile(configPath); | ||
Optional<Asset> asset = plugin.getAsset("default.conf"); | ||
if (asset.isPresent()) { | ||
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. Can simplify this to plugin.getAsset("default.conf").ifPresent(asset -> asset.copyToDirectory(configPath)); 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. Changed |
||
asset.get().copyToDirectory(configPath); | ||
} | ||
} | ||
|
||
.. note:: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,9 +23,6 @@ For example, let's try to spawn a Creeper: | |
|
||
import org.spongepowered.api.entity.Entity; | ||
import org.spongepowered.api.entity.EntityTypes; | ||
import org.spongepowered.api.event.cause.Cause; | ||
import org.spongepowered.api.event.cause.entity.spawn.SpawnCause; | ||
import org.spongepowered.api.event.cause.entity.spawn.SpawnTypes; | ||
import org.spongepowered.api.world.Location; | ||
import org.spongepowered.api.world.World; | ||
|
||
|
@@ -35,8 +32,7 @@ For example, let's try to spawn a Creeper: | |
World world = spawnLocation.getExtent(); | ||
Entity creeper = world | ||
.createEntity(EntityTypes.CREEPER, spawnLocation.getPosition()); | ||
SpawnCause spawnCause = SpawnCause.builder().type(SpawnTypes.PLUGIN).build(); | ||
world.spawnEntity(creeper, Cause.source(spawnCause).build()); | ||
world.spawnEntity(creeper); | ||
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. Should be pushing to the cause stack frame for a SpawnType. 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. Fixed |
||
} | ||
|
||
This will grab the world from our ``Location``, which we will need for the actual spawning. Next, it uses | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,12 +50,12 @@ include this all before ``return superMegaAwesomeSword;``. | |
|
||
EnchantmentData enchantmentData = superMegaAwesomeSword | ||
.getOrCreate(EnchantmentData.class).get(); | ||
final List<Enchantment> enchantments = Sponge.getRegistry() | ||
.getAllOf(Enchantment.class).stream().collect(Collectors.toList()); | ||
final List<EnchantmentType> enchantments = Sponge.getRegistry() | ||
.getAllOf(EnchantmentType.class).stream().collect(Collectors.toList()); | ||
|
||
for (Enchantment enchantment : enchantments) { | ||
for (EnchantmentType enchantment : enchantments) { | ||
enchantmentData.set(enchantmentData.enchantments() | ||
.add(new ItemEnchantment(enchantment, 1000))); | ||
.add(Enchantment.of(enchantment, 1000))); | ||
} | ||
superMegaAwesomeSword.offer(enchantmentData); | ||
|
||
|
@@ -107,14 +107,9 @@ An example is shown below: | |
|
||
public void spawnItem(ItemStack superMegaAwesomeSword, Location<World> spawnLocation) { | ||
Extent extent = spawnLocation.getExtent(); | ||
Optional<Entity> optional = extent | ||
.createEntity(EntityTypes.ITEM, spawnLocation.getPosition()); | ||
if (optional.isPresent()) { | ||
Entity item = optional.get(); | ||
item.offer(Keys.REPRESENTED_ITEM, superMegaAwesomeSword.createSnapshot()); | ||
extent.spawnEntity(item, Cause.source(EntitySpawnCause.builder() | ||
.entity(item).type(SpawnTypes.PLUGIN).build()).build()); | ||
} | ||
Entity item = extent.createEntity(EntityTypes.ITEM, spawnLocation.getPosition()); | ||
item.offer(Keys.REPRESENTED_ITEM, superMegaAwesomeSword.createSnapshot()); | ||
extent.spawnEntity(item); | ||
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. Likewise here, need to add the 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. Can wrap with: try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushStackFrame()) {
frame.addContext(EventContextKeys.SPAWN_TYPE, SpawnTypes.PLACEMENT);
extent.spawnEntity(item);
} 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. Fixed |
||
} | ||
|
||
Creating an ItemStack From a Block | ||
|
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.
All the key stuff needs to be updated to use the register method like so:
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.
Fixed