- copy the seed from the preview to the seed input box when pressing 'done'

This commit is contained in:
dags- 2020-03-21 00:40:09 +00:00
parent 1963a388a7
commit 13cb455012
3 changed files with 53 additions and 7 deletions

View File

@ -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;
}
}

View File

@ -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() {

View File

@ -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<Settings> consumer) {