WorldClient .java

net.minecraft.client.multiplayer.WorldClient (class, 483 lines): members: invalidateBlockReceiveRegion, invalidateRegionAndSetBlock, removeEntityFromWorld.

net.minecraft.client.multiplayerclass483 linesclientextends World16.0 KB

API Surface (28)

void tick()
void invalidateBlockReceiveRegion(int x1, int y1, int z1, int x2, int y2, int z2)
IChunkProvider createChunkProvider()
void updateBlocks()
void doPreChunk(int chuncX, int chuncZ, boolean loadChunk)
boolean spawnEntityInWorld(Entity entityIn)
void removeEntity(Entity entityIn)
void onEntityAdded(Entity entityIn)
void onEntityRemoved(Entity entityIn)
void addEntityToWorld(int entityID, Entity entityToSpawn)
Entity getEntityByID(int id)
Entity removeEntityFromWorld(int entityID)
boolean invalidateRegionAndSetBlock(BlockPos pos, IBlockState state)
void sendQuittingDisconnectingPacket()
void updateWeather()
int getRenderDistanceChunks()
void doVoidFogParticles(int posX, int posY, int posZ)
void removeAllEntities()
CrashReportCategory addWorldInfoToCrashReport(CrashReport report)
String call()
String call()
String call()
String call()
void playSoundAtPos(BlockPos pos, String soundName, float volume, float pitch, boolean distanceDelay)
void playSound(double x, double y, double z, String soundName, float volume, float pitch, boolean distanceDelay)
void makeFireworks(double x, double y, double z, double motionX, double motionY, double motionZ, NBTTagCompound compund)
void setWorldScoreboard(Scoreboard scoreboardIn)
void setWorldTime(long time)

Fields & Constants (6)

sendQueue
clientChunkProvider
entityList
entitySpawnQueue
mc
previousActiveChunkSet

String literals (14)

"MpServer"
"doDaylightCycle"
"reEntryProcessing"
"chunkCache"
"blocks"
"getChunk"
"Quitting"
"Forced entities"
" total; "
"Retry entities"
"Server brand"
"Server type"
"Non-integrated multiplayer server"
"Integrated singleplayer server"

Full Source

WorldClient.java483 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.client.multiplayer;
2
3
import com.google.common.collect.Sets;
4
import java.util.Random;
5
import java.util.Set;
6
import java.util.concurrent.Callable;
7
import net.minecraft.block.Block;
8
import net.minecraft.block.state.IBlockState;
9
import net.minecraft.client.Minecraft;
10
import net.minecraft.client.audio.MovingSoundMinecart;
11
import net.minecraft.client.audio.PositionedSoundRecord;
12
import net.minecraft.client.network.NetHandlerPlayClient;
13
import net.minecraft.client.particle.EntityFirework;
14
import net.minecraft.crash.CrashReport;
15
import net.minecraft.crash.CrashReportCategory;
16
import net.minecraft.entity.Entity;
17
import net.minecraft.entity.item.EntityMinecart;
18
import net.minecraft.init.Blocks;
19
import net.minecraft.item.ItemStack;
20
import net.minecraft.nbt.NBTTagCompound;
21
import net.minecraft.profiler.Profiler;
22
import net.minecraft.scoreboard.Scoreboard;
23
import net.minecraft.util.BlockPos;
24
import net.minecraft.util.ChatComponentText;
25
import net.minecraft.util.EnumParticleTypes;
26
import net.minecraft.util.ResourceLocation;
27
import net.minecraft.world.ChunkCoordIntPair;
28
import net.minecraft.world.EnumDifficulty;
29
import net.minecraft.world.World;
30
import net.minecraft.world.WorldProvider;
31
import net.minecraft.world.WorldSettings;
32
import net.minecraft.world.chunk.Chunk;
33
import net.minecraft.world.chunk.IChunkProvider;
34
import net.minecraft.world.storage.SaveDataMemoryStorage;
35
import net.minecraft.world.storage.SaveHandlerMP;
36
import net.minecraft.world.storage.WorldInfo;
37
38
public class WorldClient extends World
39
{
40
    /** The packets that need to be sent to the server. */
41
    private NetHandlerPlayClient sendQueue;
42
43
    /** The ChunkProviderClient instance */
44
    private ChunkProviderClient clientChunkProvider;
45
    private final Set<Entity> entityList = Sets.<Entity>newHashSet();
46
    private final Set<Entity> entitySpawnQueue = Sets.<Entity>newHashSet();
47
    private final Minecraft mc = Minecraft.getMinecraft();
48
    private final Set<ChunkCoordIntPair> previousActiveChunkSet = Sets.<ChunkCoordIntPair>newHashSet();
49
50
    public WorldClient(NetHandlerPlayClient netHandler, WorldSettings settings, int dimension, EnumDifficulty difficulty, Profiler profilerIn)
51
    {
52
        super(new SaveHandlerMP(), new WorldInfo(settings, "MpServer"), WorldProvider.getProviderForDimension(dimension), profilerIn, true);
53
        this.sendQueue = netHandler;
54
        this.getWorldInfo().setDifficulty(difficulty);
55
        this.setSpawnPoint(new BlockPos(8, 64, 8));
56
        this.provider.registerWorld(this);
57
        this.chunkProvider = this.createChunkProvider();
58
        this.mapStorage = new SaveDataMemoryStorage();
59
        this.calculateInitialSkylight();
60
        this.calculateInitialWeather();
61
    }
62
63
    /**
64
     * Runs a single tick for the world
65
     */
66
    public void tick()
67
    {
68
        super.tick();
69
        this.setTotalWorldTime(this.getTotalWorldTime() + 1L);
70
71
        if (this.getGameRules().getBoolean("doDaylightCycle"))
72
        {
73
            this.setWorldTime(this.getWorldTime() + 1L);
74
        }
75
76
        this.theProfiler.startSection("reEntryProcessing");
77
78
        for (int i = 0; i < 10 && !this.entitySpawnQueue.isEmpty(); ++i)
79
        {
80
            Entity entity = (Entity)this.entitySpawnQueue.iterator().next();
81
            this.entitySpawnQueue.remove(entity);
82
83
            if (!this.loadedEntityList.contains(entity))
84
            {
85
                this.spawnEntityInWorld(entity);
86
            }
87
        }
88
89
        this.theProfiler.endStartSection("chunkCache");
90
        this.clientChunkProvider.unloadQueuedChunks();
91
        this.theProfiler.endStartSection("blocks");
92
        this.updateBlocks();
93
        this.theProfiler.endSection();
94
    }
95
96
    /**
97
     * Invalidates an AABB region of blocks from the receive queue, in the event that the block has been modified
98
     * client-side in the intervening 80 receive ticks.
99
     *  
100
     * @param x1 X position of the block where the region begin
101
     * @param y1 Y position of the block where the region begin
102
     * @param z1 Z position of the block where the region begin
103
     * @param x2 X position of the block where the region end
104
     * @param y2 Y position of the block where the region end
105
     * @param z2 Z position of the block where the region end
106
     */
107
    public void invalidateBlockReceiveRegion(int x1, int y1, int z1, int x2, int y2, int z2)
108
    {
109
    }
110
111
    /**
112
     * Creates the chunk provider for this world. Called in the constructor. Retrieves provider from worldProvider?
113
     */
114
    protected IChunkProvider createChunkProvider()
115
    {
116
        this.clientChunkProvider = new ChunkProviderClient(this);
117
        return this.clientChunkProvider;
118
    }
119
120
    protected void updateBlocks()
121
    {
122
        super.updateBlocks();
123
        this.previousActiveChunkSet.retainAll(this.activeChunkSet);
124
125
        if (this.previousActiveChunkSet.size() == this.activeChunkSet.size())
126
        {
127
            this.previousActiveChunkSet.clear();
128
        }
129
130
        int i = 0;
131
132
        for (ChunkCoordIntPair chunkcoordintpair : this.activeChunkSet)
133
        {
134
            if (!this.previousActiveChunkSet.contains(chunkcoordintpair))
135
            {
136
                int j = chunkcoordintpair.chunkXPos * 16;
137
                int k = chunkcoordintpair.chunkZPos * 16;
138
                this.theProfiler.startSection("getChunk");
139
                Chunk chunk = this.getChunkFromChunkCoords(chunkcoordintpair.chunkXPos, chunkcoordintpair.chunkZPos);
140
                this.playMoodSoundAndCheckLight(j, k, chunk);
141
                this.theProfiler.endSection();
142
                this.previousActiveChunkSet.add(chunkcoordintpair);
143
                ++i;
144
145
                if (i >= 10)
146
                {
147
                    return;
148
                }
149
            }
150
        }
151
    }
152
153
    public void doPreChunk(int chuncX, int chuncZ, boolean loadChunk)
154
    {
155
        if (loadChunk)
156
        {
157
            this.clientChunkProvider.loadChunk(chuncX, chuncZ);
158
        }
159
        else
160
        {
161
            this.clientChunkProvider.unloadChunk(chuncX, chuncZ);
162
        }
163
164
        if (!loadChunk)
165
        {
166
            this.markBlockRangeForRenderUpdate(chuncX * 16, 0, chuncZ * 16, chuncX * 16 + 15, 256, chuncZ * 16 + 15);
167
        }
168
    }
169
170
    /**
171
     * Called when an entity is spawned in the world. This includes players.
172
     */
173
    public boolean spawnEntityInWorld(Entity entityIn)
174
    {
175
        boolean flag = super.spawnEntityInWorld(entityIn);
176
        this.entityList.add(entityIn);
177
178
        if (!flag)
179
        {
180
            this.entitySpawnQueue.add(entityIn);
181
        }
182
        else if (entityIn instanceof EntityMinecart)
183
        {
184
            this.mc.getSoundHandler().playSound(new MovingSoundMinecart((EntityMinecart)entityIn));
185
        }
186
187
        return flag;
188
    }
189
190
    /**
191
     * Schedule the entity for removal during the next tick. Marks the entity dead in anticipation.
192
     */
193
    public void removeEntity(Entity entityIn)
194
    {
195
        super.removeEntity(entityIn);
196
        this.entityList.remove(entityIn);
197
    }
198
199
    protected void onEntityAdded(Entity entityIn)
200
    {
201
        super.onEntityAdded(entityIn);
202
203
        if (this.entitySpawnQueue.contains(entityIn))
204
        {
205
            this.entitySpawnQueue.remove(entityIn);
206
        }
207
    }
208
209
    protected void onEntityRemoved(Entity entityIn)
210
    {
211
        super.onEntityRemoved(entityIn);
212
        boolean flag = false;
213
214
        if (this.entityList.contains(entityIn))
215
        {
216
            if (entityIn.isEntityAlive())
217
            {
218
                this.entitySpawnQueue.add(entityIn);
219
                flag = true;
220
            }
221
            else
222
            {
223
                this.entityList.remove(entityIn);
224
            }
225
        }
226
    }
227
228
    /**
229
     * Add an ID to Entity mapping to entityHashSet
230
     *  
231
     * @param entityID The ID to give to the entity to spawn
232
     * @param entityToSpawn The Entity to spawn in the World
233
     */
234
    public void addEntityToWorld(int entityID, Entity entityToSpawn)
235
    {
236
        Entity entity = this.getEntityByID(entityID);
237
238
        if (entity != null)
239
        {
240
            this.removeEntity(entity);
241
        }
242
243
        this.entityList.add(entityToSpawn);
244
        entityToSpawn.setEntityId(entityID);
245
246
        if (!this.spawnEntityInWorld(entityToSpawn))
247
        {
248
            this.entitySpawnQueue.add(entityToSpawn);
249
        }
250
251
        this.entitiesById.addKey(entityID, entityToSpawn);
252
    }
253
254
    /**
255
     * Returns the Entity with the given ID, or null if it doesn't exist in this World.
256
     */
257
    public Entity getEntityByID(int id)
258
    {
259
        return (Entity)(id == this.mc.thePlayer.getEntityId() ? this.mc.thePlayer : super.getEntityByID(id));
260
    }
261
262
    public Entity removeEntityFromWorld(int entityID)
263
    {
264
        Entity entity = (Entity)this.entitiesById.removeObject(entityID);
265
266
        if (entity != null)
267
        {
268
            this.entityList.remove(entity);
269
            this.removeEntity(entity);
270
        }
271
272
        return entity;
273
    }
274
275
    public boolean invalidateRegionAndSetBlock(BlockPos pos, IBlockState state)
276
    {
277
        int i = pos.getX();
278
        int j = pos.getY();
279
        int k = pos.getZ();
280
        this.invalidateBlockReceiveRegion(i, j, k, i, j, k);
281
        return super.setBlockState(pos, state, 3);
282
    }
283
284
    /**
285
     * If on MP, sends a quitting packet.
286
     */
287
    public void sendQuittingDisconnectingPacket()
288
    {
289
        this.sendQueue.getNetworkManager().closeChannel(new ChatComponentText("Quitting"));
290
    }
291
292
    /**
293
     * Updates all weather states.
294
     */
295
    protected void updateWeather()
296
    {
297
    }
298
299
    protected int getRenderDistanceChunks()
300
    {
301
        return this.mc.gameSettings.renderDistanceChunks;
302
    }
303
304
    public void doVoidFogParticles(int posX, int posY, int posZ)
305
    {
306
        int i = 16;
307
        Random random = new Random();
308
        ItemStack itemstack = this.mc.thePlayer.getHeldItem();
309
        boolean flag = this.mc.playerController.getCurrentGameType() == WorldSettings.GameType.CREATIVE && itemstack != null && Block.getBlockFromItem(itemstack.getItem()) == Blocks.barrier;
310
        BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();
311
312
        for (int j = 0; j < 1000; ++j)
313
        {
314
            int k = posX + this.rand.nextInt(i) - this.rand.nextInt(i);
315
            int l = posY + this.rand.nextInt(i) - this.rand.nextInt(i);
316
            int i1 = posZ + this.rand.nextInt(i) - this.rand.nextInt(i);
317
            blockpos$mutableblockpos.set(k, l, i1);
318
            IBlockState iblockstate = this.getBlockState(blockpos$mutableblockpos);
319
            iblockstate.getBlock().randomDisplayTick(this, blockpos$mutableblockpos, iblockstate, random);
320
321
            if (flag && iblockstate.getBlock() == Blocks.barrier)
322
            {
323
                this.spawnParticle(EnumParticleTypes.BARRIER, (double)((float)k + 0.5F), (double)((float)l + 0.5F), (double)((float)i1 + 0.5F), 0.0D, 0.0D, 0.0D, new int[0]);
324
            }
325
        }
326
    }
327
328
    /**
329
     * also releases skins.
330
     */
331
    public void removeAllEntities()
332
    {
333
        this.loadedEntityList.removeAll(this.unloadedEntityList);
334
335
        for (int i = 0; i < this.unloadedEntityList.size(); ++i)
336
        {
337
            Entity entity = (Entity)this.unloadedEntityList.get(i);
338
            int j = entity.chunkCoordX;
339
            int k = entity.chunkCoordZ;
340
341
            if (entity.addedToChunk && this.isChunkLoaded(j, k, true))
342
            {
343
                this.getChunkFromChunkCoords(j, k).removeEntity(entity);
344
            }
345
        }
346
347
        for (int l = 0; l < this.unloadedEntityList.size(); ++l)
348
        {
349
            this.onEntityRemoved((Entity)this.unloadedEntityList.get(l));
350
        }
351
352
        this.unloadedEntityList.clear();
353
354
        for (int i1 = 0; i1 < this.loadedEntityList.size(); ++i1)
355
        {
356
            Entity entity1 = (Entity)this.loadedEntityList.get(i1);
357
358
            if (entity1.ridingEntity != null)
359
            {
360
                if (!entity1.ridingEntity.isDead && entity1.ridingEntity.riddenByEntity == entity1)
361
                {
362
                    continue;
363
                }
364
365
                entity1.ridingEntity.riddenByEntity = null;
366
                entity1.ridingEntity = null;
367
            }
368
369
            if (entity1.isDead)
370
            {
371
                int j1 = entity1.chunkCoordX;
372
                int k1 = entity1.chunkCoordZ;
373
374
                if (entity1.addedToChunk && this.isChunkLoaded(j1, k1, true))
375
                {
376
                    this.getChunkFromChunkCoords(j1, k1).removeEntity(entity1);
377
                }
378
379
                this.loadedEntityList.remove(i1--);
380
                this.onEntityRemoved(entity1);
381
            }
382
        }
383
    }
384
385
    /**
386
     * Adds some basic stats of the world to the given crash report.
387
     */
388
    public CrashReportCategory addWorldInfoToCrashReport(CrashReport report)
389
    {
390
        CrashReportCategory crashreportcategory = super.addWorldInfoToCrashReport(report);
391
        crashreportcategory.addCrashSectionCallable("Forced entities", new Callable<String>()
392
        {
393
            public String call()
394
            {
395
                return WorldClient.this.entityList.size() + " total; " + WorldClient.this.entityList.toString();
396
            }
397
        });
398
        crashreportcategory.addCrashSectionCallable("Retry entities", new Callable<String>()
399
        {
400
            public String call()
401
            {
402
                return WorldClient.this.entitySpawnQueue.size() + " total; " + WorldClient.this.entitySpawnQueue.toString();
403
            }
404
        });
405
        crashreportcategory.addCrashSectionCallable("Server brand", new Callable<String>()
406
        {
407
            public String call() throws Exception
408
            {
409
                return WorldClient.this.mc.thePlayer.getClientBrand();
410
            }
411
        });
412
        crashreportcategory.addCrashSectionCallable("Server type", new Callable<String>()
413
        {
414
            public String call() throws Exception
415
            {
416
                return WorldClient.this.mc.getIntegratedServer() == null ? "Non-integrated multiplayer server" : "Integrated singleplayer server";
417
            }
418
        });
419
        return crashreportcategory;
420
    }
421
422
    /**
423
     * Plays a sound at the specified position.
424
     *  
425
     * @param pos The position where to play the sound
426
     * @param soundName The name of the sound to play
427
     * @param volume The volume of the sound
428
     * @param pitch The pitch of the sound
429
     * @param distanceDelay True if the sound is delayed over distance
430
     */
431
    public void playSoundAtPos(BlockPos pos, String soundName, float volume, float pitch, boolean distanceDelay)
432
    {
433
        this.playSound((double)pos.getX() + 0.5D, (double)pos.getY() + 0.5D, (double)pos.getZ() + 0.5D, soundName, volume, pitch, distanceDelay);
434
    }
435
436
    /**
437
     * par8 is loudness, all pars passed to minecraftInstance.sndManager.playSound
438
     */
439
    public void playSound(double x, double y, double z, String soundName, float volume, float pitch, boolean distanceDelay)
440
    {
441
        double d0 = this.mc.getRenderViewEntity().getDistanceSq(x, y, z);
442
        PositionedSoundRecord positionedsoundrecord = new PositionedSoundRecord(new ResourceLocation(soundName), volume, pitch, (float)x, (float)y, (float)z);
443
444
        if (distanceDelay && d0 > 100.0D)
445
        {
446
            double d1 = Math.sqrt(d0) / 40.0D;
447
            this.mc.getSoundHandler().playDelayedSound(positionedsoundrecord, (int)(d1 * 20.0D));
448
        }
449
        else
450
        {
451
            this.mc.getSoundHandler().playSound(positionedsoundrecord);
452
        }
453
    }
454
455
    public void makeFireworks(double x, double y, double z, double motionX, double motionY, double motionZ, NBTTagCompound compund)
456
    {
457
        this.mc.effectRenderer.addEffect(new EntityFirework.StarterFX(this, x, y, z, motionX, motionY, motionZ, this.mc.effectRenderer, compund));
458
    }
459
460
    public void setWorldScoreboard(Scoreboard scoreboardIn)
461
    {
462
        this.worldScoreboard = scoreboardIn;
463
    }
464
465
    /**
466
     * Sets the world time.
467
     */
468
    public void setWorldTime(long time)
469
    {
470
        if (time < 0L)
471
        {
472
            time = -time;
473
            this.getGameRules().setOrCreateGameRule("doDaylightCycle", "false");
474
        }
475
        else
476
        {
477
            this.getGameRules().setOrCreateGameRule("doDaylightCycle", "true");
478
        }
479
480
        super.setWorldTime(time);
481
    }
482
}
483

Deobfuscated MCP 1.8.9 source of WorldClient from Marcelektro/MavenMCP-1.8.9 (net/minecraft/client/multiplayer/WorldClient.java), stored verbatim.