Files
Opis/mcp/mobius/opis/data/holders/TileEntityStats.java
T
ProfMobius 202255e6c0 Reworked the network system to use one unique packet to send data over to the client (ArrayList formatted data).
All the ArrayList stat data is now extending one base class.
Removed 3 packets, added 1 generic

MISSING 2 FILES FROM A DIRECTORY DERP !
2014-03-18 18:46:21 +01:00

77 lines
2.1 KiB
Java

package mcp.mobius.opis.data.holders;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import mcp.mobius.opis.modOpis;
import net.minecraft.network.packet.Packet;
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
public class TileEntityStats extends StatAbstract implements ISerializable {
private int blockID;
private short blockMeta;
private double cachedMedian = -1.0;
public TileEntityStats(CoordinatesBlock coord, int blockID, short blockMeta){
this.coord = coord;
//this.name = teclass;
this.blockID = blockID;
this.blockMeta = blockMeta;
}
public int getID(){
return this.blockID;
}
public short getMeta(){
return this.blockMeta;
}
public void setBlock(int ID, short meta){
this.blockID = ID;
this.blockMeta = meta;
}
public double getMedian(){
if (this.cachedMedian < 0.0){
int ndata = (int)this.dstat.getN();
if (ndata == 1)
return this.dstat.getElement(0);
if (ndata % 2 == 1)
return this.dstat.getSortedValues()[ndata/2];
if (ndata % 2 == 0)
return (this.dstat.getSortedValues()[ndata/2 - 1] + this.dstat.getSortedValues()[ndata/2]) / 2;
}
return this.cachedMedian;
}
@Override
public void writeToStream(DataOutputStream stream) throws IOException{
this.coord.writeToStream(stream);
//Packet.writeString(this.name, stream);
stream.writeInt(this.blockID);
stream.writeShort(this.blockMeta);
stream.writeDouble(this.getGeometricMean());
}
public static TileEntityStats readFromStream(DataInputStream stream) throws IOException {
CoordinatesBlock coord = CoordinatesBlock.readFromStream(stream);
int blockID = stream.readInt();
short blockMeta = stream.readShort();
//String classname = Packet.readString(stream, 255);
TileEntityStats stat = new TileEntityStats(coord, blockID, blockMeta);
stat.setGeometricMean(stream.readDouble());
return stat;
}
public String toString(){
return String.format("[%d:%d] %s %s", this.blockID, this.blockMeta, this.coord, this.getGeometricMean());
}
}