StructureComponent .java

net.minecraft.world.gen.structure.StructureComponent (class): members: clearCurrentPositionBlocksUpwards, isLiquidInStructureBoundingBox, fillWithAir.

net.minecraft.world.gen.structureclass854 linescommon28.5 KB

API Surface (27)

NBTTagCompound createStructureBaseNBT()
void readStructureBaseNBT(World worldIn, NBTTagCompound tagCompound)
void buildComponent(StructureComponent componentIn, List<StructureComponent> listIn, Random rand)
StructureBoundingBox getBoundingBox()
int getComponentType()
StructureComponent findIntersecting(List<StructureComponent> listIn, StructureBoundingBox boundingboxIn)
BlockPos getBoundingBoxCenter()
boolean isLiquidInStructureBoundingBox(World worldIn, StructureBoundingBox boundingboxIn)
int getXWithOffset(int x, int z)
int getYWithOffset(int y)
int getZWithOffset(int x, int z)
int getMetadataWithOffset(Block blockIn, int meta)
void setBlockState(World worldIn, IBlockState blockstateIn, int x, int y, int z, StructureBoundingBox boundingboxIn)
IBlockState getBlockStateFromPos(World worldIn, int x, int y, int z, StructureBoundingBox boundingboxIn)
void fillWithAir(World worldIn, StructureBoundingBox structurebb, int minX, int minY, int minZ, int maxX, int maxY, int maxZ)
void fillWithBlocks(World worldIn, StructureBoundingBox boundingboxIn, int xMin, int yMin, int zMin, int xMax, int yMax, int zMax, IBlockState boundaryBlockState, IBlockState insideBlockState, boolean existingOnly)
void fillWithRandomizedBlocks(World worldIn, StructureBoundingBox boundingboxIn, int minX, int minY, int minZ, int maxX, int maxY, int maxZ, boolean alwaysReplace, Random rand, StructureComponent.BlockSelector blockselector)
void func_175805_a(World worldIn, StructureBoundingBox boundingboxIn, Random rand, float chance, int minX, int minY, int minZ, int maxX, int maxY, int maxZ, IBlockState blockstate1, IBlockState blockstate2, boolean p_175805_13_)
void randomlyPlaceBlock(World worldIn, StructureBoundingBox boundingboxIn, Random rand, float chance, int x, int y, int z, IBlockState blockstateIn)
void randomlyRareFillWithBlocks(World worldIn, StructureBoundingBox boundingboxIn, int minX, int minY, int minZ, int maxX, int maxY, int maxZ, IBlockState blockstateIn, boolean p_180777_10_)
void clearCurrentPositionBlocksUpwards(World worldIn, int x, int y, int z, StructureBoundingBox structurebb)
void replaceAirAndLiquidDownwards(World worldIn, IBlockState blockstateIn, int x, int y, int z, StructureBoundingBox boundingboxIn)
boolean generateChestContents(World worldIn, StructureBoundingBox boundingBoxIn, Random rand, int x, int y, int z, List<WeightedRandomChestContent> listIn, int max)
boolean generateDispenserContents(World worldIn, StructureBoundingBox boundingBoxIn, Random rand, int x, int y, int z, int meta, List<WeightedRandomChestContent> listIn, int max)
void placeDoorCurrentPosition(World worldIn, StructureBoundingBox boundingBoxIn, Random rand, int x, int y, int z, EnumFacing facing)
void func_181138_a(int p_181138_1_, int p_181138_2_, int p_181138_3_)
IBlockState getBlockState()

Fields & Constants (3)

boundingBox
coordBaseMode
componentType

Full Source

