WorldEvents.java 964 B

12345678910111213141516171819202122232425
  1. package me.km.world;
  2. import me.km.utils.ReflectionUtils;
  3. import me.km.utils.Utils;
  4. import net.minecraft.world.server.ServerWorld;
  5. import net.minecraft.world.storage.DerivedWorldInfo;
  6. import net.minecraftforge.event.world.WorldEvent;
  7. import net.minecraftforge.eventbus.api.EventPriority;
  8. import net.minecraftforge.eventbus.api.SubscribeEvent;
  9. public class WorldEvents {
  10. @SubscribeEvent(priority = EventPriority.HIGHEST)
  11. public void onWorldLoad(WorldEvent.Load e) {
  12. if(!(e.getWorld() instanceof ServerWorld)) {
  13. return;
  14. }
  15. ServerWorld w = (ServerWorld) e.getWorld();
  16. if(w.getLevelData() instanceof DerivedWorldInfo) {
  17. DerivedWorldInfo info = (DerivedWorldInfo) w.getLevelData();
  18. ReflectionUtils.setWorldInfo(w, new ModWorldInfo(info));
  19. System.out.println(String.format("updated world info of %s to mod world info",
  20. Utils.getWorldName(w)));
  21. }
  22. }
  23. }