void HandleTeleporting(float dt) { toremove.Clear(); foreach (var val in tpingEntities) { if (val.Value.Entity.Teleporting) { continue; } val.Value.SecondsPassed += Math.Min(0.5f, dt); if (api.World.ElapsedMilliseconds - val.Value.LastCollideMs > 100) { toremove.Add(val.Key); continue; } if (val.Value.SecondsPassed > 1.5 && tpLocation != null) { // Preload the chunk sapi.WorldManager.LoadChunkColumnFast((int)tpLocation.X / api.World.BlockAccessor.ChunkSize, (int)tpLocation.Z / api.World.BlockAccessor.ChunkSize, new ChunkLoadOptions() { KeepLoaded = true }); } if (val.Value.SecondsPassed > 5 && tpLocation != null) { val.Value.Entity.TeleportTo(tpLocation.ToVec3d().Add(0.5, 1, 0.5)); Entity e = val.Value.Entity; if (e is EntityPlayer) { api.World.Logger.Debug("Teleporting player {0} to {1}", (e as EntityPlayer).GetBehavior <EntityBehaviorNameTag>().DisplayName, tpLocation); manager.DidTranslocateServer((e as EntityPlayer).Player as IServerPlayer); } else { api.World.Logger.Debug("Teleporting entity {0} to {1}", e.Code, tpLocation); } toremove.Add(val.Key); activated = false; MarkDirty(); } } foreach (long entityid in toremove) { tpingEntities.Remove(entityid); } }
void HandleTeleporting(float dt) { toremove.Clear(); bool wasTeleporting = somebodyIsTeleporting; somebodyIsTeleporting &= tpingEntities.Count > 0; foreach (var val in tpingEntities) { if (val.Value.Entity.Teleporting) { continue; } val.Value.SecondsPassed += Math.Min(0.5f, dt); if (Api.World.ElapsedMilliseconds - val.Value.LastCollideMs > 100) { // Make sure its not just server lag Block block = Api.World.CollisionTester.GetCollidingBlock(Api.World.BlockAccessor, val.Value.Entity.CollisionBox, val.Value.Entity.Pos.XYZ, true); if (!(block is BlockStaticTranslocator)) { toremove.Add(val.Key); continue; } } if (val.Value.SecondsPassed > 0.1 && !somebodyIsTeleporting) { somebodyIsTeleporting = true; MarkDirty(); } if (val.Value.SecondsPassed > 1.5 && tpLocation != null) { // Preload the chunk IWorldChunk chunk = sapi.World.BlockAccessor.GetChunkAtBlockPos(tpLocation); if (chunk != null) { chunk.MapChunk.MarkFresh(); } else { sapi.WorldManager.LoadChunkColumnPriority((int)tpLocation.X / Api.World.BlockAccessor.ChunkSize, (int)tpLocation.Z / Api.World.BlockAccessor.ChunkSize, new ChunkLoadOptions() { KeepLoaded = false }); } } if (val.Value.SecondsPassed > 4.4 && tpLocation != null) { val.Value.Entity.TeleportTo(tpLocation.ToVec3d().Add(-0.3, 1, -0.3)); // Fugly, need some better exit pos thing Entity e = val.Value.Entity; if (e is EntityPlayer) { Api.World.Logger.Debug("Teleporting player {0} to {1}", (e as EntityPlayer).GetBehavior <EntityBehaviorNameTag>().DisplayName, tpLocation); manager.DidTranslocateServer((e as EntityPlayer).Player as IServerPlayer); } else { Api.World.Logger.Debug("Teleporting entity {0} to {1}", e.Code, tpLocation); } toremove.Add(val.Key); activated = false; somebodyIsTeleporting = false; somebodyDidTeleport = true; ownBlock.teleportParticles.MinPos.Set(Pos.X, Pos.Y, Pos.Z); ownBlock.teleportParticles.AddPos.Set(1, 1.8, 1); ownBlock.teleportParticles.MinVelocity.Set(-1, -1, -1); ownBlock.teleportParticles.AddVelocity.Set(2, 2, 2); ownBlock.teleportParticles.MinQuantity = 150; ownBlock.teleportParticles.AddQuantity = 0.5f; int r = 53; int g = 221; int b = 172; ownBlock.teleportParticles.Color = (r << 16) | (g << 8) | (b << 0) | (100 << 24); ownBlock.teleportParticles.BlueEvolve = null; ownBlock.teleportParticles.RedEvolve = null; ownBlock.teleportParticles.GreenEvolve = null; ownBlock.teleportParticles.MinSize = 0.1f; ownBlock.teleportParticles.MaxSize = 0.2f; ownBlock.teleportParticles.SizeEvolve = null; ownBlock.teleportParticles.OpacityEvolve = EvolvingNatFloat.create(EnumTransformFunction.QUADRATIC, -10f); Api.World.SpawnParticles(ownBlock.teleportParticles); MarkDirty(); } } foreach (long entityid in toremove) { tpingEntities.Remove(entityid); } if (wasTeleporting && !somebodyIsTeleporting) { MarkDirty(); } }