Skip to content

Commit 71aa969

Browse files
committed
now seed can be string value so gtvi will calculate hash from the string
added refresh button
1 parent 3620f69 commit 71aa969

File tree

1 file changed

+36
-20
lines changed

1 file changed

+36
-20
lines changed

src/org/prank/MainFrame.java

+36-20
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import java.io.FileWriter;
99
import java.util.*;
1010
import java.util.List;
11-
import java.util.stream.Collectors;
1211

12+
@SuppressWarnings({"WeakerAccess", "SameParameterValue"})
1313
public class MainFrame extends JFrame {
1414
public static Map<Coord, String> result = new HashMap<>();
1515

@@ -20,7 +20,6 @@ public class MainFrame extends JFrame {
2020
private JComboBox<String> cbDim;
2121
private JComboBox<String> cbOre;
2222
private JTextArea taOutput;
23-
;
2423

2524
public MainFrame() throws HeadlessException {
2625
super("GTVeinInfo");
@@ -42,7 +41,7 @@ public void windowClosing(WindowEvent we) {
4241

4342
setVisible(true);
4443

45-
tfSeed.setText("123");
44+
tfSeed.setText("");
4645
tfSize.setText("10");
4746
tfOffsetX.setText("0");
4847
tfOffsetZ.setText("0");
@@ -52,7 +51,6 @@ public void generate(long wSeed, int chX, int chZ, String dim) {
5251
Random fmlRandom = new Random(wSeed);
5352
long xSeed = fmlRandom.nextLong() >> 2 + 1L;
5453
long zSeed = fmlRandom.nextLong() >> 2 + 1L;
55-
//8487375766640924151
5654
fmlRandom.setSeed((xSeed * chX + zSeed * chZ) ^ wSeed);
5755
String oreName = String.valueOf(cbOre.getSelectedItem());
5856
Tuple t = generateGT(new XSTR(fmlRandom.nextInt()), chX, chZ, dim);
@@ -105,7 +103,7 @@ public int hashCode() {
105103

106104
private void calculate() {
107105
result.clear();
108-
long seed = Long.parseLong(tfSeed.getText());
106+
long seed = getSeed();
109107
int size = Integer.parseInt(tfSize.getText()) * 3;
110108
int offsetX = Integer.parseInt(tfOffsetX.getText()) >> 4;
111109
int offsetZ = Integer.parseInt(tfOffsetZ.getText()) >> 4;
@@ -115,7 +113,7 @@ private void calculate() {
115113
for (int z = -size; z < size; z++)
116114
generate(seed, x + offsetX, z + offsetZ, dim);
117115

118-
List<Coord> coords = result.keySet().stream().collect(Collectors.toList());
116+
List<Coord> coords = new ArrayList<>(result.keySet());
119117
coords.sort((l, r) -> l.x != r.x ? l.x - r.x : l.z - r.z);
120118
StringBuilder sb = new StringBuilder();
121119
coords.forEach(c -> sb
@@ -127,26 +125,44 @@ private void calculate() {
127125
taOutput.setText(sb.toString());
128126
}
129127

128+
private long getSeed() {
129+
String seedStr = tfSeed.getText();
130+
if (seedStr == null || seedStr.equals("")) {
131+
long newSeed = new Random().nextLong();
132+
tfSeed.setText(String.valueOf(newSeed));
133+
return newSeed;
134+
}
135+
long seed;
136+
try {
137+
seed = Long.parseLong(seedStr);
138+
} catch (Exception e) {
139+
seed = seedStr.hashCode();
140+
tfSeed.setText(String.valueOf(seed));
141+
}
142+
return seed;
143+
}
144+
130145
private void export() {
131146
if (result.isEmpty())
132147
calculate();
133148
File waypoints = new File("waypoints");
134149
if (!waypoints.exists()) {
150+
//noinspection ResultOfMethodCallIgnored
135151
waypoints.mkdir();
136152
}
137153
result.forEach(this::writeWayPoint);
138154
}
139155

140156
private void writeWayPoint(Coord coord, String name) {
141-
String upName = name.substring(0, 1).toUpperCase() + name.substring(1, name.length());
142-
String wpName = upName + "_" + coord.x + "," + coord.y + "," + coord.z;
143-
String fileName = "waypoints/" + wpName + "." + getCurrentDimID() + ".json";
144-
145157
// Translate chunk coords to block coords
146158
int x = coord.x * 16 + 8;
147159
int y = coord.y;
148160
int z = coord.z * 16 + 8;
149161

162+
String upName = name.substring(0, 1).toUpperCase() + name.substring(1, name.length());
163+
String wpName = upName + "_" + x + "," + y + "," + z;
164+
String fileName = "waypoints/" + wpName + "." + getCurrentDimID() + ".json";
165+
150166
// Stretch coords if nether dimension due to JourneyMap squeezing
151167
if (getCurrentDimID() == -1)
152168
{
@@ -200,13 +216,21 @@ private int getCurrentDimID() {
200216
private void setButtons() {
201217
setButton("Calculate", 10, 40, 95, 25, this::calculate);
202218
setButton("JM Export", 110, 40, 95, 25, this::export);
219+
JButton btnRefresh = setButton("↻", 300, 10, 25, 25, this::refresh);
220+
btnRefresh.setMargin(new Insets(0, 0, 0, 0));
203221
}
204222

205-
private void setButton(String name, int x, int y, int w, int h, Runnable action) {
223+
private void refresh() {
224+
tfSeed.setText("");
225+
calculate();
226+
}
227+
228+
private JButton setButton(String name, int x, int y, int w, int h, Runnable action) {
206229
JButton jButton = new JButton(name);
207230
jButton.addActionListener(e -> action.run());
208231
jButton.setBounds(x, y, w, h);
209232
add(jButton);
233+
return jButton;
210234
}
211235

212236
private void setInputs() {
@@ -231,11 +255,10 @@ private void setLabels() {
231255
setLabel("Z:", 360, 40, 50, 25);
232256
}
233257

234-
private JLabel setLabel(String text, int x, int y, int w, int h) {
258+
private void setLabel(String text, int x, int y, int w, int h) {
235259
JLabel jLabel = new JLabel(text);
236260
jLabel.setBounds(x, y, w, h);
237261
add(jLabel);
238-
return jLabel;
239262
}
240263

241264
private void setTextAreas() {
@@ -274,11 +297,4 @@ private final <T> JComboBox<T> setComboBox(int x, int y, int w, int h, T... valu
274297
add(jComboBox);
275298
return jComboBox;
276299
}
277-
278-
private JCheckBox setCheckBox(String name, int x, int y, int w, int h) {
279-
JCheckBox jCheckBox = new JCheckBox(name);
280-
jCheckBox.setBounds(x, y, w, h);
281-
add(jCheckBox);
282-
return jCheckBox;
283-
}
284300
}

0 commit comments

Comments
 (0)