public static void AddTextures() { var textureMapping = new ItemTypesServer.TextureMapping(new JSONNode()); textureMapping.AlbedoPath = GameLoader.BLOCKS_ALBEDO_PATH + "AirTurret.png"; textureMapping.NormalPath = GameLoader.BLOCKS_NORMAL_PATH + "Turret.png"; textureMapping.HeightPath = GameLoader.BLOCKS_HEIGHT_PATH + "Turret.png"; ItemTypesServer.SetTextureMapping(AIRTURRET_NAMESPACE + "sides", textureMapping); var earthTexture = new ItemTypesServer.TextureMapping(new JSONNode()); earthTexture.AlbedoPath = GameLoader.BLOCKS_ALBEDO_PATH + "EarthTurret.png"; earthTexture.NormalPath = GameLoader.BLOCKS_NORMAL_PATH + "Turret.png"; earthTexture.HeightPath = GameLoader.BLOCKS_HEIGHT_PATH + "Turret.png"; ItemTypesServer.SetTextureMapping(EARTHTURRET_NAMESPACE + "sides", earthTexture); var fireTexture = new ItemTypesServer.TextureMapping(new JSONNode()); fireTexture.AlbedoPath = GameLoader.BLOCKS_ALBEDO_PATH + "FireTurret.png"; fireTexture.NormalPath = GameLoader.BLOCKS_NORMAL_PATH + "Turret.png"; fireTexture.HeightPath = GameLoader.BLOCKS_HEIGHT_PATH + "Turret.png"; ItemTypesServer.SetTextureMapping(FIRETURRET_NAMESPACE + "sides", fireTexture); var waterTexture = new ItemTypesServer.TextureMapping(new JSONNode()); waterTexture.AlbedoPath = GameLoader.BLOCKS_ALBEDO_PATH + "WaterTurret.png"; waterTexture.NormalPath = GameLoader.BLOCKS_NORMAL_PATH + "Turret.png"; waterTexture.HeightPath = GameLoader.BLOCKS_HEIGHT_PATH + "Turret.png"; ItemTypesServer.SetTextureMapping(WATERTURRET_NAMESPACE + "sides", waterTexture); var voidTexture = new ItemTypesServer.TextureMapping(new JSONNode()); voidTexture.AlbedoPath = GameLoader.BLOCKS_ALBEDO_PATH + "VoidTurret.png"; voidTexture.NormalPath = GameLoader.BLOCKS_NORMAL_PATH + "Turret.png"; voidTexture.HeightPath = GameLoader.BLOCKS_HEIGHT_PATH + "Turret.png"; ItemTypesServer.SetTextureMapping(VOIDTURRET_NAMESPACE + "sides", voidTexture); }
public void RegisterActionCallback() { // Utilities.WriteLog("Registering actions for:" + this.TypeName); if (this._HasAddAction) { Utilities.WriteLog(this.TypeName + " has action Add"); ItemTypesServer.RegisterOnAdd(this.TypeName, this.onAddAction); } if (this._HasChangeAction) { Utilities.WriteLog(this.TypeName + " has action change"); ItemTypesServer.RegisterOnChange(this.TypeName, this.onChangeAction); } if (this._HasRemoveAction) { Utilities.WriteLog(this.TypeName + " has action remove"); ItemTypesServer.RegisterOnRemove(this.TypeName, this.onRemoveAction); } }
/// <summary> /// Registers this texture in the server database. Should be called during the afterSelectedWorld callback method. /// </summary> public void registerTexture() { Pipliz.Log.Write("{0}: Registering specific texture as {1}", NAMESPACE == null ? "" : NAMESPACE, this.ID); foreach (string S in new List <string> { this.AlbedoPath, this.EmissivePath, this.HeightPath, this.NormalPath }) { if (S != null) { if (System.IO.File.Exists(S)) { Pipliz.Log.Write("{0}: Looks good, albedo file exists.", NAMESPACE == null ? "" : NAMESPACE); } else { Pipliz.Log.WriteError("{0}: ERROR! Registering texture to a file {1} which does not exist!", NAMESPACE == null ? "" : NAMESPACE, S); } } } ItemTypesServer.SetTextureMapping(this.ID, this.asTextureMapping()); Pipliz.Log.Write("{0}: Specific texture registered: {1}", NAMESPACE == null ? "" : NAMESPACE, this.Name); }
public static void AfterAddingBaseTypes() { ItemTypesServer.AddTextureMapping(MOD_PREFIX + "bucketSide", new JSONNode() .SetAs("albedo", "furnaceSide") .SetAs("normal", "neutral") .SetAs("emissive", "neutral") .SetAs("height", "neutral") ); ItemTypesServer.AddTextureMapping(MOD_PREFIX + "bucketemptytop", new JSONNode() .SetAs("albedo", Path.Combine(RelativeTexturesPath, "bucketEmptyTop")) .SetAs("normal", "furnaceUnlitTop") .SetAs("emissive", "neutral") .SetAs("height", "neutral") ); ItemTypes.AddRawType(MOD_PREFIX + "bucket", new JSONNode(NodeType.Object) .SetAs("icon", Path.Combine(RelativeIconsPath, "bucket.png")) .SetAs("maxStackSize", 5) .SetAs("needsBase", "true") .SetAs("npcLimit", 0) .SetAs("sideall", MOD_PREFIX + "bucketSide") .SetAs("sidey+", MOD_PREFIX + "bucketemptytop") ); ItemTypesServer.AddTextureMapping(MOD_PREFIX + "waterbucketfilledtop", new JSONNode() .SetAs("albedo", Path.Combine(RelativeTexturesPath, "waterbucketFilledTop")) .SetAs("normal", "furnaceUnlitTop") .SetAs("emissive", "neutral") .SetAs("height", "neutral") ); ItemTypes.AddRawType(MOD_PREFIX + "waterbucket", new JSONNode(NodeType.Object) .SetAs("icon", Path.Combine(RelativeIconsPath, "waterbucket.png")) .SetAs("maxStackSize", 5) .SetAs("needsBase", "true") .SetAs("npcLimit", 0) .SetAs("sideall", MOD_PREFIX + "bucketSide") .SetAs("sidey+", MOD_PREFIX + "waterbucketfilledtop") ); }
public void Register() { JSONNode texture = new JSONNode(); texture.SetAs("albedo", Albedo); if (Emissive != null && Emissive != "") { texture.SetAs("emissive", Emissive); } if (Height != null && Height != "") { texture.SetAs("height", Height); } if (Normal != null && Normal != "") { texture.SetAs("normal", Normal); } ItemTypesServer.SetTextureMapping(Name, new ItemTypesServer.TextureMapping(texture)); }
public static void AfterAddingBaseTypes() { ItemTypesServer.AddTextureMapping("ExampleBlock1", new JSONNode() .SetAs("albedo", "grassTemperate") .SetAs("normal", "stoneblock") .SetAs("emissive", "ovenLitFront") .SetAs("height", "oreCoal") ); ItemTypesServer.AddTextureMapping("ExampleBlock2", new JSONNode() .SetAs("albedo", "grindstone") .SetAs("normal", "berrybush") .SetAs("emissive", "torch") .SetAs("height", "snow") ); ItemTypes.AddRawType("ExampleBlock1", new JSONNode(NodeType.Object) .SetAs("onPlaceAudio", "stonePlace") .SetAs("onRemoveAudio", "woodDeleteLight") .SetAs("sideall", "SELF") .SetAs("onRemoveAmount", 2) .SetAs("maxStackSize", 500) .SetAs("npcLimit", 1000) ); ItemTypes.AddRawType("ExampleBlock2", new JSONNode(NodeType.Object) .SetAs("onPlaceAudio", "stonePlace") .SetAs("onRemoveAudio", "woodDeleteLight") .SetAs("sideall", "SELF") .SetAs("onRemoveAmount", 2) .SetAs("maxStackSize", 500) .SetAs("npcLimit", 1000) ); }
public virtual void OnNPCAtJob(IAreaJob job, ref Vector3Int positionSub, ref NPCBase.NPCState state, ref bool shouldDumpInventory) { if (stages == null || stages.Length < 2) { state.SetCooldown(1.0); return; } state.JobIsDone = true; if (positionSub.IsValid) { ushort type; if (World.TryGetTypeAt(positionSub, out type)) { ushort typeSeeds = stages[0]; ushort typeFinal = stages[stages.Length - 1]; if (type == 0) { if (state.Inventory.TryGetOneItem(typeSeeds) || job.NPC.Colony.UsedStockpile.TryRemove(typeSeeds)) { ushort typeBelow; if (World.TryGetTypeAt(positionSub.Add(0, -1, 0), out typeBelow)) { // check for fertile below if (ItemTypes.GetType(typeBelow).IsFertile) { ServerManager.TryChangeBlock(positionSub, typeSeeds, job.Owner, ServerManager.SetBlockFlags.DefaultAudio); state.SetCooldown(1.0); shouldDumpInventory = false; } else { // not fertile below AreaJobTracker.RemoveJob(job); state.SetCooldown(2.0); } } else { // didn't load this part of the world state.SetCooldown(Random.NextFloat(3f, 6f)); } } else { state.SetIndicator(new Shared.IndicatorState(2f, typeSeeds, true, false)); shouldDumpInventory = state.Inventory.UsedCapacity > 0f; } } else if (type == typeFinal) { if (ServerManager.TryChangeBlock(positionSub, 0, job.Owner, ServerManager.SetBlockFlags.DefaultAudio)) { GatherResults.Clear(); var results = ItemTypes.GetType(typeFinal).OnRemoveItems; for (int i = 0; i < results.Count; i++) { GatherResults.Add(results[i]); } ModLoader.TriggerCallbacks(ModLoader.EModCallbackType.OnNPCGathered, job as IJob, positionSub, GatherResults); job.NPC.Inventory.Add(GatherResults); } state.SetCooldown(1.0); shouldDumpInventory = false; } else { shouldDumpInventory = state.Inventory.UsedCapacity > 0f; Server.GrowableBlocks.IGrowableBlock block; if (Server.GrowableBlocks.GrowableBlockManager.TryGetGrowableBlock(positionSub, out block)) { state.SetCooldown(5.0); } else { bool found = false; for (int i = 0; i < stages.Length; i++) { if (stages[i] == type) { ItemTypesServer.OnChange(positionSub, 0, type, null); state.SetIndicator(new Shared.IndicatorState(2f, type)); state.SetCooldown(0.2); found = true; break; } } if (!found) { state.SetCooldown(5.0); } } } } else { state.SetCooldown(Random.NextFloat(3f, 6f)); } positionSub = Vector3Int.invalidPos; } else { state.SetCooldown(10.0); } }
private static void AddTextureMapping(string path, string sub) { Logger.Log("Update texture mappings..."); if (JSON.Deserialize(path + "/UpdateTextures.json", out JSONNode jsonTextureMapping, false)) { if (jsonTextureMapping.NodeType == NodeType.Object) { foreach (KeyValuePair <string, JSONNode> textureEntry in jsonTextureMapping.LoopObject()) { try { string albedoPath = null; string normalPath = null; string emissivePath = null; string heightPath = null; foreach (string textureType in new string[] { "albedo", "normal", "emissive", "height" }) { string textureTypeValue = textureEntry.Value.GetAs <string>(textureType); string realTextureTypeValue = textureTypeValue; if (!textureTypeValue.Equals("neutral")) { if (textureTypeValue.StartsWith(VANILLA_PREFIX)) { realTextureTypeValue = realTextureTypeValue.Substring(VANILLA_PREFIX.Length); } else { realTextureTypeValue = GameLoader.TextureFolder + "/" + textureType + "/" + sub + textureTypeValue + ".png"; switch (textureType.ToLowerInvariant()) { case "albedo": albedoPath = realTextureTypeValue; break; case "normal": normalPath = realTextureTypeValue; break; case "emissive": emissivePath = realTextureTypeValue; break; case "height": heightPath = realTextureTypeValue; break; } } } textureEntry.Value.SetAs(textureType, realTextureTypeValue); } var textureMapping = new ItemTypesServer.TextureMapping(textureEntry.Value); if (albedoPath != null) { textureMapping.AlbedoPath = albedoPath; } if (normalPath != null) { textureMapping.NormalPath = normalPath; } if (emissivePath != null) { textureMapping.EmissivePath = emissivePath; } if (heightPath != null) { textureMapping.HeightPath = heightPath; } string realkey; if (!textureEntry.Key.StartsWith(VANILLA_PREFIX)) { realkey = Blocks.MOD_NAMESPACE + "." + textureEntry.Key; } else { realkey = textureEntry.Key.Substring(VANILLA_PREFIX.Length); } ItemTypesServer.SetTextureMapping(realkey, textureMapping); Logger.Log("TextureMapping loaded for..." + realkey); } catch (Exception exception) { Logger.Log("Exception while loading from {0}; {1}", "texturemapping.json", exception.Message); } } } else { Logger.Log("Expected json object in {0}, but got {1} instead", "texturemapping.json", jsonTextureMapping.NodeType); } } }
static void ItemRotator(Dictionary <string, ItemTypesServer.ItemTypeRaw> items, RotatorSettings settings, JSONNode customDataLitOnly) { ItemTypesServer.ItemTypeRaw unlitXP = RotatedTypeUnlit(settings.BaseType.name, "x+", settings.rotatedSideUnlit); ItemTypesServer.ItemTypeRaw unlitXN = RotatedTypeUnlit(settings.BaseType.name, "x-", settings.rotatedSideUnlit); ItemTypesServer.ItemTypeRaw unlitZP = RotatedTypeUnlit(settings.BaseType.name, "z+", settings.rotatedSideUnlit); ItemTypesServer.ItemTypeRaw unlitZN = RotatedTypeUnlit(settings.BaseType.name, "z-", settings.rotatedSideUnlit); settings.BaseType.description .SetAs("isRotatable", true) .SetAs("rotatablex+", unlitXP.name) .SetAs("rotatablex-", unlitXN.name) .SetAs("rotatablez+", unlitZP.name) .SetAs("rotatablez-", unlitZN.name); if (settings.sideTopUnlit != null) { settings.BaseType.description.SetAs("sidey+", settings.sideTopUnlit); } items[unlitXP.name] = unlitXP; items[unlitXN.name] = unlitXN; items[unlitZP.name] = unlitZP; items[unlitZN.name] = unlitZN; items[settings.BaseType.name] = settings.BaseType; if (customDataLitOnly != null) { string litBaseName = settings.BaseType.name + "lit"; ItemTypesServer.ItemTypeRaw litXP = RotatedTypeLit(litBaseName, "x+", settings.rotatedSideLit, customDataLitOnly.DeepClone()); ItemTypesServer.ItemTypeRaw litXN = RotatedTypeLit(litBaseName, "x-", settings.rotatedSideLit, customDataLitOnly.DeepClone()); ItemTypesServer.ItemTypeRaw litZP = RotatedTypeLit(litBaseName, "z+", settings.rotatedSideLit, customDataLitOnly.DeepClone()); ItemTypesServer.ItemTypeRaw litZN = RotatedTypeLit(litBaseName, "z-", settings.rotatedSideLit, customDataLitOnly.DeepClone()); ItemTypesServer.ItemTypeRaw baseLitType = new ItemTypesServer.ItemTypeRaw( litBaseName, new JSONNode() .SetAs("parentType", settings.BaseType.name) .SetAs("isRotatable", true) .SetAs("rotatablex+", litXP.name) .SetAs("rotatablex-", litXN.name) .SetAs("rotatablez+", litZP.name) .SetAs("rotatablez-", litZN.name) .SetAs("sidey+", settings.sideTopLit) ); items[litXP.name] = litXP; items[litXN.name] = litXN; items[litZP.name] = litZP; items[litZN.name] = litZN; items[baseLitType.name] = baseLitType; RegisteringChangeTypes.Add(() => ItemTypesServer.RegisterChangeTypes(settings.BaseType.name, new List <string>() { litXP.name, litXN.name, litZP.name, litZN.name, unlitXP.name, unlitXN.name, unlitZP.name, unlitZN.name }) ); } else { RegisteringChangeTypes.Add(() => ItemTypesServer.RegisterChangeTypes(settings.BaseType.name, new List <string>() { unlitXP.name, unlitXN.name, unlitZP.name, unlitZN.name }) ); } }
public void RegisterCallback() { ItemTypesServer.RegisterOnAdd(blockName, OnAdd); ItemTypesServer.RegisterOnRemove(blockName, OnRemove); }
public override void OnNPCAtJob(IAreaJob job, ref Vector3Int positionSub, ref NPCBase.NPCState state, ref bool shouldDumpInventory) { state.JobIsDone = true; Vector3Int min = job.Minimum; Vector3Int max = job.Maximum; if (positionSub.x == min.x || positionSub.x == max.x || positionSub.z == min.z || positionSub.z == max.z || (positionSub.x - (min.x + 1)) % 3 != 0 || (positionSub.z - (min.z + 1)) % 3 != 0) { ushort type; if (World.TryGetTypeAt(positionSub.Add(1, 0, 1), out type)) { if (type == saplingIndex) { Server.GrowableBlocks.IGrowableBlock block; if (Server.GrowableBlocks.GrowableBlockManager.TryGetGrowableBlock(positionSub.Add(1, 0, 1), out block)) { state.SetCooldown(5.0); } else { ItemTypesServer.OnChange(positionSub.Add(1, 0, 1), 0, saplingIndex, null); state.SetIndicator(new Shared.IndicatorState(2f, saplingIndex)); state.SetCooldown(0.2); } } } } else if (positionSub.IsValid) { ushort type; if (World.TryGetTypeAt(positionSub, out type)) { if (type == 0) { if (job.NPC.Inventory.TryGetOneItem(saplingIndex) || job.NPC.Colony.UsedStockpile.TryRemove(saplingIndex)) { ServerManager.TryChangeBlock(positionSub, saplingIndex, job.Owner, ServerManager.SetBlockFlags.DefaultAudio); state.SetCooldown(2.0); } else { state.SetIndicator(new Shared.IndicatorState(2f, saplingIndex)); } } else if (type == logIndex) { if (ChopTree(positionSub, job.Owner)) { state.SetIndicator(new Shared.IndicatorState(10f, logIndex)); ServerManager.SendAudio(positionSub.Vector, "woodDeleteHeavy"); GatherResults.Clear(); GatherResults.Add(new ItemTypes.ItemTypeDrops(logIndex, 3, 1.0)); GatherResults.Add(new ItemTypes.ItemTypeDrops(leaveIndex, 9, 1.0)); GatherResults.Add(new ItemTypes.ItemTypeDrops(saplingIndex, 1, 1.0)); GatherResults.Add(new ItemTypes.ItemTypeDrops(saplingIndex, 1, 0.25)); GatherResults.Add(new ItemTypes.ItemTypeDrops(fruitIndex, 2, 0.5)); ModLoader.TriggerCallbacks(ModLoader.EModCallbackType.OnNPCGathered, job as IJob, positionSub, GatherResults); job.NPC.Inventory.Add(GatherResults); } else { state.SetCooldown(Random.NextFloat(3f, 6f)); } } else { state.SetCooldown(Random.NextFloat(8f, 16f)); } } else { state.SetCooldown(Random.NextFloat(3f, 6f)); } } else { state.SetCooldown(10.0); } positionSub = Vector3Int.invalidPos; }
public override void OnNPCAtJob(IAreaJob job, ref Vector3Int positionSub, ref NPCBase.NPCState state, ref bool shouldDumpInventory) { state.JobIsDone = true; Vector3Int min = job.Minimum; Vector3Int max = job.Maximum; if (positionSub.x == min.x || positionSub.x == max.x || positionSub.z == min.z || positionSub.z == max.z || (positionSub.x - (min.x + 1)) % 3 != 0 || (positionSub.z - (min.z + 1)) % 3 != 0) { ushort type; if (World.TryGetTypeAt(positionSub.Add(1, 0, 1), out type)) { if (type == BuiltinBlocks.Sapling) { Server.GrowableBlocks.IGrowableBlock block; if (Server.GrowableBlocks.GrowableBlockManager.TryGetGrowableBlock(positionSub.Add(1, 0, 1), out block)) { state.SetCooldown(5.0); } else { ItemTypesServer.OnChange(positionSub.Add(1, 0, 1), 0, BuiltinBlocks.Sapling, null); state.SetIndicator(new Shared.IndicatorState(2f, BuiltinBlocks.Sapling)); state.SetCooldown(0.2); } } else { state.SetCooldown(1.0); // no sapling at sapling spot (shouldn't occur a lot, something changed between calculate sub position and this } } else { state.SetCooldown(4.0); // walked to sapling spot, not loaded } } else if (positionSub.IsValid) { ushort type; if (World.TryGetTypeAt(positionSub, out type)) { if (type == 0) { if (job.NPC.Inventory.TryGetOneItem(BuiltinBlocks.Sapling) || job.NPC.Colony.UsedStockpile.TryRemove(BuiltinBlocks.Sapling)) { ServerManager.TryChangeBlock(positionSub, BuiltinBlocks.Sapling, job.Owner, ServerManager.SetBlockFlags.DefaultAudio); state.SetCooldown(2.0); } else { state.SetIndicator(new Shared.IndicatorState(2f, BuiltinBlocks.Sapling)); } } else if (type == BuiltinBlocks.LogTemperate) { if (ChopTree(positionSub, job.Owner)) { state.SetIndicator(new Shared.IndicatorState(10f, BuiltinBlocks.LogTemperate)); ServerManager.SendAudio(positionSub.Vector, "woodDeleteHeavy"); GatherResults.Clear(); GatherResults.Add(new ItemTypes.ItemTypeDrops(BuiltinBlocks.LogTemperate, 3, 1.0)); GatherResults.Add(new ItemTypes.ItemTypeDrops(BuiltinBlocks.LeavesTemperate, 9, 1.0)); GatherResults.Add(new ItemTypes.ItemTypeDrops(BuiltinBlocks.Sapling, 1, 1.0)); GatherResults.Add(new ItemTypes.ItemTypeDrops(BuiltinBlocks.Sapling, 1, 0.25)); ModLoader.TriggerCallbacks(ModLoader.EModCallbackType.OnNPCGathered, job as IJob, positionSub, GatherResults); job.NPC.Inventory.Add(GatherResults); } else { state.SetCooldown(Random.NextFloat(3f, 6f)); } } else { state.SetCooldown(Random.NextFloat(8f, 16f)); } } else { state.SetCooldown(Random.NextFloat(3f, 6f)); } } else { state.SetCooldown(10.0); } positionSub = Vector3Int.invalidPos; }
public static void AfterItemTypesServer() { ItemTypesServer.RegisterOnRemove("water", WaterbucketCode.OnWaterRemoved); ItemTypesServer.RegisterOnAdd(MOD_PREFIX + "waterbucket", WaterbucketCode.OnAddFilled); }
public virtual void OnNPCAtJob(IAreaJob job, ref Vector3Int positionSub, ref NPCBase.NPCState state, ref bool shouldDumpInventory) { if (stages == null || stages.Length < 2) { state.SetCooldown(1.0); return; } state.JobIsDone = true; if (positionSub.IsValid) { ushort type; if (World.TryGetTypeAt(positionSub, out type)) { ushort typeSeeds = stages[0]; ushort typeFinal = stages[stages.Length - 1]; if (type == 0) { if (state.Inventory.TryGetOneItem(typeSeeds) || job.UsedNPC.Colony.UsedStockpile.TryRemove(typeSeeds)) { ServerManager.TryChangeBlock(positionSub, typeSeeds, job.Owner, ServerManager.SetBlockFlags.DefaultAudio); state.SetCooldown(1.0); shouldDumpInventory = false; } else { state.SetIndicator(new Shared.IndicatorState(2f, typeSeeds, true, false)); shouldDumpInventory = state.Inventory.UsedCapacity > 0f; } } else if (type == typeFinal) { if (ServerManager.TryChangeBlock(positionSub, 0, job.Owner, ServerManager.SetBlockFlags.DefaultAudio)) { job.UsedNPC.Inventory.Add(ItemTypes.GetType(typeFinal).OnRemoveItems); } state.SetCooldown(1.0); shouldDumpInventory = false; } else { shouldDumpInventory = state.Inventory.UsedCapacity > 0f; Server.GrowableBlocks.IGrowableBlock block; if (Server.GrowableBlocks.GrowableBlockManager.TryGetGrowableBlock(positionSub, out block)) { state.SetCooldown(5.0); } else { bool found = false; for (int i = 0; i < stages.Length; i++) { if (stages[i] == type) { ItemTypesServer.OnChange(positionSub, 0, type, null); state.SetIndicator(new Shared.IndicatorState(2f, type)); state.SetCooldown(0.2); found = true; break; } } if (!found) { state.SetCooldown(5.0); } } } } else { state.SetCooldown(Random.NextFloat(3f, 6f)); } positionSub = Vector3Int.invalidPos; } else { state.SetCooldown(10.0); } }
public override void OnNPCAtJob(IAreaJob job, ref Vector3Int positionSub, ref NPCBase.NPCState state, ref bool shouldDumpInventory) { state.JobIsDone = true; Vector3Int min = job.Minimum; Vector3Int max = job.Maximum; if (positionSub.x == min.x || positionSub.x == max.x || positionSub.z == min.z || positionSub.z == max.z || (positionSub.x - (min.x + 1)) % 3 != 0 || (positionSub.z - (min.z + 1)) % 3 != 0) { ushort type; if (World.TryGetTypeAt(positionSub.Add(1, 0, 1), out type)) { if (type == BuiltinBlocks.Sapling) { Server.GrowableBlocks.IGrowableBlock block; if (Server.GrowableBlocks.GrowableBlockManager.TryGetGrowableBlock(positionSub.Add(1, 0, 1), out block)) { state.SetCooldown(5.0); } else { ItemTypesServer.OnChange(positionSub.Add(1, 0, 1), 0, BuiltinBlocks.Sapling, null); state.SetIndicator(NPCIndicatorType.Crafted, 2f, BuiltinBlocks.Sapling); state.SetCooldown(0.2); } } } } else if (positionSub.IsValid) { ushort type; if (World.TryGetTypeAt(positionSub, out type)) { if (type == 0) { if (job.UsedNPC.Inventory.TryGetOneItem(BuiltinBlocks.Sapling) || job.UsedNPC.Colony.UsedStockpile.TryRemove(BuiltinBlocks.Sapling)) { ServerManager.TryChangeBlock(positionSub, BuiltinBlocks.Sapling, ServerManager.SetBlockFlags.DefaultAudio); state.SetCooldown(2.0); } else { state.SetIndicator(NPCIndicatorType.MissingItem, 2f, BuiltinBlocks.Sapling); } } else if (type == BuiltinBlocks.LogTemperate) { if (ChopTree(positionSub)) { state.SetIndicator(NPCIndicatorType.Crafted, 10f, BuiltinBlocks.LogTemperate); ServerManager.SendAudio(positionSub.Vector, "woodDeleteHeavy"); AddResults(job.UsedNPC.Inventory); } else { state.SetCooldown(Random.NextFloat(3f, 6f)); } } else { state.SetCooldown(Random.NextFloat(8f, 16f)); } } else { state.SetCooldown(Random.NextFloat(3f, 6f)); } } else { state.SetCooldown(10.0); } positionSub = Vector3Int.invalidPos; }
public static void AfterSelectedWorld() { foreach (string fullDirPath in Directory.GetDirectories(BlocksDirectory)) { string packageName = Path.GetFileName(fullDirPath); if (packageName.Equals("examples")) { continue; } Pipliz.Log.Write(string.Format("Started loading '{0}' texture mappings...", packageName)); JSONNode jsonTextureMapping; if (Pipliz.JSON.JSON.Deserialize(MultiPath.Combine(BlocksDirectory, packageName, "texturemapping.json"), out jsonTextureMapping, false)) { if (jsonTextureMapping.NodeType == NodeType.Object) { foreach (KeyValuePair <string, JSONNode> textureEntry in jsonTextureMapping.LoopObject()) { try { string albedoPath = null; string normalPath = null; string emissivePath = null; string heightPath = null; foreach (string textureType in new string[] { "albedo", "normal", "emissive", "height" }) { string textureTypeValue = textureEntry.Value.GetAs <string> (textureType); string realTextureTypeValue = textureTypeValue; if (!textureTypeValue.Equals("neutral")) { if (textureTypeValue.StartsWith(VANILLA_PREFIX)) { realTextureTypeValue = realTextureTypeValue.Substring(VANILLA_PREFIX.Length); } else { realTextureTypeValue = MultiPath.Combine(BlocksDirectory, packageName, "textures", textureType, textureTypeValue + ".png"); if (textureType.Equals("albedo")) { albedoPath = realTextureTypeValue; } else if (textureType.Equals("normal")) { normalPath = realTextureTypeValue; } else if (textureType.Equals("emissive")) { emissivePath = realTextureTypeValue; } else if (textureType.Equals("height")) { heightPath = realTextureTypeValue; } } Pipliz.Log.Write(string.Format("Rewriting {0} texture path from '{1}' to '{2}'", textureType, textureTypeValue, realTextureTypeValue)); } textureEntry.Value.SetAs(textureType, realTextureTypeValue); } var textureMapping = new ItemTypesServer.TextureMapping(textureEntry.Value); if (albedoPath != null) { textureMapping.AlbedoPath = albedoPath; } if (normalPath != null) { textureMapping.NormalPath = normalPath; } if (emissivePath != null) { textureMapping.EmissivePath = emissivePath; } if (heightPath != null) { textureMapping.HeightPath = heightPath; } string realkey = MOD_PREFIX + packageName + "." + textureEntry.Key; Pipliz.Log.Write(string.Format("Adding texture mapping for '{0}'", realkey)); ItemTypesServer.SetTextureMapping(realkey, textureMapping); } catch (Exception exception) { Pipliz.Log.WriteError(string.Format("Exception while loading from {0}; {1}", "texturemapping.json", exception.Message)); } } } else { Pipliz.Log.WriteError(string.Format("Expected json object in {0}, but got {1} instead", "texturemapping.json", jsonTextureMapping.NodeType)); } } } }
#pragma warning disable IDE0060 // Remove unused parameter internal static void AutoDiscoverType(Dictionary <string, ItemTypesServer.ItemTypeRaw> dict) #pragma warning restore IDE0060 // Remove unused parameter { int typecount = 0; foreach (string modname in Mods.ModManager.GetMods().Keys) { Mods.Mod mod = Mods.ModManager.GetMod(modname); Assembly assembly = Mods.ModManager.GetAssembly(mod.ModName); var typelist = assembly.GetTypes() .Where(t => (t.IsClass && t.IsDefined(typeof(NCAPIType), true))); foreach (var type in typelist) { try { BaseType @base = ((BaseType)Activator.CreateInstance(type)); JSONNode typenode = @base.Register(); if (@base.OverrideReplace) { ItemTypesServer.QueueItemTypePatch(@base.TypeName, ItemTypesServer.EItemTypePatchType.OverrideTypeProperties, typenode, typecount); } else { ItemTypesServer.QueueItemTypePatch(@base.TypeName, ItemTypesServer.EItemTypePatchType.AddNewTypes, typenode, typecount); } typecount++; } catch (MissingFieldException mfe) { Helpers.Logging.WriteLog(mod.ModName, type.Name + " cannot be instantiated. This probably is not an error. " + mfe.Message + " |||| " + mfe.StackTrace, Helpers.Logging.LogType.Issue, true); } catch (InvalidCastException ice) { Helpers.Logging.WriteLog(mod.ModName, type.Name + " does not properly implement our Type System. This probably is not an error. " + ice.Message + " |||| " + ice.StackTrace, Helpers.Logging.LogType.Issue, true); } catch (Exception e) { Helpers.Logging.WriteLog(mod.ModName, type.Name + " Type Error: " + e.Message + "\n" + e.StackTrace + "\n\n" + e.InnerException.Message + "\n" + e.InnerException.StackTrace, Helpers.Logging.LogType.Issue, true); } } string[] directories = Directory.GetDirectories(mod.ModFolder, "*", SearchOption.AllDirectories); foreach (string dir in directories) { if (dir.EndsWith("typesadd")) { string[] files = Directory.GetFiles(dir, "*.json", SearchOption.AllDirectories); foreach (string file in files) { ItemTypesServer.QueueItemTypePatches(file, ItemTypesServer.EItemTypePatchType.AddNewTypes, 1); } } if (dir.EndsWith("typesreplace")) { string[] files = Directory.GetFiles(dir, "*.json", SearchOption.AllDirectories); foreach (string file in files) { ItemTypesServer.QueueItemTypePatches(file, ItemTypesServer.EItemTypePatchType.OverrideTypeProperties, 1); } } } if (Power.PowerManager.IsEnabled()) { var powerlist = assembly.GetTypes() .Where(t => (t.IsClass && t.IsDefined(typeof(Power.PowerManager.NCAPIPowerType), true))); foreach (var power in powerlist) { try { BaseType baseType = ((BaseType)Activator.CreateInstance(power)); JSONNode typenode = baseType.Register(); if (baseType.OverrideReplace) { ItemTypesServer.QueueItemTypePatch(baseType.TypeName, ItemTypesServer.EItemTypePatchType.OverrideTypeProperties, typenode, typecount); } else { ItemTypesServer.QueueItemTypePatch(baseType.TypeName, ItemTypesServer.EItemTypePatchType.AddNewTypes, typenode, typecount); } } catch (MissingFieldException mfe) { Helpers.Logging.WriteLog(mod.ModName, power.Name + " cannot be instantiated. This probably is not an error. " + mfe.Message + " |||| " + mfe.StackTrace, Helpers.Logging.LogType.Issue, true); } catch (InvalidCastException ice) { Helpers.Logging.WriteLog(mod.ModName, power.Name + " does not properly implement our Power Type System. This probably is not an error. " + ice.Message + " |||| " + ice.StackTrace, Helpers.Logging.LogType.Issue, true); } catch (Exception e) { Helpers.Logging.WriteLog(mod.ModName, power.Name + "Power Type Error: " + e.Message + "\n" + e.StackTrace + "\n\n" + e.InnerException.Message + "\n" + e.InnerException.StackTrace, Helpers.Logging.LogType.Issue, true); } } } } Helpers.Logging.WriteLog(NewColonyAPIEntry.ModName, string.Format("Autoloaded {0} blocks/types", typecount), Helpers.Logging.LogType.Loading); }
public static void AfterItemTypesDefined() { ItemTypesServer.RegisterOnRemove(ITEMKEY, OnLootboxPickup); }
public void RegisterCallbackandLoad() { ItemTypesServer.RegisterOnAdd(blockName, onAdd); ItemTypesServer.RegisterOnAdd(blockName, onRemove); }