Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //from server tick handler
- World world2 = DimensionManager.getWorld(-64);
- if (!(world2.getWorldInfo() instanceof DerivedWorldInfoOverride)) {
- DerivedWorldInfoOverride wi = new DerivedWorldInfoOverride(world2.getWorldInfo());
- c_CoroAIUtil.setPrivateValueSRGMCP(World.class, world2, "field_72986_A", "worldInfo", wi);
- wi.readFromFile();
- }
- //override class
- package combat.test;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import net.minecraft.nbt.CompressedStreamTools;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.world.storage.DerivedWorldInfo;
- import net.minecraft.world.storage.WorldInfo;
- import CoroAI.util.CoroUtilFile;
- public class DerivedWorldInfoOverride extends DerivedWorldInfo {
- private long totalTime;
- private long worldTime;
- public DerivedWorldInfoOverride(WorldInfo par1WorldInfo) {
- super(par1WorldInfo);
- // TODO Auto-generated constructor stub
- }
- //only injects new data if found custom data
- public void readFromFile() {
- String saveFolder = CoroUtilFile.getWorldSaveFolderPath() + CoroUtilFile.getWorldFolderName() + "epoch" + File.separator;
- try {
- NBTTagCompound data = new NBTTagCompound();
- if ((new File(saveFolder + "EpochMainWorldInfo.dat")).exists()) {
- data = CompressedStreamTools.readCompressed(new FileInputStream(saveFolder + "EpochMainWorldInfo.dat"));
- readFromNBT(data);
- }
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- }
- public void readFromNBT(NBTTagCompound par1NBTTagCompound) {
- totalTime = par1NBTTagCompound.getLong("totalTime");
- worldTime = par1NBTTagCompound.getLong("worldTime");
- }
- public void writeToFile() {
- try {
- String saveFolder = CoroUtilFile.getWorldSaveFolderPath() + CoroUtilFile.getWorldFolderName() + "epoch" + File.separator;
- //Write out to file
- if (!(new File(saveFolder).exists())) (new File(saveFolder)).mkdirs();
- FileOutputStream fos = new FileOutputStream(saveFolder + "EpochMainWorldInfo.dat");
- NBTTagCompound data = new NBTTagCompound();
- updateTagCompound(data);
- CompressedStreamTools.writeCompressed(data, fos);
- fos.close();
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- }
- private void updateTagCompound(NBTTagCompound par1NBTTagCompound/*, NBTTagCompound par2NBTTagCompound*/)
- {
- par1NBTTagCompound.setLong("totalTime", totalTime);
- par1NBTTagCompound.setLong("worldTime", worldTime);
- /*if (par2NBTTagCompound != null)
- {
- par1NBTTagCompound.setCompoundTag("Player", par2NBTTagCompound);
- }*/
- }
- @Override
- public long getWorldTotalTime()
- {
- return this.totalTime;
- }
- @Override
- public void incrementTotalWorldTime(long par1) {
- this.totalTime = par1;
- }
- @Override
- public long getWorldTime()
- {
- //System.out.println("derived time: " + worldTime);
- return this.worldTime;
- }
- @Override
- public void setWorldTime(long par1) {
- worldTime = par1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement