From 8b374c47342cbe92a1a3841df3b3726fdcc67954 Mon Sep 17 00:00:00 2001 From: s809 <43530948+s809@users.noreply.github.com> Date: Sat, 11 Jan 2025 02:54:30 +0500 Subject: [PATCH 1/2] Fix compilation --- .../wrappers/gui/updater/ChangelogScreen.java | 42 ++++++++++++------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/gui/updater/ChangelogScreen.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/gui/updater/ChangelogScreen.java index 318440f4a..6e5cb4e3c 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/gui/updater/ChangelogScreen.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/gui/updater/ChangelogScreen.java @@ -1,6 +1,5 @@ package com.seibel.distanthorizons.common.wrappers.gui.updater; -import com.mojang.blaze3d.vertex.PoseStack; import com.seibel.distanthorizons.common.wrappers.gui.DhScreen; import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector; import com.seibel.distanthorizons.core.logging.DhLoggerBuilder; @@ -15,6 +14,7 @@ import net.minecraft.client.gui.components.ContainerObjectSelectionList; import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.Component; +import org.apache.logging.log4j.Logger; #if MC_VER >= MC_1_17_1 import net.minecraft.client.gui.narration.NarratableEntry; @@ -22,9 +22,9 @@ import net.minecraft.client.gui.narration.NarratableEntry; #if MC_VER < MC_1_20_1 import net.minecraft.client.gui.GuiComponent; +import com.mojang.blaze3d.vertex.PoseStack; #else import net.minecraft.client.gui.GuiGraphics; -import org.apache.logging.log4j.Logger; #endif @@ -56,20 +56,28 @@ public class ChangelogScreen extends DhScreen this(parent, null); if (!ModrinthGetter.initted) // Make sure the modrinth stuff is initted + { ModrinthGetter.init(); + } if (!ModrinthGetter.initted) // If its not initted, then this isnt usable + { return; + } if (!ModrinthGetter.mcVersions.contains(SingletonInjector.INSTANCE.get(IVersionConstants.class).getMinecraftVersion())) + { return; + } String versionID = ModrinthGetter.getLatestIDForVersion(SingletonInjector.INSTANCE.get(IVersionConstants.class).getMinecraftVersion()); if (versionID == null) + { return; + } try { - setupChangelog(versionID); - usable = true; + this.setupChangelog(versionID); + this.usable = true; } catch (Exception e) { @@ -85,11 +93,13 @@ public class ChangelogScreen extends DhScreen if (versionID == null) + { return; + } try { - setupChangelog(versionID); - usable = true; + this.setupChangelog(versionID); + this.usable = true; } catch (Exception e) { @@ -134,8 +144,10 @@ public class ChangelogScreen extends DhScreen protected void init() { super.init(); - if (!usable) + if (!this.usable) + { return; + } this.addBtn( // Close @@ -146,9 +158,9 @@ public class ChangelogScreen extends DhScreen this.changelogArea = new TextArea(this.minecraft, this.width * 2, this.height, 32, 32, 10); - for (int i = 0; i < changelog.size(); i++) + for (int i = 0; i < this.changelog.size(); i++) { - this.changelogArea.addButton(TextOrLiteral(changelog.get(i))); + this.changelogArea.addButton(TextOrLiteral(this.changelog.get(i))); // drawString(matrices, this.font, changelog.get(i), this.width / 2 - 175, this.height / 2 - 100 + i*10, 0xFFFFFF); } @@ -194,13 +206,13 @@ public class ChangelogScreen extends DhScreen // render order matters, otherwise on 1.20.6+ the blurred background will render on top of the text super.render(matrices, mouseX, mouseY, delta); // Render the buttons this.changelogArea.render(matrices, mouseX, mouseY, delta); // Render the changelog - DhDrawCenteredString(matrices, font, title, width / 2, 15, 0xFFFFFF); // Render title + this.DhDrawCenteredString(matrices, this.font, this.title, this.width / 2, 15, 0xFFFFFF); // Render title } @Override public void onClose() { - Objects.requireNonNull(minecraft).setScreen(this.parent); // Goto the parent screen + Objects.requireNonNull(this.minecraft).setScreen(this.parent); // Goto the parent screen } public static class TextArea extends ContainerObjectSelectionList @@ -215,7 +227,7 @@ public class ChangelogScreen extends DhScreen super(minecraftClient, canvasWidth, canvasHeight - (topMargin + botMargin), topMargin, itemSpacing); #endif this.centerListVertically = false; - textRenderer = minecraftClient.font; + this.textRenderer = minecraftClient.font; } public void addButton(Component text) @@ -257,20 +269,20 @@ public class ChangelogScreen extends DhScreen @Override public void render(GuiGraphics matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) { - matrices.drawString(textRenderer, text, 12, y + 5, 0xFFFFFF); + matrices.drawString(textRenderer, this.text, 12, y + 5, 0xFFFFFF); } #endif @Override public List children() { - return children; + return this.children; } #if MC_VER >= MC_1_17_1 @Override public List narratables() { - return children; + return this.children; } #endif } From 069ebfe24e9879e8f5d391442785987ba673bb82 Mon Sep 17 00:00:00 2001 From: s809 <43530948+s809@users.noreply.github.com> Date: Sat, 11 Jan 2025 02:55:09 +0500 Subject: [PATCH 2/2] Add pregen command --- .../common/commands/AbstractCommand.java | 44 ++++++++- .../common/commands/CommandInitializer.java | 1 + .../common/commands/PregenCommand.java | 99 +++++++++++++++++++ coreSubProjects | 2 +- 4 files changed, 142 insertions(+), 4 deletions(-) create mode 100644 common/src/main/java/com/seibel/distanthorizons/common/commands/PregenCommand.java diff --git a/common/src/main/java/com/seibel/distanthorizons/common/commands/AbstractCommand.java b/common/src/main/java/com/seibel/distanthorizons/common/commands/AbstractCommand.java index febb0c7f4..2d056e973 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/commands/AbstractCommand.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/commands/AbstractCommand.java @@ -33,11 +33,49 @@ public abstract class AbstractCommand protected int sendSuccessResponse(CommandContext commandContext, String text) { #if MC_VER >= MC_1_20_1 - commandContext.getSource().sendSuccess(() -> Component.literal(text), true); + commandContext.getSource().sendSuccess(() -> Component.literal(text), false); #elif MC_VER >= MC_1_19_2 - commandContext.getSource().sendSuccess(Component.literal(text), true); + commandContext.getSource().sendSuccess(Component.literal(text), false); #else - commandContext.getSource().sendSuccess(new TranslatableComponent(text), true); + commandContext.getSource().sendSuccess(new TranslatableComponent(text), false); + #endif + return 1; + } + + /** + * Sends a failure response to the player with the given text. + * + * @param commandContext The command context to send the response to. + * @param text The text to display in the failure message. + * @return 1, indicating that the command was successful. + */ + protected int sendFailureResponse(CommandContext commandContext, String text) + { + #if MC_VER >= MC_1_20_1 + commandContext.getSource().sendFailure(Component.literal(text)); + #elif MC_VER >= MC_1_19_2 + commandContext.getSource().sendFailure(Component.literal(text)); + #else + commandContext.getSource().sendFailure(new TranslatableComponent(text)); + #endif + return 1; + } + + /** + * Sends a failure response to the player with the given text. + * + * @param commandContext The command context to send the response to. + * @param text The text to display in the failure message. + * @return 1, indicating that the command was successful. + */ + protected int sendSystemMessage(CommandContext commandContext, String text) + { + #if MC_VER >= MC_1_20_1 + commandContext.getSource().sendSystemMessage(Component.literal(text)); + #elif MC_VER >= MC_1_19_2 + commandContext.getSource().sendSystemMessage(Component.literal(text)); + #else + commandContext.getSource().sendSuccess(new TranslatableComponent(text), false); #endif return 1; } diff --git a/common/src/main/java/com/seibel/distanthorizons/common/commands/CommandInitializer.java b/common/src/main/java/com/seibel/distanthorizons/common/commands/CommandInitializer.java index d03274498..0cf47d98d 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/commands/CommandInitializer.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/commands/CommandInitializer.java @@ -36,6 +36,7 @@ public class CommandInitializer builder.then(new ConfigCommand().buildCommand()); builder.then(new DebugCommand().buildCommand()); + builder.then(new PregenCommand().buildCommand()); if (DEBUG_CODEC_CRASH_MESSAGE) { diff --git a/common/src/main/java/com/seibel/distanthorizons/common/commands/PregenCommand.java b/common/src/main/java/com/seibel/distanthorizons/common/commands/PregenCommand.java new file mode 100644 index 000000000..76f0ff207 --- /dev/null +++ b/common/src/main/java/com/seibel/distanthorizons/common/commands/PregenCommand.java @@ -0,0 +1,99 @@ +package com.seibel.distanthorizons.common.commands; + +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.seibel.distanthorizons.common.wrappers.world.ServerLevelWrapper; +import com.seibel.distanthorizons.core.generation.PregenManager; +import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos2D; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.DimensionArgument; +import net.minecraft.commands.arguments.coordinates.ColumnPosArgument; +import net.minecraft.server.level.ColumnPos; +import net.minecraft.server.level.ServerLevel; + +import java.util.concurrent.CompletableFuture; + +import static com.mojang.brigadier.arguments.IntegerArgumentType.getInteger; +import static com.mojang.brigadier.arguments.IntegerArgumentType.integer; +import static net.minecraft.commands.Commands.argument; +import static net.minecraft.commands.Commands.literal; + +public class PregenCommand extends AbstractCommand +{ + private final PregenManager pregenManager = new PregenManager(); + + @Override + public LiteralArgumentBuilder buildCommand() + { + LiteralArgumentBuilder statusCommand = literal("status") + .executes(this::pregenStatus); + + LiteralArgumentBuilder startCommand = literal("start") + .then(argument("dimension", DimensionArgument.dimension()) + .then(argument("origin", ColumnPosArgument.columnPos()) + .then(argument("chunkRadius", integer(32)) + .executes(this::pregenStart)))); + + LiteralArgumentBuilder stopCommand = literal("stop") + .executes(this::pregenStop); + + return literal("pregen") + .then(statusCommand) + .then(startCommand) + .then(stopCommand); + } + + + private int pregenStatus(CommandContext c) + { + if (this.pregenManager.getRunningPregen() != null) + { + return this.sendSuccessResponse(c, "Pregen is running"); + } + else + { + return this.sendSuccessResponse(c, "Pregen is not running"); + } + } + + private int pregenStart(CommandContext c) throws CommandSyntaxException + { + this.sendSuccessResponse(c, "Starting pregen"); + + ServerLevel level = DimensionArgument.getDimension(c, "dimension"); + ColumnPos origin = ColumnPosArgument.getColumnPos(c, "origin"); + int chunkRadius = getInteger(c, "chunkRadius"); + + CompletableFuture future = this.pregenManager.startPregen( + ServerLevelWrapper.getWrapper(level), + new DhBlockPos2D(#if MC_VER >= MC_1_19_2 origin.x(), origin.z() #else origin.x, origin.z #endif), + chunkRadius, + update -> this.sendSystemMessage(c, update) + ); + + future.whenComplete((result, throwable) -> { + if (throwable != null) + { + this.sendFailureResponse(c, "Pregen failed: " + throwable.getMessage() + "\n Check the logs for more details."); + return; + } + + this.sendSuccessResponse(c, "Pregen is complete"); + }); + + return 1; + } + + private int pregenStop(CommandContext c) + { + CompletableFuture runningPregen = this.pregenManager.getRunningPregen(); + if (runningPregen != null) + { + runningPregen.cancel(true); + } + + return 1; + } + +} diff --git a/coreSubProjects b/coreSubProjects index 29040519e..ec19e4321 160000 --- a/coreSubProjects +++ b/coreSubProjects @@ -1 +1 @@ -Subproject commit 29040519e0db7d2ae50e636777bb23149e065e6c +Subproject commit ec19e432169d498ea5673c61e18434b111e14324