mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-26 02:19:23 +00:00
修复字体分配
This commit is contained in:
@@ -46,6 +46,7 @@ import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CompletionException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public abstract class AbstractBlockManager extends AbstractModelGenerator implements BlockManager {
|
||||
@@ -428,13 +429,9 @@ public abstract class AbstractBlockManager extends AbstractModelGenerator implem
|
||||
}
|
||||
}
|
||||
|
||||
CompletableFutures.allOf(internalIdAllocators).thenRun(() -> ResourceConfigUtils.runCatching(path, node, () -> {
|
||||
for (int i = 0; i < internalIdAllocators.size(); i++) {
|
||||
CompletableFuture<Integer> future = internalIdAllocators.get(i);
|
||||
try {
|
||||
int internalId = future.get();
|
||||
states.get(i).setCustomBlockState(BlockRegistryMirror.byId(internalId + AbstractBlockManager.this.vanillaBlockStateCount));
|
||||
} catch (ExecutionException e) {
|
||||
CompletableFutures.allOf(internalIdAllocators).whenComplete((v, t) -> ResourceConfigUtils.runCatching(path, node, () -> {
|
||||
if (t != null) {
|
||||
if (t instanceof CompletionException e) {
|
||||
Throwable cause = e.getCause();
|
||||
// 这里不会有conflict了,因为之前已经判断过了
|
||||
if (cause instanceof IdAllocator.IdExhaustedException) {
|
||||
@@ -443,7 +440,16 @@ public abstract class AbstractBlockManager extends AbstractModelGenerator implem
|
||||
Debugger.BLOCK.warn(() -> "Unknown error while allocating internal block state id.", cause);
|
||||
return;
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
throw new RuntimeException("Unknown error occurred", t);
|
||||
}
|
||||
|
||||
for (int i = 0; i < internalIdAllocators.size(); i++) {
|
||||
CompletableFuture<Integer> future = internalIdAllocators.get(i);
|
||||
try {
|
||||
int internalId = future.get();
|
||||
states.get(i).setCustomBlockState(BlockRegistryMirror.byId(internalId + AbstractBlockManager.this.vanillaBlockStateCount));
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
AbstractBlockManager.this.plugin.logger().warn("Interrupted while allocating internal block state for block " + id.asString(), e);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CompletionException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -572,7 +573,7 @@ public abstract class AbstractFontManager implements FontManager {
|
||||
codepoints = CharacterUtils.charsToCodePoints(charString.toCharArray());
|
||||
}
|
||||
for (int j = 0; j < codepoints.length; j++) {
|
||||
futureCodepoints.add(allocator.assignFixedId(id.asString() + ":" + i + ":" + j, codepoints[i]));
|
||||
futureCodepoints.add(allocator.assignFixedId(id.asString() + ":" + i + ":" + j, codepoints[j]));
|
||||
}
|
||||
if (tempColumns == -1) {
|
||||
tempColumns = codepoints.length;
|
||||
@@ -607,26 +608,32 @@ public abstract class AbstractFontManager implements FontManager {
|
||||
}
|
||||
}
|
||||
|
||||
CompletableFutures.allOf(futureCodepoints).thenRun(() -> ResourceConfigUtils.runCatching(path, node, () -> {
|
||||
CompletableFutures.allOf(futureCodepoints).whenComplete((v, t) -> ResourceConfigUtils.runCatching(path, node, () -> {
|
||||
if (t != null) {
|
||||
if (t instanceof CompletionException e) {
|
||||
Throwable cause = e.getCause();
|
||||
if (cause instanceof IdAllocator.IdConflictException conflict) {
|
||||
throw new LocalizedResourceConfigException("warning.config.image.codepoint.conflict",
|
||||
fontId.toString(),
|
||||
CharacterUtils.encodeCharsToUnicode(Character.toChars(conflict.id())),
|
||||
new String(Character.toChars(conflict.id())),
|
||||
conflict.previousOwner()
|
||||
);
|
||||
} else if (cause instanceof IdAllocator.IdExhaustedException) {
|
||||
throw new LocalizedResourceConfigException("warning.config.image.codepoint.exhausted", fontId.asString());
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("Unknown error occurred", t);
|
||||
}
|
||||
|
||||
int[][] codepointGrid = new int[rows][columns];
|
||||
|
||||
for (int i = 0; i < rows; i++) {
|
||||
for (int j = 0; j < columns; j++) {
|
||||
try {
|
||||
int codepoint = futureCodepoints.get(i * columns + j).get();
|
||||
codepointGrid[i][j] = codepoint;
|
||||
} catch (ExecutionException e) {
|
||||
Throwable cause = e.getCause();
|
||||
if (cause instanceof IdAllocator.IdConflictException conflict) {
|
||||
throw new LocalizedResourceConfigException("warning.config.image.codepoint.conflict",
|
||||
fontId.toString(),
|
||||
CharacterUtils.encodeCharsToUnicode(Character.toChars(conflict.id())),
|
||||
new String(Character.toChars(conflict.id())),
|
||||
conflict.previousOwner()
|
||||
);
|
||||
} else if (cause instanceof IdAllocator.IdExhaustedException) {
|
||||
throw new LocalizedResourceConfigException("warning.config.image.codepoint.exhausted", fontId.asString());
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
AbstractFontManager.this.plugin.logger().warn("Interrupted while allocating codepoint for image " + id.asString(), e);
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user