StructureComponent.java854 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.world.gen.structure;
2
3
import java.util.List;
4
import java.util.Random;
5
import net.minecraft.block.Block;
6
import net.minecraft.block.BlockDirectional;
7
import net.minecraft.block.BlockDoor;
8
import net.minecraft.block.material.Material;
9
import net.minecraft.block.state.IBlockState;
10
import net.minecraft.init.Blocks;
11
import net.minecraft.item.ItemDoor;
12
import net.minecraft.nbt.NBTTagCompound;
13
import net.minecraft.tileentity.TileEntity;
14
import net.minecraft.tileentity.TileEntityChest;
15
import net.minecraft.tileentity.TileEntityDispenser;
16
import net.minecraft.util.BlockPos;
17
import net.minecraft.util.EnumFacing;
18
import net.minecraft.util.WeightedRandomChestContent;
19
import net.minecraft.world.World;
20
21
public abstract class StructureComponent
22
{
23
    protected StructureBoundingBox boundingBox;
24
25
    /** switches the Coordinate System base off the Bounding Box */
26
    protected EnumFacing coordBaseMode;
27
28
    /** The type ID of this component. */
29
    protected int componentType;
30
31
    public StructureComponent()
32
    {
33
    }
34
35
    protected StructureComponent(int type)
36
    {
37
        this.componentType = type;
38
    }
39
40
    /**
41
     * Writes structure base data (id, boundingbox, {@link
42
     * net.minecraft.world.gen.structure.StructureComponent#coordBaseMode coordBase} and {@link
43
     * net.minecraft.world.gen.structure.StructureComponent#componentType componentType}) to new NBTTagCompound and
44
     * returns it.
45
     */
46
    public NBTTagCompound createStructureBaseNBT()
47
    {
48
        NBTTagCompound nbttagcompound = new NBTTagCompound();
49
        nbttagcompound.setString("id", MapGenStructureIO.getStructureComponentName(this));
50
        nbttagcompound.setTag("BB", this.boundingBox.toNBTTagIntArray());
51
        nbttagcompound.setInteger("O", this.coordBaseMode == null ? -1 : this.coordBaseMode.getHorizontalIndex());
52
        nbttagcompound.setInteger("GD", this.componentType);
53
        this.writeStructureToNBT(nbttagcompound);
54
        return nbttagcompound;
55
    }
56
57
    /**
58
     * (abstract) Helper method to write subclass data to NBT
59
     */
60
    protected abstract void writeStructureToNBT(NBTTagCompound tagCompound);
61
62
    /**
63
     * Reads and sets structure base data (boundingbox, {@link
64
     * net.minecraft.world.gen.structure.StructureComponent#coordBaseMode coordBase} and {@link
65
     * net.minecraft.world.gen.structure.StructureComponent#componentType componentType})
66
     */
67
    public void readStructureBaseNBT(World worldIn, NBTTagCompound tagCompound)
68
    {
69
        if (tagCompound.hasKey("BB"))
70
        {
71
            this.boundingBox = new StructureBoundingBox(tagCompound.getIntArray("BB"));
72
        }
73
74
        int i = tagCompound.getInteger("O");
75
        this.coordBaseMode = i == -1 ? null : EnumFacing.getHorizontal(i);
76
        this.componentType = tagCompound.getInteger("GD");
77
        this.readStructureFromNBT(tagCompound);
78
    }
79
80
    /**
81
     * (abstract) Helper method to read subclass data from NBT
82
     */
83
    protected abstract void readStructureFromNBT(NBTTagCompound tagCompound);
84
85
    /**
86
     * Initiates construction of the Structure Component picked, at the current Location of StructGen
87
     */
88
    public void buildComponent(StructureComponent componentIn, List<StructureComponent> listIn, Random rand)
89
    {
90
    }
91
92
    /**
93
     * second Part of Structure generating, this for example places Spiderwebs, Mob Spawners, it closes Mineshafts at
94
     * the end, it adds Fences...
95
     */
96
    public abstract boolean addComponentParts(World worldIn, Random randomIn, StructureBoundingBox structureBoundingBoxIn);
97
98
    public StructureBoundingBox getBoundingBox()
99
    {
100
        return this.boundingBox;
101
    }
102
103
    /**
104
     * Returns the component type ID of this component.
105
     */
106
    public int getComponentType()
107
    {
108
        return this.componentType;
109
    }
110
111
    /**
112
     * Discover if bounding box can fit within the current bounding box object.
113
     */
114
    public static StructureComponent findIntersecting(List<StructureComponent> listIn, StructureBoundingBox boundingboxIn)
115
    {
116
        for (StructureComponent structurecomponent : listIn)
117
        {
118
            if (structurecomponent.getBoundingBox() != null && structurecomponent.getBoundingBox().intersectsWith(boundingboxIn))
119
            {
120
                return structurecomponent;
121
            }
122
        }
123
124
        return null;
125
    }
126
127
    public BlockPos getBoundingBoxCenter()
128
    {
129
        return new BlockPos(this.boundingBox.getCenter());
130
    }
131
132
    /**
133
     * checks the entire StructureBoundingBox for Liquids
134
     */
135
    protected boolean isLiquidInStructureBoundingBox(World worldIn, StructureBoundingBox boundingboxIn)
136
    {
137
        int i = Math.max(this.boundingBox.minX - 1, boundingboxIn.minX);
138
        int j = Math.max(this.boundingBox.minY - 1, boundingboxIn.minY);
139
        int k = Math.max(this.boundingBox.minZ - 1, boundingboxIn.minZ);
140
        int l = Math.min(this.boundingBox.maxX + 1, boundingboxIn.maxX);
141
        int i1 = Math.min(this.boundingBox.maxY + 1, boundingboxIn.maxY);
142
        int j1 = Math.min(this.boundingBox.maxZ + 1, boundingboxIn.maxZ);
143
        BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();
144
145
        for (int k1 = i; k1 <= l; ++k1)
146
        {
147
            for (int l1 = k; l1 <= j1; ++l1)
148
            {
149
                if (worldIn.getBlockState(blockpos$mutableblockpos.set(k1, j, l1)).getBlock().getMaterial().isLiquid())
150
                {
151
                    return true;
152
                }
153
154
                if (worldIn.getBlockState(blockpos$mutableblockpos.set(k1, i1, l1)).getBlock().getMaterial().isLiquid())
155
                {
156
                    return true;
157
                }
158
            }
159
        }
160
161
        for (int i2 = i; i2 <= l; ++i2)
162
        {
163
            for (int k2 = j; k2 <= i1; ++k2)
164
            {
165
                if (worldIn.getBlockState(blockpos$mutableblockpos.set(i2, k2, k)).getBlock().getMaterial().isLiquid())
166
                {
167
                    return true;
168
                }
169
170
                if (worldIn.getBlockState(blockpos$mutableblockpos.set(i2, k2, j1)).getBlock().getMaterial().isLiquid())
171
                {
172
                    return true;
173
                }
174
            }
175
        }
176
177
        for (int j2 = k; j2 <= j1; ++j2)
178
        {
179
            for (int l2 = j; l2 <= i1; ++l2)
180
            {
181
                if (worldIn.getBlockState(blockpos$mutableblockpos.set(i, l2, j2)).getBlock().getMaterial().isLiquid())
182
                {
183
                    return true;
184
                }
185
186
                if (worldIn.getBlockState(blockpos$mutableblockpos.set(l, l2, j2)).getBlock().getMaterial().isLiquid())
187
                {
188
                    return true;
189
                }
190
            }
191
        }
192
193
        return false;
194
    }
195
196
    protected int getXWithOffset(int x, int z)
197
    {
198
        if (this.coordBaseMode == null)
199
        {
200
            return x;
201
        }
202
        else
203
        {
204
            switch (this.coordBaseMode)
205
            {
206
                case NORTH:
207
                case SOUTH:
208
                    return this.boundingBox.minX + x;
209
210
                case WEST:
211
                    return this.boundingBox.maxX - z;
212
213
                case EAST:
214
                    return this.boundingBox.minX + z;
215
216
                default:
217
                    return x;
218
            }
219
        }
220
    }
221
222
    protected int getYWithOffset(int y)
223
    {
224
        return this.coordBaseMode == null ? y : y + this.boundingBox.minY;
225
    }
226
227
    protected int getZWithOffset(int x, int z)
228
    {
229
        if (this.coordBaseMode == null)
230
        {
231
            return z;
232
        }
233
        else
234
        {
235
            switch (this.coordBaseMode)
236
            {
237
                case NORTH:
238
                    return this.boundingBox.maxZ - z;
239
240
                case SOUTH:
241
                    return this.boundingBox.minZ + z;
242
243
                case WEST:
244
                case EAST:
245
                    return this.boundingBox.minZ + x;
246
247
                default:
248
                    return z;
249
            }
250
        }
251
    }
252
253
    /**
254
     * Returns the direction-shifted metadata for blocks that require orientation, e.g. doors, stairs, ladders.
255
     */
256
    protected int getMetadataWithOffset(Block blockIn, int meta)
257
    {
258
        if (blockIn == Blocks.rail)
259
        {
260
            if (this.coordBaseMode == EnumFacing.WEST || this.coordBaseMode == EnumFacing.EAST)
261
            {
262
                if (meta == 1)
263
                {
264
                    return 0;
265
                }
266
267
                return 1;
268
            }
269
        }
270
        else if (blockIn instanceof BlockDoor)
271
        {
272
            if (this.coordBaseMode == EnumFacing.SOUTH)
273
            {
274
                if (meta == 0)
275
                {
276
                    return 2;
277
                }
278
279
                if (meta == 2)
280
                {
281
                    return 0;
282
                }
283
            }
284
            else
285
            {
286
                if (this.coordBaseMode == EnumFacing.WEST)
287
                {
288
                    return meta + 1 & 3;
289
                }
290
291
                if (this.coordBaseMode == EnumFacing.EAST)
292
                {
293
                    return meta + 3 & 3;
294
                }
295
            }
296
        }
297
        else if (blockIn != Blocks.stone_stairs && blockIn != Blocks.oak_stairs && blockIn != Blocks.nether_brick_stairs && blockIn != Blocks.stone_brick_stairs && blockIn != Blocks.sandstone_stairs)
298
        {
299
            if (blockIn == Blocks.ladder)
300
            {
301
                if (this.coordBaseMode == EnumFacing.SOUTH)
302
                {
303
                    if (meta == EnumFacing.NORTH.getIndex())
304
                    {
305
                        return EnumFacing.SOUTH.getIndex();
306
                    }
307
308
                    if (meta == EnumFacing.SOUTH.getIndex())
309
                    {
310
                        return EnumFacing.NORTH.getIndex();
311
                    }
312
                }
313
                else if (this.coordBaseMode == EnumFacing.WEST)
314
                {
315
                    if (meta == EnumFacing.NORTH.getIndex())
316
                    {
317
                        return EnumFacing.WEST.getIndex();
318
                    }
319
320
                    if (meta == EnumFacing.SOUTH.getIndex())
321
                    {
322
                        return EnumFacing.EAST.getIndex();
323
                    }
324
325
                    if (meta == EnumFacing.WEST.getIndex())
326
                    {
327
                        return EnumFacing.NORTH.getIndex();
328
                    }
329
330
                    if (meta == EnumFacing.EAST.getIndex())
331
                    {
332
                        return EnumFacing.SOUTH.getIndex();
333
                    }
334
                }
335
                else if (this.coordBaseMode == EnumFacing.EAST)
336
                {
337
                    if (meta == EnumFacing.NORTH.getIndex())
338
                    {
339
                        return EnumFacing.EAST.getIndex();
340
                    }
341
342
                    if (meta == EnumFacing.SOUTH.getIndex())
343
                    {
344
                        return EnumFacing.WEST.getIndex();
345
                    }
346
347
                    if (meta == EnumFacing.WEST.getIndex())
348
                    {
349
                        return EnumFacing.NORTH.getIndex();
350
                    }
351
352
                    if (meta == EnumFacing.EAST.getIndex())
353
                    {
354
                        return EnumFacing.SOUTH.getIndex();
355
                    }
356
                }
357
            }
358
            else if (blockIn == Blocks.stone_button)
359
            {
360
                if (this.coordBaseMode == EnumFacing.SOUTH)
361
                {
362
                    if (meta == 3)
363
                    {
364
                        return 4;
365
                    }
366
367
                    if (meta == 4)
368
                    {
369
                        return 3;
370
                    }
371
                }
372
                else if (this.coordBaseMode == EnumFacing.WEST)
373
                {
374
                    if (meta == 3)
375
                    {
376
                        return 1;
377
                    }
378
379
                    if (meta == 4)
380
                    {
381
                        return 2;
382
                    }
383
384
                    if (meta == 2)
385
                    {
386
                        return 3;
387
                    }
388
389
                    if (meta == 1)
390
                    {
391
                        return 4;
392
                    }
393
                }
394
                else if (this.coordBaseMode == EnumFacing.EAST)
395
                {
396
                    if (meta == 3)
397
                    {
398
                        return 2;
399
                    }
400
401
                    if (meta == 4)
402
                    {
403
                        return 1;
404
                    }
405
406
                    if (meta == 2)
407
                    {
408
                        return 3;
409
                    }
410
411
                    if (meta == 1)
412
                    {
413
                        return 4;
414
                    }
415
                }
416
            }
417
            else if (blockIn != Blocks.tripwire_hook && !(blockIn instanceof BlockDirectional))
418
            {
419
                if (blockIn == Blocks.piston || blockIn == Blocks.sticky_piston || blockIn == Blocks.lever || blockIn == Blocks.dispenser)
420
                {
421
                    if (this.coordBaseMode == EnumFacing.SOUTH)
422
                    {
423
                        if (meta == EnumFacing.NORTH.getIndex() || meta == EnumFacing.SOUTH.getIndex())
424
                        {
425
                            return EnumFacing.getFront(meta).getOpposite().getIndex();
426
                        }
427
                    }
428
                    else if (this.coordBaseMode == EnumFacing.WEST)
429
                    {
430
                        if (meta == EnumFacing.NORTH.getIndex())
431
                        {
432
                            return EnumFacing.WEST.getIndex();
433
                        }
434
435
                        if (meta == EnumFacing.SOUTH.getIndex())
436
                        {
437
                            return EnumFacing.EAST.getIndex();
438
                        }
439
440
                        if (meta == EnumFacing.WEST.getIndex())
441
                        {
442
                            return EnumFacing.NORTH.getIndex();
443
                        }
444
445
                        if (meta == EnumFacing.EAST.getIndex())
446
                        {
447
                            return EnumFacing.SOUTH.getIndex();
448
                        }
449
                    }
450
                    else if (this.coordBaseMode == EnumFacing.EAST)
451
                    {
452
                        if (meta == EnumFacing.NORTH.getIndex())
453
                        {
454
                            return EnumFacing.EAST.getIndex();
455
                        }
456
457
                        if (meta == EnumFacing.SOUTH.getIndex())
458
                        {
459
                            return EnumFacing.WEST.getIndex();
460
                        }
461
462
                        if (meta == EnumFacing.WEST.getIndex())
463
                        {
464
                            return EnumFacing.NORTH.getIndex();
465
                        }
466
467
                        if (meta == EnumFacing.EAST.getIndex())
468
                        {
469
                            return EnumFacing.SOUTH.getIndex();
470
                        }
471
                    }
472
                }
473
            }
474
            else
475
            {
476
                EnumFacing enumfacing = EnumFacing.getHorizontal(meta);
477
478
                if (this.coordBaseMode == EnumFacing.SOUTH)
479
                {
480
                    if (enumfacing == EnumFacing.SOUTH || enumfacing == EnumFacing.NORTH)
481
                    {
482
                        return enumfacing.getOpposite().getHorizontalIndex();
483
                    }
484
                }
485
                else if (this.coordBaseMode == EnumFacing.WEST)
486
                {
487
                    if (enumfacing == EnumFacing.NORTH)
488
                    {
489
                        return EnumFacing.WEST.getHorizontalIndex();
490
                    }
491
492
                    if (enumfacing == EnumFacing.SOUTH)
493
                    {
494
                        return EnumFacing.EAST.getHorizontalIndex();
495
                    }
496
497
                    if (enumfacing == EnumFacing.WEST)
498
                    {
499
                        return EnumFacing.NORTH.getHorizontalIndex();
500
                    }
501
502
                    if (enumfacing == EnumFacing.EAST)
503
                    {
504
                        return EnumFacing.SOUTH.getHorizontalIndex();
505
                    }
506
                }
507
                else if (this.coordBaseMode == EnumFacing.EAST)
508
                {
509
                    if (enumfacing == EnumFacing.NORTH)
510
                    {
511
                        return EnumFacing.EAST.getHorizontalIndex();
512
                    }
513
514
                    if (enumfacing == EnumFacing.SOUTH)
515
                    {
516
                        return EnumFacing.WEST.getHorizontalIndex();
517
                    }
518
519
                    if (enumfacing == EnumFacing.WEST)
520
                    {
521
                        return EnumFacing.NORTH.getHorizontalIndex();
522
                    }
523
524
                    if (enumfacing == EnumFacing.EAST)
525
                    {
526
                        return EnumFacing.SOUTH.getHorizontalIndex();
527
                    }
528
                }
529
            }
530
        }
531
        else if (this.coordBaseMode == EnumFacing.SOUTH)
532
        {
533
            if (meta == 2)
534
            {
535
                return 3;
536
            }
537
538
            if (meta == 3)
539
            {
540
                return 2;
541
            }
542
        }
543
        else if (this.coordBaseMode == EnumFacing.WEST)
544
        {
545
            if (meta == 0)
546
            {
547
                return 2;
548
            }
549
550
            if (meta == 1)
551
            {
552
                return 3;
553
            }
554
555
            if (meta == 2)
556
            {
557
                return 0;
558
            }
559
560
            if (meta == 3)
561
            {
562
                return 1;
563
            }
564
        }
565
        else if (this.coordBaseMode == EnumFacing.EAST)
566
        {
567
            if (meta == 0)
568
            {
569
                return 2;
570
            }
571
572
            if (meta == 1)
573
            {
574
                return 3;
575
            }
576
577
            if (meta == 2)
578
            {
579
                return 1;
580
            }
581
582
            if (meta == 3)
583
            {
584
                return 0;
585
            }
586
        }
587
588
        return meta;
589
    }
590
591
    protected void setBlockState(World worldIn, IBlockState blockstateIn, int x, int y, int z, StructureBoundingBox boundingboxIn)
592
    {
593
        BlockPos blockpos = new BlockPos(this.getXWithOffset(x, z), this.getYWithOffset(y), this.getZWithOffset(x, z));
594
595
        if (boundingboxIn.isVecInside(blockpos))
596
        {
597
            worldIn.setBlockState(blockpos, blockstateIn, 2);
598
        }
599
    }
600
601
    protected IBlockState getBlockStateFromPos(World worldIn, int x, int y, int z, StructureBoundingBox boundingboxIn)
602
    {
603
        int i = this.getXWithOffset(x, z);
604
        int j = this.getYWithOffset(y);
605
        int k = this.getZWithOffset(x, z);
606
        BlockPos blockpos = new BlockPos(i, j, k);
607
        return !boundingboxIn.isVecInside(blockpos) ? Blocks.air.getDefaultState() : worldIn.getBlockState(blockpos);
608
    }
609
610
    /**
611
     * arguments: (World worldObj, StructureBoundingBox structBB, int minX, int minY, int minZ, int maxX, int maxY, int
612
     * maxZ)
613
     */
614
    protected void fillWithAir(World worldIn, StructureBoundingBox structurebb, int minX, int minY, int minZ, int maxX, int maxY, int maxZ)
615
    {
616
        for (int i = minY; i <= maxY; ++i)
617
        {
618
            for (int j = minX; j <= maxX; ++j)
619
            {
620
                for (int k = minZ; k <= maxZ; ++k)
621
                {
622
                    this.setBlockState(worldIn, Blocks.air.getDefaultState(), j, i, k, structurebb);
623
                }
624
            }
625
        }
626
    }
627
628
    /**
629
     * Fill the given area with the selected blocks
630
     */
631
    protected void fillWithBlocks(World worldIn, StructureBoundingBox boundingboxIn, int xMin, int yMin, int zMin, int xMax, int yMax, int zMax, IBlockState boundaryBlockState, IBlockState insideBlockState, boolean existingOnly)
632
    {
633
        for (int i = yMin; i <= yMax; ++i)
634
        {
635
            for (int j = xMin; j <= xMax; ++j)
636
            {
637
                for (int k = zMin; k <= zMax; ++k)
638
                {
639
                    if (!existingOnly || this.getBlockStateFromPos(worldIn, j, i, k, boundingboxIn).getBlock().getMaterial() != Material.air)
640
                    {
641
                        if (i != yMin && i != yMax && j != xMin && j != xMax && k != zMin && k != zMax)
642
                        {
643
                            this.setBlockState(worldIn, insideBlockState, j, i, k, boundingboxIn);
644
                        }
645
                        else
646
                        {
647
                            this.setBlockState(worldIn, boundaryBlockState, j, i, k, boundingboxIn);
648
                        }
649
                    }
650
                }
651
            }
652
        }
653
    }
654
655
    /**
656
     * arguments: World worldObj, StructureBoundingBox structBB, int minX, int minY, int minZ, int maxX, int maxY, int
657
     * maxZ, boolean alwaysreplace, Random rand, StructurePieceBlockSelector blockselector
658
     */
659
    protected void fillWithRandomizedBlocks(World worldIn, StructureBoundingBox boundingboxIn, int minX, int minY, int minZ, int maxX, int maxY, int maxZ, boolean alwaysReplace, Random rand, StructureComponent.BlockSelector blockselector)
660
    {
661
        for (int i = minY; i <= maxY; ++i)
662
        {
663
            for (int j = minX; j <= maxX; ++j)
664
            {
665
                for (int k = minZ; k <= maxZ; ++k)
666
                {
667
                    if (!alwaysReplace || this.getBlockStateFromPos(worldIn, j, i, k, boundingboxIn).getBlock().getMaterial() != Material.air)
668
                    {
669
                        blockselector.selectBlocks(rand, j, i, k, i == minY || i == maxY || j == minX || j == maxX || k == minZ || k == maxZ);
670
                        this.setBlockState(worldIn, blockselector.getBlockState(), j, i, k, boundingboxIn);
671
                    }
672
                }
673
            }
674
        }
675
    }
676
677
    protected void func_175805_a(World worldIn, StructureBoundingBox boundingboxIn, Random rand, float chance, int minX, int minY, int minZ, int maxX, int maxY, int maxZ, IBlockState blockstate1, IBlockState blockstate2, boolean p_175805_13_)
678
    {
679
        for (int i = minY; i <= maxY; ++i)
680
        {
681
            for (int j = minX; j <= maxX; ++j)
682
            {
683
                for (int k = minZ; k <= maxZ; ++k)
684
                {
685
                    if (rand.nextFloat() <= chance && (!p_175805_13_ || this.getBlockStateFromPos(worldIn, j, i, k, boundingboxIn).getBlock().getMaterial() != Material.air))
686
                    {
687
                        if (i != minY && i != maxY && j != minX && j != maxX && k != minZ && k != maxZ)
688
                        {
689
                            this.setBlockState(worldIn, blockstate2, j, i, k, boundingboxIn);
690
                        }
691
                        else
692
                        {
693
                            this.setBlockState(worldIn, blockstate1, j, i, k, boundingboxIn);
694
                        }
695
                    }
696
                }
697
            }
698
        }
699
    }
700
701
    protected void randomlyPlaceBlock(World worldIn, StructureBoundingBox boundingboxIn, Random rand, float chance, int x, int y, int z, IBlockState blockstateIn)
702
    {
703
        if (rand.nextFloat() < chance)
704
        {
705
            this.setBlockState(worldIn, blockstateIn, x, y, z, boundingboxIn);
706
        }
707
    }
708
709
    protected void randomlyRareFillWithBlocks(World worldIn, StructureBoundingBox boundingboxIn, int minX, int minY, int minZ, int maxX, int maxY, int maxZ, IBlockState blockstateIn, boolean p_180777_10_)
710
    {
711
        float f = (float)(maxX - minX + 1);
712
        float f1 = (float)(maxY - minY + 1);
713
        float f2 = (float)(maxZ - minZ + 1);
714
        float f3 = (float)minX + f / 2.0F;
715
        float f4 = (float)minZ + f2 / 2.0F;
716
717
        for (int i = minY; i <= maxY; ++i)
718
        {
719
            float f5 = (float)(i - minY) / f1;
720
721
            for (int j = minX; j <= maxX; ++j)
722
            {
723
                float f6 = ((float)j - f3) / (f * 0.5F);
724
725
                for (int k = minZ; k <= maxZ; ++k)
726
                {
727
                    float f7 = ((float)k - f4) / (f2 * 0.5F);
728
729
                    if (!p_180777_10_ || this.getBlockStateFromPos(worldIn, j, i, k, boundingboxIn).getBlock().getMaterial() != Material.air)
730
                    {
731
                        float f8 = f6 * f6 + f5 * f5 + f7 * f7;
732
733
                        if (f8 <= 1.05F)
734
                        {
735
                            this.setBlockState(worldIn, blockstateIn, j, i, k, boundingboxIn);
736
                        }
737
                    }
738
                }
739
            }
740
        }
741
    }
742
743
    /**
744
     * Deletes all continuous blocks from selected position upwards. Stops at hitting air.
745
     */
746
    protected void clearCurrentPositionBlocksUpwards(World worldIn, int x, int y, int z, StructureBoundingBox structurebb)
747
    {
748
        BlockPos blockpos = new BlockPos(this.getXWithOffset(x, z), this.getYWithOffset(y), this.getZWithOffset(x, z));
749
750
        if (structurebb.isVecInside(blockpos))
751
        {
752
            while (!worldIn.isAirBlock(blockpos) && blockpos.getY() < 255)
753
            {
754
                worldIn.setBlockState(blockpos, Blocks.air.getDefaultState(), 2);
755
                blockpos = blockpos.up();
756
            }
757
        }
758
    }
759
760
    /**
761
     * Replaces air and liquid from given position downwards. Stops when hitting anything else than air or liquid
762
     */
763
    protected void replaceAirAndLiquidDownwards(World worldIn, IBlockState blockstateIn, int x, int y, int z, StructureBoundingBox boundingboxIn)
764
    {
765
        int i = this.getXWithOffset(x, z);
766
        int j = this.getYWithOffset(y);
767
        int k = this.getZWithOffset(x, z);
768
769
        if (boundingboxIn.isVecInside(new BlockPos(i, j, k)))
770
        {
771
            while ((worldIn.isAirBlock(new BlockPos(i, j, k)) || worldIn.getBlockState(new BlockPos(i, j, k)).getBlock().getMaterial().isLiquid()) && j > 1)
772
            {
773
                worldIn.setBlockState(new BlockPos(i, j, k), blockstateIn, 2);
774
                --j;
775
            }
776
        }
777
    }
778
779
    protected boolean generateChestContents(World worldIn, StructureBoundingBox boundingBoxIn, Random rand, int x, int y, int z, List<WeightedRandomChestContent> listIn, int max)
780
    {
781
        BlockPos blockpos = new BlockPos(this.getXWithOffset(x, z), this.getYWithOffset(y), this.getZWithOffset(x, z));
782
783
        if (boundingBoxIn.isVecInside(blockpos) && worldIn.getBlockState(blockpos).getBlock() != Blocks.chest)
784
        {
785
            IBlockState iblockstate = Blocks.chest.getDefaultState();
786
            worldIn.setBlockState(blockpos, Blocks.chest.correctFacing(worldIn, blockpos, iblockstate), 2);
787
            TileEntity tileentity = worldIn.getTileEntity(blockpos);
788
789
            if (tileentity instanceof TileEntityChest)
790
            {
791
                WeightedRandomChestContent.generateChestContents(rand, listIn, (TileEntityChest)tileentity, max);
792
            }
793
794
            return true;
795
        }
796
        else
797
        {
798
            return false;
799
        }
800
    }
801
802
    protected boolean generateDispenserContents(World worldIn, StructureBoundingBox boundingBoxIn, Random rand, int x, int y, int z, int meta, List<WeightedRandomChestContent> listIn, int max)
803
    {
804
        BlockPos blockpos = new BlockPos(this.getXWithOffset(x, z), this.getYWithOffset(y), this.getZWithOffset(x, z));
805
806
        if (boundingBoxIn.isVecInside(blockpos) && worldIn.getBlockState(blockpos).getBlock() != Blocks.dispenser)
807
        {
808
            worldIn.setBlockState(blockpos, Blocks.dispenser.getStateFromMeta(this.getMetadataWithOffset(Blocks.dispenser, meta)), 2);
809
            TileEntity tileentity = worldIn.getTileEntity(blockpos);
810
811
            if (tileentity instanceof TileEntityDispenser)
812
            {
813
                WeightedRandomChestContent.generateDispenserContents(rand, listIn, (TileEntityDispenser)tileentity, max);
814
            }
815
816
            return true;
817
        }
818
        else
819
        {
820
            return false;
821
        }
822
    }
823
824
    /**
825
     * Places door on given position
826
     */
827
    protected void placeDoorCurrentPosition(World worldIn, StructureBoundingBox boundingBoxIn, Random rand, int x, int y, int z, EnumFacing facing)
828
    {
829
        BlockPos blockpos = new BlockPos(this.getXWithOffset(x, z), this.getYWithOffset(y), this.getZWithOffset(x, z));
830
831
        if (boundingBoxIn.isVecInside(blockpos))
832
        {
833
            ItemDoor.placeDoor(worldIn, blockpos, facing.rotateYCCW(), Blocks.oak_door);
834
        }
835
    }
836
837
    public void func_181138_a(int p_181138_1_, int p_181138_2_, int p_181138_3_)
838
    {
839
        this.boundingBox.offset(p_181138_1_, p_181138_2_, p_181138_3_);
840
    }
841
842
    public abstract static class BlockSelector
843
    {
844
        protected IBlockState blockstate = Blocks.air.getDefaultState();
845
846
        public abstract void selectBlocks(Random rand, int x, int y, int z, boolean p_75062_5_);
847
848
        public IBlockState getBlockState()
849
        {
850
            return this.blockstate;
851
        }
852
    }
853
}
854

Deobfuscated MCP 1.8.9 source of StructureComponent from Marcelektro/MavenMCP-1.8.9 (net/minecraft/world/gen/structure/StructureComponent.java), stored verbatim.