WorldGeneratorBonusChest .java

net.minecraft.world.gen.feature.WorldGeneratorBonusChest (class, 93 lines): members: itemsToGenerateInBonusChest, chestItems, generate. imports: Block.

net.minecraft.world.gen.featureclass93 linescommonextends WorldGenerator3.5 KB

API Surface (1)

boolean generate(World worldIn, Random rand, BlockPos position)

Fields & Constants (2)

chestItems
itemsToGenerateInBonusChest

Full Source

WorldGeneratorBonusChest.java93 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.world.gen.feature;
2
3
import java.util.List;
4
import java.util.Random;
5
import net.minecraft.block.Block;
6
import net.minecraft.block.material.Material;
7
import net.minecraft.init.Blocks;
8
import net.minecraft.tileentity.TileEntity;
9
import net.minecraft.tileentity.TileEntityChest;
10
import net.minecraft.util.BlockPos;
11
import net.minecraft.util.WeightedRandomChestContent;
12
import net.minecraft.world.World;
13
14
public class WorldGeneratorBonusChest extends WorldGenerator
15
{
16
    private final List<WeightedRandomChestContent> chestItems;
17
18
    /**
19
     * Value of this int will determine how much items gonna generate in Bonus Chest.
20
     */
21
    private final int itemsToGenerateInBonusChest;
22
23
    public WorldGeneratorBonusChest(List<WeightedRandomChestContent> p_i45634_1_, int p_i45634_2_)
24
    {
25
        this.chestItems = p_i45634_1_;
26
        this.itemsToGenerateInBonusChest = p_i45634_2_;
27
    }
28
29
    public boolean generate(World worldIn, Random rand, BlockPos position)
30
    {
31
        Block block;
32
33
        while (((block = worldIn.getBlockState(position).getBlock()).getMaterial() == Material.air || block.getMaterial() == Material.leaves) && position.getY() > 1)
34
        {
35
            position = position.down();
36
        }
37
38
        if (position.getY() < 1)
39
        {
40
            return false;
41
        }
42
        else
43
        {
44
            position = position.up();
45
46
            for (int i = 0; i < 4; ++i)
47
            {
48
                BlockPos blockpos = position.add(rand.nextInt(4) - rand.nextInt(4), rand.nextInt(3) - rand.nextInt(3), rand.nextInt(4) - rand.nextInt(4));
49
50
                if (worldIn.isAirBlock(blockpos) && World.doesBlockHaveSolidTopSurface(worldIn, blockpos.down()))
51
                {
52
                    worldIn.setBlockState(blockpos, Blocks.chest.getDefaultState(), 2);
53
                    TileEntity tileentity = worldIn.getTileEntity(blockpos);
54
55
                    if (tileentity instanceof TileEntityChest)
56
                    {
57
                        WeightedRandomChestContent.generateChestContents(rand, this.chestItems, (TileEntityChest)tileentity, this.itemsToGenerateInBonusChest);
58
                    }
59
60
                    BlockPos blockpos1 = blockpos.east();
61
                    BlockPos blockpos2 = blockpos.west();
62
                    BlockPos blockpos3 = blockpos.north();
63
                    BlockPos blockpos4 = blockpos.south();
64
65
                    if (worldIn.isAirBlock(blockpos2) && World.doesBlockHaveSolidTopSurface(worldIn, blockpos2.down()))
66
                    {
67
                        worldIn.setBlockState(blockpos2, Blocks.torch.getDefaultState(), 2);
68
                    }
69
70
                    if (worldIn.isAirBlock(blockpos1) && World.doesBlockHaveSolidTopSurface(worldIn, blockpos1.down()))
71
                    {
72
                        worldIn.setBlockState(blockpos1, Blocks.torch.getDefaultState(), 2);
73
                    }
74
75
                    if (worldIn.isAirBlock(blockpos3) && World.doesBlockHaveSolidTopSurface(worldIn, blockpos3.down()))
76
                    {
77
                        worldIn.setBlockState(blockpos3, Blocks.torch.getDefaultState(), 2);
78
                    }
79
80
                    if (worldIn.isAirBlock(blockpos4) && World.doesBlockHaveSolidTopSurface(worldIn, blockpos4.down()))
81
                    {
82
                        worldIn.setBlockState(blockpos4, Blocks.torch.getDefaultState(), 2);
83
                    }
84
85
                    return true;
86
                }
87
            }
88
89
            return false;
90
        }
91
    }
92
}
93

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