Paper/src/main/java/net/minecraft/server/WorldServer.java

1007 Zeilen
37 KiB
Java

package net.minecraft.server;
2011-01-29 22:50:29 +01:00
import java.util.ArrayList;
2012-07-29 09:33:13 +02:00
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
2011-01-29 22:50:29 +01:00
import java.util.List;
2012-07-29 09:33:13 +02:00
import java.util.Random;
import java.util.Set;
import java.util.TreeSet;
2013-11-04 14:07:38 +01:00
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
// CraftBukkit start
import org.bukkit.WeatherType;
2012-07-29 09:33:13 +02:00
import org.bukkit.block.BlockState;
import org.bukkit.craftbukkit.util.LongHash;
import org.bukkit.event.block.BlockFormEvent;
import org.bukkit.event.weather.LightningStrikeEvent;
2012-07-29 09:33:13 +02:00
import org.bukkit.event.weather.ThunderChangeEvent;
import org.bukkit.event.weather.WeatherChangeEvent;
public class WorldServer extends World implements org.bukkit.BlockChangeDelegate {
2011-06-12 00:02:58 +02:00
// CraftBukkit end
2013-11-04 14:07:38 +01:00
private static final Logger a = LogManager.getLogger();
2012-07-29 09:33:13 +02:00
private final MinecraftServer server;
public EntityTracker tracker; // CraftBukkit - private final -> public
2012-12-20 05:03:52 +01:00
private final PlayerChunkMap manager;
2013-11-04 14:07:38 +01:00
private Set M;
private TreeSet N;
public ChunkProviderServer chunkProviderServer;
public boolean savingDisabled;
2013-11-04 14:07:38 +01:00
private boolean O;
2013-07-01 13:03:00 +02:00
private int emptyTime;
2013-11-04 14:07:38 +01:00
private final PortalTravelAgent Q;
private final SpawnerCreature R = new SpawnerCreature();
private NoteDataList[] S = new NoteDataList[] { new NoteDataList((EmptyClass2) null), new NoteDataList((EmptyClass2) null)};
private int T;
private static final StructurePieceTreasure[] U = new StructurePieceTreasure[] { new StructurePieceTreasure(Items.STICK, 0, 1, 3, 10), new StructurePieceTreasure(Item.getItemOf(Blocks.WOOD), 0, 1, 3, 10), new StructurePieceTreasure(Item.getItemOf(Blocks.LOG), 0, 1, 3, 10), new StructurePieceTreasure(Items.STONE_AXE, 0, 1, 1, 3), new StructurePieceTreasure(Items.WOOD_AXE, 0, 1, 1, 5), new StructurePieceTreasure(Items.STONE_PICKAXE, 0, 1, 1, 3), new StructurePieceTreasure(Items.WOOD_PICKAXE, 0, 1, 1, 5), new StructurePieceTreasure(Items.APPLE, 0, 2, 3, 5), new StructurePieceTreasure(Items.BREAD, 0, 2, 3, 3), new StructurePieceTreasure(Item.getItemOf(Blocks.LOG2), 0, 1, 3, 10)};
private List V = new ArrayList();
private IntHashMap entitiesById;
2012-07-29 09:33:13 +02:00
// CraftBukkit start
public final int dimension;
2013-11-04 14:07:38 +01:00
// Add env and gen to constructor
public WorldServer(MinecraftServer minecraftserver, IDataManager idatamanager, String s, int i, WorldSettings worldsettings, MethodProfiler methodprofiler, org.bukkit.World.Environment env, org.bukkit.generator.ChunkGenerator gen) {
super(idatamanager, s, worldsettings, WorldProvider.byDimension(env.getId()), methodprofiler, gen, env);
2012-07-29 09:33:13 +02:00
this.dimension = i;
this.pvpMode = minecraftserver.getPvP();
// CraftBukkit end
this.server = minecraftserver;
2012-07-29 09:33:13 +02:00
this.tracker = new EntityTracker(this);
2012-12-20 05:03:52 +01:00
this.manager = new PlayerChunkMap(this, minecraftserver.getPlayerList().o());
if (this.entitiesById == null) {
this.entitiesById = new IntHashMap();
}
2011-01-29 22:50:29 +01:00
2013-11-04 14:07:38 +01:00
if (this.M == null) {
this.M = new HashSet();
2012-07-29 09:33:13 +02:00
}
2013-11-04 14:07:38 +01:00
if (this.N == null) {
this.N = new TreeSet();
2012-07-29 09:33:13 +02:00
}
2012-11-06 13:05:28 +01:00
2013-11-04 14:07:38 +01:00
this.Q = new org.bukkit.craftbukkit.CraftTravelAgent(this); // CraftBukkit
2013-03-13 23:33:27 +01:00
this.scoreboard = new ScoreboardServer(minecraftserver);
2013-11-04 14:07:38 +01:00
PersistentScoreboard persistentscoreboard = (PersistentScoreboard) this.worldMaps.get(PersistentScoreboard.class, "scoreboard");
2013-03-13 23:33:27 +01:00
2013-11-04 14:07:38 +01:00
if (persistentscoreboard == null) {
persistentscoreboard = new PersistentScoreboard();
this.worldMaps.a("scoreboard", persistentscoreboard);
2013-03-13 23:33:27 +01:00
}
2013-11-04 14:07:38 +01:00
persistentscoreboard.a(this.scoreboard);
((ScoreboardServer) this.scoreboard).a(persistentscoreboard);
2011-01-29 22:50:29 +01:00
}
2012-07-29 09:33:13 +02:00
// CraftBukkit start
@Override
public TileEntity getTileEntity(int i, int j, int k) {
TileEntity result = super.getTileEntity(i, j, k);
2013-11-04 14:07:38 +01:00
Block type = getType(i, j, k);
2013-11-04 14:07:38 +01:00
if (type == Blocks.CHEST) {
if (!(result instanceof TileEntityChest)) {
result = fixTileEntity(i, j, k, type, result);
}
2013-11-04 14:07:38 +01:00
} else if (type == Blocks.FURNACE) {
if (!(result instanceof TileEntityFurnace)) {
result = fixTileEntity(i, j, k, type, result);
}
2013-11-04 14:07:38 +01:00
} else if (type == Blocks.DROPPER) {
if (!(result instanceof TileEntityDropper)) {
result = fixTileEntity(i, j, k, type, result);
}
2013-11-04 14:07:38 +01:00
} else if (type == Blocks.DISPENSER) {
if (!(result instanceof TileEntityDispenser)) {
result = fixTileEntity(i, j, k, type, result);
}
2013-11-04 14:07:38 +01:00
} else if (type == Blocks.JUKEBOX) {
if (!(result instanceof TileEntityRecordPlayer)) {
result = fixTileEntity(i, j, k, type, result);
}
2013-11-04 14:07:38 +01:00
} else if (type == Blocks.NOTE_BLOCK) {
if (!(result instanceof TileEntityNote)) {
result = fixTileEntity(i, j, k, type, result);
}
2013-11-04 14:07:38 +01:00
} else if (type == Blocks.MOB_SPAWNER) {
if (!(result instanceof TileEntityMobSpawner)) {
result = fixTileEntity(i, j, k, type, result);
}
2013-11-04 14:07:38 +01:00
} else if ((type == Blocks.SIGN_POST) || (type == Blocks.WALL_SIGN)) {
if (!(result instanceof TileEntitySign)) {
result = fixTileEntity(i, j, k, type, result);
}
2013-11-04 14:07:38 +01:00
} else if (type == Blocks.ENDER_CHEST) {
2012-07-29 09:33:13 +02:00
if (!(result instanceof TileEntityEnderChest)) {
result = fixTileEntity(i, j, k, type, result);
}
2013-11-04 14:07:38 +01:00
} else if (type == Blocks.BREWING_STAND) {
if (!(result instanceof TileEntityBrewingStand)) {
result = fixTileEntity(i, j, k, type, result);
}
2013-11-04 14:07:38 +01:00
} else if (type == Blocks.BEACON) {
if (!(result instanceof TileEntityBeacon)) {
result = fixTileEntity(i, j, k, type, result);
}
2013-11-04 14:07:38 +01:00
} else if (type == Blocks.HOPPER) {
if (!(result instanceof TileEntityHopper)) {
result = fixTileEntity(i, j, k, type, result);
}
}
return result;
}
2013-11-04 14:07:38 +01:00
private TileEntity fixTileEntity(int x, int y, int z, Block type, TileEntity found) {
this.getServer().getLogger().severe("Block at " + x + "," + y + "," + z + " is " + org.bukkit.Material.getMaterial(Block.b(type)).toString() + " but has " + found + ". "
+ "Bukkit will attempt to fix this, but there may be additional damage that we cannot recover.");
2013-11-04 14:07:38 +01:00
if (type instanceof IContainer) {
TileEntity replacement = ((IContainer) type).a(this, this.getData(x, y, z));
replacement.world = this;
2013-03-13 23:33:27 +01:00
this.setTileEntity(x, y, z, replacement);
return replacement;
} else {
2013-03-13 23:33:27 +01:00
this.getServer().getLogger().severe("Don't know how to fix for this type... Can't do anything! :(");
return found;
}
}
2012-07-29 09:33:13 +02:00
private boolean canSpawn(int x, int z) {
if (this.generator != null) {
return this.generator.canSpawn(this.getWorld(), x, z);
} else {
return this.worldProvider.canSpawn(x, z);
}
}
2011-01-29 22:50:29 +01:00
// CraftBukkit end
2012-07-29 09:33:13 +02:00
public void doTick() {
super.doTick();
2013-11-04 14:07:38 +01:00
if (this.getWorldData().isHardcore() && this.difficulty != EnumDifficulty.HARD) {
this.difficulty = EnumDifficulty.HARD;
2012-07-29 09:33:13 +02:00
}
2013-07-01 13:03:00 +02:00
this.worldProvider.e.b();
2012-07-29 09:33:13 +02:00
if (this.everyoneDeeplySleeping()) {
2013-07-01 13:03:00 +02:00
if (this.getGameRules().getBoolean("doDaylightCycle")) {
2012-11-06 13:05:28 +01:00
long i = this.worldData.getDayTime() + 24000L;
2012-07-29 09:33:13 +02:00
2012-11-06 13:05:28 +01:00
this.worldData.setDayTime(i - i % 24000L);
2012-07-29 09:33:13 +02:00
}
2013-07-01 13:03:00 +02:00
this.d();
2012-07-29 09:33:13 +02:00
}
2012-09-10 06:19:28 +02:00
this.methodProfiler.a("mobSpawner");
2012-07-29 09:33:13 +02:00
// CraftBukkit start - Only call spawner if we have players online and the world allows for mobs or animals
long time = this.worldData.getTime();
if (this.getGameRules().getBoolean("doMobSpawning") && (this.allowMonsters || this.allowAnimals) && (this instanceof WorldServer && this.players.size() > 0)) {
2013-11-04 14:07:38 +01:00
this.R.spawnEntities(this, this.allowMonsters && (this.ticksPerMonsterSpawns != 0 && time % this.ticksPerMonsterSpawns == 0L), this.allowAnimals && (this.ticksPerAnimalSpawns != 0 && time % this.ticksPerAnimalSpawns == 0L), this.worldData.getTime() % 400L == 0L);
// CraftBukkit end
2012-07-29 09:33:13 +02:00
}
2013-11-04 14:07:38 +01:00
2012-09-10 06:19:28 +02:00
this.methodProfiler.c("chunkSource");
2012-07-29 09:33:13 +02:00
this.chunkProvider.unloadChunks();
int j = this.a(1.0F);
if (j != this.j) {
this.j = j;
2012-07-29 09:33:13 +02:00
}
2012-11-06 13:05:28 +01:00
this.worldData.setTime(this.worldData.getTime() + 1L);
2013-07-01 13:03:00 +02:00
if (this.getGameRules().getBoolean("doDaylightCycle")) {
this.worldData.setDayTime(this.worldData.getDayTime() + 1L);
}
2012-09-10 06:19:28 +02:00
this.methodProfiler.c("tickPending");
2012-07-29 09:33:13 +02:00
this.a(false);
2013-11-04 14:07:38 +01:00
this.methodProfiler.c("tickBlocks");
2012-07-29 09:33:13 +02:00
this.g();
2012-09-10 06:19:28 +02:00
this.methodProfiler.c("chunkMap");
2012-07-29 09:33:13 +02:00
this.manager.flush();
2012-09-10 06:19:28 +02:00
this.methodProfiler.c("village");
2012-07-29 09:33:13 +02:00
this.villages.tick();
this.siegeManager.a();
2012-11-06 13:05:28 +01:00
this.methodProfiler.c("portalForcer");
2013-11-04 14:07:38 +01:00
this.Q.a(this.getTime());
2012-09-10 06:19:28 +02:00
this.methodProfiler.b();
2013-11-04 14:07:38 +01:00
this.Z();
this.getWorld().processChunkGC(); // CraftBukkit
2012-07-29 09:33:13 +02:00
}
public BiomeMeta a(EnumCreatureType enumcreaturetype, int i, int j, int k) {
2013-11-04 14:07:38 +01:00
List list = this.K().getMobsFor(enumcreaturetype, i, j, k);
2012-07-29 09:33:13 +02:00
return list != null && !list.isEmpty() ? (BiomeMeta) WeightedRandom.a(this.random, (Collection) list) : null;
}
public void everyoneSleeping() {
2013-11-04 14:07:38 +01:00
this.O = !this.players.isEmpty();
2012-07-29 09:33:13 +02:00
Iterator iterator = this.players.iterator();
while (iterator.hasNext()) {
EntityHuman entityhuman = (EntityHuman) iterator.next();
if (!entityhuman.isSleeping() && !entityhuman.fauxSleeping) { // CraftBukkit
2013-11-04 14:07:38 +01:00
this.O = false;
2012-07-29 09:33:13 +02:00
break;
}
}
}
protected void d() {
2013-11-04 14:07:38 +01:00
this.O = false;
2012-07-29 09:33:13 +02:00
Iterator iterator = this.players.iterator();
while (iterator.hasNext()) {
EntityHuman entityhuman = (EntityHuman) iterator.next();
if (entityhuman.isSleeping()) {
entityhuman.a(false, false, true);
}
}
2013-11-04 14:07:38 +01:00
this.Y();
2012-07-29 09:33:13 +02:00
}
2013-11-04 14:07:38 +01:00
private void Y() {
2012-07-29 09:33:13 +02:00
// CraftBukkit start
WeatherChangeEvent weather = new WeatherChangeEvent(this.getWorld(), false);
this.getServer().getPluginManager().callEvent(weather);
ThunderChangeEvent thunder = new ThunderChangeEvent(this.getWorld(), false);
this.getServer().getPluginManager().callEvent(thunder);
if (!weather.isCancelled()) {
this.worldData.setWeatherDuration(0);
this.worldData.setStorm(false);
}
if (!thunder.isCancelled()) {
this.worldData.setThunderDuration(0);
this.worldData.setThundering(false);
}
// CraftBukkit end
}
public boolean everyoneDeeplySleeping() {
2013-11-04 14:07:38 +01:00
if (this.O && !this.isStatic) {
2012-07-29 09:33:13 +02:00
Iterator iterator = this.players.iterator();
// CraftBukkit - This allows us to assume that some people are in bed but not really, allowing time to pass in spite of AFKers
boolean foundActualSleepers = false;
EntityHuman entityhuman;
do {
if (!iterator.hasNext()) {
return foundActualSleepers; // CraftBukkit
}
entityhuman = (EntityHuman) iterator.next();
// CraftBukkit start
if (entityhuman.isDeeplySleeping()) {
foundActualSleepers = true;
}
} while (entityhuman.isDeeplySleeping() || entityhuman.fauxSleeping);
// CraftBukkit end
return false;
} else {
return false;
}
}
protected void g() {
super.g();
int i = 0;
int j = 0;
// CraftBukkit start
// Iterator iterator = this.chunkTickList.iterator();
2012-07-29 09:33:13 +02:00
for (long chunkCoord : this.chunkTickList.popAll()) {
2013-11-04 14:07:38 +01:00
// ChunkCoordIntPair chunkcoordintpair = (ChunkCoordIntPair) iterator.next();
2012-07-29 09:33:13 +02:00
int chunkX = LongHash.msw(chunkCoord);
int chunkZ = LongHash.lsw(chunkCoord);
int k = chunkX * 16;
int l = chunkZ * 16;
2012-09-10 06:19:28 +02:00
this.methodProfiler.a("getChunk");
2012-07-29 09:33:13 +02:00
Chunk chunk = this.getChunkAt(chunkX, chunkZ);
// CraftBukkit end
this.a(k, l, chunk);
2012-09-10 06:19:28 +02:00
this.methodProfiler.c("tickChunk");
2013-11-04 14:07:38 +01:00
chunk.b(false);
2012-09-10 06:19:28 +02:00
this.methodProfiler.c("thunder");
2012-07-29 09:33:13 +02:00
int i1;
int j1;
int k1;
int l1;
2013-11-04 14:07:38 +01:00
if (this.random.nextInt(100000) == 0 && this.P() && this.O()) {
this.k = this.k * 3 + 1013904223;
i1 = this.k >> 2;
2012-07-29 09:33:13 +02:00
j1 = k + (i1 & 15);
k1 = l + (i1 >> 8 & 15);
l1 = this.h(j1, k1);
2013-09-19 20:25:08 +02:00
if (this.isRainingAt(j1, l1, k1)) {
2012-07-29 09:33:13 +02:00
this.strikeLightning(new EntityLightning(this, (double) j1, (double) l1, (double) k1));
}
}
2012-09-10 06:19:28 +02:00
this.methodProfiler.c("iceandsnow");
2012-07-29 09:33:13 +02:00
if (this.random.nextInt(16) == 0) {
this.k = this.k * 3 + 1013904223;
i1 = this.k >> 2;
2012-07-29 09:33:13 +02:00
j1 = i1 & 15;
k1 = i1 >> 8 & 15;
l1 = this.h(j1 + k, k1 + l);
2013-11-04 14:07:38 +01:00
if (this.s(j1 + k, l1 - 1, k1 + l)) {
2012-07-29 09:33:13 +02:00
// CraftBukkit start
BlockState blockState = this.getWorld().getBlockAt(j1 + k, l1 - 1, k1 + l).getState();
2013-11-04 14:07:38 +01:00
blockState.setTypeId(Block.b(Blocks.ICE));
2012-07-29 09:33:13 +02:00
BlockFormEvent iceBlockForm = new BlockFormEvent(blockState.getBlock(), blockState);
this.getServer().getPluginManager().callEvent(iceBlockForm);
if (!iceBlockForm.isCancelled()) {
blockState.update(true);
}
// CraftBukkit end
}
2013-11-04 14:07:38 +01:00
if (this.P() && this.e(j1 + k, l1, k1 + l, true)) {
2012-07-29 09:33:13 +02:00
// CraftBukkit start
BlockState blockState = this.getWorld().getBlockAt(j1 + k, l1, k1 + l).getState();
2013-11-04 14:07:38 +01:00
blockState.setTypeId(Block.b(Blocks.SNOW));
2012-07-29 09:33:13 +02:00
BlockFormEvent snow = new BlockFormEvent(blockState.getBlock(), blockState);
this.getServer().getPluginManager().callEvent(snow);
if (!snow.isCancelled()) {
blockState.update(true);
}
// CraftBukkit end
}
2013-11-04 14:07:38 +01:00
if (this.P()) {
2012-07-29 09:33:13 +02:00
BiomeBase biomebase = this.getBiome(j1 + k, k1 + l);
2013-11-04 14:07:38 +01:00
if (biomebase.e()) {
this.getType(j1 + k, l1 - 1, k1 + l).l(this, j1 + k, l1 - 1, k1 + l);
2012-07-29 09:33:13 +02:00
}
}
}
2013-11-04 14:07:38 +01:00
this.methodProfiler.c("tickBlocks");
2012-07-29 09:33:13 +02:00
ChunkSection[] achunksection = chunk.i();
j1 = achunksection.length;
for (k1 = 0; k1 < j1; ++k1) {
ChunkSection chunksection = achunksection[k1];
2013-04-27 11:40:05 +02:00
if (chunksection != null && chunksection.shouldTick()) {
2013-11-04 14:07:38 +01:00
for (int i2 = 0; i2 < 3; ++i2) {
this.k = this.k * 3 + 1013904223;
2013-11-04 14:07:38 +01:00
int j2 = this.k >> 2;
int k2 = j2 & 15;
int l2 = j2 >> 8 & 15;
int i3 = j2 >> 16 & 15;
2012-07-29 09:33:13 +02:00
++j;
2013-11-04 14:07:38 +01:00
Block block = chunksection.getTypeId(k2, i3, l2);
2012-07-29 09:33:13 +02:00
2013-11-04 14:07:38 +01:00
if (block.isTicking()) {
2012-07-29 09:33:13 +02:00
++i;
2013-04-27 11:40:05 +02:00
block.a(this, k2 + k, i3 + chunksection.getYPosition(), l2 + l, this.random);
2012-07-29 09:33:13 +02:00
}
}
}
}
2012-09-10 06:19:28 +02:00
this.methodProfiler.b();
2012-07-29 09:33:13 +02:00
}
}
2013-11-04 14:07:38 +01:00
public boolean a(int i, int j, int k, Block block) {
NextTickListEntry nextticklistentry = new NextTickListEntry(i, j, k, block);
2013-03-13 23:33:27 +01:00
2013-11-04 14:07:38 +01:00
return this.V.contains(nextticklistentry);
2013-03-13 23:33:27 +01:00
}
2013-11-04 14:07:38 +01:00
public void a(int i, int j, int k, Block block, int l) {
this.a(i, j, k, block, l, 0);
}
2013-11-04 14:07:38 +01:00
public void a(int i, int j, int k, Block block, int l, int i1) {
NextTickListEntry nextticklistentry = new NextTickListEntry(i, j, k, block);
2013-03-13 23:33:27 +01:00
byte b0 = 0;
2012-07-29 09:33:13 +02:00
2013-11-04 14:07:38 +01:00
if (this.d && block.getMaterial() != Material.AIR) {
if (block.L()) {
2013-07-01 13:03:00 +02:00
b0 = 8;
2013-11-04 14:07:38 +01:00
if (this.b(nextticklistentry.a - b0, nextticklistentry.b - b0, nextticklistentry.c - b0, nextticklistentry.a + b0, nextticklistentry.b + b0, nextticklistentry.c + b0)) {
Block block1 = this.getType(nextticklistentry.a, nextticklistentry.b, nextticklistentry.c);
2012-07-29 09:33:13 +02:00
2013-11-04 14:07:38 +01:00
if (block1.getMaterial() != Material.AIR && block1 == nextticklistentry.a()) {
block1.a(this, nextticklistentry.a, nextticklistentry.b, nextticklistentry.c, this.random);
}
2012-07-29 09:33:13 +02:00
}
return;
2012-07-29 09:33:13 +02:00
}
2013-11-04 14:07:38 +01:00
l = 1;
}
2013-11-04 14:07:38 +01:00
if (this.b(i - b0, j - b0, k - b0, i + b0, j + b0, k + b0)) {
if (block.getMaterial() != Material.AIR) {
nextticklistentry.a((long) l + this.worldData.getTime());
nextticklistentry.a(i1);
}
2013-11-04 14:07:38 +01:00
if (!this.M.contains(nextticklistentry)) {
this.M.add(nextticklistentry);
2013-11-04 14:07:38 +01:00
this.N.add(nextticklistentry);
2012-07-29 09:33:13 +02:00
}
}
}
2013-11-04 14:07:38 +01:00
public void b(int i, int j, int k, Block block, int l, int i1) {
NextTickListEntry nextticklistentry = new NextTickListEntry(i, j, k, block);
2012-07-29 09:33:13 +02:00
2013-11-04 14:07:38 +01:00
nextticklistentry.a(i1);
if (block.getMaterial() != Material.AIR) {
nextticklistentry.a((long) l + this.worldData.getTime());
2012-07-29 09:33:13 +02:00
}
2013-11-04 14:07:38 +01:00
if (!this.M.contains(nextticklistentry)) {
this.M.add(nextticklistentry);
2013-11-04 14:07:38 +01:00
this.N.add(nextticklistentry);
2012-07-29 09:33:13 +02:00
}
}
2012-08-25 02:51:51 +02:00
public void tickEntities() {
if (false && this.players.isEmpty()) { // CraftBukkit - this prevents entity cleanup, other issues on servers with no players
if (this.emptyTime++ >= 1200) {
2012-08-25 02:51:51 +02:00
return;
}
} else {
this.i();
2012-08-25 02:51:51 +02:00
}
super.tickEntities();
}
public void i() {
this.emptyTime = 0;
}
2012-07-29 09:33:13 +02:00
public boolean a(boolean flag) {
2013-11-04 14:07:38 +01:00
int i = this.N.size();
2012-07-29 09:33:13 +02:00
2013-11-04 14:07:38 +01:00
if (i != this.M.size()) {
2012-07-29 09:33:13 +02:00
throw new IllegalStateException("TickNextTick list out of synch");
} else {
if (i > 1000) {
2013-03-25 05:22:32 +01:00
// CraftBukkit start - If the server has too much to process over time, try to alleviate that
2012-07-29 09:33:13 +02:00
if (i > 20 * 1000) {
i = i / 20;
} else {
i = 1000;
}
// CraftBukkit end
}
2013-03-13 23:33:27 +01:00
this.methodProfiler.a("cleaning");
NextTickListEntry nextticklistentry;
2012-07-29 09:33:13 +02:00
2013-03-13 23:33:27 +01:00
for (int j = 0; j < i; ++j) {
2013-11-04 14:07:38 +01:00
nextticklistentry = (NextTickListEntry) this.N.first();
if (!flag && nextticklistentry.d > this.worldData.getTime()) {
2012-07-29 09:33:13 +02:00
break;
}
2013-11-04 14:07:38 +01:00
this.N.remove(nextticklistentry);
this.M.remove(nextticklistentry);
2013-11-04 14:07:38 +01:00
this.V.add(nextticklistentry);
2013-03-13 23:33:27 +01:00
}
2012-07-29 09:33:13 +02:00
2013-03-13 23:33:27 +01:00
this.methodProfiler.b();
this.methodProfiler.a("ticking");
2013-11-04 14:07:38 +01:00
Iterator iterator = this.V.iterator();
2013-03-13 23:33:27 +01:00
while (iterator.hasNext()) {
nextticklistentry = (NextTickListEntry) iterator.next();
iterator.remove();
byte b0 = 0;
2013-11-04 14:07:38 +01:00
if (this.b(nextticklistentry.a - b0, nextticklistentry.b - b0, nextticklistentry.c - b0, nextticklistentry.a + b0, nextticklistentry.b + b0, nextticklistentry.c + b0)) {
Block block = this.getType(nextticklistentry.a, nextticklistentry.b, nextticklistentry.c);
2012-07-29 09:33:13 +02:00
2013-11-04 14:07:38 +01:00
if (block.getMaterial() != Material.AIR && Block.a(block, nextticklistentry.a())) {
2012-11-06 13:05:28 +01:00
try {
2013-11-04 14:07:38 +01:00
block.a(this, nextticklistentry.a, nextticklistentry.b, nextticklistentry.c, this.random);
2012-11-06 13:05:28 +01:00
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.a(throwable, "Exception while ticking a block");
CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Block being ticked");
2013-11-04 14:07:38 +01:00
int k;
2012-11-06 13:05:28 +01:00
try {
2013-11-04 14:07:38 +01:00
k = this.getData(nextticklistentry.a, nextticklistentry.b, nextticklistentry.c);
2012-11-06 13:05:28 +01:00
} catch (Throwable throwable1) {
2013-11-04 14:07:38 +01:00
k = -1;
2012-11-06 13:05:28 +01:00
}
2013-11-04 14:07:38 +01:00
CrashReportSystemDetails.a(crashreportsystemdetails, nextticklistentry.a, nextticklistentry.b, nextticklistentry.c, block, k);
2012-11-06 13:05:28 +01:00
throw new ReportedException(crashreport);
2012-12-20 05:03:52 +01:00
}
}
2013-03-13 23:33:27 +01:00
} else {
2013-11-04 14:07:38 +01:00
this.a(nextticklistentry.a, nextticklistentry.b, nextticklistentry.c, nextticklistentry.a(), 0);
2012-07-29 09:33:13 +02:00
}
}
2013-03-13 23:33:27 +01:00
this.methodProfiler.b();
2013-11-04 14:07:38 +01:00
this.V.clear();
return !this.N.isEmpty();
2012-07-29 09:33:13 +02:00
}
}
public List a(Chunk chunk, boolean flag) {
ArrayList arraylist = null;
ChunkCoordIntPair chunkcoordintpair = chunk.l();
2013-03-13 23:33:27 +01:00
int i = (chunkcoordintpair.x << 4) - 2;
int j = i + 16 + 2;
int k = (chunkcoordintpair.z << 4) - 2;
int l = k + 16 + 2;
2012-07-29 09:33:13 +02:00
2013-03-13 23:33:27 +01:00
for (int i1 = 0; i1 < 2; ++i1) {
Iterator iterator;
2012-07-29 09:33:13 +02:00
2013-03-13 23:33:27 +01:00
if (i1 == 0) {
2013-11-04 14:07:38 +01:00
iterator = this.N.iterator();
2013-03-13 23:33:27 +01:00
} else {
2013-11-04 14:07:38 +01:00
iterator = this.V.iterator();
if (!this.V.isEmpty()) {
a.debug("toBeTicked = " + this.V.size());
2012-07-29 09:33:13 +02:00
}
2013-03-13 23:33:27 +01:00
}
2012-07-29 09:33:13 +02:00
2013-03-13 23:33:27 +01:00
while (iterator.hasNext()) {
NextTickListEntry nextticklistentry = (NextTickListEntry) iterator.next();
2012-07-29 09:33:13 +02:00
2013-03-13 23:33:27 +01:00
if (nextticklistentry.a >= i && nextticklistentry.a < j && nextticklistentry.c >= k && nextticklistentry.c < l) {
if (flag) {
2013-11-04 14:07:38 +01:00
this.M.remove(nextticklistentry);
2013-03-13 23:33:27 +01:00
iterator.remove();
}
if (arraylist == null) {
arraylist = new ArrayList();
}
arraylist.add(nextticklistentry);
}
2012-07-29 09:33:13 +02:00
}
}
return arraylist;
}
2013-07-01 13:03:00 +02:00
/* CraftBukkit start - We prevent spawning in general, so this butchering is not needed
public void entityJoinedWorld(Entity entity, boolean flag) {
2012-07-29 09:33:13 +02:00
if (!this.server.getSpawnAnimals() && (entity instanceof EntityAnimal || entity instanceof EntityWaterAnimal)) {
2011-05-14 16:29:42 +02:00
entity.die();
}
2013-07-01 13:03:00 +02:00
2012-07-29 09:33:13 +02:00
if (!this.server.getSpawnNPCs() && entity instanceof NPC) {
2012-01-12 23:10:13 +01:00
entity.die();
}
2011-01-29 22:50:29 +01:00
2013-07-09 01:43:37 +02:00
super.entityJoinedWorld(entity, flag);
}
2013-07-01 13:03:00 +02:00
// CraftBukkit end */
protected IChunkProvider j() {
IChunkLoader ichunkloader = this.dataManager.createChunkLoader(this.worldProvider);
2011-02-23 03:37:56 +01:00
2011-06-12 00:02:58 +02:00
// CraftBukkit start
org.bukkit.craftbukkit.generator.InternalChunkGenerator gen;
if (this.generator != null) {
gen = new org.bukkit.craftbukkit.generator.CustomChunkGenerator(this, this.getSeed(), this.generator);
} else if (this.worldProvider instanceof WorldProviderHell) {
gen = new org.bukkit.craftbukkit.generator.NetherChunkGenerator(this, this.getSeed());
} else if (this.worldProvider instanceof WorldProviderTheEnd) {
gen = new org.bukkit.craftbukkit.generator.SkyLandsChunkGenerator(this, this.getSeed());
} else {
gen = new org.bukkit.craftbukkit.generator.NormalChunkGenerator(this, this.getSeed());
}
this.chunkProviderServer = new ChunkProviderServer(this, ichunkloader, gen);
2011-06-12 00:02:58 +02:00
// CraftBukkit end
return this.chunkProviderServer;
}
public List getTileEntities(int i, int j, int k, int l, int i1, int j1) {
ArrayList arraylist = new ArrayList();
// CraftBukkit start - Get tile entities from chunks instead of world
for (int chunkX = (i >> 4); chunkX <= ((l - 1) >> 4); chunkX++) {
for (int chunkZ = (k >> 4); chunkZ <= ((j1 - 1) >> 4); chunkZ++) {
Chunk chunk = getChunkAt(chunkX, chunkZ);
if (chunk == null) {
continue;
}
for (Object te : chunk.tileEntities.values()) {
TileEntity tileentity = (TileEntity) te;
if ((tileentity.x >= i) && (tileentity.y >= j) && (tileentity.z >= k) && (tileentity.x < l) && (tileentity.y < i1) && (tileentity.z < j1)) {
arraylist.add(tileentity);
}
}
}
}
// CraftBukkit end
2011-01-29 22:50:29 +01:00
return arraylist;
}
2011-01-29 22:50:29 +01:00
public boolean a(EntityHuman entityhuman, int i, int j, int k) {
2013-03-13 23:33:27 +01:00
return !this.server.a(this, i, j, k, entityhuman);
}
2012-07-29 09:33:13 +02:00
protected void a(WorldSettings worldsettings) {
if (this.entitiesById == null) {
this.entitiesById = new IntHashMap();
}
2013-11-04 14:07:38 +01:00
if (this.M == null) {
this.M = new HashSet();
2012-07-29 09:33:13 +02:00
}
2013-11-04 14:07:38 +01:00
if (this.N == null) {
this.N = new TreeSet();
2012-07-29 09:33:13 +02:00
}
this.b(worldsettings);
super.a(worldsettings);
}
protected void b(WorldSettings worldsettings) {
if (!this.worldProvider.e()) {
this.worldData.setSpawn(0, this.worldProvider.getSeaLevel(), 0);
} else {
this.isLoading = true;
2013-07-01 13:03:00 +02:00
WorldChunkManager worldchunkmanager = this.worldProvider.e;
2012-07-29 09:33:13 +02:00
List list = worldchunkmanager.a();
Random random = new Random(this.getSeed());
ChunkPosition chunkposition = worldchunkmanager.a(0, 0, 256, list, random);
int i = 0;
int j = this.worldProvider.getSeaLevel();
int k = 0;
// CraftBukkit start
if (this.generator != null) {
Random rand = new Random(this.getSeed());
org.bukkit.Location spawn = this.generator.getFixedSpawnLocation(((WorldServer) this).getWorld(), rand);
if (spawn != null) {
if (spawn.getWorld() != ((WorldServer) this).getWorld()) {
throw new IllegalStateException("Cannot set spawn point for " + this.worldData.getName() + " to be in another world (" + spawn.getWorld().getName() + ")");
} else {
this.worldData.setSpawn(spawn.getBlockX(), spawn.getBlockY(), spawn.getBlockZ());
this.isLoading = false;
return;
}
}
}
// CraftBukkit end
if (chunkposition != null) {
i = chunkposition.x;
k = chunkposition.z;
} else {
2013-11-04 14:07:38 +01:00
a.warn("Unable to find spawn biome");
2012-07-29 09:33:13 +02:00
}
int l = 0;
while (!this.canSpawn(i, k)) { // CraftBukkit - use our own canSpawn
2012-07-29 09:33:13 +02:00
i += random.nextInt(64) - random.nextInt(64);
k += random.nextInt(64) - random.nextInt(64);
++l;
if (l == 1000) {
break;
}
}
this.worldData.setSpawn(i, j, k);
this.isLoading = false;
if (worldsettings.c()) {
this.k();
2012-07-29 09:33:13 +02:00
}
}
}
protected void k() {
2013-11-04 14:07:38 +01:00
WorldGenBonusChest worldgenbonuschest = new WorldGenBonusChest(U, 10);
2012-07-29 09:33:13 +02:00
for (int i = 0; i < 10; ++i) {
int j = this.worldData.c() + this.random.nextInt(6) - this.random.nextInt(6);
int k = this.worldData.e() + this.random.nextInt(6) - this.random.nextInt(6);
int l = this.i(j, k) + 1;
2012-07-29 09:33:13 +02:00
if (worldgenbonuschest.a(this, this.random, j, l, k)) {
break;
}
}
}
2012-07-29 09:33:13 +02:00
public ChunkCoordinates getDimensionSpawn() {
return this.worldProvider.h();
}
public void save(boolean flag, IProgressUpdate iprogressupdate) throws ExceptionWorldConflict { // CraftBukkit - added throws
if (this.chunkProvider.canSave()) {
if (iprogressupdate != null) {
iprogressupdate.a("Saving level");
}
this.a();
if (iprogressupdate != null) {
iprogressupdate.c("Saving chunks");
}
this.chunkProvider.saveChunks(flag, iprogressupdate);
}
}
2013-04-27 11:40:05 +02:00
public void flushSave() {
if (this.chunkProvider.canSave()) {
this.chunkProvider.b();
}
}
2012-07-29 09:33:13 +02:00
protected void a() throws ExceptionWorldConflict { // CraftBukkit - added throws
2013-11-04 14:07:38 +01:00
this.F();
2012-12-20 05:03:52 +01:00
this.dataManager.saveWorldData(this.worldData, this.server.getPlayerList().q());
// CraftBukkit start - save worldMaps once, rather than once per shared world
if (!(this instanceof SecondaryWorldServer)) {
this.worldMaps.a();
}
// CraftBukkit end
2012-07-29 09:33:13 +02:00
}
protected void a(Entity entity) {
super.a(entity);
2013-11-04 14:07:38 +01:00
this.entitiesById.a(entity.getId(), entity);
Entity[] aentity = entity.at();
2011-11-20 09:01:14 +01:00
if (aentity != null) {
2012-11-06 13:05:28 +01:00
for (int i = 0; i < aentity.length; ++i) {
2013-11-04 14:07:38 +01:00
this.entitiesById.a(aentity[i].getId(), aentity[i]);
2011-11-20 09:01:14 +01:00
}
}
2011-04-20 22:47:26 +02:00
}
2012-07-29 09:33:13 +02:00
protected void b(Entity entity) {
super.b(entity);
2013-11-04 14:07:38 +01:00
this.entitiesById.d(entity.getId());
Entity[] aentity = entity.at();
2011-11-20 09:01:14 +01:00
if (aentity != null) {
2012-11-06 13:05:28 +01:00
for (int i = 0; i < aentity.length; ++i) {
2013-11-04 14:07:38 +01:00
this.entitiesById.d(aentity[i].getId());
2011-11-20 09:01:14 +01:00
}
}
}
public Entity getEntity(int i) {
2012-02-29 22:31:04 +01:00
return (Entity) this.entitiesById.get(i);
2011-04-20 22:47:26 +02:00
}
public boolean strikeLightning(Entity entity) {
// CraftBukkit start
LightningStrikeEvent lightning = new LightningStrikeEvent(this.getWorld(), (org.bukkit.entity.LightningStrike) entity.getBukkitEntity());
this.getServer().getPluginManager().callEvent(lightning);
2011-05-14 16:29:42 +02:00
if (lightning.isCancelled()) {
return false;
}
if (super.strikeLightning(entity)) {
2013-11-04 14:07:38 +01:00
this.server.getPlayerList().sendPacketNearby(entity.locX, entity.locY, entity.locZ, 512.0D, this.dimension, new PacketPlayOutSpawnEntityWeather(entity));
2011-05-14 16:29:42 +02:00
// CraftBukkit end
return true;
2011-04-20 22:47:26 +02:00
} else {
return false;
}
}
2012-02-29 22:31:04 +01:00
public void broadcastEntityEffect(Entity entity, byte b0) {
2013-11-04 14:07:38 +01:00
this.getTracker().sendPacketToEntity(entity, new PacketPlayOutEntityStatus(entity, b0));
}
public Explosion createExplosion(Entity entity, double d0, double d1, double d2, float f, boolean flag, boolean flag1) {
2011-05-14 16:29:42 +02:00
// CraftBukkit start
Explosion explosion = super.createExplosion(entity, d0, d1, d2, f, flag, flag1);
2011-02-23 13:56:36 +01:00
if (explosion.wasCanceled) {
return explosion;
}
/* Remove
2011-06-12 00:02:58 +02:00
explosion.a = flag;
explosion.b = flag1;
2011-06-12 00:02:58 +02:00
explosion.a();
explosion.a(false);
*/
// CraftBukkit end - TODO: Check if explosions are still properly implemented
if (!flag1) {
explosion.blocks.clear();
}
2012-07-29 09:33:13 +02:00
Iterator iterator = this.players.iterator();
while (iterator.hasNext()) {
EntityHuman entityhuman = (EntityHuman) iterator.next();
if (entityhuman.e(d0, d1, d2) < 4096.0D) {
2013-11-04 14:07:38 +01:00
((EntityPlayer) entityhuman).playerConnection.sendPacket(new PacketPlayOutExplosion(d0, d1, d2, f, explosion.blocks, (Vec3D) explosion.b().get(entityhuman)));
2012-07-29 09:33:13 +02:00
}
}
return explosion;
}
2013-11-04 14:07:38 +01:00
public void playNote(int i, int j, int k, Block block, int l, int i1) {
NoteBlockData noteblockdata = new NoteBlockData(i, j, k, block, l, i1);
Iterator iterator = this.S[this.T].iterator();
2012-07-29 09:33:13 +02:00
NoteBlockData noteblockdata1;
do {
if (!iterator.hasNext()) {
2013-11-04 14:07:38 +01:00
this.S[this.T].add(noteblockdata);
2012-07-29 09:33:13 +02:00
return;
}
noteblockdata1 = (NoteBlockData) iterator.next();
} while (!noteblockdata1.equals(noteblockdata));
}
2013-11-04 14:07:38 +01:00
private void Z() {
while (!this.S[this.T].isEmpty()) {
int i = this.T;
2012-07-29 09:33:13 +02:00
2013-11-04 14:07:38 +01:00
this.T ^= 1;
Iterator iterator = this.S[i].iterator();
2012-07-29 09:33:13 +02:00
while (iterator.hasNext()) {
NoteBlockData noteblockdata = (NoteBlockData) iterator.next();
if (this.a(noteblockdata)) {
// CraftBukkit - this.worldProvider.dimension -> this.dimension
2013-11-04 14:07:38 +01:00
this.server.getPlayerList().sendPacketNearby((double) noteblockdata.a(), (double) noteblockdata.b(), (double) noteblockdata.c(), 64.0D, this.dimension, new PacketPlayOutBlockAction(noteblockdata.a(), noteblockdata.b(), noteblockdata.c(), noteblockdata.f(), noteblockdata.d(), noteblockdata.e()));
2012-07-29 09:33:13 +02:00
}
}
2013-11-04 14:07:38 +01:00
this.S[i].clear();
2012-07-29 09:33:13 +02:00
}
}
private boolean a(NoteBlockData noteblockdata) {
2013-11-04 14:07:38 +01:00
Block block = this.getType(noteblockdata.a(), noteblockdata.b(), noteblockdata.c());
2012-07-29 09:33:13 +02:00
2013-11-04 14:07:38 +01:00
return block == noteblockdata.f() ? block.a(this, noteblockdata.a(), noteblockdata.b(), noteblockdata.c(), noteblockdata.d(), noteblockdata.e()) : false;
2011-02-23 03:37:56 +01:00
}
public void saveLevel() {
2012-07-29 09:33:13 +02:00
this.dataManager.a();
2011-04-20 22:47:26 +02:00
}
2013-04-27 11:40:05 +02:00
protected void o() {
2013-11-04 14:07:38 +01:00
boolean flag = this.P();
2011-04-20 22:47:26 +02:00
2013-04-27 11:40:05 +02:00
super.o();
2013-11-04 14:07:38 +01:00
/* CraftBukkit start
if (this.m != this.n) {
this.server.getPlayerList().a(new PacketPlayOutGameStateChange(7, this.n), this.worldProvider.dimension);
}
if (this.o != this.p) {
this.server.getPlayerList().a(new PacketPlayOutGameStateChange(8, this.p), this.worldProvider.dimension);
}
if (flag != this.P()) {
if (flag) {
this.server.getPlayerList().sendAll(new PacketPlayOutGameStateChange(2, 0.0F));
} else {
this.server.getPlayerList().sendAll(new PacketPlayOutGameStateChange(1, 0.0F));
}
this.server.getPlayerList().sendAll(new PacketPlayOutGameStateChange(7, this.n));
this.server.getPlayerList().sendAll(new PacketPlayOutGameStateChange(8, this.p));
}
// */
if (flag != this.P()) {
// Only send weather packets to those affected
for (int i = 0; i < this.players.size(); ++i) {
if (((EntityPlayer) this.players.get(i)).world == this) {
((EntityPlayer) this.players.get(i)).setPlayerWeather((!flag ? WeatherType.DOWNFALL : WeatherType.CLEAR), false);
}
2011-04-20 22:47:26 +02:00
}
// CraftBukkit end
2011-04-20 22:47:26 +02:00
}
}
2012-07-29 09:33:13 +02:00
public MinecraftServer getMinecraftServer() {
return this.server;
}
public EntityTracker getTracker() {
return this.tracker;
}
2012-12-20 05:03:52 +01:00
public PlayerChunkMap getPlayerChunkMap() {
2012-07-29 09:33:13 +02:00
return this.manager;
}
2012-11-06 13:05:28 +01:00
2013-04-27 11:40:05 +02:00
public PortalTravelAgent t() {
2013-11-04 14:07:38 +01:00
return this.Q;
}
public void a(String s, double d0, double d1, double d2, int i, double d3, double d4, double d5, double d6) {
PacketPlayOutWorldParticles packetplayoutworldparticles = new PacketPlayOutWorldParticles(s, (float) d0, (float) d1, (float) d2, (float) d3, (float) d4, (float) d5, (float) d6, i);
for (int j = 0; j < this.players.size(); ++j) {
EntityPlayer entityplayer = (EntityPlayer) this.players.get(j);
ChunkCoordinates chunkcoordinates = entityplayer.getChunkCoordinates();
double d7 = d0 - (double) chunkcoordinates.x;
double d8 = d1 - (double) chunkcoordinates.y;
double d9 = d2 - (double) chunkcoordinates.z;
double d10 = d7 * d7 + d8 * d8 + d9 * d9;
if (d10 <= 256.0D) {
entityplayer.playerConnection.sendPacket(packetplayoutworldparticles);
}
}
2012-11-06 13:05:28 +01:00
}
2013-03-13 23:33:27 +01:00
// CraftBukkit start - Compatibility methods for BlockChangeDelegate
public boolean setRawTypeId(int x, int y, int z, int typeId) {
2013-11-04 14:07:38 +01:00
return this.setTypeAndData(x, y, z, Block.e(typeId), 0, 4);
2013-03-13 23:33:27 +01:00
}
public boolean setRawTypeIdAndData(int x, int y, int z, int typeId, int data) {
2013-11-04 14:07:38 +01:00
return this.setTypeAndData(x, y, z, Block.e(typeId), data, 4);
2013-03-13 23:33:27 +01:00
}
public boolean setTypeId(int x, int y, int z, int typeId) {
2013-11-04 14:07:38 +01:00
return this.setTypeAndData(x, y, z, Block.e(typeId), 0, 3);
2013-03-13 23:33:27 +01:00
}
public boolean setTypeIdAndData(int x, int y, int z, int typeId, int data) {
2013-11-04 14:07:38 +01:00
return this.setTypeAndData(x, y, z, Block.e(typeId), data, 3);
}
public int getTypeId(int x, int y, int z) {
return Block.b(getType(x, y, z));
2013-03-13 23:33:27 +01:00
}
// CraftBukkit end
}