diff --git a/src/main/java/io/github/gaming32/niceload/api/NiceLoad.java b/src/main/java/io/github/gaming32/niceload/api/NiceLoad.java index 37735e7..f5eab35 100644 --- a/src/main/java/io/github/gaming32/niceload/api/NiceLoad.java +++ b/src/main/java/io/github/gaming32/niceload/api/NiceLoad.java @@ -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; } @@ -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; } @@ -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); + } } } diff --git a/src/main/java/io/github/gaming32/niceload/client/NiceLoadMod.java b/src/main/java/io/github/gaming32/niceload/client/NiceLoadMod.java index 3ccec60..d6561dc 100644 --- a/src/main/java/io/github/gaming32/niceload/client/NiceLoadMod.java +++ b/src/main/java/io/github/gaming32/niceload/client/NiceLoadMod.java @@ -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; @@ -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() { diff --git a/src/main/java/io/github/gaming32/niceload/client/mixin/core/MixinSplashOverlay.java b/src/main/java/io/github/gaming32/niceload/client/mixin/core/MixinSplashOverlay.java index 8f6ac41..ec71816 100644 --- a/src/main/java/io/github/gaming32/niceload/client/mixin/core/MixinSplashOverlay.java +++ b/src/main/java/io/github/gaming32/niceload/client/mixin/core/MixinSplashOverlay.java @@ -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( @@ -71,44 +75,46 @@ private void render(MatrixStack matrices, int mouseX, int mouseY, float delta, C (textColor & 0xffffff) | ((int)(opacity * 255) << 24) ); - final Iterator 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 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; } }