WorldGenDungeons .java

net.minecraft.world.gen.feature.WorldGenDungeons (class): members: field_175918_a, CHESTCONTENT, SPAWNERTYPES, generate. strings: "Spider", "Zombie".

net.minecraft.world.gen.featureclass168 linescommonextends WorldGenerator7.3 KB

API Surface (1)

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

Fields & Constants (3)

field_175918_a
SPAWNERTYPES
CHESTCONTENT

String literals (4)

"Skeleton"
"Zombie"
"Spider"
"Failed to fetch mob spawner entity at ("

Full Source

WorldGenDungeons.java168 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.world.gen.feature;
2
3
import com.google.common.collect.Lists;
4
import java.util.List;
5
import java.util.Random;
6
import net.minecraft.block.material.Material;
7
import net.minecraft.init.Blocks;
8
import net.minecraft.init.Items;
9
import net.minecraft.tileentity.TileEntity;
10
import net.minecraft.tileentity.TileEntityChest;
11
import net.minecraft.tileentity.TileEntityMobSpawner;
12
import net.minecraft.util.BlockPos;
13
import net.minecraft.util.EnumFacing;
14
import net.minecraft.util.WeightedRandomChestContent;
15
import net.minecraft.world.World;
16
import org.apache.logging.log4j.LogManager;
17
import org.apache.logging.log4j.Logger;
18
19
public class WorldGenDungeons extends WorldGenerator
20
{
21
    private static final Logger field_175918_a = LogManager.getLogger();
22
    private static final String[] SPAWNERTYPES = new String[] {"Skeleton", "Zombie", "Zombie", "Spider"};
23
    private static final List<WeightedRandomChestContent> CHESTCONTENT = Lists.newArrayList(new WeightedRandomChestContent[] {new WeightedRandomChestContent(Items.saddle, 0, 1, 1, 10), new WeightedRandomChestContent(Items.iron_ingot, 0, 1, 4, 10), new WeightedRandomChestContent(Items.bread, 0, 1, 1, 10), new WeightedRandomChestContent(Items.wheat, 0, 1, 4, 10), new WeightedRandomChestContent(Items.gunpowder, 0, 1, 4, 10), new WeightedRandomChestContent(Items.string, 0, 1, 4, 10), new WeightedRandomChestContent(Items.bucket, 0, 1, 1, 10), new WeightedRandomChestContent(Items.golden_apple, 0, 1, 1, 1), new WeightedRandomChestContent(Items.redstone, 0, 1, 4, 10), new WeightedRandomChestContent(Items.record_13, 0, 1, 1, 4), new WeightedRandomChestContent(Items.record_cat, 0, 1, 1, 4), new WeightedRandomChestContent(Items.name_tag, 0, 1, 1, 10), new WeightedRandomChestContent(Items.golden_horse_armor, 0, 1, 1, 2), new WeightedRandomChestContent(Items.iron_horse_armor, 0, 1, 1, 5), new WeightedRandomChestContent(Items.diamond_horse_armor, 0, 1, 1, 1)});
24
25
    public boolean generate(World worldIn, Random rand, BlockPos position)
26
    {
27
        int i = 3;
28
        int j = rand.nextInt(2) + 2;
29
        int k = -j - 1;
30
        int l = j + 1;
31
        int i1 = -1;
32
        int j1 = 4;
33
        int k1 = rand.nextInt(2) + 2;
34
        int l1 = -k1 - 1;
35
        int i2 = k1 + 1;
36
        int j2 = 0;
37
38
        for (int k2 = k; k2 <= l; ++k2)
39
        {
40
            for (int l2 = -1; l2 <= 4; ++l2)
41
            {
42
                for (int i3 = l1; i3 <= i2; ++i3)
43
                {
44
                    BlockPos blockpos = position.add(k2, l2, i3);
45
                    Material material = worldIn.getBlockState(blockpos).getBlock().getMaterial();
46
                    boolean flag = material.isSolid();
47
48
                    if (l2 == -1 && !flag)
49
                    {
50
                        return false;
51
                    }
52
53
                    if (l2 == 4 && !flag)
54
                    {
55
                        return false;
56
                    }
57
58
                    if ((k2 == k || k2 == l || i3 == l1 || i3 == i2) && l2 == 0 && worldIn.isAirBlock(blockpos) && worldIn.isAirBlock(blockpos.up()))
59
                    {
60
                        ++j2;
61
                    }
62
                }
63
            }
64
        }
65
66
        if (j2 >= 1 && j2 <= 5)
67
        {
68
            for (int k3 = k; k3 <= l; ++k3)
69
            {
70
                for (int i4 = 3; i4 >= -1; --i4)
71
                {
72
                    for (int k4 = l1; k4 <= i2; ++k4)
73
                    {
74
                        BlockPos blockpos1 = position.add(k3, i4, k4);
75
76
                        if (k3 != k && i4 != -1 && k4 != l1 && k3 != l && i4 != 4 && k4 != i2)
77
                        {
78
                            if (worldIn.getBlockState(blockpos1).getBlock() != Blocks.chest)
79
                            {
80
                                worldIn.setBlockToAir(blockpos1);
81
                            }
82
                        }
83
                        else if (blockpos1.getY() >= 0 && !worldIn.getBlockState(blockpos1.down()).getBlock().getMaterial().isSolid())
84
                        {
85
                            worldIn.setBlockToAir(blockpos1);
86
                        }
87
                        else if (worldIn.getBlockState(blockpos1).getBlock().getMaterial().isSolid() && worldIn.getBlockState(blockpos1).getBlock() != Blocks.chest)
88
                        {
89
                            if (i4 == -1 && rand.nextInt(4) != 0)
90
                            {
91
                                worldIn.setBlockState(blockpos1, Blocks.mossy_cobblestone.getDefaultState(), 2);
92
                            }
93
                            else
94
                            {
95
                                worldIn.setBlockState(blockpos1, Blocks.cobblestone.getDefaultState(), 2);
96
                            }
97
                        }
98
                    }
99
                }
100
            }
101
102
            for (int l3 = 0; l3 < 2; ++l3)
103
            {
104
                for (int j4 = 0; j4 < 3; ++j4)
105
                {
106
                    int l4 = position.getX() + rand.nextInt(j * 2 + 1) - j;
107
                    int i5 = position.getY();
108
                    int j5 = position.getZ() + rand.nextInt(k1 * 2 + 1) - k1;
109
                    BlockPos blockpos2 = new BlockPos(l4, i5, j5);
110
111
                    if (worldIn.isAirBlock(blockpos2))
112
                    {
113
                        int j3 = 0;
114
115
                        for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL)
116
                        {
117
                            if (worldIn.getBlockState(blockpos2.offset(enumfacing)).getBlock().getMaterial().isSolid())
118
                            {
119
                                ++j3;
120
                            }
121
                        }
122
123
                        if (j3 == 1)
124
                        {
125
                            worldIn.setBlockState(blockpos2, Blocks.chest.correctFacing(worldIn, blockpos2, Blocks.chest.getDefaultState()), 2);
126
                            List<WeightedRandomChestContent> list = WeightedRandomChestContent.func_177629_a(CHESTCONTENT, new WeightedRandomChestContent[] {Items.enchanted_book.getRandom(rand)});
127
                            TileEntity tileentity1 = worldIn.getTileEntity(blockpos2);
128
129
                            if (tileentity1 instanceof TileEntityChest)
130
                            {
131
                                WeightedRandomChestContent.generateChestContents(rand, list, (TileEntityChest)tileentity1, 8);
132
                            }
133
134
                            break;
135
                        }
136
                    }
137
                }
138
            }
139
140
            worldIn.setBlockState(position, Blocks.mob_spawner.getDefaultState(), 2);
141
            TileEntity tileentity = worldIn.getTileEntity(position);
142
143
            if (tileentity instanceof TileEntityMobSpawner)
144
            {
145
                ((TileEntityMobSpawner)tileentity).getSpawnerBaseLogic().setEntityName(this.pickMobSpawner(rand));
146
            }
147
            else
148
            {
149
                field_175918_a.error("Failed to fetch mob spawner entity at (" + position.getX() + ", " + position.getY() + ", " + position.getZ() + ")");
150
            }
151
152
            return true;
153
        }
154
        else
155
        {
156
            return false;
157
        }
158
    }
159
160
    /**
161
     * Randomly decides which spawner to use in a dungeon
162
     */
163
    private String pickMobSpawner(Random p_76543_1_)
164
    {
165
        return SPAWNERTYPES[p_76543_1_.nextInt(SPAWNERTYPES.length)];
166
    }
167
}
168

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