Reduce complexity.

This commit is contained in:
tastybento 2024-03-15 18:49:20 -07:00
parent 91998b4e24
commit 6127cdced1

View File

@ -237,25 +237,7 @@ public class BlueprintPaster {
private void pasteBlocks(Bits bits, int count, Optional<User> owner, int pasteSpeed, boolean useNMS) { private void pasteBlocks(Bits bits, int count, Optional<User> owner, int pasteSpeed, boolean useNMS) {
Iterator<Entry<Vector, BlueprintBlock>> it = pasteState.equals(PasteState.BLOCKS) ? bits.it : bits.it2; Iterator<Entry<Vector, BlueprintBlock>> it = pasteState.equals(PasteState.BLOCKS) ? bits.it : bits.it2;
if (it.hasNext()) { if (it.hasNext()) {
Map<Location, BlueprintBlock> blockMap = new HashMap<>(); pasteBlocksNow(it, count, pasteSpeed, useNMS);
// Paste blocks
while (count < pasteSpeed) {
if (!it.hasNext()) {
break;
}
Entry<Vector, BlueprintBlock> entry = it.next();
Location pasteTo = location.clone().add(entry.getKey());
// pos1 and pos2 update
updatePos(pasteTo);
BlueprintBlock block = entry.getValue();
blockMap.put(pasteTo, block);
count++;
}
if (!blockMap.isEmpty()) {
currentTask = useNMS ? paster.pasteBlocks(island, world, blockMap)
: fallback.pasteBlocks(island, world, blockMap);
}
} else { } else {
if (pasteState.equals(PasteState.BLOCKS)) { if (pasteState.equals(PasteState.BLOCKS)) {
// Blocks done // Blocks done
@ -272,6 +254,29 @@ public class BlueprintPaster {
} }
private void pasteBlocksNow(Iterator<Entry<Vector, BlueprintBlock>> it, int count, int pasteSpeed, boolean useNMS) {
Map<Location, BlueprintBlock> blockMap = new HashMap<>();
// Paste blocks
while (count < pasteSpeed) {
if (!it.hasNext()) {
break;
}
Entry<Vector, BlueprintBlock> entry = it.next();
Location pasteTo = location.clone().add(entry.getKey());
// pos1 and pos2 update
updatePos(pasteTo);
BlueprintBlock block = entry.getValue();
blockMap.put(pasteTo, block);
count++;
}
if (!blockMap.isEmpty()) {
currentTask = useNMS ? paster.pasteBlocks(island, world, blockMap)
: fallback.pasteBlocks(island, world, blockMap);
}
}
private void loadChunk() { private void loadChunk() {
long timer = System.currentTimeMillis(); long timer = System.currentTimeMillis();
pasteState = PasteState.CHUNK_LOADING; pasteState = PasteState.CHUNK_LOADING;