8
8
import java .io .FileWriter ;
9
9
import java .util .*;
10
10
import java .util .List ;
11
- import java .util .stream .Collectors ;
12
11
12
+ @ SuppressWarnings ({"WeakerAccess" , "SameParameterValue" })
13
13
public class MainFrame extends JFrame {
14
14
public static Map <Coord , String > result = new HashMap <>();
15
15
@@ -20,7 +20,6 @@ public class MainFrame extends JFrame {
20
20
private JComboBox <String > cbDim ;
21
21
private JComboBox <String > cbOre ;
22
22
private JTextArea taOutput ;
23
- ;
24
23
25
24
public MainFrame () throws HeadlessException {
26
25
super ("GTVeinInfo" );
@@ -42,7 +41,7 @@ public void windowClosing(WindowEvent we) {
42
41
43
42
setVisible (true );
44
43
45
- tfSeed .setText ("123 " );
44
+ tfSeed .setText ("" );
46
45
tfSize .setText ("10" );
47
46
tfOffsetX .setText ("0" );
48
47
tfOffsetZ .setText ("0" );
@@ -52,7 +51,6 @@ public void generate(long wSeed, int chX, int chZ, String dim) {
52
51
Random fmlRandom = new Random (wSeed );
53
52
long xSeed = fmlRandom .nextLong () >> 2 + 1L ;
54
53
long zSeed = fmlRandom .nextLong () >> 2 + 1L ;
55
- //8487375766640924151
56
54
fmlRandom .setSeed ((xSeed * chX + zSeed * chZ ) ^ wSeed );
57
55
String oreName = String .valueOf (cbOre .getSelectedItem ());
58
56
Tuple t = generateGT (new XSTR (fmlRandom .nextInt ()), chX , chZ , dim );
@@ -105,7 +103,7 @@ public int hashCode() {
105
103
106
104
private void calculate () {
107
105
result .clear ();
108
- long seed = Long . parseLong ( tfSeed . getText () );
106
+ long seed = getSeed ( );
109
107
int size = Integer .parseInt (tfSize .getText ()) * 3 ;
110
108
int offsetX = Integer .parseInt (tfOffsetX .getText ()) >> 4 ;
111
109
int offsetZ = Integer .parseInt (tfOffsetZ .getText ()) >> 4 ;
@@ -115,7 +113,7 @@ private void calculate() {
115
113
for (int z = -size ; z < size ; z ++)
116
114
generate (seed , x + offsetX , z + offsetZ , dim );
117
115
118
- List <Coord > coords = result .keySet (). stream (). collect ( Collectors . toList ());
116
+ List <Coord > coords = new ArrayList <>( result .keySet ());
119
117
coords .sort ((l , r ) -> l .x != r .x ? l .x - r .x : l .z - r .z );
120
118
StringBuilder sb = new StringBuilder ();
121
119
coords .forEach (c -> sb
@@ -127,26 +125,44 @@ private void calculate() {
127
125
taOutput .setText (sb .toString ());
128
126
}
129
127
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
+
130
145
private void export () {
131
146
if (result .isEmpty ())
132
147
calculate ();
133
148
File waypoints = new File ("waypoints" );
134
149
if (!waypoints .exists ()) {
150
+ //noinspection ResultOfMethodCallIgnored
135
151
waypoints .mkdir ();
136
152
}
137
153
result .forEach (this ::writeWayPoint );
138
154
}
139
155
140
156
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
-
145
157
// Translate chunk coords to block coords
146
158
int x = coord .x * 16 + 8 ;
147
159
int y = coord .y ;
148
160
int z = coord .z * 16 + 8 ;
149
161
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
+
150
166
// Stretch coords if nether dimension due to JourneyMap squeezing
151
167
if (getCurrentDimID () == -1 )
152
168
{
@@ -200,13 +216,21 @@ private int getCurrentDimID() {
200
216
private void setButtons () {
201
217
setButton ("Calculate" , 10 , 40 , 95 , 25 , this ::calculate );
202
218
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 ));
203
221
}
204
222
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 ) {
206
229
JButton jButton = new JButton (name );
207
230
jButton .addActionListener (e -> action .run ());
208
231
jButton .setBounds (x , y , w , h );
209
232
add (jButton );
233
+ return jButton ;
210
234
}
211
235
212
236
private void setInputs () {
@@ -231,11 +255,10 @@ private void setLabels() {
231
255
setLabel ("Z:" , 360 , 40 , 50 , 25 );
232
256
}
233
257
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 ) {
235
259
JLabel jLabel = new JLabel (text );
236
260
jLabel .setBounds (x , y , w , h );
237
261
add (jLabel );
238
- return jLabel ;
239
262
}
240
263
241
264
private void setTextAreas () {
@@ -274,11 +297,4 @@ private final <T> JComboBox<T> setComboBox(int x, int y, int w, int h, T... valu
274
297
add (jComboBox );
275
298
return jComboBox ;
276
299
}
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
- }
284
300
}
0 commit comments