StructureStart .java

net.minecraft.world.gen.structure.StructureStart (class, 188 lines): members: readStructureComponentsFromNBT, writeStructureComponentsToNBT, func_175787_b.

net.minecraft.world.gen.structureclass188 linescommon5.1 KB

API Surface (15)

StructureBoundingBox getBoundingBox()
LinkedList<StructureComponent> getComponents()
void generateStructure(World worldIn, Random rand, StructureBoundingBox structurebb)
void updateBoundingBox()
NBTTagCompound writeStructureComponentsToNBT(int chunkX, int chunkZ)
void writeToNBT(NBTTagCompound tagCompound)
void readStructureComponentsFromNBT(World worldIn, NBTTagCompound tagCompound)
void readFromNBT(NBTTagCompound tagCompound)
void markAvailableHeight(World worldIn, Random rand, int p_75067_3_)
void setRandomHeight(World worldIn, Random rand, int p_75070_3_, int p_75070_4_)
boolean isSizeableStructure()
boolean func_175788_a(ChunkCoordIntPair pair)
void func_175787_b(ChunkCoordIntPair pair)
int getChunkPosX()
int getChunkPosZ()

Fields & Constants (4)

components
boundingBox
chunkPosX
chunkPosZ

String literals (3)

"ChunkX"
"ChunkZ"
"Children"

Full Source

StructureStart.java188 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.world.gen.structure;
2
3
import java.util.Iterator;
4
import java.util.LinkedList;
5
import java.util.Random;
6
import net.minecraft.nbt.NBTTagCompound;
7
import net.minecraft.nbt.NBTTagList;
8
import net.minecraft.world.ChunkCoordIntPair;
9
import net.minecraft.world.World;
10
11
public abstract class StructureStart
12
{
13
    protected LinkedList<StructureComponent> components = new LinkedList();
14
    protected StructureBoundingBox boundingBox;
15
    private int chunkPosX;
16
    private int chunkPosZ;
17
18
    public StructureStart()
19
    {
20
    }
21
22
    public StructureStart(int chunkX, int chunkZ)
23
    {
24
        this.chunkPosX = chunkX;
25
        this.chunkPosZ = chunkZ;
26
    }
27
28
    public StructureBoundingBox getBoundingBox()
29
    {
30
        return this.boundingBox;
31
    }
32
33
    public LinkedList<StructureComponent> getComponents()
34
    {
35
        return this.components;
36
    }
37
38
    /**
39
     * Keeps iterating Structure Pieces and spawning them until the checks tell it to stop
40
     */
41
    public void generateStructure(World worldIn, Random rand, StructureBoundingBox structurebb)
42
    {
43
        Iterator<StructureComponent> iterator = this.components.iterator();
44
45
        while (iterator.hasNext())
46
        {
47
            StructureComponent structurecomponent = (StructureComponent)iterator.next();
48
49
            if (structurecomponent.getBoundingBox().intersectsWith(structurebb) && !structurecomponent.addComponentParts(worldIn, rand, structurebb))
50
            {
51
                iterator.remove();
52
            }
53
        }
54
    }
55
56
    /**
57
     * Calculates total bounding box based on components' bounding boxes and saves it to boundingBox
58
     */
59
    protected void updateBoundingBox()
60
    {
61
        this.boundingBox = StructureBoundingBox.getNewBoundingBox();
62
63
        for (StructureComponent structurecomponent : this.components)
64
        {
65
            this.boundingBox.expandTo(structurecomponent.getBoundingBox());
66
        }
67
    }
68
69
    public NBTTagCompound writeStructureComponentsToNBT(int chunkX, int chunkZ)
70
    {
71
        NBTTagCompound nbttagcompound = new NBTTagCompound();
72
        nbttagcompound.setString("id", MapGenStructureIO.getStructureStartName(this));
73
        nbttagcompound.setInteger("ChunkX", chunkX);
74
        nbttagcompound.setInteger("ChunkZ", chunkZ);
75
        nbttagcompound.setTag("BB", this.boundingBox.toNBTTagIntArray());
76
        NBTTagList nbttaglist = new NBTTagList();
77
78
        for (StructureComponent structurecomponent : this.components)
79
        {
80
            nbttaglist.appendTag(structurecomponent.createStructureBaseNBT());
81
        }
82
83
        nbttagcompound.setTag("Children", nbttaglist);
84
        this.writeToNBT(nbttagcompound);
85
        return nbttagcompound;
86
    }
87
88
    public void writeToNBT(NBTTagCompound tagCompound)
89
    {
90
    }
91
92
    public void readStructureComponentsFromNBT(World worldIn, NBTTagCompound tagCompound)
93
    {
94
        this.chunkPosX = tagCompound.getInteger("ChunkX");
95
        this.chunkPosZ = tagCompound.getInteger("ChunkZ");
96
97
        if (tagCompound.hasKey("BB"))
98
        {
99
            this.boundingBox = new StructureBoundingBox(tagCompound.getIntArray("BB"));
100
        }
101
102
        NBTTagList nbttaglist = tagCompound.getTagList("Children", 10);
103
104
        for (int i = 0; i < nbttaglist.tagCount(); ++i)
105
        {
106
            this.components.add(MapGenStructureIO.getStructureComponent(nbttaglist.getCompoundTagAt(i), worldIn));
107
        }
108
109
        this.readFromNBT(tagCompound);
110
    }
111
112
    public void readFromNBT(NBTTagCompound tagCompound)
113
    {
114
    }
115
116
    /**
117
     * offsets the structure Bounding Boxes up to a certain height, typically 63 - 10
118
     */
119
    protected void markAvailableHeight(World worldIn, Random rand, int p_75067_3_)
120
    {
121
        int i = worldIn.getSeaLevel() - p_75067_3_;
122
        int j = this.boundingBox.getYSize() + 1;
123
124
        if (j < i)
125
        {
126
            j += rand.nextInt(i - j);
127
        }
128
129
        int k = j - this.boundingBox.maxY;
130
        this.boundingBox.offset(0, k, 0);
131
132
        for (StructureComponent structurecomponent : this.components)
133
        {
134
            structurecomponent.func_181138_a(0, k, 0);
135
        }
136
    }
137
138
    protected void setRandomHeight(World worldIn, Random rand, int p_75070_3_, int p_75070_4_)
139
    {
140
        int i = p_75070_4_ - p_75070_3_ + 1 - this.boundingBox.getYSize();
141
        int j = 1;
142
143
        if (i > 1)
144
        {
145
            j = p_75070_3_ + rand.nextInt(i);
146
        }
147
        else
148
        {
149
            j = p_75070_3_;
150
        }
151
152
        int k = j - this.boundingBox.minY;
153
        this.boundingBox.offset(0, k, 0);
154
155
        for (StructureComponent structurecomponent : this.components)
156
        {
157
            structurecomponent.func_181138_a(0, k, 0);
158
        }
159
    }
160
161
    /**
162
     * currently only defined for Villages, returns true if Village has more than 2 non-road components
163
     */
164
    public boolean isSizeableStructure()
165
    {
166
        return true;
167
    }
168
169
    public boolean func_175788_a(ChunkCoordIntPair pair)
170
    {
171
        return true;
172
    }
173
174
    public void func_175787_b(ChunkCoordIntPair pair)
175
    {
176
    }
177
178
    public int getChunkPosX()
179
    {
180
        return this.chunkPosX;
181
    }
182
183
    public int getChunkPosZ()
184
    {
185
        return this.chunkPosZ;
186
    }
187
}
188

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