Add world unload event (And functional interface annotations to events) (#895)

* Add world unload event

* Add functional interface annotations to all events
This commit is contained in:
i509VCB 2020-07-29 19:54:16 +01:00 committed by modmuss50
parent 33df8bfb70
commit 3d76399a1e
13 changed files with 54 additions and 0 deletions

View file

@ -78,10 +78,12 @@ public final class ClientBlockEntityEvents {
}
});
@FunctionalInterface
public interface Load {
void onLoad(BlockEntity blockEntity, ClientWorld world);
}
@FunctionalInterface
public interface Unload {
void onUnload(BlockEntity blockEntity, ClientWorld world);
}

View file

@ -78,10 +78,12 @@ public final class ClientChunkEvents {
}
});
@FunctionalInterface
public interface Load {
void onChunkLoad(ClientWorld world, WorldChunk chunk);
}
@FunctionalInterface
public interface Unload {
void onChunkUnload(ClientWorld world, WorldChunk chunk);
}

View file

@ -78,10 +78,12 @@ public final class ClientEntityEvents {
}
});
@FunctionalInterface
public interface Load {
void onLoad(Entity entity, ClientWorld world);
}
@FunctionalInterface
public interface Unload {
void onUnload(Entity entity, ClientWorld world);
}

View file

@ -51,10 +51,12 @@ public final class ClientLifecycleEvents {
}
});
@FunctionalInterface
public interface ClientStarted {
void onClientStarted(MinecraftClient client);
}
@FunctionalInterface
public interface ClientStopping {
void onClientStopping(MinecraftClient client);
}

View file

@ -120,18 +120,22 @@ public final class ClientTickEvents {
}
});
@FunctionalInterface
public interface StartTick {
void onStartTick(MinecraftClient client);
}
@FunctionalInterface
public interface EndTick {
void onEndTick(MinecraftClient client);
}
@FunctionalInterface
public interface StartWorldTick {
void onStartTick(ClientWorld world);
}
@FunctionalInterface
public interface EndWorldTick {
void onEndTick(ClientWorld world);
}

View file

@ -75,10 +75,12 @@ public final class ServerBlockEntityEvents {
}
});
@FunctionalInterface
public interface Load {
void onLoad(BlockEntity blockEntity, ServerWorld world);
}
@FunctionalInterface
public interface Unload {
void onUnload(BlockEntity blockEntity, ServerWorld world);
}

View file

@ -75,10 +75,12 @@ public final class ServerChunkEvents {
}
});
@FunctionalInterface
public interface Load {
void onChunkLoad(ServerWorld world, WorldChunk chunk);
}
@FunctionalInterface
public interface Unload {
void onChunkUnload(ServerWorld world, WorldChunk chunk);
}

View file

@ -53,6 +53,7 @@ public final class ServerEntityEvents {
}
});
@FunctionalInterface
public interface Load {
void onLoad(Entity entity, ServerWorld world);
}

View file

@ -96,26 +96,32 @@ public final class ServerLifecycleEvents {
}
});
@FunctionalInterface
public interface ServerStarting {
void onServerStarting(MinecraftServer server);
}
@FunctionalInterface
public interface ServerStarted {
void onServerStarted(MinecraftServer server);
}
@FunctionalInterface
public interface ServerStopping {
void onServerStopping(MinecraftServer server);
}
@FunctionalInterface
public interface ServerStopped {
void onServerStopped(MinecraftServer server);
}
@FunctionalInterface
public interface StartDataPackReload {
void startDataPackReload(MinecraftServer server, ReloadableResourceManager serverResourceManager);
}
@FunctionalInterface
public interface EndDataPackReload {
/**
* Called after data packs on a Minecraft server have been reloaded.

View file

@ -117,18 +117,22 @@ public final class ServerTickEvents {
}
});
@FunctionalInterface
public interface StartTick {
void onStartTick(MinecraftServer server);
}
@FunctionalInterface
public interface EndTick {
void onEndTick(MinecraftServer server);
}
@FunctionalInterface
public interface StartWorldTick {
void onStartTick(ServerWorld world);
}
@FunctionalInterface
public interface EndWorldTick {
void onEndTick(ServerWorld world);
}

View file

@ -35,10 +35,28 @@ public final class ServerWorldEvents {
}
});
/**
* Called before a world is unloaded by a Minecraft server.
*
* <p>This typically occurs after a server has {@link ServerLifecycleEvents#SERVER_STOPPING started shutting down}.
* Mods which allow dynamic world (un)registration should use this event so mods can let go of world handles when a world is removed.
*/
public static final Event<Unload> UNLOAD = EventFactory.createArrayBacked(Unload.class, callbacks -> (server, world) -> {
for (Unload callback : callbacks) {
callback.onWorldUnload(server, world);
}
});
@FunctionalInterface
public interface Load {
void onWorldLoad(MinecraftServer server, ServerWorld world);
}
@FunctionalInterface
public interface Unload {
void onWorldUnload(MinecraftServer server, ServerWorld world);
}
private ServerWorldEvents() {
}
}

View file

@ -99,6 +99,11 @@ public abstract class MinecraftServerMixin {
return result;
}
@Inject(method = "shutdown", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;close()V", shift = At.Shift.AFTER), locals = LocalCapture.CAPTURE_FAILEXCEPTION)
private void onUnloadWorldAtShutdown(CallbackInfo ci, Iterator<ServerWorld> worlds, ServerWorld world) {
ServerWorldEvents.UNLOAD.invoker().onWorldUnload((MinecraftServer) (Object) this, world);
}
@Inject(method = "reloadDataPacks", at = @At("HEAD"))
private void startResourceReload(LevelProperties levelProperties, CallbackInfo cir) {
ServerLifecycleEvents.START_DATA_PACK_RELOAD.invoker().startDataPackReload((MinecraftServer) (Object) this, this.dataManager);

View file

@ -46,5 +46,9 @@ public class ServerLifecycleTests implements ModInitializer {
ServerWorldEvents.LOAD.register((server, world) -> {
LOGGER.info("Loaded world " + world.dimension.getType().toString());
});
ServerWorldEvents.UNLOAD.register((server, world) -> {
LOGGER.info("Unloaded world " + world.dimension.getType().toString());
});
}
}