Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class WorldEvents {
- @SubscribeEvent
- public void onWorld(WorldEvent.Load e){
- this.genImportantDirectories();
- //gathering world data
- WorldData data=WorldData.forWorld(e.getWorld());
- if(data.isWorldCreated()){
- this.onWorldCreated(e,data);
- data.setWorldCreated(false);
- }
- //make registries
- if(e.getWorld().isRemote)
- WorldRegister.initWorldClient(new RegistryHandler(e.getWorld(),data));
- else
- WorldRegister.initWorldServer(new RegistryHandler(e.getWorld(),data));
- WorldRegister.initWorldCommon(new RegistryHandler(e.getWorld(),data));
- if(data.isNewSave()){
- ScriptWorldInit.onNewSave(e.getWorld());
- data.setNewSave(false);
- }
- ScriptWorldInit.onLoad(e.getWorld());
- data.sendUpdate();
- if(e.getWorld().isRemote)
- Minecraft.getMinecraft().refreshResources();
- }
- private void genImportantDirectories(){
- Path path=new File(Refs.getWorldSavePath()).toPath().resolve("mapres");
- File mapres=path.toFile();
- File npc=path.resolve("npc").toFile();
- File sounds=path.resolve("sounds").toFile();
- File clips=path.resolve("clips").toFile();
- File scripts=path.resolve("scripts").toFile();
- File textures=path.resolve("textures").toFile();
- File items=path.resolve("items").toFile();
- File entity=path.resolve("entity").toFile();
- if(!mapres.exists()){
- boolean generated=mapres.mkdirs();
- if(generated){
- PixelEngine.LOGGER.info("Created the resource directory for the world.");
- if(!npc.exists()){
- boolean npcGen=npc.mkdirs();
- if(npcGen)
- PixelEngine.LOGGER.info("Created npc texture folder in the resources directory.");
- }
- if(!sounds.exists()){
- boolean soundsGen=sounds.mkdirs();
- if(soundsGen)
- PixelEngine.LOGGER.info("Created sounds folder in the resources directory.");
- }
- if(!clips.exists()){
- boolean clipsGen=clips.mkdirs();
- if(clipsGen)
- PixelEngine.LOGGER.info("Created clips folder in the resources directory.");
- }
- if(!scripts.exists()){
- boolean scriptsGen=scripts.mkdirs();
- if(scriptsGen)
- PixelEngine.LOGGER.info("Created scripts folder in the resources directory.");
- }
- if(!textures.exists()){
- boolean texturesGen=textures.mkdirs();
- if(texturesGen)
- PixelEngine.LOGGER.info("Created textures folder in the resources directory.");
- }
- if(!items.exists()){
- boolean itemsGen=items.mkdirs();
- if(itemsGen)
- PixelEngine.LOGGER.info("Created items folder in the resources directory.");
- }
- if(!entity.exists()){
- boolean entityGen=entity.mkdirs();
- if(entityGen)
- PixelEngine.LOGGER.info("Created entity folder in the resources directory.");
- }
- }
- }
- }
- @SubscribeEvent
- public void onTickWorld(TickEvent.WorldTickEvent e){
- ScriptWorldInit.onUpdate(e.world);
- }
- private void onWorldCreated(WorldEvent.Load e, WorldData data){
- data.setWorldID(UUID.randomUUID().toString());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment