This commit is contained in:
Jesse Boyd 2019-04-23 23:41:12 +10:00
parent a523ef8176
commit aaa39d1d32
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
2 changed files with 18 additions and 18 deletions

View File

@ -79,16 +79,12 @@ public class Rollback extends FaweCommand {
long seconds = (System.currentTimeMillis() - edit.getBDFile().lastModified()) / 1000;
total += edit.getBDFile().length();
int size = summary.getSize();
Map<Integer, Double> percents = summary.getPercents();
Map<BlockState, Double> percents = summary.getPercents();
StringBuilder percentString = new StringBuilder();
String prefix = "";
for (Map.Entry<Integer, Double> entry : percents.entrySet()) {
int id = entry.getKey();
BlockStateHolder state = null;
try {
state = BlockState.getFromInternalId(id);
} catch (Throwable ignore) {};
String itemName = state == null ? "#" + id : state.getAsString();
for (Map.Entry<BlockState, Double> entry : percents.entrySet()) {
BlockState state = entry.getKey();
String itemName = "#" + state;
percentString.append(prefix).append(entry.getValue()).append("% ").append(itemName);
prefix = ", ";
}

View File

@ -11,6 +11,8 @@ import com.sk89q.jnbt.NBTOutputStream;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypes;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import java.io.DataOutput;
import java.io.File;
@ -18,6 +20,7 @@ import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
@ -455,7 +458,7 @@ public class DiskStorageHistory extends FaweStreamChangeSet {
public int maxZ;
public DiskStorageSummary(int x, int z) {
blocks = new int[256];
blocks = new int[BlockTypes.states.length];
this.x = x;
this.z = z;
minX = x;
@ -465,7 +468,7 @@ public class DiskStorageHistory extends FaweStreamChangeSet {
}
public void add(int x, int z, int id) {
blocks[id]++;
blocks[BlockState.getFromInternalId(id).getOrdinal()]++;
if (x < minX) {
minX = x;
} else if (x > maxX) {
@ -478,22 +481,23 @@ public class DiskStorageHistory extends FaweStreamChangeSet {
}
}
public Map<Integer, Integer> getBlocks() {
Int2ObjectOpenHashMap<Integer> map = new Int2ObjectOpenHashMap<>();
public Map<BlockState, Integer> getBlocks() {
HashMap<BlockState, Integer> map = new HashMap<>();
for (int i = 0; i < blocks.length; i++) {
if (blocks[i] != 0) {
map.put(i, (Integer) blocks[i]);
BlockState state = BlockTypes.states[i];
map.put(state, (Integer) blocks[i]);
}
}
return map;
}
public Map<Integer, Double> getPercents() {
Map<Integer, Integer> map = getBlocks();
public Map<BlockState, Double> getPercents() {
Map<BlockState, Integer> map = getBlocks();
int count = getSize();
Int2ObjectOpenHashMap<Double> newMap = new Int2ObjectOpenHashMap<>();
for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
int id = entry.getKey();
Map<BlockState, Double> newMap = new HashMap<>();
for (Map.Entry<BlockState, Integer> entry : map.entrySet()) {
BlockState id = entry.getKey();
int changes = entry.getValue();
double percent = ((changes * 1000l) / count) / 10d;
newMap.put(id, (Double) percent);