| 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.Maps;
|
| 6 | import com.google.common.collect.Sets;
|
| 7 | import com.google.common.util.concurrent.ListenableFuture;
|
| 8 | import java.util.ArrayList;
|
| 9 | import java.util.Iterator;
|
| 10 | import java.util.List;
|
| 11 | import java.util.Map;
|
| 12 | import java.util.Random;
|
| 13 | import java.util.Set;
|
| 14 | import java.util.TreeSet;
|
| 15 | import java.util.UUID;
|
| 16 | import net.minecraft.block.Block;
|
| 17 | import net.minecraft.block.BlockEventData;
|
| 18 | import net.minecraft.block.material.Material;
|
| 19 | import net.minecraft.block.state.IBlockState;
|
| 20 | import net.minecraft.crash.CrashReport;
|
| 21 | import net.minecraft.crash.CrashReportCategory;
|
| 22 | import net.minecraft.entity.Entity;
|
| 23 | import net.minecraft.entity.EntityLivingBase;
|
| 24 | import net.minecraft.entity.EntityTracker;
|
| 25 | import net.minecraft.entity.EnumCreatureType;
|
| 26 | import net.minecraft.entity.INpc;
|
| 27 | import net.minecraft.entity.effect.EntityLightningBolt;
|
| 28 | import net.minecraft.entity.passive.EntityAnimal;
|
| 29 | import net.minecraft.entity.passive.EntityWaterMob;
|
| 30 | import net.minecraft.entity.player.EntityPlayer;
|
| 31 | import net.minecraft.entity.player.EntityPlayerMP;
|
| 32 | import net.minecraft.init.Blocks;
|
| 33 | import net.minecraft.init.Items;
|
| 34 | import net.minecraft.item.Item;
|
| 35 | import net.minecraft.network.Packet;
|
| 36 | import net.minecraft.network.play.server.S19PacketEntityStatus;
|
| 37 | import net.minecraft.network.play.server.S24PacketBlockAction;
|
| 38 | import net.minecraft.network.play.server.S27PacketExplosion;
|
| 39 | import net.minecraft.network.play.server.S2APacketParticles;
|
| 40 | import net.minecraft.network.play.server.S2BPacketChangeGameState;
|
| 41 | import net.minecraft.network.play.server.S2CPacketSpawnGlobalEntity;
|
| 42 | import net.minecraft.profiler.Profiler;
|
| 43 | import net.minecraft.scoreboard.ScoreboardSaveData;
|
| 44 | import net.minecraft.scoreboard.ServerScoreboard;
|
| 45 | import net.minecraft.server.MinecraftServer;
|
| 46 | import net.minecraft.server.management.PlayerManager;
|
| 47 | import net.minecraft.tileentity.TileEntity;
|
| 48 | import net.minecraft.util.AxisAlignedBB;
|
| 49 | import net.minecraft.util.BlockPos;
|
| 50 | import net.minecraft.util.EnumParticleTypes;
|
| 51 | import net.minecraft.util.IProgressUpdate;
|
| 52 | import net.minecraft.util.IThreadListener;
|
| 53 | import net.minecraft.util.ReportedException;
|
| 54 | import net.minecraft.util.Vec3;
|
| 55 | import net.minecraft.util.WeightedRandom;
|
| 56 | import net.minecraft.util.WeightedRandomChestContent;
|
| 57 | import net.minecraft.village.VillageCollection;
|
| 58 | import net.minecraft.village.VillageSiege;
|
| 59 | import net.minecraft.world.biome.BiomeGenBase;
|
| 60 | import net.minecraft.world.biome.WorldChunkManager;
|
| 61 | import net.minecraft.world.chunk.Chunk;
|
| 62 | import net.minecraft.world.chunk.IChunkProvider;
|
| 63 | import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
|
| 64 | import net.minecraft.world.chunk.storage.IChunkLoader;
|
| 65 | import net.minecraft.world.gen.ChunkProviderServer;
|
| 66 | import net.minecraft.world.gen.feature.WorldGeneratorBonusChest;
|
| 67 | import net.minecraft.world.gen.structure.StructureBoundingBox;
|
| 68 | import net.minecraft.world.storage.ISaveHandler;
|
| 69 | import net.minecraft.world.storage.MapStorage;
|
| 70 | import net.minecraft.world.storage.WorldInfo;
|
| 71 | import org.apache.logging.log4j.LogManager;
|
| 72 | import org.apache.logging.log4j.Logger;
|
| 73 |
|
| 74 | public class WorldServer extends World implements IThreadListener
|
| 75 | {
|
| 76 | private static final Logger logger = LogManager.getLogger();
|
| 77 | private final MinecraftServer mcServer;
|
| 78 | private final EntityTracker theEntityTracker;
|
| 79 | private final PlayerManager thePlayerManager;
|
| 80 | private final Set<NextTickListEntry> pendingTickListEntriesHashSet = Sets.<NextTickListEntry>newHashSet();
|
| 81 | private final TreeSet<NextTickListEntry> pendingTickListEntriesTreeSet = new TreeSet();
|
| 82 | private final Map<UUID, Entity> entitiesByUuid = Maps.<UUID, Entity>newHashMap();
|
| 83 | public ChunkProviderServer theChunkProviderServer;
|
| 84 |
|
| 85 | /** Whether level saving is disabled or not */
|
| 86 | public boolean disableLevelSaving;
|
| 87 |
|
| 88 | /** is false if there are no players */
|
| 89 | private boolean allPlayersSleeping;
|
| 90 | private int updateEntityTick;
|
| 91 |
|
| 92 | /**
|
| 93 | * the teleporter to use when the entity is being transferred into the dimension
|
| 94 | */
|
| 95 | private final Teleporter worldTeleporter;
|
| 96 | private final SpawnerAnimals mobSpawner = new SpawnerAnimals();
|
| 97 | protected final VillageSiege villageSiege = new VillageSiege(this);
|
| 98 | private WorldServer.ServerBlockEventList[] blockEventQueue = new WorldServer.ServerBlockEventList[] {new WorldServer.ServerBlockEventList(), new WorldServer.ServerBlockEventList()};
|
| 99 | private int blockEventCacheIndex;
|
| 100 | private static final List<WeightedRandomChestContent> bonusChestContent = Lists.newArrayList(new WeightedRandomChestContent[] {new WeightedRandomChestContent(Items.stick, 0, 1, 3, 10), new WeightedRandomChestContent(Item.getItemFromBlock(Blocks.planks), 0, 1, 3, 10), new WeightedRandomChestContent(Item.getItemFromBlock(Blocks.log), 0, 1, 3, 10), new WeightedRandomChestContent(Items.stone_axe, 0, 1, 1, 3), new WeightedRandomChestContent(Items.wooden_axe, 0, 1, 1, 5), new WeightedRandomChestContent(Items.stone_pickaxe, 0, 1, 1, 3), new WeightedRandomChestContent(Items.wooden_pickaxe, 0, 1, 1, 5), new WeightedRandomChestContent(Items.apple, 0, 2, 3, 5), new WeightedRandomChestContent(Items.bread, 0, 2, 3, 3), new WeightedRandomChestContent(Item.getItemFromBlock(Blocks.log2), 0, 1, 3, 10)});
|
| 101 | private List<NextTickListEntry> pendingTickListEntriesThisTick = Lists.<NextTickListEntry>newArrayList();
|
| 102 |
|
| 103 | public WorldServer(MinecraftServer server, ISaveHandler saveHandlerIn, WorldInfo info, int dimensionId, Profiler profilerIn)
|
| 104 | {
|
| 105 | super(saveHandlerIn, info, WorldProvider.getProviderForDimension(dimensionId), profilerIn, false);
|
| 106 | this.mcServer = server;
|
| 107 | this.theEntityTracker = new EntityTracker(this);
|
| 108 | this.thePlayerManager = new PlayerManager(this);
|
| 109 | this.provider.registerWorld(this);
|
| 110 | this.chunkProvider = this.createChunkProvider();
|
| 111 | this.worldTeleporter = new Teleporter(this);
|
| 112 | this.calculateInitialSkylight();
|
| 113 | this.calculateInitialWeather();
|
| 114 | this.getWorldBorder().setSize(server.getMaxWorldSize());
|
| 115 | }
|
| 116 |
|
| 117 | public World init()
|
| 118 | {
|
| 119 | this.mapStorage = new MapStorage(this.saveHandler);
|
| 120 | String s = VillageCollection.fileNameForProvider(this.provider);
|
| 121 | VillageCollection villagecollection = (VillageCollection)this.mapStorage.loadData(VillageCollection.class, s);
|
| 122 |
|
| 123 | if (villagecollection == null)
|
| 124 | {
|
| 125 | this.villageCollectionObj = new VillageCollection(this);
|
| 126 | this.mapStorage.setData(s, this.villageCollectionObj);
|
| 127 | }
|
| 128 | else
|
| 129 | {
|
| 130 | this.villageCollectionObj = villagecollection;
|
| 131 | this.villageCollectionObj.setWorldsForAll(this);
|
| 132 | }
|
| 133 |
|
| 134 | this.worldScoreboard = new ServerScoreboard(this.mcServer);
|
| 135 | ScoreboardSaveData scoreboardsavedata = (ScoreboardSaveData)this.mapStorage.loadData(ScoreboardSaveData.class, "scoreboard");
|
| 136 |
|
| 137 | if (scoreboardsavedata == null)
|
| 138 | {
|
| 139 | scoreboardsavedata = new ScoreboardSaveData();
|
| 140 | this.mapStorage.setData("scoreboard", scoreboardsavedata);
|
| 141 | }
|
| 142 |
|
| 143 | scoreboardsavedata.setScoreboard(this.worldScoreboard);
|
| 144 | ((ServerScoreboard)this.worldScoreboard).func_96547_a(scoreboardsavedata);
|
| 145 | this.getWorldBorder().setCenter(this.worldInfo.getBorderCenterX(), this.worldInfo.getBorderCenterZ());
|
| 146 | this.getWorldBorder().setDamageAmount(this.worldInfo.getBorderDamagePerBlock());
|
| 147 | this.getWorldBorder().setDamageBuffer(this.worldInfo.getBorderSafeZone());
|
| 148 | this.getWorldBorder().setWarningDistance(this.worldInfo.getBorderWarningDistance());
|
| 149 | this.getWorldBorder().setWarningTime(this.worldInfo.getBorderWarningTime());
|
| 150 |
|
| 151 | if (this.worldInfo.getBorderLerpTime() > 0L)
|
| 152 | {
|
| 153 | this.getWorldBorder().setTransition(this.worldInfo.getBorderSize(), this.worldInfo.getBorderLerpTarget(), this.worldInfo.getBorderLerpTime());
|
| 154 | }
|
| 155 | else
|
| 156 | {
|
| 157 | this.getWorldBorder().setTransition(this.worldInfo.getBorderSize());
|
| 158 | }
|
| 159 |
|
| 160 | return this;
|
| 161 | }
|
| 162 |
|
| 163 | /**
|
| 164 | * Runs a single tick for the world
|
| 165 | */
|
| 166 | public void tick()
|
| 167 | {
|
| 168 | super.tick();
|
| 169 |
|
| 170 | if (this.getWorldInfo().isHardcoreModeEnabled() && this.getDifficulty() != EnumDifficulty.HARD)
|
| 171 | {
|
| 172 | this.getWorldInfo().setDifficulty(EnumDifficulty.HARD);
|
| 173 | }
|
| 174 |
|
| 175 | this.provider.getWorldChunkManager().cleanupCache();
|
| 176 |
|
| 177 | if (this.areAllPlayersAsleep())
|
| 178 | {
|
| 179 | if (this.getGameRules().getBoolean("doDaylightCycle"))
|
| 180 | {
|
| 181 | long i = this.worldInfo.getWorldTime() + 24000L;
|
| 182 | this.worldInfo.setWorldTime(i - i % 24000L);
|
| 183 | }
|
| 184 |
|
| 185 | this.wakeAllPlayers();
|
| 186 | }
|
| 187 |
|
| 188 | this.theProfiler.startSection("mobSpawner");
|
| 189 |
|
| 190 | if (this.getGameRules().getBoolean("doMobSpawning") && this.worldInfo.getTerrainType() != WorldType.DEBUG_WORLD)
|
| 191 | {
|
| 192 | this.mobSpawner.findChunksForSpawning(this, this.spawnHostileMobs, this.spawnPeacefulMobs, this.worldInfo.getWorldTotalTime() % 400L == 0L);
|
| 193 | }
|
| 194 |
|
| 195 | this.theProfiler.endStartSection("chunkSource");
|
| 196 | this.chunkProvider.unloadQueuedChunks();
|
| 197 | int j = this.calculateSkylightSubtracted(1.0F);
|
| 198 |
|
| 199 | if (j != this.getSkylightSubtracted())
|
| 200 | {
|
| 201 | this.setSkylightSubtracted(j);
|
| 202 | }
|
| 203 |
|
| 204 | this.worldInfo.setWorldTotalTime(this.worldInfo.getWorldTotalTime() + 1L);
|
| 205 |
|
| 206 | if (this.getGameRules().getBoolean("doDaylightCycle"))
|
| 207 | {
|
| 208 | this.worldInfo.setWorldTime(this.worldInfo.getWorldTime() + 1L);
|
| 209 | }
|
| 210 |
|
| 211 | this.theProfiler.endStartSection("tickPending");
|
| 212 | this.tickUpdates(false);
|
| 213 | this.theProfiler.endStartSection("tickBlocks");
|
| 214 | this.updateBlocks();
|
| 215 | this.theProfiler.endStartSection("chunkMap");
|
| 216 | this.thePlayerManager.updatePlayerInstances();
|
| 217 | this.theProfiler.endStartSection("village");
|
| 218 | this.villageCollectionObj.tick();
|
| 219 | this.villageSiege.tick();
|
| 220 | this.theProfiler.endStartSection("portalForcer");
|
| 221 | this.worldTeleporter.removeStalePortalLocations(this.getTotalWorldTime());
|
| 222 | this.theProfiler.endSection();
|
| 223 | this.sendQueuedBlockEvents();
|
| 224 | }
|
| 225 |
|
| 226 | public BiomeGenBase.SpawnListEntry getSpawnListEntryForTypeAt(EnumCreatureType creatureType, BlockPos pos)
|
| 227 | {
|
| 228 | List<BiomeGenBase.SpawnListEntry> list = this.getChunkProvider().getPossibleCreatures(creatureType, pos);
|
| 229 | return list != null && !list.isEmpty() ? (BiomeGenBase.SpawnListEntry)WeightedRandom.getRandomItem(this.rand, list) : null;
|
| 230 | }
|
| 231 |
|
| 232 | public boolean canCreatureTypeSpawnHere(EnumCreatureType creatureType, BiomeGenBase.SpawnListEntry spawnListEntry, BlockPos pos)
|
| 233 | {
|
| 234 | List<BiomeGenBase.SpawnListEntry> list = this.getChunkProvider().getPossibleCreatures(creatureType, pos);
|
| 235 | return list != null && !list.isEmpty() ? list.contains(spawnListEntry) : false;
|
| 236 | }
|
| 237 |
|
| 238 | /**
|
| 239 | * Updates the flag that indicates whether or not all players in the world are sleeping.
|
| 240 | */
|
| 241 | public void updateAllPlayersSleepingFlag()
|
| 242 | {
|
| 243 | this.allPlayersSleeping = false;
|
| 244 |
|
| 245 | if (!this.playerEntities.isEmpty())
|
| 246 | {
|
| 247 | int i = 0;
|
| 248 | int j = 0;
|
| 249 |
|
| 250 | for (EntityPlayer entityplayer : this.playerEntities)
|
| 251 | {
|
| 252 | if (entityplayer.isSpectator())
|
| 253 | {
|
| 254 | ++i;
|
| 255 | }
|
| 256 | else if (entityplayer.isPlayerSleeping())
|
| 257 | {
|
| 258 | ++j;
|
| 259 | }
|
| 260 | }
|
| 261 |
|
| 262 | this.allPlayersSleeping = j > 0 && j >= this.playerEntities.size() - i;
|
| 263 | }
|
| 264 | }
|
| 265 |
|
| 266 | protected void wakeAllPlayers()
|
| 267 | {
|
| 268 | this.allPlayersSleeping = false;
|
| 269 |
|
| 270 | for (EntityPlayer entityplayer : this.playerEntities)
|
| 271 | {
|
| 272 | if (entityplayer.isPlayerSleeping())
|
| 273 | {
|
| 274 | entityplayer.wakeUpPlayer(false, false, true);
|
| 275 | }
|
| 276 | }
|
| 277 |
|
| 278 | this.resetRainAndThunder();
|
| 279 | }
|
| 280 |
|
| 281 | private void resetRainAndThunder()
|
| 282 | {
|
| 283 | this.worldInfo.setRainTime(0);
|
| 284 | this.worldInfo.setRaining(false);
|
| 285 | this.worldInfo.setThunderTime(0);
|
| 286 | this.worldInfo.setThundering(false);
|
| 287 | }
|
| 288 |
|
| 289 | public boolean areAllPlayersAsleep()
|
| 290 | {
|
| 291 | if (this.allPlayersSleeping && !this.isRemote)
|
| 292 | {
|
| 293 | for (EntityPlayer entityplayer : this.playerEntities)
|
| 294 | {
|
| 295 | if (entityplayer.isSpectator() || !entityplayer.isPlayerFullyAsleep())
|
| 296 | {
|
| 297 | return false;
|
| 298 | }
|
| 299 | }
|
| 300 |
|
| 301 | return true;
|
| 302 | }
|
| 303 | else
|
| 304 | {
|
| 305 | return false;
|
| 306 | }
|
| 307 | }
|
| 308 |
|
| 309 | /**
|
| 310 | * Sets a new spawn location by finding an uncovered block at a random (x,z) location in the chunk.
|
| 311 | */
|
| 312 | public void setInitialSpawnLocation()
|
| 313 | {
|
| 314 | if (this.worldInfo.getSpawnY() <= 0)
|
| 315 | {
|
| 316 | this.worldInfo.setSpawnY(this.getSeaLevel() + 1);
|
| 317 | }
|
| 318 |
|
| 319 | int i = this.worldInfo.getSpawnX();
|
| 320 | int j = this.worldInfo.getSpawnZ();
|
| 321 | int k = 0;
|
| 322 |
|
| 323 | while (this.getGroundAboveSeaLevel(new BlockPos(i, 0, j)).getMaterial() == Material.air)
|
| 324 | {
|
| 325 | i += this.rand.nextInt(8) - this.rand.nextInt(8);
|
| 326 | j += this.rand.nextInt(8) - this.rand.nextInt(8);
|
| 327 | ++k;
|
| 328 |
|
| 329 | if (k == 10000)
|
| 330 | {
|
| 331 | break;
|
| 332 | }
|
| 333 | }
|
| 334 |
|
| 335 | this.worldInfo.setSpawnX(i);
|
| 336 | this.worldInfo.setSpawnZ(j);
|
| 337 | }
|
| 338 |
|
| 339 | protected void updateBlocks()
|
| 340 | {
|
| 341 | super.updateBlocks();
|
| 342 |
|
| 343 | if (this.worldInfo.getTerrainType() == WorldType.DEBUG_WORLD)
|
| 344 | {
|
| 345 | for (ChunkCoordIntPair chunkcoordintpair1 : this.activeChunkSet)
|
| 346 | {
|
| 347 | this.getChunkFromChunkCoords(chunkcoordintpair1.chunkXPos, chunkcoordintpair1.chunkZPos).func_150804_b(false);
|
| 348 | }
|
| 349 | }
|
| 350 | else
|
| 351 | {
|
| 352 | int i = 0;
|
| 353 | int j = 0;
|
| 354 |
|
| 355 | for (ChunkCoordIntPair chunkcoordintpair : this.activeChunkSet)
|
| 356 | {
|
| 357 | int k = chunkcoordintpair.chunkXPos * 16;
|
| 358 | int l = chunkcoordintpair.chunkZPos * 16;
|
| 359 | this.theProfiler.startSection("getChunk");
|
| 360 | Chunk chunk = this.getChunkFromChunkCoords(chunkcoordintpair.chunkXPos, chunkcoordintpair.chunkZPos);
|
| 361 | this.playMoodSoundAndCheckLight(k, l, chunk);
|
| 362 | this.theProfiler.endStartSection("tickChunk");
|
| 363 | chunk.func_150804_b(false);
|
| 364 | this.theProfiler.endStartSection("thunder");
|
| 365 |
|
| 366 | if (this.rand.nextInt(100000) == 0 && this.isRaining() && this.isThundering())
|
| 367 | {
|
| 368 | this.updateLCG = this.updateLCG * 3 + 1013904223;
|
| 369 | int i1 = this.updateLCG >> 2;
|
| 370 | BlockPos blockpos = this.adjustPosToNearbyEntity(new BlockPos(k + (i1 & 15), 0, l + (i1 >> 8 & 15)));
|
| 371 |
|
| 372 | if (this.isRainingAt(blockpos))
|
| 373 | {
|
| 374 | this.addWeatherEffect(new EntityLightningBolt(this, (double)blockpos.getX(), (double)blockpos.getY(), (double)blockpos.getZ()));
|
| 375 | }
|
| 376 | }
|
| 377 |
|
| 378 | this.theProfiler.endStartSection("iceandsnow");
|
| 379 |
|
| 380 | if (this.rand.nextInt(16) == 0)
|
| 381 | {
|
| 382 | this.updateLCG = this.updateLCG * 3 + 1013904223;
|
| 383 | int k2 = this.updateLCG >> 2;
|
| 384 | BlockPos blockpos2 = this.getPrecipitationHeight(new BlockPos(k + (k2 & 15), 0, l + (k2 >> 8 & 15)));
|
| 385 | BlockPos blockpos1 = blockpos2.down();
|
| 386 |
|
| 387 | if (this.canBlockFreezeNoWater(blockpos1))
|
| 388 | {
|
| 389 | this.setBlockState(blockpos1, Blocks.ice.getDefaultState());
|
| 390 | }
|
| 391 |
|
| 392 | if (this.isRaining() && this.canSnowAt(blockpos2, true))
|
| 393 | {
|
| 394 | this.setBlockState(blockpos2, Blocks.snow_layer.getDefaultState());
|
| 395 | }
|
| 396 |
|
| 397 | if (this.isRaining() && this.getBiomeGenForCoords(blockpos1).canRain())
|
| 398 | {
|
| 399 | this.getBlockState(blockpos1).getBlock().fillWithRain(this, blockpos1);
|
| 400 | }
|
| 401 | }
|
| 402 |
|
| 403 | this.theProfiler.endStartSection("tickBlocks");
|
| 404 | int l2 = this.getGameRules().getInt("randomTickSpeed");
|
| 405 |
|
| 406 | if (l2 > 0)
|
| 407 | {
|
| 408 | for (ExtendedBlockStorage extendedblockstorage : chunk.getBlockStorageArray())
|
| 409 | {
|
| 410 | if (extendedblockstorage != null && extendedblockstorage.getNeedsRandomTick())
|
| 411 | {
|
| 412 | for (int j1 = 0; j1 < l2; ++j1)
|
| 413 | {
|
| 414 | this.updateLCG = this.updateLCG * 3 + 1013904223;
|
| 415 | int k1 = this.updateLCG >> 2;
|
| 416 | int l1 = k1 & 15;
|
| 417 | int i2 = k1 >> 8 & 15;
|
| 418 | int j2 = k1 >> 16 & 15;
|
| 419 | ++j;
|
| 420 | IBlockState iblockstate = extendedblockstorage.get(l1, j2, i2);
|
| 421 | Block block = iblockstate.getBlock();
|
| 422 |
|
| 423 | if (block.getTickRandomly())
|
| 424 | {
|
| 425 | ++i;
|
| 426 | block.randomTick(this, new BlockPos(l1 + k, j2 + extendedblockstorage.getYLocation(), i2 + l), iblockstate, this.rand);
|
| 427 | }
|
| 428 | }
|
| 429 | }
|
| 430 | }
|
| 431 | }
|
| 432 |
|
| 433 | this.theProfiler.endSection();
|
| 434 | }
|
| 435 | }
|
| 436 | }
|
| 437 |
|
| 438 | protected BlockPos adjustPosToNearbyEntity(BlockPos pos)
|
| 439 | {
|
| 440 | BlockPos blockpos = this.getPrecipitationHeight(pos);
|
| 441 | AxisAlignedBB axisalignedbb = (new AxisAlignedBB(blockpos, new BlockPos(blockpos.getX(), this.getHeight(), blockpos.getZ()))).expand(3.0D, 3.0D, 3.0D);
|
| 442 | List<EntityLivingBase> list = this.getEntitiesWithinAABB(EntityLivingBase.class, axisalignedbb, new Predicate<EntityLivingBase>()
|
| 443 | {
|
| 444 | public boolean apply(EntityLivingBase p_apply_1_)
|
| 445 | {
|
| 446 | return p_apply_1_ != null && p_apply_1_.isEntityAlive() && WorldServer.this.canSeeSky(p_apply_1_.getPosition());
|
| 447 | }
|
| 448 | });
|
| 449 | return !list.isEmpty() ? ((EntityLivingBase)list.get(this.rand.nextInt(list.size()))).getPosition() : blockpos;
|
| 450 | }
|
| 451 |
|
| 452 | public boolean isBlockTickPending(BlockPos pos, Block blockType)
|
| 453 | {
|
| 454 | NextTickListEntry nextticklistentry = new NextTickListEntry(pos, blockType);
|
| 455 | return this.pendingTickListEntriesThisTick.contains(nextticklistentry);
|
| 456 | }
|
| 457 |
|
| 458 | public void scheduleUpdate(BlockPos pos, Block blockIn, int delay)
|
| 459 | {
|
| 460 | this.updateBlockTick(pos, blockIn, delay, 0);
|
| 461 | }
|
| 462 |
|
| 463 | public void updateBlockTick(BlockPos pos, Block blockIn, int delay, int priority)
|
| 464 | {
|
| 465 | NextTickListEntry nextticklistentry = new NextTickListEntry(pos, blockIn);
|
| 466 | int i = 0;
|
| 467 |
|
| 468 | if (this.scheduledUpdatesAreImmediate && blockIn.getMaterial() != Material.air)
|
| 469 | {
|
| 470 | if (blockIn.requiresUpdates())
|
| 471 | {
|
| 472 | i = 8;
|
| 473 |
|
| 474 | if (this.isAreaLoaded(nextticklistentry.position.add(-i, -i, -i), nextticklistentry.position.add(i, i, i)))
|
| 475 | {
|
| 476 | IBlockState iblockstate = this.getBlockState(nextticklistentry.position);
|
| 477 |
|
| 478 | if (iblockstate.getBlock().getMaterial() != Material.air && iblockstate.getBlock() == nextticklistentry.getBlock())
|
| 479 | {
|
| 480 | iblockstate.getBlock().updateTick(this, nextticklistentry.position, iblockstate, this.rand);
|
| 481 | }
|
| 482 | }
|
| 483 |
|
| 484 | return;
|
| 485 | }
|
| 486 |
|
| 487 | delay = 1;
|
| 488 | }
|
| 489 |
|
| 490 | if (this.isAreaLoaded(pos.add(-i, -i, -i), pos.add(i, i, i)))
|
| 491 | {
|
| 492 | if (blockIn.getMaterial() != Material.air)
|
| 493 | {
|
| 494 | nextticklistentry.setScheduledTime((long)delay + this.worldInfo.getWorldTotalTime());
|
| 495 | nextticklistentry.setPriority(priority);
|
| 496 | }
|
| 497 |
|
| 498 | if (!this.pendingTickListEntriesHashSet.contains(nextticklistentry))
|
| 499 | {
|
| 500 | this.pendingTickListEntriesHashSet.add(nextticklistentry);
|
| 501 | this.pendingTickListEntriesTreeSet.add(nextticklistentry);
|
| 502 | }
|
| 503 | }
|
| 504 | }
|
| 505 |
|
| 506 | public void scheduleBlockUpdate(BlockPos pos, Block blockIn, int delay, int priority)
|
| 507 | {
|
| 508 | NextTickListEntry nextticklistentry = new NextTickListEntry(pos, blockIn);
|
| 509 | nextticklistentry.setPriority(priority);
|
| 510 |
|
| 511 | if (blockIn.getMaterial() != Material.air)
|
| 512 | {
|
| 513 | nextticklistentry.setScheduledTime((long)delay + this.worldInfo.getWorldTotalTime());
|
| 514 | }
|
| 515 |
|
| 516 | if (!this.pendingTickListEntriesHashSet.contains(nextticklistentry))
|
| 517 | {
|
| 518 | this.pendingTickListEntriesHashSet.add(nextticklistentry);
|
| 519 | this.pendingTickListEntriesTreeSet.add(nextticklistentry);
|
| 520 | }
|
| 521 | }
|
| 522 |
|
| 523 | /**
|
| 524 | * Updates (and cleans up) entities and tile entities
|
| 525 | */
|
| 526 | public void updateEntities()
|
| 527 | {
|
| 528 | if (this.playerEntities.isEmpty())
|
| 529 | {
|
| 530 | if (this.updateEntityTick++ >= 1200)
|
| 531 | {
|
| 532 | return;
|
| 533 | }
|
| 534 | }
|
| 535 | else
|
| 536 | {
|
| 537 | this.resetUpdateEntityTick();
|
| 538 | }
|
| 539 |
|
| 540 | super.updateEntities();
|
| 541 | }
|
| 542 |
|
| 543 | /**
|
| 544 | * Resets the updateEntityTick field to 0
|
| 545 | */
|
| 546 | public void resetUpdateEntityTick()
|
| 547 | {
|
| 548 | this.updateEntityTick = 0;
|
| 549 | }
|
| 550 |
|
| 551 | /**
|
| 552 | * Runs through the list of updates to run and ticks them
|
| 553 | */
|
| 554 | public boolean tickUpdates(boolean p_72955_1_)
|
| 555 | {
|
| 556 | if (this.worldInfo.getTerrainType() == WorldType.DEBUG_WORLD)
|
| 557 | {
|
| 558 | return false;
|
| 559 | }
|
| 560 | else
|
| 561 | {
|
| 562 | int i = this.pendingTickListEntriesTreeSet.size();
|
| 563 |
|
| 564 | if (i != this.pendingTickListEntriesHashSet.size())
|
| 565 | {
|
| 566 | throw new IllegalStateException("TickNextTick list out of synch");
|
| 567 | }
|
| 568 | else
|
| 569 | {
|
| 570 | if (i > 1000)
|
| 571 | {
|
| 572 | i = 1000;
|
| 573 | }
|
| 574 |
|
| 575 | this.theProfiler.startSection("cleaning");
|
| 576 |
|
| 577 | for (int j = 0; j < i; ++j)
|
| 578 | {
|
| 579 | NextTickListEntry nextticklistentry = (NextTickListEntry)this.pendingTickListEntriesTreeSet.first();
|
| 580 |
|
| 581 | if (!p_72955_1_ && nextticklistentry.scheduledTime > this.worldInfo.getWorldTotalTime())
|
| 582 | {
|
| 583 | break;
|
| 584 | }
|
| 585 |
|
| 586 | this.pendingTickListEntriesTreeSet.remove(nextticklistentry);
|
| 587 | this.pendingTickListEntriesHashSet.remove(nextticklistentry);
|
| 588 | this.pendingTickListEntriesThisTick.add(nextticklistentry);
|
| 589 | }
|
| 590 |
|
| 591 | this.theProfiler.endSection();
|
| 592 | this.theProfiler.startSection("ticking");
|
| 593 | Iterator<NextTickListEntry> iterator = this.pendingTickListEntriesThisTick.iterator();
|
| 594 |
|
| 595 | while (iterator.hasNext())
|
| 596 | {
|
| 597 | NextTickListEntry nextticklistentry1 = (NextTickListEntry)iterator.next();
|
| 598 | iterator.remove();
|
| 599 | int k = 0;
|
| 600 |
|
| 601 | if (this.isAreaLoaded(nextticklistentry1.position.add(-k, -k, -k), nextticklistentry1.position.add(k, k, k)))
|
| 602 | {
|
| 603 | IBlockState iblockstate = this.getBlockState(nextticklistentry1.position);
|
| 604 |
|
| 605 | if (iblockstate.getBlock().getMaterial() != Material.air && Block.isEqualTo(iblockstate.getBlock(), nextticklistentry1.getBlock()))
|
| 606 | {
|
| 607 | try
|
| 608 | {
|
| 609 | iblockstate.getBlock().updateTick(this, nextticklistentry1.position, iblockstate, this.rand);
|
| 610 | }
|
| 611 | catch (Throwable throwable)
|
| 612 | {
|
| 613 | CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Exception while ticking a block");
|
| 614 | CrashReportCategory crashreportcategory = crashreport.makeCategory("Block being ticked");
|
| 615 | CrashReportCategory.addBlockInfo(crashreportcategory, nextticklistentry1.position, iblockstate);
|
| 616 | throw new ReportedException(crashreport);
|
| 617 | }
|
| 618 | }
|
| 619 | }
|
| 620 | else
|
| 621 | {
|
| 622 | this.scheduleUpdate(nextticklistentry1.position, nextticklistentry1.getBlock(), 0);
|
| 623 | }
|
| 624 | }
|
| 625 |
|
| 626 | this.theProfiler.endSection();
|
| 627 | this.pendingTickListEntriesThisTick.clear();
|
| 628 | return !this.pendingTickListEntriesTreeSet.isEmpty();
|
| 629 | }
|
| 630 | }
|
| 631 | }
|
| 632 |
|
| 633 | public List<NextTickListEntry> getPendingBlockUpdates(Chunk chunkIn, boolean p_72920_2_)
|
| 634 | {
|
| 635 | ChunkCoordIntPair chunkcoordintpair = chunkIn.getChunkCoordIntPair();
|
| 636 | int i = (chunkcoordintpair.chunkXPos << 4) - 2;
|
| 637 | int j = i + 16 + 2;
|
| 638 | int k = (chunkcoordintpair.chunkZPos << 4) - 2;
|
| 639 | int l = k + 16 + 2;
|
| 640 | return this.func_175712_a(new StructureBoundingBox(i, 0, k, j, 256, l), p_72920_2_);
|
| 641 | }
|
| 642 |
|
| 643 | public List<NextTickListEntry> func_175712_a(StructureBoundingBox structureBB, boolean p_175712_2_)
|
| 644 | {
|
| 645 | List<NextTickListEntry> list = null;
|
| 646 |
|
| 647 | for (int i = 0; i < 2; ++i)
|
| 648 | {
|
| 649 | Iterator<NextTickListEntry> iterator;
|
| 650 |
|
| 651 | if (i == 0)
|
| 652 | {
|
| 653 | iterator = this.pendingTickListEntriesTreeSet.iterator();
|
| 654 | }
|
| 655 | else
|
| 656 | {
|
| 657 | iterator = this.pendingTickListEntriesThisTick.iterator();
|
| 658 | }
|
| 659 |
|
| 660 | while (iterator.hasNext())
|
| 661 | {
|
| 662 | NextTickListEntry nextticklistentry = (NextTickListEntry)iterator.next();
|
| 663 | BlockPos blockpos = nextticklistentry.position;
|
| 664 |
|
| 665 | if (blockpos.getX() >= structureBB.minX && blockpos.getX() < structureBB.maxX && blockpos.getZ() >= structureBB.minZ && blockpos.getZ() < structureBB.maxZ)
|
| 666 | {
|
| 667 | if (p_175712_2_)
|
| 668 | {
|
| 669 | this.pendingTickListEntriesHashSet.remove(nextticklistentry);
|
| 670 | iterator.remove();
|
| 671 | }
|
| 672 |
|
| 673 | if (list == null)
|
| 674 | {
|
| 675 | list = Lists.<NextTickListEntry>newArrayList();
|
| 676 | }
|
| 677 |
|
| 678 | list.add(nextticklistentry);
|
| 679 | }
|
| 680 | }
|
| 681 | }
|
| 682 |
|
| 683 | return list;
|
| 684 | }
|
| 685 |
|
| 686 | /**
|
| 687 | * Will update the entity in the world if the chunk the entity is in is currently loaded or its forced to update.
|
| 688 | * Args: entity, forceUpdate
|
| 689 | */
|
| 690 | public void updateEntityWithOptionalForce(Entity entityIn, boolean forceUpdate)
|
| 691 | {
|
| 692 | if (!this.canSpawnAnimals() && (entityIn instanceof EntityAnimal || entityIn instanceof EntityWaterMob))
|
| 693 | {
|
| 694 | entityIn.setDead();
|
| 695 | }
|
| 696 |
|
| 697 | if (!this.canSpawnNPCs() && entityIn instanceof INpc)
|
| 698 | {
|
| 699 | entityIn.setDead();
|
| 700 | }
|
| 701 |
|
| 702 | super.updateEntityWithOptionalForce(entityIn, forceUpdate);
|
| 703 | }
|
| 704 |
|
| 705 | private boolean canSpawnNPCs()
|
| 706 | {
|
| 707 | return this.mcServer.getCanSpawnNPCs();
|
| 708 | }
|
| 709 |
|
| 710 | private boolean canSpawnAnimals()
|
| 711 | {
|
| 712 | return this.mcServer.getCanSpawnAnimals();
|
| 713 | }
|
| 714 |
|
| 715 | /**
|
| 716 | * Creates the chunk provider for this world. Called in the constructor. Retrieves provider from worldProvider?
|
| 717 | */
|
| 718 | protected IChunkProvider createChunkProvider()
|
| 719 | {
|
| 720 | IChunkLoader ichunkloader = this.saveHandler.getChunkLoader(this.provider);
|
| 721 | this.theChunkProviderServer = new ChunkProviderServer(this, ichunkloader, this.provider.createChunkGenerator());
|
| 722 | return this.theChunkProviderServer;
|
| 723 | }
|
| 724 |
|
| 725 | public List<TileEntity> getTileEntitiesIn(int minX, int minY, int minZ, int maxX, int maxY, int maxZ)
|
| 726 | {
|
| 727 | List<TileEntity> list = Lists.<TileEntity>newArrayList();
|
| 728 |
|
| 729 | for (int i = 0; i < this.loadedTileEntityList.size(); ++i)
|
| 730 | {
|
| 731 | TileEntity tileentity = (TileEntity)this.loadedTileEntityList.get(i);
|
| 732 | BlockPos blockpos = tileentity.getPos();
|
| 733 |
|
| 734 | if (blockpos.getX() >= minX && blockpos.getY() >= minY && blockpos.getZ() >= minZ && blockpos.getX() < maxX && blockpos.getY() < maxY && blockpos.getZ() < maxZ)
|
| 735 | {
|
| 736 | list.add(tileentity);
|
| 737 | }
|
| 738 | }
|
| 739 |
|
| 740 | return list;
|
| 741 | }
|
| 742 |
|
| 743 | public boolean isBlockModifiable(EntityPlayer player, BlockPos pos)
|
| 744 | {
|
| 745 | return !this.mcServer.isBlockProtected(this, pos, player) && this.getWorldBorder().contains(pos);
|
| 746 | }
|
| 747 |
|
| 748 | public void initialize(WorldSettings settings)
|
| 749 | {
|
| 750 | if (!this.worldInfo.isInitialized())
|
| 751 | {
|
| 752 | try
|
| 753 | {
|
| 754 | this.createSpawnPosition(settings);
|
| 755 |
|
| 756 | if (this.worldInfo.getTerrainType() == WorldType.DEBUG_WORLD)
|
| 757 | {
|
| 758 | this.setDebugWorldSettings();
|
| 759 | }
|
| 760 |
|
| 761 | super.initialize(settings);
|
| 762 | }
|
| 763 | catch (Throwable throwable)
|
| 764 | {
|
| 765 | CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Exception initializing level");
|
| 766 |
|
| 767 | try
|
| 768 | {
|
| 769 | this.addWorldInfoToCrashReport(crashreport);
|
| 770 | }
|
| 771 | catch (Throwable var5)
|
| 772 | {
|
| 773 | ;
|
| 774 | }
|
| 775 |
|
| 776 | throw new ReportedException(crashreport);
|
| 777 | }
|
| 778 |
|
| 779 | this.worldInfo.setServerInitialized(true);
|
| 780 | }
|
| 781 | }
|
| 782 |
|
| 783 | private void setDebugWorldSettings()
|
| 784 | {
|
| 785 | this.worldInfo.setMapFeaturesEnabled(false);
|
| 786 | this.worldInfo.setAllowCommands(true);
|
| 787 | this.worldInfo.setRaining(false);
|
| 788 | this.worldInfo.setThundering(false);
|
| 789 | this.worldInfo.setCleanWeatherTime(1000000000);
|
| 790 | this.worldInfo.setWorldTime(6000L);
|
| 791 | this.worldInfo.setGameType(WorldSettings.GameType.SPECTATOR);
|
| 792 | this.worldInfo.setHardcore(false);
|
| 793 | this.worldInfo.setDifficulty(EnumDifficulty.PEACEFUL);
|
| 794 | this.worldInfo.setDifficultyLocked(true);
|
| 795 | this.getGameRules().setOrCreateGameRule("doDaylightCycle", "false");
|
| 796 | }
|
| 797 |
|
| 798 | /**
|
| 799 | * creates a spawn position at random within 256 blocks of 0,0
|
| 800 | */
|
| 801 | private void createSpawnPosition(WorldSettings settings)
|
| 802 | {
|
| 803 | if (!this.provider.canRespawnHere())
|
| 804 | {
|
| 805 | this.worldInfo.setSpawn(BlockPos.ORIGIN.up(this.provider.getAverageGroundLevel()));
|
| 806 | }
|
| 807 | else if (this.worldInfo.getTerrainType() == WorldType.DEBUG_WORLD)
|
| 808 | {
|
| 809 | this.worldInfo.setSpawn(BlockPos.ORIGIN.up());
|
| 810 | }
|
| 811 | else
|
| 812 | {
|
| 813 | this.findingSpawnPoint = true;
|
| 814 | WorldChunkManager worldchunkmanager = this.provider.getWorldChunkManager();
|
| 815 | List<BiomeGenBase> list = worldchunkmanager.getBiomesToSpawnIn();
|
| 816 | Random random = new Random(this.getSeed());
|
| 817 | BlockPos blockpos = worldchunkmanager.findBiomePosition(0, 0, 256, list, random);
|
| 818 | int i = 0;
|
| 819 | int j = this.provider.getAverageGroundLevel();
|
| 820 | int k = 0;
|
| 821 |
|
| 822 | if (blockpos != null)
|
| 823 | {
|
| 824 | i = blockpos.getX();
|
| 825 | k = blockpos.getZ();
|
| 826 | }
|
| 827 | else
|
| 828 | {
|
| 829 | logger.warn("Unable to find spawn biome");
|
| 830 | }
|
| 831 |
|
| 832 | int l = 0;
|
| 833 |
|
| 834 | while (!this.provider.canCoordinateBeSpawn(i, k))
|
| 835 | {
|
| 836 | i += random.nextInt(64) - random.nextInt(64);
|
| 837 | k += random.nextInt(64) - random.nextInt(64);
|
| 838 | ++l;
|
| 839 |
|
| 840 | if (l == 1000)
|
| 841 | {
|
| 842 | break;
|
| 843 | }
|
| 844 | }
|
| 845 |
|
| 846 | this.worldInfo.setSpawn(new BlockPos(i, j, k));
|
| 847 | this.findingSpawnPoint = false;
|
| 848 |
|
| 849 | if (settings.isBonusChestEnabled())
|
| 850 | {
|
| 851 | this.createBonusChest();
|
| 852 | }
|
| 853 | }
|
| 854 | }
|
| 855 |
|
| 856 | /**
|
| 857 | * Creates the bonus chest in the world.
|
| 858 | */
|
| 859 | protected void createBonusChest()
|
| 860 | {
|
| 861 | WorldGeneratorBonusChest worldgeneratorbonuschest = new WorldGeneratorBonusChest(bonusChestContent, 10);
|
| 862 |
|
| 863 | for (int i = 0; i < 10; ++i)
|
| 864 | {
|
| 865 | int j = this.worldInfo.getSpawnX() + this.rand.nextInt(6) - this.rand.nextInt(6);
|
| 866 | int k = this.worldInfo.getSpawnZ() + this.rand.nextInt(6) - this.rand.nextInt(6);
|
| 867 | BlockPos blockpos = this.getTopSolidOrLiquidBlock(new BlockPos(j, 0, k)).up();
|
| 868 |
|
| 869 | if (worldgeneratorbonuschest.generate(this, this.rand, blockpos))
|
| 870 | {
|
| 871 | break;
|
| 872 | }
|
| 873 | }
|
| 874 | }
|
| 875 |
|
| 876 | /**
|
| 877 | * Returns null for anything other than the End
|
| 878 | */
|
| 879 | public BlockPos getSpawnCoordinate()
|
| 880 | {
|
| 881 | return this.provider.getSpawnCoordinate();
|
| 882 | }
|
| 883 |
|
| 884 | /**
|
| 885 | * Saves all chunks to disk while updating progress bar.
|
| 886 | */
|
| 887 | public void saveAllChunks(boolean p_73044_1_, IProgressUpdate progressCallback) throws MinecraftException
|
| 888 | {
|
| 889 | if (this.chunkProvider.canSave())
|
| 890 | {
|
| 891 | if (progressCallback != null)
|
| 892 | {
|
| 893 | progressCallback.displaySavingString("Saving level");
|
| 894 | }
|
| 895 |
|
| 896 | this.saveLevel();
|
| 897 |
|
| 898 | if (progressCallback != null)
|
| 899 | {
|
| 900 | progressCallback.displayLoadingString("Saving chunks");
|
| 901 | }
|
| 902 |
|
| 903 | this.chunkProvider.saveChunks(p_73044_1_, progressCallback);
|
| 904 |
|
| 905 | for (Chunk chunk : Lists.newArrayList(this.theChunkProviderServer.func_152380_a()))
|
| 906 | {
|
| 907 | if (chunk != null && !this.thePlayerManager.hasPlayerInstance(chunk.xPosition, chunk.zPosition))
|
| 908 | {
|
| 909 | this.theChunkProviderServer.dropChunk(chunk.xPosition, chunk.zPosition);
|
| 910 | }
|
| 911 | }
|
| 912 | }
|
| 913 | }
|
| 914 |
|
| 915 | /**
|
| 916 | * saves chunk data - currently only called during execution of the Save All command
|
| 917 | */
|
| 918 | public void saveChunkData()
|
| 919 | {
|
| 920 | if (this.chunkProvider.canSave())
|
| 921 | {
|
| 922 | this.chunkProvider.saveExtraData();
|
| 923 | }
|
| 924 | }
|
| 925 |
|
| 926 | /**
|
| 927 | * Saves the chunks to disk.
|
| 928 | */
|
| 929 | protected void saveLevel() throws MinecraftException
|
| 930 | {
|
| 931 | this.checkSessionLock();
|
| 932 | this.worldInfo.setBorderSize(this.getWorldBorder().getDiameter());
|
| 933 | this.worldInfo.getBorderCenterX(this.getWorldBorder().getCenterX());
|
| 934 | this.worldInfo.getBorderCenterZ(this.getWorldBorder().getCenterZ());
|
| 935 | this.worldInfo.setBorderSafeZone(this.getWorldBorder().getDamageBuffer());
|
| 936 | this.worldInfo.setBorderDamagePerBlock(this.getWorldBorder().getDamageAmount());
|
| 937 | this.worldInfo.setBorderWarningDistance(this.getWorldBorder().getWarningDistance());
|
| 938 | this.worldInfo.setBorderWarningTime(this.getWorldBorder().getWarningTime());
|
| 939 | this.worldInfo.setBorderLerpTarget(this.getWorldBorder().getTargetSize());
|
| 940 | this.worldInfo.setBorderLerpTime(this.getWorldBorder().getTimeUntilTarget());
|
| 941 | this.saveHandler.saveWorldInfoWithPlayer(this.worldInfo, this.mcServer.getConfigurationManager().getHostPlayerData());
|
| 942 | this.mapStorage.saveAllData();
|
| 943 | }
|
| 944 |
|
| 945 | protected void onEntityAdded(Entity entityIn)
|
| 946 | {
|
| 947 | super.onEntityAdded(entityIn);
|
| 948 | this.entitiesById.addKey(entityIn.getEntityId(), entityIn);
|
| 949 | this.entitiesByUuid.put(entityIn.getUniqueID(), entityIn);
|
| 950 | Entity[] aentity = entityIn.getParts();
|
| 951 |
|
| 952 | if (aentity != null)
|
| 953 | {
|
| 954 | for (int i = 0; i < aentity.length; ++i)
|
| 955 | {
|
| 956 | this.entitiesById.addKey(aentity[i].getEntityId(), aentity[i]);
|
| 957 | }
|
| 958 | }
|
| 959 | }
|
| 960 |
|
| 961 | protected void onEntityRemoved(Entity entityIn)
|
| 962 | {
|
| 963 | super.onEntityRemoved(entityIn);
|
| 964 | this.entitiesById.removeObject(entityIn.getEntityId());
|
| 965 | this.entitiesByUuid.remove(entityIn.getUniqueID());
|
| 966 | Entity[] aentity = entityIn.getParts();
|
| 967 |
|
| 968 | if (aentity != null)
|
| 969 | {
|
| 970 | for (int i = 0; i < aentity.length; ++i)
|
| 971 | {
|
| 972 | this.entitiesById.removeObject(aentity[i].getEntityId());
|
| 973 | }
|
| 974 | }
|
| 975 | }
|
| 976 |
|
| 977 | /**
|
| 978 | * adds a lightning bolt to the list of lightning bolts in this world.
|
| 979 | */
|
| 980 | public boolean addWeatherEffect(Entity entityIn)
|
| 981 | {
|
| 982 | if (super.addWeatherEffect(entityIn))
|
| 983 | {
|
| 984 | this.mcServer.getConfigurationManager().sendToAllNear(entityIn.posX, entityIn.posY, entityIn.posZ, 512.0D, this.provider.getDimensionId(), new S2CPacketSpawnGlobalEntity(entityIn));
|
| 985 | return true;
|
| 986 | }
|
| 987 | else
|
| 988 | {
|
| 989 | return false;
|
| 990 | }
|
| 991 | }
|
| 992 |
|
| 993 | /**
|
| 994 | * sends a Packet 38 (Entity Status) to all tracked players of that entity
|
| 995 | */
|
| 996 | public void setEntityState(Entity entityIn, byte state)
|
| 997 | {
|
| 998 | this.getEntityTracker().func_151248_b(entityIn, new S19PacketEntityStatus(entityIn, state));
|
| 999 | }
|
| 1000 |
|
| 1001 | /**
|
| 1002 | * returns a new explosion. Does initiation (at time of writing Explosion is not finished)
|
| 1003 | */
|
| 1004 | public Explosion newExplosion(Entity entityIn, double x, double y, double z, float strength, boolean isFlaming, boolean isSmoking)
|
| 1005 | {
|
| 1006 | Explosion explosion = new Explosion(this, entityIn, x, y, z, strength, isFlaming, isSmoking);
|
| 1007 | explosion.doExplosionA();
|
| 1008 | explosion.doExplosionB(false);
|
| 1009 |
|
| 1010 | if (!isSmoking)
|
| 1011 | {
|
| 1012 | explosion.clearAffectedBlockPositions();
|
| 1013 | }
|
| 1014 |
|
| 1015 | for (EntityPlayer entityplayer : this.playerEntities)
|
| 1016 | {
|
| 1017 | if (entityplayer.getDistanceSq(x, y, z) < 4096.0D)
|
| 1018 | {
|
| 1019 | ((EntityPlayerMP)entityplayer).playerNetServerHandler.sendPacket(new S27PacketExplosion(x, y, z, strength, explosion.getAffectedBlockPositions(), (Vec3)explosion.getPlayerKnockbackMap().get(entityplayer)));
|
| 1020 | }
|
| 1021 | }
|
| 1022 |
|
| 1023 | return explosion;
|
| 1024 | }
|
| 1025 |
|
| 1026 | public void addBlockEvent(BlockPos pos, Block blockIn, int eventID, int eventParam)
|
| 1027 | {
|
| 1028 | BlockEventData blockeventdata = new BlockEventData(pos, blockIn, eventID, eventParam);
|
| 1029 |
|
| 1030 | for (BlockEventData blockeventdata1 : this.blockEventQueue[this.blockEventCacheIndex])
|
| 1031 | {
|
| 1032 | if (blockeventdata1.equals(blockeventdata))
|
| 1033 | {
|
| 1034 | return;
|
| 1035 | }
|
| 1036 | }
|
| 1037 |
|
| 1038 | this.blockEventQueue[this.blockEventCacheIndex].add(blockeventdata);
|
| 1039 | }
|
| 1040 |
|
| 1041 | private void sendQueuedBlockEvents()
|
| 1042 | {
|
| 1043 | while (!this.blockEventQueue[this.blockEventCacheIndex].isEmpty())
|
| 1044 | {
|
| 1045 | int i = this.blockEventCacheIndex;
|
| 1046 | this.blockEventCacheIndex ^= 1;
|
| 1047 |
|
| 1048 | for (BlockEventData blockeventdata : this.blockEventQueue[i])
|
| 1049 | {
|
| 1050 | if (this.fireBlockEvent(blockeventdata))
|
| 1051 | {
|
| 1052 | this.mcServer.getConfigurationManager().sendToAllNear((double)blockeventdata.getPosition().getX(), (double)blockeventdata.getPosition().getY(), (double)blockeventdata.getPosition().getZ(), 64.0D, this.provider.getDimensionId(), new S24PacketBlockAction(blockeventdata.getPosition(), blockeventdata.getBlock(), blockeventdata.getEventID(), blockeventdata.getEventParameter()));
|
| 1053 | }
|
| 1054 | }
|
| 1055 |
|
| 1056 | this.blockEventQueue[i].clear();
|
| 1057 | }
|
| 1058 | }
|
| 1059 |
|
| 1060 | private boolean fireBlockEvent(BlockEventData event)
|
| 1061 | {
|
| 1062 | IBlockState iblockstate = this.getBlockState(event.getPosition());
|
| 1063 | return iblockstate.getBlock() == event.getBlock() ? iblockstate.getBlock().onBlockEventReceived(this, event.getPosition(), iblockstate, event.getEventID(), event.getEventParameter()) : false;
|
| 1064 | }
|
| 1065 |
|
| 1066 | /**
|
| 1067 | * Syncs all changes to disk and wait for completion.
|
| 1068 | */
|
| 1069 | public void flush()
|
| 1070 | {
|
| 1071 | this.saveHandler.flush();
|
| 1072 | }
|
| 1073 |
|
| 1074 | /**
|
| 1075 | * Updates all weather states.
|
| 1076 | */
|
| 1077 | protected void updateWeather()
|
| 1078 | {
|
| 1079 | boolean flag = this.isRaining();
|
| 1080 | super.updateWeather();
|
| 1081 |
|
| 1082 | if (this.prevRainingStrength != this.rainingStrength)
|
| 1083 | {
|
| 1084 | this.mcServer.getConfigurationManager().sendPacketToAllPlayersInDimension(new S2BPacketChangeGameState(7, this.rainingStrength), this.provider.getDimensionId());
|
| 1085 | }
|
| 1086 |
|
| 1087 | if (this.prevThunderingStrength != this.thunderingStrength)
|
| 1088 | {
|
| 1089 | this.mcServer.getConfigurationManager().sendPacketToAllPlayersInDimension(new S2BPacketChangeGameState(8, this.thunderingStrength), this.provider.getDimensionId());
|
| 1090 | }
|
| 1091 |
|
| 1092 | if (flag != this.isRaining())
|
| 1093 | {
|
| 1094 | if (flag)
|
| 1095 | {
|
| 1096 | this.mcServer.getConfigurationManager().sendPacketToAllPlayers(new S2BPacketChangeGameState(2, 0.0F));
|
| 1097 | }
|
| 1098 | else
|
| 1099 | {
|
| 1100 | this.mcServer.getConfigurationManager().sendPacketToAllPlayers(new S2BPacketChangeGameState(1, 0.0F));
|
| 1101 | }
|
| 1102 |
|
| 1103 | this.mcServer.getConfigurationManager().sendPacketToAllPlayers(new S2BPacketChangeGameState(7, this.rainingStrength));
|
| 1104 | this.mcServer.getConfigurationManager().sendPacketToAllPlayers(new S2BPacketChangeGameState(8, this.thunderingStrength));
|
| 1105 | }
|
| 1106 | }
|
| 1107 |
|
| 1108 | protected int getRenderDistanceChunks()
|
| 1109 | {
|
| 1110 | return this.mcServer.getConfigurationManager().getViewDistance();
|
| 1111 | }
|
| 1112 |
|
| 1113 | public MinecraftServer getMinecraftServer()
|
| 1114 | {
|
| 1115 | return this.mcServer;
|
| 1116 | }
|
| 1117 |
|
| 1118 | /**
|
| 1119 | * Gets the EntityTracker
|
| 1120 | */
|
| 1121 | public EntityTracker getEntityTracker()
|
| 1122 | {
|
| 1123 | return this.theEntityTracker;
|
| 1124 | }
|
| 1125 |
|
| 1126 | public PlayerManager getPlayerManager()
|
| 1127 | {
|
| 1128 | return this.thePlayerManager;
|
| 1129 | }
|
| 1130 |
|
| 1131 | public Teleporter getDefaultTeleporter()
|
| 1132 | {
|
| 1133 | return this.worldTeleporter;
|
| 1134 | }
|
| 1135 |
|
| 1136 | /**
|
| 1137 | * Spawns the desired particle and sends the necessary packets to the relevant connected players.
|
| 1138 | */
|
| 1139 | public void spawnParticle(EnumParticleTypes particleType, double xCoord, double yCoord, double zCoord, int numberOfParticles, double xOffset, double yOffset, double zOffset, double particleSpeed, int... particleArguments)
|
| 1140 | {
|
| 1141 | this.spawnParticle(particleType, false, xCoord, yCoord, zCoord, numberOfParticles, xOffset, yOffset, zOffset, particleSpeed, particleArguments);
|
| 1142 | }
|
| 1143 |
|
| 1144 | /**
|
| 1145 | * Spawns the desired particle and sends the necessary packets to the relevant connected players.
|
| 1146 | */
|
| 1147 | public void spawnParticle(EnumParticleTypes particleType, boolean longDistance, double xCoord, double yCoord, double zCoord, int numberOfParticles, double xOffset, double yOffset, double zOffset, double particleSpeed, int... particleArguments)
|
| 1148 | {
|
| 1149 | Packet packet = new S2APacketParticles(particleType, longDistance, (float)xCoord, (float)yCoord, (float)zCoord, (float)xOffset, (float)yOffset, (float)zOffset, (float)particleSpeed, numberOfParticles, particleArguments);
|
| 1150 |
|
| 1151 | for (int i = 0; i < this.playerEntities.size(); ++i)
|
| 1152 | {
|
| 1153 | EntityPlayerMP entityplayermp = (EntityPlayerMP)this.playerEntities.get(i);
|
| 1154 | BlockPos blockpos = entityplayermp.getPosition();
|
| 1155 | double d0 = blockpos.distanceSq(xCoord, yCoord, zCoord);
|
| 1156 |
|
| 1157 | if (d0 <= 256.0D || longDistance && d0 <= 65536.0D)
|
| 1158 | {
|
| 1159 | entityplayermp.playerNetServerHandler.sendPacket(packet);
|
| 1160 | }
|
| 1161 | }
|
| 1162 | }
|
| 1163 |
|
| 1164 | public Entity getEntityFromUuid(UUID uuid)
|
| 1165 | {
|
| 1166 | return (Entity)this.entitiesByUuid.get(uuid);
|
| 1167 | }
|
| 1168 |
|
| 1169 | public ListenableFuture<Object> addScheduledTask(Runnable runnableToSchedule)
|
| 1170 | {
|
| 1171 | return this.mcServer.addScheduledTask(runnableToSchedule);
|
| 1172 | }
|
| 1173 |
|
| 1174 | public boolean isCallingFromMinecraftThread()
|
| 1175 | {
|
| 1176 | return this.mcServer.isCallingFromMinecraftThread();
|
| 1177 | }
|
| 1178 |
|
| 1179 | static class ServerBlockEventList extends ArrayList<BlockEventData>
|
| 1180 | {
|
| 1181 | private ServerBlockEventList()
|
| 1182 | {
|
| 1183 | }
|
| 1184 | }
|
| 1185 | }
|
| 1186 |
|