void ResolveBlockIds(ICoreServerAPI api, RockStrataConfig rockstrata) { if (BlockCode != null && BlockCode.Path.Length > 0) { if (BlockCode.Path.Contains("{rocktype}")) { BlockIdMapping = new Dictionary <int, int>(); for (int i = 0; i < rockstrata.Variants.Length; i++) { if (rockstrata.Variants[i].IsDeposit) { continue; } string rocktype = rockstrata.Variants[i].BlockCode.Path.Split('-')[1]; Block rockBlock = api.World.GetBlock(rockstrata.Variants[i].BlockCode); Block typedBlock = api.World.GetBlock(BlockCode.CopyWithPath(BlockCode.Path.Replace("{rocktype}", rocktype))); if (rockBlock != null && typedBlock != null) { BlockIdMapping[rockBlock.BlockId] = typedBlock.BlockId; } } } else { BlockId = api.WorldManager.GetBlockId(BlockCode); } } else { BlockCode = null; } }
private void ResolveBlockCodesWithParentPlaceHolder(ICoreServerAPI api, AssetLocation forBlockCode, List <ushort> parentBlockIds, List <ushort> blockIds) { bool haveWildcard = false; for (int j = 0; j < ParentBlockCodes.Length; j++) { AssetLocation parentLocation = ParentBlockCodes[j]; if (parentLocation.Path.EndsWith("*")) { haveWildcard = true; Block[] parentBlocks = api.WorldManager.SearchBlockTypes(parentLocation.Path.Substring(0, parentLocation.Path.Length - 1)); for (int i = 0; i < parentBlocks.Length; i++) { parentBlockIds.Add(parentBlocks[i].BlockId); string parentblockcode = parentBlocks[i].Code.Path.Substring(parentLocation.Path.Length - 1); AddBlock(api, blockIds, forBlockCode.CopyWithPath(forBlockCode.Path.Replace("{parentblocktype}", parentblockcode))); } } } if (!haveWildcard) { for (int j = 0; j < ParentBlockCodes.Length; j++) { AssetLocation parentLocation = ParentBlockCodes[j]; Block parentBlock = api.World.GetBlock(parentLocation); parentBlockIds.Add(parentBlock.BlockId); string parentblockcode = parentBlock.CodeEndWithoutParts(1); AddBlock(api, blockIds, forBlockCode.CopyWithPath(forBlockCode.Path.Replace("{parentblocktype}", parentblockcode))); } } int missingIds = parentBlockIds.Count - blockIds.Count; for (int i = 0; i < missingIds; i++) { blockIds.Add(blockIds[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); } } }
private void ResolveBlockCodesWithGrandParentPlaceHolder(ICoreServerAPI api, List <ushort> parentBlockIds, List <ushort> blockIds) { Block[] grandParentBlocks = api.WorldManager.SearchBlockTypes(GrandParentBlockLocs[0].Path.Substring(0, GrandParentBlockLocs[0].Path.Length - 1)); for (int i = 0; i < ParentBlockCodes.Length; i++) { string grandparentblockcode = grandParentBlocks[i].Code.Path.Substring(GrandParentBlockLocs[0].Path.Length - 1); AddBlock(api, parentBlockIds, ParentBlockCodes[i]); AddBlock(api, blockIds, BlockCode.CopyWithPath(BlockCode.Path.Replace("{grandparentblocktype}", grandparentblockcode))); } int missingIds = parentBlockIds.Count - blockIds.Count; for (int i = 0; i < missingIds; i++) { blockIds.Add(blockIds[0]); } }
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 override void OnLoaded(ICoreAPI api) { paintableOnBlockMaterials = new EnumBlockMaterial[onmaterialsStrTmp.Length]; for (int i = 0; i < onmaterialsStrTmp.Length; i++) { if (onmaterialsStrTmp[i] == null) { continue; } try { paintableOnBlockMaterials[i] = (EnumBlockMaterial)Enum.Parse(typeof(EnumBlockMaterial), onmaterialsStrTmp[i]); } catch (Exception) { api.Logger.Warning("ArtPigment behavior for collectible {0}, paintable on material {1} is not a valid block material, will default to stone", collObj.Code, onmaterialsStrTmp[i]); paintableOnBlockMaterials[i] = EnumBlockMaterial.Stone; } } onmaterialsStrTmp = null; var capi = api as ICoreClientAPI; foreach (var loc in decorCodesTmp) { if (loc.Path.Contains("*")) { Block[] blocks = api.World.SearchBlocks(loc); foreach (var block in blocks) { decorBlocks.Add(block); //Console.WriteLine("\"/bir remapq " + block.Code.ToShortString() + " drawnart"+block.Variant["material"]+"-1-" + block.Variant["row"] +"-" + block.Variant["col"] + " force\","); } if (blocks.Length == 0) { api.Logger.Warning("ArtPigment behavior for collectible {0}, decor {1}, no such block using this wildcard found", collObj.Code, loc); } } else { Block block = api.World.GetBlock(loc); if (block == null) { api.Logger.Warning("ArtPigment behavior for collectible {0}, decor {1} is not a loaded block", collObj.Code, loc); } else { decorBlocks.Add(block); } } } if (api.Side == EnumAppSide.Client) { if (decorBlocks.Count > 0) { BakedCompositeTexture tex = decorBlocks[0].Textures["up"].Baked; texPos = capi.BlockTextureAtlas.Positions[tex.TextureSubId]; } else { texPos = capi.BlockTextureAtlas.UnknownTexturePosition; } } AssetLocation blockCode = collObj.Code; toolModes = new SkillItem[decorBlocks.Count]; for (int i = 0; i < toolModes.Length; i++) { toolModes[i] = new SkillItem() { Code = blockCode.CopyWithPath("art" + i), // Unique code, it doesn't really matter what it is Linebreak = i % GlobalConstants.CaveArtColsPerRow == 0, Name = "", // No name - alternatively each icon could be given a name? But discussed in meeting on 6/6/21 and decided it is better for players to assign their own meanings to the icons Data = decorBlocks[i], RenderHandler = (AssetLocation code, float dt, double atPosX, double atPosY) => { float wdt = (float)GuiElement.scaled(GuiElementPassiveItemSlot.unscaledSlotSize); string id = code.Path.Substring(3); capi.Render.Render2DTexture(meshes[int.Parse(id)], texPos.atlasTextureId, (float)atPosX, (float)atPosY, wdt, wdt); } }; } if (capi != null) { meshes = new MeshRef[decorBlocks.Count]; for (int i = 0; i < meshes.Length; i++) { MeshData mesh = genMesh(i); meshes[i] = capi.Render.UploadMesh(mesh); } } }
void ResolveBlockIds(ICoreServerAPI api, RockstrataWorldProperty rockstrata) { if (BlockCode != null && BlockCode.Path.Length > 0) { if (BlockCode.Path.Contains("{rocktype}")) { BlockIdMapping = new Dictionary <ushort, ushort>(); for (int i = 0; i < rockstrata.Variants.Length; i++) { string rocktype = rockstrata.Variants[i].BlockCode.Path.Split('-')[1]; BlockIdMapping.Add(api.WorldManager.GetBlockId(rockstrata.Variants[i].BlockCode), api.WorldManager.GetBlockId(BlockCode.CopyWithPath(BlockCode.Path.Replace("{rocktype}", rocktype)))); } } else { BlockId = api.WorldManager.GetBlockId(BlockCode); } } else { BlockCode = null; } }