Guest User

WorldEvents.class

a guest
Sep 30th, 2016
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.95 KB | None | 0 0
  1. public class WorldEvents {
  2.    
  3.     @SubscribeEvent
  4.     public void onWorld(WorldEvent.Load e){
  5.         this.genImportantDirectories();
  6.        
  7.         //gathering world data
  8.         WorldData data=WorldData.forWorld(e.getWorld());
  9.         if(data.isWorldCreated()){
  10.             this.onWorldCreated(e,data);
  11.             data.setWorldCreated(false);
  12.         }
  13.        
  14.         //make registries
  15.         if(e.getWorld().isRemote)
  16.             WorldRegister.initWorldClient(new RegistryHandler(e.getWorld(),data));
  17.         else
  18.             WorldRegister.initWorldServer(new RegistryHandler(e.getWorld(),data));
  19.         WorldRegister.initWorldCommon(new RegistryHandler(e.getWorld(),data));
  20.        
  21.         if(data.isNewSave()){
  22.             ScriptWorldInit.onNewSave(e.getWorld());
  23.             data.setNewSave(false);
  24.         }
  25.        
  26.         ScriptWorldInit.onLoad(e.getWorld());
  27.         data.sendUpdate();
  28.        
  29.         if(e.getWorld().isRemote)
  30.             Minecraft.getMinecraft().refreshResources();
  31.     }
  32.    
  33.     private void genImportantDirectories(){
  34.         Path path=new File(Refs.getWorldSavePath()).toPath().resolve("mapres");
  35.         File mapres=path.toFile();
  36.         File npc=path.resolve("npc").toFile();
  37.         File sounds=path.resolve("sounds").toFile();
  38.         File clips=path.resolve("clips").toFile();
  39.         File scripts=path.resolve("scripts").toFile();
  40.         File textures=path.resolve("textures").toFile();
  41.         File items=path.resolve("items").toFile();
  42.         File entity=path.resolve("entity").toFile();
  43.         if(!mapres.exists()){
  44.             boolean generated=mapres.mkdirs();
  45.             if(generated){
  46.                 PixelEngine.LOGGER.info("Created the resource directory for the world.");
  47.                 if(!npc.exists()){
  48.                     boolean npcGen=npc.mkdirs();
  49.                     if(npcGen)
  50.                         PixelEngine.LOGGER.info("Created npc texture folder in the resources directory."); 
  51.                 }
  52.                 if(!sounds.exists()){
  53.                     boolean soundsGen=sounds.mkdirs();
  54.                     if(soundsGen)
  55.                         PixelEngine.LOGGER.info("Created sounds folder in the resources directory.");  
  56.                 }
  57.                 if(!clips.exists()){
  58.                     boolean clipsGen=clips.mkdirs();
  59.                     if(clipsGen)
  60.                         PixelEngine.LOGGER.info("Created clips folder in the resources directory.");   
  61.                 }
  62.                 if(!scripts.exists()){
  63.                     boolean scriptsGen=scripts.mkdirs();
  64.                     if(scriptsGen)
  65.                         PixelEngine.LOGGER.info("Created scripts folder in the resources directory."); 
  66.                 }
  67.                 if(!textures.exists()){
  68.                     boolean texturesGen=textures.mkdirs();
  69.                     if(texturesGen)
  70.                         PixelEngine.LOGGER.info("Created textures folder in the resources directory.");
  71.                 }
  72.                 if(!items.exists()){
  73.                     boolean itemsGen=items.mkdirs();
  74.                     if(itemsGen)
  75.                         PixelEngine.LOGGER.info("Created items folder in the resources directory.");   
  76.                 }
  77.                 if(!entity.exists()){
  78.                     boolean entityGen=entity.mkdirs();
  79.                     if(entityGen)
  80.                         PixelEngine.LOGGER.info("Created entity folder in the resources directory.");  
  81.                 }
  82.             }
  83.         }
  84.     }
  85.    
  86.     @SubscribeEvent
  87.     public void onTickWorld(TickEvent.WorldTickEvent e){
  88.         ScriptWorldInit.onUpdate(e.world);
  89.     }
  90.    
  91.     private void onWorldCreated(WorldEvent.Load e, WorldData data){
  92.         data.setWorldID(UUID.randomUUID().toString());
  93.     }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment