Advertisement
Corosus

independant time for custom dimension

Jan 6th, 2014
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.05 KB | None | 0 0
  1. //from server tick handler
  2. World world2 = DimensionManager.getWorld(-64);
  3. if (!(world2.getWorldInfo() instanceof DerivedWorldInfoOverride)) {
  4.     DerivedWorldInfoOverride wi = new DerivedWorldInfoOverride(world2.getWorldInfo());
  5.     c_CoroAIUtil.setPrivateValueSRGMCP(World.class, world2, "field_72986_A", "worldInfo", wi);
  6.     wi.readFromFile();
  7. }
  8.  
  9. //override class
  10.  
  11. package combat.test;
  12.  
  13. import java.io.File;
  14. import java.io.FileInputStream;
  15. import java.io.FileOutputStream;
  16.  
  17. import net.minecraft.nbt.CompressedStreamTools;
  18. import net.minecraft.nbt.NBTTagCompound;
  19. import net.minecraft.world.storage.DerivedWorldInfo;
  20. import net.minecraft.world.storage.WorldInfo;
  21. import CoroAI.util.CoroUtilFile;
  22.  
  23. public class DerivedWorldInfoOverride extends DerivedWorldInfo {
  24.  
  25.     private long totalTime;
  26.     private long worldTime;
  27.    
  28.     public DerivedWorldInfoOverride(WorldInfo par1WorldInfo) {
  29.         super(par1WorldInfo);
  30.         // TODO Auto-generated constructor stub
  31.     }
  32.    
  33.     //only injects new data if found custom data
  34.     public void readFromFile() {
  35.         String saveFolder = CoroUtilFile.getWorldSaveFolderPath() + CoroUtilFile.getWorldFolderName() + "epoch" + File.separator;
  36.        
  37.         try {
  38.             NBTTagCompound data = new NBTTagCompound();
  39.            
  40.             if ((new File(saveFolder + "EpochMainWorldInfo.dat")).exists()) {
  41.                 data = CompressedStreamTools.readCompressed(new FileInputStream(saveFolder + "EpochMainWorldInfo.dat"));
  42.                
  43.                 readFromNBT(data);
  44.             }
  45.            
  46.         } catch (Exception ex) {
  47.             ex.printStackTrace();
  48.         }
  49.     }
  50.    
  51.     public void readFromNBT(NBTTagCompound par1NBTTagCompound) {
  52.         totalTime = par1NBTTagCompound.getLong("totalTime");
  53.         worldTime = par1NBTTagCompound.getLong("worldTime");
  54.     }
  55.    
  56.     public void writeToFile() {
  57.         try {
  58.            
  59.             String saveFolder = CoroUtilFile.getWorldSaveFolderPath() + CoroUtilFile.getWorldFolderName() + "epoch" + File.separator;
  60.            
  61.             //Write out to file
  62.             if (!(new File(saveFolder).exists())) (new File(saveFolder)).mkdirs();
  63.             FileOutputStream fos = new FileOutputStream(saveFolder + "EpochMainWorldInfo.dat");
  64.             NBTTagCompound data = new NBTTagCompound();
  65.             updateTagCompound(data);
  66.             CompressedStreamTools.writeCompressed(data, fos);
  67.             fos.close();
  68.            
  69.         } catch (Exception ex) {
  70.             ex.printStackTrace();
  71.         }
  72.     }
  73.    
  74.     private void updateTagCompound(NBTTagCompound par1NBTTagCompound/*, NBTTagCompound par2NBTTagCompound*/)
  75.     {
  76.         par1NBTTagCompound.setLong("totalTime", totalTime);
  77.         par1NBTTagCompound.setLong("worldTime", worldTime);
  78.        
  79.         /*if (par2NBTTagCompound != null)
  80.         {
  81.             par1NBTTagCompound.setCompoundTag("Player", par2NBTTagCompound);
  82.         }*/
  83.     }
  84.    
  85.     @Override
  86.     public long getWorldTotalTime()
  87.     {
  88.         return this.totalTime;
  89.     }
  90.    
  91.     @Override
  92.     public void incrementTotalWorldTime(long par1) {
  93.         this.totalTime = par1;
  94.     }
  95.  
  96.     @Override
  97.     public long getWorldTime()
  98.     {
  99.         //System.out.println("derived time: " + worldTime);
  100.         return this.worldTime;
  101.     }
  102.    
  103.     @Override
  104.     public void setWorldTime(long par1) {
  105.         worldTime = par1;
  106.     }
  107.  
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement