WorldProvider .java

net.minecraft.world.WorldProvider (class): members: getLightBrightnessTable, getProviderForDimension, lightBrightnessTable, colorsSunriseSunset, hasNoSky.

net.minecraft.worldclass284 linescommon8.6 KB

API Surface (24)

void registerWorld(World worldIn)
void generateLightBrightnessTable()
void registerWorldChunkManager()
IChunkProvider createChunkGenerator()
boolean canCoordinateBeSpawn(int x, int z)
float calculateCelestialAngle(long worldTime, float partialTicks)
int getMoonPhase(long worldTime)
boolean isSurfaceWorld()
float[] calcSunriseSunsetColors(float celestialAngle, float partialTicks)
Vec3 getFogColor(float p_76562_1_, float p_76562_2_)
boolean canRespawnHere()
WorldProvider getProviderForDimension(int dimension)
float getCloudHeight()
boolean isSkyColored()
BlockPos getSpawnCoordinate()
int getAverageGroundLevel()
double getVoidFogYFactor()
boolean doesXZShowFog(int x, int z)
WorldChunkManager getWorldChunkManager()
boolean doesWaterVaporize()
boolean getHasNoSky()
float[] getLightBrightnessTable()
int getDimensionId()
WorldBorder getWorldBorder()

Fields & Constants (10)

moonPhaseFactors
worldObj
terrainType
generatorSettings
worldChunkMgr
isHellWorld
hasNoSky
lightBrightnessTable
dimensionId
colorsSunriseSunset

Full Source

