Skip to content

Commit

Permalink
Fix crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaming32 committed Sep 27, 2022
1 parent 561ec0a commit 7fca394
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 40 deletions.
14 changes: 10 additions & 4 deletions src/main/java/io/github/gaming32/niceload/api/NiceLoad.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ public static SplashScreen getSplashScreen() {
}
final SplashScreen splash = (SplashScreen)overlay;
if (!TO_ADD_QUEUE.isEmpty()) {
TO_ADD_QUEUE.values().forEach(splash::addTask);
TO_ADD_QUEUE.clear();
synchronized (TO_ADD_QUEUE) {
TO_ADD_QUEUE.values().forEach(splash::addTask);
TO_ADD_QUEUE.clear();
}
}
return splash;
}
Expand All @@ -37,7 +39,9 @@ public static LoadTask addTask(LoadTask task) {
if (splash != null) {
splash.addTask(task);
} else {
TO_ADD_QUEUE.put(task.getName(), task);
synchronized (TO_ADD_QUEUE) {
TO_ADD_QUEUE.put(task.getName(), task);
}
}
return task;
}
Expand All @@ -47,7 +51,9 @@ public static LoadTask getTask(String name) {
if (splash != null) {
return splash.getTask(name);
} else {
return TO_ADD_QUEUE.get(name);
synchronized (TO_ADD_QUEUE) {
return TO_ADD_QUEUE.get(name);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.github.gaming32.niceload.api.NiceLoad;
import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint;
import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher;
import net.minecraft.client.render.entity.EntityRenderDispatcher;
import org.slf4j.Logger;

import java.io.IOException;
Expand All @@ -28,7 +29,7 @@ public void onPreLaunch() {
throw new UncheckedIOException(e);
}
NiceLoad.registerReloader(BlockEntityRenderDispatcher.class.getSimpleName());
NiceLoad.registerReloader(BlockEntityRenderDispatcher.class.getSimpleName());
NiceLoad.registerReloader(EntityRenderDispatcher.class.getSimpleName());
}

public static NiceLoadMod getInstance() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,18 @@ public SplashOverlay getOverlay() {

@Override
public LoadTask addTask(LoadTask task) {
niceload$tasks.put(task.getName(), task);
synchronized (niceload$tasks) {
niceload$tasks.put(task.getName(), task);
}
NiceLoadInternals.attemptRender();
return task;
}

@Override
public LoadTask getTask(String name) {
return niceload$tasks.get(name);
synchronized (niceload$tasks) {
return niceload$tasks.get(name);
}
}

@Inject(
Expand All @@ -71,44 +75,46 @@ private void render(MatrixStack matrices, int mouseX, int mouseY, float delta, C
(textColor & 0xffffff) | ((int)(opacity * 255) << 24)
);

final Iterator<LoadTask> it = niceload$tasks.values().iterator();
int count = 0;
int limit = (client.getWindow().getScaledHeight() - s - 20) / 20;
int y = s + 20;
while (it.hasNext()) {
final LoadTask task = it.next();
final float progress = task.getProgress01();
if (progress >= 1f) {
it.remove();
continue;
}
if (++count > limit) continue;
RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, h);
renderProgressBar(
matrices, i / 2 - r, y - 6, i / 2 + r, y + 7, opacity,
task.getMaxProgress() > 1 ? progress : 0.5f
);
String text = task.getName();
if (task.getMaxProgress() > 1) {
text += " - " + (Math.round(MathHelper.clamp(progress, 0f, 1f) * 1000) / 10.0) + "%";
}
if (!task.getDescription().isEmpty()) {
text += " - " + task.getDescription();
NiceLoadMod.getInstance().getTextRenderer().drawText(
matrices,
text,
i / 2 - r + 3, y - 3, r * 2 - 6,
textColor | ((int)(opacity * 255) << 24)
);
} else {
NiceLoadMod.getInstance().getTextRenderer().drawCenteredText(
matrices,
text,
i / 2, y - 3,
textColor | ((int)(opacity * 255) << 24)
synchronized (niceload$tasks) {
final Iterator<LoadTask> it = niceload$tasks.values().iterator();
while (it.hasNext()) {
final LoadTask task = it.next();
final float progress = task.getProgress01();
if (progress >= 1f) {
it.remove();
continue;
}
if (++count > limit) continue;
RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, h);
renderProgressBar(
matrices, i / 2 - r, y - 6, i / 2 + r, y + 7, opacity,
task.getMaxProgress() > 1 ? progress : 0.5f
);
String text = task.getName();
if (task.getMaxProgress() > 1) {
text += " - " + (Math.round(MathHelper.clamp(progress, 0f, 1f) * 1000) / 10.0) + "%";
}
if (!task.getDescription().isEmpty()) {
text += " - " + task.getDescription();
NiceLoadMod.getInstance().getTextRenderer().drawText(
matrices,
text,
i / 2 - r + 3, y - 3, r * 2 - 6,
textColor | ((int)(opacity * 255) << 24)
);
} else {
NiceLoadMod.getInstance().getTextRenderer().drawCenteredText(
matrices,
text,
i / 2, y - 3,
textColor | ((int)(opacity * 255) << 24)
);
}
y += 20;
}
y += 20;
}
}

Expand Down

0 comments on commit 7fca394

Please sign in to comment.