World

Abstract world: block read/write, raytrace, entity/AABB queries, spawning, weather, scoreboard and border access.

net/minecraft/world/World.java

Updated 2026-09-12

Packets Referenced (0)

Deep Analysis

Abstract block/entity store and simulation hub for server and client. Provides chunk-backed block access, DDA rayTraceBlocks, AABB entity queries, collision lists, and sound/particle fan-out to IWorldAccess. Owns entity/tile tick loops, light, weather, and save metadata.

Key Methods (8)

getBlockState/setBlockState

Chunk-backed block read and flagged write path.

Validates coords, delegates to Chunk, handles light check, markBlockForUpdate for render, and neighbor/comparator updates. Flags control notify vs client sync. Basis for S22/S23.

rayTraceBlocks

DDA voxel traversal returning block hit or miss.

Steps grid up to 200 iterations honoring stopOnLiquid and bounding-box flags. Calls Block.collisionRayTrace per cell. Used by Entity.rayTrace and interaction.

getCollidingBoundingBoxes

Collects block plus entity boxes intersecting an AABB.

Iterates block range with border checks, adds block collision boxes, then nearby entity boxes. Feeds Entity.moveEntity resolution.

getEntitiesWithinAABBExcludingEntity

Chunk-scoped entity query with spectator filter.

Expands chunk range by margin, delegates to Chunk.getEntitiesWithinAABBForEntity. Powers collision, combat targeting, and sleep safety checks.

spawnEntityInWorld/removeEntity

Registers and unregisters entities with chunks and lists.

Validates chunk loaded, adds players to playerEntities, links chunk and calls onEntityAdded/Removed for render/tracker hooks. Backs S0E/S13.

updateEntities/updateEntity

Ticks weather effects, entities, and tile entities.

Handles riding consistency, NaN guards, chunk migration, dead removal, and ITickable tiles. Called each world tick before block ticks.

playSoundAtEntity/spawnParticle

Fans out audible and visual effects to world accesses.

Iterates IWorldAccess for playSound, playRecord, broadcastSound, aux SFX, and particle IDs. Server listeners convert to S29/S2A; client renders directly.

setEntityState/addBlockEvent

Hooks for entity status and block animation events.

Base World is no-op; WorldServer overrides to send S19 entity status and S24 block action to trackers. Comment notes legacy Packet 38.

Internal State

loadedEntityList/playerEntitiesTicked entities and player subset for queries and sleep
chunkProviderChunk source backing block, light, and entity storage
worldAccessesListeners receiving block, sound, particle, entity events
isRemoteClient vs server branch for logic and packet fan-out
worldInfo/worldBorderTime, spawn, rules, and border constraining validity

Related Vanilla Internals

Full Source

World.java3865 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.world;
2
3
import com.google.common.base.Predicate;
4
import com.google.common.collect.Lists;
5
import com.google.common.collect.Sets;
6
import java.util.Calendar;
7
import java.util.Collection;
8
import java.util.Iterator;
9
import java.util.List;
10
import java.util.Random;
11
import java.util.Set;
12
import java.util.UUID;
13
import java.util.concurrent.Callable;
14
import net.minecraft.block.Block;
15
import net.minecraft.block.BlockHopper;
16
import net.minecraft.block.BlockLiquid;
17
import net.minecraft.block.BlockSlab;
18
import net.minecraft.block.BlockSnow;
19
import net.minecraft.block.BlockStairs;
20
import net.minecraft.block.material.Material;
21
import net.minecraft.block.state.IBlockState;
22
import net.minecraft.crash.CrashReport;
23
import net.minecraft.crash.CrashReportCategory;
24
import net.minecraft.entity.Entity;
25
import net.minecraft.entity.EntityLiving;
26
import net.minecraft.entity.player.EntityPlayer;
27
import net.minecraft.init.Blocks;
28
import net.minecraft.item.ItemStack;
29
import net.minecraft.nbt.NBTTagCompound;
30
import net.minecraft.profiler.Profiler;
31
import net.minecraft.scoreboard.Scoreboard;
32
import net.minecraft.server.MinecraftServer;
33
import net.minecraft.tileentity.TileEntity;
34
import net.minecraft.util.AxisAlignedBB;
35
import net.minecraft.util.BlockPos;
36
import net.minecraft.util.EntitySelectors;
37
import net.minecraft.util.EnumFacing;
38
import net.minecraft.util.EnumParticleTypes;
39
import net.minecraft.util.ITickable;
40
import net.minecraft.util.IntHashMap;
41
import net.minecraft.util.MathHelper;
42
import net.minecraft.util.MovingObjectPosition;
43
import net.minecraft.util.ReportedException;
44
import net.minecraft.util.Vec3;
45
import net.minecraft.village.VillageCollection;
46
import net.minecraft.world.biome.BiomeGenBase;
47
import net.minecraft.world.biome.WorldChunkManager;
48
import net.minecraft.world.border.WorldBorder;
49
import net.minecraft.world.chunk.Chunk;
50
import net.minecraft.world.chunk.IChunkProvider;
51
import net.minecraft.world.gen.structure.StructureBoundingBox;
52
import net.minecraft.world.storage.ISaveHandler;
53
import net.minecraft.world.storage.MapStorage;
54
import net.minecraft.world.storage.WorldInfo;
55
56
public abstract class World implements IBlockAccess
57
{
58
    private int seaLevel = 63;
59
60
    /**
61
     * boolean; if true updates scheduled by scheduleBlockUpdate happen immediately
62
     */
63
    protected boolean scheduledUpdatesAreImmediate;
64
    public final List<Entity> loadedEntityList = Lists.<Entity>newArrayList();
65
    protected final List<Entity> unloadedEntityList = Lists.<Entity>newArrayList();
66
    public final List<TileEntity> loadedTileEntityList = Lists.<TileEntity>newArrayList();
67
    public final List<TileEntity> tickableTileEntities = Lists.<TileEntity>newArrayList();
68
    private final List<TileEntity> addedTileEntityList = Lists.<TileEntity>newArrayList();
69
    private final List<TileEntity> tileEntitiesToBeRemoved = Lists.<TileEntity>newArrayList();
70
    public final List<EntityPlayer> playerEntities = Lists.<EntityPlayer>newArrayList();
71
    public final List<Entity> weatherEffects = Lists.<Entity>newArrayList();
72
    protected final IntHashMap<Entity> entitiesById = new IntHashMap<>(); // Added type inference
73
    private long cloudColour = 16777215L;
74
75
    /** How much light is subtracted from full daylight */
76
    private int skylightSubtracted;
77
78
    /**
79
     * Contains the current Linear Congruential Generator seed for block updates. Used with an A value of 3 and a C
80
     * value of 0x3c6ef35f, producing a highly planar series of values ill-suited for choosing random blocks in a
81
     * 16x128x16 field.
82
     */
83
    protected int updateLCG = (new Random()).nextInt();
84
85
    /**
86
     * magic number used to generate fast random numbers for 3d distribution within a chunk
87
     */
88
    protected final int DIST_HASH_MAGIC = 1013904223;
89
    protected float prevRainingStrength;
90
    protected float rainingStrength;
91
    protected float prevThunderingStrength;
92
    protected float thunderingStrength;
93
94
    /**
95
     * Set to 2 whenever a lightning bolt is generated in SSP. Decrements if > 0 in updateWeather(). Value appears to be
96
     * unused.
97
     */
98
    private int lastLightningBolt;
99
100
    /** RNG for World. */
101
    public final Random rand = new Random();
102
103
    /** The WorldProvider instance that World uses. */
104
    public final WorldProvider provider;
105
    protected List<IWorldAccess> worldAccesses = Lists.<IWorldAccess>newArrayList();
106
107
    /** Handles chunk operations and caching */
108
    protected IChunkProvider chunkProvider;
109
    protected final ISaveHandler saveHandler;
110
111
    /**
112
     * holds information about a world (size on disk, time, spawn point, seed, ...)
113
     */
114
    protected WorldInfo worldInfo;
115
116
    /**
117
     * if set, this flag forces a request to load a chunk to load the chunk rather than defaulting to the world's
118
     * chunkprovider's dummy if possible
119
     */
120
    protected boolean findingSpawnPoint;
121
    protected MapStorage mapStorage;
122
    protected VillageCollection villageCollectionObj;
123
    public final Profiler theProfiler;
124
    private final Calendar theCalendar = Calendar.getInstance();
125
    protected Scoreboard worldScoreboard = new Scoreboard();
126
127
    /**
128
     * True if the world is a 'slave' client; changes will not be saved or propagated from this world. For example,
129
     * server worlds have this set to false, client worlds have this set to true.
130
     */
131
    public final boolean isRemote;
132
    protected Set<ChunkCoordIntPair> activeChunkSet = Sets.<ChunkCoordIntPair>newHashSet();
133
134
    /** number of ticks until the next random ambients play */
135
    private int ambientTickCountdown;
136
137
    /** indicates if enemies are spawned or not */
138
    protected boolean spawnHostileMobs;
139
140
    /** A flag indicating whether we should spawn peaceful mobs. */
141
    protected boolean spawnPeacefulMobs;
142
    private boolean processingLoadedTiles;
143
    private final WorldBorder worldBorder;
144
145
    /**
146
     * is a temporary list of blocks and light values used when updating light levels. Holds up to 32x32x32 blocks (the
147
     * maximum influence of a light source.) Every element is a packed bit value: 0000000000LLLLzzzzzzyyyyyyxxxxxx. The
148
     * 4-bit L is a light level used when darkening blocks. 6-bit numbers x, y and z represent the block's offset from
149
     * the original block, plus 32 (i.e. value of 31 would mean a -1 offset
150
     */
151
    int[] lightUpdateBlockList;
152
153
    protected World(ISaveHandler saveHandlerIn, WorldInfo info, WorldProvider providerIn, Profiler profilerIn, boolean client)
154
    {
155
        this.ambientTickCountdown = this.rand.nextInt(12000);
156
        this.spawnHostileMobs = true;
157
        this.spawnPeacefulMobs = true;
158
        this.lightUpdateBlockList = new int[32768];
159
        this.saveHandler = saveHandlerIn;
160
        this.theProfiler = profilerIn;
161
        this.worldInfo = info;
162
        this.provider = providerIn;
163
        this.isRemote = client;
164
        this.worldBorder = providerIn.getWorldBorder();
165
    }
166
167
    public World init()
168
    {
169
        return this;
170
    }
171
172
    public BiomeGenBase getBiomeGenForCoords(final BlockPos pos)
173
    {
174
        if (this.isBlockLoaded(pos))
175
        {
176
            Chunk chunk = this.getChunkFromBlockCoords(pos);
177
178
            try
179
            {
180
                return chunk.getBiome(pos, this.provider.getWorldChunkManager());
181
            }
182
            catch (Throwable throwable)
183
            {
184
                CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Getting biome");
185
                CrashReportCategory crashreportcategory = crashreport.makeCategory("Coordinates of biome request");
186
                crashreportcategory.addCrashSectionCallable("Location", new Callable<String>()
187
                {
188
                    public String call() throws Exception
189
                    {
190
                        return CrashReportCategory.getCoordinateInfo(pos);
191
                    }
192
                });
193
                throw new ReportedException(crashreport);
194
            }
195
        }
196
        else
197
        {
198
            return this.provider.getWorldChunkManager().getBiomeGenerator(pos, BiomeGenBase.plains);
199
        }
200
    }
201
202
    public WorldChunkManager getWorldChunkManager()
203
    {
204
        return this.provider.getWorldChunkManager();
205
    }
206
207
    /**
208
     * Creates the chunk provider for this world. Called in the constructor. Retrieves provider from worldProvider?
209
     */
210
    protected abstract IChunkProvider createChunkProvider();
211
212
    public void initialize(WorldSettings settings)
213
    {
214
        this.worldInfo.setServerInitialized(true);
215
    }
216
217
    /**
218
     * Sets a new spawn location by finding an uncovered block at a random (x,z) location in the chunk.
219
     */
220
    public void setInitialSpawnLocation()
221
    {
222
        this.setSpawnPoint(new BlockPos(8, 64, 8));
223
    }
224
225
    public Block getGroundAboveSeaLevel(BlockPos pos)
226
    {
227
        BlockPos blockpos;
228
229
        for (blockpos = new BlockPos(pos.getX(), this.getSeaLevel(), pos.getZ()); !this.isAirBlock(blockpos.up()); blockpos = blockpos.up())
230
        {
231
            ;
232
        }
233
234
        return this.getBlockState(blockpos).getBlock();
235
    }
236
237
    /**
238
     * Check if the given BlockPos has valid coordinates
239
     */
240
    private boolean isValid(BlockPos pos)
241
    {
242
        return pos.getX() >= -30000000 && pos.getZ() >= -30000000 && pos.getX() < 30000000 && pos.getZ() < 30000000 && pos.getY() >= 0 && pos.getY() < 256;
243
    }
244
245
    /**
246
     * Checks to see if an air block exists at the provided location. Note that this only checks to see if the blocks
247
     * material is set to air, meaning it is possible for non-vanilla blocks to still pass this check.
248
     */
249
    public boolean isAirBlock(BlockPos pos)
250
    {
251
        return this.getBlockState(pos).getBlock().getMaterial() == Material.air;
252
    }
253
254
    public boolean isBlockLoaded(BlockPos pos)
255
    {
256
        return this.isBlockLoaded(pos, true);
257
    }
258
259
    public boolean isBlockLoaded(BlockPos pos, boolean allowEmpty)
260
    {
261
        return !this.isValid(pos) ? false : this.isChunkLoaded(pos.getX() >> 4, pos.getZ() >> 4, allowEmpty);
262
    }
263
264
    public boolean isAreaLoaded(BlockPos center, int radius)
265
    {
266
        return this.isAreaLoaded(center, radius, true);
267
    }
268
269
    public boolean isAreaLoaded(BlockPos center, int radius, boolean allowEmpty)
270
    {
271
        return this.isAreaLoaded(center.getX() - radius, center.getY() - radius, center.getZ() - radius, center.getX() + radius, center.getY() + radius, center.getZ() + radius, allowEmpty);
272
    }
273
274
    public boolean isAreaLoaded(BlockPos from, BlockPos to)
275
    {
276
        return this.isAreaLoaded(from, to, true);
277
    }
278
279
    public boolean isAreaLoaded(BlockPos from, BlockPos to, boolean allowEmpty)
280
    {
281
        return this.isAreaLoaded(from.getX(), from.getY(), from.getZ(), to.getX(), to.getY(), to.getZ(), allowEmpty);
282
    }
283
284
    public boolean isAreaLoaded(StructureBoundingBox box)
285
    {
286
        return this.isAreaLoaded(box, true);
287
    }
288
289
    public boolean isAreaLoaded(StructureBoundingBox box, boolean allowEmpty)
290
    {
291
        return this.isAreaLoaded(box.minX, box.minY, box.minZ, box.maxX, box.maxY, box.maxZ, allowEmpty);
292
    }
293
294
    private boolean isAreaLoaded(int xStart, int yStart, int zStart, int xEnd, int yEnd, int zEnd, boolean allowEmpty)
295
    {
296
        if (yEnd >= 0 && yStart < 256)
297
        {
298
            xStart = xStart >> 4;
299
            zStart = zStart >> 4;
300
            xEnd = xEnd >> 4;
301
            zEnd = zEnd >> 4;
302
303
            for (int i = xStart; i <= xEnd; ++i)
304
            {
305
                for (int j = zStart; j <= zEnd; ++j)
306
                {
307
                    if (!this.isChunkLoaded(i, j, allowEmpty))
308
                    {
309
                        return false;
310
                    }
311
                }
312
            }
313
314
            return true;
315
        }
316
        else
317
        {
318
            return false;
319
        }
320
    }
321
322
    protected boolean isChunkLoaded(int x, int z, boolean allowEmpty)
323
    {
324
        return this.chunkProvider.chunkExists(x, z) && (allowEmpty || !this.chunkProvider.provideChunk(x, z).isEmpty());
325
    }
326
327
    public Chunk getChunkFromBlockCoords(BlockPos pos)
328
    {
329
        return this.getChunkFromChunkCoords(pos.getX() >> 4, pos.getZ() >> 4);
330
    }
331
332
    /**
333
     * Returns back a chunk looked up by chunk coordinates Args: x, y
334
     */
335
    public Chunk getChunkFromChunkCoords(int chunkX, int chunkZ)
336
    {
337
        return this.chunkProvider.provideChunk(chunkX, chunkZ);
338
    }
339
340
    /**
341
     * Sets the block state at a given location. Flag 1 will cause a block update. Flag 2 will send the change to
342
     * clients (you almost always want this). Flag 4 prevents the block from being re-rendered, if this is a client
343
     * world. Flags can be added together.
344
     */
345
    public boolean setBlockState(BlockPos pos, IBlockState newState, int flags)
346
    {
347
        if (!this.isValid(pos))
348
        {
349
            return false;
350
        }
351
        else if (!this.isRemote && this.worldInfo.getTerrainType() == WorldType.DEBUG_WORLD)
352
        {
353
            return false;
354
        }
355
        else
356
        {
357
            Chunk chunk = this.getChunkFromBlockCoords(pos);
358
            Block block = newState.getBlock();
359
            IBlockState iblockstate = chunk.setBlockState(pos, newState);
360
361
            if (iblockstate == null)
362
            {
363
                return false;
364
            }
365
            else
366
            {
367
                Block block1 = iblockstate.getBlock();
368
369
                if (block.getLightOpacity() != block1.getLightOpacity() || block.getLightValue() != block1.getLightValue())
370
                {
371
                    this.theProfiler.startSection("checkLight");
372
                    this.checkLight(pos);
373
                    this.theProfiler.endSection();
374
                }
375
376
                if ((flags & 2) != 0 && (!this.isRemote || (flags & 4) == 0) && chunk.isPopulated())
377
                {
378
                    this.markBlockForUpdate(pos);
379
                }
380
381
                if (!this.isRemote && (flags & 1) != 0)
382
                {
383
                    this.notifyNeighborsRespectDebug(pos, iblockstate.getBlock());
384
385
                    if (block.hasComparatorInputOverride())
386
                    {
387
                        this.updateComparatorOutputLevel(pos, block);
388
                    }
389
                }
390
391
                return true;
392
            }
393
        }
394
    }
395
396
    public boolean setBlockToAir(BlockPos pos)
397
    {
398
        return this.setBlockState(pos, Blocks.air.getDefaultState(), 3);
399
    }
400
401
    /**
402
     * Sets a block to air, but also plays the sound and particles and can spawn drops
403
     */
404
    public boolean destroyBlock(BlockPos pos, boolean dropBlock)
405
    {
406
        IBlockState iblockstate = this.getBlockState(pos);
407
        Block block = iblockstate.getBlock();
408
409
        if (block.getMaterial() == Material.air)
410
        {
411
            return false;
412
        }
413
        else
414
        {
415
            this.playAuxSFX(2001, pos, Block.getStateId(iblockstate));
416
417
            if (dropBlock)
418
            {
419
                block.dropBlockAsItem(this, pos, iblockstate, 0);
420
            }
421
422
            return this.setBlockState(pos, Blocks.air.getDefaultState(), 3);
423
        }
424
    }
425
426
    /**
427
     * Convenience method to update the block on both the client and server
428
     */
429
    public boolean setBlockState(BlockPos pos, IBlockState state)
430
    {
431
        return this.setBlockState(pos, state, 3);
432
    }
433
434
    public void markBlockForUpdate(BlockPos pos)
435
    {
436
        for (int i = 0; i < this.worldAccesses.size(); ++i)
437
        {
438
            ((IWorldAccess)this.worldAccesses.get(i)).markBlockForUpdate(pos);
439
        }
440
    }
441
442
    public void notifyNeighborsRespectDebug(BlockPos pos, Block blockType)
443
    {
444
        if (this.worldInfo.getTerrainType() != WorldType.DEBUG_WORLD)
445
        {
446
            this.notifyNeighborsOfStateChange(pos, blockType);
447
        }
448
    }
449
450
    /**
451
     * marks a vertical line of blocks as dirty
452
     */
453
    public void markBlocksDirtyVertical(int x1, int z1, int x2, int z2)
454
    {
455
        if (x2 > z2)
456
        {
457
            int i = z2;
458
            z2 = x2;
459
            x2 = i;
460
        }
461
462
        if (!this.provider.getHasNoSky())
463
        {
464
            for (int j = x2; j <= z2; ++j)
465
            {
466
                this.checkLightFor(EnumSkyBlock.SKY, new BlockPos(x1, j, z1));
467
            }
468
        }
469
470
        this.markBlockRangeForRenderUpdate(x1, x2, z1, x1, z2, z1);
471
    }
472
473
    public void markBlockRangeForRenderUpdate(BlockPos rangeMin, BlockPos rangeMax)
474
    {
475
        this.markBlockRangeForRenderUpdate(rangeMin.getX(), rangeMin.getY(), rangeMin.getZ(), rangeMax.getX(), rangeMax.getY(), rangeMax.getZ());
476
    }
477
478
    public void markBlockRangeForRenderUpdate(int x1, int y1, int z1, int x2, int y2, int z2)
479
    {
480
        for (int i = 0; i < this.worldAccesses.size(); ++i)
481
        {
482
            ((IWorldAccess)this.worldAccesses.get(i)).markBlockRangeForRenderUpdate(x1, y1, z1, x2, y2, z2);
483
        }
484
    }
485
486
    public void notifyNeighborsOfStateChange(BlockPos pos, Block blockType)
487
    {
488
        this.notifyBlockOfStateChange(pos.west(), blockType);
489
        this.notifyBlockOfStateChange(pos.east(), blockType);
490
        this.notifyBlockOfStateChange(pos.down(), blockType);
491
        this.notifyBlockOfStateChange(pos.up(), blockType);
492
        this.notifyBlockOfStateChange(pos.north(), blockType);
493
        this.notifyBlockOfStateChange(pos.south(), blockType);
494
    }
495
496
    public void notifyNeighborsOfStateExcept(BlockPos pos, Block blockType, EnumFacing skipSide)
497
    {
498
        if (skipSide != EnumFacing.WEST)
499
        {
500
            this.notifyBlockOfStateChange(pos.west(), blockType);
501
        }
502
503
        if (skipSide != EnumFacing.EAST)
504
        {
505
            this.notifyBlockOfStateChange(pos.east(), blockType);
506
        }
507
508
        if (skipSide != EnumFacing.DOWN)
509
        {
510
            this.notifyBlockOfStateChange(pos.down(), blockType);
511
        }
512
513
        if (skipSide != EnumFacing.UP)
514
        {
515
            this.notifyBlockOfStateChange(pos.up(), blockType);
516
        }
517
518
        if (skipSide != EnumFacing.NORTH)
519
        {
520
            this.notifyBlockOfStateChange(pos.north(), blockType);
521
        }
522
523
        if (skipSide != EnumFacing.SOUTH)
524
        {
525
            this.notifyBlockOfStateChange(pos.south(), blockType);
526
        }
527
    }
528
529
    public void notifyBlockOfStateChange(BlockPos pos, final Block blockIn)
530
    {
531
        if (!this.isRemote)
532
        {
533
            IBlockState iblockstate = this.getBlockState(pos);
534
535
            try
536
            {
537
                iblockstate.getBlock().onNeighborBlockChange(this, pos, iblockstate, blockIn);
538
            }
539
            catch (Throwable throwable)
540
            {
541
                CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Exception while updating neighbours");
542
                CrashReportCategory crashreportcategory = crashreport.makeCategory("Block being updated");
543
                crashreportcategory.addCrashSectionCallable("Source block type", new Callable<String>()
544
                {
545
                    public String call() throws Exception
546
                    {
547
                        try
548
                        {
549
                            return String.format("ID #%d (%s // %s)", new Object[] {Integer.valueOf(Block.getIdFromBlock(blockIn)), blockIn.getUnlocalizedName(), blockIn.getClass().getCanonicalName()});
550
                        }
551
                        catch (Throwable var2)
552
                        {
553
                            return "ID #" + Block.getIdFromBlock(blockIn);
554
                        }
555
                    }
556
                });
557
                CrashReportCategory.addBlockInfo(crashreportcategory, pos, iblockstate);
558
                throw new ReportedException(crashreport);
559
            }
560
        }
561
    }
562
563
    public boolean isBlockTickPending(BlockPos pos, Block blockType)
564
    {
565
        return false;
566
    }
567
568
    public boolean canSeeSky(BlockPos pos)
569
    {
570
        return this.getChunkFromBlockCoords(pos).canSeeSky(pos);
571
    }
572
573
    public boolean canBlockSeeSky(BlockPos pos)
574
    {
575
        if (pos.getY() >= this.getSeaLevel())
576
        {
577
            return this.canSeeSky(pos);
578
        }
579
        else
580
        {
581
            BlockPos blockpos = new BlockPos(pos.getX(), this.getSeaLevel(), pos.getZ());
582
583
            if (!this.canSeeSky(blockpos))
584
            {
585
                return false;
586
            }
587
            else
588
            {
589
                for (blockpos = blockpos.down(); blockpos.getY() > pos.getY(); blockpos = blockpos.down())
590
                {
591
                    Block block = this.getBlockState(blockpos).getBlock();
592
593
                    if (block.getLightOpacity() > 0 && !block.getMaterial().isLiquid())
594
                    {
595
                        return false;
596
                    }
597
                }
598
599
                return true;
600
            }
601
        }
602
    }
603
604
    public int getLight(BlockPos pos)
605
    {
606
        if (pos.getY() < 0)
607
        {
608
            return 0;
609
        }
610
        else
611
        {
612
            if (pos.getY() >= 256)
613
            {
614
                pos = new BlockPos(pos.getX(), 255, pos.getZ());
615
            }
616
617
            return this.getChunkFromBlockCoords(pos).getLightSubtracted(pos, 0);
618
        }
619
    }
620
621
    public int getLightFromNeighbors(BlockPos pos)
622
    {
623
        return this.getLight(pos, true);
624
    }
625
626
    public int getLight(BlockPos pos, boolean checkNeighbors)
627
    {
628
        if (pos.getX() >= -30000000 && pos.getZ() >= -30000000 && pos.getX() < 30000000 && pos.getZ() < 30000000)
629
        {
630
            if (checkNeighbors && this.getBlockState(pos).getBlock().getUseNeighborBrightness())
631
            {
632
                int i1 = this.getLight(pos.up(), false);
633
                int i = this.getLight(pos.east(), false);
634
                int j = this.getLight(pos.west(), false);
635
                int k = this.getLight(pos.south(), false);
636
                int l = this.getLight(pos.north(), false);
637
638
                if (i > i1)
639
                {
640
                    i1 = i;
641
                }
642
643
                if (j > i1)
644
                {
645
                    i1 = j;
646
                }
647
648
                if (k > i1)
649
                {
650
                    i1 = k;
651
                }
652
653
                if (l > i1)
654
                {
655
                    i1 = l;
656
                }
657
658
                return i1;
659
            }
660
            else if (pos.getY() < 0)
661
            {
662
                return 0;
663
            }
664
            else
665
            {
666
                if (pos.getY() >= 256)
667
                {
668
                    pos = new BlockPos(pos.getX(), 255, pos.getZ());
669
                }
670
671
                Chunk chunk = this.getChunkFromBlockCoords(pos);
672
                return chunk.getLightSubtracted(pos, this.skylightSubtracted);
673
            }
674
        }
675
        else
676
        {
677
            return 15;
678
        }
679
    }
680
681
    /**
682
     * Returns the position at this x, z coordinate in the chunk with y set to the value from the height map.
683
     */
684
    public BlockPos getHeight(BlockPos pos)
685
    {
686
        int i;
687
688
        if (pos.getX() >= -30000000 && pos.getZ() >= -30000000 && pos.getX() < 30000000 && pos.getZ() < 30000000)
689
        {
690
            if (this.isChunkLoaded(pos.getX() >> 4, pos.getZ() >> 4, true))
691
            {
692
                i = this.getChunkFromChunkCoords(pos.getX() >> 4, pos.getZ() >> 4).getHeightValue(pos.getX() & 15, pos.getZ() & 15);
693
            }
694
            else
695
            {
696
                i = 0;
697
            }
698
        }
699
        else
700
        {
701
            i = this.getSeaLevel() + 1;
702
        }
703
704
        return new BlockPos(pos.getX(), i, pos.getZ());
705
    }
706
707
    /**
708
     * Gets the lowest height of the chunk where sunlight directly reaches
709
     */
710
    public int getChunksLowestHorizon(int x, int z)
711
    {
712
        if (x >= -30000000 && z >= -30000000 && x < 30000000 && z < 30000000)
713
        {
714
            if (!this.isChunkLoaded(x >> 4, z >> 4, true))
715
            {
716
                return 0;
717
            }
718
            else
719
            {
720
                Chunk chunk = this.getChunkFromChunkCoords(x >> 4, z >> 4);
721
                return chunk.getLowestHeight();
722
            }
723
        }
724
        else
725
        {
726
            return this.getSeaLevel() + 1;
727
        }
728
    }
729
730
    public int getLightFromNeighborsFor(EnumSkyBlock type, BlockPos pos)
731
    {
732
        if (this.provider.getHasNoSky() && type == EnumSkyBlock.SKY)
733
        {
734
            return 0;
735
        }
736
        else
737
        {
738
            if (pos.getY() < 0)
739
            {
740
                pos = new BlockPos(pos.getX(), 0, pos.getZ());
741
            }
742
743
            if (!this.isValid(pos))
744
            {
745
                return type.defaultLightValue;
746
            }
747
            else if (!this.isBlockLoaded(pos))
748
            {
749
                return type.defaultLightValue;
750
            }
751
            else if (this.getBlockState(pos).getBlock().getUseNeighborBrightness())
752
            {
753
                int i1 = this.getLightFor(type, pos.up());
754
                int i = this.getLightFor(type, pos.east());
755
                int j = this.getLightFor(type, pos.west());
756
                int k = this.getLightFor(type, pos.south());
757
                int l = this.getLightFor(type, pos.north());
758
759
                if (i > i1)
760
                {
761
                    i1 = i;
762
                }
763
764
                if (j > i1)
765
                {
766
                    i1 = j;
767
                }
768
769
                if (k > i1)
770
                {
771
                    i1 = k;
772
                }
773
774
                if (l > i1)
775
                {
776
                    i1 = l;
777
                }
778
779
                return i1;
780
            }
781
            else
782
            {
783
                Chunk chunk = this.getChunkFromBlockCoords(pos);
784
                return chunk.getLightFor(type, pos);
785
            }
786
        }
787
    }
788
789
    public int getLightFor(EnumSkyBlock type, BlockPos pos)
790
    {
791
        if (pos.getY() < 0)
792
        {
793
            pos = new BlockPos(pos.getX(), 0, pos.getZ());
794
        }
795
796
        if (!this.isValid(pos))
797
        {
798
            return type.defaultLightValue;
799
        }
800
        else if (!this.isBlockLoaded(pos))
801
        {
802
            return type.defaultLightValue;
803
        }
804
        else
805
        {
806
            Chunk chunk = this.getChunkFromBlockCoords(pos);
807
            return chunk.getLightFor(type, pos);
808
        }
809
    }
810
811
    public void setLightFor(EnumSkyBlock type, BlockPos pos, int lightValue)
812
    {
813
        if (this.isValid(pos))
814
        {
815
            if (this.isBlockLoaded(pos))
816
            {
817
                Chunk chunk = this.getChunkFromBlockCoords(pos);
818
                chunk.setLightFor(type, pos, lightValue);
819
                this.notifyLightSet(pos);
820
            }
821
        }
822
    }
823
824
    public void notifyLightSet(BlockPos pos)
825
    {
826
        for (int i = 0; i < this.worldAccesses.size(); ++i)
827
        {
828
            ((IWorldAccess)this.worldAccesses.get(i)).notifyLightSet(pos);
829
        }
830
    }
831
832
    public int getCombinedLight(BlockPos pos, int lightValue)
833
    {
834
        int i = this.getLightFromNeighborsFor(EnumSkyBlock.SKY, pos);
835
        int j = this.getLightFromNeighborsFor(EnumSkyBlock.BLOCK, pos);
836
837
        if (j < lightValue)
838
        {
839
            j = lightValue;
840
        }
841
842
        return i << 20 | j << 4;
843
    }
844
845
    public float getLightBrightness(BlockPos pos)
846
    {
847
        return this.provider.getLightBrightnessTable()[this.getLightFromNeighbors(pos)];
848
    }
849
850
    public IBlockState getBlockState(BlockPos pos)
851
    {
852
        if (!this.isValid(pos))
853
        {
854
            return Blocks.air.getDefaultState();
855
        }
856
        else
857
        {
858
            Chunk chunk = this.getChunkFromBlockCoords(pos);
859
            return chunk.getBlockState(pos);
860
        }
861
    }
862
863
    /**
864
     * Checks whether its daytime by seeing if the light subtracted from the skylight is less than 4
865
     */
866
    public boolean isDaytime()
867
    {
868
        return this.skylightSubtracted < 4;
869
    }
870
871
    /**
872
     * ray traces all blocks, including non-collideable ones
873
     */
874
    public MovingObjectPosition rayTraceBlocks(Vec3 p_72933_1_, Vec3 p_72933_2_)
875
    {
876
        return this.rayTraceBlocks(p_72933_1_, p_72933_2_, false, false, false);
877
    }
878
879
    public MovingObjectPosition rayTraceBlocks(Vec3 start, Vec3 end, boolean stopOnLiquid)
880
    {
881
        return this.rayTraceBlocks(start, end, stopOnLiquid, false, false);
882
    }
883
884
    /**
885
     * Performs a raycast against all blocks in the world. Args : Vec1, Vec2, stopOnLiquid,
886
     * ignoreBlockWithoutBoundingBox, returnLastUncollidableBlock
887
     */
888
    public MovingObjectPosition rayTraceBlocks(Vec3 vec31, Vec3 vec32, boolean stopOnLiquid, boolean ignoreBlockWithoutBoundingBox, boolean returnLastUncollidableBlock)
889
    {
890
        if (!Double.isNaN(vec31.xCoord) && !Double.isNaN(vec31.yCoord) && !Double.isNaN(vec31.zCoord))
891
        {
892
            if (!Double.isNaN(vec32.xCoord) && !Double.isNaN(vec32.yCoord) && !Double.isNaN(vec32.zCoord))
893
            {
894
                int i = MathHelper.floor_double(vec32.xCoord);
895
                int j = MathHelper.floor_double(vec32.yCoord);
896
                int k = MathHelper.floor_double(vec32.zCoord);
897
                int l = MathHelper.floor_double(vec31.xCoord);
898
                int i1 = MathHelper.floor_double(vec31.yCoord);
899
                int j1 = MathHelper.floor_double(vec31.zCoord);
900
                BlockPos blockpos = new BlockPos(l, i1, j1);
901
                IBlockState iblockstate = this.getBlockState(blockpos);
902
                Block block = iblockstate.getBlock();
903
904
                if ((!ignoreBlockWithoutBoundingBox || block.getCollisionBoundingBox(this, blockpos, iblockstate) != null) && block.canCollideCheck(iblockstate, stopOnLiquid))
905
                {
906
                    MovingObjectPosition movingobjectposition = block.collisionRayTrace(this, blockpos, vec31, vec32);
907
908
                    if (movingobjectposition != null)
909
                    {
910
                        return movingobjectposition;
911
                    }
912
                }
913
914
                MovingObjectPosition movingobjectposition2 = null;
915
                int k1 = 200;
916
917
                while (k1-- >= 0)
918
                {
919
                    if (Double.isNaN(vec31.xCoord) || Double.isNaN(vec31.yCoord) || Double.isNaN(vec31.zCoord))
920
                    {
921
                        return null;
922
                    }
923
924
                    if (l == i && i1 == j && j1 == k)
925
                    {
926
                        return returnLastUncollidableBlock ? movingobjectposition2 : null;
927
                    }
928
929
                    boolean flag2 = true;
930
                    boolean flag = true;
931
                    boolean flag1 = true;
932
                    double d0 = 999.0D;
933
                    double d1 = 999.0D;
934
                    double d2 = 999.0D;
935
936
                    if (i > l)
937
                    {
938
                        d0 = (double)l + 1.0D;
939
                    }
940
                    else if (i < l)
941
                    {
942
                        d0 = (double)l + 0.0D;
943
                    }
944
                    else
945
                    {
946
                        flag2 = false;
947
                    }
948
949
                    if (j > i1)
950
                    {
951
                        d1 = (double)i1 + 1.0D;
952
                    }
953
                    else if (j < i1)
954
                    {
955
                        d1 = (double)i1 + 0.0D;
956
                    }
957
                    else
958
                    {
959
                        flag = false;
960
                    }
961
962
                    if (k > j1)
963
                    {
964
                        d2 = (double)j1 + 1.0D;
965
                    }
966
                    else if (k < j1)
967
                    {
968
                        d2 = (double)j1 + 0.0D;
969
                    }
970
                    else
971
                    {
972
                        flag1 = false;
973
                    }
974
975
                    double d3 = 999.0D;
976
                    double d4 = 999.0D;
977
                    double d5 = 999.0D;
978
                    double d6 = vec32.xCoord - vec31.xCoord;
979
                    double d7 = vec32.yCoord - vec31.yCoord;
980
                    double d8 = vec32.zCoord - vec31.zCoord;
981
982
                    if (flag2)
983
                    {
984
                        d3 = (d0 - vec31.xCoord) / d6;
985
                    }
986
987
                    if (flag)
988
                    {
989
                        d4 = (d1 - vec31.yCoord) / d7;
990
                    }
991
992
                    if (flag1)
993
                    {
994
                        d5 = (d2 - vec31.zCoord) / d8;
995
                    }
996
997
                    if (d3 == -0.0D)
998
                    {
999
                        d3 = -1.0E-4D;
1000
                    }
1001
1002
                    if (d4 == -0.0D)
1003
                    {
1004
                        d4 = -1.0E-4D;
1005
                    }
1006
1007
                    if (d5 == -0.0D)
1008
                    {
1009
                        d5 = -1.0E-4D;
1010
                    }
1011
1012
                    EnumFacing enumfacing;
1013
1014
                    if (d3 < d4 && d3 < d5)
1015
                    {
1016
                        enumfacing = i > l ? EnumFacing.WEST : EnumFacing.EAST;
1017
                        vec31 = new Vec3(d0, vec31.yCoord + d7 * d3, vec31.zCoord + d8 * d3);
1018
                    }
1019
                    else if (d4 < d5)
1020
                    {
1021
                        enumfacing = j > i1 ? EnumFacing.DOWN : EnumFacing.UP;
1022
                        vec31 = new Vec3(vec31.xCoord + d6 * d4, d1, vec31.zCoord + d8 * d4);
1023
                    }
1024
                    else
1025
                    {
1026
                        enumfacing = k > j1 ? EnumFacing.NORTH : EnumFacing.SOUTH;
1027
                        vec31 = new Vec3(vec31.xCoord + d6 * d5, vec31.yCoord + d7 * d5, d2);
1028
                    }
1029
1030
                    l = MathHelper.floor_double(vec31.xCoord) - (enumfacing == EnumFacing.EAST ? 1 : 0);
1031
                    i1 = MathHelper.floor_double(vec31.yCoord) - (enumfacing == EnumFacing.UP ? 1 : 0);
1032
                    j1 = MathHelper.floor_double(vec31.zCoord) - (enumfacing == EnumFacing.SOUTH ? 1 : 0);
1033
                    blockpos = new BlockPos(l, i1, j1);
1034
                    IBlockState iblockstate1 = this.getBlockState(blockpos);
1035
                    Block block1 = iblockstate1.getBlock();
1036
1037
                    if (!ignoreBlockWithoutBoundingBox || block1.getCollisionBoundingBox(this, blockpos, iblockstate1) != null)
1038
                    {
1039
                        if (block1.canCollideCheck(iblockstate1, stopOnLiquid))
1040
                        {
1041
                            MovingObjectPosition movingobjectposition1 = block1.collisionRayTrace(this, blockpos, vec31, vec32);
1042
1043
                            if (movingobjectposition1 != null)
1044
                            {
1045
                                return movingobjectposition1;
1046
                            }
1047
                        }
1048
                        else
1049
                        {
1050
                            movingobjectposition2 = new MovingObjectPosition(MovingObjectPosition.MovingObjectType.MISS, vec31, enumfacing, blockpos);
1051
                        }
1052
                    }
1053
                }
1054
1055
                return returnLastUncollidableBlock ? movingobjectposition2 : null;
1056
            }
1057
            else
1058
            {
1059
                return null;
1060
            }
1061
        }
1062
        else
1063
        {
1064
            return null;
1065
        }
1066
    }
1067
1068
    /**
1069
     * Plays a sound at the entity's position. Args: entity, sound, volume (relative to 1.0), and frequency (or pitch,
1070
     * also relative to 1.0).
1071
     */
1072
    public void playSoundAtEntity(Entity entityIn, String name, float volume, float pitch)
1073
    {
1074
        for (int i = 0; i < this.worldAccesses.size(); ++i)
1075
        {
1076
            ((IWorldAccess)this.worldAccesses.get(i)).playSound(name, entityIn.posX, entityIn.posY, entityIn.posZ, volume, pitch);
1077
        }
1078
    }
1079
1080
    /**
1081
     * Plays sound to all near players except the player reference given
1082
     */
1083
    public void playSoundToNearExcept(EntityPlayer player, String name, float volume, float pitch)
1084
    {
1085
        for (int i = 0; i < this.worldAccesses.size(); ++i)
1086
        {
1087
            ((IWorldAccess)this.worldAccesses.get(i)).playSoundToNearExcept(player, name, player.posX, player.posY, player.posZ, volume, pitch);
1088
        }
1089
    }
1090
1091
    /**
1092
     * Play a sound effect. Many many parameters for this function. Not sure what they do, but a classic call is :
1093
     * (double)i + 0.5D, (double)j + 0.5D, (double)k + 0.5D, 'random.door_open', 1.0F, world.rand.nextFloat() * 0.1F +
1094
     * 0.9F with i,j,k position of the block.
1095
     */
1096
    public void playSoundEffect(double x, double y, double z, String soundName, float volume, float pitch)
1097
    {
1098
        for (int i = 0; i < this.worldAccesses.size(); ++i)
1099
        {
1100
            ((IWorldAccess)this.worldAccesses.get(i)).playSound(soundName, x, y, z, volume, pitch);
1101
        }
1102
    }
1103
1104
    /**
1105
     * par8 is loudness, all pars passed to minecraftInstance.sndManager.playSound
1106
     */
1107
    public void playSound(double x, double y, double z, String soundName, float volume, float pitch, boolean distanceDelay)
1108
    {
1109
    }
1110
1111
    public void playRecord(BlockPos pos, String name)
1112
    {
1113
        for (int i = 0; i < this.worldAccesses.size(); ++i)
1114
        {
1115
            ((IWorldAccess)this.worldAccesses.get(i)).playRecord(name, pos);
1116
        }
1117
    }
1118
1119
    public void spawnParticle(EnumParticleTypes particleType, double xCoord, double yCoord, double zCoord, double xOffset, double yOffset, double zOffset, int... p_175688_14_)
1120
    {
1121
        this.spawnParticle(particleType.getParticleID(), particleType.getShouldIgnoreRange(), xCoord, yCoord, zCoord, xOffset, yOffset, zOffset, p_175688_14_);
1122
    }
1123
1124
    public void spawnParticle(EnumParticleTypes particleType, boolean p_175682_2_, double xCoord, double yCoord, double zCoord, double xOffset, double yOffset, double zOffset, int... p_175682_15_)
1125
    {
1126
        this.spawnParticle(particleType.getParticleID(), particleType.getShouldIgnoreRange() | p_175682_2_, xCoord, yCoord, zCoord, xOffset, yOffset, zOffset, p_175682_15_);
1127
    }
1128
1129
    private void spawnParticle(int particleID, boolean p_175720_2_, double xCood, double yCoord, double zCoord, double xOffset, double yOffset, double zOffset, int... p_175720_15_)
1130
    {
1131
        for (int i = 0; i < this.worldAccesses.size(); ++i)
1132
        {
1133
            ((IWorldAccess)this.worldAccesses.get(i)).spawnParticle(particleID, p_175720_2_, xCood, yCoord, zCoord, xOffset, yOffset, zOffset, p_175720_15_);
1134
        }
1135
    }
1136
1137
    /**
1138
     * adds a lightning bolt to the list of lightning bolts in this world.
1139
     */
1140
    public boolean addWeatherEffect(Entity entityIn)
1141
    {
1142
        this.weatherEffects.add(entityIn);
1143
        return true;
1144
    }
1145
1146
    /**
1147
     * Called when an entity is spawned in the world. This includes players.
1148
     */
1149
    public boolean spawnEntityInWorld(Entity entityIn)
1150
    {
1151
        int i = MathHelper.floor_double(entityIn.posX / 16.0D);
1152
        int j = MathHelper.floor_double(entityIn.posZ / 16.0D);
1153
        boolean flag = entityIn.forceSpawn;
1154
1155
        if (entityIn instanceof EntityPlayer)
1156
        {
1157
            flag = true;
1158
        }
1159
1160
        if (!flag && !this.isChunkLoaded(i, j, true))
1161
        {
1162
            return false;
1163
        }
1164
        else
1165
        {
1166
            if (entityIn instanceof EntityPlayer)
1167
            {
1168
                EntityPlayer entityplayer = (EntityPlayer)entityIn;
1169
                this.playerEntities.add(entityplayer);
1170
                this.updateAllPlayersSleepingFlag();
1171
            }
1172
1173
            this.getChunkFromChunkCoords(i, j).addEntity(entityIn);
1174
            this.loadedEntityList.add(entityIn);
1175
            this.onEntityAdded(entityIn);
1176
            return true;
1177
        }
1178
    }
1179
1180
    protected void onEntityAdded(Entity entityIn)
1181
    {
1182
        for (int i = 0; i < this.worldAccesses.size(); ++i)
1183
        {
1184
            ((IWorldAccess)this.worldAccesses.get(i)).onEntityAdded(entityIn);
1185
        }
1186
    }
1187
1188
    protected void onEntityRemoved(Entity entityIn)
1189
    {
1190
        for (int i = 0; i < this.worldAccesses.size(); ++i)
1191
        {
1192
            ((IWorldAccess)this.worldAccesses.get(i)).onEntityRemoved(entityIn);
1193
        }
1194
    }
1195
1196
    /**
1197
     * Schedule the entity for removal during the next tick. Marks the entity dead in anticipation.
1198
     */
1199
    public void removeEntity(Entity entityIn)
1200
    {
1201
        if (entityIn.riddenByEntity != null)
1202
        {
1203
            entityIn.riddenByEntity.mountEntity((Entity)null);
1204
        }
1205
1206
        if (entityIn.ridingEntity != null)
1207
        {
1208
            entityIn.mountEntity((Entity)null);
1209
        }
1210
1211
        entityIn.setDead();
1212
1213
        if (entityIn instanceof EntityPlayer)
1214
        {
1215
            this.playerEntities.remove(entityIn);
1216
            this.updateAllPlayersSleepingFlag();
1217
            this.onEntityRemoved(entityIn);
1218
        }
1219
    }
1220
1221
    /**
1222
     * Do NOT use this method to remove normal entities- use normal removeEntity
1223
     */
1224
    public void removePlayerEntityDangerously(Entity entityIn)
1225
    {
1226
        entityIn.setDead();
1227
1228
        if (entityIn instanceof EntityPlayer)
1229
        {
1230
            this.playerEntities.remove(entityIn);
1231
            this.updateAllPlayersSleepingFlag();
1232
        }
1233
1234
        int i = entityIn.chunkCoordX;
1235
        int j = entityIn.chunkCoordZ;
1236
1237
        if (entityIn.addedToChunk && this.isChunkLoaded(i, j, true))
1238
        {
1239
            this.getChunkFromChunkCoords(i, j).removeEntity(entityIn);
1240
        }
1241
1242
        this.loadedEntityList.remove(entityIn);
1243
        this.onEntityRemoved(entityIn);
1244
    }
1245
1246
    /**
1247
     * Adds a IWorldAccess to the list of worldAccesses
1248
     */
1249
    public void addWorldAccess(IWorldAccess worldAccess)
1250
    {
1251
        this.worldAccesses.add(worldAccess);
1252
    }
1253
1254
    /**
1255
     * Removes a worldAccess from the worldAccesses object
1256
     */
1257
    public void removeWorldAccess(IWorldAccess worldAccess)
1258
    {
1259
        this.worldAccesses.remove(worldAccess);
1260
    }
1261
1262
    public List<AxisAlignedBB> getCollidingBoundingBoxes(Entity entityIn, AxisAlignedBB bb)
1263
    {
1264
        List<AxisAlignedBB> list = Lists.<AxisAlignedBB>newArrayList();
1265
        int i = MathHelper.floor_double(bb.minX);
1266
        int j = MathHelper.floor_double(bb.maxX + 1.0D);
1267
        int k = MathHelper.floor_double(bb.minY);
1268
        int l = MathHelper.floor_double(bb.maxY + 1.0D);
1269
        int i1 = MathHelper.floor_double(bb.minZ);
1270
        int j1 = MathHelper.floor_double(bb.maxZ + 1.0D);
1271
        WorldBorder worldborder = this.getWorldBorder();
1272
        boolean flag = entityIn.isOutsideBorder();
1273
        boolean flag1 = this.isInsideBorder(worldborder, entityIn);
1274
        IBlockState iblockstate = Blocks.stone.getDefaultState();
1275
        BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();
1276
1277
        for (int k1 = i; k1 < j; ++k1)
1278
        {
1279
            for (int l1 = i1; l1 < j1; ++l1)
1280
            {
1281
                if (this.isBlockLoaded(blockpos$mutableblockpos.set(k1, 64, l1)))
1282
                {
1283
                    for (int i2 = k - 1; i2 < l; ++i2)
1284
                    {
1285
                        blockpos$mutableblockpos.set(k1, i2, l1);
1286
1287
                        if (flag && flag1)
1288
                        {
1289
                            entityIn.setOutsideBorder(false);
1290
                        }
1291
                        else if (!flag && !flag1)
1292
                        {
1293
                            entityIn.setOutsideBorder(true);
1294
                        }
1295
1296
                        IBlockState iblockstate1 = iblockstate;
1297
1298
                        if (worldborder.contains(blockpos$mutableblockpos) || !flag1)
1299
                        {
1300
                            iblockstate1 = this.getBlockState(blockpos$mutableblockpos);
1301
                        }
1302
1303
                        iblockstate1.getBlock().addCollisionBoxesToList(this, blockpos$mutableblockpos, iblockstate1, bb, list, entityIn);
1304
                    }
1305
                }
1306
            }
1307
        }
1308
1309
        double d0 = 0.25D;
1310
        List<Entity> list1 = this.getEntitiesWithinAABBExcludingEntity(entityIn, bb.expand(d0, d0, d0));
1311
1312
        for (int j2 = 0; j2 < list1.size(); ++j2)
1313
        {
1314
            if (entityIn.riddenByEntity != list1 && entityIn.ridingEntity != list1)
1315
            {
1316
                AxisAlignedBB axisalignedbb = ((Entity)list1.get(j2)).getCollisionBoundingBox();
1317
1318
                if (axisalignedbb != null && axisalignedbb.intersectsWith(bb))
1319
                {
1320
                    list.add(axisalignedbb);
1321
                }
1322
1323
                axisalignedbb = entityIn.getCollisionBox((Entity)list1.get(j2));
1324
1325
                if (axisalignedbb != null && axisalignedbb.intersectsWith(bb))
1326
                {
1327
                    list.add(axisalignedbb);
1328
                }
1329
            }
1330
        }
1331
1332
        return list;
1333
    }
1334
1335
    public boolean isInsideBorder(WorldBorder worldBorderIn, Entity entityIn)
1336
    {
1337
        double d0 = worldBorderIn.minX();
1338
        double d1 = worldBorderIn.minZ();
1339
        double d2 = worldBorderIn.maxX();
1340
        double d3 = worldBorderIn.maxZ();
1341
1342
        if (entityIn.isOutsideBorder())
1343
        {
1344
            ++d0;
1345
            ++d1;
1346
            --d2;
1347
            --d3;
1348
        }
1349
        else
1350
        {
1351
            --d0;
1352
            --d1;
1353
            ++d2;
1354
            ++d3;
1355
        }
1356
1357
        return entityIn.posX > d0 && entityIn.posX < d2 && entityIn.posZ > d1 && entityIn.posZ < d3;
1358
    }
1359
1360
    public List<AxisAlignedBB> getCollisionBoxes(AxisAlignedBB bb)
1361
    {
1362
        List<AxisAlignedBB> list = Lists.<AxisAlignedBB>newArrayList();
1363
        int i = MathHelper.floor_double(bb.minX);
1364
        int j = MathHelper.floor_double(bb.maxX + 1.0D);
1365
        int k = MathHelper.floor_double(bb.minY);
1366
        int l = MathHelper.floor_double(bb.maxY + 1.0D);
1367
        int i1 = MathHelper.floor_double(bb.minZ);
1368
        int j1 = MathHelper.floor_double(bb.maxZ + 1.0D);
1369
        BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();
1370
1371
        for (int k1 = i; k1 < j; ++k1)
1372
        {
1373
            for (int l1 = i1; l1 < j1; ++l1)
1374
            {
1375
                if (this.isBlockLoaded(blockpos$mutableblockpos.set(k1, 64, l1)))
1376
                {
1377
                    for (int i2 = k - 1; i2 < l; ++i2)
1378
                    {
1379
                        blockpos$mutableblockpos.set(k1, i2, l1);
1380
                        IBlockState iblockstate;
1381
1382
                        if (k1 >= -30000000 && k1 < 30000000 && l1 >= -30000000 && l1 < 30000000)
1383
                        {
1384
                            iblockstate = this.getBlockState(blockpos$mutableblockpos);
1385
                        }
1386
                        else
1387
                        {
1388
                            iblockstate = Blocks.bedrock.getDefaultState();
1389
                        }
1390
1391
                        iblockstate.getBlock().addCollisionBoxesToList(this, blockpos$mutableblockpos, iblockstate, bb, list, (Entity)null);
1392
                    }
1393
                }
1394
            }
1395
        }
1396
1397
        return list;
1398
    }
1399
1400
    /**
1401
     * Returns the amount of skylight subtracted for the current time
1402
     */
1403
    public int calculateSkylightSubtracted(float p_72967_1_)
1404
    {
1405
        float f = this.getCelestialAngle(p_72967_1_);
1406
        float f1 = 1.0F - (MathHelper.cos(f * (float)Math.PI * 2.0F) * 2.0F + 0.5F);
1407
        f1 = MathHelper.clamp_float(f1, 0.0F, 1.0F);
1408
        f1 = 1.0F - f1;
1409
        f1 = (float)((double)f1 * (1.0D - (double)(this.getRainStrength(p_72967_1_) * 5.0F) / 16.0D));
1410
        f1 = (float)((double)f1 * (1.0D - (double)(this.getThunderStrength(p_72967_1_) * 5.0F) / 16.0D));
1411
        f1 = 1.0F - f1;
1412
        return (int)(f1 * 11.0F);
1413
    }
1414
1415
    /**
1416
     * Returns the sun brightness - checks time of day, rain and thunder
1417
     */
1418
    public float getSunBrightness(float p_72971_1_)
1419
    {
1420
        float f = this.getCelestialAngle(p_72971_1_);
1421
        float f1 = 1.0F - (MathHelper.cos(f * (float)Math.PI * 2.0F) * 2.0F + 0.2F);
1422
        f1 = MathHelper.clamp_float(f1, 0.0F, 1.0F);
1423
        f1 = 1.0F - f1;
1424
        f1 = (float)((double)f1 * (1.0D - (double)(this.getRainStrength(p_72971_1_) * 5.0F) / 16.0D));
1425
        f1 = (float)((double)f1 * (1.0D - (double)(this.getThunderStrength(p_72971_1_) * 5.0F) / 16.0D));
1426
        return f1 * 0.8F + 0.2F;
1427
    }
1428
1429
    /**
1430
     * Calculates the color for the skybox
1431
     */
1432
    public Vec3 getSkyColor(Entity entityIn, float partialTicks)
1433
    {
1434
        float f = this.getCelestialAngle(partialTicks);
1435
        float f1 = MathHelper.cos(f * (float)Math.PI * 2.0F) * 2.0F + 0.5F;
1436
        f1 = MathHelper.clamp_float(f1, 0.0F, 1.0F);
1437
        int i = MathHelper.floor_double(entityIn.posX);
1438
        int j = MathHelper.floor_double(entityIn.posY);
1439
        int k = MathHelper.floor_double(entityIn.posZ);
1440
        BlockPos blockpos = new BlockPos(i, j, k);
1441
        BiomeGenBase biomegenbase = this.getBiomeGenForCoords(blockpos);
1442
        float f2 = biomegenbase.getFloatTemperature(blockpos);
1443
        int l = biomegenbase.getSkyColorByTemp(f2);
1444
        float f3 = (float)(l >> 16 & 255) / 255.0F;
1445
        float f4 = (float)(l >> 8 & 255) / 255.0F;
1446
        float f5 = (float)(l & 255) / 255.0F;
1447
        f3 = f3 * f1;
1448
        f4 = f4 * f1;
1449
        f5 = f5 * f1;
1450
        float f6 = this.getRainStrength(partialTicks);
1451
1452
        if (f6 > 0.0F)
1453
        {
1454
            float f7 = (f3 * 0.3F + f4 * 0.59F + f5 * 0.11F) * 0.6F;
1455
            float f8 = 1.0F - f6 * 0.75F;
1456
            f3 = f3 * f8 + f7 * (1.0F - f8);
1457
            f4 = f4 * f8 + f7 * (1.0F - f8);
1458
            f5 = f5 * f8 + f7 * (1.0F - f8);
1459
        }
1460
1461
        float f10 = this.getThunderStrength(partialTicks);
1462
1463
        if (f10 > 0.0F)
1464
        {
1465
            float f11 = (f3 * 0.3F + f4 * 0.59F + f5 * 0.11F) * 0.2F;
1466
            float f9 = 1.0F - f10 * 0.75F;
1467
            f3 = f3 * f9 + f11 * (1.0F - f9);
1468
            f4 = f4 * f9 + f11 * (1.0F - f9);
1469
            f5 = f5 * f9 + f11 * (1.0F - f9);
1470
        }
1471
1472
        if (this.lastLightningBolt > 0)
1473
        {
1474
            float f12 = (float)this.lastLightningBolt - partialTicks;
1475
1476
            if (f12 > 1.0F)
1477
            {
1478
                f12 = 1.0F;
1479
            }
1480
1481
            f12 = f12 * 0.45F;
1482
            f3 = f3 * (1.0F - f12) + 0.8F * f12;
1483
            f4 = f4 * (1.0F - f12) + 0.8F * f12;
1484
            f5 = f5 * (1.0F - f12) + 1.0F * f12;
1485
        }
1486
1487
        return new Vec3((double)f3, (double)f4, (double)f5);
1488
    }
1489
1490
    /**
1491
     * calls calculateCelestialAngle
1492
     */
1493
    public float getCelestialAngle(float partialTicks)
1494
    {
1495
        return this.provider.calculateCelestialAngle(this.worldInfo.getWorldTime(), partialTicks);
1496
    }
1497
1498
    public int getMoonPhase()
1499
    {
1500
        return this.provider.getMoonPhase(this.worldInfo.getWorldTime());
1501
    }
1502
1503
    /**
1504
     * gets the current fullness of the moon expressed as a float between 1.0 and 0.0, in steps of .25
1505
     */
1506
    public float getCurrentMoonPhaseFactor()
1507
    {
1508
        return WorldProvider.moonPhaseFactors[this.provider.getMoonPhase(this.worldInfo.getWorldTime())];
1509
    }
1510
1511
    /**
1512
     * Return getCelestialAngle()*2*PI
1513
     */
1514
    public float getCelestialAngleRadians(float partialTicks)
1515
    {
1516
        float f = this.getCelestialAngle(partialTicks);
1517
        return f * (float)Math.PI * 2.0F;
1518
    }
1519
1520
    public Vec3 getCloudColour(float partialTicks)
1521
    {
1522
        float f = this.getCelestialAngle(partialTicks);
1523
        float f1 = MathHelper.cos(f * (float)Math.PI * 2.0F) * 2.0F + 0.5F;
1524
        f1 = MathHelper.clamp_float(f1, 0.0F, 1.0F);
1525
        float f2 = (float)(this.cloudColour >> 16 & 255L) / 255.0F;
1526
        float f3 = (float)(this.cloudColour >> 8 & 255L) / 255.0F;
1527
        float f4 = (float)(this.cloudColour & 255L) / 255.0F;
1528
        float f5 = this.getRainStrength(partialTicks);
1529
1530
        if (f5 > 0.0F)
1531
        {
1532
            float f6 = (f2 * 0.3F + f3 * 0.59F + f4 * 0.11F) * 0.6F;
1533
            float f7 = 1.0F - f5 * 0.95F;
1534
            f2 = f2 * f7 + f6 * (1.0F - f7);
1535
            f3 = f3 * f7 + f6 * (1.0F - f7);
1536
            f4 = f4 * f7 + f6 * (1.0F - f7);
1537
        }
1538
1539
        f2 = f2 * (f1 * 0.9F + 0.1F);
1540
        f3 = f3 * (f1 * 0.9F + 0.1F);
1541
        f4 = f4 * (f1 * 0.85F + 0.15F);
1542
        float f9 = this.getThunderStrength(partialTicks);
1543
1544
        if (f9 > 0.0F)
1545
        {
1546
            float f10 = (f2 * 0.3F + f3 * 0.59F + f4 * 0.11F) * 0.2F;
1547
            float f8 = 1.0F - f9 * 0.95F;
1548
            f2 = f2 * f8 + f10 * (1.0F - f8);
1549
            f3 = f3 * f8 + f10 * (1.0F - f8);
1550
            f4 = f4 * f8 + f10 * (1.0F - f8);
1551
        }
1552
1553
        return new Vec3((double)f2, (double)f3, (double)f4);
1554
    }
1555
1556
    /**
1557
     * Returns vector(ish) with R/G/B for fog
1558
     */
1559
    public Vec3 getFogColor(float partialTicks)
1560
    {
1561
        float f = this.getCelestialAngle(partialTicks);
1562
        return this.provider.getFogColor(f, partialTicks);
1563
    }
1564
1565
    public BlockPos getPrecipitationHeight(BlockPos pos)
1566
    {
1567
        return this.getChunkFromBlockCoords(pos).getPrecipitationHeight(pos);
1568
    }
1569
1570
    /**
1571
     * Finds the highest block on the x and z coordinate that is solid or liquid, and returns its y coord.
1572
     */
1573
    public BlockPos getTopSolidOrLiquidBlock(BlockPos pos)
1574
    {
1575
        Chunk chunk = this.getChunkFromBlockCoords(pos);
1576
        BlockPos blockpos;
1577
        BlockPos blockpos1;
1578
1579
        for (blockpos = new BlockPos(pos.getX(), chunk.getTopFilledSegment() + 16, pos.getZ()); blockpos.getY() >= 0; blockpos = blockpos1)
1580
        {
1581
            blockpos1 = blockpos.down();
1582
            Material material = chunk.getBlock(blockpos1).getMaterial();
1583
1584
            if (material.blocksMovement() && material != Material.leaves)
1585
            {
1586
                break;
1587
            }
1588
        }
1589
1590
        return blockpos;
1591
    }
1592
1593
    /**
1594
     * How bright are stars in the sky
1595
     */
1596
    public float getStarBrightness(float partialTicks)
1597
    {
1598
        float f = this.getCelestialAngle(partialTicks);
1599
        float f1 = 1.0F - (MathHelper.cos(f * (float)Math.PI * 2.0F) * 2.0F + 0.25F);
1600
        f1 = MathHelper.clamp_float(f1, 0.0F, 1.0F);
1601
        return f1 * f1 * 0.5F;
1602
    }
1603
1604
    public void scheduleUpdate(BlockPos pos, Block blockIn, int delay)
1605
    {
1606
    }
1607
1608
    public void updateBlockTick(BlockPos pos, Block blockIn, int delay, int priority)
1609
    {
1610
    }
1611
1612
    public void scheduleBlockUpdate(BlockPos pos, Block blockIn, int delay, int priority)
1613
    {
1614
    }
1615
1616
    /**
1617
     * Updates (and cleans up) entities and tile entities
1618
     */
1619
    public void updateEntities()
1620
    {
1621
        this.theProfiler.startSection("entities");
1622
        this.theProfiler.startSection("global");
1623
1624
        for (int i = 0; i < this.weatherEffects.size(); ++i)
1625
        {
1626
            Entity entity = (Entity)this.weatherEffects.get(i);
1627
1628
            try
1629
            {
1630
                ++entity.ticksExisted;
1631
                entity.onUpdate();
1632
            }
1633
            catch (Throwable throwable2)
1634
            {
1635
                CrashReport crashreport = CrashReport.makeCrashReport(throwable2, "Ticking entity");
1636
                CrashReportCategory crashreportcategory = crashreport.makeCategory("Entity being ticked");
1637
1638
                if (entity == null)
1639
                {
1640
                    crashreportcategory.addCrashSection("Entity", "~~NULL~~");
1641
                }
1642
                else
1643
                {
1644
                    entity.addEntityCrashInfo(crashreportcategory);
1645
                }
1646
1647
                throw new ReportedException(crashreport);
1648
            }
1649
1650
            if (entity.isDead)
1651
            {
1652
                this.weatherEffects.remove(i--);
1653
            }
1654
        }
1655
1656
        this.theProfiler.endStartSection("remove");
1657
        this.loadedEntityList.removeAll(this.unloadedEntityList);
1658
1659
        for (int k = 0; k < this.unloadedEntityList.size(); ++k)
1660
        {
1661
            Entity entity1 = (Entity)this.unloadedEntityList.get(k);
1662
            int j = entity1.chunkCoordX;
1663
            int l1 = entity1.chunkCoordZ;
1664
1665
            if (entity1.addedToChunk && this.isChunkLoaded(j, l1, true))
1666
            {
1667
                this.getChunkFromChunkCoords(j, l1).removeEntity(entity1);
1668
            }
1669
        }
1670
1671
        for (int l = 0; l < this.unloadedEntityList.size(); ++l)
1672
        {
1673
            this.onEntityRemoved((Entity)this.unloadedEntityList.get(l));
1674
        }
1675
1676
        this.unloadedEntityList.clear();
1677
        this.theProfiler.endStartSection("regular");
1678
1679
        for (int i1 = 0; i1 < this.loadedEntityList.size(); ++i1)
1680
        {
1681
            Entity entity2 = (Entity)this.loadedEntityList.get(i1);
1682
1683
            if (entity2.ridingEntity != null)
1684
            {
1685
                if (!entity2.ridingEntity.isDead && entity2.ridingEntity.riddenByEntity == entity2)
1686
                {
1687
                    continue;
1688
                }
1689
1690
                entity2.ridingEntity.riddenByEntity = null;
1691
                entity2.ridingEntity = null;
1692
            }
1693
1694
            this.theProfiler.startSection("tick");
1695
1696
            if (!entity2.isDead)
1697
            {
1698
                try
1699
                {
1700
                    this.updateEntity(entity2);
1701
                }
1702
                catch (Throwable throwable1)
1703
                {
1704
                    CrashReport crashreport1 = CrashReport.makeCrashReport(throwable1, "Ticking entity");
1705
                    CrashReportCategory crashreportcategory2 = crashreport1.makeCategory("Entity being ticked");
1706
                    entity2.addEntityCrashInfo(crashreportcategory2);
1707
                    throw new ReportedException(crashreport1);
1708
                }
1709
            }
1710
1711
            this.theProfiler.endSection();
1712
            this.theProfiler.startSection("remove");
1713
1714
            if (entity2.isDead)
1715
            {
1716
                int k1 = entity2.chunkCoordX;
1717
                int i2 = entity2.chunkCoordZ;
1718
1719
                if (entity2.addedToChunk && this.isChunkLoaded(k1, i2, true))
1720
                {
1721
                    this.getChunkFromChunkCoords(k1, i2).removeEntity(entity2);
1722
                }
1723
1724
                this.loadedEntityList.remove(i1--);
1725
                this.onEntityRemoved(entity2);
1726
            }
1727
1728
            this.theProfiler.endSection();
1729
        }
1730
1731
        this.theProfiler.endStartSection("blockEntities");
1732
        this.processingLoadedTiles = true;
1733
        Iterator<TileEntity> iterator = this.tickableTileEntities.iterator();
1734
1735
        while (iterator.hasNext())
1736
        {
1737
            TileEntity tileentity = (TileEntity)iterator.next();
1738
1739
            if (!tileentity.isInvalid() && tileentity.hasWorldObj())
1740
            {
1741
                BlockPos blockpos = tileentity.getPos();
1742
1743
                if (this.isBlockLoaded(blockpos) && this.worldBorder.contains(blockpos))
1744
                {
1745
                    try
1746
                    {
1747
                        ((ITickable)tileentity).update();
1748
                    }
1749
                    catch (Throwable throwable)
1750
                    {
1751
                        CrashReport crashreport2 = CrashReport.makeCrashReport(throwable, "Ticking block entity");
1752
                        CrashReportCategory crashreportcategory1 = crashreport2.makeCategory("Block entity being ticked");
1753
                        tileentity.addInfoToCrashReport(crashreportcategory1);
1754
                        throw new ReportedException(crashreport2);
1755
                    }
1756
                }
1757
            }
1758
1759
            if (tileentity.isInvalid())
1760
            {
1761
                iterator.remove();
1762
                this.loadedTileEntityList.remove(tileentity);
1763
1764
                if (this.isBlockLoaded(tileentity.getPos()))
1765
                {
1766
                    this.getChunkFromBlockCoords(tileentity.getPos()).removeTileEntity(tileentity.getPos());
1767
                }
1768
            }
1769
        }
1770
1771
        this.processingLoadedTiles = false;
1772
1773
        if (!this.tileEntitiesToBeRemoved.isEmpty())
1774
        {
1775
            this.tickableTileEntities.removeAll(this.tileEntitiesToBeRemoved);
1776
            this.loadedTileEntityList.removeAll(this.tileEntitiesToBeRemoved);
1777
            this.tileEntitiesToBeRemoved.clear();
1778
        }
1779
1780
        this.theProfiler.endStartSection("pendingBlockEntities");
1781
1782
        if (!this.addedTileEntityList.isEmpty())
1783
        {
1784
            for (int j1 = 0; j1 < this.addedTileEntityList.size(); ++j1)
1785
            {
1786
                TileEntity tileentity1 = (TileEntity)this.addedTileEntityList.get(j1);
1787
1788
                if (!tileentity1.isInvalid())
1789
                {
1790
                    if (!this.loadedTileEntityList.contains(tileentity1))
1791
                    {
1792
                        this.addTileEntity(tileentity1);
1793
                    }
1794
1795
                    if (this.isBlockLoaded(tileentity1.getPos()))
1796
                    {
1797
                        this.getChunkFromBlockCoords(tileentity1.getPos()).addTileEntity(tileentity1.getPos(), tileentity1);
1798
                    }
1799
1800
                    this.markBlockForUpdate(tileentity1.getPos());
1801
                }
1802
            }
1803
1804
            this.addedTileEntityList.clear();
1805
        }
1806
1807
        this.theProfiler.endSection();
1808
        this.theProfiler.endSection();
1809
    }
1810
1811
    public boolean addTileEntity(TileEntity tile)
1812
    {
1813
        boolean flag = this.loadedTileEntityList.add(tile);
1814
1815
        if (flag && tile instanceof ITickable)
1816
        {
1817
            this.tickableTileEntities.add(tile);
1818
        }
1819
1820
        return flag;
1821
    }
1822
1823
    public void addTileEntities(Collection<TileEntity> tileEntityCollection)
1824
    {
1825
        if (this.processingLoadedTiles)
1826
        {
1827
            this.addedTileEntityList.addAll(tileEntityCollection);
1828
        }
1829
        else
1830
        {
1831
            for (TileEntity tileentity : tileEntityCollection)
1832
            {
1833
                this.loadedTileEntityList.add(tileentity);
1834
1835
                if (tileentity instanceof ITickable)
1836
                {
1837
                    this.tickableTileEntities.add(tileentity);
1838
                }
1839
            }
1840
        }
1841
    }
1842
1843
    /**
1844
     * Will update the entity in the world if the chunk the entity is in is currently loaded. Args: entity
1845
     */
1846
    public void updateEntity(Entity ent)
1847
    {
1848
        this.updateEntityWithOptionalForce(ent, true);
1849
    }
1850
1851
    /**
1852
     * Will update the entity in the world if the chunk the entity is in is currently loaded or its forced to update.
1853
     * Args: entity, forceUpdate
1854
     */
1855
    public void updateEntityWithOptionalForce(Entity entityIn, boolean forceUpdate)
1856
    {
1857
        int i = MathHelper.floor_double(entityIn.posX);
1858
        int j = MathHelper.floor_double(entityIn.posZ);
1859
        int k = 32;
1860
1861
        if (!forceUpdate || this.isAreaLoaded(i - k, 0, j - k, i + k, 0, j + k, true))
1862
        {
1863
            entityIn.lastTickPosX = entityIn.posX;
1864
            entityIn.lastTickPosY = entityIn.posY;
1865
            entityIn.lastTickPosZ = entityIn.posZ;
1866
            entityIn.prevRotationYaw = entityIn.rotationYaw;
1867
            entityIn.prevRotationPitch = entityIn.rotationPitch;
1868
1869
            if (forceUpdate && entityIn.addedToChunk)
1870
            {
1871
                ++entityIn.ticksExisted;
1872
1873
                if (entityIn.ridingEntity != null)
1874
                {
1875
                    entityIn.updateRidden();
1876
                }
1877
                else
1878
                {
1879
                    entityIn.onUpdate();
1880
                }
1881
            }
1882
1883
            this.theProfiler.startSection("chunkCheck");
1884
1885
            if (Double.isNaN(entityIn.posX) || Double.isInfinite(entityIn.posX))
1886
            {
1887
                entityIn.posX = entityIn.lastTickPosX;
1888
            }
1889
1890
            if (Double.isNaN(entityIn.posY) || Double.isInfinite(entityIn.posY))
1891
            {
1892
                entityIn.posY = entityIn.lastTickPosY;
1893
            }
1894
1895
            if (Double.isNaN(entityIn.posZ) || Double.isInfinite(entityIn.posZ))
1896
            {
1897
                entityIn.posZ = entityIn.lastTickPosZ;
1898
            }
1899
1900
            if (Double.isNaN((double)entityIn.rotationPitch) || Double.isInfinite((double)entityIn.rotationPitch))
1901
            {
1902
                entityIn.rotationPitch = entityIn.prevRotationPitch;
1903
            }
1904
1905
            if (Double.isNaN((double)entityIn.rotationYaw) || Double.isInfinite((double)entityIn.rotationYaw))
1906
            {
1907
                entityIn.rotationYaw = entityIn.prevRotationYaw;
1908
            }
1909
1910
            int l = MathHelper.floor_double(entityIn.posX / 16.0D);
1911
            int i1 = MathHelper.floor_double(entityIn.posY / 16.0D);
1912
            int j1 = MathHelper.floor_double(entityIn.posZ / 16.0D);
1913
1914
            if (!entityIn.addedToChunk || entityIn.chunkCoordX != l || entityIn.chunkCoordY != i1 || entityIn.chunkCoordZ != j1)
1915
            {
1916
                if (entityIn.addedToChunk && this.isChunkLoaded(entityIn.chunkCoordX, entityIn.chunkCoordZ, true))
1917
                {
1918
                    this.getChunkFromChunkCoords(entityIn.chunkCoordX, entityIn.chunkCoordZ).removeEntityAtIndex(entityIn, entityIn.chunkCoordY);
1919
                }
1920
1921
                if (this.isChunkLoaded(l, j1, true))
1922
                {
1923
                    entityIn.addedToChunk = true;
1924
                    this.getChunkFromChunkCoords(l, j1).addEntity(entityIn);
1925
                }
1926
                else
1927
                {
1928
                    entityIn.addedToChunk = false;
1929
                }
1930
            }
1931
1932
            this.theProfiler.endSection();
1933
1934
            if (forceUpdate && entityIn.addedToChunk && entityIn.riddenByEntity != null)
1935
            {
1936
                if (!entityIn.riddenByEntity.isDead && entityIn.riddenByEntity.ridingEntity == entityIn)
1937
                {
1938
                    this.updateEntity(entityIn.riddenByEntity);
1939
                }
1940
                else
1941
                {
1942
                    entityIn.riddenByEntity.ridingEntity = null;
1943
                    entityIn.riddenByEntity = null;
1944
                }
1945
            }
1946
        }
1947
    }
1948
1949
    /**
1950
     * Returns true if there are no solid, live entities in the specified AxisAlignedBB
1951
     */
1952
    public boolean checkNoEntityCollision(AxisAlignedBB bb)
1953
    {
1954
        return this.checkNoEntityCollision(bb, (Entity)null);
1955
    }
1956
1957
    /**
1958
     * Returns true if there are no solid, live entities in the specified AxisAlignedBB, excluding the given entity
1959
     */
1960
    public boolean checkNoEntityCollision(AxisAlignedBB bb, Entity entityIn)
1961
    {
1962
        List<Entity> list = this.getEntitiesWithinAABBExcludingEntity((Entity)null, bb);
1963
1964
        for (int i = 0; i < list.size(); ++i)
1965
        {
1966
            Entity entity = (Entity)list.get(i);
1967
1968
            if (!entity.isDead && entity.preventEntitySpawning && entity != entityIn && (entityIn == null || entityIn.ridingEntity != entity && entityIn.riddenByEntity != entity))
1969
            {
1970
                return false;
1971
            }
1972
        }
1973
1974
        return true;
1975
    }
1976
1977
    /**
1978
     * Returns true if there are any blocks in the region constrained by an AxisAlignedBB
1979
     */
1980
    public boolean checkBlockCollision(AxisAlignedBB bb)
1981
    {
1982
        int i = MathHelper.floor_double(bb.minX);
1983
        int j = MathHelper.floor_double(bb.maxX);
1984
        int k = MathHelper.floor_double(bb.minY);
1985
        int l = MathHelper.floor_double(bb.maxY);
1986
        int i1 = MathHelper.floor_double(bb.minZ);
1987
        int j1 = MathHelper.floor_double(bb.maxZ);
1988
        BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();
1989
1990
        for (int k1 = i; k1 <= j; ++k1)
1991
        {
1992
            for (int l1 = k; l1 <= l; ++l1)
1993
            {
1994
                for (int i2 = i1; i2 <= j1; ++i2)
1995
                {
1996
                    Block block = this.getBlockState(blockpos$mutableblockpos.set(k1, l1, i2)).getBlock();
1997
1998
                    if (block.getMaterial() != Material.air)
1999
                    {
2000
                        return true;
2001
                    }
2002
                }
2003
            }
2004
        }
2005
2006
        return false;
2007
    }
2008
2009
    /**
2010
     * Returns if any of the blocks within the aabb are liquids. Args: aabb
2011
     */
2012
    public boolean isAnyLiquid(AxisAlignedBB bb)
2013
    {
2014
        int i = MathHelper.floor_double(bb.minX);
2015
        int j = MathHelper.floor_double(bb.maxX);
2016
        int k = MathHelper.floor_double(bb.minY);
2017
        int l = MathHelper.floor_double(bb.maxY);
2018
        int i1 = MathHelper.floor_double(bb.minZ);
2019
        int j1 = MathHelper.floor_double(bb.maxZ);
2020
        BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();
2021
2022
        for (int k1 = i; k1 <= j; ++k1)
2023
        {
2024
            for (int l1 = k; l1 <= l; ++l1)
2025
            {
2026
                for (int i2 = i1; i2 <= j1; ++i2)
2027
                {
2028
                    Block block = this.getBlockState(blockpos$mutableblockpos.set(k1, l1, i2)).getBlock();
2029
2030
                    if (block.getMaterial().isLiquid())
2031
                    {
2032
                        return true;
2033
                    }
2034
                }
2035
            }
2036
        }
2037
2038
        return false;
2039
    }
2040
2041
    public boolean isFlammableWithin(AxisAlignedBB bb)
2042
    {
2043
        int i = MathHelper.floor_double(bb.minX);
2044
        int j = MathHelper.floor_double(bb.maxX + 1.0D);
2045
        int k = MathHelper.floor_double(bb.minY);
2046
        int l = MathHelper.floor_double(bb.maxY + 1.0D);
2047
        int i1 = MathHelper.floor_double(bb.minZ);
2048
        int j1 = MathHelper.floor_double(bb.maxZ + 1.0D);
2049
2050
        if (this.isAreaLoaded(i, k, i1, j, l, j1, true))
2051
        {
2052
            BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();
2053
2054
            for (int k1 = i; k1 < j; ++k1)
2055
            {
2056
                for (int l1 = k; l1 < l; ++l1)
2057
                {
2058
                    for (int i2 = i1; i2 < j1; ++i2)
2059
                    {
2060
                        Block block = this.getBlockState(blockpos$mutableblockpos.set(k1, l1, i2)).getBlock();
2061
2062
                        if (block == Blocks.fire || block == Blocks.flowing_lava || block == Blocks.lava)
2063
                        {
2064
                            return true;
2065
                        }
2066
                    }
2067
                }
2068
            }
2069
        }
2070
2071
        return false;
2072
    }
2073
2074
    /**
2075
     * handles the acceleration of an object whilst in water. Not sure if it is used elsewhere.
2076
     */
2077
    public boolean handleMaterialAcceleration(AxisAlignedBB bb, Material materialIn, Entity entityIn)
2078
    {
2079
        int i = MathHelper.floor_double(bb.minX);
2080
        int j = MathHelper.floor_double(bb.maxX + 1.0D);
2081
        int k = MathHelper.floor_double(bb.minY);
2082
        int l = MathHelper.floor_double(bb.maxY + 1.0D);
2083
        int i1 = MathHelper.floor_double(bb.minZ);
2084
        int j1 = MathHelper.floor_double(bb.maxZ + 1.0D);
2085
2086
        if (!this.isAreaLoaded(i, k, i1, j, l, j1, true))
2087
        {
2088
            return false;
2089
        }
2090
        else
2091
        {
2092
            boolean flag = false;
2093
            Vec3 vec3 = new Vec3(0.0D, 0.0D, 0.0D);
2094
            BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();
2095
2096
            for (int k1 = i; k1 < j; ++k1)
2097
            {
2098
                for (int l1 = k; l1 < l; ++l1)
2099
                {
2100
                    for (int i2 = i1; i2 < j1; ++i2)
2101
                    {
2102
                        blockpos$mutableblockpos.set(k1, l1, i2);
2103
                        IBlockState iblockstate = this.getBlockState(blockpos$mutableblockpos);
2104
                        Block block = iblockstate.getBlock();
2105
2106
                        if (block.getMaterial() == materialIn)
2107
                        {
2108
                            double d0 = (double)((float)(l1 + 1) - BlockLiquid.getLiquidHeightPercent(((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue()));
2109
2110
                            if ((double)l >= d0)
2111
                            {
2112
                                flag = true;
2113
                                vec3 = block.modifyAcceleration(this, blockpos$mutableblockpos, entityIn, vec3);
2114
                            }
2115
                        }
2116
                    }
2117
                }
2118
            }
2119
2120
            if (vec3.lengthVector() > 0.0D && entityIn.isPushedByWater())
2121
            {
2122
                vec3 = vec3.normalize();
2123
                double d1 = 0.014D;
2124
                entityIn.motionX += vec3.xCoord * d1;
2125
                entityIn.motionY += vec3.yCoord * d1;
2126
                entityIn.motionZ += vec3.zCoord * d1;
2127
            }
2128
2129
            return flag;
2130
        }
2131
    }
2132
2133
    /**
2134
     * Returns true if the given bounding box contains the given material
2135
     */
2136
    public boolean isMaterialInBB(AxisAlignedBB bb, Material materialIn)
2137
    {
2138
        int i = MathHelper.floor_double(bb.minX);
2139
        int j = MathHelper.floor_double(bb.maxX + 1.0D);
2140
        int k = MathHelper.floor_double(bb.minY);
2141
        int l = MathHelper.floor_double(bb.maxY + 1.0D);
2142
        int i1 = MathHelper.floor_double(bb.minZ);
2143
        int j1 = MathHelper.floor_double(bb.maxZ + 1.0D);
2144
        BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();
2145
2146
        for (int k1 = i; k1 < j; ++k1)
2147
        {
2148
            for (int l1 = k; l1 < l; ++l1)
2149
            {
2150
                for (int i2 = i1; i2 < j1; ++i2)
2151
                {
2152
                    if (this.getBlockState(blockpos$mutableblockpos.set(k1, l1, i2)).getBlock().getMaterial() == materialIn)
2153
                    {
2154
                        return true;
2155
                    }
2156
                }
2157
            }
2158
        }
2159
2160
        return false;
2161
    }
2162
2163
    /**
2164
     * checks if the given AABB is in the material given. Used while swimming.
2165
     */
2166
    public boolean isAABBInMaterial(AxisAlignedBB bb, Material materialIn)
2167
    {
2168
        int i = MathHelper.floor_double(bb.minX);
2169
        int j = MathHelper.floor_double(bb.maxX + 1.0D);
2170
        int k = MathHelper.floor_double(bb.minY);
2171
        int l = MathHelper.floor_double(bb.maxY + 1.0D);
2172
        int i1 = MathHelper.floor_double(bb.minZ);
2173
        int j1 = MathHelper.floor_double(bb.maxZ + 1.0D);
2174
        BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();
2175
2176
        for (int k1 = i; k1 < j; ++k1)
2177
        {
2178
            for (int l1 = k; l1 < l; ++l1)
2179
            {
2180
                for (int i2 = i1; i2 < j1; ++i2)
2181
                {
2182
                    IBlockState iblockstate = this.getBlockState(blockpos$mutableblockpos.set(k1, l1, i2));
2183
                    Block block = iblockstate.getBlock();
2184
2185
                    if (block.getMaterial() == materialIn)
2186
                    {
2187
                        int j2 = ((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue();
2188
                        double d0 = (double)(l1 + 1);
2189
2190
                        if (j2 < 8)
2191
                        {
2192
                            d0 = (double)(l1 + 1) - (double)j2 / 8.0D;
2193
                        }
2194
2195
                        if (d0 >= bb.minY)
2196
                        {
2197
                            return true;
2198
                        }
2199
                    }
2200
                }
2201
            }
2202
        }
2203
2204
        return false;
2205
    }
2206
2207
    /**
2208
     * Creates an explosion. Args: entity, x, y, z, strength
2209
     */
2210
    public Explosion createExplosion(Entity entityIn, double x, double y, double z, float strength, boolean isSmoking)
2211
    {
2212
        return this.newExplosion(entityIn, x, y, z, strength, false, isSmoking);
2213
    }
2214
2215
    /**
2216
     * returns a new explosion. Does initiation (at time of writing Explosion is not finished)
2217
     */
2218
    public Explosion newExplosion(Entity entityIn, double x, double y, double z, float strength, boolean isFlaming, boolean isSmoking)
2219
    {
2220
        Explosion explosion = new Explosion(this, entityIn, x, y, z, strength, isFlaming, isSmoking);
2221
        explosion.doExplosionA();
2222
        explosion.doExplosionB(true);
2223
        return explosion;
2224
    }
2225
2226
    /**
2227
     * Gets the percentage of real blocks within within a bounding box, along a specified vector.
2228
     */
2229
    public float getBlockDensity(Vec3 vec, AxisAlignedBB bb)
2230
    {
2231
        double d0 = 1.0D / ((bb.maxX - bb.minX) * 2.0D + 1.0D);
2232
        double d1 = 1.0D / ((bb.maxY - bb.minY) * 2.0D + 1.0D);
2233
        double d2 = 1.0D / ((bb.maxZ - bb.minZ) * 2.0D + 1.0D);
2234
        double d3 = (1.0D - Math.floor(1.0D / d0) * d0) / 2.0D;
2235
        double d4 = (1.0D - Math.floor(1.0D / d2) * d2) / 2.0D;
2236
2237
        if (d0 >= 0.0D && d1 >= 0.0D && d2 >= 0.0D)
2238
        {
2239
            int i = 0;
2240
            int j = 0;
2241
2242
            for (float f = 0.0F; f <= 1.0F; f = (float)((double)f + d0))
2243
            {
2244
                for (float f1 = 0.0F; f1 <= 1.0F; f1 = (float)((double)f1 + d1))
2245
                {
2246
                    for (float f2 = 0.0F; f2 <= 1.0F; f2 = (float)((double)f2 + d2))
2247
                    {
2248
                        double d5 = bb.minX + (bb.maxX - bb.minX) * (double)f;
2249
                        double d6 = bb.minY + (bb.maxY - bb.minY) * (double)f1;
2250
                        double d7 = bb.minZ + (bb.maxZ - bb.minZ) * (double)f2;
2251
2252
                        if (this.rayTraceBlocks(new Vec3(d5 + d3, d6, d7 + d4), vec) == null)
2253
                        {
2254
                            ++i;
2255
                        }
2256
2257
                        ++j;
2258
                    }
2259
                }
2260
            }
2261
2262
            return (float)i / (float)j;
2263
        }
2264
        else
2265
        {
2266
            return 0.0F;
2267
        }
2268
    }
2269
2270
    /**
2271
     * Attempts to extinguish a fire
2272
     */
2273
    public boolean extinguishFire(EntityPlayer player, BlockPos pos, EnumFacing side)
2274
    {
2275
        pos = pos.offset(side);
2276
2277
        if (this.getBlockState(pos).getBlock() == Blocks.fire)
2278
        {
2279
            this.playAuxSFXAtEntity(player, 1004, pos, 0);
2280
            this.setBlockToAir(pos);
2281
            return true;
2282
        }
2283
        else
2284
        {
2285
            return false;
2286
        }
2287
    }
2288
2289
    /**
2290
     * This string is 'All: (number of loaded entities)' Viewable by press ing F3
2291
     */
2292
    public String getDebugLoadedEntities()
2293
    {
2294
        return "All: " + this.loadedEntityList.size();
2295
    }
2296
2297
    /**
2298
     * Returns the name of the current chunk provider, by calling chunkprovider.makeString()
2299
     */
2300
    public String getProviderName()
2301
    {
2302
        return this.chunkProvider.makeString();
2303
    }
2304
2305
    public TileEntity getTileEntity(BlockPos pos)
2306
    {
2307
        if (!this.isValid(pos))
2308
        {
2309
            return null;
2310
        }
2311
        else
2312
        {
2313
            TileEntity tileentity = null;
2314
2315
            if (this.processingLoadedTiles)
2316
            {
2317
                for (int i = 0; i < this.addedTileEntityList.size(); ++i)
2318
                {
2319
                    TileEntity tileentity1 = (TileEntity)this.addedTileEntityList.get(i);
2320
2321
                    if (!tileentity1.isInvalid() && tileentity1.getPos().equals(pos))
2322
                    {
2323
                        tileentity = tileentity1;
2324
                        break;
2325
                    }
2326
                }
2327
            }
2328
2329
            if (tileentity == null)
2330
            {
2331
                tileentity = this.getChunkFromBlockCoords(pos).getTileEntity(pos, Chunk.EnumCreateEntityType.IMMEDIATE);
2332
            }
2333
2334
            if (tileentity == null)
2335
            {
2336
                for (int j = 0; j < this.addedTileEntityList.size(); ++j)
2337
                {
2338
                    TileEntity tileentity2 = (TileEntity)this.addedTileEntityList.get(j);
2339
2340
                    if (!tileentity2.isInvalid() && tileentity2.getPos().equals(pos))
2341
                    {
2342
                        tileentity = tileentity2;
2343
                        break;
2344
                    }
2345
                }
2346
            }
2347
2348
            return tileentity;
2349
        }
2350
    }
2351
2352
    public void setTileEntity(BlockPos pos, TileEntity tileEntityIn)
2353
    {
2354
        if (tileEntityIn != null && !tileEntityIn.isInvalid())
2355
        {
2356
            if (this.processingLoadedTiles)
2357
            {
2358
                tileEntityIn.setPos(pos);
2359
                Iterator<TileEntity> iterator = this.addedTileEntityList.iterator();
2360
2361
                while (iterator.hasNext())
2362
                {
2363
                    TileEntity tileentity = (TileEntity)iterator.next();
2364
2365
                    if (tileentity.getPos().equals(pos))
2366
                    {
2367
                        tileentity.invalidate();
2368
                        iterator.remove();
2369
                    }
2370
                }
2371
2372
                this.addedTileEntityList.add(tileEntityIn);
2373
            }
2374
            else
2375
            {
2376
                this.addTileEntity(tileEntityIn);
2377
                this.getChunkFromBlockCoords(pos).addTileEntity(pos, tileEntityIn);
2378
            }
2379
        }
2380
    }
2381
2382
    public void removeTileEntity(BlockPos pos)
2383
    {
2384
        TileEntity tileentity = this.getTileEntity(pos);
2385
2386
        if (tileentity != null && this.processingLoadedTiles)
2387
        {
2388
            tileentity.invalidate();
2389
            this.addedTileEntityList.remove(tileentity);
2390
        }
2391
        else
2392
        {
2393
            if (tileentity != null)
2394
            {
2395
                this.addedTileEntityList.remove(tileentity);
2396
                this.loadedTileEntityList.remove(tileentity);
2397
                this.tickableTileEntities.remove(tileentity);
2398
            }
2399
2400
            this.getChunkFromBlockCoords(pos).removeTileEntity(pos);
2401
        }
2402
    }
2403
2404
    /**
2405
     * Adds the specified TileEntity to the pending removal list.
2406
     */
2407
    public void markTileEntityForRemoval(TileEntity tileEntityIn)
2408
    {
2409
        this.tileEntitiesToBeRemoved.add(tileEntityIn);
2410
    }
2411
2412
    public boolean isBlockFullCube(BlockPos pos)
2413
    {
2414
        IBlockState iblockstate = this.getBlockState(pos);
2415
        AxisAlignedBB axisalignedbb = iblockstate.getBlock().getCollisionBoundingBox(this, pos, iblockstate);
2416
        return axisalignedbb != null && axisalignedbb.getAverageEdgeLength() >= 1.0D;
2417
    }
2418
2419
    public static boolean doesBlockHaveSolidTopSurface(IBlockAccess blockAccess, BlockPos pos)
2420
    {
2421
        IBlockState iblockstate = blockAccess.getBlockState(pos);
2422
        Block block = iblockstate.getBlock();
2423
        return block.getMaterial().isOpaque() && block.isFullCube() ? true : (block instanceof BlockStairs ? iblockstate.getValue(BlockStairs.HALF) == BlockStairs.EnumHalf.TOP : (block instanceof BlockSlab ? iblockstate.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.TOP : (block instanceof BlockHopper ? true : (block instanceof BlockSnow ? ((Integer)iblockstate.getValue(BlockSnow.LAYERS)).intValue() == 7 : false))));
2424
    }
2425
2426
    /**
2427
     * Checks if a block's material is opaque, and that it takes up a full cube
2428
     */
2429
    public boolean isBlockNormalCube(BlockPos pos, boolean _default)
2430
    {
2431
        if (!this.isValid(pos))
2432
        {
2433
            return _default;
2434
        }
2435
        else
2436
        {
2437
            Chunk chunk = this.chunkProvider.provideChunk(pos);
2438
2439
            if (chunk.isEmpty())
2440
            {
2441
                return _default;
2442
            }
2443
            else
2444
            {
2445
                Block block = this.getBlockState(pos).getBlock();
2446
                return block.getMaterial().isOpaque() && block.isFullCube();
2447
            }
2448
        }
2449
    }
2450
2451
    /**
2452
     * Called on construction of the World class to setup the initial skylight values
2453
     */
2454
    public void calculateInitialSkylight()
2455
    {
2456
        int i = this.calculateSkylightSubtracted(1.0F);
2457
2458
        if (i != this.skylightSubtracted)
2459
        {
2460
            this.skylightSubtracted = i;
2461
        }
2462
    }
2463
2464
    /**
2465
     * first boolean for hostile mobs and second for peaceful mobs
2466
     */
2467
    public void setAllowedSpawnTypes(boolean hostile, boolean peaceful)
2468
    {
2469
        this.spawnHostileMobs = hostile;
2470
        this.spawnPeacefulMobs = peaceful;
2471
    }
2472
2473
    /**
2474
     * Runs a single tick for the world
2475
     */
2476
    public void tick()
2477
    {
2478
        this.updateWeather();
2479
    }
2480
2481
    /**
2482
     * Called from World constructor to set rainingStrength and thunderingStrength
2483
     */
2484
    protected void calculateInitialWeather()
2485
    {
2486
        if (this.worldInfo.isRaining())
2487
        {
2488
            this.rainingStrength = 1.0F;
2489
2490
            if (this.worldInfo.isThundering())
2491
            {
2492
                this.thunderingStrength = 1.0F;
2493
            }
2494
        }
2495
    }
2496
2497
    /**
2498
     * Updates all weather states.
2499
     */
2500
    protected void updateWeather()
2501
    {
2502
        if (!this.provider.getHasNoSky())
2503
        {
2504
            if (!this.isRemote)
2505
            {
2506
                int i = this.worldInfo.getCleanWeatherTime();
2507
2508
                if (i > 0)
2509
                {
2510
                    --i;
2511
                    this.worldInfo.setCleanWeatherTime(i);
2512
                    this.worldInfo.setThunderTime(this.worldInfo.isThundering() ? 1 : 2);
2513
                    this.worldInfo.setRainTime(this.worldInfo.isRaining() ? 1 : 2);
2514
                }
2515
2516
                int j = this.worldInfo.getThunderTime();
2517
2518
                if (j <= 0)
2519
                {
2520
                    if (this.worldInfo.isThundering())
2521
                    {
2522
                        this.worldInfo.setThunderTime(this.rand.nextInt(12000) + 3600);
2523
                    }
2524
                    else
2525
                    {
2526
                        this.worldInfo.setThunderTime(this.rand.nextInt(168000) + 12000);
2527
                    }
2528
                }
2529
                else
2530
                {
2531
                    --j;
2532
                    this.worldInfo.setThunderTime(j);
2533
2534
                    if (j <= 0)
2535
                    {
2536
                        this.worldInfo.setThundering(!this.worldInfo.isThundering());
2537
                    }
2538
                }
2539
2540
                this.prevThunderingStrength = this.thunderingStrength;
2541
2542
                if (this.worldInfo.isThundering())
2543
                {
2544
                    this.thunderingStrength = (float)((double)this.thunderingStrength + 0.01D);
2545
                }
2546
                else
2547
                {
2548
                    this.thunderingStrength = (float)((double)this.thunderingStrength - 0.01D);
2549
                }
2550
2551
                this.thunderingStrength = MathHelper.clamp_float(this.thunderingStrength, 0.0F, 1.0F);
2552
                int k = this.worldInfo.getRainTime();
2553
2554
                if (k <= 0)
2555
                {
2556
                    if (this.worldInfo.isRaining())
2557
                    {
2558
                        this.worldInfo.setRainTime(this.rand.nextInt(12000) + 12000);
2559
                    }
2560
                    else
2561
                    {
2562
                        this.worldInfo.setRainTime(this.rand.nextInt(168000) + 12000);
2563
                    }
2564
                }
2565
                else
2566
                {
2567
                    --k;
2568
                    this.worldInfo.setRainTime(k);
2569
2570
                    if (k <= 0)
2571
                    {
2572
                        this.worldInfo.setRaining(!this.worldInfo.isRaining());
2573
                    }
2574
                }
2575
2576
                this.prevRainingStrength = this.rainingStrength;
2577
2578
                if (this.worldInfo.isRaining())
2579
                {
2580
                    this.rainingStrength = (float)((double)this.rainingStrength + 0.01D);
2581
                }
2582
                else
2583
                {
2584
                    this.rainingStrength = (float)((double)this.rainingStrength - 0.01D);
2585
                }
2586
2587
                this.rainingStrength = MathHelper.clamp_float(this.rainingStrength, 0.0F, 1.0F);
2588
            }
2589
        }
2590
    }
2591
2592
    protected void setActivePlayerChunksAndCheckLight()
2593
    {
2594
        this.activeChunkSet.clear();
2595
        this.theProfiler.startSection("buildList");
2596
2597
        for (int i = 0; i < this.playerEntities.size(); ++i)
2598
        {
2599
            EntityPlayer entityplayer = (EntityPlayer)this.playerEntities.get(i);
2600
            int j = MathHelper.floor_double(entityplayer.posX / 16.0D);
2601
            int k = MathHelper.floor_double(entityplayer.posZ / 16.0D);
2602
            int l = this.getRenderDistanceChunks();
2603
2604
            for (int i1 = -l; i1 <= l; ++i1)
2605
            {
2606
                for (int j1 = -l; j1 <= l; ++j1)
2607
                {
2608
                    this.activeChunkSet.add(new ChunkCoordIntPair(i1 + j, j1 + k));
2609
                }
2610
            }
2611
        }
2612
2613
        this.theProfiler.endSection();
2614
2615
        if (this.ambientTickCountdown > 0)
2616
        {
2617
            --this.ambientTickCountdown;
2618
        }
2619
2620
        this.theProfiler.startSection("playerCheckLight");
2621
2622
        if (!this.playerEntities.isEmpty())
2623
        {
2624
            int k1 = this.rand.nextInt(this.playerEntities.size());
2625
            EntityPlayer entityplayer1 = (EntityPlayer)this.playerEntities.get(k1);
2626
            int l1 = MathHelper.floor_double(entityplayer1.posX) + this.rand.nextInt(11) - 5;
2627
            int i2 = MathHelper.floor_double(entityplayer1.posY) + this.rand.nextInt(11) - 5;
2628
            int j2 = MathHelper.floor_double(entityplayer1.posZ) + this.rand.nextInt(11) - 5;
2629
            this.checkLight(new BlockPos(l1, i2, j2));
2630
        }
2631
2632
        this.theProfiler.endSection();
2633
    }
2634
2635
    protected abstract int getRenderDistanceChunks();
2636
2637
    protected void playMoodSoundAndCheckLight(int p_147467_1_, int p_147467_2_, Chunk chunkIn)
2638
    {
2639
        this.theProfiler.endStartSection("moodSound");
2640
2641
        if (this.ambientTickCountdown == 0 && !this.isRemote)
2642
        {
2643
            this.updateLCG = this.updateLCG * 3 + 1013904223;
2644
            int i = this.updateLCG >> 2;
2645
            int j = i & 15;
2646
            int k = i >> 8 & 15;
2647
            int l = i >> 16 & 255;
2648
            BlockPos blockpos = new BlockPos(j, l, k);
2649
            Block block = chunkIn.getBlock(blockpos);
2650
            j = j + p_147467_1_;
2651
            k = k + p_147467_2_;
2652
2653
            if (block.getMaterial() == Material.air && this.getLight(blockpos) <= this.rand.nextInt(8) && this.getLightFor(EnumSkyBlock.SKY, blockpos) <= 0)
2654
            {
2655
                EntityPlayer entityplayer = this.getClosestPlayer((double)j + 0.5D, (double)l + 0.5D, (double)k + 0.5D, 8.0D);
2656
2657
                if (entityplayer != null && entityplayer.getDistanceSq((double)j + 0.5D, (double)l + 0.5D, (double)k + 0.5D) > 4.0D)
2658
                {
2659
                    this.playSoundEffect((double)j + 0.5D, (double)l + 0.5D, (double)k + 0.5D, "ambient.cave.cave", 0.7F, 0.8F + this.rand.nextFloat() * 0.2F);
2660
                    this.ambientTickCountdown = this.rand.nextInt(12000) + 6000;
2661
                }
2662
            }
2663
        }
2664
2665
        this.theProfiler.endStartSection("checkLight");
2666
        chunkIn.enqueueRelightChecks();
2667
    }
2668
2669
    protected void updateBlocks()
2670
    {
2671
        this.setActivePlayerChunksAndCheckLight();
2672
    }
2673
2674
    public void forceBlockUpdateTick(Block blockType, BlockPos pos, Random random)
2675
    {
2676
        this.scheduledUpdatesAreImmediate = true;
2677
        blockType.updateTick(this, pos, this.getBlockState(pos), random);
2678
        this.scheduledUpdatesAreImmediate = false;
2679
    }
2680
2681
    public boolean canBlockFreezeWater(BlockPos pos)
2682
    {
2683
        return this.canBlockFreeze(pos, false);
2684
    }
2685
2686
    public boolean canBlockFreezeNoWater(BlockPos pos)
2687
    {
2688
        return this.canBlockFreeze(pos, true);
2689
    }
2690
2691
    /**
2692
     * Checks to see if a given block is both water and cold enough to freeze.
2693
     */
2694
    public boolean canBlockFreeze(BlockPos pos, boolean noWaterAdj)
2695
    {
2696
        BiomeGenBase biomegenbase = this.getBiomeGenForCoords(pos);
2697
        float f = biomegenbase.getFloatTemperature(pos);
2698
2699
        if (f > 0.15F)
2700
        {
2701
            return false;
2702
        }
2703
        else
2704
        {
2705
            if (pos.getY() >= 0 && pos.getY() < 256 && this.getLightFor(EnumSkyBlock.BLOCK, pos) < 10)
2706
            {
2707
                IBlockState iblockstate = this.getBlockState(pos);
2708
                Block block = iblockstate.getBlock();
2709
2710
                if ((block == Blocks.water || block == Blocks.flowing_water) && ((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue() == 0)
2711
                {
2712
                    if (!noWaterAdj)
2713
                    {
2714
                        return true;
2715
                    }
2716
2717
                    boolean flag = this.isWater(pos.west()) && this.isWater(pos.east()) && this.isWater(pos.north()) && this.isWater(pos.south());
2718
2719
                    if (!flag)
2720
                    {
2721
                        return true;
2722
                    }
2723
                }
2724
            }
2725
2726
            return false;
2727
        }
2728
    }
2729
2730
    private boolean isWater(BlockPos pos)
2731
    {
2732
        return this.getBlockState(pos).getBlock().getMaterial() == Material.water;
2733
    }
2734
2735
    /**
2736
     * Checks to see if a given block can accumulate snow from it snowing
2737
     */
2738
    public boolean canSnowAt(BlockPos pos, boolean checkLight)
2739
    {
2740
        BiomeGenBase biomegenbase = this.getBiomeGenForCoords(pos);
2741
        float f = biomegenbase.getFloatTemperature(pos);
2742
2743
        if (f > 0.15F)
2744
        {
2745
            return false;
2746
        }
2747
        else if (!checkLight)
2748
        {
2749
            return true;
2750
        }
2751
        else
2752
        {
2753
            if (pos.getY() >= 0 && pos.getY() < 256 && this.getLightFor(EnumSkyBlock.BLOCK, pos) < 10)
2754
            {
2755
                Block block = this.getBlockState(pos).getBlock();
2756
2757
                if (block.getMaterial() == Material.air && Blocks.snow_layer.canPlaceBlockAt(this, pos))
2758
                {
2759
                    return true;
2760
                }
2761
            }
2762
2763
            return false;
2764
        }
2765
    }
2766
2767
    public boolean checkLight(BlockPos pos)
2768
    {
2769
        boolean flag = false;
2770
2771
        if (!this.provider.getHasNoSky())
2772
        {
2773
            flag |= this.checkLightFor(EnumSkyBlock.SKY, pos);
2774
        }
2775
2776
        flag = flag | this.checkLightFor(EnumSkyBlock.BLOCK, pos);
2777
        return flag;
2778
    }
2779
2780
    /**
2781
     * gets the light level at the supplied position
2782
     */
2783
    private int getRawLight(BlockPos pos, EnumSkyBlock lightType)
2784
    {
2785
        if (lightType == EnumSkyBlock.SKY && this.canSeeSky(pos))
2786
        {
2787
            return 15;
2788
        }
2789
        else
2790
        {
2791
            Block block = this.getBlockState(pos).getBlock();
2792
            int i = lightType == EnumSkyBlock.SKY ? 0 : block.getLightValue();
2793
            int j = block.getLightOpacity();
2794
2795
            if (j >= 15 && block.getLightValue() > 0)
2796
            {
2797
                j = 1;
2798
            }
2799
2800
            if (j < 1)
2801
            {
2802
                j = 1;
2803
            }
2804
2805
            if (j >= 15)
2806
            {
2807
                return 0;
2808
            }
2809
            else if (i >= 14)
2810
            {
2811
                return i;
2812
            }
2813
            else
2814
            {
2815
                for (EnumFacing enumfacing : EnumFacing.values())
2816
                {
2817
                    BlockPos blockpos = pos.offset(enumfacing);
2818
                    int k = this.getLightFor(lightType, blockpos) - j;
2819
2820
                    if (k > i)
2821
                    {
2822
                        i = k;
2823
                    }
2824
2825
                    if (i >= 14)
2826
                    {
2827
                        return i;
2828
                    }
2829
                }
2830
2831
                return i;
2832
            }
2833
        }
2834
    }
2835
2836
    public boolean checkLightFor(EnumSkyBlock lightType, BlockPos pos)
2837
    {
2838
        if (!this.isAreaLoaded(pos, 17, false))
2839
        {
2840
            return false;
2841
        }
2842
        else
2843
        {
2844
            int i = 0;
2845
            int j = 0;
2846
            this.theProfiler.startSection("getBrightness");
2847
            int k = this.getLightFor(lightType, pos);
2848
            int l = this.getRawLight(pos, lightType);
2849
            int i1 = pos.getX();
2850
            int j1 = pos.getY();
2851
            int k1 = pos.getZ();
2852
2853
            if (l > k)
2854
            {
2855
                this.lightUpdateBlockList[j++] = 133152;
2856
            }
2857
            else if (l < k)
2858
            {
2859
                this.lightUpdateBlockList[j++] = 133152 | k << 18;
2860
2861
                while (i < j)
2862
                {
2863
                    int l1 = this.lightUpdateBlockList[i++];
2864
                    int i2 = (l1 & 63) - 32 + i1;
2865
                    int j2 = (l1 >> 6 & 63) - 32 + j1;
2866
                    int k2 = (l1 >> 12 & 63) - 32 + k1;
2867
                    int l2 = l1 >> 18 & 15;
2868
                    BlockPos blockpos = new BlockPos(i2, j2, k2);
2869
                    int i3 = this.getLightFor(lightType, blockpos);
2870
2871
                    if (i3 == l2)
2872
                    {
2873
                        this.setLightFor(lightType, blockpos, 0);
2874
2875
                        if (l2 > 0)
2876
                        {
2877
                            int j3 = MathHelper.abs_int(i2 - i1);
2878
                            int k3 = MathHelper.abs_int(j2 - j1);
2879
                            int l3 = MathHelper.abs_int(k2 - k1);
2880
2881
                            if (j3 + k3 + l3 < 17)
2882
                            {
2883
                                BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();
2884
2885
                                for (EnumFacing enumfacing : EnumFacing.values())
2886
                                {
2887
                                    int i4 = i2 + enumfacing.getFrontOffsetX();
2888
                                    int j4 = j2 + enumfacing.getFrontOffsetY();
2889
                                    int k4 = k2 + enumfacing.getFrontOffsetZ();
2890
                                    blockpos$mutableblockpos.set(i4, j4, k4);
2891
                                    int l4 = Math.max(1, this.getBlockState(blockpos$mutableblockpos).getBlock().getLightOpacity());
2892
                                    i3 = this.getLightFor(lightType, blockpos$mutableblockpos);
2893
2894
                                    if (i3 == l2 - l4 && j < this.lightUpdateBlockList.length)
2895
                                    {
2896
                                        this.lightUpdateBlockList[j++] = i4 - i1 + 32 | j4 - j1 + 32 << 6 | k4 - k1 + 32 << 12 | l2 - l4 << 18;
2897
                                    }
2898
                                }
2899
                            }
2900
                        }
2901
                    }
2902
                }
2903
2904
                i = 0;
2905
            }
2906
2907
            this.theProfiler.endSection();
2908
            this.theProfiler.startSection("checkedPosition < toCheckCount");
2909
2910
            while (i < j)
2911
            {
2912
                int i5 = this.lightUpdateBlockList[i++];
2913
                int j5 = (i5 & 63) - 32 + i1;
2914
                int k5 = (i5 >> 6 & 63) - 32 + j1;
2915
                int l5 = (i5 >> 12 & 63) - 32 + k1;
2916
                BlockPos blockpos1 = new BlockPos(j5, k5, l5);
2917
                int i6 = this.getLightFor(lightType, blockpos1);
2918
                int j6 = this.getRawLight(blockpos1, lightType);
2919
2920
                if (j6 != i6)
2921
                {
2922
                    this.setLightFor(lightType, blockpos1, j6);
2923
2924
                    if (j6 > i6)
2925
                    {
2926
                        int k6 = Math.abs(j5 - i1);
2927
                        int l6 = Math.abs(k5 - j1);
2928
                        int i7 = Math.abs(l5 - k1);
2929
                        boolean flag = j < this.lightUpdateBlockList.length - 6;
2930
2931
                        if (k6 + l6 + i7 < 17 && flag)
2932
                        {
2933
                            if (this.getLightFor(lightType, blockpos1.west()) < j6)
2934
                            {
2935
                                this.lightUpdateBlockList[j++] = j5 - 1 - i1 + 32 + (k5 - j1 + 32 << 6) + (l5 - k1 + 32 << 12);
2936
                            }
2937
2938
                            if (this.getLightFor(lightType, blockpos1.east()) < j6)
2939
                            {
2940
                                this.lightUpdateBlockList[j++] = j5 + 1 - i1 + 32 + (k5 - j1 + 32 << 6) + (l5 - k1 + 32 << 12);
2941
                            }
2942
2943
                            if (this.getLightFor(lightType, blockpos1.down()) < j6)
2944
                            {
2945
                                this.lightUpdateBlockList[j++] = j5 - i1 + 32 + (k5 - 1 - j1 + 32 << 6) + (l5 - k1 + 32 << 12);
2946
                            }
2947
2948
                            if (this.getLightFor(lightType, blockpos1.up()) < j6)
2949
                            {
2950
                                this.lightUpdateBlockList[j++] = j5 - i1 + 32 + (k5 + 1 - j1 + 32 << 6) + (l5 - k1 + 32 << 12);
2951
                            }
2952
2953
                            if (this.getLightFor(lightType, blockpos1.north()) < j6)
2954
                            {
2955
                                this.lightUpdateBlockList[j++] = j5 - i1 + 32 + (k5 - j1 + 32 << 6) + (l5 - 1 - k1 + 32 << 12);
2956
                            }
2957
2958
                            if (this.getLightFor(lightType, blockpos1.south()) < j6)
2959
                            {
2960
                                this.lightUpdateBlockList[j++] = j5 - i1 + 32 + (k5 - j1 + 32 << 6) + (l5 + 1 - k1 + 32 << 12);
2961
                            }
2962
                        }
2963
                    }
2964
                }
2965
            }
2966
2967
            this.theProfiler.endSection();
2968
            return true;
2969
        }
2970
    }
2971
2972
    /**
2973
     * Runs through the list of updates to run and ticks them
2974
     */
2975
    public boolean tickUpdates(boolean p_72955_1_)
2976
    {
2977
        return false;
2978
    }
2979
2980
    public List<NextTickListEntry> getPendingBlockUpdates(Chunk chunkIn, boolean p_72920_2_)
2981
    {
2982
        return null;
2983
    }
2984
2985
    public List<NextTickListEntry> func_175712_a(StructureBoundingBox structureBB, boolean p_175712_2_)
2986
    {
2987
        return null;
2988
    }
2989
2990
    public List<Entity> getEntitiesWithinAABBExcludingEntity(Entity entityIn, AxisAlignedBB bb)
2991
    {
2992
        return this.getEntitiesInAABBexcluding(entityIn, bb, EntitySelectors.NOT_SPECTATING);
2993
    }
2994
2995
    public List<Entity> getEntitiesInAABBexcluding(Entity entityIn, AxisAlignedBB boundingBox, Predicate <? super Entity > predicate)
2996
    {
2997
        List<Entity> list = Lists.<Entity>newArrayList();
2998
        int i = MathHelper.floor_double((boundingBox.minX - 2.0D) / 16.0D);
2999
        int j = MathHelper.floor_double((boundingBox.maxX + 2.0D) / 16.0D);
3000
        int k = MathHelper.floor_double((boundingBox.minZ - 2.0D) / 16.0D);
3001
        int l = MathHelper.floor_double((boundingBox.maxZ + 2.0D) / 16.0D);
3002
3003
        for (int i1 = i; i1 <= j; ++i1)
3004
        {
3005
            for (int j1 = k; j1 <= l; ++j1)
3006
            {
3007
                if (this.isChunkLoaded(i1, j1, true))
3008
                {
3009
                    this.getChunkFromChunkCoords(i1, j1).getEntitiesWithinAABBForEntity(entityIn, boundingBox, list, predicate);
3010
                }
3011
            }
3012
        }
3013
3014
        return list;
3015
    }
3016
3017
    public <T extends Entity> List<T> getEntities(Class <? extends T > entityType, Predicate <? super T > filter)
3018
    {
3019
        List<T> list = Lists.<T>newArrayList();
3020
3021
        for (Entity entity : this.loadedEntityList)
3022
        {
3023
            if (entityType.isAssignableFrom(entity.getClass()) && filter.apply((T)entity))
3024
            {
3025
                list.add((T)entity);
3026
            }
3027
        }
3028
3029
        return list;
3030
    }
3031
3032
    public <T extends Entity> List<T> getPlayers(Class <? extends T > playerType, Predicate <? super T > filter)
3033
    {
3034
        List<T> list = Lists.<T>newArrayList();
3035
3036
        for (Entity entity : this.playerEntities)
3037
        {
3038
            if (playerType.isAssignableFrom(entity.getClass()) && filter.apply((T)entity))
3039
            {
3040
                list.add((T)entity);
3041
            }
3042
        }
3043
3044
        return list;
3045
    }
3046
3047
    public <T extends Entity> List<T> getEntitiesWithinAABB(Class <? extends T > classEntity, AxisAlignedBB bb)
3048
    {
3049
        return this.<T>getEntitiesWithinAABB(classEntity, bb, EntitySelectors.NOT_SPECTATING);
3050
    }
3051
3052
    public <T extends Entity> List<T> getEntitiesWithinAABB(Class <? extends T > clazz, AxisAlignedBB aabb, Predicate <? super T > filter)
3053
    {
3054
        int i = MathHelper.floor_double((aabb.minX - 2.0D) / 16.0D);
3055
        int j = MathHelper.floor_double((aabb.maxX + 2.0D) / 16.0D);
3056
        int k = MathHelper.floor_double((aabb.minZ - 2.0D) / 16.0D);
3057
        int l = MathHelper.floor_double((aabb.maxZ + 2.0D) / 16.0D);
3058
        List<T> list = Lists.<T>newArrayList();
3059
3060
        for (int i1 = i; i1 <= j; ++i1)
3061
        {
3062
            for (int j1 = k; j1 <= l; ++j1)
3063
            {
3064
                if (this.isChunkLoaded(i1, j1, true))
3065
                {
3066
                    this.getChunkFromChunkCoords(i1, j1).getEntitiesOfTypeWithinAAAB(clazz, aabb, list, filter);
3067
                }
3068
            }
3069
        }
3070
3071
        return list;
3072
    }
3073
3074
    public <T extends Entity> T findNearestEntityWithinAABB(Class <? extends T > entityType, AxisAlignedBB aabb, T closestTo)
3075
    {
3076
        List<T> list = this.<T>getEntitiesWithinAABB(entityType, aabb);
3077
        T t = null;
3078
        double d0 = Double.MAX_VALUE;
3079
3080
        for (int i = 0; i < list.size(); ++i)
3081
        {
3082
            T t1 = list.get(i);
3083
3084
            if (t1 != closestTo && EntitySelectors.NOT_SPECTATING.apply(t1))
3085
            {
3086
                double d1 = closestTo.getDistanceSqToEntity(t1);
3087
3088
                if (d1 <= d0)
3089
                {
3090
                    t = t1;
3091
                    d0 = d1;
3092
                }
3093
            }
3094
        }
3095
3096
        return t;
3097
    }
3098
3099
    /**
3100
     * Returns the Entity with the given ID, or null if it doesn't exist in this World.
3101
     */
3102
    public Entity getEntityByID(int id)
3103
    {
3104
        return (Entity)this.entitiesById.lookup(id);
3105
    }
3106
3107
    public List<Entity> getLoadedEntityList()
3108
    {
3109
        return this.loadedEntityList;
3110
    }
3111
3112
    public void markChunkDirty(BlockPos pos, TileEntity unusedTileEntity)
3113
    {
3114
        if (this.isBlockLoaded(pos))
3115
        {
3116
            this.getChunkFromBlockCoords(pos).setChunkModified();
3117
        }
3118
    }
3119
3120
    /**
3121
     * Counts how many entities of an entity class exist in the world. Args: entityClass
3122
     */
3123
    public int countEntities(Class<?> entityType)
3124
    {
3125
        int i = 0;
3126
3127
        for (Entity entity : this.loadedEntityList)
3128
        {
3129
            if ((!(entity instanceof EntityLiving) || !((EntityLiving)entity).isNoDespawnRequired()) && entityType.isAssignableFrom(entity.getClass()))
3130
            {
3131
                ++i;
3132
            }
3133
        }
3134
3135
        return i;
3136
    }
3137
3138
    public void loadEntities(Collection<Entity> entityCollection)
3139
    {
3140
        this.loadedEntityList.addAll(entityCollection);
3141
3142
        for (Entity entity : entityCollection)
3143
        {
3144
            this.onEntityAdded(entity);
3145
        }
3146
    }
3147
3148
    public void unloadEntities(Collection<Entity> entityCollection)
3149
    {
3150
        this.unloadedEntityList.addAll(entityCollection);
3151
    }
3152
3153
    public boolean canBlockBePlaced(Block blockIn, BlockPos pos, boolean p_175716_3_, EnumFacing side, Entity entityIn, ItemStack itemStackIn)
3154
    {
3155
        Block block = this.getBlockState(pos).getBlock();
3156
        AxisAlignedBB axisalignedbb = p_175716_3_ ? null : blockIn.getCollisionBoundingBox(this, pos, blockIn.getDefaultState());
3157
        return axisalignedbb != null && !this.checkNoEntityCollision(axisalignedbb, entityIn) ? false : (block.getMaterial() == Material.circuits && blockIn == Blocks.anvil ? true : block.getMaterial().isReplaceable() && blockIn.canReplace(this, pos, side, itemStackIn));
3158
    }
3159
3160
    public int getSeaLevel()
3161
    {
3162
        return this.seaLevel;
3163
    }
3164
3165
    /**
3166
     * Warning this value may not be respected in all cases as it is still hardcoded in many places.
3167
     */
3168
    public void setSeaLevel(int p_181544_1_)
3169
    {
3170
        this.seaLevel = p_181544_1_;
3171
    }
3172
3173
    public int getStrongPower(BlockPos pos, EnumFacing direction)
3174
    {
3175
        IBlockState iblockstate = this.getBlockState(pos);
3176
        return iblockstate.getBlock().getStrongPower(this, pos, iblockstate, direction);
3177
    }
3178
3179
    public WorldType getWorldType()
3180
    {
3181
        return this.worldInfo.getTerrainType();
3182
    }
3183
3184
    /**
3185
     * Returns the single highest strong power out of all directions using getStrongPower(BlockPos, EnumFacing)
3186
     */
3187
    public int getStrongPower(BlockPos pos)
3188
    {
3189
        int i = 0;
3190
        i = Math.max(i, this.getStrongPower(pos.down(), EnumFacing.DOWN));
3191
3192
        if (i >= 15)
3193
        {
3194
            return i;
3195
        }
3196
        else
3197
        {
3198
            i = Math.max(i, this.getStrongPower(pos.up(), EnumFacing.UP));
3199
3200
            if (i >= 15)
3201
            {
3202
                return i;
3203
            }
3204
            else
3205
            {
3206
                i = Math.max(i, this.getStrongPower(pos.north(), EnumFacing.NORTH));
3207
3208
                if (i >= 15)
3209
                {
3210
                    return i;
3211
                }
3212
                else
3213
                {
3214
                    i = Math.max(i, this.getStrongPower(pos.south(), EnumFacing.SOUTH));
3215
3216
                    if (i >= 15)
3217
                    {
3218
                        return i;
3219
                    }
3220
                    else
3221
                    {
3222
                        i = Math.max(i, this.getStrongPower(pos.west(), EnumFacing.WEST));
3223
3224
                        if (i >= 15)
3225
                        {
3226
                            return i;
3227
                        }
3228
                        else
3229
                        {
3230
                            i = Math.max(i, this.getStrongPower(pos.east(), EnumFacing.EAST));
3231
                            return i >= 15 ? i : i;
3232
                        }
3233
                    }
3234
                }
3235
            }
3236
        }
3237
    }
3238
3239
    public boolean isSidePowered(BlockPos pos, EnumFacing side)
3240
    {
3241
        return this.getRedstonePower(pos, side) > 0;
3242
    }
3243
3244
    public int getRedstonePower(BlockPos pos, EnumFacing facing)
3245
    {
3246
        IBlockState iblockstate = this.getBlockState(pos);
3247
        Block block = iblockstate.getBlock();
3248
        return block.isNormalCube() ? this.getStrongPower(pos) : block.getWeakPower(this, pos, iblockstate, facing);
3249
    }
3250
3251
    public boolean isBlockPowered(BlockPos pos)
3252
    {
3253
        return this.getRedstonePower(pos.down(), EnumFacing.DOWN) > 0 ? true : (this.getRedstonePower(pos.up(), EnumFacing.UP) > 0 ? true : (this.getRedstonePower(pos.north(), EnumFacing.NORTH) > 0 ? true : (this.getRedstonePower(pos.south(), EnumFacing.SOUTH) > 0 ? true : (this.getRedstonePower(pos.west(), EnumFacing.WEST) > 0 ? true : this.getRedstonePower(pos.east(), EnumFacing.EAST) > 0))));
3254
    }
3255
3256
    /**
3257
     * Checks if the specified block or its neighbors are powered by a neighboring block. Used by blocks like TNT and
3258
     * Doors.
3259
     */
3260
    public int isBlockIndirectlyGettingPowered(BlockPos pos)
3261
    {
3262
        int i = 0;
3263
3264
        for (EnumFacing enumfacing : EnumFacing.values())
3265
        {
3266
            int j = this.getRedstonePower(pos.offset(enumfacing), enumfacing);
3267
3268
            if (j >= 15)
3269
            {
3270
                return 15;
3271
            }
3272
3273
            if (j > i)
3274
            {
3275
                i = j;
3276
            }
3277
        }
3278
3279
        return i;
3280
    }
3281
3282
    /**
3283
     * Gets the closest player to the entity within the specified distance (if distance is less than 0 then ignored).
3284
     * Args: entity, dist
3285
     */
3286
    public EntityPlayer getClosestPlayerToEntity(Entity entityIn, double distance)
3287
    {
3288
        return this.getClosestPlayer(entityIn.posX, entityIn.posY, entityIn.posZ, distance);
3289
    }
3290
3291
    /**
3292
     * Gets the closest player to the point within the specified distance (distance can be set to less than 0 to not
3293
     * limit the distance). Args: x, y, z, dist
3294
     */
3295
    public EntityPlayer getClosestPlayer(double x, double y, double z, double distance)
3296
    {
3297
        double d0 = -1.0D;
3298
        EntityPlayer entityplayer = null;
3299
3300
        for (int i = 0; i < this.playerEntities.size(); ++i)
3301
        {
3302
            EntityPlayer entityplayer1 = (EntityPlayer)this.playerEntities.get(i);
3303
3304
            if (EntitySelectors.NOT_SPECTATING.apply(entityplayer1))
3305
            {
3306
                double d1 = entityplayer1.getDistanceSq(x, y, z);
3307
3308
                if ((distance < 0.0D || d1 < distance * distance) && (d0 == -1.0D || d1 < d0))
3309
                {
3310
                    d0 = d1;
3311
                    entityplayer = entityplayer1;
3312
                }
3313
            }
3314
        }
3315
3316
        return entityplayer;
3317
    }
3318
3319
    public boolean isAnyPlayerWithinRangeAt(double x, double y, double z, double range)
3320
    {
3321
        for (int i = 0; i < this.playerEntities.size(); ++i)
3322
        {
3323
            EntityPlayer entityplayer = (EntityPlayer)this.playerEntities.get(i);
3324
3325
            if (EntitySelectors.NOT_SPECTATING.apply(entityplayer))
3326
            {
3327
                double d0 = entityplayer.getDistanceSq(x, y, z);
3328
3329
                if (range < 0.0D || d0 < range * range)
3330
                {
3331
                    return true;
3332
                }
3333
            }
3334
        }
3335
3336
        return false;
3337
    }
3338
3339
    /**
3340
     * Find a player by name in this world.
3341
     */
3342
    public EntityPlayer getPlayerEntityByName(String name)
3343
    {
3344
        for (int i = 0; i < this.playerEntities.size(); ++i)
3345
        {
3346
            EntityPlayer entityplayer = (EntityPlayer)this.playerEntities.get(i);
3347
3348
            if (name.equals(entityplayer.getName()))
3349
            {
3350
                return entityplayer;
3351
            }
3352
        }
3353
3354
        return null;
3355
    }
3356
3357
    public EntityPlayer getPlayerEntityByUUID(UUID uuid)
3358
    {
3359
        for (int i = 0; i < this.playerEntities.size(); ++i)
3360
        {
3361
            EntityPlayer entityplayer = (EntityPlayer)this.playerEntities.get(i);
3362
3363
            if (uuid.equals(entityplayer.getUniqueID()))
3364
            {
3365
                return entityplayer;
3366
            }
3367
        }
3368
3369
        return null;
3370
    }
3371
3372
    /**
3373
     * If on MP, sends a quitting packet.
3374
     */
3375
    public void sendQuittingDisconnectingPacket()
3376
    {
3377
    }
3378
3379
    /**
3380
     * Checks whether the session lock file was modified by another process
3381
     */
3382
    public void checkSessionLock() throws MinecraftException
3383
    {
3384
        this.saveHandler.checkSessionLock();
3385
    }
3386
3387
    public void setTotalWorldTime(long worldTime)
3388
    {
3389
        this.worldInfo.setWorldTotalTime(worldTime);
3390
    }
3391
3392
    /**
3393
     * gets the random world seed
3394
     */
3395
    public long getSeed()
3396
    {
3397
        return this.worldInfo.getSeed();
3398
    }
3399
3400
    public long getTotalWorldTime()
3401
    {
3402
        return this.worldInfo.getWorldTotalTime();
3403
    }
3404
3405
    public long getWorldTime()
3406
    {
3407
        return this.worldInfo.getWorldTime();
3408
    }
3409
3410
    /**
3411
     * Sets the world time.
3412
     */
3413
    public void setWorldTime(long time)
3414
    {
3415
        this.worldInfo.setWorldTime(time);
3416
    }
3417
3418
    /**
3419
     * Gets the spawn point in the world
3420
     */
3421
    public BlockPos getSpawnPoint()
3422
    {
3423
        BlockPos blockpos = new BlockPos(this.worldInfo.getSpawnX(), this.worldInfo.getSpawnY(), this.worldInfo.getSpawnZ());
3424
3425
        if (!this.getWorldBorder().contains(blockpos))
3426
        {
3427
            blockpos = this.getHeight(new BlockPos(this.getWorldBorder().getCenterX(), 0.0D, this.getWorldBorder().getCenterZ()));
3428
        }
3429
3430
        return blockpos;
3431
    }
3432
3433
    public void setSpawnPoint(BlockPos pos)
3434
    {
3435
        this.worldInfo.setSpawn(pos);
3436
    }
3437
3438
    /**
3439
     * spwans an entity and loads surrounding chunks
3440
     */
3441
    public void joinEntityInSurroundings(Entity entityIn)
3442
    {
3443
        int i = MathHelper.floor_double(entityIn.posX / 16.0D);
3444
        int j = MathHelper.floor_double(entityIn.posZ / 16.0D);
3445
        int k = 2;
3446
3447
        for (int l = i - k; l <= i + k; ++l)
3448
        {
3449
            for (int i1 = j - k; i1 <= j + k; ++i1)
3450
            {
3451
                this.getChunkFromChunkCoords(l, i1);
3452
            }
3453
        }
3454
3455
        if (!this.loadedEntityList.contains(entityIn))
3456
        {
3457
            this.loadedEntityList.add(entityIn);
3458
        }
3459
    }
3460
3461
    public boolean isBlockModifiable(EntityPlayer player, BlockPos pos)
3462
    {
3463
        return true;
3464
    }
3465
3466
    /**
3467
     * sends a Packet 38 (Entity Status) to all tracked players of that entity
3468
     */
3469
    public void setEntityState(Entity entityIn, byte state)
3470
    {
3471
    }
3472
3473
    /**
3474
     * gets the world's chunk provider
3475
     */
3476
    public IChunkProvider getChunkProvider()
3477
    {
3478
        return this.chunkProvider;
3479
    }
3480
3481
    public void addBlockEvent(BlockPos pos, Block blockIn, int eventID, int eventParam)
3482
    {
3483
        blockIn.onBlockEventReceived(this, pos, this.getBlockState(pos), eventID, eventParam);
3484
    }
3485
3486
    /**
3487
     * Returns this world's current save handler
3488
     */
3489
    public ISaveHandler getSaveHandler()
3490
    {
3491
        return this.saveHandler;
3492
    }
3493
3494
    /**
3495
     * Returns the world's WorldInfo object
3496
     */
3497
    public WorldInfo getWorldInfo()
3498
    {
3499
        return this.worldInfo;
3500
    }
3501
3502
    /**
3503
     * Gets the GameRules instance.
3504
     */
3505
    public GameRules getGameRules()
3506
    {
3507
        return this.worldInfo.getGameRulesInstance();
3508
    }
3509
3510
    /**
3511
     * Updates the flag that indicates whether or not all players in the world are sleeping.
3512
     */
3513
    public void updateAllPlayersSleepingFlag()
3514
    {
3515
    }
3516
3517
    public float getThunderStrength(float delta)
3518
    {
3519
        return (this.prevThunderingStrength + (this.thunderingStrength - this.prevThunderingStrength) * delta) * this.getRainStrength(delta);
3520
    }
3521
3522
    /**
3523
     * Sets the strength of the thunder.
3524
     */
3525
    public void setThunderStrength(float strength)
3526
    {
3527
        this.prevThunderingStrength = strength;
3528
        this.thunderingStrength = strength;
3529
    }
3530
3531
    /**
3532
     * Returns rain strength.
3533
     */
3534
    public float getRainStrength(float delta)
3535
    {
3536
        return this.prevRainingStrength + (this.rainingStrength - this.prevRainingStrength) * delta;
3537
    }
3538
3539
    /**
3540
     * Sets the strength of the rain.
3541
     */
3542
    public void setRainStrength(float strength)
3543
    {
3544
        this.prevRainingStrength = strength;
3545
        this.rainingStrength = strength;
3546
    }
3547
3548
    /**
3549
     * Returns true if the current thunder strength (weighted with the rain strength) is greater than 0.9
3550
     */
3551
    public boolean isThundering()
3552
    {
3553
        return (double)this.getThunderStrength(1.0F) > 0.9D;
3554
    }
3555
3556
    /**
3557
     * Returns true if the current rain strength is greater than 0.2
3558
     */
3559
    public boolean isRaining()
3560
    {
3561
        return (double)this.getRainStrength(1.0F) > 0.2D;
3562
    }
3563
3564
    /**
3565
     * Check if precipitation is currently happening at a position
3566
     */
3567
    public boolean isRainingAt(BlockPos strikePosition)
3568
    {
3569
        if (!this.isRaining())
3570
        {
3571
            return false;
3572
        }
3573
        else if (!this.canSeeSky(strikePosition))
3574
        {
3575
            return false;
3576
        }
3577
        else if (this.getPrecipitationHeight(strikePosition).getY() > strikePosition.getY())
3578
        {
3579
            return false;
3580
        }
3581
        else
3582
        {
3583
            BiomeGenBase biomegenbase = this.getBiomeGenForCoords(strikePosition);
3584
            return biomegenbase.getEnableSnow() ? false : (this.canSnowAt(strikePosition, false) ? false : biomegenbase.canRain());
3585
        }
3586
    }
3587
3588
    public boolean isBlockinHighHumidity(BlockPos pos)
3589
    {
3590
        BiomeGenBase biomegenbase = this.getBiomeGenForCoords(pos);
3591
        return biomegenbase.isHighHumidity();
3592
    }
3593
3594
    public MapStorage getMapStorage()
3595
    {
3596
        return this.mapStorage;
3597
    }
3598
3599
    /**
3600
     * Assigns the given String id to the given MapDataBase using the MapStorage, removing any existing ones of the same
3601
     * id.
3602
     */
3603
    public void setItemData(String dataID, WorldSavedData worldSavedDataIn)
3604
    {
3605
        this.mapStorage.setData(dataID, worldSavedDataIn);
3606
    }
3607
3608
    /**
3609
     * Loads an existing MapDataBase corresponding to the given String id from disk using the MapStorage, instantiating
3610
     * the given Class, or returns null if none such file exists. args: Class to instantiate, String dataid
3611
     */
3612
    public WorldSavedData loadItemData(Class <? extends WorldSavedData > clazz, String dataID)
3613
    {
3614
        return this.mapStorage.loadData(clazz, dataID);
3615
    }
3616
3617
    /**
3618
     * Returns an unique new data id from the MapStorage for the given prefix and saves the idCounts map to the
3619
     * 'idcounts' file.
3620
     */
3621
    public int getUniqueDataId(String key)
3622
    {
3623
        return this.mapStorage.getUniqueDataId(key);
3624
    }
3625
3626
    public void playBroadcastSound(int p_175669_1_, BlockPos pos, int p_175669_3_)
3627
    {
3628
        for (int i = 0; i < this.worldAccesses.size(); ++i)
3629
        {
3630
            ((IWorldAccess)this.worldAccesses.get(i)).broadcastSound(p_175669_1_, pos, p_175669_3_);
3631
        }
3632
    }
3633
3634
    public void playAuxSFX(int p_175718_1_, BlockPos pos, int p_175718_3_)
3635
    {
3636
        this.playAuxSFXAtEntity((EntityPlayer)null, p_175718_1_, pos, p_175718_3_);
3637
    }
3638
3639
    public void playAuxSFXAtEntity(EntityPlayer player, int sfxType, BlockPos pos, int p_180498_4_)
3640
    {
3641
        try
3642
        {
3643
            for (int i = 0; i < this.worldAccesses.size(); ++i)
3644
            {
3645
                ((IWorldAccess)this.worldAccesses.get(i)).playAuxSFX(player, sfxType, pos, p_180498_4_);
3646
            }
3647
        }
3648
        catch (Throwable throwable)
3649
        {
3650
            CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Playing level event");
3651
            CrashReportCategory crashreportcategory = crashreport.makeCategory("Level event being played");
3652
            crashreportcategory.addCrashSection("Block coordinates", CrashReportCategory.getCoordinateInfo(pos));
3653
            crashreportcategory.addCrashSection("Event source", player);
3654
            crashreportcategory.addCrashSection("Event type", Integer.valueOf(sfxType));
3655
            crashreportcategory.addCrashSection("Event data", Integer.valueOf(p_180498_4_));
3656
            throw new ReportedException(crashreport);
3657
        }
3658
    }
3659
3660
    /**
3661
     * Returns maximum world height.
3662
     */
3663
    public int getHeight()
3664
    {
3665
        return 256;
3666
    }
3667
3668
    /**
3669
     * Returns current world height.
3670
     */
3671
    public int getActualHeight()
3672
    {
3673
        return this.provider.getHasNoSky() ? 128 : 256;
3674
    }
3675
3676
    /**
3677
     * puts the World Random seed to a specific state dependant on the inputs
3678
     */
3679
    public Random setRandomSeed(int p_72843_1_, int p_72843_2_, int p_72843_3_)
3680
    {
3681
        long i = (long)p_72843_1_ * 341873128712L + (long)p_72843_2_ * 132897987541L + this.getWorldInfo().getSeed() + (long)p_72843_3_;
3682
        this.rand.setSeed(i);
3683
        return this.rand;
3684
    }
3685
3686
    public BlockPos getStrongholdPos(String name, BlockPos pos)
3687
    {
3688
        return this.getChunkProvider().getStrongholdGen(this, name, pos);
3689
    }
3690
3691
    /**
3692
     * set by !chunk.getAreLevelsEmpty
3693
     */
3694
    public boolean extendedLevelsInChunkCache()
3695
    {
3696
        return false;
3697
    }
3698
3699
    /**
3700
     * Returns horizon height for use in rendering the sky.
3701
     */
3702
    public double getHorizon()
3703
    {
3704
        return this.worldInfo.getTerrainType() == WorldType.FLAT ? 0.0D : 63.0D;
3705
    }
3706
3707
    /**
3708
     * Adds some basic stats of the world to the given crash report.
3709
     */
3710
    public CrashReportCategory addWorldInfoToCrashReport(CrashReport report)
3711
    {
3712
        CrashReportCategory crashreportcategory = report.makeCategoryDepth("Affected level", 1);
3713
        crashreportcategory.addCrashSection("Level name", this.worldInfo == null ? "????" : this.worldInfo.getWorldName());
3714
        crashreportcategory.addCrashSectionCallable("All players", new Callable<String>()
3715
        {
3716
            public String call()
3717
            {
3718
                return World.this.playerEntities.size() + " total; " + World.this.playerEntities.toString();
3719
            }
3720
        });
3721
        crashreportcategory.addCrashSectionCallable("Chunk stats", new Callable<String>()
3722
        {
3723
            public String call()
3724
            {
3725
                return World.this.chunkProvider.makeString();
3726
            }
3727
        });
3728
3729
        try
3730
        {
3731
            this.worldInfo.addToCrashReport(crashreportcategory);
3732
        }
3733
        catch (Throwable throwable)
3734
        {
3735
            crashreportcategory.addCrashSectionThrowable("Level Data Unobtainable", throwable);
3736
        }
3737
3738
        return crashreportcategory;
3739
    }
3740
3741
    public void sendBlockBreakProgress(int breakerId, BlockPos pos, int progress)
3742
    {
3743
        for (int i = 0; i < this.worldAccesses.size(); ++i)
3744
        {
3745
            IWorldAccess iworldaccess = (IWorldAccess)this.worldAccesses.get(i);
3746
            iworldaccess.sendBlockBreakProgress(breakerId, pos, progress);
3747
        }
3748
    }
3749
3750
    /**
3751
     * returns a calendar object containing the current date
3752
     */
3753
    public Calendar getCurrentDate()
3754
    {
3755
        if (this.getTotalWorldTime() % 600L == 0L)
3756
        {
3757
            this.theCalendar.setTimeInMillis(MinecraftServer.getCurrentTimeMillis());
3758
        }
3759
3760
        return this.theCalendar;
3761
    }
3762
3763
    public void makeFireworks(double x, double y, double z, double motionX, double motionY, double motionZ, NBTTagCompound compund)
3764
    {
3765
    }
3766
3767
    public Scoreboard getScoreboard()
3768
    {
3769
        return this.worldScoreboard;
3770
    }
3771
3772
    public void updateComparatorOutputLevel(BlockPos pos, Block blockIn)
3773
    {
3774
        for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL)
3775
        {
3776
            BlockPos blockpos = pos.offset(enumfacing);
3777
3778
            if (this.isBlockLoaded(blockpos))
3779
            {
3780
                IBlockState iblockstate = this.getBlockState(blockpos);
3781
3782
                if (Blocks.unpowered_comparator.isAssociated(iblockstate.getBlock()))
3783
                {
3784
                    iblockstate.getBlock().onNeighborBlockChange(this, blockpos, iblockstate, blockIn);
3785
                }
3786
                else if (iblockstate.getBlock().isNormalCube())
3787
                {
3788
                    blockpos = blockpos.offset(enumfacing);
3789
                    iblockstate = this.getBlockState(blockpos);
3790
3791
                    if (Blocks.unpowered_comparator.isAssociated(iblockstate.getBlock()))
3792
                    {
3793
                        iblockstate.getBlock().onNeighborBlockChange(this, blockpos, iblockstate, blockIn);
3794
                    }
3795
                }
3796
            }
3797
        }
3798
    }
3799
3800
    public DifficultyInstance getDifficultyForLocation(BlockPos pos)
3801
    {
3802
        long i = 0L;
3803
        float f = 0.0F;
3804
3805
        if (this.isBlockLoaded(pos))
3806
        {
3807
            f = this.getCurrentMoonPhaseFactor();
3808
            i = this.getChunkFromBlockCoords(pos).getInhabitedTime();
3809
        }
3810
3811
        return new DifficultyInstance(this.getDifficulty(), this.getWorldTime(), i, f);
3812
    }
3813
3814
    public EnumDifficulty getDifficulty()
3815
    {
3816
        return this.getWorldInfo().getDifficulty();
3817
    }
3818
3819
    public int getSkylightSubtracted()
3820
    {
3821
        return this.skylightSubtracted;
3822
    }
3823
3824
    public void setSkylightSubtracted(int newSkylightSubtracted)
3825
    {
3826
        this.skylightSubtracted = newSkylightSubtracted;
3827
    }
3828
3829
    public int getLastLightningBolt()
3830
    {
3831
        return this.lastLightningBolt;
3832
    }
3833
3834
    public void setLastLightningBolt(int lastLightningBoltIn)
3835
    {
3836
        this.lastLightningBolt = lastLightningBoltIn;
3837
    }
3838
3839
    public boolean isFindingSpawnPoint()
3840
    {
3841
        return this.findingSpawnPoint;
3842
    }
3843
3844
    public VillageCollection getVillageCollection()
3845
    {
3846
        return this.villageCollectionObj;
3847
    }
3848
3849
    public WorldBorder getWorldBorder()
3850
    {
3851
        return this.worldBorder;
3852
    }
3853
3854
    /**
3855
     * Returns true if the chunk is located near the spawn point
3856
     */
3857
    public boolean isSpawnChunk(int x, int z)
3858
    {
3859
        BlockPos blockpos = this.getSpawnPoint();
3860
        int i = x * 16 + 8 - blockpos.getX();
3861
        int j = z * 16 + 8 - blockpos.getZ();
3862
        int k = 128;
3863
        return i >= -k && i <= k && j >= -k && j <= k;
3864
    }
3865
}

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