public override int[] GenLayer(int xCoord, int zCoord, int sizeX, int sizeZ)
        {
            int[] outData = new int[sizeX * sizeZ];

            if (thresholds != null)
            {
                for (int z = 0; z < sizeZ; ++z)
                {
                    for (int x = 0; x < sizeX; ++x)
                    {
                        outData[z * sizeX + x] = (int)GameMath.Clamp(multiplier * noisegen.Noise(xCoord + x, zCoord + z, thresholds), 0, 255);
                    }
                }
            }
            else
            {
                for (int z = 0; z < sizeZ; ++z)
                {
                    for (int x = 0; x < sizeX; ++x)
                    {
                        outData[z * sizeX + x] = (int)GameMath.Clamp(multiplier * noisegen.Noise(xCoord + x, zCoord + z), 0, 255);
                    }
                }
            }



            return(outData);
        }
Exemple #2
0
        public override void OnBeforeGameRender(float dt)
        {
            if (!capi.IsGamePaused)
            {
                var            eplr       = capi.World.Player;
                ITreeAttribute healthTree = eplr.Entity.WatchedAttributes.GetTreeAttribute("health");
                float          healthRel  = healthTree == null ? 1 : healthTree.GetFloat("currenthealth") / healthTree.GetFloat("maxhealth");

                float f             = Math.Max(0, (0.23f - healthRel) * 1 / 0.18f);
                float lowHealthness = 0;

                if (f > 0)
                {
                    float ellapseSec = (float)(capi.InWorldEllapsedMilliseconds / 1000.0);

                    float bla = (float)noisegen.Noise(12412, ellapseSec / 2) * 0.5f + (float)Math.Pow(Math.Abs(GameMath.Sin(ellapseSec * 1 / 0.7f)), 30) * 0.5f;
                    lowHealthness = Math.Min(f * 1.5f, 1) * (bla * 0.75f + 0.5f);

                    if (eplr.Entity.Alive)
                    {
                        capi.Render.ShaderUniforms.ExtraSepia = GameMath.Clamp(f * (float)noisegen.Noise(0, ellapseSec / 3) * 1.2f, 0, 1.2f);
                        if (capi.World.Rand.NextDouble() < 0.01)
                        {
                            capi.World.AddCameraShake(0.15f * f);
                        }

                        capi.Input.MouseYaw += f * (float)(noisegen.Noise(76, ellapseSec / 50) - 0.5f) * 0.003f;

                        float dp = f * (float)(noisegen.Noise(ellapseSec / 50, 987) - 0.5f) * 0.003f;;

                        eplr.Entity.Pos.Pitch += dp;
                        capi.Input.MousePitch += dp;
                    }
                }
                else
                {
                    capi.Render.ShaderUniforms.ExtraSepia = 0;
                }

                int val = GameMath.Clamp((int)(damangeVignettingUntil - capi.ElapsedMilliseconds), 0, duration);

                capi.Render.ShaderUniforms.DamageVignetting = GameMath.Clamp(GameMath.Clamp(strength / 2, 0.5f, 3.5f) * ((float)val / Math.Max(1, duration)) + lowHealthness, 0, 1.5f);

                float freezing = eplr.Entity.WatchedAttributes.GetFloat("freezingEffectStrength", 0);

                curFreezingVal += (freezing - curFreezingVal) * dt;

                if (curFreezingVal > 0.1 && eplr.CameraMode == EnumCameraMode.FirstPerson)
                {
                    float ellapseSec = (float)(capi.InWorldEllapsedMilliseconds / 1000.0);
                    capi.Input.MouseYaw += capi.Settings.Float["cameraShakeStrength"] * (float)(Math.Max(0, noisegen.Noise(ellapseSec, 12) - 0.4f) * Math.Sin(ellapseSec * 90) * 0.01) * GameMath.Clamp(curFreezingVal * 3, 0, 1);
                }

                capi.Render.ShaderUniforms.FrostVignetting = curFreezingVal;
            }
        }
Exemple #3
0
        public override int[] GenLayer(int xCoord, int zCoord, int sizeX, int sizeZ)
        {
            int[] result = new int[sizeX * sizeZ];

            for (int x = 0; x < sizeX; x++)
            {
                for (int z = 0; z < sizeZ; z++)
                {
                    int offsetX = (int)(wobbleIntensity * noisegenX.Noise(xCoord + x, zCoord + z));
                    int offsetY = (int)(wobbleIntensity * noisegenY.Noise(xCoord + x, zCoord + z));

                    int finalX = (xCoord + x + offsetX);
                    int finalZ = (zCoord + z + offsetY);

                    int climate = climateNoise.GetLerpedClimateAt(finalX / TerraGenConfig.climateMapScale, finalZ / TerraGenConfig.climateMapScale);
                    int rain    = (climate >> 8) & 0xff;
                    int temp    = TerraGenConfig.GetScaledAdjustedTemperature((climate >> 16) & 0xff, 0);

                    result[z * sizeX + x] = noiseLandforms.GetLandformIndexAt(
                        finalX,
                        finalZ,
                        temp,
                        rain
                        );
                }
            }

            return(result);
        }
