mirror of
https://github.com/GTNewHorizons/Opis.git
synced 2026-11-22 21:20:04 +00:00
74 lines
1.8 KiB
Java
74 lines
1.8 KiB
Java
package mcp.mobius.opis.data.holders.stats;
|
|
|
|
import java.io.DataInputStream;
|
|
import java.io.DataOutputStream;
|
|
import java.io.IOException;
|
|
|
|
import mcp.mobius.opis.data.holders.basetypes.CoordinatesChunk;
|
|
|
|
public class StatsChunk extends StatAbstract{
|
|
public int tileEntities = 0;
|
|
public int entities = 0;
|
|
|
|
public StatsChunk(){}
|
|
|
|
public StatsChunk(CoordinatesChunk chunk){
|
|
this.chunk = chunk;
|
|
}
|
|
|
|
public StatsChunk(CoordinatesChunk chunk, int tileEntities, int entities){
|
|
this.chunk = chunk;
|
|
this.tileEntities = tileEntities;
|
|
this.entities = entities;
|
|
}
|
|
|
|
public StatsChunk(CoordinatesChunk chunk, int tileEntities, int entities, double time){
|
|
this.chunk = chunk;
|
|
this.tileEntities = tileEntities;
|
|
this.entities = entities;
|
|
this.setDataSum(time);
|
|
}
|
|
|
|
public void addTileEntity(){
|
|
this.tileEntities += 1;
|
|
}
|
|
|
|
public void addEntity(){
|
|
this.entities += 1;
|
|
}
|
|
|
|
@Override
|
|
public CoordinatesChunk getChunk(){
|
|
return this.chunk;
|
|
}
|
|
|
|
@Override
|
|
public void writeToStream(DataOutputStream stream) throws IOException{
|
|
this.chunk.writeToStream(stream);
|
|
stream.writeInt(this.tileEntities);
|
|
stream.writeInt(this.entities);
|
|
stream.writeDouble(this.getDataSum());
|
|
}
|
|
|
|
public static StatsChunk readFromStream(DataInputStream stream) throws IOException {
|
|
CoordinatesChunk chunk = CoordinatesChunk.readFromStream(stream);
|
|
StatsChunk chunkStats = new StatsChunk(chunk, stream.readInt(), stream.readInt());
|
|
chunkStats.setDataSum(stream.readDouble());
|
|
return chunkStats;
|
|
}
|
|
|
|
@Override
|
|
public int compareTo(Object o) {
|
|
double value = ((StatAbstract)o).getDataSum() - this.getDataSum();
|
|
if (value > 0)
|
|
return 1;
|
|
if (value < 0)
|
|
return -1;
|
|
return 0;
|
|
}
|
|
|
|
public String toString(){
|
|
return String.format("%s %s %s", this.chunk, this.getDataSum() / 1000, this.tileEntities);
|
|
}
|
|
}
|