- copy the seed from the preview to the seed input box when pressing 'done'
This commit is contained in:
parent
1963a388a7
commit
13cb455012
@ -40,17 +40,20 @@ import com.terraforged.mod.settings.SettingsHelper;
|
|||||||
import com.terraforged.mod.settings.TerraSettings;
|
import com.terraforged.mod.settings.TerraSettings;
|
||||||
import com.terraforged.mod.util.nbt.NBTHelper;
|
import com.terraforged.mod.util.nbt.NBTHelper;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.gui.IGuiEventListener;
|
||||||
import net.minecraft.client.gui.screen.CreateWorldScreen;
|
import net.minecraft.client.gui.screen.CreateWorldScreen;
|
||||||
import net.minecraft.client.gui.screen.Screen;
|
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.gui.widget.button.Button;
|
||||||
|
import net.minecraft.client.resources.I18n;
|
||||||
|
|
||||||
public class SettingsScreen extends OverlayScreen {
|
public class SettingsScreen extends OverlayScreen {
|
||||||
|
|
||||||
private static final Button.IPressable NO_ACTION = b -> {};
|
private static final Button.IPressable NO_ACTION = b -> {};
|
||||||
|
|
||||||
private final Page[] pages;
|
private final Page[] pages;
|
||||||
|
private final PreviewPage preview;
|
||||||
private final CreateWorldScreen parent;
|
private final CreateWorldScreen parent;
|
||||||
private final PreviewPage preview = new PreviewPage();
|
|
||||||
private final TerraSettings settings = new TerraSettings();
|
private final TerraSettings settings = new TerraSettings();
|
||||||
|
|
||||||
private int pageIndex = 0;
|
private int pageIndex = 0;
|
||||||
@ -59,6 +62,7 @@ public class SettingsScreen extends OverlayScreen {
|
|||||||
public SettingsScreen(CreateWorldScreen parent) {
|
public SettingsScreen(CreateWorldScreen parent) {
|
||||||
SettingsHelper.applyDefaults(parent.chunkProviderSettingsJson, settings);
|
SettingsHelper.applyDefaults(parent.chunkProviderSettingsJson, settings);
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
|
this.preview = new PreviewPage(getSeed(parent));
|
||||||
this.pages = new Page[]{
|
this.pages = new Page[]{
|
||||||
new GeneratorPage(settings, preview),
|
new GeneratorPage(settings, preview),
|
||||||
new ClimatePage(settings, preview),
|
new ClimatePage(settings, preview),
|
||||||
@ -108,6 +112,7 @@ public class SettingsScreen extends OverlayScreen {
|
|||||||
page.save();
|
page.save();
|
||||||
}
|
}
|
||||||
parent.chunkProviderSettingsJson = NBTHelper.serializeCompact(settings);
|
parent.chunkProviderSettingsJson = NBTHelper.serializeCompact(settings);
|
||||||
|
SettingsScreen.setSeed(parent, preview.getSeed());
|
||||||
onClose();
|
onClose();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@ -260,4 +265,37 @@ public class SettingsScreen extends OverlayScreen {
|
|||||||
private boolean hasPrevious() {
|
private boolean hasPrevious() {
|
||||||
return pageIndex > 0;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,11 +72,15 @@ public class Preview extends Button {
|
|||||||
private String[] labels = {"Area: ", "Terrain: ", "Biome: "};
|
private String[] labels = {"Area: ", "Terrain: ", "Biome: "};
|
||||||
private String[] values = {"", "", ""};
|
private String[] values = {"", "", ""};
|
||||||
|
|
||||||
public Preview() {
|
public Preview(int seed) {
|
||||||
super(0, 0, 0, 0, "", b -> {});
|
super(0, 0, 0, 0, "", b -> {});
|
||||||
this.seed = random.nextInt();
|
this.seed = seed == -1 ? random.nextInt() : seed;
|
||||||
this.offsetX = random.nextInt(50000) - 25000;
|
this.offsetX = 0;//random.nextInt(50000) - 25000;
|
||||||
this.offsetZ = random.nextInt(50000) - 25000;
|
this.offsetZ = 0;//random.nextInt(50000) - 25000;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSeed() {
|
||||||
|
return seed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void regenerate() {
|
public void regenerate() {
|
||||||
|
@ -36,12 +36,16 @@ import java.util.function.Consumer;
|
|||||||
|
|
||||||
public class PreviewPage extends BasePage {
|
public class PreviewPage extends BasePage {
|
||||||
|
|
||||||
private final Preview preview = new Preview();
|
private final Preview preview;
|
||||||
private final Settings settings = new Settings();
|
private final Settings settings = new Settings();
|
||||||
private final CompoundNBT previewerSettings = NBTHelper.serialize(new PreviewSettings());
|
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) {
|
public void apply(Consumer<Settings> consumer) {
|
||||||
|
Loading…
Reference in New Issue
Block a user