Exemple #4
0
        double[] GetTerrainNoise3D(double[] octX0, double[] octX1, double[] octX2, double[] octX3, double[] octThX0, double[] octThX1, double[] octThX2, double[] octThX3, int xPos, int yPos, int zPos)
        {
            for (int x = 0; x < paddedNoiseWidth; x++)
            {
                for (int z = 0; z < paddedNoiseWidth; z++)
                {
                    for (int i = 0; i < TerraGenConfig.terrainGenOctaves; i++)
                    {
                        lerpedAmps[i] = GameMath.BiLerp(octX0[i], octX1[i], octX2[i], octX3[i], (double)x / paddedNoiseWidth, (double)z / paddedNoiseWidth);
                        lerpedTh[i]   = GameMath.BiLerp(octThX0[i], octThX1[i], octThX2[i], octThX3[i], (double)x / paddedNoiseWidth, (double)z / paddedNoiseWidth);
                    }

                    for (int y = 0; y < paddedNoiseHeight; y++)
                    {
                        noiseTemp[NoiseIndex3d(x, y, z)] = TerrainNoise.Noise(
                            (xPos + x),
                            (yPos + y) / TerraGenConfig.terrainNoiseVerticalScale,
                            (zPos + z),
                            lerpedAmps,
                            lerpedTh
                            );
                    }
                }
            }

            return(noiseTemp);
        }
Exemple #5
0
        public override int[] GenLayer(int xCoord, int zCoord, int sizeX, int sizeZ)
        {
            int[] result = new int[sizeX * sizeZ];

            for (int x = 0; x < sizeX; x++)
            {
                for (int z = 0; z < sizeZ; z++)
                {
                    int offsetX = (int)(wobbleIntensity * noisegenX.Noise(xCoord + x, zCoord + z));
                    int offsetY = (int)(wobbleIntensity * noisegenY.Noise(xCoord + x, zCoord + z));

                    int finalX = (xCoord + x + offsetX);
                    int finalZ = (zCoord + z + offsetY);

                    result[z * sizeX + x] = noiseLandforms.GetLandformIndexAt(
                        finalX,
                        finalZ,
                        climateNoise.GetLerpedClimateAt(finalX / TerraGenConfig.climateMapScale, finalZ / TerraGenConfig.climateMapScale)
                        );

                    /*float baseX = (float)finalX / TerraGenConfig.landformMapScale;
                     * float baseY = (float)finalZ / TerraGenConfig.landformMapScale;
                     *
                     * result[z * sizeX + x] = noiseLandforms.GetParentLandformIndexAt(
                     *  (int)baseX,
                     *  (int)baseY,
                     *  climateNoise.GetLerpedClimateAt(finalX / TerraGenConfig.climateMapScale, finalZ / TerraGenConfig.climateMapScale),
                     *  baseX - (int)baseX,
                     *  baseY - (int)baseY
                     * );*/
                }
            }

            return(result);
        }
        double[] GetTerrainNoise3D(double[] octX0, double[] octX1, double[] octX2, double[] octX3, double[] octThX0, double[] octThX1, double[] octThX2, double[] octThX3, int xPos, int yPos, int zPos)
        {
            for (int x = 0; x < paddedNoiseWidth; x++)
            {
                for (int z = 0; z < paddedNoiseWidth; z++)
                {
                    for (int i = 0; i < TerraGenConfig.terrainGenOctaves; i++)
                    {
                        lerpedAmps[i] = GameMath.BiLerp(octX0[i], octX1[i], octX2[i], octX3[i], (double)x / paddedNoiseWidth, (double)z / paddedNoiseWidth);
                        lerpedTh[i]   = GameMath.BiLerp(octThX0[i], octThX1[i], octThX2[i], octThX3[i], (double)x / paddedNoiseWidth, (double)z / paddedNoiseWidth);
                    }

                    float distx = (float)distort2dx.Noise(xPos + x, zPos + z);
                    float distz = (float)distort2dz.Noise(xPos + x, zPos + z);

                    for (int y = 0; y < paddedNoiseHeight; y++)
                    {
                        noiseTemp[NoiseIndex3d(x, y, z)] = TerrainNoise.Noise(
                            (xPos + x) + (distx > 0 ? Math.Max(0, distx - 10) : Math.Min(0, distx + 10)),
                            (yPos + y) / TerraGenConfig.terrainNoiseVerticalScale,
                            (zPos + z) + (distz > 0 ? Math.Max(0, distz - 10) : Math.Min(0, distz + 10)),
                            lerpedAmps,
                            lerpedTh
                            );
                    }
                }
            }

            return(noiseTemp);
        }
        public override int[] GenLayer(int xCoord, int zCoord, int sizeX, int sizeZ)
        {
            int margin      = (int)Math.Ceiling(intensity);
            int paddedSizeX = sizeX + 2 * margin;
            int paddedSizeZ = sizeZ + 2 * margin;


            int[] inData = parent.GenLayer(xCoord - margin, zCoord - margin, paddedSizeX, paddedSizeZ);

            int[] outData = new int[sizeX * sizeZ];

            for (int y = 0; y < sizeZ; ++y)
            {
                for (int x = 0; x < sizeX; ++x)
                {
                    int offsetX = (int)(intensity * noisegenX.Noise(xCoord + x + margin, zCoord + y + margin));
                    int offsetY = (int)(intensity * noisegenY.Noise(xCoord + x + margin, zCoord + y + margin));

                    // We wrap around overflowing coordinates
                    int newXCoord = GameMath.Mod(x + offsetX + margin / 2, paddedSizeX);
                    int newYCoord = GameMath.Mod(y + offsetY + margin / 2, paddedSizeZ);

                    outData[y * sizeX + x] = inData[newYCoord * paddedSizeX + newXCoord];
                }
            }

            return(outData);
        }
Exemple #8
0
        public override int[] GenLayer(int xCoord, int zCoord, int sizeX, int sizeZ)
        {
            int[] outData = new int[sizeX * sizeZ];

            for (int z = 0; z < sizeZ; ++z)
            {
                for (int x = 0; x < sizeX; ++x)
                {
                    int offsetX = (int)(wobbleIntensity * noisegenX.Noise(xCoord + x, zCoord + z));
                    int offsetY = (int)(wobbleIntensity * noisegenY.Noise(xCoord + x, zCoord + z));

                    int wobbledX = xCoord + x + offsetX;
                    int wobbledZ = zCoord + z + offsetY;

                    double forestValue = offset + multiplier * noisegen.Noise(wobbledX, wobbledZ);

                    int climate = inputMap.GetUnpaddedInt((x * inputMap.InnerSize) / outputMap.InnerSize, (z * inputMap.InnerSize) / outputMap.InnerSize);

                    float rain        = (climate >> 8) & 0xff;
                    float temperature = (climate >> 16) & 0xff;

                    outData[z * sizeX + x] = (int)GameMath.Clamp(forestValue - GameMath.Clamp(128 - rain * temperature / (255 * 255), 0, 128), 0, 255);
                }
            }

            return(outData);
        }
        public override int[] GenLayer(int xCoord, int zCoord, int sizeX, int sizeZ)
        {
            int[] outData = new int[sizeX * sizeZ];

            for (int z = 0; z < sizeZ; ++z)
            {
                for (int x = 0; x < sizeX; ++x)
                {
                    outData[z * sizeX + x] =
                        (int)GameMath.Clamp(128 + multiplier * noisegenX.Noise(xCoord + x, zCoord + z), 0, 255) |
                        (int)GameMath.Clamp(128 + multiplier * noisegenX.Noise(xCoord + x, zCoord + z), 0, 255) << 8
                    ;
                }
            }

            return(outData);
        }
        private void TestNoise(IServerPlayer player, CmdArgs arguments)
        {
            bool use3d   = false;
            int  octaves = 1;

            if (arguments.Length > 1)
            {
                if (!int.TryParse(arguments[1], out octaves))
                {
                    octaves = 1;
                }
            }


            Random rnd  = new Random();
            long   seed = rnd.Next();

            NormalizedSimplexNoise noise = NormalizedSimplexNoise.FromDefaultOctaves(octaves, 5, 0.7, seed);
            int    size = 800;
            Bitmap bmp  = new Bitmap(size, size);

            int   underflows = 0;
            int   overflows  = 0;
            float min        = 1;
            float max        = 0;

            for (int x = 0; x < size; x++)
            {
                for (int y = 0; y < size; y++)
                {
                    double value = use3d ? noise.Noise((double)x / size, 0, (double)y / size) : noise.Noise((double)x / size, (double)y / size);
                    if (value < 0)
                    {
                        underflows++;
                        value = 0;
                    }
                    if (value > 1)
                    {
                        overflows++;
                        value = 1;
                    }

                    min = Math.Min((float)value, min);
                    max = Math.Max((float)value, max);

                    int light = (int)(value * 255);
                    bmp.SetPixel(x, y, Color.FromArgb(255, light, light, light));
                }
            }

            bmp.Save("noise.png");
            player.SendMessage(groupId, (use3d ? "3D" : "2D") + " Noise (" + octaves + " Octaves) saved to noise.png. Overflows: " + overflows + ", Underflows: " + underflows, EnumChatType.CommandSuccess);
            player.SendMessage(groupId, "Noise min = " + min.ToString("0.##") + ", max= " + max.ToString("0.##"), EnumChatType.CommandSuccess);
        }
Exemple #11
0
        private void OnChunkColumnGen(IServerChunk[] chunks, int chunkX, int chunkZ, ITreeAttribute chunkGenParams)
        {
            IntMap   beachMap = chunks[0].MapChunk.MapRegion.BeachMap;
            Vec3i    climate  = chunks[0].MapChunk.MapRegion.ClimateMap.ToClimateVec(chunkX, chunkZ, api.WorldManager.RegionSize, chunksize);
            BlockPos pos      = new BlockPos();

            ushort[] heightMap = chunks[0].MapChunk.RainHeightMap;

            int regionChunkSize = api.WorldManager.RegionSize / chunksize;
            int rdx             = chunkX % regionChunkSize;
            int rdz             = chunkZ % regionChunkSize;

            float beachStep = (float)beachMap.InnerSize / regionChunkSize;

            int beachUpLeft   = beachMap.GetUnpaddedInt((int)(rdx * beachStep), (int)(rdz * beachStep));
            int beachUpRight  = beachMap.GetUnpaddedInt((int)(rdx * beachStep + beachStep), (int)(rdz * beachStep));
            int beachBotLeft  = beachMap.GetUnpaddedInt((int)(rdx * beachStep), (int)(rdz * beachStep + beachStep));
            int beachBotRight = beachMap.GetUnpaddedInt((int)(rdx * beachStep + beachStep), (int)(rdz * beachStep + beachStep));

            for (int x = 0; x < chunksize; x++)
            {
                for (int z = 0; z < chunksize; z++)
                {
                    int y = heightMap[z * chunksize + x];

                    float beachRel = GameMath.BiLerp(beachUpLeft, beachUpRight, beachBotLeft, beachBotRight, (float)x / chunksize, (float)z / chunksize) / 255f;
                    float tempRel  = climate.Z / 255f;
                    if (beachRel > 0.5 && tempRel > 0.5)
                    {
                        pos.X = chunkX * chunksize + x;
                        pos.Y = y + 1;
                        pos.Z = chunkZ * chunksize + z;

                        var a      = api.ModLoader.GetModSystem <GenBlockLayers>();
                        int rockID = chunks[0].MapChunk.TopRockIdMap[z * chunksize + x];

                        if (a.blockLayerConfig.BeachLayer.BlockIdMapping.TryGetValue(rockID, out int sand))
                        {
                            int lY     = y % chunksize;
                            int i3d    = (chunksize * lY + z) * chunksize + x;
                            int chunkY = y / chunksize;

                            double noise = sNoise.Noise(rdx + x, rdx + z);

                            if (chunks[chunkY].Blocks[i3d] == sand && noise > 0.84)
                            {
                                GenPalmTree(blockAccessor, pos, sizeNoise.Noise(pos.X, pos.Y, pos.Z), fruitNoise.Noise(pos.X, pos.Y, pos.Z), frondNoise.Noise(pos.X, pos.Y, pos.Z));
                            }
                        }
                    }
                }
            }
        }
Exemple #12
0
        private void OnMapChunkGen(IMapChunk mapChunk, int chunkX, int chunkZ)
        {
            mapChunk.CaveHeightDistort = new byte[chunksize * chunksize];

            for (int dx = 0; dx < chunksize; dx++)
            {
                for (int dz = 0; dz < chunksize; dz++)
                {
                    double val = heightvarNoise.Noise(chunksize * chunkX + dx, chunksize * chunkZ + dz) - 0.5;
                    val = val > 0 ? Math.Max(0, val - 0.07) : Math.Min(0, val + 0.07);

                    mapChunk.CaveHeightDistort[dz * chunksize + dx] = (byte)(128 * val + 127);
                }
            }
        }
Exemple #13
0
        public override int[] GenLayer(int xCoord, int zCoord, int sizeX, int sizeZ)
        {
            int[] result = new int[sizeX * sizeZ];

            for (int x = 0; x < sizeX; x++)
            {
                for (int z = 0; z < sizeZ; z++)
                {
                    int offsetX = (int)(wobbleIntensity * noisegenX.Noise(xCoord + x, zCoord + z));
                    int offsetY = (int)(wobbleIntensity * noisegenY.Noise(xCoord + x, zCoord + z));

                    int finalX = (xCoord + x + offsetX) / TerraGenConfig.geoProvMapScale;
                    int finalZ = (zCoord + z + offsetY) / TerraGenConfig.geoProvMapScale;

                    result[z * sizeX + x] = noiseGeoProvince.GetProvinceIndexAt(finalX, finalZ);
                }
            }

            return(result);
        }
Exemple #14
0
        public override int[] GenLayer(int xCoord, int zCoord, int sizeX, int sizeZ)
        {
            int[] outData = new int[sizeX * sizeZ];

            for (int z = 0; z < sizeZ; ++z)
            {
                for (int x = 0; x < sizeX; ++x)
                {
                    int offsetX = (int)(wobbleIntensity * noisegenX.Noise(xCoord + x, zCoord + z));
                    int offsetY = (int)(wobbleIntensity * noisegenY.Noise(xCoord + x, zCoord + z));

                    int wobbledX = xCoord + x + offsetX;
                    int wobbledZ = zCoord + z + offsetY;

                    double value = offset + multiplier * noisegen.Noise(wobbledX, wobbledZ);

                    outData[z * sizeX + x] = (int)GameMath.Clamp(value, 0, 255);
                }
            }

            return(outData);
        }
Exemple #15
0
        private void OnChunkColumnGen(IServerChunk[] chunks, int chunkX, int chunkZ, ITreeAttribute chunkGenParams = null)
        {
            ushort[] heightMap = chunks[0].MapChunk.RainHeightMap;

            int regionChunkSize = Api.WorldManager.RegionSize / chunksize;
            int rdx             = chunkX % regionChunkSize;
            int rdz             = chunkZ % regionChunkSize;

            for (int x = 0; x < chunksize; x++)
            {
                for (int z = 0; z < chunksize; z++)
                {
                    double noise = sNoise.Noise(chunkX * chunksize + x, chunkZ * chunksize + z);

                    int y       = heightMap[z * chunksize + x];
                    int chunkY  = y / chunksize;
                    int lY      = y % chunksize;
                    int index3d = (chunksize * lY + z) * chunksize + x;
                    int bID     = chunks[chunkY].Blocks[index3d];
                    if (bID == 0 || bA.GetBlock(bID).LiquidCode != null)
                    {
                        continue;
                    }

                    int tY       = heightMap[z * chunksize + x] + 1;
                    int tChunkY  = tY / chunksize;
                    int tlY      = tY % chunksize;
                    int tIndex3d = (chunksize * tlY + z) * chunksize + x;

                    int    rockID = chunks[0].MapChunk.TopRockIdMap[z * chunksize + x];
                    string rock   = bA.GetBlock(rockID).Variant["rock"];

                    rand.InitPositionSeed(rdx + x, rdz + z);

                    var deposits = Deposits.Shuffle(rand);

                    for (int i = 0; i < Deposits.Length; i++)
                    {
                        double dnoise = sNoise.Noise(rdx + x + i + 4987, rdz + z + i + 15654);
                        if (dnoise > 0.9)
                        {
                            continue;
                        }

                        DepositVariant variant = Deposits[i];
                        if (!variant.WithOreMap)
                        {
                            continue;
                        }
                        float factor = variant.GetOreMapFactor(chunkX, chunkZ);
                        factor *= (float)genProperties.GlobalMult;

                        if (factor > 0 && factor > noise)
                        {
                            int?placed = bA.GetBlock(new AssetLocation(variant.Attributes.Token["placeblock"]["code"].ToString().Replace("{rock}", rock).Replace("*", "poor")))?.Id;
                            if (placed == null || !surfaceBlocks.ContainsKey((int)placed))
                            {
                                continue;
                            }

                            chunks[tChunkY].Blocks[tIndex3d] = surfaceBlocks[(int)placed];
                            chunks[tChunkY].MarkModified();
                            break;
                        }
                    }
                }
            }
        }
        public override void OnGameTick(float deltaTime)
        {
            if (!enabled)
            {
                return;
            }

            if (requireInitSounds)
            {
                initSoundsAndEffects();
                requireInitSounds = false;
            }

            if (entity.World.Side == EnumAppSide.Client)
            {
                if (!(entity.World.Api as ICoreClientAPI).PlayerReadyFired)
                {
                    return;
                }
            }
            else
            {
                IServerPlayer player = entity.World.PlayerByUid(((EntityPlayer)entity).PlayerUID) as IServerPlayer;
                if (player != null && player.ConnectionState != EnumClientState.Playing)
                {
                    return;
                }
            }


            deltaTime = GameMath.Min(0.5f, deltaTime);

            float changeSpeed = deltaTime / 3;


            double hereStability = stabilityOffset + tempStabilitySystem.GetTemporalStability(entity.SidedPos.X, entity.SidedPos.Y, entity.SidedPos.Z);

            entity.Attributes.SetDouble("tempStabChangeVelocity", TempStabChangeVelocity);

            double gain = TempStabChangeVelocity > 0 ? (TempStabChangeVelocity / 200.0) : (TempStabChangeVelocity / 800.0);

            OwnStability = GameMath.Clamp(OwnStability + gain, 0f, 1);
            double ownStability = OwnStability;

            TempStabChangeVelocity = (hereTempStabChangeVelocity - TempStabChangeVelocity) * deltaTime;

            float glitchEffectExtraStrength = tempStabilitySystem.GetGlitchEffectExtraStrength();

            double targetGlitchEffectStrength = Math.Max(0, Math.Max(0, (0.2f - ownStability) * 1 / 0.2f) + glitchEffectExtraStrength);

            glitchEffectStrength += (targetGlitchEffectStrength - glitchEffectStrength) * changeSpeed;
            glitchEffectStrength  = GameMath.Clamp(glitchEffectStrength, 0, 1.1f);

            double targetFogEffectStrength = Math.Max(0, Math.Max(0, (0.3f - ownStability) * 1 / 0.3f) + glitchEffectExtraStrength);

            fogEffectStrength += (targetFogEffectStrength - fogEffectStrength) * changeSpeed;
            fogEffectStrength  = GameMath.Clamp(fogEffectStrength, 0, 1.1f);

            double targetRustPrecipStrength = Math.Max(0, Math.Max(0, (0.3f - ownStability) * 1 / 0.3f) + glitchEffectExtraStrength);

            rustPrecipColorStrength += (targetRustPrecipStrength - rustPrecipColorStrength) * changeSpeed;
            rustPrecipColorStrength  = GameMath.Clamp(rustPrecipColorStrength, 0, 1f);

            if (precipParticleSys != null)
            {
                precipParticleSys.rainParticleColor = ColorUtil.ColorOverlay(WeatherSimulationParticles.waterColor, WeatherSimulationParticles.lowStabColor, (float)rustPrecipColorStrength);
            }


            hereTempStabChangeVelocity = hereStability - 1;

            oneSecAccum += deltaTime;
            if (oneSecAccum > 1)
            {
                oneSecAccum = 0;
                updateSoundsAndEffects(hereStability, Math.Max(0, ownStability - 1.5f * glitchEffectExtraStrength));
            }
            threeSecAccum += deltaTime;
            if (threeSecAccum > 4)
            {
                threeSecAccum = 0;
                if (entity.World.Side == EnumAppSide.Server && ownStability < 0.13)
                {
                    entity.ReceiveDamage(new DamageSource()
                    {
                        DamageTier = 0,
                        Source     = EnumDamageSource.Machine,
                        Type       = EnumDamageType.Poison
                    }, (float)(0.15 - ownStability));
                }
            }

            if (isSelf)
            {
                capi.Render.ShaderUniforms.GlitchStrength = 0;
            }

            if (isSelf && (fogEffectStrength > 0.05 || glitchEffectStrength > 0.05))
            {
                capi.Render.ShaderUniforms.GlitchStrength    = (float)glitchEffectStrength;
                capi.Render.ShaderUniforms.GlobalWorldWarp   = (float)(capi.World.Rand.NextDouble() < 0.015 ? (Math.Max(0, glitchEffectStrength - 0.05f) * capi.World.Rand.NextDouble() * capi.World.Rand.NextDouble()) : 0);
                capi.Render.ShaderUniforms.WindWaveCounter  += (float)(capi.World.Rand.NextDouble() < 0.015 ? 9 * capi.World.Rand.NextDouble() : 0);
                capi.Render.ShaderUniforms.WaterWaveCounter += (float)(capi.World.Rand.NextDouble() < 0.015 ? 9 * capi.World.Rand.NextDouble() : 0);

                if (capi.World.Rand.NextDouble() < 0.002)
                {
                    capi.Input.MouseYaw   += (float)capi.World.Rand.NextDouble() * 0.125f - 0.125f / 2;
                    capi.Input.MousePitch += (float)capi.World.Rand.NextDouble() * 0.125f - 0.125f / 2;
                }

                tmpPos.Set((int)entity.Pos.X, (int)entity.Pos.Y, (int)entity.Pos.Z);
                float sunb = capi.World.BlockAccessor.GetLightLevel(tmpPos, EnumLightLevelType.OnlySunLight) / 22f;

                float strength = Math.Min(1, (float)(glitchEffectStrength));

                double fognoise = fogEffectStrength * Math.Abs(fogNoise.Noise(0, capi.InWorldEllapsedMilliseconds / 1000f)) / 60f;

                rainfogAmbient.FogDensity.Value = 0.05f + (float)fognoise;

                rainfogAmbient.AmbientColor.Weight = strength;
                rainfogAmbient.FogColor.Weight     = strength;
                rainfogAmbient.FogDensity.Weight   = (float)Math.Pow(strength, 2);

                rainfogAmbient.FogColor.Value[0] = sunb * 116 / 255f;
                rainfogAmbient.FogColor.Value[1] = sunb * 77 / 255f;
                rainfogAmbient.FogColor.Value[2] = sunb * 49 / 255f;

                rainfogAmbient.AmbientColor.Value[0] = 0.5f * 116 / 255f;
                rainfogAmbient.AmbientColor.Value[1] = 0.5f * 77 / 255f;
                rainfogAmbient.AmbientColor.Value[2] = 0.5f * 49 / 255f;

                rustParticles.MinVelocity.Set(-0.1f, 0.1f, 0.1f);
                rustParticles.AddVelocity.Set(0.2f, 0.2f, 0.2f);
                rustParticles.Color   = ColorUtil.ToRgba((int)(strength * 150), 50, 25, 15);
                rustParticles.MaxSize = 0.25f;
                rustParticles.RandomVelocityChange = false;
                rustParticles.MinVelocity.Set(0, 0, 0);
                rustParticles.AddVelocity.Set(0, 1, 0);


                Vec3d     position = new Vec3d();
                EntityPos plrPos   = capi.World.Player.Entity.Pos;

                float tries = 20 * strength;

                while (tries-- > 0)
                {
                    float offX = (float)capi.World.Rand.NextDouble() * 24 - 12;
                    float offY = (float)capi.World.Rand.NextDouble() * 24 - 12;
                    float offZ = (float)capi.World.Rand.NextDouble() * 24 - 12;

                    position.Set(plrPos.X + offX, plrPos.Y + offY, plrPos.Z + offZ);
                    BlockPos pos = new BlockPos((int)position.X, (int)position.Y, (int)position.Z);

                    if (!capi.World.BlockAccessor.IsValidPos(pos))
                    {
                        continue;
                    }

                    rustParticles.MinPos = position;
                    capi.World.SpawnParticles(rustParticles);
                }
            }
        }
 public void slowTick3s()
 {
     windSpeed = api.World.BlockAccessor.GetWindSpeedAt(CenterPosition) * (0.2 + noiseGen.Noise(0, api.World.Calendar.TotalHours * 50) * 0.8);
 }
        internal void GenChunkColumn(IServerChunk[] chunks, int chunkX, int chunkZ)
        {
            ushort[] heightMap = chunks[0].MapChunk.RainHeightMap;

            float lerpMapInv = 1f / TerraGenConfig.geoProvMapScale;

            float chunkInRegionX = (chunkX % regionChunkSize) * lerpMapInv * chunksize;
            float chunkInRegionZ = (chunkZ % regionChunkSize) * lerpMapInv * chunksize;

            LerpedWeightedIndex2DMap map = GetOrLoadLerpedProvinceMap(chunks[0].MapChunk, chunkX, chunkZ);


            int localIndex3D;

            float chunkSizeFloat = chunksize;

            int absX, absZ;

            for (int x = 0; x < chunksize; x++)
            {
                for (int z = 0; z < chunksize; z++)
                {
                    int surfaceY = heightMap[z * chunksize + x];

                    absX = chunkX * chunksize + x;
                    absZ = chunkZ * chunksize + z;

                    // Todo: lerp these 3 noise gens for performance
                    double distortX   = (float)distort2dX.Noise(absX, absZ) * 160f;
                    double distortZ   = (float)distort2dZ.Noise(absX, absZ) * 160f;
                    double noiseValue = noiseGen.Noise(
                        absX + distortX,
                        absZ + distortZ
                        );

                    WeightedIndex[] indices = map[
                        TerraGenConfig.geoProvMapPadding + chunkInRegionX + x * lerpMapInv,
                        TerraGenConfig.geoProvMapPadding + chunkInRegionZ + z * lerpMapInv
                                              ];

                    LoadInterpolatedLayerBlockIds(noiseValue, indices, surfaceY);

                    int i = 0;

                    while (surfaceY >= 0)
                    {
                        int chunkY = surfaceY / chunksize;
                        int lY     = Math.Min(chunksize - 1, surfaceY - chunkY * chunksize);

                        localIndex3D = (chunksize * lY + z) * chunksize + x;

                        if (chunks[chunkY].Blocks[localIndex3D] == rockBlockId && finalBlockIds.Count > i)
                        {
                            chunks[chunkY].Blocks[localIndex3D] = finalBlockIds[i++];
                        }

                        surfaceY--;
                    }
                }
            }
        }
Exemple #19
0
        private static bool Patch_SystemRenderPlayerEffects_onBeforeRender(
            ref SystemRenderPlayerEffects __instance, float dt, ref ClientMain ___game, ref int ___maxDynLights,
            ref NormalizedSimplexNoise ___noisegen, ref float ___curFreezingVal, ref long ___damangeVignettingUntil,
            ref int ___duration, float ___strength)
        {
            var shUniforms = ___game.GetField <DefaultShaderUniforms>("shUniforms");
            var mouseYaw   = ___game.GetField <float>("mouseYaw");
            var mousePitch = ___game.GetField <float>("mousePitch");

            shUniforms.PointLightsCount = 0;
            var plrPos = ___game.EntityPlayer.Pos.XYZ;
            var array  = ___game.GetEntitiesAround(plrPos, 60f, 60f, e => e.LightHsv != null && e.LightHsv[2] > 0);

            if (array.Length > ___maxDynLights)
            {
                array = (from e in array
                         orderby e.Pos.SquareDistanceTo(plrPos)
                         select e).ToArray();
            }
            foreach (var entity in array)
            {
                var lightHsv = entity.LightHsv;
                __instance.CallMethod("AddPointLight", lightHsv, entity.Pos);
            }

            if (Api.IsGamePaused)
            {
                return(false);
            }
            var treeAttribute = ___game.EntityPlayer.WatchedAttributes.GetTreeAttribute("health");
            var num           = treeAttribute.GetFloat("currenthealth") / treeAttribute.GetFloat("maxhealth");
            var num2          = Math.Max(0f, (0.23f - num) * 1f / 0.18f);
            var num3          = 0f;

            if (num2 > 0f)
            {
                var num4 = (float)(___game.InWorldEllapsedMs / 1000.0);
                var num5 = (float)___noisegen.Noise(12412.0, num4 / 2f) * 0.5f + (float)Math.Pow(Math.Abs(GameMath.Sin(num4 * 1f / 0.7f)), 30.0) * 0.5f;
                num3 = Math.Min(num2 * 1.5f, 1f) * (num5 * 0.75f + 0.5f);
                if (___game.EntityPlayer.Alive && Settings.AllowCameraShake)
                {
                    shUniforms.ExtraSepia = GameMath.Clamp(num2 * (float)___noisegen.Noise(0.0, num4 / 3f) * 1.2f, 0f, 1.2f);
                    if (___game.Rand.NextDouble() < 0.01)
                    {
                        ___game.AddCameraShake(0.15f * num2);
                    }
                    ___game.SetField("mouseYaw", mouseYaw + num2 * (float)(___noisegen.Noise(76.0, num4 / 50f) - 0.5) * 0.003f);
                    var num6 = num2 * (float)(___noisegen.Noise(num4 / 50f, 987.0) - 0.5) * 0.003f;
                    ___game.EntityPlayer.Pos.Pitch += num6;
                    ___game.SetField("mousePitch", mousePitch + num6);
                }
            }
            else
            {
                shUniforms.ExtraSepia = 0f;
            }
            var num7 = GameMath.Clamp((int)(___damangeVignettingUntil - ___game.ElapsedMilliseconds), 0, ___duration);

            shUniforms.DamageVignetting = GameMath.Clamp(GameMath.Clamp(___strength / 2f, 0.5f, 3.5f) * (num7 / (float)Math.Max(1, ___duration)) + num3, 0f, 1.5f);
            var @float = ___game.EntityPlayer.WatchedAttributes.GetFloat("freezingEffectStrength");

            ___curFreezingVal += (@float - ___curFreezingVal) * dt;
            if (___curFreezingVal > 0.1 && Api.World.Player.CameraMode == EnumCameraMode.FirstPerson && Settings.AllowCameraShake)
            {
                var num8 = (float)(___game.InWorldEllapsedMs / 1000.0);
                ___game.SetField("mouseYaw", mouseYaw + ClientSettings.CameraShakeStrength * (float)(Math.Max(0.0, ___noisegen.Noise(num8, 12.0) - 0.40000000596046448) * Math.Sin(num8 * 90f) * 0.01) * GameMath.Clamp(___curFreezingVal * 3f, 0f, 1f));
            }
            shUniforms.FrostVignetting = ___curFreezingVal;
            return(false);
        }
Exemple #20
0
        void OnUse(WorldEdit worldEdit, BlockPos pos, int oldBlockId, int sign, ItemStack withItemStack)
        {
            if (Radius <= 0)
            {
                return;
            }

            int   radInt = (int)Math.Ceiling(Radius);
            float radSq  = Radius * Radius;

            Block block = blockAccessRev.GetBlock(pos);

            if (sign > 0)
            {
                worldEdit.sapi.World.BlockAccessor.SetBlock(oldBlockId, pos);
            }

            float maxhgt            = Depth;
            EnumHeightToolMode dist = Mode;

            int quantityBlocks = (int)(GameMath.PI * radSq) * (int)maxhgt;

            if (!worldEdit.MayPlace(block, quantityBlocks))
            {
                return;
            }

            for (int dx = -radInt; dx <= radInt; dx++)
            {
                for (int dz = -radInt; dz <= radInt; dz++)
                {
                    float distanceSq = dx * dx + dz * dz;
                    if (distanceSq > radSq)
                    {
                        continue;
                    }

                    BlockPos dpos = pos.AddCopy(dx, 0, dz);

                    float height = sign * maxhgt;
                    switch (dist)
                    {
                    case EnumHeightToolMode.Pyramid:
                        height *= 1 - distanceSq / radSq;
                        break;

                    case EnumHeightToolMode.Gaussian:
                        float sigmaSq = 0.1f;
                        float sigma   = GameMath.Sqrt(sigmaSq);
                        float a       = 1f / (sigma * GameMath.Sqrt(GameMath.TWOPI));
                        float x       = distanceSq / radSq;

                        double gaussValue = a * Math.Exp(-(x * x) / (2 * sigmaSq));

                        height *= (float)gaussValue;
                        break;

                    case EnumHeightToolMode.Perlin:

                        height *= (float)noiseGen.Noise(dpos.X, dpos.Y, dpos.Z);

                        break;
                    }

                    while (dpos.Y > 0 && blockAccessRev.GetBlock(dpos).Replaceable >= 6000)
                    {
                        dpos.Down();
                    }


                    if (height < 0)
                    {
                        Erode(-height, dpos);
                    }
                    else
                    {
                        dpos.Up();
                        Grow(worldEdit.sapi.World, height, dpos, block, BlockFacing.UP, withItemStack);
                    }
                }
            }

            blockAccessRev.SetHistoryStateBlock(pos.X, pos.Y, pos.Z, oldBlockId, blockAccessRev.GetBlockId(pos));
            blockAccessRev.Commit();
        }
Exemple #21
0
        private bool SetBlocks(IServerChunk[] chunks, float horRadius, float vertRadius, double centerX, double centerY, double centerZ, ushort[] terrainheightmap, ushort[] rainheightmap, int chunkX, int chunkZ)
        {
            IMapChunk mapchunk  = chunks[0].MapChunk;
            int       chunkSize = worldgenBlockAccessor.ChunkSize;

            // One extra size for checking if we run into water
            horRadius++;
            vertRadius++;

            int mindx = (int)GameMath.Clamp(centerX - horRadius, 0, chunksize - 1);
            int maxdx = (int)GameMath.Clamp(centerX + horRadius + 1, 0, chunksize - 1);
            int mindy = (int)GameMath.Clamp(centerY - vertRadius * 0.7f, 1, worldheight - 1);
            int maxdy = (int)GameMath.Clamp(centerY + vertRadius + 1, 1, worldheight - 1);
            int mindz = (int)GameMath.Clamp(centerZ - horRadius, 0, chunksize - 1);
            int maxdz = (int)GameMath.Clamp(centerZ + horRadius + 1, 0, chunksize - 1);

            double xdistRel, ydistRel, zdistRel;
            double hRadiusSq       = horRadius * horRadius;
            double vRadiusSq       = vertRadius * vertRadius;
            double distortStrength = GameMath.Clamp(vertRadius / 4.0, 0, 0.1);


            bool foundWater = false;

            for (int lx = mindx; lx <= maxdx && !foundWater; lx++)
            {
                xdistRel = (lx - centerX) * (lx - centerX) / hRadiusSq;

                for (int lz = mindz; lz <= maxdz && !foundWater; lz++)
                {
                    zdistRel = (lz - centerZ) * (lz - centerZ) / hRadiusSq;

                    double heightrnd = (mapchunk.CaveHeightDistort[lz * chunksize + lx] - 127) * distortStrength;

                    for (int y = mindy; y <= maxdy + 10 && !foundWater; y++)
                    {
                        double yDist        = y - centerY;
                        double heightOffFac = yDist > 0 ? heightrnd * heightrnd : 0;

                        ydistRel = yDist * yDist / (vRadiusSq + heightOffFac);

                        if (y > worldheight - 1 || xdistRel + ydistRel + zdistRel > 1.0)
                        {
                            continue;
                        }

                        int ly = y % chunksize;

                        // dominionsmod
                        foundWater = (chunks[y / chunksize].Blocks[(ly * chunksize + lz) * chunksize + lx] == saltWater || chunks[y / chunksize].Blocks[(ly * chunksize + lz) * chunksize + lx] == GlobalConfig.waterBlockId);
                    }
                }
            }

            if (foundWater)
            {
                return(false);
            }

            horRadius--;
            vertRadius--;

            mindx = (int)GameMath.Clamp(centerX - horRadius, 0, chunksize - 1);
            maxdx = (int)GameMath.Clamp(centerX + horRadius + 1, 0, chunksize - 1);
            mindz = (int)GameMath.Clamp(centerZ - horRadius, 0, chunksize - 1);
            maxdz = (int)GameMath.Clamp(centerZ + horRadius + 1, 0, chunksize - 1);

            mindy = (int)GameMath.Clamp(centerY - vertRadius * 0.7f, 1, worldheight - 1);
            maxdy = (int)GameMath.Clamp(centerY + vertRadius + 1, 1, worldheight - 1);

            hRadiusSq = horRadius * horRadius;
            vRadiusSq = vertRadius * vertRadius;


            for (int lx = mindx; lx <= maxdx; lx++)
            {
                xdistRel = (lx - centerX) * (lx - centerX) / hRadiusSq;

                for (int lz = mindz; lz <= maxdz; lz++)
                {
                    zdistRel = (lz - centerZ) * (lz - centerZ) / hRadiusSq;

                    double heightrnd = (mapchunk.CaveHeightDistort[lz * chunksize + lx] - 127) * distortStrength;
                    int    surfaceY  = terrainheightmap[lz * chunksize + lx];

                    for (int y = maxdy + 10; y >= mindy; y--)
                    {
                        double yDist        = y - centerY;
                        double heightOffFac = yDist > 0 ? heightrnd * heightrnd * Math.Min(1, Math.Abs(y - surfaceY) / 10.0) : 0;

                        ydistRel = yDist * yDist / (vRadiusSq + heightOffFac);

                        if (y > worldheight - 1 || xdistRel + ydistRel + zdistRel > 1.0)
                        {
                            continue;
                        }

                        IChunkBlocks chunkBlockData = chunks[y / chunksize].Blocks;
                        int          ly             = y % chunksize;

                        chunkBlockData[(ly * chunksize + lz) * chunksize + lx] = y < 12 ? GlobalConfig.lavaBlockId : blockId;

                        if (terrainheightmap[lz * chunksize + lx] == y)
                        {
                            terrainheightmap[lz * chunksize + lx]--;
                            rainheightmap[lz * chunksize + lx]--;
                        }

                        if (y == 11)
                        {
                            if (basaltNoise.Noise(chunkX * chunkSize + lx, chunkZ * chunkSize + lz) > 0.65)
                            {
                                chunkBlockData[(ly * chunksize + lz) * chunksize + lx] = GlobalConfig.basaltBlockId;
                                terrainheightmap[lz * chunksize + lx] = Math.Max(terrainheightmap[lz * chunksize + lx], (ushort)11);
                                rainheightmap[lz * chunksize + lx]    = Math.Max(rainheightmap[lz * chunksize + lx], (ushort)11);
                            }
                            else
                            {
                                worldgenBlockAccessor.ScheduleBlockLightUpdate(new BlockPos(chunkX * chunkSize + lx, y, chunkZ * chunkSize + lz), airBlockId, GlobalConfig.lavaBlockId);
                            }
                        }
                    }
                }
            }



            return(true);
        }