all hsitory types can summarize

This commit is contained in:
Jesse Boyd 2020-01-06 09:06:38 +00:00
parent 195c4a7647
commit 9623c5cb3f
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
4 changed files with 34 additions and 13 deletions

View File

@ -399,6 +399,7 @@ public class DiskStorageHistory extends FaweStreamChangeSet {
return new SimpleChangeSetSummary(getOriginX(), getOriginZ());
}
@Override
public SimpleChangeSetSummary summarize(Region region, boolean shallow) {
if (bdFile.exists()) {
int ox = getOriginX();

View File

@ -1,3 +1,5 @@
package com.boydti.fawe.object.changeset;
import com.sk89q.worldedit.history.changeset.ChangeSetSummary;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypesCache;
@ -14,6 +16,14 @@ public class SimpleChangeSetSummary implements ChangeSetSummary {
public int maxX;
public int maxZ;
public SimpleChangeSetSummary() {
blocks = new int[BlockTypesCache.states.length];
this.minX = Integer.MAX_VALUE;
this.minZ = Integer.MAX_VALUE;
this.maxX = Integer.MIN_VALUE;
this.maxZ = Integer.MIN_VALUE;
}
public SimpleChangeSetSummary(int x, int z) {
blocks = new int[BlockTypesCache.states.length];
minX = x;

View File

@ -21,8 +21,12 @@ package com.sk89q.worldedit.history.changeset;
import static com.google.common.base.Preconditions.checkNotNull;
import com.boydti.fawe.object.changeset.SimpleChangeSetSummary;
import com.google.common.collect.Lists;
import com.sk89q.worldedit.history.change.BlockChange;
import com.sk89q.worldedit.history.change.Change;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region;
import java.util.ArrayList;
import java.util.Iterator;
@ -70,4 +74,16 @@ public class ArrayListHistory implements ChangeSet {
return changes.size();
}
@Override
public ChangeSetSummary summarize(Region region, boolean shallow) {
SimpleChangeSetSummary summary = new SimpleChangeSetSummary();
for (Change change : changes) {
if (change instanceof BlockChange) {
BlockChange blockChange = (BlockChange) change;
BlockVector3 pos = blockChange.getPosition();
summary.add(pos.getX(), pos.getZ(), blockChange.getCurrent().getOrdinal());
}
}
return summary;
}
}

View File

@ -97,19 +97,13 @@ public interface ChangeSet extends Closeable {
*/
default void delete() {}
ChangeSetSummary summarize(Region region, boolean shallow) {
return new ChangeSetSummary() {
@Override
public Map<BlockState, Integer> getBlocks() {
return Collections.emptyMap();
}
@Override
public int getSize() {
return size();
}
};
}
/**
* Get a summary of this changeset
* @param region
* @param shallow
* @return
*/
ChangeSetSummary summarize(Region region, boolean shallow);
/**
* Get if the changeset is empty (i.e. size == 0)