private bool CheckWater(GeneratorJobWaterInstance instance)
        {
            if (instance.WaterPoisiton != Pipliz.Vector3Int.invalidPos)
            {
                if (World.TryGetTypeAt(instance.WaterPoisiton, out ushort type) == false)
                {
                    return(false);
                }
                if (type == BuiltinBlocks.Indices.water)
                {
                    return(true);
                }
                instance.WaterPoisiton = Pipliz.Vector3Int.invalidPos;
            }
            Assert.IsTrue(instance.WaterPoisiton == Pipliz.Vector3Int.invalidPos, "Water position was not invalid");
            Vector3Int checkDir = WaterDirCheck(instance);

            for (int y = -1; y <= 0; y++)
            {
                if (World.TryGetTypeAt(instance.Position.Add(checkDir.x, y, checkDir.z), out ushort type2))
                {
                    if (type2 == BuiltinBlocks.Indices.water)
                    {
                        instance.WaterPoisiton = instance.Position.Add(0, y, 0);
                        return(true);
                    }
                    continue;
                }
                return(false);
            }

            return(false);
        }
        public override void OnNPCAtJob(BlockJobInstance blockJobInstance, ref NPC.NPCBase.NPCState state)
        {
            GeneratorJobWaterInstance instance = (GeneratorJobWaterInstance)blockJobInstance;

            //Colony owner = instance.Owner;
            state.JobIsDone = true;
            if (!CheckWater(instance))
            {
                state.SetCooldown(0.3);
                return;
            }

            if (instance.counter >= 10)
            {
                instance.counter         = 0;
                instance.ShouldTakeItems = true;
            }
            else
            {
                //Setup power info
                PowerManager.GetPower(blockJobInstance.Position, out int power);
                PowerManager.GetMaxPower(blockJobInstance.Position, out int maxpower);
                if (power != maxpower)
                {
                    state.SetIndicator(new Shared.IndicatorState(CraftingCooldown, ItemTypes.IndexLookup.GetIndex("electricity"), false, false));
                    PowerManager.GeneratePower(blockJobInstance.Position);
                    if (instance.IsCrafting == false)
                    {
                        instance.IsCrafting = true;
                        OnStartCrafting(blockJobInstance);
                    }
                    instance.counter++;
                }
                else
                {
                    state.SetCooldown(0.5);
                    if (instance.IsCrafting == true)
                    {
                        instance.IsCrafting = false;
                        OnStopCrafting(blockJobInstance);
                    }
                }
            }
        }
        private bool CheckWater(GeneratorJobWaterInstance instance)
        {
            if (instance.WaterPoisiton != Pipliz.Vector3Int.invalidPos)
            {
                if (!World.TryGetTypeAt(instance.WaterPoisiton, out ushort type))
                {
                    return(false);
                }
                if (type == BuiltinBlocks.Indices.water)
                {
                    return(true);
                }
                instance.WaterPoisiton = Pipliz.Vector3Int.invalidPos;
            }
            Assert.IsTrue(instance.WaterPoisiton == Pipliz.Vector3Int.invalidPos, "waterpos wasn't invalid");
            for (int x = -1; x <= 1; x++)
            {
                for (int y = -1; y <= 1; y++)
                {
                    for (int z = -1; z <= 1; z++)
                    {
                        if (World.TryGetTypeAt(instance.Position.Add(x, y, z), out ushort type2))
                        {
                            if (type2 == BuiltinBlocks.Indices.water)
                            {
                                instance.WaterPoisiton = instance.Position.Add(x, y, z);
                                return(true);
                            }
                            continue;
                        }
                        return(false);
                    }
                }
            }

            ServerManager.TryChangeBlock(instance.Position, instance.BlockType, ItemTypes.GetType("air"), new BlockChangeRequestOrigin(instance.Owner));
            return(false);
        }