use of org.spongepowered.api.event.world.LoadWorldEvent in project SpongeForge by SpongePowered.
the class SpongeForgeEventFactory method callWorldLoadEvent.
private static LoadWorldEvent callWorldLoadEvent(Event event) {
LoadWorldEvent spongeEvent = (LoadWorldEvent) event;
// Since Forge only uses a single save handler, we need to make sure to pass the overworld's handler.
// This makes sure that mods dont attempt to save/read their data from the wrong location.
final net.minecraft.world.World minecraftWorld = (net.minecraft.world.World) spongeEvent.getTargetWorld();
((IMixinWorld) spongeEvent.getTargetWorld()).setCallingWorldEvent(true);
((IMixinChunkProviderServer) minecraftWorld.getChunkProvider()).setForceChunkRequests(true);
((IMixinEventBus) MinecraftForge.EVENT_BUS).post(new WorldEvent.Load(minecraftWorld), true);
((IMixinChunkProviderServer) minecraftWorld.getChunkProvider()).setForceChunkRequests(false);
((IMixinWorld) minecraftWorld).setCallingWorldEvent(false);
return spongeEvent;
}
use of org.spongepowered.api.event.world.LoadWorldEvent in project LanternServer by LanternPowered.
the class LanternWorldManager method loadWorld.
/**
* Loads a {@link World} for the world entry if possible.
*
* @param worldEntry the world entry
* @return the world, if found
*/
private Optional<World> loadWorld(@Nullable WorldLookupEntry worldEntry) {
if (worldEntry == null) {
return Optional.empty();
}
if (worldEntry.world != null) {
return Optional.of(worldEntry.world);
}
WorldConfigResult result;
try {
result = getOrCreateWorldConfig(worldEntry.properties.getWorldName());
} catch (IOException e) {
this.game.getLogger().error("Unable to read the world config, please fix this issue before loading the world.", e);
return Optional.empty();
}
Scoreboard scoreboard;
try {
scoreboard = ScoreboardIO.read(worldEntry.folder);
} catch (IOException e) {
this.logger.error("Unable to read the scoreboard data.", e);
scoreboard = Scoreboard.builder().build();
}
// Create the world instance
final LanternWorld world = new LanternWorld(this.game, result.config, worldEntry.folder, scoreboard, worldEntry.properties);
// Share the world instance
worldEntry.world = world;
worldEntry.properties.setWorld(world);
// Initialize the world if not done before
world.initialize();
// Generate the spawn if needed
if (worldEntry.properties.doesKeepSpawnLoaded()) {
world.enableSpawnArea(true);
}
// Load the chunk loading tickets, they may load some chunks
try {
world.getChunkManager().loadTickets();
} catch (IOException e) {
this.logger.warn("An error occurred while loading the chunk loading tickets", e);
}
final CauseStack causeStack = CauseStack.currentOrEmpty();
causeStack.pushCause(world);
final LoadWorldEvent event = SpongeEventFactory.createLoadWorldEvent(causeStack.getCurrentCause(), world);
causeStack.popCause();
Sponge.getEventManager().post(event);
if (event.isCancelled()) {
return Optional.empty();
}
// The world is ready for ticks
addWorldTask(world);
return Optional.of(world);
}
Aggregations