public void LoadTreeGenerators() { Dictionary <AssetLocation, TreeGenConfig> TreeGenModelsByTree = sapi.Assets.GetMany <TreeGenConfig>(sapi.Server.Logger, "worldgen/treegen"); string names = ""; foreach (var val in TreeGenModelsByTree) { AssetLocation name = val.Key.Clone(); if (names.Length > 0) { names += ", "; } names += name; name.Path = val.Key.Path.Substring("worldgen/treegen/".Length); name.RemoveEnding(); val.Value.Init(val.Key, sapi.Server.Logger); sapi.RegisterTreeGenerator(name, new TreeGen(val.Value, sapi.WorldManager.Seed)); val.Value.treeBlocks.ResolveBlockNames(sapi); } sapi.Server.LogNotification("Reloaded {0} tree generators", TreeGenModelsByTree.Count); }
private void LoadWorldProperties() { worldProperties = new Dictionary <AssetLocation, StandardWorldProperty>(); foreach (var entry in api.Assets.GetMany <StandardWorldProperty>(api.Server.Logger, "worldproperties/")) { AssetLocation loc = entry.Key.Clone(); loc.Path = loc.Path.Replace("worldproperties/", ""); loc.RemoveEnding(); entry.Value.Code.Domain = entry.Key.Domain; worldProperties.Add(loc, entry.Value); } worldPropertiesVariants = new Dictionary <AssetLocation, VariantEntry[]>(); foreach (var val in worldProperties) { if (val.Value == null) { continue; } WorldPropertyVariant[] variants = val.Value.Variants; if (variants == null) { continue; } if (val.Value.Code == null) { api.Server.LogError("Error in worldproperties {0}, code is null, so I won't load it", val.Key); continue; } worldPropertiesVariants[val.Value.Code] = new VariantEntry[variants.Length]; for (int i = 0; i < variants.Length; i++) { if (variants[i].Code == null) { api.Server.LogError("Error in worldproperties {0}, variant {1}, code is null, so I won't load it", val.Key, i); worldPropertiesVariants[val.Value.Code] = worldPropertiesVariants[val.Value.Code].RemoveEntry(i); continue; } worldPropertiesVariants[val.Value.Code][i] = new VariantEntry() { Code = variants[i].Code.Path }; } } }
public void LoadTreeGenerators() { Dictionary <AssetLocation, TreeGenConfig> TreeGenModelsByTree = sapi.Assets.GetMany <TreeGenConfig>(sapi.Server.Logger, "worldgen/treegen"); var worldprops = sapi.Assets.Get <WoodWorldProperty>(new AssetLocation("worldproperties/block/wood.json")); Dictionary <string, EnumTreeType> treetypes = new Dictionary <string, EnumTreeType>(); foreach (var val in worldprops.Variants) { treetypes[val.Code.Path] = val.TreeType; } string names = ""; foreach (var val in TreeGenModelsByTree) { AssetLocation name = val.Key.Clone(); if (names.Length > 0) { names += ", "; } names += name; name.Path = val.Key.Path.Substring("worldgen/treegen/".Length); name.RemoveEnding(); val.Value.Init(val.Key, sapi.Server.Logger); sapi.RegisterTreeGenerator(name, new TreeGen(val.Value, sapi.WorldManager.Seed, forestFloorSystem)); val.Value.treeBlocks.ResolveBlockNames(sapi, name.Path); treetypes.TryGetValue(sapi.World.GetBlock(val.Value.treeBlocks.logBlockId).Variant["wood"], out val.Value.Treetype); } sapi.Server.LogNotification("Reloaded {0} tree generators", TreeGenModelsByTree.Count); }
public override void StartServerSide(ICoreServerAPI api) { this.api = api; worldProperties = new Dictionary <AssetLocation, StandardWorldProperty>(); foreach (var entry in api.Assets.GetMany <StandardWorldProperty>(api.Server.Logger, "worldproperties/")) { AssetLocation loc = entry.Key.Clone(); loc.Path = loc.Path.Replace("worldproperties/", ""); loc.RemoveEnding(); worldProperties.Add(loc, entry.Value); } blockShapes = api.Assets.GetMany <Shape>(api.Server.Logger, "shapes/block/"); blockTypes = new Dictionary <AssetLocation, BlockType>(); foreach (KeyValuePair <AssetLocation, JObject> entry in api.Assets.GetMany <JObject>(api.Server.Logger, "blocktypes/")) { JToken property = null; JObject blockTypeObject = entry.Value; if (blockTypeObject == null) { api.Server.LogWarning("Unable to load block type {0}, does not seem to be a json file. Will ignore.", entry.Key); continue; } AssetLocation location = null; try { location = blockTypeObject.GetValue("code").ToObject <AssetLocation>(); location.Domain = entry.Key.Domain; } catch (Exception e) { api.World.Logger.Error("Block type {0} has no valid code property. Will ignore. Exception thrown: {1}", entry.Key, e); continue; } blockTypes.Add(entry.Key, new BlockType() { Code = location, VariantGroups = blockTypeObject.TryGetValue("variantgroups", out property) ? property.ToObject <CollectibleVariantGroup[]>() : null, Enabled = blockTypeObject.TryGetValue("enabled", out property) ? property.ToObject <bool>() : true, jsonObject = blockTypeObject }); } itemTypes = new Dictionary <AssetLocation, ItemType>(); foreach (KeyValuePair <AssetLocation, JObject> entry in api.Assets.GetMany <JObject>(api.Server.Logger, "itemtypes/")) { JToken property = null; JObject itemTypeObject = entry.Value; if (itemTypeObject == null) { api.Server.LogWarning("Unable to load item type {0}, does not seem to be a json file. Will ignore.", entry.Key); continue; } AssetLocation location = itemTypeObject.GetValue("code").ToObject <AssetLocation>(); location.Domain = entry.Key.Domain; itemTypes.Add(entry.Key, new ItemType() { Code = location, VariantGroups = itemTypeObject.TryGetValue("variantgroups", out property) ? property.ToObject <CollectibleVariantGroup[]>() : null, Enabled = itemTypeObject.TryGetValue("enabled", out property) ? property.ToObject <bool>() : true, jsonObject = itemTypeObject }); } worldPropertiesVariants = new Dictionary <AssetLocation, BlockVariant[]>(); foreach (var val in worldProperties) { if (val.Value == null) { continue; } WorldPropertyVariant[] variants = val.Value.Variants; if (variants == null) { continue; } if (val.Value.Code == null) { api.Server.LogError("Error in worldproperties {0}, not code set", val.Key); return; } worldPropertiesVariants[val.Value.Code] = new BlockVariant[variants.Length]; for (int i = 0; i < variants.Length; i++) { worldPropertiesVariants[val.Value.Code][i] = new BlockVariant() { Code = variants[i].Code.Path }; } } LoadItems(); LoadBlocks(); api.Server.LogNotification("BlockLoader: Blocks and Items loaded"); }
/// <summary> /// Expands a CompositeTexture to a texture atlas friendly version and populates the Baked field /// </summary> /// <param name="assetManager"></param> /// <param name="ct"></param> /// <returns></returns> static BakedCompositeTexture Bake(IAssetManager assetManager, CompositeTexture ct) { BakedCompositeTexture bct = new BakedCompositeTexture(); bct.BakedName = ct.Base.Clone(); if (ct.Base.Path.EndsWith("*")) { List <IAsset> assets = assetManager.GetMany("textures/" + bct.BakedName.Path.Substring(0, bct.BakedName.Path.Length - 1), bct.BakedName.Domain); if (assets.Count == 0) { ct.Base = bct.BakedName = new AssetLocation("unknown"); } if (assets.Count == 1) { ct.Base = assets[0].Location.Clone(); ct.Base.Path = assets[0].Location.Path.Substring("textures/".Length); ct.Base.RemoveEnding(); bct.BakedName = ct.Base.Clone(); } if (assets.Count > 1) { int origLength = (ct.Alternates == null ? 0 : ct.Alternates.Length); CompositeTexture[] alternates = new CompositeTexture[origLength + assets.Count - 1]; if (ct.Alternates != null) { Array.Copy(ct.Alternates, alternates, ct.Alternates.Length); } int i = 0; foreach (IAsset asset in assets) { AssetLocation newLocation = assets[0].Location.Clone(); newLocation.Path = asset.Location.Path.Substring("textures/".Length); newLocation.RemoveEnding(); if (i == 0) { ct.Base = newLocation; bct.BakedName = ct.Base; } else { alternates[origLength + i - 1] = new CompositeTexture(newLocation); } i++; } ct.Alternates = alternates; } } if (ct.Overlays != null) { bct.TextureFilenames = new AssetLocation[ct.Overlays.Length + 1]; bct.TextureFilenames[0] = ct.Base.Clone(); for (int i = 0; i < ct.Overlays.Length; i++) { bct.TextureFilenames[i + 1] = ct.Overlays[i].Clone(); bct.BakedName.Path += "++" + ct.Overlays[i].ToShortString(); } } else { bct.TextureFilenames = new AssetLocation[] { ct.Base.Clone() }; } if (ct.Rotation != 0) { if (ct.Rotation != 90 && ct.Rotation != 0 && ct.Rotation != 180 && ct.Rotation != 270) { throw new Exception("Texture definition " + ct.Base + " has a rotation thats not 0, 90, 180 or 270. These are the only allowed values!"); } bct.BakedName.Path += "@" + ct.Rotation; } if (ct.Alternates != null) { bct.BakedVariants = new BakedCompositeTexture[ct.Alternates.Length + 1]; bct.BakedVariants[0] = bct; for (int i = 0; i < ct.Alternates.Length; i++) { bct.BakedVariants[i + 1] = Bake(assetManager, ct.Alternates[i]); } } return(bct); }