3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-12-25 18:40:05 +01:00

Support using //distr on console properly (#1827)

Dieser Commit ist enthalten in:
Jordan 2022-06-19 22:35:36 +01:00 committet von GitHub
Ursprung dac3610bcf
Commit 396faf6732
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
3 geänderte Dateien mit 38 neuen und 7 gelöschten Zeilen

Datei anzeigen

@ -2832,13 +2832,16 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
public List<Countable<BlockState>> getBlockDistribution(Region region, boolean separateStates) { public List<Countable<BlockState>> getBlockDistribution(Region region, boolean separateStates) {
//FAWE start - get distr //FAWE start - get distr
if (separateStates) { if (separateStates) {
return getBlockDistributionWithData(region); List<Countable<BlockState>> distr = getBlockDistributionWithData(region);
Collections.reverse(distr);
return distr;
} }
List<Countable<BlockType>> normalDistr = getBlockDistribution(region); List<Countable<BlockType>> normalDistr = getBlockDistribution(region);
List<Countable<BlockState>> distribution = new ArrayList<>(); List<Countable<BlockState>> distribution = new ArrayList<>();
for (Countable<BlockType> count : normalDistr) { for (Countable<BlockType> count : normalDistr) {
distribution.add(new Countable<>(count.getID().getDefaultState(), count.getAmount())); distribution.add(new Countable<>(count.getID().getDefaultState(), count.getAmount()));
} }
Collections.reverse(distribution);
//FAWE end //FAWE end
return distribution; return distribution;
} }

Datei anzeigen

@ -770,6 +770,10 @@ public class SelectionCommands {
private final List<Countable<BlockState>> distribution; private final List<Countable<BlockState>> distribution;
private final int totalBlocks; private final int totalBlocks;
private final boolean separateStates; private final boolean separateStates;
//FAWE start
private final int maxDigits;
private boolean consoleFormat = false;
//FAWE end
public BlockDistributionResult(List<Countable<BlockState>> distribution, boolean separateStates) { public BlockDistributionResult(List<Countable<BlockState>> distribution, boolean separateStates) {
this(distribution, separateStates, "//distr -p %page%" + (separateStates ? " -d" : "")); this(distribution, separateStates, "//distr -p %page%" + (separateStates ? " -d" : ""));
@ -782,6 +786,9 @@ public class SelectionCommands {
this.totalBlocks = distribution.stream().mapToInt(Countable::getAmount).sum(); this.totalBlocks = distribution.stream().mapToInt(Countable::getAmount).sum();
this.separateStates = separateStates; this.separateStates = separateStates;
setComponentsPerPage(7); setComponentsPerPage(7);
//FAWE start
this.maxDigits = (int) (Math.log10(distribution.get(0).getAmount()) + 1);
//FAWE end
} }
@Override @Override
@ -791,17 +798,31 @@ public class SelectionCommands {
final int count = c.getAmount(); final int count = c.getAmount();
//FAWE start - better formatting, support console
final double perc = count / (double) totalBlocks * 100; final double perc = count / (double) totalBlocks * 100;
final int maxDigits = (int) (Math.log10(totalBlocks) + 1);
final int curDigits = (int) (Math.log10(count) + 1); final int curDigits = (int) (Math.log10(count) + 1);
line.append(String.format("%s%.3f%% ", perc < 10 ? " " : "", perc), TextColor.GOLD); // Assume console uses monospaced font
final int space = maxDigits - curDigits; final String space = consoleFormat ? " " : " ";
String pad = Strings.repeat(" ", space == 0 ? 2 : 2 * space + 1);
line.append(String.format("%s%.3f%% ", perc < 10 ? space : "", perc), TextColor.GOLD);
final int diff = maxDigits - curDigits;
final int multipler;
if (consoleFormat) {
multipler = diff + 2;
} else {
multipler = diff == 0 ? 2 : 2 * diff + 1;
}
String pad = Strings.repeat(" ", multipler);
//FAWE end
line.append(String.format("%s%s", count, pad), TextColor.YELLOW); line.append(String.format("%s%s", count, pad), TextColor.YELLOW);
final BlockState state = c.getID(); final BlockState state = c.getID();
final BlockType blockType = state.getBlockType(); final BlockType blockType = state.getBlockType();
Component blockName = blockType.getRichName();
//FAWE start - better formatting, support console; Translation keys will not work on console
Component blockName = consoleFormat ? TextComponent.of(blockType.getName()) : blockType.getRichName();
//FAWE end
TextComponent toolTip; TextComponent toolTip;
if (separateStates && state != blockType.getDefaultState()) { if (separateStates && state != blockType.getDefaultState()) {
toolTip = TextComponent.of(state.getAsString()); toolTip = TextComponent.of(state.getAsString());
@ -820,6 +841,14 @@ public class SelectionCommands {
return distribution.size(); return distribution.size();
} }
//FAWE start - support for console
@Override
public void formatForConsole() {
this.consoleFormat = true;
super.formatForConsole();
}
//FAWE end
@Override @Override
public Component create(int page) throws InvalidComponentException { public Component create(int page) throws InvalidComponentException {
super.getContents().append(Caption.of("worldedit.distr.total", TextComponent.of(totalBlocks))) super.getContents().append(Caption.of("worldedit.distr.total", TextComponent.of(totalBlocks)))

Datei anzeigen

@ -621,7 +621,6 @@ public interface Extent extends InputExtent, OutputExtent {
} }
} }
} }
// Collections.reverse(distribution);
return distribution; return distribution;
} }