Merge branch 'main' of gitlab.com:distant-horizons-team/distant-horizons

This commit is contained in:
James Seibel
2025-01-10 22:00:24 -06:00
5 changed files with 169 additions and 19 deletions
@@ -33,11 +33,49 @@ public abstract class AbstractCommand
protected int sendSuccessResponse(CommandContext<CommandSourceStack> 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<CommandSourceStack> 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<CommandSourceStack> 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;
}
@@ -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)
{
@@ -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<CommandSourceStack> buildCommand()
{
LiteralArgumentBuilder<CommandSourceStack> statusCommand = literal("status")
.executes(this::pregenStatus);
LiteralArgumentBuilder<CommandSourceStack> startCommand = literal("start")
.then(argument("dimension", DimensionArgument.dimension())
.then(argument("origin", ColumnPosArgument.columnPos())
.then(argument("chunkRadius", integer(32))
.executes(this::pregenStart))));
LiteralArgumentBuilder<CommandSourceStack> stopCommand = literal("stop")
.executes(this::pregenStop);
return literal("pregen")
.then(statusCommand)
.then(startCommand)
.then(stopCommand);
}
private int pregenStatus(CommandContext<CommandSourceStack> 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<CommandSourceStack> 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<Void> 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<CommandSourceStack> c)
{
CompletableFuture<Void> runningPregen = this.pregenManager.getRunningPregen();
if (runningPregen != null)
{
runningPregen.cancel(true);
}
return 1;
}
}
@@ -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<ButtonEntry>
@@ -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<? extends GuiEventListener> children()
{
return children;
return this.children;
}
#if MC_VER >= MC_1_17_1
@Override
public List<? extends NarratableEntry> narratables()
{
return children;
return this.children;
}
#endif
}