public override Vector3Int GetJobLocation(BlockJobInstance instance) { Vector3Int pos = instance.Position; if (BlockTypes.ContainsByReference(instance.BlockType, out int index)) { switch (index) { case 1: pos.x++; break; case 2: pos.x--; break; case 3: pos.z++; break; case 4: pos.z--; break; } } return(pos); }
private Vector3Int WaterDirCheck(BlockJobInstance instance) { Vector3Int pos = Vector3Int.zero; if (BlockTypes.ContainsByReference(instance.BlockType, out int index)) { switch (index) { case 1: pos.x--; break; case 2: pos.x++; break; case 3: pos.z--; break; case 4: pos.z++; pos.z++; break; } } return(pos); }
public override void OnStopCrafting(BlockJobInstance instance) { if (!BlockTypes.ContainsByReference(instance.BlockType, out int index)) { return; } int num = index; if ((uint)(num - 6) <= 3u) { ItemTypes.ItemType newType = BlockTypes[index - 5]; ESetBlockFlags flags = ESetBlockFlags.None; if (ServerManager.TryChangeBlock(instance.Position, instance.BlockType, newType, instance.Owner, flags) == EServerChangeBlockResult.Success) { instance.BlockType = newType; } } }
public virtual void OnNPCAtJob(BlockJobInstance blockJobInstance, ref NPCState state) { ConstructionJobInstance instance = (ConstructionJobInstance)blockJobInstance; if (BlockTypes.ContainsByReference(instance.BlockType, out int index)) { Vector3 rotate = instance.NPC.Position.Vector; switch (index) { case 1: rotate.x -= 1f; break; case 2: rotate.x += 1f; break; case 3: rotate.z -= 1f; break; case 4: rotate.z += 1f; break; } instance.NPC.LookAt(rotate); } if (instance.ConstructionArea != null && !instance.ConstructionArea.IsValid) { instance.ConstructionArea = null; } if (instance.ConstructionArea == null) { if (AreaJobTracker.ExistingAreaAt(instance.Position.Add(-1, -1, -1), instance.Position.Add(1, 1, 1), out List <IAreaJob> jobs)) { for (int i = 0; i < jobs.Count; i++) { if (jobs[i] is ConstructionArea neighbourArea) { instance.ConstructionArea = neighbourArea; break; } } AreaJobTracker.AreaJobListPool.Return(jobs); } if (instance.ConstructionArea == null) { if (instance.DidAreaPresenceTest) { state.SetCooldown(0.5); ServerManager.TryChangeBlock(instance.Position, instance.BlockType, BuiltinBlocks.Types.air, instance.Owner); } else { state.SetIndicator(new Shared.IndicatorState(Random.NextFloat(3f, 5f), BuiltinBlocks.Indices.erroridle)); instance.DidAreaPresenceTest = true; } return; } } Assert.IsNotNull(instance.ConstructionArea); instance.ConstructionArea.DoJob(instance, ref state); }
public virtual void OnNPCAtJob(BlockJobInstance blockJobInstance, ref NPCState state) { state.JobIsDone = true; MinerJobInstance instance = (MinerJobInstance)blockJobInstance; if (instance.BlockTypeBelow == null || instance.BlockTypeBelow == BuiltinBlocks.Types.air) { if (World.TryGetTypeAt(instance.Position.Add(0, -1, 0), out ItemTypes.ItemType foundType)) { if (foundType == BuiltinBlocks.Types.air) { ThreadManager.InvokeOnMainThread(() => ServerManager.TryChangeBlock(instance.Position, instance.BlockType, BuiltinBlocks.Types.air, instance.Owner)); state.SetCooldown(3.0); // I don't know what's going on here, floating miner jobs return; } instance.BlockTypeBelow = foundType; } else { state.SetCooldown(5.0); return; } } if (instance.MiningCooldown <= 0f) { float cooldown = 0f; if (instance.BlockTypeBelow.CustomDataNode?.TryGetAs("minerMiningTime", out cooldown) ?? false) { instance.MiningCooldown = cooldown; } if (instance.MiningCooldown <= 0f) { ThreadManager.InvokeOnMainThread(() => ServerManager.TryChangeBlock(instance.Position, instance.BlockType, BuiltinBlocks.Types.air, instance.Owner)); state.SetCooldown(3.0); // loaded block below, but it turned out to be non-mineable return; } } if (BlockTypes.ContainsByReference(instance.BlockType, out int index)) { Vector3 rotate = instance.NPC.Position.Vector; switch (index) { case 1: rotate.x += 1f; break; case 2: rotate.x -= 1f; break; case 3: rotate.z += 1f; break; case 4: rotate.z -= 1f; break; } instance.NPC.LookAt(rotate); } AudioManager.SendAudio(instance.Position.Vector, "stoneDelete"); GatherResults.Clear(); var itemList = instance.BlockTypeBelow.OnRemoveItems; for (int i = 0; i < itemList.Count; i++) { GatherResults.Add(itemList[i]); } ModLoader.Callbacks.OnNPCGathered.Invoke(instance, instance.Position.Add(0, -1, 0), GatherResults); InventoryItem toShow = ItemTypes.ItemTypeDrops.GetWeightedRandom(GatherResults); if (toShow.Amount > 0) { state.SetIndicator(new Shared.IndicatorState(instance.MiningCooldown, toShow.Type)); } else { state.SetCooldown(instance.MiningCooldown); } state.Inventory.Add(GatherResults); instance.GatheredItemCount++; if (instance.GatheredItemCount >= MaxCraftsPerRun) { instance.ShouldTakeItems = true; } }