WorldProvider.java284 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.world;
2
3
import net.minecraft.init.Blocks;
4
import net.minecraft.util.BlockPos;
5
import net.minecraft.util.MathHelper;
6
import net.minecraft.util.Vec3;
7
import net.minecraft.world.biome.BiomeGenBase;
8
import net.minecraft.world.biome.WorldChunkManager;
9
import net.minecraft.world.biome.WorldChunkManagerHell;
10
import net.minecraft.world.border.WorldBorder;
11
import net.minecraft.world.chunk.IChunkProvider;
12
import net.minecraft.world.gen.ChunkProviderDebug;
13
import net.minecraft.world.gen.ChunkProviderFlat;
14
import net.minecraft.world.gen.ChunkProviderGenerate;
15
import net.minecraft.world.gen.FlatGeneratorInfo;
16
17
public abstract class WorldProvider
18
{
19
    public static final float[] moonPhaseFactors = new float[] {1.0F, 0.75F, 0.5F, 0.25F, 0.0F, 0.25F, 0.5F, 0.75F};
20
21
    /** world object being used */
22
    protected World worldObj;
23
    private WorldType terrainType;
24
    private String generatorSettings;
25
26
    /** World chunk manager being used to generate chunks */
27
    protected WorldChunkManager worldChunkMgr;
28
29
    /**
30
     * States whether the Hell world provider is used(true) or if the normal world provider is used(false)
31
     */
32
    protected boolean isHellWorld;
33
34
    /**
35
     * A boolean that tells if a world does not have a sky. Used in calculating weather and skylight
36
     */
37
    protected boolean hasNoSky;
38
39
    /** Light to brightness conversion table */
40
    protected final float[] lightBrightnessTable = new float[16];
41
42
    /** The id for the dimension (ex. -1: Nether, 0: Overworld, 1: The End) */
43
    protected int dimensionId;
44
45
    /** Array for sunrise/sunset colors (RGBA) */
46
    private final float[] colorsSunriseSunset = new float[4];
47
48
    /**
49
     * associate an existing world with a World provider, and setup its lightbrightness table
50
     */
51
    public final void registerWorld(World worldIn)
52
    {
53
        this.worldObj = worldIn;
54
        this.terrainType = worldIn.getWorldInfo().getTerrainType();
55
        this.generatorSettings = worldIn.getWorldInfo().getGeneratorOptions();
56
        this.registerWorldChunkManager();
57
        this.generateLightBrightnessTable();
58
    }
59
60
    /**
61
     * Creates the light to brightness table
62
     */
63
    protected void generateLightBrightnessTable()
64
    {
65
        float f = 0.0F;
66
67
        for (int i = 0; i <= 15; ++i)
68
        {
69
            float f1 = 1.0F - (float)i / 15.0F;
70
            this.lightBrightnessTable[i] = (1.0F - f1) / (f1 * 3.0F + 1.0F) * (1.0F - f) + f;
71
        }
72
    }
73
74
    /**
75
     * creates a new world chunk manager for WorldProvider
76
     */
77
    protected void registerWorldChunkManager()
78
    {
79
        WorldType worldtype = this.worldObj.getWorldInfo().getTerrainType();
80
81
        if (worldtype == WorldType.FLAT)
82
        {
83
            FlatGeneratorInfo flatgeneratorinfo = FlatGeneratorInfo.createFlatGeneratorFromString(this.worldObj.getWorldInfo().getGeneratorOptions());
84
            this.worldChunkMgr = new WorldChunkManagerHell(BiomeGenBase.getBiomeFromBiomeList(flatgeneratorinfo.getBiome(), BiomeGenBase.field_180279_ad), 0.5F);
85
        }
86
        else if (worldtype == WorldType.DEBUG_WORLD)
87
        {
88
            this.worldChunkMgr = new WorldChunkManagerHell(BiomeGenBase.plains, 0.0F);
89
        }
90
        else
91
        {
92
            this.worldChunkMgr = new WorldChunkManager(this.worldObj);
93
        }
94
    }
95
96
    /**
97
     * Returns a new chunk provider which generates chunks for this world
98
     */
99
    public IChunkProvider createChunkGenerator()
100
    {
101
        return (IChunkProvider)(this.terrainType == WorldType.FLAT ? new ChunkProviderFlat(this.worldObj, this.worldObj.getSeed(), this.worldObj.getWorldInfo().isMapFeaturesEnabled(), this.generatorSettings) : (this.terrainType == WorldType.DEBUG_WORLD ? new ChunkProviderDebug(this.worldObj) : (this.terrainType == WorldType.CUSTOMIZED ? new ChunkProviderGenerate(this.worldObj, this.worldObj.getSeed(), this.worldObj.getWorldInfo().isMapFeaturesEnabled(), this.generatorSettings) : new ChunkProviderGenerate(this.worldObj, this.worldObj.getSeed(), this.worldObj.getWorldInfo().isMapFeaturesEnabled(), this.generatorSettings))));
102
    }
103
104
    /**
105
     * Will check if the x, z position specified is alright to be set as the map spawn point
106
     */
107
    public boolean canCoordinateBeSpawn(int x, int z)
108
    {
109
        return this.worldObj.getGroundAboveSeaLevel(new BlockPos(x, 0, z)) == Blocks.grass;
110
    }
111
112
    /**
113
     * Calculates the angle of sun and moon in the sky relative to a specified time (usually worldTime)
114
     */
115
    public float calculateCelestialAngle(long worldTime, float partialTicks)
116
    {
117
        int i = (int)(worldTime % 24000L);
118
        float f = ((float)i + partialTicks) / 24000.0F - 0.25F;
119
120
        if (f < 0.0F)
121
        {
122
            ++f;
123
        }
124
125
        if (f > 1.0F)
126
        {
127
            --f;
128
        }
129
130
        f = 1.0F - (float)((Math.cos((double)f * Math.PI) + 1.0D) / 2.0D);
131
        f = f + (f - f) / 3.0F;
132
        return f;
133
    }
134
135
    public int getMoonPhase(long worldTime)
136
    {
137
        return (int)(worldTime / 24000L % 8L + 8L) % 8;
138
    }
139
140
    /**
141
     * Returns 'true' if in the "main surface world", but 'false' if in the Nether or End dimensions.
142
     */
143
    public boolean isSurfaceWorld()
144
    {
145
        return true;
146
    }
147
148
    /**
149
     * Returns array with sunrise/sunset colors
150
     */
151
    public float[] calcSunriseSunsetColors(float celestialAngle, float partialTicks)
152
    {
153
        float f = 0.4F;
154
        float f1 = MathHelper.cos(celestialAngle * (float)Math.PI * 2.0F) - 0.0F;
155
        float f2 = -0.0F;
156
157
        if (f1 >= f2 - f && f1 <= f2 + f)
158
        {
159
            float f3 = (f1 - f2) / f * 0.5F + 0.5F;
160
            float f4 = 1.0F - (1.0F - MathHelper.sin(f3 * (float)Math.PI)) * 0.99F;
161
            f4 = f4 * f4;
162
            this.colorsSunriseSunset[0] = f3 * 0.3F + 0.7F;
163
            this.colorsSunriseSunset[1] = f3 * f3 * 0.7F + 0.2F;
164
            this.colorsSunriseSunset[2] = f3 * f3 * 0.0F + 0.2F;
165
            this.colorsSunriseSunset[3] = f4;
166
            return this.colorsSunriseSunset;
167
        }
168
        else
169
        {
170
            return null;
171
        }
172
    }
173
174
    /**
175
     * Return Vec3D with biome specific fog color
176
     */
177
    public Vec3 getFogColor(float p_76562_1_, float p_76562_2_)
178
    {
179
        float f = MathHelper.cos(p_76562_1_ * (float)Math.PI * 2.0F) * 2.0F + 0.5F;
180
        f = MathHelper.clamp_float(f, 0.0F, 1.0F);
181
        float f1 = 0.7529412F;
182
        float f2 = 0.84705883F;
183
        float f3 = 1.0F;
184
        f1 = f1 * (f * 0.94F + 0.06F);
185
        f2 = f2 * (f * 0.94F + 0.06F);
186
        f3 = f3 * (f * 0.91F + 0.09F);
187
        return new Vec3((double)f1, (double)f2, (double)f3);
188
    }
189
190
    /**
191
     * True if the player can respawn in this dimension (true = overworld, false = nether).
192
     */
193
    public boolean canRespawnHere()
194
    {
195
        return true;
196
    }
197
198
    public static WorldProvider getProviderForDimension(int dimension)
199
    {
200
        return (WorldProvider)(dimension == -1 ? new WorldProviderHell() : (dimension == 0 ? new WorldProviderSurface() : (dimension == 1 ? new WorldProviderEnd() : null)));
201
    }
202
203
    /**
204
     * the y level at which clouds are rendered.
205
     */
206
    public float getCloudHeight()
207
    {
208
        return 128.0F;
209
    }
210
211
    public boolean isSkyColored()
212
    {
213
        return true;
214
    }
215
216
    public BlockPos getSpawnCoordinate()
217
    {
218
        return null;
219
    }
220
221
    public int getAverageGroundLevel()
222
    {
223
        return this.terrainType == WorldType.FLAT ? 4 : this.worldObj.getSeaLevel() + 1;
224
    }
225
226
    /**
227
     * Returns a double value representing the Y value relative to the top of the map at which void fog is at its
228
     * maximum. The default factor of 0.03125 relative to 256, for example, means the void fog will be at its maximum at
229
     * (256*0.03125), or 8.
230
     */
231
    public double getVoidFogYFactor()
232
    {
233
        return this.terrainType == WorldType.FLAT ? 1.0D : 0.03125D;
234
    }
235
236
    /**
237
     * Returns true if the given X,Z coordinate should show environmental fog.
238
     */
239
    public boolean doesXZShowFog(int x, int z)
240
    {
241
        return false;
242
    }
243
244
    /**
245
     * Returns the dimension's name, e.g. "The End", "Nether", or "Overworld".
246
     */
247
    public abstract String getDimensionName();
248
249
    public abstract String getInternalNameSuffix();
250
251
    public WorldChunkManager getWorldChunkManager()
252
    {
253
        return this.worldChunkMgr;
254
    }
255
256
    public boolean doesWaterVaporize()
257
    {
258
        return this.isHellWorld;
259
    }
260
261
    public boolean getHasNoSky()
262
    {
263
        return this.hasNoSky;
264
    }
265
266
    public float[] getLightBrightnessTable()
267
    {
268
        return this.lightBrightnessTable;
269
    }
270
271
    /**
272
     * Gets the dimension of the provider
273
     */
274
    public int getDimensionId()
275
    {
276
        return this.dimensionId;
277
    }
278
279
    public WorldBorder getWorldBorder()
280
    {
281
        return new WorldBorder();
282
    }
283
}
284

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