-
Notifications
You must be signed in to change notification settings - Fork 29
/
StructureArrayTutorialPart1.java
514 lines (492 loc) · 21.2 KB
/
StructureArrayTutorialPart1.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
/*
STRUCTURE GENERATOR TOOL TUTORIAL PART 1: YOUR FIRST STRUCTURE
This tutorial is for use with my Structure Generation Tool, NOT regular minecraft structures.
In this tutorial I will cover how to build your structure using an array from scratch.
Please also refer to the instructions in 'StructureArrays.java' for more information.
*/
/*
* Step 1: Create a new class and array for your structure
*/
/*
Just create a completely empty class. We'll name it 'StructureArrayTutorial' for now.
*/
public class StructureArrayTutorial
{
}
/*
Yep, totally empty right now. Next, look in StructureArrays.java, find 'blockArrayTemplate',
and copy and paste that into your class. It should now look like this:
*/
public class StructureArrayTutorial
{
public static final int[][][][] blockArrayTemplate =
{
{ // y
{ // x
{} // z
}
}
};
}
/*
* Step 2: Create a basic structure
*/
/*
In this step, we're going to create a 5x5 platform. Recall that the z axis runs
north to south, and the x axis runs east to west. All we need to do is place a
block at five consecutive points along the z axis, making a north-south column,
and repeat this column five times along the x axis (east-west).
*/
public static final int[][][][] blockArrayTemplate =
{
{ // y
{ // x
// z: place 5 blocks here that will run north to south
// This first z column is stored at x = 0 in our block array
{Block.wood.blockID}, // here's one, be sure to add a comma ','
{Block.wood.blockID}, // 2
{Block.wood.blockID}, // 3
{Block.wood.blockID}, // 4
{Block.wood.blockID} // 5
// That finishes one column, but we need four more columns
// The next column will be at x = 1
}, // Again, be sure to add a comma ','
{ // This is the start of x = 1
// The brackets within start off the z array once again
// Just copy and paste from above!
{Block.wood.blockID}, // here's one, be sure to add a comma ','
{Block.wood.blockID}, // 2
{Block.wood.blockID}, // 3
{Block.wood.blockID}, // 4
{Block.wood.blockID} // 5
// Just like that! Now copy an entire x subsection and paste it
// 3 more times. Don't forget to add that comma!
},
{ // This is the start of x = 1
// The brackets within start off the z array once again
// Just copy and paste from above!
{Block.wood.blockID}, // here's one, be sure to add a comma ','
{Block.wood.blockID}, // 2
{Block.wood.blockID}, // 3
{Block.wood.blockID}, // 4
{Block.wood.blockID} // 5
// Just like that! Now copy an entire x subsection and paste it
// 3 more times. Don't forget to add that comma!
},
{ // This is the start of x = 1
// The brackets within start off the z array once again
// Just copy and paste from above!
{Block.wood.blockID}, // here's one, be sure to add a comma ','
{Block.wood.blockID}, // 2
{Block.wood.blockID}, // 3
{Block.wood.blockID}, // 4
{Block.wood.blockID} // 5
// Just like that! Now copy an entire x subsection and paste it
// 3 more times. Don't forget to add that comma!
},
{ // This is the start of x = 1
// The brackets within start off the z array once again
// Just copy and paste from above!
{Block.wood.blockID}, // here's one, be sure to add a comma ','
{Block.wood.blockID}, // 2
{Block.wood.blockID}, // 3
{Block.wood.blockID}, // 4
{Block.wood.blockID} // 5 <-- Remove the last comma!
// Just like that! Now copy an entire x subsection and paste it
// 3 more times. Don't forget to add that comma!
}, // <-- Remove the last comma, as there won't be another x sub-array here
}
}; // <-- There needs to be a semi-colon ';' at the end of your array
/*
Step 3: Add your structure to the StructureGenerator and test it out
*/
/*
To allow your structure to be easily spawned by the ItemStructureSpawner, we
need to add a new Structure to the list. Open the StructureGenerator class and
go to the very bottom. There you'll find a static {...} initializer that adds
all the current Structures. Add the following code after the last structure:
*/
// In StructureGenerator:
static
{
// All the other structures are here, put your code last:
structure = new Structure("Tutorial");
structure.addBlockArray(StructureArrayTutorial.blockArrayTutorial);
structures.add(structure);
}
/*
Easy as that! Note that I changed the name from 'blockArrayTemplate' to
'blockArrayTutorial'. You should do the same. Now launch Minecraft in Creative
mode, grab yourself a hammer (ItemStructureSpawner), press '[' left bracket
and your 'Tutorial' structure should be selected. Right click on a block to
generate it. Well, that's not so great, is it? A 5x5 wooden platform. Yay.
Let's make it better.
*/
/*
* Step 4: Build a House
*/
/*
First, clean up the array by removing all those random comments, but leave the
'x=0', 'z=0', 'z=1', etc. comments in there, and make sure they are correct.
Trust me, it makes it a LOT easier to keep track of stuff that way.
Now your array should look like this:
*/
public static final int[][][][] blockArrayTutorial =
{
{ // y = 1
{ // x = 1
{Block.wood.blockID}, // z = 1
{Block.wood.blockID}, // z = 2
{Block.wood.blockID}, // z = 3
{Block.wood.blockID}, // z = 4
{Block.wood.blockID} // z = 5
},
{ // x = 2
{Block.wood.blockID}, // z = 1
{Block.wood.blockID}, // z = 2
{Block.wood.blockID}, // z = 3
{Block.wood.blockID}, // z = 4
{Block.wood.blockID} // z = 5
},
{ // x = 3
{Block.wood.blockID}, // z = 1
{Block.wood.blockID}, // z = 2
{Block.wood.blockID}, // z = 3
{Block.wood.blockID}, // z = 4
{Block.wood.blockID} // z = 5
},
{ // x = 4
{Block.wood.blockID}, // z = 1
{Block.wood.blockID}, // z = 2
{Block.wood.blockID}, // z = 3
{Block.wood.blockID}, // z = 4
{Block.wood.blockID} // z = 5
},
{ // x = 5
{Block.wood.blockID}, // z = 1
{Block.wood.blockID}, // z = 2
{Block.wood.blockID}, // z = 3
{Block.wood.blockID}, // z = 4
{Block.wood.blockID} // z = 5
}
}
};
/*
You should notice that I started counting at 1, even though the array index is
really 0. That's because it doesn't matter as far as we're concerned. We just
need to keep track of the relative order, and it's far more natural to count
from 1 rather than 0. If you'd rather start at 0, that's fine too.
Ok, first copy and paste ALL of the array from x=1 to x=5 into a new y layer,
then do it one more time. You should now have 3 identical 5x5 'layers'.
*/
public static final int[][][][] blockArrayTutorial =
{
{ // y = 1
{ // x = 1
{Block.wood.blockID}, // z = 1
{Block.wood.blockID}, // z = 2
{Block.wood.blockID}, // z = 3
{Block.wood.blockID}, // z = 4
{Block.wood.blockID} // z = 5
},
{ // x = 2
{Block.wood.blockID}, // z = 1
{Block.wood.blockID}, // z = 2
{Block.wood.blockID}, // z = 3
{Block.wood.blockID}, // z = 4
{Block.wood.blockID} // z = 5
},
{ // x = 3
{Block.wood.blockID}, // z = 1
{Block.wood.blockID}, // z = 2
{Block.wood.blockID}, // z = 3
{Block.wood.blockID}, // z = 4
{Block.wood.blockID} // z = 5
},
{ // x = 4
{Block.wood.blockID}, // z = 1
{Block.wood.blockID}, // z = 2
{Block.wood.blockID}, // z = 3
{Block.wood.blockID}, // z = 4
{Block.wood.blockID} // z = 5
},
{ // x = 5
{Block.wood.blockID}, // z = 1
{Block.wood.blockID}, // z = 2
{Block.wood.blockID}, // z = 3
{Block.wood.blockID}, // z = 4
{Block.wood.blockID} // z = 5
}
},
{ // y = 2
{ // x = 1
{Block.wood.blockID}, // z = 1
{Block.wood.blockID}, // z = 2
{Block.wood.blockID}, // z = 3
{Block.wood.blockID}, // z = 4
{Block.wood.blockID} // z = 5
},
{ // x = 2
{Block.wood.blockID}, // z = 1
{Block.wood.blockID}, // z = 2
{Block.wood.blockID}, // z = 3
{Block.wood.blockID}, // z = 4
{Block.wood.blockID} // z = 5
},
{ // x = 3
{Block.wood.blockID}, // z = 1
{Block.wood.blockID}, // z = 2
{Block.wood.blockID}, // z = 3
{Block.wood.blockID}, // z = 4
{Block.wood.blockID} // z = 5
},
{ // x = 4
{Block.wood.blockID}, // z = 1
{Block.wood.blockID}, // z = 2
{Block.wood.blockID}, // z = 3
{Block.wood.blockID}, // z = 4
{Block.wood.blockID} // z = 5
},
{ // x = 5
{Block.wood.blockID}, // z = 1
{Block.wood.blockID}, // z = 2
{Block.wood.blockID}, // z = 3
{Block.wood.blockID}, // z = 4
{Block.wood.blockID} // z = 5
}
},
{ // y = 3
{ // x = 1
{Block.wood.blockID}, // z = 1
{Block.wood.blockID}, // z = 2
{Block.wood.blockID}, // z = 3
{Block.wood.blockID}, // z = 4
{Block.wood.blockID} // z = 5
},
{ // x = 2
{Block.wood.blockID}, // z = 1
{Block.wood.blockID}, // z = 2
{Block.wood.blockID}, // z = 3
{Block.wood.blockID}, // z = 4
{Block.wood.blockID} // z = 5
},
{ // x = 3
{Block.wood.blockID}, // z = 1
{Block.wood.blockID}, // z = 2
{Block.wood.blockID}, // z = 3
{Block.wood.blockID}, // z = 4
{Block.wood.blockID} // z = 5
},
{ // x = 4
{Block.wood.blockID}, // z = 1
{Block.wood.blockID}, // z = 2
{Block.wood.blockID}, // z = 3
{Block.wood.blockID}, // z = 4
{Block.wood.blockID} // z = 5
},
{ // x = 5
{Block.wood.blockID}, // z = 1
{Block.wood.blockID}, // z = 2
{Block.wood.blockID}, // z = 3
{Block.wood.blockID}, // z = 4
{Block.wood.blockID} // z = 5
}
}
};
/*
You can see how the array quickly gets very long, so we're going to scrunch it
together some to save space. Later on, we may have to write it 'longhand' again
in order to more clearly see what's going on. Here's the short version:
*/
public static final int[][][][] blockArrayTutorial =
{
{ // y = 1
{ // x = 1
{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID}
},
{ // x = 2
{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID}
},
{ // x = 3
{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID}
},
{ // x = 4
{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID}
},
{ // x = 5
{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID}
}
},
{ // y = 2
{ // x = 1
{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID}
},
{ // x = 2
{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID}
},
{ // x = 3
{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID}
},
{ // x = 4
{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID}
},
{ // x = 5
{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID}
}
},
{ // y = 3
{ // x = 1
{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID}
},
{ // x = 2
{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID}
},
{ // x = 3
{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID}
},
{ // x = 4
{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID}
},
{ // x = 5
{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID}
}
}
};
/*
Use caution when condensing your arrays in this way, as it's much easier to make errors like this.
I actually recommend you keep your array in the longer format, but for the sake of space in this
tutorial, I will use the condensed version.
Ok, so we wanted to make a house, right? A house is hollow on the inside, so we just need to set
all the blocks inside to air, or id of 0. But where is inside? Easy. The first and last index of
both x and z represent the outer edges of the array, and thus are the outer edges of our structure.
So the first and last block in each z 'column' need to stay wood, as do all of the blocks at the
first and last x arrays. We need to do this for each y 'layer' as well, but we'll leave y=3 totally
solid as a roof.
*/
public static final int[][][][] blockArrayTutorial =
{
{ // y = 1
{ // x = 1
// We need an entrance to, so let's make it in the center of this column here, so at z=3
{Block.wood.blockID},{Block.wood.blockID},{0},{Block.wood.blockID},{Block.wood.blockID}
},
{ // x = 2
{Block.wood.blockID},{0},{0},{0},{Block.wood.blockID}
},
{ // x = 3
{Block.wood.blockID},{0},{0},{0},{Block.wood.blockID}
},
{ // x = 4
{Block.wood.blockID},{0},{0},{0},{Block.wood.blockID}
},
{ // x = 5
{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID}
}
},
{ // y = 2
{ // x = 1
// Don't forget to make your entrance at the same x/z location in the next layer!
// In y=1, we made a hole at x=1, z=3, so let's do the same here for a 2-block tall entrance
{Block.wood.blockID},{Block.wood.blockID},{0},{Block.wood.blockID},{Block.wood.blockID}
},
{ // x = 2
{Block.wood.blockID},{0},{0},{0},{Block.wood.blockID}
},
{ // x = 3
{Block.wood.blockID},{0},{0},{0},{Block.wood.blockID}
},
{ // x = 4
{Block.wood.blockID},{0},{0},{0},{Block.wood.blockID}
},
{ // x = 5
{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID}
}
},
{ // y = 3
{ // x = 1
{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID}
},
{ // x = 2
{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID}
},
{ // x = 3
{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID}
},
{ // x = 4
{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID}
},
{ // x = 5
{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID},{Block.wood.blockID}
}
}
};
/*
Alright, give it a try and see. Where is your entrance? Probably not in front of you. What's
going on? Well, we didn't set a default facing for our structure. Since we want x=1 (minimum
x value) to be the front of our structure, taking a glance at the StructureArrays.java
instructions tells us we need to set our default facing to WEST. In StructureGenerator where
we added our new "Tutorial" structure, you need to add one line.
*/
structure = new Structure("Tutorial");
structure.addBlockArray(StructureArrays.blockArrayTutorial);
// The following line does just what it says. Best to do it before adding the structure to the List.
structure.setFacing(StructureGeneratorBase.WEST);
structures.add(structure);
/*
Try again, your entrance should be directly in front of you when you generate the structure
no matter which way you turn.
Note that setting a structure facing is only important when you want a specific side to face
the player; if you are generating structures during world generation, it won't matter what
default facing you set, and you can even forego setting a facing altogether. I like to always
have a facing in mind, though, as it makes figuring out the correct metadata values easier.
Once you have the correct value, though, it won't matter which facing you give the structure.
*/
/*
* Step 5: Embellishments and Furnishings
*/
/*
So you've got a hollow wooden box with a hole in it large enough for Steve to walk through.
Not very exciting. In this step we'll add a door, some windows, a bed, a chest, and a torch.
First, the windows. Obviously they will replace one of the wall blocks, so change some 'wood'
blocks to 'glass'. I'd suggest doing this at your second y layer, perhaps in the center of
each wall.
Next, we need to add a door. That's a little more complicated, and will involve using metadata.
In our array, each 'z' value is actually an array of its own, though we currently only store a
single block id value in there. To add metadata, simply place a comma ',' after the block id
followed by the value: {Block.block.blockID, MetaDataValue}
Taking a look at either the Minecraft wiki 'DataValues' page or StructureArrays.java instructions,
we see: "Bottom block should have a value of 0,1,2,3 facing west, north, east, or south". Hm, well,
our door is on the front of our structure, and our structure faces west, so it would make sense for
our door to face west as well. Therefore the bottom block should have a metadata value of '0'. For
the top block, the metadata value is simply that of the bottom block plus '8'.
For the bed, we'll put it along the back wall, so it's length is along the north-south axis. Let's
put the head towards the wall, rather than in the center of the room. Refer back to the instruction
manual to see how to set metadata for beds: "0,1,2,3 facing south, west, north, east; plus 8 for head".
Our bed will be facing 'left' when we look at it from the doorway, which for a structure of facing
WEST, 'left' is to the north (and also happens to be 'left' in the array, as in z = 1). So the block
in the corner should have a meta of north+head, or 2+8 = 10. The block to it's right also needs to
face north, so we'll set it's meta to 2.
Next, we'll place a chest in the opposite corner, just to the right of the door. We want it to be
easily accessible right when you step inside, so it will face toward the entrance, which just so
happens to be the same direction our bed is facing, north. Note that chests don't use the same meta
values as beds, so go find the correct value for a chest facing 'north' and use that.
Finally, we'll place a torch to light up the inside of our little house. A nice place for this might
be opposite the chest, on the block adjacent to the door and facing inwards. Recall that our door faces
west, so the torch should face east, since it's facing the opposite direction compared to the door.
Here's a little diagram of the floor layout; your array setup should look very similar! Keep in mind
that the glass windows and torch should be at eye level, not on the ground.
W W D W W W: Wood =: Glass
W T - C W D: Door -: Air
= - - - = C: Chest
W B B - W B: Bed
W W = W W T: Torch
Fire it up and see how it looks! If a block is out of place, try placing it elsewhere in the array
until you get it right. If a block is facing the wrong way, check StructureArrays.java once again
and read up on how to set metadata for that block.
If you got everything just right, play around with it and see if you can rearrange the room. Swap the
bed with the chest, but keep the bed running along the wall. Move the torch to a different wall. Can
you figure out how to get a torch on the outside of the house?
If you tried and tried and tried but couldn't get the structure correct, I've uploaded the completed
block array to my Github Forge Tutorials page under 'supplementary' materials:
https://github.com/coolAlias/Forge_Tutorials/tree/master/supplementary
*/