From 13cb45501283afa8158be9b02567bced6ac912f9 Mon Sep 17 00:00:00 2001 From: dags- Date: Sat, 21 Mar 2020 00:40:09 +0000 Subject: [PATCH] - copy the seed from the preview to the seed input box when pressing 'done' --- .../terraforged/mod/gui/SettingsScreen.java | 40 ++++++++++++++++++- .../terraforged/mod/gui/preview/Preview.java | 12 ++++-- .../mod/gui/preview/PreviewPage.java | 8 +++- 3 files changed, 53 insertions(+), 7 deletions(-) diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/SettingsScreen.java b/TerraForgedMod/src/main/java/com/terraforged/mod/gui/SettingsScreen.java index 14b3f49..37f0052 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/SettingsScreen.java +++ b/TerraForgedMod/src/main/java/com/terraforged/mod/gui/SettingsScreen.java @@ -40,17 +40,20 @@ import com.terraforged.mod.settings.SettingsHelper; import com.terraforged.mod.settings.TerraSettings; import com.terraforged.mod.util.nbt.NBTHelper; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.IGuiEventListener; import net.minecraft.client.gui.screen.CreateWorldScreen; import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.widget.TextFieldWidget; import net.minecraft.client.gui.widget.button.Button; +import net.minecraft.client.resources.I18n; public class SettingsScreen extends OverlayScreen { private static final Button.IPressable NO_ACTION = b -> {}; private final Page[] pages; + private final PreviewPage preview; private final CreateWorldScreen parent; - private final PreviewPage preview = new PreviewPage(); private final TerraSettings settings = new TerraSettings(); private int pageIndex = 0; @@ -59,6 +62,7 @@ public class SettingsScreen extends OverlayScreen { public SettingsScreen(CreateWorldScreen parent) { SettingsHelper.applyDefaults(parent.chunkProviderSettingsJson, settings); this.parent = parent; + this.preview = new PreviewPage(getSeed(parent)); this.pages = new Page[]{ new GeneratorPage(settings, preview), new ClimatePage(settings, preview), @@ -108,6 +112,7 @@ public class SettingsScreen extends OverlayScreen { page.save(); } parent.chunkProviderSettingsJson = NBTHelper.serializeCompact(settings); + SettingsScreen.setSeed(parent, preview.getSeed()); onClose(); })); @@ -260,4 +265,37 @@ public class SettingsScreen extends OverlayScreen { private boolean hasPrevious() { return pageIndex > 0; } + + private static int getSeed(CreateWorldScreen screen) { + TextFieldWidget field = getWidget(screen); + if (field != null && !field.getText().isEmpty()) { + try { + long seed = Long.parseLong(field.getText()); + return (int) seed; + } catch (NumberFormatException var6) { + return field.getText().hashCode(); + } + } + return -1; + } + + private static void setSeed(CreateWorldScreen screen, int seed) { + TextFieldWidget field = getWidget(screen); + if (field != null) { + field.setText("" + seed); + } + } + + private static TextFieldWidget getWidget(CreateWorldScreen screen) { + String message = I18n.format("selectWorld.enterSeed"); + for (IGuiEventListener widget : screen.children()) { + if (widget instanceof TextFieldWidget) { + TextFieldWidget field = (TextFieldWidget) widget; + if (field.getMessage().equals(message)) { + return field; + } + } + } + return null; + } } diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/preview/Preview.java b/TerraForgedMod/src/main/java/com/terraforged/mod/gui/preview/Preview.java index 906b567..260cefb 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/preview/Preview.java +++ b/TerraForgedMod/src/main/java/com/terraforged/mod/gui/preview/Preview.java @@ -72,11 +72,15 @@ public class Preview extends Button { private String[] labels = {"Area: ", "Terrain: ", "Biome: "}; private String[] values = {"", "", ""}; - public Preview() { + public Preview(int seed) { super(0, 0, 0, 0, "", b -> {}); - this.seed = random.nextInt(); - this.offsetX = random.nextInt(50000) - 25000; - this.offsetZ = random.nextInt(50000) - 25000; + this.seed = seed == -1 ? random.nextInt() : seed; + this.offsetX = 0;//random.nextInt(50000) - 25000; + this.offsetZ = 0;//random.nextInt(50000) - 25000; + } + + public int getSeed() { + return seed; } public void regenerate() { diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/preview/PreviewPage.java b/TerraForgedMod/src/main/java/com/terraforged/mod/gui/preview/PreviewPage.java index 027e148..691082b 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/gui/preview/PreviewPage.java +++ b/TerraForgedMod/src/main/java/com/terraforged/mod/gui/preview/PreviewPage.java @@ -36,12 +36,16 @@ import java.util.function.Consumer; public class PreviewPage extends BasePage { - private final Preview preview = new Preview(); + private final Preview preview; private final Settings settings = new Settings(); private final CompoundNBT previewerSettings = NBTHelper.serialize(new PreviewSettings()); - public PreviewPage() { + public PreviewPage(int seed) { + preview = new Preview(seed); + } + public int getSeed() { + return preview.getSeed(); } public void apply(Consumer consumer) {