示例#1
0
        private void onClientTick(float dt)
        {
            if (!riftsEnabled)
            {
                return;
            }

            Vec3d plrPos = capi.World.Player.Entity.Pos.XYZ;

            nearestRifts = rifts.OrderBy(rift => rift.Position.SquareDistanceTo(plrPos)).ToArray();

            for (int i = 0; i < Math.Min(4, nearestRifts.Length); i++)
            {
                Rift         rift  = nearestRifts[i];
                ILoadedSound sound = riftSounds[i];
                if (!sound.IsPlaying)
                {
                    sound.Start();
                    sound.PlaybackPosition = sound.SoundLengthSeconds * (float)capi.World.Rand.NextDouble();
                }

                sound.SetVolume(GameMath.Clamp(rift.GetNowSize(capi) / 3f, 0.1f, 1f));
                sound.SetPosition((float)rift.Position.X, (float)rift.Position.Y, (float)rift.Position.Z);
            }

            for (int i = nearestRifts.Length; i < 4; i++)
            {
                if (riftSounds[i].IsPlaying)
                {
                    riftSounds[i].Stop();
                }
            }
        }
示例#2
0
        private void OnServerTick100ms(float dt)
        {
            if (riftMode != "visible")
            {
                return;
            }

            foreach (IServerPlayer plr in sapi.World.AllOnlinePlayers)
            {
                if (plr.ConnectionState != EnumClientState.Playing)
                {
                    continue;
                }

                var bh = plr.Entity.GetBehavior <EntityBehaviorTemporalStabilityAffected>();
                if (bh == null)
                {
                    continue;
                }
                bh.stabilityOffset = 0;

                var  plrPos = plr.Entity.Pos.XYZ;
                Rift rift   = rifts.Nearest((r) => r.Position.SquareDistanceTo(plrPos));
                if (rift == null)
                {
                    continue;
                }

                float dist = Math.Max(0, GameMath.Sqrt(plrPos.SquareDistanceTo(rift.Position)) - 2 - rift.Size / 2f);

                if (bh != null)
                {
                    bh.stabilityOffset = -Math.Pow(Math.Max(0, 1 - dist / 3), 2) * 20;
                }
            }
        }
示例#3
0
        private bool SpawnNewRifts(Dictionary <string, List <Rift> > nearbyRiftsByPlayerUid)
        {
            var uids         = nearbyRiftsByPlayerUid.Keys;
            int riftsSpawned = 0;

            foreach (var uid in uids)
            {
                float cap = GetRiftCap(uid);
                var   plr = api.World.PlayerByUid(uid);
                if (plr.WorldData.CurrentGameMode == EnumGameMode.Creative || plr.WorldData.CurrentGameMode == EnumGameMode.Spectator)
                {
                    continue;
                }

                var nearbyRifts   = nearbyRiftsByPlayerUid[uid].Count;
                int canSpawnCount = (int)(cap - nearbyRifts);

                float fract = (cap - nearbyRifts) - canSpawnCount;
                if (api.World.Rand.NextDouble() < fract / 50.0)
                {
                    canSpawnCount++;
                }

                if (canSpawnCount <= 0)
                {
                    continue;
                }

                if (api.World.Calendar.TotalDays < 2 && api.World.Calendar.GetDayLightStrength(plr.Entity.Pos.AsBlockPos) > 0.9f)
                {
                    continue;
                }

                for (int i = 0; i < canSpawnCount; i++)
                {
                    double distance = spawnMinDistance + api.World.Rand.NextDouble() * spawnAddDistance;
                    double angle    = api.World.Rand.NextDouble() * GameMath.TWOPI;

                    double dz = distance * Math.Sin(angle);
                    double dx = distance * Math.Cos(angle);

                    Vec3d    riftPos = plr.Entity.Pos.XYZ.Add(dx, 0, dz);
                    BlockPos pos     = new BlockPos((int)riftPos.X, 0, (int)riftPos.Z);
                    pos.Y = api.World.BlockAccessor.GetTerrainMapheightAt(pos);

                    var block = api.World.BlockAccessor.GetBlock(pos);
                    if (block.Replaceable < 6000)
                    {
                        pos.Up();
                        block = api.World.BlockAccessor.GetBlock(pos);
                    }
                    if (block.IsLiquid() && api.World.Rand.NextDouble() > 0.1)
                    {
                        continue;
                    }

                    // Don't spawn near bases
                    int blocklight   = api.World.BlockAccessor.GetLightLevel(pos, EnumLightLevelType.OnlyBlockLight);
                    int blocklightup = api.World.BlockAccessor.GetLightLevel(pos.UpCopy(), EnumLightLevelType.OnlyBlockLight);
                    if (blocklight >= 3 || blocklightup >= 3)
                    {
                        continue;
                    }

                    float size = 2 + (float)api.World.Rand.NextDouble() * 4f;

                    riftPos.Y = pos.Y + size / 2f + 1;
                    var rift = new Rift()
                    {
                        Position          = riftPos,
                        Size              = size,
                        SpawnedTotalHours = api.World.Calendar.TotalHours,
                        DieAtTotalHours   = api.World.Calendar.TotalHours + 8 + api.World.Rand.NextDouble() * 48
                    };

                    rifts.Add(rift);
                    riftsSpawned++;

                    // Update the list as we go, so we don't spawn overlapping amounts of rifts around players
                    foreach (var nuid in uids)
                    {
                        if (plr.Entity.Pos.HorDistanceTo(riftPos) <= despawnDistance)
                        {
                            nearbyRiftsByPlayerUid[plr.PlayerUID].Add(rift);
                        }
                    }
                }
            }

            return(riftsSpawned > 0);
        }
示例#4
0
        public void OnRenderFrame(float deltaTime, EnumRenderStage stage)
        {
            var plrPos = capi.World.Player.Entity.Pos;
            var bh     = capi.World.Player.Entity.GetBehavior <EntityBehaviorTemporalStabilityAffected>();

            if (bh != null)
            {
                bh.stabilityOffset = 0;
            }

            if (modsys.nearestRifts.Length > 0)
            {
                Rift rift = modsys.nearestRifts[0];

                float dist   = Math.Max(0, GameMath.Sqrt(plrPos.SquareDistanceTo(rift.Position)) - 1 - rift.Size / 2f);
                float f      = Math.Max(0, 1 - dist / 3f);
                float jitter = capi.World.Rand.NextDouble() < 0.25 ? f * ((float)capi.World.Rand.NextDouble() - 0.5f) / 1f : 0;

                GlobalConstants.GuiGearRotJitter = jitter;

                capi.ModLoader.GetModSystem <SystemTemporalStability>().modGlitchStrength = Math.Min(1, f * 1.3f);

                if (bh != null)
                {
                    bh.stabilityOffset = -Math.Pow(Math.Max(0, 1 - dist / 3), 2) * 20;
                }
            }
            else
            {
                capi.ModLoader.GetModSystem <SystemTemporalStability>().modGlitchStrength = 0;
            }

            counter += deltaTime;
            if (capi.World.Rand.NextDouble() < 0.012)
            {
                counter += 20 * (float)capi.World.Rand.NextDouble();
            }

            capi.Render.GLDepthMask(false);

            prog.Use();
            prog.BindTexture2D("primaryFb", capi.Render.FrameBuffers[(int)EnumFrameBuffer.Primary].ColorTextureIds[0], 0);
            prog.BindTexture2D("depthTex", capi.Render.FrameBuffers[(int)EnumFrameBuffer.Primary].DepthTextureId, 1);
            prog.UniformMatrix("projectionMatrix", capi.Render.CurrentProjectionMatrix);


            int width  = capi.Render.FrameWidth;
            int height = capi.Render.FrameHeight;

            prog.Uniform("counter", counter);
            float bf = 200 + (float)GameMath.Sin(capi.InWorldEllapsedMilliseconds / 24000.0) * 100;

            prog.Uniform("counterSmooth", bf);
            prog.Uniform("invFrameSize", new Vec2f(1f / width, 1f / height));
            int riftIndex = 0;

            cnt = (cnt + 1) % 3;

            foreach (var rift in rifts)
            {
                if (cnt == 0)
                {
                    rift.Visible = capi.World.BlockAccessor.GetChunkAtBlockPos((int)rift.Position.X, (int)rift.Position.Y, (int)rift.Position.Z) != null;
                }

                riftIndex++;
                matrixf.Identity();

                float dx = (float)(rift.Position.X - plrPos.X);
                float dy = (float)(rift.Position.Y - plrPos.Y);
                float dz = (float)(rift.Position.Z - plrPos.Z);

                matrixf.Translate(dx, dy, dz);
                matrixf.ReverseMul(capi.Render.CameraMatrixOriginf);

                matrixf.Values[0] = 1f;
                matrixf.Values[1] = 0f;
                matrixf.Values[2] = 0f;

                //matrixf.Values[4] = 0f;
                //matrixf.Values[5] = 1f;
                //matrixf.Values[6] = 0f;

                matrixf.Values[8]  = 0f;
                matrixf.Values[9]  = 0f;
                matrixf.Values[10] = 1f;

                float size = rift.GetNowSize(capi);
                matrixf.Scale(size, size, size);

                prog.UniformMatrix("modelViewMatrix", matrixf.Values);
                prog.Uniform("riftIndex", riftIndex);

                capi.Render.RenderMesh(meshref);

                if (dx * dx + dy * dy + dz * dz < 40 * 40)
                {
                    Vec3d ppos = rift.Position;
                    capi.World.SpawnParticles(0.1f, ColorUtil.ColorFromRgba(21 / 2, 70 / 2, 116 / 2, 128), ppos, ppos, new Vec3f(-0.125f, -0.125f, -0.125f), new Vec3f(0.125f, 0.125f, 0.125f), 5, 0, (0.125f / 2 + (float)capi.World.Rand.NextDouble() * 0.25f) / 2);
                }
            }


            counter = GameMath.Mod(counter + deltaTime, GameMath.TWOPI * 100f);

            prog.Stop();

            capi.Render.GLDepthMask(true);
        }