-
-
Save wesserboy/ac072ba4a046ee0379f7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package chunkedPVP.worldData; | |
import java.util.ArrayList; | |
import net.minecraft.nbt.NBTTagCompound; | |
import net.minecraft.nbt.NBTTagList; | |
import net.minecraft.world.World; | |
import net.minecraft.world.WorldSavedData; | |
import net.minecraft.world.chunk.Chunk; | |
import net.minecraft.world.storage.MapStorage; | |
import net.minecraftforge.common.util.Constants; | |
public class ChunkedPVPWorldData extends WorldSavedData{ | |
ArrayList<Chunk> pvpChunks = new ArrayList<Chunk>(); | |
static String key = "ChunkedPVP"; | |
World world; | |
public NBTTagCompound compound; | |
public ChunkedPVPWorldData(String key) { | |
super(key); | |
} | |
public static ChunkedPVPWorldData forWorld(World world) { | |
MapStorage storage = world.perWorldStorage; | |
ChunkedPVPWorldData result = (ChunkedPVPWorldData)storage.loadData(ChunkedPVPWorldData.class, key); | |
if (result == null) { | |
result = new ChunkedPVPWorldData(key); | |
result.setWorld(world); | |
storage.setData(key, result); | |
} | |
result.setWorld(world); | |
return result; | |
} | |
@Override | |
public void readFromNBT(NBTTagCompound compound) { | |
this.compound = compound; | |
if(this.world != null){ | |
NBTTagList chunks = compound.getTagList("ChunkList", Constants.NBT.TAG_COMPOUND); | |
for(int i = 0; i < chunks.tagCount(); i++){ | |
NBTTagCompound chunk = (NBTTagCompound)chunks.getCompoundTagAt(i); | |
if(!pvpChunks.contains(world.getChunkFromChunkCoords(chunk.getInteger("ChunkPosX"), chunk.getInteger("ChunkPosZ")))){ | |
pvpChunks.add(world.getChunkFromChunkCoords(chunk.getInteger("ChunkPosX"), chunk.getInteger("ChunkPosZ"))); | |
} | |
} | |
} | |
} | |
@Override | |
public void writeToNBT(NBTTagCompound compound) { | |
NBTTagList chunks = new NBTTagList(); | |
for(int i = 0; i < pvpChunks.size(); i++){ | |
Chunk chunk = pvpChunks.get(i); | |
NBTTagCompound chunkCompound = new NBTTagCompound(); | |
chunkCompound.setInteger("ChunkPosX", chunk.xPosition); | |
chunkCompound.setInteger("ChunkPosZ", chunk.zPosition); | |
chunks.appendTag(chunkCompound); | |
} | |
compound.setTag("ChunkList", chunks); | |
} | |
public void setWorld(World world){ | |
this.world = world; | |
} | |
public boolean hasChunk(Chunk chunk){ | |
return pvpChunks.contains(chunk); | |
} | |
public void addChunk(Chunk chunk){ | |
pvpChunks.add(chunk); | |
} | |
public void removeChunk(Chunk chunk){ | |
pvpChunks.remove(chunk); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment