internal void OnDeserializedMethod(StreamingContext context) { if (angleVert == null) { angleVert = NatFloat.createUniform(0, 0); } }
public override void Start(ICoreAPI api) { base.Start(api); this.api = api; texts = new Dictionary <EnumTempStormStrength, TemporalStormText>() { { EnumTempStormStrength.Light, new TemporalStormText() { Approaching = Lang.Get("A light temporal storm is approaching"), Imminent = Lang.Get("A light temporal storm is imminent"), Waning = Lang.Get("The temporal storm seems to be waning") } }, { EnumTempStormStrength.Medium, new TemporalStormText() { Approaching = Lang.Get("A medium temporal storm is approaching"), Imminent = Lang.Get("A medium temporal storm is imminent"), Waning = Lang.Get("The temporal storm seems to be waning") } }, { EnumTempStormStrength.Heavy, new TemporalStormText() { Approaching = Lang.Get("A heavy temporal storm is approaching"), Imminent = Lang.Get("A heavy temporal storm is imminent"), Waning = Lang.Get("The temporal storm seems to be waning") } }, }; configs = new Dictionary <string, TemporalStormConfig>() { { "veryrare", new TemporalStormConfig() { Frequency = NatFloat.create(EnumDistribution.UNIFORM, 30, 5), StrengthIncrease = 2.5f / 100, StrengthIncreaseCap = 25f / 100 } }, { "rare", new TemporalStormConfig() { Frequency = NatFloat.create(EnumDistribution.UNIFORM, 25, 5), StrengthIncrease = 5f / 100, StrengthIncreaseCap = 50f / 100 } }, { "sometimes", new TemporalStormConfig() { Frequency = NatFloat.create(EnumDistribution.UNIFORM, 15, 5), StrengthIncrease = 10f / 100, StrengthIncreaseCap = 100f / 100 } }, { "often", new TemporalStormConfig() { Frequency = NatFloat.create(EnumDistribution.UNIFORM, 7.5f, 2.5f), StrengthIncrease = 15f / 100, StrengthIncreaseCap = 150f / 100 } }, { "veryoften", new TemporalStormConfig() { Frequency = NatFloat.create(EnumDistribution.UNIFORM, 4.5f, 1.5f), StrengthIncrease = 20f / 100, StrengthIncreaseCap = 200f / 100 } } }; }
public override void Initialize(JsonObject properties) { base.Initialize(properties); vineGrowthStage = properties["vineGrowthStage"].AsInt(); vineGrowthQuantityGen = properties["vineGrowthQuantity"].AsObject <NatFloat>(); vineBlockLocation = new AssetLocation("pumpkin-vine-1-normal"); }
public override void LoadConfig(JsonObject taskConfig, JsonObject aiConfig) { base.LoadConfig(taskConfig, aiConfig); SpawnPosition = new Vec3d(entity.Attributes.GetDouble("spawnX"), entity.Attributes.GetDouble("spawnY"), entity.Attributes.GetDouble("spawnZ")); float wanderRangeMin = 3, wanderRangeMax = 30; if (taskConfig["maxDistanceToSpawn"].Exists) { StayCloseToSpawn = true; MaxDistanceToSpawn = taskConfig["maxDistanceToSpawn"].AsDouble(10); TeleportWhenOutOfRange = taskConfig["teleportWhenOutOfRange"].AsBool(true); TeleportInGameHours = taskConfig["teleportInGameHours"].AsDouble(1); } if (taskConfig["targetDistance"] != null) { targetDistance = taskConfig["targetDistance"].AsFloat(0.12f); } if (taskConfig["movespeed"] != null) { moveSpeed = taskConfig["movespeed"].AsFloat(0.03f); } if (taskConfig["wanderChance"] != null) { wanderChance = taskConfig["wanderChance"].AsFloat(0.015f); } if (taskConfig["wanderRangeMin"] != null) { wanderRangeMin = taskConfig["wanderRangeMin"].AsFloat(3); } if (taskConfig["wanderRangeMax"] != null) { wanderRangeMax = taskConfig["wanderRangeMax"].AsFloat(30); } wanderRangeHorizontal = NatFloat.createInvexp(wanderRangeMin, wanderRangeMax); if (taskConfig["maxHeight"] != null) { maxHeight = taskConfig["maxHeight"].AsFloat(7f); } if (taskConfig["preferredLightLevel"] != null) { preferredLightLevel = taskConfig["preferredLightLevel"].AsFloat(-99); if (preferredLightLevel < 0) { preferredLightLevel = null; } } }
public void FromBytes(BinaryReader reader, IClassRegistryAPI instancer) { Type = (EnumTransitionType)reader.ReadUInt16(); FreshHours = NatFloat.createFromBytes(reader); TransitionHours = NatFloat.createFromBytes(reader); TransitionedStack = new JsonItemStack(); TransitionedStack.FromBytes(reader, instancer); TransitionRatio = reader.ReadSingle(); }
public void Init(ICoreServerAPI api) { ResolveBlockCodes(api); if (Placement == EnumDepositPlacement.Anywhere) { Depth.avg *= api.WorldManager.MapSizeY; Depth.var *= api.WorldManager.MapSizeY; } if (Placement == EnumDepositPlacement.FollowSeaLevel) { Depth.avg *= TerraGenConfig.seaLevel; Depth.var *= TerraGenConfig.seaLevel; } if (CheckClimate && Radius.avg + Radius.var >= 32) { api.Server.LogWarning("Deposit has CheckClimate=true and radius > 32 blocks - this is not supported, sorry. Defaulting to uniform radius 10"); Radius = NatFloat.createUniform(10, 0); } if (BlockIds.Length == 0) { string code = BlockCode.Path.Replace("{", "{{").Replace("}", "}}"); throw new Exception("Invalid deposits.json: Can't have a deposit without blockcode (maybe invalid name? " + code + ")!"); } if (ChildDeposits != null) { for (int i = 0; i < ChildDeposits.Length; i++) { if (ChildDeposits[i].ParentBlockCodes == null) { ChildDeposits[i].ParentBlockCodes = new AssetLocation[BlockIds.Length]; for (int j = 0; j < BlockIds.Length; j++) { ChildDeposits[i].ParentBlockCodes[j] = api.World.Blocks[BlockIds[j]].Code; } ChildDeposits[i].GrandParentBlockLocs = new AssetLocation[ParentBlockCodes.Length]; for (int j = 0; j < ParentBlockCodes.Length; j++) { ChildDeposits[i].GrandParentBlockLocs[j] = ParentBlockCodes[j]; } } ChildDeposits[i].Init(api); } } else { ChildDeposits = new DepositVariant[0]; } }
public void Init(ICoreServerAPI api, RockStrataConfig rockstrata, LCGRandom rnd, int i) { List <Block> blocks = new List <Block>(); for (int j = 0; j < blockCodes.Length; j++) { AssetLocation code = blockCodes[j]; if (code.Path.Contains("{rocktype}")) { if (BlocksByRockType == null) { BlocksByRockType = new Dictionary <int, Block[]>(); } for (int k = 0; k < rockstrata.Variants.Length; k++) { string rocktype = rockstrata.Variants[k].BlockCode.Path.Split('-')[1]; AssetLocation rocktypedCode = code.CopyWithPath(code.Path.Replace("{rocktype}", rocktype)); Block rockBlock = api.World.GetBlock(rockstrata.Variants[k].BlockCode); if (rockBlock != null) { BlocksByRockType[rockBlock.BlockId] = new Block[] { api.World.GetBlock(rocktypedCode) }; } } } else { Block block = api.World.GetBlock(code); if (block != null) { blocks.Add(block); } else { api.World.Logger.Warning("Block patch Nr. {0}: Unable to resolve block with code {1}. Will ignore.", i, code); } } } Blocks = blocks.ToArray(); if (BlockCodeIndex == null) { BlockCodeIndex = NatFloat.createUniform(0, Blocks.Length); } if (RandomMapCodePool != null) { int index = rnd.NextInt(RandomMapCodePool.Length); MapCode = RandomMapCodePool[index]; } }
internal void ResolveBlockIds(ICoreServerAPI api, RockStrataConfig rockstrata) { for (int i = 0; i < Patches.Length; i++) { BlockPatch patch = Patches[i]; List <Block> blocks = new List <Block>(); for (int j = 0; j < patch.blockCodes.Length; j++) { AssetLocation code = patch.blockCodes[j]; if (code.Path.Contains("{rocktype}")) { if (patch.BlocksByRockType == null) { patch.BlocksByRockType = new Dictionary <int, Block[]>(); } for (int k = 0; k < rockstrata.Variants.Length; k++) { string rocktype = rockstrata.Variants[k].BlockCode.Path.Split('-')[1]; AssetLocation rocktypedCode = code.CopyWithPath(code.Path.Replace("{rocktype}", rocktype)); Block rockBlock = api.World.GetBlock(rockstrata.Variants[k].BlockCode); if (rockBlock != null) { patch.BlocksByRockType[rockBlock.BlockId] = new Block[] { api.World.GetBlock(rocktypedCode) }; } } } else { Block block = api.World.GetBlock(code); if (block != null) { blocks.Add(block); } else { api.World.Logger.Warning("Block patch Nr. {0}: Unable to resolve block with code {1}. Will ignore.", i, code); } } } patch.Blocks = blocks.ToArray(); if (patch.BlockCodeIndex == null) { patch.BlockCodeIndex = NatFloat.createUniform(0, patch.Blocks.Length); } } }
/// <summary> /// Reads the contents of the block bytes and converts it into a block. /// </summary> /// <param name="reader">The reader of the block</param> /// <param name="instancer">The block registry</param> public virtual void FromBytes(BinaryReader reader, IClassRegistryAPI instancer) { Type = (EnumItemClass)reader.ReadInt16(); Code = new AssetLocation(reader.ReadString()); Quantity = NatFloat.One; Quantity.FromBytes(reader); ResolvedItemstack = new ItemStack(reader); LastDrop = reader.ReadBoolean(); if (reader.ReadBoolean()) { DropModbyStat = reader.ReadString(); } }
public override void Init() { if (Radius == null) { Api.Server.LogWarning("Alluvial Deposit {0} has no radius property defined. Defaulting to uniform radius 10", variant.fromFile); Radius = NatFloat.createUniform(10, 0); } if (variant.Climate != null && Radius.avg + Radius.var >= 32) { Api.Server.LogWarning("Alluvial Deposit {0} has CheckClimate=true and radius > 32 blocks - this is not supported, sorry. Defaulting to uniform radius 10", variant.fromFile); Radius = NatFloat.createUniform(10, 0); } }
public override void OnBlockPlaced(ItemStack byItemStack = null) { Block block = Api.World.BlockAccessor.GetBlock(Pos); NatFloat growthDays = NatFloat.create(EnumDistribution.UNIFORM, 6.5f, 1.5f); if (block?.Attributes != null) { growthDays = block.Attributes["growthDays"].AsObject(growthDays); } totalHoursTillGrowth = Api.World.Calendar.TotalHours + growthDays.nextFloat(1, Api.World.Rand) * 24; }
public override void Init() { base.Init(); if (YPosRel == null) { Api.World.Logger.Error("Deposit variant {0} in {1} does not have a YPosRel definition. Where shall I place the deposit?", variant.Code, variant.fromFile); YPosRel = NatFloat.Zero; } YPosRel.avg *= TerraGenConfig.seaLevel; YPosRel.var *= TerraGenConfig.seaLevel; }
public override void LoadConfig(JsonObject taskConfig, JsonObject aiConfig) { base.LoadConfig(taskConfig, aiConfig); float wanderRangeMin = 3, wanderRangeMax = 30; if (taskConfig["targetDistance"] != null) { targetDistance = taskConfig["targetDistance"].AsFloat(0.12f); } if (taskConfig["movespeed"] != null) { moveSpeed = taskConfig["movespeed"].AsFloat(0.03f); } if (taskConfig["wanderChance"] != null) { wanderChance = taskConfig["wanderChance"].AsFloat(0.015f); } if (taskConfig["wanderRangeMin"] != null) { wanderRangeMin = taskConfig["wanderRangeMin"].AsFloat(3); } if (taskConfig["wanderRangeMax"] != null) { wanderRangeMax = taskConfig["wanderRangeMax"].AsFloat(30); } wanderRangeHorizontal = NatFloat.createStrongerInvexp(wanderRangeMin, wanderRangeMax); if (taskConfig["maxHeight"] != null) { maxHeight = taskConfig["maxHeight"].AsFloat(7f); } if (taskConfig["preferredLightLevel"] != null) { preferredLightLevel = taskConfig["preferredLightLevel"].AsFloat(-99); if (preferredLightLevel < 0) { preferredLightLevel = null; } } if (taskConfig["awaitReached"] != null) { awaitReached = taskConfig["awaitReached"].AsBool(true); } }
public float widthBranchLossBase = 1f; // Each branch action, this value gets multiplied to the current width (=> 1f = no loss in width from branching) public TreeGenRoot(NatFloat baseWidth, NatFloat rootEnd, NatFloat rootSpacing, NatFloat numBranching, float widthloss, EvolvingNatFloat horizontalAngle, EvolvingNatFloat verticalAngle, NatFloat branchVerticalAngle, NatFloat branchHorizontalAngle, NatFloat branchSpacing, NatFloat branchStart, float widthBranchLossBase) { this.baseWidth = baseWidth; this.rootEnd = rootEnd; this.rootSpacing = rootSpacing; this.numBranching = numBranching; this.horizontalAngle = horizontalAngle; this.verticalAngle = verticalAngle; this.widthloss = widthloss; this.branchVerticalAngle = branchVerticalAngle; this.branchHorizontalAngle = branchHorizontalAngle; this.branchSpacing = branchSpacing; this.branchStart = branchStart; this.widthBranchLossBase = widthBranchLossBase; }
internal void ResolveBlockIds(ICoreServerAPI api, RockstrataWorldProperty rockstrata) { for (int i = 0; i < Patches.Length; i++) { BlockPatch patch = Patches[i]; List <Block> blocks = new List <Block>(); for (int j = 0; j < patch.blockCodes.Length; j++) { AssetLocation code = patch.blockCodes[j]; if (code.Path.Contains("{rocktype}")) { if (patch.BlocksByRockType == null) { patch.BlocksByRockType = new Dictionary <ushort, Block[]>(); } for (int k = 0; k < rockstrata.Variants.Length; k++) { string rocktype = rockstrata.Variants[k].BlockCode.Path.Split('-')[1]; patch.BlocksByRockType.Add( api.WorldManager.GetBlockId(rockstrata.Variants[k].BlockCode), new Block[] { api.World.GetBlock(code.CopyWithPath(code.Path.Replace("{rocktype}", rocktype))) } ); } } else { blocks.Add(api.WorldManager.GetBlockType(api.WorldManager.GetBlockId(code))); } } patch.Blocks = blocks.ToArray(); if (patch.BlockCodeIndex == null) { patch.BlockCodeIndex = NatFloat.createUniform(0, patch.Blocks.Length); } } }
public void FromBytes(BinaryReader reader, IWorldAccessor resolver) { basePos = new Vec3d(reader.ReadDouble(), reader.ReadDouble(), reader.ReadDouble()); DieInAir = reader.ReadBoolean(); DieInLiquid = reader.ReadBoolean(); SwimOnLiquid = reader.ReadBoolean(); HsvaColor = new NatFloat[] { NatFloat.createFromBytes(reader), NatFloat.createFromBytes(reader), NatFloat.createFromBytes(reader), NatFloat.createFromBytes(reader) }; GravityEffect = NatFloat.createFromBytes(reader); LifeLength = NatFloat.createFromBytes(reader); PosOffset = new NatFloat[] { NatFloat.createFromBytes(reader), NatFloat.createFromBytes(reader), NatFloat.createFromBytes(reader) }; Quantity = NatFloat.createFromBytes(reader); Size = NatFloat.createFromBytes(reader); Velocity = new NatFloat[] { NatFloat.createFromBytes(reader), NatFloat.createFromBytes(reader), NatFloat.createFromBytes(reader) }; ParticleModel = (EnumParticleModel)reader.ReadByte(); VertexFlags = reader.ReadInt32(); if (!reader.ReadBoolean()) { OpacityEvolve = EvolvingNatFloat.CreateFromBytes(reader); } if (!reader.ReadBoolean()) { RedEvolve = EvolvingNatFloat.CreateFromBytes(reader); } if (!reader.ReadBoolean()) { GreenEvolve = EvolvingNatFloat.CreateFromBytes(reader); } if (!reader.ReadBoolean()) { BlueEvolve = EvolvingNatFloat.CreateFromBytes(reader); } SizeEvolve.FromBytes(reader); SelfPropelled = reader.ReadBoolean(); TerrainCollision = reader.ReadBoolean(); ColorByBlock = reader.ReadBoolean(); if (reader.ReadBoolean()) { VelocityEvolve = new EvolvingNatFloat[] { EvolvingNatFloat.createIdentical(0), EvolvingNatFloat.createIdentical(0), EvolvingNatFloat.createIdentical(0), }; VelocityEvolve[0].FromBytes(reader); VelocityEvolve[1].FromBytes(reader); VelocityEvolve[2].FromBytes(reader); } SecondarySpawnInterval = NatFloat.createFromBytes(reader); int secondaryPropCount = reader.ReadInt32(); if (secondaryPropCount > 0) { SecondaryParticles = new AdvancedParticleProperties[secondaryPropCount]; for (int i = 0; i < secondaryPropCount; i++) { SecondaryParticles[i] = AdvancedParticleProperties.createFromBytes(reader, resolver); } } int deathPropCount = reader.ReadInt32(); if (deathPropCount > 0) { DeathParticles = new AdvancedParticleProperties[deathPropCount]; for (int i = 0; i < deathPropCount; i++) { DeathParticles[i] = AdvancedParticleProperties.createFromBytes(reader, resolver); } } WindAffectednes = reader.ReadSingle(); }
public override void Init() { if (Radius == null) { Api.Server.LogWarning("Deposit {0} has no radius property defined. Defaulting to uniform radius 10", variant.fromFile); Radius = NatFloat.createUniform(10, 0); } if (variant.Climate != null && Radius.avg + Radius.var >= 32) { Api.Server.LogWarning("Deposit {0} has CheckClimate=true and radius > 32 blocks - this is not supported, sorry. Defaulting to uniform radius 10", variant.fromFile); Radius = NatFloat.createUniform(10, 0); } if (InBlock != null) { Block[] blocks = Api.World.SearchBlocks(InBlock.Code); if (blocks.Length == 0) { Api.Server.LogWarning("Deposit in file {0}, no such blocks found by code/wildcard '{1}'. Deposit will never spawn.", variant.fromFile, InBlock.Code); } foreach (var block in blocks) { if (InBlock.AllowedVariants != null && !WildcardUtil.Match(InBlock.Code, block.Code, InBlock.AllowedVariants)) { continue; } if (InBlock.AllowedVariantsByInBlock != null && !InBlock.AllowedVariantsByInBlock.ContainsKey(block.Code)) { continue; } string key = InBlock.Name; string value = WildcardUtil.GetWildcardValue(InBlock.Code, block.Code); placeBlockByInBlockId[block.BlockId] = PlaceBlock.Resolve(variant.fromFile, Api, block, key, value); if (SurfaceBlock != null) { surfaceBlockByInBlockId[block.BlockId] = SurfaceBlock.Resolve(variant.fromFile, Api, block, key, value); } if (variant.ChildDeposits != null) { foreach (var val in variant.ChildDeposits) { if (val.GeneratorInst == null) { val.InitWithoutGenerator(Api); val.GeneratorInst = new ChildDepositGenerator(Api, val, DepositRand, DistortNoiseGen); JsonUtil.Populate(val.Attributes.Token, val.GeneratorInst); } foreach (Block depositblock in placeBlockByInBlockId[block.BlockId].Blocks) { (val.GeneratorInst as ChildDepositGenerator).ResolveAdd(depositblock, key, value); } } } // Host rock for if (block.Attributes == null) { block.Attributes = new JsonObject(JToken.Parse("{}")); } int[] oreIds = block.Attributes["hostRockFor"].AsArray <int>(new int[0]); oreIds = oreIds.Append(placeBlockByInBlockId[block.BlockId].Blocks.Select(b => b.BlockId).ToArray()); block.Attributes.Token["hostRockFor"] = JToken.FromObject(oreIds); // In host rock Block[] placeBlocks = placeBlockByInBlockId[block.BlockId].Blocks; for (int i = 0; i < placeBlocks.Length; i++) { Block pblock = placeBlocks[i]; if (pblock.Attributes == null) { pblock.Attributes = new JsonObject(JToken.Parse("{}")); } oreIds = pblock.Attributes["hostRock"].AsArray <int>(new int[0]); oreIds = oreIds.Append(block.BlockId); pblock.Attributes.Token["hostRock"] = JToken.FromObject(oreIds); } } } else { Api.Server.LogWarning("Deposit in file {0} has no inblock defined, it will never spawn.", variant.fromFile); } }